在emacs而不是其他模式下,如何设置密钥绑定在某些模式下工作 [英] How to set a key-binding to work in certain modes in emacs and not others
本文介绍了在emacs而不是其他模式下,如何设置密钥绑定在某些模式下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(defun sml-create-comment()
Documentation ..
(interactive)
(code-to-insert-评论))
我希望将此函数绑定到一个键,例如Cc c。如果我是sml模式,并键入'C-c',它会发出一个sml评论;同样,如果我在c模式,它会做一个c评论。我很抱歉,如果我已经表达了这个奇怪的,或者应该是很明显的。
解决方案
(eval-after-load'sml-mode
'(define-key sml-mode-map(kbdCc c)'sml-create-comment)
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.
解决方案
(eval-after-load 'sml-mode
'(define-key sml-mode-map (kbd "C-c c") 'sml-create-comment))
这篇关于在emacs而不是其他模式下,如何设置密钥绑定在某些模式下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文