Occasionally ido
12 Feb 2015As I was refactoring my .emacs
, I found a silly wrapper around
describe-function
that uses ido-completing-read
. I think I was
aware at the time that
ido-ubiquitous
could simply make describe-function
use ido-completing-read
. The
problem was that it also affected the completing-read
in functions
that became headlong-bookmark-jump
from
headlong
(see the corresponding post
if you missed it).
A bit of code to make things right
(defun ido-occasional-completing-read
(prompt collection
&optional predicate require-match initial-input
hist def inherit-input-method)
"Use `ido-completing-read' if the collection isn't too large.
Fall back to `completing-read' otherwise."
(let ((filtered-collection
(all-completions "" collection predicate)))
(if (<= (length filtered-collection) 30000)
(ido-completing-read
prompt filtered-collection nil
require-match initial-input hist
def nil)
(completing-read
prompt collection predicate
require-match initial-input hist
def inherit-input-method))))
;;;###autoload
(defmacro with-ido-completion (fun)
"Wrap FUN in another interactive function with ido completion."
`(defun ,(intern (concat (symbol-name fun) "/with-ido")) ()
,(format "Forward to `%S' with ido completion." fun)
(interactive)
(let ((completing-read-function
'ido-occasional-completing-read))
(call-interactively #',fun))))
The only thing that ido-occasional-completing-read
does is to
pre-filter collection
with predicate
and pass it on to
ido-completing-read
. And with-ido-completion
is just a convenience wrapper.
Example
(global-set-key (kbd "<f1> f")
(with-ido-completion describe-function))
(global-set-key (kbd "<f1> v")
(with-ido-completion describe-variable))
(global-set-key (kbd "<f2> i")
(with-ido-completion info-lookup-symbol))
Here, with-ido-completion
will generate
e.g. describe-function/with-ido
, which will subsequently be bound to
<f1> f. The good-old describe-function
is left unaffected.
Note, that if I turn on helm-mode
at this point, it will override
describe-function
with its own completion, but it will not touch
describe-function/with-ido
which I bound. This can be useful e.g. if
I want to use helm-mode
(or icy-mode
or icomplete-mode
) for some
completion, but not all.
You can find the package at ido-occasional.