Subject: bug#47699: [PATCH] Improve completion-list-mode-map

From: Gregory Heytings <[email-masked]>
Date: Tue, 25 May 2021 08:34:13 +0000

>> Juri said recently that he uses some of the keys in M-g in the 
>> minibuffer, so I changed my mind, and I now think that it would be 
>> better to use 'M-g M-c' for this, which is unused, and does not hide 
>> the complete M-g map. Updated patch attached.  WDYT?
>
> Sure, `M-g M-c' is fine by me.  But could you send a new patch against 
> the current tree?  The previous version of the patch has already been 
> applied and pushed.
>

Hmmm...  Why did you remove "read-expression-switch-to-completions" from 
the patch?  I know that you can, in vanilla Emacs, achieve the same effect 
with TAB TAB C-- C-x o, which is I think too complicated.  Patch attached, 
against the current trunk.

From a5f1e8a16df0d4fc8616c2b77830f0646ecf79d1 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Tue, 25 May 2021 08:20:26 +0000
Subject: [PATCH] Further improvements to completion-list-mode-map

* lisp/simple.el (completion-list-mode-map): Change the M-g key to M-g M-c.
(read-expression-map): Bind M-g M-c to read-expression-switch-to-completions.
(read-expression-switch-to-completions): New function.

* lisp/minibuffer.el (minibuffer-local-completion-map): Change the M-g key to
M-g M-c.

* doc/emacs/mini.texi (Completion Commands): Mention the change, and mention
the 'n' and 'p' keys bound to 'next-completion' and 'previous-completion'.
---
 doc/emacs/mini.texi | 6 ++++--
 etc/NEWS            | 4 ++--
 lisp/minibuffer.el  | 2 +-
 lisp/simple.el      | 9 ++++++++-
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi
index 564e576300..2fdb1e7072 100644
--- a/doc/emacs/mini.texi
+++ b/doc/emacs/mini.texi
@@ -375,8 +375,8 @@ Completion Commands
 Typing @kbd{M-v}, while in the minibuffer, selects the window showing
 the completion list (@code{switch-to-completions}).  This paves the
 way for using the commands below.  @key{PageUp}, @key{prior} and
-@kbd{M-g} does the same.  You can also select the window in other ways
-(@pxref{Windows}).
+@kbd{M-g M-c} does the same.  You can also select the window in other
+ways (@pxref{Windows}).
 
 @findex choose-completion
 @item @key{RET}
@@ -388,12 +388,14 @@ Completion Commands
 @findex next-completion
 @item @key{TAB}
 @item @key{RIGHT}
+@item @key{n}
 While in the completion list buffer, these keys move point to the
 following completion alternative (@code{next-completion}).
 
 @findex previous-completion
 @item @key{S-TAB}
 @item @key{LEFT}
+@item @key{p}
 While in the completion list buffer, these keys move point to the
 previous completion alternative (@code{previous-completion}).
 
diff --git a/etc/NEWS b/etc/NEWS
index d163c18871..1541b74a3b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -444,8 +444,8 @@ major mode.
 
 ** Completion List Mode
 New key bindings have been added: 'n' and 'p' to navigate completions,
-and 'M-g' to switch to the minibuffer, and you can also switch back
-to the completion list buffer with 'M-g'.
+and 'M-g M-c' to switch to the minibuffer, and you can also switch back
+to the completion list buffer with 'M-g M-c'.
 
 ** Benchmark
 *** New function 'benchmark-call' to measure the execution time of a function.
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 36fb8e72c1..ec21b7b93b 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2603,7 +2603,7 @@ minibuffer-local-completion-map
     (define-key map "?" 'minibuffer-completion-help)
     (define-key map [prior] 'switch-to-completions)
     (define-key map "\M-v"  'switch-to-completions)
-    (define-key map "\M-g"  'switch-to-completions)
+    (define-key map "\M-g\M-c"  'switch-to-completions)
     map)
   "Local keymap for minibuffer input with completion.")
 
diff --git a/lisp/simple.el b/lisp/simple.el
index b3470ac7b0..8849919360 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1661,6 +1661,7 @@ read-expression-map
     (define-key m "\t" 'completion-at-point)
     (define-key m "\r" 'read--expression-try-read)
     (define-key m "\n" 'read--expression-try-read)
+    (define-key m "\M-g\M-c" 'read-expression-switch-to-completions)
     (set-keymap-parent m minibuffer-local-map)
     m))
 
@@ -8848,7 +8849,7 @@ completion-list-mode-map
     (define-key map "z" 'kill-current-buffer)
     (define-key map "n" 'next-completion)
     (define-key map "p" 'previous-completion)
-    (define-key map "\M-g" 'switch-to-minibuffer)
+    (define-key map "\M-g\M-c" 'switch-to-minibuffer)
     map)
   "Local map for completion list buffers.")
 
@@ -9138,6 +9139,12 @@ switch-to-completions
       (when (bobp)
 	(next-completion 1)))))
 
+(defun read-expression-switch-to-completions ()
+  "Select the completion list window while reading an expression."
+  (interactive)
+  (completion-help-at-point)
+  (switch-to-completions))
+
 (defun switch-to-minibuffer ()
   "Select the minibuffer window."
   (interactive)
-- 
2.30.2