如何在地图中将地图中的键绑定取消设置为模式?

sta*_*ner 2 emacs elisp autocomplete key-bindings

我已经为修改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 " ")
    ))
Run Code Online (Sandbox Code Playgroud)

......我想禁用此键绑定中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))
            ))
Run Code Online (Sandbox Code Playgroud)

不幸的是,这并没有在本地(即仅在org-mode)中取消键绑定.相反,它从ac-menu-map任何地方删除键绑定.

jua*_*eon 5

解决问题的另一种方法是检查ac-complete-with-space模式.如果org-mode,然后调用self-insert-command,否则按照您当前的逻辑.