emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Select completions from the minibuffer


From: Juri Linkov
Subject: Re: Select completions from the minibuffer
Date: Sun, 13 Mar 2022 20:05:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> I posted a patch to bug#49931 that adds a new user option.
>> Maybe it could be enabled by default?
>
> Skimming the patch, I think that might make sense.  But perhaps push it
> disabled first, and then we can gain some experience with it, and then
> enable it by default if there's no unforeseen side effects?

Yep, this would be the best course of action.

The new variable completion-use-base-affixes will be also enabled
for the M-up/down feature.  Here is an updated patch that also requires
other two patches from bug#47417 (merged with bug#49931) and bug#48356:

diff --git a/lisp/simple.el b/lisp/simple.el
index accc119e2b..52cf54c563 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3891,6 +3891,9 @@ minibuffer-local-shell-command-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map minibuffer-local-map)
     (define-key map "\t" 'completion-at-point)
+    (define-key map (kbd "M-<up>") 'minibuffer-previous-completion)
+    (define-key map (kbd "M-<down>") 'minibuffer-next-completion)
+    (define-key map (kbd "M-RET") 'minibuffer-choose-completion)
     map)
   "Keymap used for completing shell commands in minibuffer.")
 
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 36b8d80841..5685f078ad 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2681,7 +2775,12 @@ minibuffer-local-completion-map
   "?"         #'minibuffer-completion-help
   "<prior>"   #'switch-to-completions
   "M-v"       #'switch-to-completions
-  "M-g M-c"   #'switch-to-completions)
+  "M-g M-c"   #'switch-to-completions
+  "M-S-<up>"    #'minibuffer-previous-completion
+  "M-S-<down>"  #'minibuffer-next-completion
+  "M-<up>"    #'minibuffer-choose-previous-completion
+  "M-<down>"  #'minibuffer-choose-next-completion
+  "M-RET"     #'minibuffer-choose-completion)
 
 (defvar-keymap minibuffer-local-must-match-map
   :doc "Local keymap for minibuffer input with completion, for exact match."
@@ -4271,6 +4370,52 @@ minibuffer-scroll-other-window-down
   (with-minibuffer-selected-window
     (scroll-other-window-down arg)))
 
+(defmacro with-minibuffer-completions-window (&rest body)
+  "Execute the forms in BODY from the minibuffer in its completions window.
+When used in a minibuffer window, select the window with completions,
+and execute the forms."
+  (declare (indent 0) (debug t))
+  `(let ((window (or (get-buffer-window "*Completions*" 0)
+                    ;; Make sure we have a completions window.
+                     (progn (minibuffer-completion-help)
+                            (get-buffer-window "*Completions*" 0)))))
+     (when window
+       (with-selected-window window
+         ,@body))))
+
+(defun minibuffer-previous-completion (&optional n)
+  "Run `previous-completion' from the minibuffer in its completions window."
+  (interactive "p")
+  (with-minibuffer-completions-window
+    (previous-completion n)))
+
+(defun minibuffer-next-completion (&optional n)
+  "Run `next-completion' from the minibuffer in its completions window."
+  (interactive "p")
+  (with-minibuffer-completions-window
+    (next-completion n)))
+
+(defun minibuffer-choose-previous-completion (&optional n)
+  "Run `previous-completion' from the minibuffer in its completions window.
+Also insert the selected completion to the minibuffer."
+  (interactive "p")
+  (minibuffer-previous-completion n)
+  (minibuffer-choose-completion t t))
+
+(defun minibuffer-choose-next-completion (&optional n)
+  "Run `next-completion' from the minibuffer in its completions window.
+Also insert the selected completion to the minibuffer."
+  (interactive "p")
+  (minibuffer-next-completion n)
+  (minibuffer-choose-completion t t))
+
+(defun minibuffer-choose-completion (&optional no-exit no-quit)
+  "Run `choose-completion' from the minibuffer in its completions window."
+  (interactive "p")
+  (with-minibuffer-completions-window
+    (let ((completion-use-base-affixes t))
+      (choose-completion nil no-exit no-quit))))
+
 (defcustom minibuffer-default-prompt-format " (default %s)"
   "Format string used to output \"default\" values.
 When prompting for input, there will often be a default value,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]