views:

482

answers:

5

I'm a big fan of ido-mode, so much so that I would like to use it for things like describe-function or find-tag and so on, without having to write something like in "Can I get ido-mode-style completion for searching tags in Emacs?" for each one.

Both

(defalias completing-read ido-completing-read)

and

(setf 'completing-read 'ido-completing-read)

don't work, at least partly because ido-completing-read calls completing-read in its body, so any simple redefinition would result in infinite recursion.

In theory, it should be possible, since the first line of the docstring for ido-completing-read is "Ido replacement for the built-in completing-read." I've looked around a bit and can't seem to find anyone else who has attempted or succeeded at it.

I realize that Icicles [2] probably provides something like this, and I may end up going with that anyway, but it is a bit more of a plunge than I care to take right now.

Thanks for any help.

A: 

Just a thought: have you tried editing ido-completing-read to call original-completing-read instead of completing-read, defining original-completing-read to be the current completing-read and then doing your defalias or setf thing?

Jouni K. Seppänen
A: 

Ido comes with a function that should do this, so just call it in your .emacs file:

(ido-everywhere t)

Nathaniel Flath
I had been hoping this would work, but ido's opinion of 'everywhere' is rather limited, restricted to just file, directory and buffer completions. It does not have any effect on things like `describe-function` or `find-tag`, since they are completing other things.My current idea is to save `completing-read` to a variable, alias the name to `ido-completing-read`, and then put a `defadvice` around `ido-completing-read` which restores the original `completing-read` for the duration of ido. That is pretty hackish, and it may not be worth it.
haxney
+1  A: 

I don't think ido-mode is ready for this quite yet. In particular, ido-completing-read currently only works with strings, while completing-read supports alists as well. This is very important once you want to have a different user-level description of the items you want to complete on.

Therefore I am not surprised that it doesn't work out of the box, yet. Short of modifying the code yourself your best bet is probably to just file a bug report/feature request.

nominolo
+3  A: 

Here is my refinement of Jacobo's answer. Credit to him for the original magic. I've added an override variable, which you can use to prevent the use of ido-completing-read in specific functions. I have also added a check that uses the original completing-read if there are no completions (This happens occasionally, for example in org-remember-apply-template from org-mode, which breaks with Jacobo's original advice).

(defvar ido-enable-replace-completing-read t
  "If t, use ido-completing-read instead of completing-read if possible.

Set it to nil using let in around-advice for functions where the
original completing-read is required.  For example, if a function
foo absolutely must use the original completing-read, define some
advice like this:

(defadvice foo (around original-completing-read-only activate)
  (let (ido-enable-replace-completing-read) ad-do-it))")

;; Replace completing-read wherever possible, unless directed otherwise
(defadvice completing-read
  (around use-ido-when-possible activate)
  (if (or (not ido-enable-replace-completing-read) ; Manual override disable ido
          (boundp 'ido-cur-list)) ; Avoid infinite loop from ido calling this
      ad-do-it
    (let ((allcomp (all-completions "" collection predicate)))
      (if allcomp
          (setq ad-return-value
                (ido-completing-read prompt
                               allcomp
                               nil require-match initial-input hist def))
        ad-do-it))))

Oh, and for using ido in M-x, use smex

Ryan Thompson
+5  A: 

Hocus pocus, abracadabra, presto!

(defadvice completing-read
  (around foo activate)
  (if (boundp 'ido-cur-list)
      ad-do-it
    (setq ad-return-value
      (ido-completing-read
       prompt
       (all-completions "" collection predicate)
       nil require-match initial-input hist def))))

That works with everything but subr's, from which execute-extended-command is the one that matters (what is binded to M-x). But we can get what we want from M-x

(global-set-key
 "\M-x"
 (lambda ()
   (interactive)
   (call-interactively
    (intern
     (ido-completing-read
      "M-x "
      (all-completions "" obarray 'commandp))))))
Jacobo Romero Manrique
seems to be broken as of Emacs 23.2. Swapping ido-cur-item for ido-cur-list seems to make it work again.
polyglot