]> code.delx.au - gnu-emacs-elpa/commitdiff
ivy.el (ivy-completion-in-region): Optimize for 1 cand
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 8 Jan 2016 12:23:20 +0000 (13:23 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 8 Jan 2016 12:24:53 +0000 (13:24 +0100)
When there's only one candidate, call the action immediately.

ivy.el

diff --git a/ivy.el b/ivy.el
index e2c5abc6111077020e49828d5cffe9cfadd9b24e..b730f78ac84d03d89b940f068330af897c35e52e 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -1401,19 +1401,21 @@ The previous string is between `ivy-completion-beg' and `ivy-completion-end'."
     (if (null comps)
         (message "No matches")
       (nconc comps nil)
-      (let* ((w (1+ (floor (log (length comps) 10))))
-             (ivy-count-format (and ivy-count-format
-                                    (format "%%-%dd " w))))
-        (setq ivy-completion-beg (- end (ivy-completion-common-length (car comps))))
-        (setq ivy-completion-end end)
-        (and
-         (ivy-read (format "(%s): " str)
-                   ;; remove 'completions-first-difference face
-                   (mapcar #'substring-no-properties comps)
-                   :predicate predicate
-                   :action #'ivy-completion-in-region-action
-                   :require-match t)
-         t)))))
+      (setq ivy-completion-beg (- end (ivy-completion-common-length (car comps))))
+      (setq ivy-completion-end end)
+      (if (null (cdr comps))
+          (ivy-completion-in-region-action (car comps))
+        (let* ((w (1+ (floor (log (length comps) 10))))
+               (ivy-count-format (and ivy-count-format
+                                      (format "%%-%dd " w))))
+          (and
+           (ivy-read (format "(%s): " str)
+                     ;; remove 'completions-first-difference face
+                     (mapcar #'substring-no-properties comps)
+                     :predicate predicate
+                     :action #'ivy-completion-in-region-action
+                     :require-match t)
+           t))))))
 
 ;;;###autoload
 (define-minor-mode ivy-mode