How to redefine a key inside a “minibuffer” mode-map?

浪子不回头ぞ 提交于 2019-12-01 04:57:34

I'm assuming you just needed minibuffer-local-map. Subsequent definitions using keys previously assigned to that key map will trump the prior definitions. To disable a prior key assignment, then just create a new definition and set the last portion to nil instead of 'function-name.

(define-key minibuffer-local-map (kbd "<f6>") 'help-for-help)

Here is an excerpt from Emacs Trunk .../lisp/bindings.el:

(let ((map minibuffer-local-map))
  (define-key map "\en"   'next-history-element)
  (define-key map [next]  'next-history-element)
  (define-key map [down]  'next-history-element)
  (define-key map [XF86Forward] 'next-history-element)
  (define-key map "\ep"   'previous-history-element)
  (define-key map [prior] 'previous-history-element)
  (define-key map [up]    'previous-history-element)
  (define-key map [XF86Back] 'previous-history-element)
  (define-key map "\es"   'next-matching-history-element)
  (define-key map "\er"   'previous-matching-history-element)
  ;; Override the global binding (which calls indent-relative via
  ;; indent-for-tab-command).  The alignment that indent-relative tries to
  ;; do doesn't make much sense here since the prompt messes it up.
  (define-key map "\t"    'self-insert-command)
  (define-key map [C-tab] 'file-cache-minibuffer-complete))

To add to what @lawlist said (which was to bind the key in minibuffer-local-map):

There are multiple minibuffer keymaps, depending on what is being read in the minibuffer, and how. And which of those keymaps you might want to use can depend on which Emacs version you are using.

In addition, there is also the keymap for interaction with buffer *Completions*: completion-list-mode-map.

For completion in the minibuffer, the main keymap is minibuffer-local-completion-map.

Here is a list of the minibuffer keymaps. Some of these might not be available (used) in your Emacs version.

  • minibuffer-local-map
  • minibuffer-local-ns-map
  • minibuffer-local-isearch-map
  • minibuffer-local-completion-map
  • minibuffer-local-must-match-map
  • minibuffer-local-filename-completion-map
  • minibuffer-local-filename-must-match-map
  • minibuffer-local-must-match-filename-map

In addition, you can use minibuffer-with-setup-hook (or minibuffer-setup-hook directly) to add key bindings on the fly, for the duration of a single minibuffer reading.

I will add this info, since it can be really helpful when you are manipulating minibuffer keymaps: You can use C-h M-k (command describe-keymap), from library help-fns+.el, to see all of the bindings of a given minibuffer keymap in human-readable form.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!