Browse files

Add workaround for a bug in ido

When both a default and an intial input are provided to ido, ido
places the point at the beginning of the input instead of at the end.
This advice works around the bug by preprocessing the arguments to
"ido-completing-read". If an initial input is provided and the default
is non-nil, we simply move the default item to the head of the choice
list, and then set the default to nil.

Note that this tweak is only applied when ido is used via the
ido-ubiquitous wrapper, so any direct calls to ido-completing-read
should be unaffected.

Fixes issue #18 in ido-ubiquitous.
  • Loading branch information...
1 parent 7f6753c commit 2971ac75b110d78b66f7f2f7584f0383d1f95ddf @DarwinAwardWinner DarwinAwardWinner committed Sep 4, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 ido-ubiquitous.el
@@ -158,10 +158,18 @@ be used as the value of `completing-read-function'."
;; through the ido-ubiquitous wrapper `completing-read-ido'.
(let* ((ido-this-call-replaces-completing-read ido-next-call-replaces-completing-read)
(ido-next-call-replaces-completing-read nil))
+ ;; Work around a bug in ido when both INITIAL-INPUT and DEF are provided
+ ;; More info:
+ (when (and ido-this-call-replaces-completing-read
+ def initial-input
+ (not (string= initial-input "")))
+ ;; Both default and initial input were provided. So keep the
+ ;; initial input and preprocess the choices list to put the
+ ;; default at the head, then proceed with default = nil.
+ (setq choices (cons def (remove def choices))
+ def nil))
-(defadvice ido-completing-read (before handle-default-initial-conflict activate)
(defmacro ido-ubiquitous-disable-in (func)
"Disable ido-ubiquitous in FUNC."
(let ((docstring

0 comments on commit 2971ac7

Please sign in to comment.