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."