"M-RET" #'minibuffer-choose-completion
"M-j" #'minibuffer-force-complete-and-exit
"C-x C-v" #'minibuffer-sort-completions
+ "C-x C-<" #'minibuffer-first-completion
+ "C-x C->" #'minibuffer-last-completion
"C-x n" 'minibuffer-narrow-completions-map
"C-x /" #'minibuffer-set-completion-styles
"C-x ~" #'minibuffer-toggle-exceptional-candidates
:type 'boolean
:version "29.1")
+(defmacro minibuffer-completions-motion (&rest body)
+ "Execute BODY in the minibuffer completions window.
+When `minibuffer-completion-auto-choose' is non-nil in the minibuffer,
+then also insert the completion candidate at point to the minibuffer
+after executing BODY."
+ (declare (indent 0) (debug t))
+ `(let ((auto-choose minibuffer-completion-auto-choose))
+ (with-minibuffer-completions-window
+ (when completions-highlight-face
+ (setq-local cursor-face-highlight-nonselected-window t))
+ ,@body
+ (when auto-choose
+ (let ((completion-use-base-affixes t))
+ (choose-completion nil t t))))))
+
+(defun minibuffer-first-completion ()
+ "Move to the first item in the completions window from the minibuffer.
+When `minibuffer-completion-auto-choose' is non-nil, then also
+insert the selected completion candidate to the minibuffer."
+ (interactive nil minibuffer-mode)
+ (minibuffer-completions-motion (first-completion)))
+
+(defun minibuffer-last-completion ()
+ "Move to the last item in the completions window from the minibuffer.
+When `minibuffer-completion-auto-choose' is non-nil, then also
+insert the selected completion candidate to the minibuffer."
+ (interactive nil minibuffer-mode)
+ (minibuffer-completions-motion (last-completion)))
+
(defun minibuffer-next-completion (&optional n vertical)
- "Move to the next item in its completions window from the minibuffer.
+ "Move to the next item in the completions window from the minibuffer.
When the optional argument VERTICAL is non-nil, move vertically
to the next item on the next line using `next-line-completion'.
Otherwise, move to the next item horizontally using `next-completion'.
When `minibuffer-completion-auto-choose' is non-nil, then also
insert the selected completion candidate to the minibuffer."
(interactive "p")
- (let ((auto-choose minibuffer-completion-auto-choose))
- (with-minibuffer-completions-window
- (when completions-highlight-face
- (setq-local cursor-face-highlight-nonselected-window t))
- (if vertical
- (next-line-completion (or n 1))
- (next-completion (or n 1)))
- (when auto-choose
- (let ((completion-use-base-affixes t))
- (choose-completion nil t t))))))
+ (minibuffer-completions-motion
+ (funcall (if vertical #'next-line-completion #'next-completion) (or n 1))))
(defun minibuffer-previous-completion (&optional n)
- "Move to the previous item in its completions window from the minibuffer.
+ "Move to the previous item in the completions window from the minibuffer.
When `minibuffer-completion-auto-choose' is non-nil, then also
insert the selected completion candidate to the minibuffer."
(interactive "p")
(minibuffer-previous-line-or-call #'minibuffer-previous-completion arg))
(defun minibuffer-choose-completion (&optional no-exit no-quit)
- "Run `choose-completion' from the minibuffer in its completions window.
+ "Run `choose-completion' from the minibuffer in the completions window.
With prefix argument NO-EXIT, insert the completion candidate at point to
the minibuffer, but don't exit the minibuffer. When the prefix argument
is not provided, then whether to exit the minibuffer depends on the value