浏览代码

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 年之前
父节点
当前提交
2971ac75b1
共有 1 个文件被更改,包括 10 次插入2 次删除
  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