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

From: Gregory Heytings <[email-masked]>
Date: Sun, 11 Apr 2021 18:30:03 +0000

>
> LGTM, thanks.  Did you test this with minibuffer-only frames?
>

Thanks.  Here is the updated patch.  I tested it with minibuffer-only 
frames, and it seems to work.

Are you sure that it's okay to rebind M-c in 
minibuffer-local-completion-map?  It's a good mnemonic for "completion", 
but it hides the capitalize-word binding, that users might possibly want 
to use there (I don't, it's only when thinking about this patch that I 
realized this).

Another option would be M-g, which would not hide anything that is 
possibly useful in the minibuffer, and is still a mnemonic of "goto".

From 2af79f204cbb30f36722b912e1ac0aff060283bd Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Sun, 11 Apr 2021 18:10:29 +0000
Subject: [PATCH] Improve completion-list-mode-map

* lisp/simple.el (completion-list-mode-map): Make special-mode-map its
parent, unbind the 'g' revert key, add the 'n' and 'p' keys for
next-completion and previous-completion, and the M-c key for
switch-to-minibuffer.
(switch-to-minibuffer): New function

* lisp/minibuffer.el (minibuffer-local-completion-map): Add the M-c key
for switch-to-completion.
---
 lisp/minibuffer.el |  1 +
 lisp/simple.el     | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 5f594679ca..d18a0f7461 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2413,6 +2413,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-c"  'switch-to-completions)
     map)
   "Local keymap for minibuffer input with completion.")
 
diff --git a/lisp/simple.el b/lisp/simple.el
index 999755a642..232177204d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8767,6 +8767,8 @@ set-variable
 
 (defvar completion-list-mode-map
   (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map special-mode-map)
+    (define-key map "g" nil) ;; There's nothing to revert from.
     (define-key map [mouse-2] 'choose-completion)
     (define-key map [follow-link] 'mouse-face)
     (define-key map [down-mouse-2] nil)
@@ -8778,6 +8780,9 @@ completion-list-mode-map
     (define-key map [backtab] 'previous-completion)
     (define-key map "q" 'quit-window)
     (define-key map "z" 'kill-current-buffer)
+    (define-key map "n" 'next-completion)
+    (define-key map "p" 'previous-completion)
+    (define-key map "\M-c" 'switch-to-minibuffer)
     map)
   "Local map for completion list buffers.")
 
@@ -9067,6 +9072,12 @@ switch-to-completions
       ;; FIXME: Perhaps this should be done in `minibuffer-completion-help'.
       (when (bobp)
 	(next-completion 1)))))
+
+(defun switch-to-minibuffer ()
+  "Select the minibuffer window."
+  (interactive)
+  (when (active-minibuffer-window)
+    (select-window (active-minibuffer-window))))
 
 ;;; Support keyboard commands to turn on various modifiers.
 
-- 
2.30.2