emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 7c6d00d 32/67: ivy.el (ivy-read): Return immediately for l


From: Oleh Krehel
Subject: [elpa] master 7c6d00d 32/67: ivy.el (ivy-read): Return immediately for less than 2 candidates
Date: Sun, 22 Mar 2015 17:33:59 +0000

branch: master
commit 7c6d00d2893dcd41bd60e7f1786a56d4cf151d01
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    ivy.el (ivy-read): Return immediately for less than 2 candidates
---
 ivy.el |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/ivy.el b/ivy.el
index 8a6432d..462067e 100644
--- a/ivy.el
+++ b/ivy.el
@@ -124,24 +124,28 @@ COLLECTION is a list of strings.
 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.
 UPDATE-FN is called each time the current candidate(s) is changed.
 If INDEX is non-nil select the corresponding candidate."
-  (setq ivy--index (or index 0))
-  (setq ivy--old-re nil)
-  (setq ivy--old-cands nil)
-  (setq ivy-text "")
-  (setq ivy--all-candidates collection)
-  (setq ivy--update-fn update-fn)
-  (setq ivy-exit nil)
-  (setq ivy--default (or (thing-at-point 'symbol) ""))
-  (unwind-protect
-       (minibuffer-with-setup-hook
-           #'ivy--minibuffer-setup
-         (read-from-minibuffer
-          prompt
-          initial-input
-          ivy-minibuffer-map
-          nil
-          'ivy-history))
-    (remove-hook 'post-command-hook #'ivy--exhibit)))
+  (cl-case (length collection)
+    (0 nil)
+    (1 (car collection))
+    (t
+     (setq ivy--index (or index 0))
+     (setq ivy--old-re nil)
+     (setq ivy--old-cands nil)
+     (setq ivy-text "")
+     (setq ivy--all-candidates collection)
+     (setq ivy--update-fn update-fn)
+     (setq ivy-exit nil)
+     (setq ivy--default (or (thing-at-point 'symbol) ""))
+     (unwind-protect
+          (minibuffer-with-setup-hook
+              #'ivy--minibuffer-setup
+            (read-from-minibuffer
+             prompt
+             initial-input
+             ivy-minibuffer-map
+             nil
+             'ivy-history))
+       (remove-hook 'post-command-hook #'ivy--exhibit)))))
 
 (defvar ivy-text ""
   "Stores the user's string as it is typed in.")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]