【发布时间】:2014-05-15 02:19:48
【问题描述】:
我已经为修改 Emacs auto-complete 行为的函数设置了键绑定:
;; ISSUE: when I type the whole candidate string and then press [SPC],
;; Emacs will insert two spaces.
(define-key ac-menu-map (kbd "SPC")
(defun ac-complete-with-space ()
"Select the candidate and append a space. Save your time for typing space."
(interactive)
(ac-complete)
;; FIXME: this auto-inserts two spaces.
(insert " ")
))
...我想在ac-menu-map in org-mode only 中禁用此键绑定。
我尝试了以下方法:
;; Avoid always selecting unwanted first candidate with auto-complete
;; when writing in org-mode.
(add-hook 'org-mode-hook
(lambda ()
;; (define-key ac-menu-map (kbd "SPC") nil)
;; (define-key ac-menu-map (kbd "SPC") 'self-insert-command)
;; (setq-local ac-menu-map (delq (kbd "SPC") ac-menu-map))
))
不幸的是,这不会取消设置键绑定本地(即,仅在org-mode 中)。相反,它会从任何地方的ac-menu-map 中删除键绑定。
【问题讨论】:
-
键盘映射(默认)是全局变量。如果您
(define-key ac-menu-map ...)anywhere 它会影响该键盘映射 everywhere。您可以执行 juanleon 建议的操作并将密钥(无处不在)绑定到检查当前主要模式然后采取相应措施的功能;或者您可以使用 org-mode-hook 为 org-mode 缓冲区创建ac-menu-mapbuffer-local,并以这种方式进行修改。
标签: emacs autocomplete elisp key-bindings