问题
I'm sorry if this is a stupid question but I've been searching on how to do this for hours. I want certain elisp functions to bind to specific key-bindings and for those key-bindings to call a function depending on the mode that the current buffer is in. I'll give an example.
(defun sml-create-comment ()
"Documentation.."
(interactive)
(code-to-insert-comment))
I want this function to be binded to a key, for example 'C-c c'. If I was in sml-mode and typed 'C-c c' it would make an sml comment; and likewise if I was in c-mode it would make a c comment. I'm sorry if I've phrased this weird or if it is supposed to be obvious.
回答1:
(eval-after-load 'sml-mode
'(define-key sml-mode-map (kbd "C-c c") 'sml-create-comment))
来源:https://stackoverflow.com/questions/14410018/how-to-set-a-key-binding-to-work-in-certain-modes-in-emacs-and-not-others