6

In my environment, the find-file is remapped to ido-find-file. How could I cancel the remap and just get the non-Ido version?

Enze Chi
  • 1,410
  • 12
  • 28
  • This does not answer this question but the end result might be what you are interested in: `C-x C-f` launches `ido-find-file` if `ido-mode` is enabled. But hitting `C-f` after that will call `find-file`; so you simply do `C-x C-f C-f` for `find-file` and `C-x C-f` for `ido-find-file`. – Kaushal Modi Apr 23 '15 at 13:20
  • Probably related solution: http://emacs.stackexchange.com/a/5399/115 – Kaushal Modi Apr 23 '15 at 13:22

2 Answers2

6
(define-key KEYMAP [remap find-file] nil)

where KEYMAP is the keymap where the remapping was done. For example, it might be the variable global-map.

The keymap is apparently not accessible directly by a variable, but it is the cdr of the cons that is pointed to by variable ido-minor-mode-map-entry. So this should pretty much do it:

(define-key (cdr ido-minor-mode-map-entry) [remap find-file] nil)

(That assumes that ido-mode has been called at least once. If not, call it. ;-))

In sum, you bind the remapping of find-file to nil, which means that you give it no binding (you unbind it). Binding to nil is how you unbind a key generally. In this case, the "key" to be unbound is [remap find-file], which is a pseudo-key, a remapping.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Is it missing the map name? – Kaushal Modi Apr 23 '15 at 00:22
  • I think the `define-key` function need a key map which I can't figure out what the proper one for this case. – Enze Chi Apr 23 '15 at 00:42
  • Almost certainly `global-map` (in which case you could alternatively just use `global-set-key` in place of `define-key`). – phils Apr 23 '15 at 00:46
  • Oops; sorry, yes, I forgot the `KEYMAP` argument. – Drew Apr 23 '15 at 02:01
  • It's not `global-map`, ido does it in a bit unconventional (to me) way. It does not have a globally accessible `map` defvar. It has a `let` bound `map` and it adds (cons 'ido-mode map)` directly to `minor-mode-map-alist`. So we'd need to get cdr of the element from that alist whose car is `ido-mode`, modify that and put that modified map back in alist. Is there a simpler way? – Kaushal Modi Apr 23 '15 at 02:15
  • @kaushalmodi: That's more or less what you'll have to do, if there is no other pointer (e.g. a variable) to the keymap itself. If the only pointer to it were in `minor-mode-map-alist`, then you'd need to grab it there. But that cons is apparently pointed to directly by variable `ido-minor-mode-map-entry`, so you can at least get to the cons that way, instead of digging it out of minor-mode-alist`. And the keymap is the cdr of that cons. Kinda weird that Ido doesn't bother to offer a keymap variable... – Drew Apr 23 '15 at 06:06
  • @Drew Thanks. I wasn't aware that `ido-minor-mode-map-entry` acted as a pointer. My understanding was that only `setcar` and `setcdr` incorporated the set-value-by-reference power. But TIL that pointers are implicit in elisp lists. Correct? – Kaushal Modi Apr 23 '15 at 11:05
  • @kaushalmodi: I wasn't aware of it either; I just looked at the ido.el code (I don't use Ido). The variable points to a particular cons cell. Its cdr is the keymap (a particular cons, itself). You just pass that keymap to `define-key`. – Drew Apr 23 '15 at 14:59
-1

Normally, you do that with (ido-mode -1).

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • 2
    The OP probably doesn't want to disable `ido-mode` but also doesn't want it to remap `find-file`; probably wants to bind `ido-find-file` to something else? – Kaushal Modi Apr 23 '15 at 13:18
  • Could be, but it's far from clear from his question, IMO. – Stefan Apr 23 '15 at 13:25