Subject: Re: bug#54173: 28.0.91; Training wheels for query-replace

From: Augusto Stoffel <[email-masked]>
Date: Sun, 27 Feb 2022 11:17:08 +0100

On Sun, 27 Feb 2022 at 11:24, Eli Zaretskii <[email-masked]> wrote:

>> From: Augusto Stoffel <[email-masked]>
>> Cc: [email-masked]
>> Date: Sun, 27 Feb 2022 09:51:42 +0100
>> 
>> > But since '?' produces a more detailed help, and that help text stays
>> > on display thereafter, do we really need one more variant?  Maybe the
>> > default message could be expanded instead (but not to such a long
>> > text, which would resize the mini-window in many cases)?
>> 
>> I think ‘y’ and ‘n’ are intuitive enough that they don't need a
>> reminder.  But mentioning the more uncommon ones (‘.’ and so on) without
>> talking about ‘y’ and ‘n’ is weird.
>
> How about the below?
>
>   (‘y’/‘n’, ‘.’ replace & exit, ‘^’ back up, ‘?’ help)

I find this better than the status quo.  I've attached the patch.

>From 290ad346d793d42c654adbde87089b22f4aa0fa5 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Sat, 26 Feb 2022 23:08:26 +0100
Subject: [PATCH] Expand help string in 'perform-replace' prompt

* lisp/replace.el (query-replace-prompt-help): New variable, help
string shown next to 'perform-replace' prompt.
(query-replace-map): Reorder entries so that 'substitute-command-keys'
does the right job.
(perform-replace): Use 'query-replace-prompt-help.
---
 lisp/replace.el | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/lisp/replace.el b/lisp/replace.el
index 06be597855..49cf652ddc 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2445,18 +2445,22 @@ query-replace-help
 in the current buffer."
   "Help message while in `query-replace'.")
 
+(defvar query-replace-prompt-help
+  "\\<query-replace-map>(\\[act]/\\[skip], \\[act-and-exit] replace & exit, \\[backup] back up, \\[help] help)"
+  "Help string to show next to the `query-replace' prompt.")
+
 (defvar query-replace-map
   (let ((map (make-sparse-keymap)))
     (define-key map " " 'act)
     (define-key map "\d" 'skip)
     (define-key map [delete] 'skip)
     (define-key map [backspace] 'skip)
-    (define-key map "y" 'act)
-    (define-key map "n" 'skip)
     (define-key map "Y" 'act)
+    (define-key map "y" 'act)
     (define-key map "N" 'skip)
-    (define-key map "e" 'edit-replacement)
+    (define-key map "n" 'skip)
     (define-key map "E" 'edit-replacement)
+    (define-key map "e" 'edit-replacement)
     (define-key map "," 'act-and-show)
     (define-key map "q" 'exit)
     (define-key map "\r" 'exit)
@@ -2840,20 +2844,20 @@ perform-replace
          (match-again t)
 
          (message
-          (if query-flag
-              (apply #'propertize
-                     (concat "Query replacing "
-                             (if backward "backward " "")
-                             (if delimited-flag
-                                 (or (and (symbolp delimited-flag)
-                                          (get delimited-flag
-                                               'isearch-message-prefix))
-                                     "word ") "")
-                             (if regexp-flag "regexp " "")
-                             "%s with %s: "
-                             (substitute-command-keys
-                              "(\\<query-replace-map>\\[help] for help) "))
-                     minibuffer-prompt-properties))))
+          (when query-flag
+            (concat
+             (apply #'propertize
+                    (concat "Query replacing "
+                            (if backward "backward " "")
+                            (if delimited-flag
+                                (or (and (symbolp delimited-flag)
+                                         (get delimited-flag
+                                              'isearch-message-prefix))
+                                    "word ") "")
+                            (if regexp-flag "regexp " "")
+                            "%s with %s: ")
+                    minibuffer-prompt-properties)
+             (substitute-command-keys query-replace-prompt-help)))))
 
     ;; Unless a single contiguous chunk is selected, operate on multiple chunks.
     (when region-noncontiguous-p
-- 
2.35.1

> An alternative is to have C-h and F1 temporarily show a longer line
> with more commands.
>
>> One idea would be to choose between the short and long messages based on
>> the size of the miniwindow as well as the length regexp and replacement
>> text.
>
> That could also be a possibility.

Between this and your suggestion, I'm undecided what's better.  Perhaps
this is more complicated than necessary.