Subject: bug#37785: closed (Re: bug#37785: [PATCH] Add a way to disable substitution of command keys in help strings)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 21 Oct 2019 01:54:01 +0000

Your bug report

#37785: [PATCH] Add a way to disable substitution of command keys in help strings

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
37785: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=37785
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#37785: [PATCH] Add a way to disable substitution of command keys in help strings
From: Clément Pit-Claudel <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sun, 20 Oct 2019 21:53:49 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

On 2019-10-20 08:08, Eli Zaretskii wrote:
> LGTM.  Please feel free to install, after fixing this one nit:

Done! Thanks again for your help :)

Subject: [PATCH] Add a way to disable substitution of command keys in help strings
From: Clément Pit-Claudel <[email-masked]>
To: bug-gnu-emacs <[email-masked]>
Date: Wed, 16 Oct 2019 21:41:27 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi all,

On 2019-10-05 04:13, Eli Zaretskii wrote (on emacs-devel):
> I guess we need to add some feature to control whether help-echo gets
> run through substitute-command-keys, or add an alternative to
> help-echo that works exactly like it, but without substitutions.
> Patches welcome.
[…]
> I'd prefer a property like help-echo-inhibit-substitution that is
> non-nil, to inhibit the call to substitute-command-keys.  A value of
> nil is easy to confuse with no property at all.

Here is a first cut at a patch implementing this feature.  I hope this tracker is the right place to post it.  I'm also not quite sure I got the Changelog format right.

Cheers,
Clément.
>From 8092b19d819182c91e6066d24f243dc7d7d8641e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit-Claudel?= <[email-masked]>
Date: Wed, 16 Oct 2019 21:28:47 -0400
Subject: [PATCH] Add a way to disable substitution of command keys in help
 strings

* src/keyboard.c (show_help_substitute_command_keys): New function
(show_help_echo, parse_menu_item): Use it
(syms_of_keyboard): Define Qshow_help_inhibit_substitution

* doc/lispref/text.texi (Special Properties), etc/NEWS: Document
the effect of 'show-help-inhibit-substitution'
---
 doc/lispref/text.texi |  8 +++++---
 etc/NEWS              |  5 +++++
 src/keyboard.c        | 23 ++++++++++++++++++++---
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index d7b04d2934..4f7e480443 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -3736,9 +3736,11 @@ Special Properties
 @pxref{Extended Menu Items}), or tool bar help strings (@pxref{Tool
 Bar}).  The specified function is called with one argument, the help
 string to display, which is passed through
-@code{substitute-command-keys} before being given to the function; see
-@ref{Keys in Documentation}.  Tooltip mode (@pxref{Tooltips,,, emacs,
-The GNU Emacs Manual}) provides an example.
+@code{substitute-command-keys} before being given to the function,
+unless the help string has a non-nil
+@code{show-help-inhibit-substitution} property on its first character;
+see @ref{Keys in Documentation}.  Tooltip mode (@pxref{Tooltips,,,
+emacs, The GNU Emacs Manual}) provides an example.
 @end defvar
 
 @defvar face-filters-always-match
diff --git a/etc/NEWS b/etc/NEWS
index 4b693aaaa1..6089515daf 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -439,6 +439,11 @@ RGB triplets with a single hexadecimal digit per component.
 ---
 ** The toolbar now shows the equivalent key binding in its tooltips.
 
++++
+** Adding a non-nil 'show-help-inhibit-substitution' text property on
+the first character of a help string disables conversion via
+'substitute-command-keys'.
+
 
 * Editing Changes in Emacs 27.1
 
diff --git a/src/keyboard.c b/src/keyboard.c
index a16d13cc7b..864c9789c5 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -2019,6 +2019,22 @@ make_ctrl_char (int c)
   return c;
 }
 
+/* Substitute key descriptions and quotes in HELP, unless its first
+   character has a non-nil show-help-inhibit-substitution property. */
+
+static Lisp_Object
+show_help_substitute_command_keys (Lisp_Object help)
+{
+  if (STRINGP (help) &&
+      SCHARS (help) > 0 &&
+      !NILP (Fget_text_property (make_fixnum(0),
+                                 Qshow_help_inhibit_substitution,
+                                 help)))
+    return help;
+
+  return Fsubstitute_command_keys(help);
+}
+
 /* Display the help-echo property of the character after the mouse pointer.
    Either show it in the echo area, or call show-help-function to display
    it by other means (maybe in a tooltip).
@@ -2078,7 +2094,7 @@ show_help_echo (Lisp_Object help, Lisp_Object window, Lisp_Object object,
   if (STRINGP (help) || NILP (help))
     {
       if (!NILP (Vshow_help_function))
-	call1 (Vshow_help_function, Fsubstitute_command_keys (help));
+	call1 (Vshow_help_function, show_help_substitute_command_keys (help));
       help_echo_showing_p = STRINGP (help);
     }
 }
@@ -7652,7 +7668,7 @@ parse_menu_item (Lisp_Object item, int inmenubar)
       if (CONSP (item) && STRINGP (XCAR (item)))
 	{
 	  ASET (item_properties, ITEM_PROPERTY_HELP,
-		Fsubstitute_command_keys (XCAR (item)));
+		show_help_substitute_command_keys (XCAR (item)));
 	  start = item;
 	  item = XCDR (item);
 	}
@@ -7716,7 +7732,7 @@ parse_menu_item (Lisp_Object item, int inmenubar)
 		{
 		  Lisp_Object help = XCAR (item);
 		  if (STRINGP (help))
-		    help = Fsubstitute_command_keys (help);
+		    help = show_help_substitute_command_keys (help);
 		  ASET (item_properties, ITEM_PROPERTY_HELP, help);
 		}
 	      else if (EQ (tem, QCfilter))
@@ -11052,6 +11068,7 @@ syms_of_keyboard (void)
   /* Tool-bars.  */
   DEFSYM (QCimage, ":image");
   DEFSYM (Qhelp_echo, "help-echo");
+  DEFSYM (Qshow_help_inhibit_substitution, "show-help-inhibit-substitution");
   DEFSYM (QCrtl, ":rtl");
 
   staticpro (&item_properties);
-- 
2.17.1