]> git.eshelyaron.com Git - emacs.git/commitdiff
Enable keys M-down, M-up, M-RET for in-buffer completion
authorJuri Linkov <juri@linkov.net>
Sun, 22 May 2022 17:55:35 +0000 (20:55 +0300)
committerJuri Linkov <juri@linkov.net>
Sun, 22 May 2022 17:55:35 +0000 (20:55 +0300)
* lisp/minibuffer.el (completion-in-region-mode-map): Add keybindings M-<up>
for minibuffer-previous-completion, M-<down> for minibuffer-next-completion,
M-RET for minibuffer-choose-completion.
(completion-in-region-mode): Set buffer-local
'minibuffer-completion-auto-choose' to nil.
(minibuffer-next-completion): Get the value of
'minibuffer-completion-auto-choose' from the minibuffer.
(minibuffer-previous-completion): Simplify by delegating to
'minibuffer-next-completion'.

* doc/emacs/programs.texi (Symbol Completion): Add description of keys
M-down, M-up, M-RET.

https://lists.gnu.org/archive/html/emacs-devel/2022-05/msg00916.html

doc/emacs/programs.texi
etc/NEWS
lisp/minibuffer.el

index 2720bdda6f77a729059e9460240409a1e18090ee..795aabee743ff17098fc637ad07816026ffd5913 100644 (file)
@@ -1439,9 +1439,13 @@ performs completion using the function, variable, or property names
 defined in the current Emacs session.
 
   In all other respects, in-buffer symbol completion behaves like
-minibuffer completion.  For instance, if Emacs cannot complete to a
-unique symbol, it displays a list of completion alternatives in
-another window.  @xref{Completion}.
+minibuffer completion.  For instance, if Emacs cannot complete to
+a unique symbol, it displays a list of completion alternatives in
+another window.  Then you can use the keys @kbd{M-@key{DOWN}} and
+@kbd{M-@key{UP}} to navigate through the completions displayed
+in the completions buffer without leaving the original buffer,
+and the key @kbd{M-@key{RET}} to insert the currently highlighted
+completion to the buffer.  @xref{Completion}.
 
   In Text mode and related modes, @kbd{M-@key{TAB}} completes words
 based on the spell-checker's dictionary.  @xref{Spelling}.
index 0295fbf1f12a4d46b8de8d1ffb5b18210f097d1d..b972163b68e8461a24427fe236ad4cac87383030 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -977,7 +977,9 @@ a completion candidate to the minibuffer, then 'M-RET' can be used
 to choose the currently active candidate from the "*Completions*"
 buffer and exit the minibuffer.  With a prefix argument, 'C-u M-RET'
 inserts the currently active candidate to the minibuffer, but doesn't
-exit the minibuffer.
+exit the minibuffer.  These keys are also available for in-buffer
+completion, but they don't insert candidates automatically, you need
+to type 'M-RET' to insert the selected candidate to the buffer.
 
 +++
 *** The "*Completions*" buffer can now be automatically selected.
index fb473cf71b0ea49ad8be0f4bb25f14ca18ed6483..ee00f96b520d413b52dc7543b1e8c54c58482ff8 100644 (file)
@@ -2543,7 +2543,10 @@ Also respects the obsolete wrapper hook `completion-in-region-functions'.
   ;; FIXME: Only works if completion-in-region-mode was activated via
   ;; completion-at-point called directly.
   "M-?" #'completion-help-at-point
-  "TAB" #'completion-at-point)
+  "TAB" #'completion-at-point
+  "M-<up>"   #'minibuffer-previous-completion
+  "M-<down>" #'minibuffer-next-completion
+  "M-RET"    #'minibuffer-choose-completion)
 
 ;; It is difficult to know when to exit completion-in-region-mode (i.e. hide
 ;; the *Completions*).  Here's how previous packages did it:
@@ -2590,6 +2593,7 @@ Also respects the obsolete wrapper hook `completion-in-region-functions'.
     (cl-assert completion-in-region-mode-predicate)
     (setq completion-in-region-mode--predicate
          completion-in-region-mode-predicate)
+    (setq-local minibuffer-completion-auto-choose nil)
     (add-hook 'post-command-hook #'completion-in-region--postch)
     (push `(completion-in-region-mode . ,completion-in-region-mode-map)
           minor-mode-overriding-map-alist)))
@@ -4369,30 +4373,25 @@ selected by these commands to the minibuffer."
   :version "29.1")
 
 (defun minibuffer-next-completion (&optional n)
-  "Run `next-completion' from the minibuffer in its completions window.
+  "Move to the next item in its completions window from the minibuffer.
 When `minibuffer-completion-auto-choose' is non-nil, then also
 insert the selected completion to the minibuffer."
   (interactive "p")
-  (with-minibuffer-completions-window
-    (when completions-highlight-face
-      (setq-local cursor-face-highlight-nonselected-window t))
-    (next-completion (or n 1))
-    (when minibuffer-completion-auto-choose
-      (let ((completion-use-base-affixes t))
-        (choose-completion nil t t)))))
+  (let ((auto-choose minibuffer-completion-auto-choose))
+    (with-minibuffer-completions-window
+      (when completions-highlight-face
+        (setq-local cursor-face-highlight-nonselected-window t))
+      (next-completion (or n 1))
+      (when auto-choose
+        (let ((completion-use-base-affixes t))
+          (choose-completion nil t t))))))
 
 (defun minibuffer-previous-completion (&optional n)
-  "Run `previous-completion' from the minibuffer in its completions window.
+  "Move to the previous item in its completions window from the minibuffer.
 When `minibuffer-completion-auto-choose' is non-nil, then also
 insert the selected completion to the minibuffer."
   (interactive "p")
-  (with-minibuffer-completions-window
-    (when completions-highlight-face
-      (setq-local cursor-face-highlight-nonselected-window t))
-    (previous-completion (or n 1))
-    (when minibuffer-completion-auto-choose
-      (let ((completion-use-base-affixes t))
-        (choose-completion nil t t)))))
+  (minibuffer-next-completion (- (or n 1))))
 
 (defun minibuffer-choose-completion (&optional no-exit no-quit)
   "Run `choose-completion' from the minibuffer in its completions window.