aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2019-10-31 20:19:35 +0000
committerJoão Távora2019-11-02 02:35:45 +0000
commit0bb97ad8b89af91e296ea791f34b46963323ce7a (patch)
treea6c708979032da419350fbe6f8f8bbd64ff6c149
parent88f193ed05649b8c622867b8b2623b8cb08fdc96 (diff)
downloademacs-0bb97ad8b89af91e296ea791f34b46963323ce7a.tar.gz
emacs-0bb97ad8b89af91e296ea791f34b46963323ce7a.zip
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.
-rw-r--r--lisp/icomplete.el26
1 files changed, 23 insertions, 3 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 89318ca4c7e..47e47f895f0 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -152,13 +152,33 @@ icompletion is occurring."
152 "Keymap used by `icomplete-mode' in the minibuffer.") 152 "Keymap used by `icomplete-mode' in the minibuffer.")
153 153
154(defun icomplete-force-complete-and-exit () 154(defun icomplete-force-complete-and-exit ()
155 "Complete the minibuffer and exit. 155 "Complete the minibuffer with the longest possible match and exit.
156Use the first of the matches if there are any displayed, and use 156Use the first of the matches if there are any displayed, and use
157the default otherwise." 157the default otherwise."
158 (interactive) 158 (interactive)
159 (if (or (and (not minibuffer-default) icomplete-show-matches-on-no-input) 159 ;; This function is tricky. The mandate is to "force", meaning we
160 (> (icomplete--field-end) (icomplete--field-beg))) 160 ;; should take the first possible valid completion for the input.
161 ;; However, if there is no input and we can prove that that
162 ;; coincides with the default, it is much faster to just call
163 ;; `minibuffer-complete-and-exit'. Otherwise, we have to call
164 ;; `minibuffer-force-complete-and-exit', which needs the full
165 ;; completion set and is potentially slow and blocking. Do the
166 ;; latter if:
167 (if (or
168 ;; there's some input, meaning the default in off the table by
169 ;; definition; OR
170 (> (icomplete--field-end) (icomplete--field-beg))
171 ;; there's no input, but there's also no minibuffer default
172 ;; (and the user really wants to see completions on no input,
173 ;; meaning he expects a "force" to be at least attempted); OR
174 (and (not minibuffer-default)
175 icomplete-show-matches-on-no-input)
176 ;; there's no input but the full completion set has been
177 ;; calculated, This causes the first cached completion to
178 ;; be taken (i.e. the one that the user sees highlighted)
179 completion-all-sorted-completions)
161 (minibuffer-force-complete-and-exit) 180 (minibuffer-force-complete-and-exit)
181 ;; Otherwise take the faster route...
162 (minibuffer-complete-and-exit))) 182 (minibuffer-complete-and-exit)))
163 183
164(defun icomplete-force-complete () 184(defun icomplete-force-complete ()