Subject: bug#76341: 31.0.50; Confusing prompt after C-q

From: Eli Zaretskii <[email-masked]>
Date: Sat, 22 Feb 2025 14:25:14 +0200

> Date: Sun, 16 Feb 2025 12:58:25 -0300
> From: Mauro Aranda <[email-masked]>
> 
> After emacs -Q:
> C-q
> 
> Wait for a little while and read:
> C-q- (<nil> for help)
> 
> I think that if there's no key to press for help, that message shouldn't
> show up.

I agree.  But in this case, there _is_ a help key, it just isn't C-h.
Please try the patch below.

Stefan, do you see a cleaner fix?  I didn't want to test the key
itself for being [nil], since perhaps it could be [foo bar nil] or
somesuch?  IOW, what possible forms of key could cause key-description
produce "<nil>" for its argument?

diff --git a/lisp/help.el b/lisp/help.el
index 91e0366..6c643e6 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -2200,18 +2200,20 @@ help--append-keystrokes-help
                                    (current-active-maps t)))))
     (catch 'res
       (dolist (val help-event-list)
-        (let ((key (vector (if (eql val 'help)
-                               help-char
-                             val))))
-          (unless (seq-find (lambda (map) (and (keymapp map) (lookup-key map key)))
-                            bindings)
+        (let* ((key (vector (if (eql val 'help)
+                                help-char
+                              val)))
+               (key-desc (key-description key)))
+          (unless (or (seq-find
+                       (lambda (map) (and (keymapp map) (lookup-key map key)))
+                       bindings)
+                      ;; Reject unhelpful "keys".
+                      (equal key-desc "<nil>"))
             (throw 'res
                    (concat
                     str
                     (substitute-command-keys
-                     (format
-                      " (\\`%s' for help)"
-                      (key-description key))))))))
+                     (format " (\\`%s' for help)" key-desc)))))))
       str)))