File-specific key-binding in emacs

后端 未结 4 975
我寻月下人不归
我寻月下人不归 2020-12-19 20:10

Is it possible to define file specific key-bindings in emacs? I suppose it would be possible to create a minor mode and have it loaded when the particular file is open but f

4条回答
  •  执笔经年
    2020-12-19 21:03

    Setting up a minor mode and loading it automatically when opening the specific file is actually simpler than I thought.

    The mode file is something along these lines:

    (define-minor-mode magic-mode
      "Provide functions to do magic."
      :lighter " !!!"
      :keymap (let ((map (make-sparse-keymap)))
                (define-key map (kbd "M-z") 'xyzzy)
                map)
    )
    
    
    (defun xyzzy()
      "Use at your own risk"
      (message "Nothing happens.")
      )
    
    
    
    (provide 'magic-mode)
    

    It has to be put somewhere the .emacs will look into and the following line is to be added to the .emacs:

    (require magic-mode)
    

    Finally, the followingblock should be added at the end of the file that should use the specific commands:

    ;; Local Variables:
    ;; eval: (magic-mode)
    ;; End:
    

提交回复
热议问题