From: Eli Zaretskii Date: Wed, 8 Dec 2021 14:22:10 +0000 (+0200) Subject: Fix mode-line display in Calendar mode X-Git-Tag: emacs-28.0.91~70 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=538fc1d0e0;p=emacs.git Fix mode-line display in Calendar mode * lisp/help.el (substitute-command-keys): New optional argument NO-FACE, to avoid putting the 'help-key-binding' face on the key bindings. * lisp/calendar/calendar.el (calendar-mode-line-entry): Call 'substitute-command-keys' with the new optional argument non-nil. (Bug#52366) * doc/lispref/help.texi (Keys in Documentation): Document the new optional argument of 'substitute-command-keys'. * etc/NEWS: Announce the addition of a new argument to 'substitute-command-keys'. --- diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi index a788852de75..a48571838cc 100644 --- a/doc/lispref/help.texi +++ b/doc/lispref/help.texi @@ -372,11 +372,15 @@ quotes. You can customize it freely according to your personal preference. @end defopt -@defun substitute-command-keys string +@defun substitute-command-keys string &optional no-face +@vindex help-key-binding@r{ (face)} This function scans @var{string} for the above special sequences and replaces them by what they stand for, returning the result as a string. This permits display of documentation that refers accurately to the -user's own customized key bindings. +user's own customized key bindings. By default, the key bindings are +given a special face @code{help-key-binding}, but if the optional +argument @var{no-face} is non-@code{nil}, the function doesn't add +this face to the produced string. @cindex advertised binding If a command has multiple bindings, this function normally uses the diff --git a/etc/NEWS b/etc/NEWS index 8e38c3690c1..734de07582c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -635,7 +635,9 @@ This works like 'C-u M-x apropos-command' but is more discoverable. *** Keybindings in 'help-mode' use the new 'help-key-binding' face. This face is added by 'substitute-command-keys' to any "\[command]" substitution. The return value of that function should consequently -be assumed to be a propertized string. +be assumed to be a propertized string. To prevent the function from +adding the 'help-key-binding' face, call 'substitute-command-keys' +with the new optional argument NO-FACE non-nil. Note that the new face will also be used in tooltips. When using the GTK toolkit, this is only true if 'x-gtk-use-system-tooltips' is t. diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index ebce2ae3ddb..e06239a5c87 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el @@ -1723,7 +1723,8 @@ COMMAND is a command to run, ECHO is the help-echo text, KEY is COMMAND's keybinding, STRING describes the binding." (propertize (or key (substitute-command-keys - (format "\\\\[%s] %s" command string))) + (format "\\\\[%s] %s" command string) + 'hands-off-my-face)) 'help-echo (format "mouse-1: %s" echo) 'mouse-face 'mode-line-highlight 'keymap (make-mode-line-mouse-map 'mouse-1 command))) diff --git a/lisp/help.el b/lisp/help.el index 47faf44b37f..941d4cfab12 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -1060,11 +1060,12 @@ is currently activated with completion." result)) -(defun substitute-command-keys (string) +(defun substitute-command-keys (string &optional no-face) "Substitute key descriptions for command names in STRING. Each substring of the form \\\\=[COMMAND] is replaced by either a keystroke sequence that invokes COMMAND, or \"M-x COMMAND\" if COMMAND -is not on any keys. Keybindings will use the face `help-key-binding'. +is not on any keys. Keybindings will use the face `help-key-binding', +unless the optional argument NO-FACE is non-nil. Each substring of the form \\\\={MAPVAR} is replaced by a summary of the value of MAPVAR as a keymap. This summary is similar to the one @@ -1141,13 +1142,17 @@ Otherwise, return a new string." (let ((op (point))) (insert "M-x ") (goto-char (+ end-point 3)) - (add-text-properties op (point) - '( face help-key-binding - font-lock-face help-key-binding)) + (or no-face + (add-text-properties + op (point) + '( face help-key-binding + font-lock-face help-key-binding))) (delete-char 1)) ;; Function is on a key. (delete-char (- end-point (point))) - (insert (help--key-description-fontified key))))) + (insert (if no-face + (key-description key) + (help--key-description-fontified key)))))) ;; 1D. \{foo} is replaced with a summary of the keymap ;; (symbol-value foo). ;; \ just sets the keymap used for \[cmd].