Mirzhan Irkegulov
Mirzhan Irkegulov

Reputation: 18055

Emacs: change Ido completion keymap in minibuffer

I use Ido mode and also use Ergoemacs mode, which binds find-file command to C-o. When you are browsing files, you can temporarily disable Ido by pressing C-x C-f inside minibuffer. I want to change it to C-o, so i can press it twice to run find-file without Ido. How can i do that?

In ido.el i see that Ido uses function ido-init-completion-maps, where it defines keys by running code like

(let ((map (make-sparse-keymap)))
  (define-key map "\C-x\C-f" 'ido-fallback-command))

However i'm not sure how to use this to bind ido-fallback-command to C-o inside minibuffer.

Emacs version: 24.0.94.1

Edit (20.03.12): After discussion with Francesco i evaluated: (define-key ido-file-completion-map "\C-o" 'ido-fallback-command).

Now when i press C-h k C-o i see this line: C-o Fallback to non-ido version of current command.

However when i press C-o again in minibuffer, i get this error: Debugger entered--Lisp error: (error "Command attempted to use minibuffer while in minibuffer") C-x C-f in minibuffer still worked as fallback command.

We found out that Ergoemacs package has to do with it. When i turn off Ergoemacs-mode, both C-x C-f and C-o work as fallback commands. I tried to swap Ido and Ergoemacs keymaps in minor-mode-map-alist using the following code:

(let ((elem (first
         (remove-if-not
          '(lambda (item) (equal 'ido-mode (car item)))
          minor-mode-map-alist))))
  (setq minor-mode-map-alist (remove elem minor-mode-map-alist))
  (add-to-list 'minor-mode-map-alist elem))

(define-key ido-file-completion-map "\C-o" 'ido-fallback-command)'

Didn't work.

Upvotes: 5

Views: 1007

Answers (1)

You can use something like this:

(define-key ido-file-completion-map "\C-o" 'ido-fallback-command)

Upvotes: 6

Related Questions