From 2691c1c7defed85efb65054c082d65151c2373f6 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 25 Jan 2024 07:42:54 +0100 Subject: [PATCH] ; (minibuffer-force-complete-and-exit): Simplify, improve docs. --- lisp/minibuffer.el | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index b6febca4d6a..9f3c74b8efb 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -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. +\\ +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." -- 2.39.5