emacs-diffs
[Top][All Lists]
Advanced

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

master b2a5bf142f: Enable keys M-down, M-up, M-RET for in-buffer complet


From: Juri Linkov
Subject: master b2a5bf142f: Enable keys M-down, M-up, M-RET for in-buffer completion
Date: Sun, 22 May 2022 13:56:17 -0400 (EDT)

branch: master
commit b2a5bf142fb25094ff623dc93d2ce916aee3d971
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    Enable keys M-down, M-up, M-RET for in-buffer completion
    
    * 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 | 10 +++++++---
 etc/NEWS                |  4 +++-
 lisp/minibuffer.el      | 33 ++++++++++++++++-----------------
 3 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi
index 2720bdda6f..795aabee74 100644
--- a/doc/emacs/programs.texi
+++ b/doc/emacs/programs.texi
@@ -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}.
diff --git a/etc/NEWS b/etc/NEWS
index 0295fbf1f1..b972163b68 100644
--- 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.
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index fb473cf71b..ee00f96b52 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -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.



reply via email to

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