emacs-diffs
[Top][All Lists]
Advanced

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

master 0bb97ad 2/3: Fix icomplete-force-complete-and-exit for no-input s


From: João Távora
Subject: master 0bb97ad 2/3: Fix icomplete-force-complete-and-exit for no-input situations
Date: Fri, 1 Nov 2019 22:39:35 -0400 (EDT)

branch: master
commit 0bb97ad8b89af91e296ea791f34b46963323ce7a
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Fix icomplete-force-complete-and-exit for no-input situations
    
    If there is no minibuffer input, but the user has already cycled some
    pre-calculated completions, we should be calling
    minibuffer-force-complete-and-exit instead of
    minibuffer-complete-and-exit.  The former is guaranteed to be fast in
    this situation and yields the desired "selected" completion, while the
    latter will just give us the default, ignoring all the cycling of
    icomplete-{forward|backward}-completions.
    
    * lisp/icomplete.el (icomplete-force-complete-and-exit): Add
    comments and fix for empty input but some completions calculated.
---
 lisp/icomplete.el | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 89318ca..47e47f8 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -152,13 +152,33 @@ icompletion is occurring."
   "Keymap used by `icomplete-mode' in the minibuffer.")
 
 (defun icomplete-force-complete-and-exit ()
-  "Complete the minibuffer and exit.
+  "Complete the minibuffer with the longest possible match and exit.
 Use the first of the matches if there are any displayed, and use
 the default otherwise."
   (interactive)
-  (if (or (and (not minibuffer-default) icomplete-show-matches-on-no-input)
-          (> (icomplete--field-end) (icomplete--field-beg)))
+  ;; This function is tricky.  The mandate is to "force", meaning we
+  ;; should take the first possible valid completion for the input.
+  ;; However, if there is no input and we can prove that that
+  ;; coincides with the default, it is much faster to just call
+  ;; `minibuffer-complete-and-exit'.  Otherwise, we have to call
+  ;; `minibuffer-force-complete-and-exit', which needs the full
+  ;; completion set and is potentially slow and blocking.  Do the
+  ;; latter if:
+  (if (or
+       ;; there's some input, meaning the default in off the table by
+       ;; definition; OR
+       (> (icomplete--field-end) (icomplete--field-beg))
+       ;; there's no input, but there's also no minibuffer default
+       ;; (and the user really wants to see completions on no input,
+       ;; meaning he expects a "force" to be at least attempted); OR
+       (and (not minibuffer-default)
+            icomplete-show-matches-on-no-input)
+       ;; there's no input but the full completion set has been
+       ;; calculated, This causes the first cached completion to
+       ;; be taken (i.e. the one that the user sees highlighted)
+       completion-all-sorted-completions)
       (minibuffer-force-complete-and-exit)
+    ;; Otherwise take the faster route...
     (minibuffer-complete-and-exit)))
 
 (defun icomplete-force-complete ()



reply via email to

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