我为修改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
org-mode
中禁用此键绑定。
我尝试了以下内容:
;; 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
到处删除密钥绑定。
答案 0 :(得分:5)
解决问题的另一种方法是检查ac-complete-with-space
模式。如果是org-mode
,请致电self-insert-command
,否则请按照您当前的逻辑进行操作。
答案 1 :(得分:0)
(defun ac-complete-with-space () "Select the candidate and append a space. save your time for typing space." (interactive) (ac-complete) (insert " ") ) ;; NOTE: ac-completing-map is the parent map of ac-menu-map. (define-key ac-completing-map (kbd "SPC") 'ac-complete-with-space) (add-hook 'org-mode-hook (lambda () (define-key ac-menu-map (kbd "SPC") 'self-insert-command)))