如何重新映射 ido-find-file 中的键?

How to remap keys in ido-find-file?

我一直在尝试对 ido-mode 进行一些更改以使其更有用。我一直在尝试做的一件事是重新映射我在 ido-find-file 中使用的一些键。最主要的是我想使用 C-d 来调用 ido-enter-dired 函数,而不是必须按 C-f+C-d 做同样的事情。

到目前为止,这是我的 ido 设置:

(defun ali/ido ()
  "My configuration for ido-mode"
  (require 'ido)
  (setq ido-create-new-buffer 'always)

  ;; Making sure that ido works in M-x
  (global-set-key
      "\M-x"
      (lambda ()
      (interactive)
      (call-interactively
          (intern
          (ido-completing-read
          "M-x "
          (all-completions "" obarray 'commandp))))))

  ;; Ido keybindings
  (defun ido-keybindings ()
    (define-key ido-completion-map (kbd "C-d") 'ido-enter-dired))


  (add-hook 'ido-setup-hook 'ido-keybindings)

  (ido-everywhere t)
  (ido-mode 1))

但是,每当我尝试在 ido-find-file 中使用 C-d 时,我总是会收到此错误:

Debugger entered--Lisp error: (error "Command attempted to use minibuffer while in minibuffer")

在迷你缓冲区处于活动状态的情况下调用时,您的命令使用递归迷你缓冲区通过 ido-completing-read.

读取输入

改为使用此命令:

(lambda ()
  (interactive)
  (let ((enable-recursive-minibuffers  t)) ; <=====================
    (call-interactively
     (intern
      (ido-completing-read
       "M-x "
       (all-completions "" obarray 'commandp))))))

C-h v enable-recursive-minibuffers 告诉我们:

enable-recursive-minibuffers is a variable defined in C source code.

Its value is nil

Documentation:

Non-nil means to allow minibuffer commands while in the minibuffer.

This variable makes a difference whenever the minibuffer window is active. Also see minibuffer-depth-indicate-mode, which may be handy if this variable is non-nil.

You can customize this variable.