Browse Source

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.
Ryan C. Thompson 13 years ago
parent
commit
2971ac75b1
1 changed files with 10 additions and 2 deletions
  1. 10 2
      ido-ubiquitous.el

+ 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: https://github.com/technomancy/ido-ubiquitous/issues/18
+    (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))
     ad-do-it))
 
-(defadvice ido-completing-read (before handle-default-initial-conflict activate)
-
 (defmacro ido-ubiquitous-disable-in (func)
   "Disable ido-ubiquitous in FUNC."
   (let ((docstring