]> git.eshelyaron.com Git - emacs.git/commitdiff
New commands 'minibuffer-first/last-completion'
authorEshel Yaron <me@eshelyaron.com>
Thu, 25 Apr 2024 16:41:24 +0000 (18:41 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 25 Apr 2024 16:41:24 +0000 (18:41 +0200)
* lisp/minibuffer.el (minibuffer-completions-motion): New macro.
(minibuffer-next-completion): Use it.
(minibuffer-first-completion, minibuffer-last-completion): New commands.
(minibuffer-local-completion-map): Bind them.
(minibuffer-previous-completion, minibuffer-choose-completion): Doc fix.

lisp/minibuffer.el

index a22d73892e943fbc905bb5fe78222755ede8eccf..17b17d6849833eecf83399f891b422a44b37a386 100644 (file)
@@ -3597,6 +3597,8 @@ The completion method is determined by `completion-at-point-functions'."
   "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
@@ -5563,27 +5565,48 @@ selected by these commands to the minibuffer."
   :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")
@@ -5620,7 +5643,7 @@ insert the selected completion candidate to the minibuffer."
   (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