覆盖主模式的键绑定的正确方法是什么,因此它只会影响缓冲区本地键映射?我想我可以使用searchDetailCriteria
或local-set-key
,但我的尝试会影响全局的键盘映射(如下所示)。
是否有必要复制地图,如下所示,或创建具有不同键映射的次要模式?如果可能的话,能够使它成为局部变量会很好。
例如,假设我希望make-local-variable
original
绑定到全局C-c C-c
,但在调用emacs-lisp-mode-map
后我希望jump-to-other-buffer
绑定到C-c C-c
local-version
仅限于该缓冲区。
(defun original ()
(interactive)
(message "original"))
(defun local-version ()
(interactive)
(message "local binding"))
;; open new buffer in emacs-lisp mode and set a local key
(defun jump-to-other-buffer ()
(interactive)
(with-current-buffer (get-buffer-create "*test1*")
(emacs-lisp-mode)
;; These change bindings in all elisp buffers
;; (make-local-variable 'emacs-lisp-mode-map)
;; (define-key emacs-lisp-mode-map (kbd "C-c C-c") 'local-version)
;; (local-set-key (kbd "C-c C-c") 'local-version)
(let ((overriding-local-map (copy-keymap emacs-lisp-mode-map)))
(define-key overriding-local-map (kbd "C-c C-c") 'local-version)
(use-local-map overriding-local-map))
(pop-to-buffer (current-buffer))))
;; default binding in elisp buffers
(define-key emacs-lisp-mode-map (kbd "C-c C-c") 'original)