(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)))
How to unset a keybinding in a map locally to a mode?
-
26-06-2023 - |
문제
I have set up a key binding for a function that modifies the behavior of 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 " ")
))
... and I want to disable this key binding in ac-menu-map
in org-mode
only.
I have tried the following:
;; 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))
))
Unfortunately, this does not unset the key binding locally (i.e., only in org-mode
). Instead, it removes the key binding from the ac-menu-map
everywhere.
해결책 2
다른 팁
A different approach to solve your problem would be to check in ac-complete-with-space
the mode. If org-mode
, then call self-insert-command
, else follow your current logic.
제휴하지 않습니다 StackOverflow