Browse Source

Disable compatibility when the user cycles choices

Ryan C. Thompson 13 years ago
parent
commit
cb1819a1bf
1 changed files with 26 additions and 6 deletions
  1. 26 6
      ido-ubiquitous.el

+ 26 - 6
ido-ubiquitous.el

@@ -201,14 +201,32 @@ effectively permanently part of this list already.)"
 Apparently, long ago `completing-read' did not have a \"default\"
 Apparently, long ago `completing-read' did not have a \"default\"
 argument, so functions that used it requested the default item by
 argument, so functions that used it requested the default item by
 returning an empty string when RET was pressed with an empty
 returning an empty string when RET was pressed with an empty
-input. When t, this option forces `ido-completing-read' to do the
-same (instead of returning the first choice in the list like it
-would normally do). This improves compatibility with many
-functions that use completing-read in this way, but may also
-break compatibility with others.
+input. When t, this option forces `ido-completing-read' to mimic
+this behavior by returning an empty string if the user has
+neither entered any text nor cycled choices (instead of ido's
+normal behavior of returning the first choice in the list). This
+improves compatibility with many older functions that use
+`completing-read' in this way, but may also break compatibility
+with others.
 
 
 This has no effect when ido is completing buffers or files.")
 This has no effect when ido is completing buffers or files.")
 
 
+(defvar ido-ubiquitous-initial-item nil
+  "The first item selected when ido starts.")
+
+(defadvice ido-read-internal (before clear-initial-item activate)
+  (setq ido-ubiquitous-initial-item nil))
+
+(defadvice ido-make-choice-list (after set-initial-item activate)
+  (when (and ad-return-value (listp ad-return-value))
+    (setq ido-ubiquitous-initial-item (car ad-return-value))))
+
+(defadvice ido-next-match (after clear-initial-item activate)
+  (setq ido-ubiquitous-initial-item nil))
+
+(defadvice ido-prev-match (after clear-initial-item activate)
+  (setq ido-ubiquitous-initial-item nil))
+
 (defadvice ido-exit-minibuffer (around required-allow-empty-string activate)
 (defadvice ido-exit-minibuffer (around required-allow-empty-string activate)
   "Emulate a quirk of `completing-read'.
   "Emulate a quirk of `completing-read'.
 
 
@@ -222,7 +240,9 @@ This has no effect when ido is completing buffers or files."
            (eq ido-cur-item 'list)
            (eq ido-cur-item 'list)
            ido-require-match
            ido-require-match
            (null ido-default-item)
            (null ido-default-item)
-           (string= ido-text ""))
+           (string= ido-text "")
+           (string= (car ido-cur-list)
+                    ido-ubiquitous-initial-item))
       (ido-select-text)
       (ido-select-text)
     ad-do-it))
     ad-do-it))