我们知道,emacs中修改全局快捷键的格式如下:
(global-set-key KEY COMMAND)
如将M-j绑定到find-file函数如下:
(global-set-key (kbd "M-j") 'find-file)
其基本格式如下:
(global-set-key KEYMAP KEY COMMAND)
这里多了一个KEYMAP的名字,也就是每个Major Mode有一个KEYMAP的名字.
这里以php-mode为例,假如我想在php-mode的Major Mode下将M-j绑定到find-file函数,
它的做法如下:
(require 'php-mode) (define-key php-mode-map (kbd "M-j") 'find-file)
你可能遇到以下两个问题
问题1 怎样获得Major Mode的名字下面的函数可以帮你得到
(defun get-buffer-mode-name (buffer-or-string) "Get the buffer major mode name." (interactive "bBuffer Name:") (message (with-current-buffer buffer-or-string major-mode)))
wrong type argument keymapp nil
你应该先判断是否为空,如下设置
(if matlab-shell-mode-map () ; Do not change the keymap if it is already set up. (setq matlab-shell-mode-map (make-sparse-keymap)) (define-key matlab-shell-mode-map (kbd "C-c SPC") 'ace-jump-mode) (define-key matlab-shell-mode-map (kbd "C-x SPC") 'ace-jump-mode) (define-key matlab-shell-mode-map (kbd "RET") 'comint-send-input) (define-key matlab-shell-mode-map (kbd "C-c C-c")'comint-interrupt-subjob) )更多设置例子见 链接