How to set a key-binding to work in certain modes

2019-07-08 00:01发布

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.

标签: emacs elisp
1条回答
仙女界的扛把子
2楼-- · 2019-07-08 00:09
(eval-after-load 'sml-mode 
  '(define-key sml-mode-map (kbd "C-c c") 'sml-create-comment))
查看更多
登录 后发表回答