]> git.eshelyaron.com Git - emacs.git/commitdiff
; (minibuffer-force-complete-and-exit): Simplify, improve docs.
authorEshel Yaron <me@eshelyaron.com>
Thu, 25 Jan 2024 06:42:54 +0000 (07:42 +0100)
committerEshel Yaron <me@eshelyaron.com>
Thu, 25 Jan 2024 06:42:54 +0000 (07:42 +0100)
lisp/minibuffer.el

index b6febca4d6a17a5f467b422a3cf995d36c4dd436..9f3c74b8efb328f3a458eb3be09fd1ca3b82d9b5 100644 (file)
@@ -1929,24 +1929,28 @@ include as `display-sort-function' in completion metadata."
            start end (nconc all base-size))))))
 
 (defun minibuffer-force-complete-and-exit ()
-  "Complete the minibuffer with first of the matches and exit."
-  (interactive)
-  ;; If `completion-cycling' is t, then surely a
-  ;; `minibuffer-force-complete' has already executed.  This is not
-  ;; just for speed: the extra rotation caused by the second
-  ;; unnecessary call would mess up the final result value
-  ;; (bug#34116).
-  (unless completion-cycling
-    (minibuffer-force-complete nil nil 'dont-cycle))
-  (completion--complete-and-exit
-   (minibuffer--completion-prompt-end) (point-max) #'exit-minibuffer
-   ;; If the previous completion completed to an element which fails
-   ;; test-completion, then we shouldn't exit, but that should be rare.
-   (lambda ()
-     (if minibuffer--require-match
-         (completion--message "Incomplete")
-       ;; If a match is not required, exit after all.
-       (exit-minibuffer)))))
+  "Exit the minibuffer with the first matching completion.
+
+If the current input does not match any completion candidate,
+report that and do nothing else.
+\\<minibuffer-local-completion-map>
+When there are multiple matching completions, this command
+chooses the first one according to the same sorting order that
+you use for cycling.  You can think of this command as a quick
+way to cycle to the next completion and exit immediately: use it
+instead of \\[minibuffer-cycle-completion] followed by \
+\\[exit-minibuffer] when you know you want the first
+completion even before cycling to it."
+  (interactive "" minibuffer-mode)
+  (if-let ((beg-end (minibuffer--completion-boundaries))
+           (beg (car beg-end)) (end (cdr beg-end))
+           (all (completion-all-sorted-completions beg end)))
+      (progn
+        (completion--replace beg end (car all))
+        (completion--done (buffer-substring-no-properties beg (point))
+                          'finished)
+        (exit-minibuffer))
+    (completion--fail)))
 
 (defun completion-switch-cycling-direction ()
   "Switch completion cycling from forward to backward and vice versa."