Friday 20 October 2017

key binding - Setting major-mode specific keybindings in emacs


In my .emacs file, I want to add a key binding for a specific major mode (setting coffee-compile-file to C-c C-c in coffee-mode).


I've found a lot of instructions on using local-set-key and global-set-key, so I can easily add this binding once I've opened a file in coffee-mode, but it would be nice for this to be handled by .emacs.



Answer



Use the mode hook. C-h m shows information about the major mode, usually including what hook(s) it supports; then you do something like


(add-hook 'coffee-mode-hook ;; guessing
'(lambda ()
(local-set-key "\C-cc" 'coffee-compile-file)))

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...