全局覆盖Emacs中的键绑定如何设置全局覆盖并优先于该键的所有其他绑定的键绑定?我希望覆盖所有主要/次要模式映射,并确保绑定始终有效。当然,这是行不通的:(global-set-key "\C-i" 'some-function)它在text-mode,但是当我用lisp-mode, C-i是反弹到lisp-indent-line.我可以在lisp-mode每一种模式都是个别的,但必须有更简单的方法。每次为新文件类型安装新模式时,我都必须返回并检查,以确保所有的键绑定都不会被新模式覆盖。我想这样做是因为我想模仿我已经从其他编辑那里学到的和根深蒂固的绑定。
3 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
(defvar my-keys-minor-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-i") 'some-function) map) "my-keys-minor-mode keymap.")(define-minor-mode my-keys-minor-mode "A minor mode so that my key settings override annoying major modes." :init-value t :lighter " my-keys")(my-keys-minor-mode 1)
(defun my-minibuffer-setup-hook () (my-keys-minor-mode 0))(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
load
(add-hook 'after-load-functions 'my-keys-have-priority)(defun my-keys-have-priority (_file) "Try to ensure that my keybindings retain priority over other minor modes. Called via the `after-load-functions' special hook." (unless (eq (caar minor-mode-map-alist) 'my-keys-minor-mode) (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist))) (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist) (add-to-list 'minor-mode-map-alist mykeys))))
添加回答
举报
0/150
提交
取消