Can I use ido-completing-read instead of completing-read everywhere?
Asked Answered
G

6

13

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 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.

Glutelin answered 25/5, 2009 at 4:39 Comment(0)
A
3

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.

Aflcio answered 26/5, 2009 at 15:48 Comment(0)
I
10

Edit: This is now an Emacs package available from MELPA. It has been expanded into a full-fledged minor mode. Development happens on GitHub.

Original post:

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 amx.

Iloilo answered 19/6, 2009 at 18:58 Comment(0)
D
7

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))))))
Deception answered 5/7, 2009 at 20:4 Comment(1)
seems to be broken as of Emacs 23.2. Swapping ido-cur-item for ido-cur-list seems to make it work again.Okoka
A
3

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.

Aflcio answered 26/5, 2009 at 15:48 Comment(0)
M
1

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

(ido-everywhere t)

Motto answered 25/5, 2009 at 15:1 Comment(1)
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.Glutelin
B
1

Using Emacs 24.3, ido-ubiquitous didn't work for me. So tried this and it is working fine so far:

(defun my-completing-read (prompt collection &optional predicate
                  require-match initial-input
                  hist def inherit-input-method)
  (if (listp collection)
      (ido-completing-read prompt collection predicate require-match
               initial-input hist def inherit-input-method)
    (completing-read-default prompt collection predicate require-match
                 initial-input hist def inherit-input-method)))

(setq completing-read-function 'my-completing-read)
Blowing answered 12/3, 2013 at 13:43 Comment(1)
ido-ubiquitous now works fine with recent Emacsen, since Ryan rewrote it.Gudrin
T
0

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?

Theolatheologian answered 25/5, 2009 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.