[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using ido-completions in other packages
From: |
Štěpán Němec |
Subject: |
Re: Using ido-completions in other packages |
Date: |
Fri, 04 Jun 2010 14:06:47 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Tassilo Horn <tassilo@member.fsf.org> writes:
> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
> Hi Andrea,
>
>> I've looked in the code but I don't see what I could substitute, maybe
>> substituting some functions or advising something else would do the
>> trick?
What I've been successfully using for some time is this, based on the
dysfunctional (for me, anyway) tip from the Emacs Wiki:
<http://www.emacswiki.org/emacs/InteractivelyDoThings#toc12>
(defvar ido-replace-completing-read t
"If non-nil, 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-replace-completing-read) ad-do-it))")
(defvar ido-replace-completing-read-ignore-commands nil
"List of commands to... you get the point.")
(setq ido-replace-completing-read-ignore-commands
'(describe-function describe-variable find-function find-variable
w3m-goto-url w3m-goto-url-new-session))
;; replace completing-read wherever possible, unless directed otherwise
(defadvice completing-read
(around use-ido-when-possible activate)
(if (or (not ido-replace-completing-read)
ido-cur-list ; Avoid infinite loop from ido calling this
(memq this-command ido-replace-completing-read-ignore-commands))
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))))
HTH,
Štěpán
>
> Basically, if you want to use ido-completion in some code, you would use
> `ido-comleting-read' instead of `completing-read'. For example, in some
> home-brewn mode I have something like that:
>
> (if (and (featurep 'ido) ido-mode)
> ;; ido is available and enabled, so use it.
> (ido-completing-read "Command: " commands)
> ;; fallback to normal completion with the
> ;; most frequently used command as default.
> (completing-read
> (concat "Command (defaults to `"
> (car commands) "'): ")
> commands
> nil t nil nil (car commands)))
>
> You could try to make `completing-read' point to `ido-completing-read':
>
> (fset 'completing-read 'ido-completing-read)
>
> But that might error in some cases, cause `completing-read' has one
> optional parameter more than `ido-completing-read'. You might want to
> create a function `andrea-completing-read' with the exact signature of
> `completing-read' which just delegates to `ido-completing-read' and
> throws away the additional parameter, and then do
>
> (fset 'completing-read 'andrea-completing-read)
>
> In any case: This method is a hammer, so be warned. ;-)
>
> Bye,
> Tassilo
- Using ido-completions in other packages, Andrea Crotti, 2010/06/04
- Re: Using ido-completions in other packages, Tassilo Horn, 2010/06/04
- Re: Using ido-completions in other packages,
Štěpán Němec <=
- Re: Using ido-completions in other packages, Andrea Crotti, 2010/06/04
- Re: Using ido-completions in other packages, Thierry Volpiatto, 2010/06/04
- Re: Using ido-completions in other packages, Andrea Crotti, 2010/06/04
- Re: Using ido-completions in other packages, Thierry Volpiatto, 2010/06/04
- Re: Using ido-completions in other packages, Andrea Crotti, 2010/06/05
Re: Using ido-completions in other packages, William Xu, 2010/06/08