Answers:
您可以在特定于模式的映射中定义键,例如:
(add-hook 'coffee-mode-hook
(lambda ()
(define-key coffee-mode-map (kbd "C-c c") 'coffee-compile-file)))
或者,更干净:
(eval-after-load "coffee-mode"
'(define-key coffee-mode-map (kbd "C-c c") 'coffee-compile-file))
第二条语句使键定义只发生一次,而第一条语句使每次coffee-mode
启用键都发生定义(这是过大的)。
eval-after-load
在这种情况下使用语句那样干净。我将适当地更新答案。
Emacs 24.4替换eval-after-load
为with-eval-after-load
:
** New macro `with-eval-after-load'.
This is like the old `eval-after-load', but better behaved.
所以答案应该是
(with-eval-after-load 'coffee-mode
(define-key coffee-mode-map (kbd "C-c C-c") 'coffee-compile-file)
(define-key erlang-mode-map (kbd "C-c C-m") 'coffee-make-coffee)
;; Add other coffee commands
)
(add-hook 'coffee-mode-hook (lambda () (define-key coffee-mode-map (kbd "C-c c") 'coffee-compile-file)))