unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, emacs-devel@gnu.org
Subject: Re: Consistent face for keys in *Help* and `substitute-command-keys'
Date: Fri, 5 Mar 2021 10:18:25 -0600	[thread overview]
Message-ID: <CADwFkm=iPeaSD3E7meeifvi7QDAnQ9yqQbe5JHe2BiQaiSaw3g@mail.gmail.com> (raw)
In-Reply-To: <83zgzjhvdn.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1754 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> Could we just use `add-face-text-property' here, perhaps?
>>
>> It seems to do what we want:
>>
>>     (let ((foo "x") bar)
>>       (add-face-text-property 0 (length foo) 'bold nil foo)
>>       (setq bar (concat "y" foo "y"))
>>       (add-face-text-property 0 (length bar) 'italic nil bar)
>>       bar)
>>
>>     => #("yxy" 0 1 (face italic) 1 2 (face (italic bold)) 2 3 (face italic))
>
> That's because you add a property which was unspecified by the
> original face.  But in the tooltip case, the function tooltip-show
> propertizes the entire text it receives with the 'tooltip' face, so
> any face attributes in the text that are also specified by the
> 'tooltip' face will be overwritten.  So, for example, if the tooltip
> text had a :background attribute, that attribute would be overwritten
> by the background color of the 'tooltip' face.  Isn't that what you
> see?

But that just comes down to which face takes priority, right?  So if we
we would need to set the APPEND argument of `add-face-text-property' to
t.

See the attached latest version of the patch, which seems to work as
you'd expect: the `help-key-binding' face overrides any attributes in
the `tooltip' face (tested using --with-x-toolkit={no,lucid}).

The interesting part for tooltips is:

modified   lisp/tooltip.el
@@ -248,7 +248,8 @@ tooltip-show
 	    (setf (alist-get 'border-color params) fg))
 	  (when (stringp bg)
 	    (setf (alist-get 'background-color params) bg))
-	  (x-show-tip (propertize text 'face 'tooltip)
+          (add-face-text-property 0 (length text) 'tooltip t text)
+          (x-show-tip text
 		      (selected-frame)
 		      params

Unless I am missing something, I think this is what we want here.

[-- Attachment #2: 0001-Colorize-keybindings-in-help.patch --]
[-- Type: text/x-diff, Size: 32000 bytes --]

From b772b42ee39f4595cf6df21d9c0b7694771f1cb6 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Wed, 24 Feb 2021 01:18:13 +0100
Subject: [PATCH] Colorize keybindings in help

---
 etc/NEWS           |   3 +
 lisp/faces.el      |   5 +
 lisp/help-fns.el   |  21 +++--
 lisp/help-macro.el | 223 ++++++++++++++++++++++-----------------------
 lisp/help.el       | 139 +++++++++++++++-------------
 lisp/isearch.el    |   8 +-
 lisp/tooltip.el    |   3 +-
 src/keymap.c       |  27 +++++-
 8 files changed, 239 insertions(+), 190 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 3522fce03a..92705d2a7b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -911,6 +911,9 @@ skipped.
 
 ** Help
 
+---
+*** Keybindings in 'help-mode' use the new `help-key-binding' face.
+
 ---
 *** 'g' ('revert-buffer') in 'help-mode' no longer requires confirmation.
 
diff --git a/lisp/faces.el b/lisp/faces.el
index 90f11bbe3b..ffe8eccdbe 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -2815,6 +2815,11 @@ help-argument-name
   "Face to highlight argument names in *Help* buffers."
   :group 'help)
 
+(defface help-key-binding '((t :foreground "ForestGreen"))
+  "Face for keybindings in *Help* buffers."
+  :version "28.1"
+  :group 'help)
+
 (defface glyphless-char
   '((((type tty)) :inherit underline)
     (((type pc)) :inherit escape-glyph)
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 290bebf7e5..fc57ec1cca 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -466,13 +466,16 @@ help-fns--key-bindings
               ;; If lots of ordinary text characters run this command,
               ;; don't mention them one by one.
               (if (< (length non-modified-keys) 10)
-                  (princ (mapconcat #'key-description keys ", "))
+                  (with-current-buffer standard-output
+                    (insert (mapconcat #'help--key-description-fontified
+                                       keys ", ")))
                 (dolist (key non-modified-keys)
                   (setq keys (delq key keys)))
                 (if keys
-                    (progn
-                      (princ (mapconcat #'key-description keys ", "))
-                      (princ ", and many ordinary text characters"))
+                    (with-current-buffer standard-output
+                      (insert (mapconcat #'help--key-description-fontified
+                                        keys ", "))
+                      (insert ", and many ordinary text characters"))
                   (princ "many ordinary text characters"))))
             (when (or remapped keys non-modified-keys)
               (princ ".")
@@ -1824,10 +1827,12 @@ describe-mode
 	      (save-excursion
 		(re-search-backward (substitute-command-keys "`\\([^`']+\\)'")
                                     nil t)
-		(help-xref-button 1 'help-function-def mode file-name)))))
-	(princ ":\n")
-	(princ (help-split-fundoc (documentation major-mode) nil 'doc))
-        (princ (help-fns--list-local-commands)))))
+                (help-xref-button 1 'help-function-def mode file-name)))))
+        (let ((fundoc (help-split-fundoc (documentation major-mode) nil 'doc)))
+          (with-current-buffer standard-output
+            (insert ":\n")
+            (insert fundoc)
+            (insert (help-fns--list-local-commands)))))))
   ;; For the sake of IELM and maybe others
   nil)
 
diff --git a/lisp/help-macro.el b/lisp/help-macro.el
index 791b10a878..74689cb5b4 100644
--- a/lisp/help-macro.el
+++ b/lisp/help-macro.el
@@ -92,119 +92,116 @@ make-help-screen
 with the key sequence that invoked FNAME.
 When FNAME finally does get a command, it executes that command
 and then returns."
-  (let ((doc-fn (intern (concat (symbol-name fname) "-doc"))))
-    `(progn
-       (defun ,doc-fn () ,help-text nil)
-       (defun ,fname ()
-	 "Help command."
-	 (interactive)
-	 (let ((line-prompt
-		(substitute-command-keys ,help-line)))
-	   (when three-step-help
-	     (message "%s" line-prompt))
-	   (let* ((help-screen (documentation (quote ,doc-fn)))
-		  ;; We bind overriding-local-map for very small
-		  ;; sections, *excluding* where we switch buffers
-		  ;; and where we execute the chosen help command.
-		  (local-map (make-sparse-keymap))
-		  (new-minor-mode-map-alist minor-mode-map-alist)
-		  (prev-frame (selected-frame))
-		  config new-frame key char)
-	     (when (string-match "%THIS-KEY%" help-screen)
-	       (setq help-screen
-		     (replace-match (key-description
-				     (substring (this-command-keys) 0 -1))
-				    t t help-screen)))
-	     (unwind-protect
-		 (let ((minor-mode-map-alist nil))
-		   (setcdr local-map ,helped-map)
-		   (define-key local-map [t] 'undefined)
-		   ;; Make the scroll bar keep working normally.
-		   (define-key local-map [vertical-scroll-bar]
-		     (lookup-key global-map [vertical-scroll-bar]))
-		   (if three-step-help
-		       (progn
-			 (setq key (let ((overriding-local-map local-map))
-				     (read-key-sequence nil)))
-			 ;; Make the HELP key translate to C-h.
-			 (if (lookup-key function-key-map key)
-			     (setq key (lookup-key function-key-map key)))
-			 (setq char (aref key 0)))
-		     (setq char ??))
-		   (when (or (eq char ??) (eq char help-char)
-			     (memq char help-event-list))
-		     (setq config (current-window-configuration))
-		     (pop-to-buffer " *Metahelp*" nil t)
-		     (and (fboundp 'make-frame)
-			  (not (eq (window-frame)
-				   prev-frame))
-			  (setq new-frame (window-frame)
-				config nil))
-		     (setq buffer-read-only nil)
-		     (let ((inhibit-read-only t))
-		       (erase-buffer)
-		       (insert help-screen))
-		     (let ((minor-mode-map-alist new-minor-mode-map-alist))
-		       (help-mode)
-		       (setq new-minor-mode-map-alist minor-mode-map-alist))
-		     (goto-char (point-min))
-		     (while (or (memq char (append help-event-list
-						   (cons help-char '(?? ?\C-v ?\s ?\177 delete backspace vertical-scroll-bar ?\M-v))))
-				(eq (car-safe char) 'switch-frame)
-				(equal key "\M-v"))
-		       (condition-case nil
-			   (cond
-			    ((eq (car-safe char) 'switch-frame)
-			     (handle-switch-frame char))
-			    ((memq char '(?\C-v ?\s))
-			     (scroll-up))
-			    ((or (memq char '(?\177 ?\M-v delete backspace))
-				 (equal key "\M-v"))
-			     (scroll-down)))
-			 (error nil))
-		       (let ((cursor-in-echo-area t)
-			     (overriding-local-map local-map))
-			 (setq key (read-key-sequence
-				    (format "Type one of the options listed%s: "
-					    (if (pos-visible-in-window-p
-						 (point-max))
-						"" ", or SPACE or DEL to scroll")))
-			       char (aref key 0)))
-
-		       ;; If this is a scroll bar command, just run it.
-		       (when (eq char 'vertical-scroll-bar)
-			 (command-execute (lookup-key local-map key) nil key))))
-		   ;; We don't need the prompt any more.
-		   (message "")
-		   ;; Mouse clicks are not part of the help feature,
-		   ;; so reexecute them in the standard environment.
-		   (if (listp char)
-		       (setq unread-command-events
-			     (cons char unread-command-events)
-			     config nil)
-		     (let ((defn (lookup-key local-map key)))
-		       (if defn
-			   (progn
-			     (when config
-			       (set-window-configuration config)
-			       (setq config nil))
-			     ;; Temporarily rebind `minor-mode-map-alist'
-			     ;; to `new-minor-mode-map-alist' (Bug#10454).
-			     (let ((minor-mode-map-alist new-minor-mode-map-alist))
-			       ;; `defn' must make sure that its frame is
-			       ;; selected, so we won't iconify it below.
-			       (call-interactively defn))
-			     (when new-frame
-			       ;; Do not iconify the selected frame.
-			       (unless (eq new-frame (selected-frame))
-				 (iconify-frame new-frame))
-			       (setq new-frame nil)))
-			 (ding)))))
-	       (when config
-		 (set-window-configuration config))
-	       (when new-frame
-		 (iconify-frame new-frame))
-	       (setq minor-mode-map-alist new-minor-mode-map-alist))))))))
+  `(defun ,fname ()
+     "Help command."
+     (interactive)
+     (let ((line-prompt
+            (substitute-command-keys ,help-line)))
+       (when three-step-help
+         (message "%s" line-prompt))
+       (let* ((help-screen ,help-text)
+              ;; We bind overriding-local-map for very small
+              ;; sections, *excluding* where we switch buffers
+              ;; and where we execute the chosen help command.
+              (local-map (make-sparse-keymap))
+              (new-minor-mode-map-alist minor-mode-map-alist)
+              (prev-frame (selected-frame))
+              config new-frame key char)
+         (when (string-match "%THIS-KEY%" help-screen)
+           (setq help-screen
+                 (replace-match (help--key-description-fontified
+                                 (substring (this-command-keys) 0 -1))
+                                t t help-screen)))
+         (unwind-protect
+             (let ((minor-mode-map-alist nil))
+               (setcdr local-map ,helped-map)
+               (define-key local-map [t] 'undefined)
+               ;; Make the scroll bar keep working normally.
+               (define-key local-map [vertical-scroll-bar]
+                 (lookup-key global-map [vertical-scroll-bar]))
+               (if three-step-help
+                   (progn
+                     (setq key (let ((overriding-local-map local-map))
+                                 (read-key-sequence nil)))
+                     ;; Make the HELP key translate to C-h.
+                     (if (lookup-key function-key-map key)
+                         (setq key (lookup-key function-key-map key)))
+                     (setq char (aref key 0)))
+                 (setq char ??))
+               (when (or (eq char ??) (eq char help-char)
+                         (memq char help-event-list))
+                 (setq config (current-window-configuration))
+                 (pop-to-buffer " *Metahelp*" nil t)
+                 (and (fboundp 'make-frame)
+                      (not (eq (window-frame)
+                               prev-frame))
+                      (setq new-frame (window-frame)
+                            config nil))
+                 (setq buffer-read-only nil)
+                 (let ((inhibit-read-only t))
+                   (erase-buffer)
+                   (insert (substitute-command-keys help-screen)))
+                 (let ((minor-mode-map-alist new-minor-mode-map-alist))
+                   (help-mode)
+                   (setq new-minor-mode-map-alist minor-mode-map-alist))
+                 (goto-char (point-min))
+                 (while (or (memq char (append help-event-list
+                                               (cons help-char '(?? ?\C-v ?\s ?\177 delete backspace vertical-scroll-bar ?\M-v))))
+                            (eq (car-safe char) 'switch-frame)
+                            (equal key "\M-v"))
+                   (condition-case nil
+                       (cond
+                        ((eq (car-safe char) 'switch-frame)
+                         (handle-switch-frame char))
+                        ((memq char '(?\C-v ?\s))
+                         (scroll-up))
+                        ((or (memq char '(?\177 ?\M-v delete backspace))
+                             (equal key "\M-v"))
+                         (scroll-down)))
+                     (error nil))
+                   (let ((cursor-in-echo-area t)
+                         (overriding-local-map local-map))
+                     (setq key (read-key-sequence
+                                (format "Type one of the options listed%s: "
+                                        (if (pos-visible-in-window-p
+                                             (point-max))
+                                            "" ", or SPACE or DEL to scroll")))
+                           char (aref key 0)))
+
+                   ;; If this is a scroll bar command, just run it.
+                   (when (eq char 'vertical-scroll-bar)
+                     (command-execute (lookup-key local-map key) nil key))))
+               ;; We don't need the prompt any more.
+               (message "")
+               ;; Mouse clicks are not part of the help feature,
+               ;; so reexecute them in the standard environment.
+               (if (listp char)
+                   (setq unread-command-events
+                         (cons char unread-command-events)
+                         config nil)
+                 (let ((defn (lookup-key local-map key)))
+                   (if defn
+                       (progn
+                         (when config
+                           (set-window-configuration config)
+                           (setq config nil))
+                         ;; Temporarily rebind `minor-mode-map-alist'
+                         ;; to `new-minor-mode-map-alist' (Bug#10454).
+                         (let ((minor-mode-map-alist new-minor-mode-map-alist))
+                           ;; `defn' must make sure that its frame is
+                           ;; selected, so we won't iconify it below.
+                           (call-interactively defn))
+                         (when new-frame
+                           ;; Do not iconify the selected frame.
+                           (unless (eq new-frame (selected-frame))
+                             (iconify-frame new-frame))
+                           (setq new-frame nil)))
+                     (ding)))))
+           (when config
+             (set-window-configuration config))
+           (when new-frame
+             (iconify-frame new-frame))
+           (setq minor-mode-map-alist new-minor-mode-map-alist))))))
 
 (provide 'help-macro)
 
diff --git a/lisp/help.el b/lisp/help.el
index 084e941549..50abb28cb1 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -104,8 +104,8 @@ help-map
     (define-key map "R" 'info-display-manual)
     (define-key map "s" 'describe-syntax)
     (define-key map "t" 'help-with-tutorial)
-    (define-key map "w" 'where-is)
     (define-key map "v" 'describe-variable)
+    (define-key map "w" 'where-is)
     (define-key map "q" 'help-quit)
     map)
   "Keymap for characters following the Help key.")
@@ -187,11 +187,8 @@ help-print-return-message
 ;; So keyboard macro definitions are documented correctly
 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
 
-(defalias 'help 'help-for-help-internal)
-;; find-function can find this.
-(defalias 'help-for-help 'help-for-help-internal)
-;; It can't find this, but nobody will look.
-(make-help-screen help-for-help-internal
+(defalias 'help 'help-for-help)
+(make-help-screen help-for-help
   (purecopy "Type a help option: [abcCdefFgiIkKlLmnprstvw.] C-[cdefmnoptw] or ?")
   ;; Don't purecopy this one, because it's not evaluated (it's
   ;; directly used as a docstring in a function definition, so it'll
@@ -199,52 +196,52 @@ 'help-for-help
   "You have typed %THIS-KEY%, the help character.  Type a Help option:
 \(Use SPC or DEL to scroll through this text.  Type \\<help-map>\\[help-quit] to exit the Help command.)
 
-a PATTERN   Show commands whose name matches the PATTERN (a list of words
+\\[apropos-command] PATTERN   Show commands whose name matches the PATTERN (a list of words
               or a regexp).  See also the `apropos' command.
-b           Display all key bindings.
-c KEYS      Display the command name run by the given key sequence.
-C CODING    Describe the given coding system, or RET for current ones.
-d PATTERN   Show a list of functions, variables, and other items whose
+\\[describe-bindings]           Display all key bindings.
+\\[describe-key-briefly] KEYS      Display the command name run by the given key sequence.
+\\[describe-coding-system] CODING    Describe the given coding system, or RET for current ones.
+\\[apropos-documentation] PATTERN   Show a list of functions, variables, and other items whose
               documentation matches the PATTERN (a list of words or a regexp).
-e           Go to the *Messages* buffer which logs echo-area messages.
-f FUNCTION  Display documentation for the given function.
-F COMMAND   Show the Emacs manual's section that describes the command.
-g           Display information about the GNU project.
-h           Display the HELLO file which illustrates various scripts.
-i           Start the Info documentation reader: read included manuals.
-I METHOD    Describe a specific input method, or RET for current.
-k KEYS      Display the full documentation for the key sequence.
-K KEYS      Show the Emacs manual's section for the command bound to KEYS.
-l           Show last 300 input keystrokes (lossage).
-L LANG-ENV  Describes a specific language environment, or RET for current.
-m           Display documentation of current minor modes and current major mode,
-              including their special commands.
-n           Display news of recent Emacs changes.
-o SYMBOL    Display the given function or variable's documentation and value.
-p TOPIC     Find packages matching a given topic keyword.
-P PACKAGE   Describe the given Emacs Lisp package.
-r           Display the Emacs manual in Info mode.
-R           Prompt for a manual and then display it in Info mode.
-s           Display contents of current syntax table, plus explanations.
-S SYMBOL    Show the section for the given symbol in the Info manual
+\\[view-echo-area-messages]           Go to the *Messages* buffer which logs echo-area messages.
+\\[describe-function] FUNCTION  Display documentation for the given function.
+\\[Info-goto-emacs-command-node] COMMAND   Show the Emacs manual's section that describes the command.
+\\[describe-gnu-project]           Display information about the GNU project.
+\\[view-hello-file]           Display the HELLO file which illustrates various scripts.
+\\[info]           Start the Info documentation reader: read included manuals.
+\\[describe-input-method] METHOD    Describe a specific input method, or RET for current.
+\\[describe-key] KEYS      Display the full documentation for the key sequence.
+\\[Info-goto-emacs-key-command-node] KEYS      Show the Emacs manual's section for the command bound to KEYS.
+\\[view-lossage]           Show last 300 input keystrokes (lossage).
+\\[describe-language-environment] LANG-ENV  Describes a specific language environment, or RET for current.
+\\[describe-mode]           Display documentation of current minor modes and current major mode,
+             including their special commands.
+\\[view-emacs-news]           Display news of recent Emacs changes.
+\\[describe-symbol] SYMBOL    Display the given function or variable's documentation and value.
+\\[finder-by-keyword] TOPIC     Find packages matching a given topic keyword.
+\\[describe-package] PACKAGE   Describe the given Emacs Lisp package.
+\\[info-emacs-manual]           Display the Emacs manual in Info mode.
+\\[info-display-manual]           Prompt for a manual and then display it in Info mode.
+\\[describe-syntax]           Display contents of current syntax table, plus explanations.
+\\[info-lookup-symbol] SYMBOL    Show the section for the given symbol in the Info manual
               for the programming language used in this buffer.
-t           Start the Emacs learn-by-doing tutorial.
-v VARIABLE  Display the given variable's documentation and value.
-w COMMAND   Display which keystrokes invoke the given command (where-is).
-.           Display any available local help at point in the echo area.
-
-C-a         Information about Emacs.
-C-c         Emacs copying permission (GNU General Public License).
-C-d         Instructions for debugging GNU Emacs.
-C-e         External packages and information about Emacs.
-C-f         Emacs FAQ.
+\\[help-with-tutorial]           Start the Emacs learn-by-doing tutorial.
+\\[describe-variable] VARIABLE  Display the given variable's documentation and value.
+\\[where-is] COMMAND   Display which keystrokes invoke the given command (where-is).
+\\[display-local-help]           Display any available local help at point in the echo area.
+
+\\[about-emacs]         Information about Emacs.
+\\[describe-copying]         Emacs copying permission (GNU General Public License).
+\\[view-emacs-debugging]         Instructions for debugging GNU Emacs.
+\\[view-external-packages]         External packages and information about Emacs.
+\\[view-emacs-FAQ]         Emacs FAQ.
 C-m         How to order printed Emacs manuals.
 C-n         News of recent Emacs changes.
-C-o         Emacs ordering and distribution information.
-C-p         Info about known Emacs problems.
-C-s         Search forward \"help window\".
-C-t         Emacs TODO list.
-C-w         Information on absence of warranty for GNU Emacs."
+\\[describe-distribution]         Emacs ordering and distribution information.
+\\[view-emacs-problems]         Info about known Emacs problems.
+\\[search-forward-help-for-help]         Search forward \"help window\".
+\\[view-emacs-todo]         Emacs TODO list.
+\\[describe-no-warranty]         Information on absence of warranty for GNU Emacs."
   help-map)
 
 \f
@@ -492,6 +489,15 @@ view-lossage
 \f
 ;; Key bindings
 
+(defun help--key-description-fontified (keys &optional prefix)
+  "Like `key-description' but add face for \"*Help*\" buffers."
+  ;; We add both the `font-lock-face' and `face' properties here, as this
+  ;; seems to be the only way to get this to work reliably in any
+  ;; buffer.
+  (propertize (key-description keys prefix)
+              'font-lock-face 'help-key-binding
+              'face 'help-key-binding))
+
 (defun describe-bindings (&optional prefix buffer)
   "Display a buffer showing a list of all defined keys, and their definitions.
 The keys are displayed in order of precedence.
@@ -511,7 +517,6 @@ describe-bindings
     (with-current-buffer (help-buffer)
       (describe-buffer-bindings buffer prefix))))
 
-;; This function used to be in keymap.c.
 (defun describe-bindings-internal (&optional menus prefix)
   "Show a list of all defined keys, and their definitions.
 We put that list in a buffer, and display the buffer.
@@ -559,7 +564,8 @@ where-is
       (let* ((remapped (command-remapping symbol))
 	     (keys (where-is-internal
 		    symbol overriding-local-map nil nil remapped))
-	     (keys (mapconcat 'key-description keys ", "))
+             (keys (mapconcat #'help--key-description-fontified
+                              keys ", "))
 	     string)
 	(setq string
 	      (if insert
@@ -587,11 +593,11 @@ where-is
   nil)
 
 (defun help-key-description (key untranslated)
-  (let ((string (key-description key)))
+  (let ((string (help--key-description-fontified key)))
     (if (or (not untranslated)
 	    (and (eq (aref untranslated 0) ?\e) (not (eq (aref key 0) ?\e))))
 	string
-      (let ((otherstring (key-description untranslated)))
+      (let ((otherstring (help--key-description-fontified untranslated)))
 	(if (equal string otherstring)
 	    string
 	  (format "%s (translated from %s)" string otherstring))))))
@@ -979,7 +985,7 @@ substitute-command-keys
   "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.
+is not on any keys.  Keybindings will use the face `help-key-binding'.
 
 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
@@ -999,7 +1005,7 @@ substitute-command-keys
 output.
 
 Return the original STRING if no substitutions are made.
-Otherwise, return a new string (without any text properties)."
+Otherwise, return a new string."
   (when (not (null string))
     ;; KEYMAP is either nil (which means search all the active
     ;; keymaps) or a specified local map (which means search just that
@@ -1053,12 +1059,15 @@ substitute-command-keys
                                 (where-is-internal fun keymap t))))
                   (if (not key)
                       ;; Function is not on any key.
-                      (progn (insert "M-x ")
-                             (goto-char (+ end-point 3))
-                             (delete-char 1))
+                      (progn
+                        (insert (propertize "M-x "
+                                            'face 'help-key-binding
+                                            'font-lock-face 'help-key-binding))
+                        (goto-char (+ end-point 3))
+                        (delete-char 1))
                     ;; Function is on a key.
                     (delete-char (- end-point (point)))
-                    (insert (key-description key)))))
+                    (insert (help--key-description-fontified key)))))
                ;; 1D. \{foo} is replaced with a summary of the keymap
                ;;            (symbol-value foo).
                ;;     \<foo> just sets the keymap used for \[cmd].
@@ -1172,7 +1181,7 @@ describe-map-tree
                           (concat title
                                   (if prefix
                                       (concat " Starting With "
-                                              (key-description prefix)))
+                                              (help--key-description-fontified prefix)))
                                   ":\n"))
                       "key             binding\n"
                       "---             -------\n")))
@@ -1228,6 +1237,8 @@ help--describe-command
                                              (= help--previous-description-column 32)))
                                     32)
                                    (t 16))))
+    ;; Insert tab without face to avoid using the `help-keymap' face.
+    (insert (propertize "\t" 'face nil 'font-lock-face nil))
     (indent-to description-column 1)
     (setq help--previous-description-column description-column)
     (cond ((symbolp definition)
@@ -1240,6 +1251,8 @@ help--describe-command
 
 (defun help--describe-translation (definition)
   ;; Converted from describe_translation in keymap.c.
+  ;; Insert tab without face to avoid using the `help-keymap' face.
+  (insert (propertize "\t" 'face nil 'font-lock-face nil))
   (indent-to 16 1)
   (cond ((symbolp definition)
          (insert (symbol-name definition) "\n"))
@@ -1351,9 +1364,9 @@ describe-map
               (setq end (caar vect))))
           ;; Now START .. END is the range to describe next.
           ;; Insert the string to describe the event START.
-          (insert (key-description (vector start) prefix))
+          (insert (help--key-description-fontified (vector start) prefix))
           (when (not (eq start end))
-            (insert " .. " (key-description (vector end) prefix)))
+            (insert " .. " (help--key-description-fontified (vector end) prefix)))
           ;; Print a description of the definition of this character.
           ;; Called function will take care of spacing out far enough
           ;; for alignment purposes.
@@ -1420,7 +1433,7 @@ describe-map
 ;;             (setq first nil))
 ;;           (when (and prefix (> (length prefix) 0))
 ;;             (insert (format "%s" prefix)))
-;;           (insert (key-description (vector start-idx) prefix))
+;;           (insert (help--key-description-fontified (vector start-idx) prefix))
 ;;           ;; Find all consecutive characters or rows that have the
 ;;           ;; same definition.
 ;;           (while (equal (keymap--get-keyelt (aref vector (1+ idx)) nil)
@@ -1433,7 +1446,7 @@ describe-map
 ;;             (insert " .. ")
 ;;             (when (and prefix (> (length prefix) 0))
 ;;               (insert (format "%s" prefix)))
-;;             (insert (key-description (vector idx) prefix)))
+;;             (insert (help--key-description-fontified (vector idx) prefix)))
 ;;           (if transl
 ;;               (help--describe-translation definition)
 ;;             (help--describe-command definition))
@@ -1924,6 +1937,8 @@ help-command-error-confusable-suggestions
 (add-function :after command-error-function
               #'help-command-error-confusable-suggestions)
 
+(define-obsolete-function-alias 'help-for-help-internal #'help-for-help "28.1")
+
 \f
 (provide 'help)
 
diff --git a/lisp/isearch.el b/lisp/isearch.el
index e7926ac08c..943e24aa56 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -460,11 +460,11 @@ isearch-help-map
 (make-help-screen isearch-help-for-help-internal
   (purecopy "Type a help option: [bkm] or ?")
   "You have typed %THIS-KEY%, the help character.  Type a Help option:
-\(Type \\<help-map>\\[help-quit] to exit the Help command.)
+\(Type \\<isearch-help-map>\\[help-quit] to exit the Help command.)
 
-b           Display all Isearch key bindings.
-k KEYS      Display full documentation of Isearch key sequence.
-m           Display documentation of Isearch mode.
+\\[isearch-describe-bindings]           Display all Isearch key bindings.
+\\[isearch-describe-key] KEYS      Display full documentation of Isearch key sequence.
+\\[isearch-describe-mode]           Display documentation of Isearch mode.
 
 You can't type here other help keys available in the global help map,
 but outside of this help window when you type them in Isearch mode,
diff --git a/lisp/tooltip.el b/lisp/tooltip.el
index 8e00aa5c2a..09ee977cf2 100644
--- a/lisp/tooltip.el
+++ b/lisp/tooltip.el
@@ -248,7 +248,8 @@ tooltip-show
 	    (setf (alist-get 'border-color params) fg))
 	  (when (stringp bg)
 	    (setf (alist-get 'background-color params) bg))
-	  (x-show-tip (propertize text 'face 'tooltip)
+          (add-face-text-property 0 (length text) 'tooltip t text)
+          (x-show-tip text
 		      (selected-frame)
 		      params
 		      tooltip-hide-delay
diff --git a/src/keymap.c b/src/keymap.c
index 782931fadf..e38c9b908a 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2846,6 +2846,23 @@ DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 2, 0,
   return unbind_to (count, Qnil);
 }
 
+static Lisp_Object fontify_key_properties;
+
+static Lisp_Object
+describe_key_maybe_fontify (Lisp_Object str, Lisp_Object prefix,
+				   bool keymap_p)
+{
+  Lisp_Object key_desc = Fkey_description (str, prefix);
+
+  if (keymap_p)
+    return Fadd_text_properties (make_fixnum (0),
+				 make_fixnum (SCHARS (key_desc)),
+				 fontify_key_properties,
+				 key_desc);
+  else
+    return key_desc;
+}
+
 DEFUN ("help--describe-vector", Fhelp__describe_vector, Shelp__describe_vector, 7, 7, 0,
        doc: /* Insert in the current buffer a description of the contents of VECTOR.
 Call DESCRIBER to insert the description of one value found in VECTOR.
@@ -3021,7 +3038,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
       if (!NILP (elt_prefix))
 	insert1 (elt_prefix);
 
-      insert1 (Fkey_description (kludge, prefix));
+      insert1 (describe_key_maybe_fontify (kludge, prefix, keymap_p));
 
       /* Find all consecutive characters or rows that have the same
 	 definition.  But, if VECTOR is a char-table, we had better
@@ -3071,7 +3088,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
 	  if (!NILP (elt_prefix))
 	    insert1 (elt_prefix);
 
-	  insert1 (Fkey_description (kludge, prefix));
+	  insert1 (describe_key_maybe_fontify (kludge, prefix, keymap_p));
 	}
 
       /* Print a description of the definition of this character.
@@ -3200,6 +3217,12 @@ syms_of_keymap (void)
   staticpro (&where_is_cache);
   staticpro (&where_is_cache_keymaps);
 
+  DEFSYM (Qfont_lock_face, "font-lock-face");
+  DEFSYM (Qhelp_key_binding, "help-key-binding");
+  staticpro (&fontify_key_properties);
+  fontify_key_properties = Fcons (Qfont_lock_face,
+				  Fcons (Qhelp_key_binding, Qnil));
+
   defsubr (&Skeymapp);
   defsubr (&Skeymap_parent);
   defsubr (&Skeymap_prompt);
-- 
2.30.1


  reply	other threads:[~2021-03-05 16:18 UTC|newest]

Thread overview: 188+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21 12:06 Proposal for an improved `help-for-help' Stefan Kangas
2021-02-21 16:46 ` [External] : " Drew Adams
2021-02-21 17:31   ` Stefan Kangas
2021-02-21 18:17     ` Drew Adams
2021-02-21 17:42 ` Lars Ingebrigtsen
2021-02-21 18:18   ` [External] : " Drew Adams
2021-02-21 19:49   ` Stefan Kangas
2021-02-24  1:40   ` Consistent face for keys in *Help* and `substitute-command-keys' Stefan Kangas
2021-02-24  2:24     ` [External] : " Drew Adams
2021-02-24  4:44       ` Stefan Kangas
2021-02-24 22:01         ` Drew Adams
2021-02-25  1:25           ` Stefan Kangas
2021-02-25  6:43             ` Drew Adams
2021-02-25 15:06               ` Eli Zaretskii
2021-02-25 16:22               ` Stefan Kangas
2021-02-24 14:00     ` Basil L. Contovounesios
2021-02-24 16:35       ` Stefan Kangas
2021-02-24 19:09         ` Basil L. Contovounesios
2021-02-25  2:11           ` Stefan Kangas
2021-02-24 14:29     ` Lars Ingebrigtsen
2021-02-24 16:46     ` Eli Zaretskii
2021-02-25  2:26       ` Stefan Kangas
2021-02-25 14:28         ` Eli Zaretskii
2021-02-25 16:45           ` Stefan Kangas
2021-02-25 18:25             ` Eli Zaretskii
2021-02-25 18:48               ` Stefan Kangas
2021-02-25 19:11                 ` Eli Zaretskii
2021-02-25 19:47                   ` Stefan Kangas
2021-02-25 20:32                     ` Eli Zaretskii
2021-03-04  6:24                       ` Stefan Kangas
2021-03-04 14:00                         ` Eli Zaretskii
2021-03-05 16:18                           ` Stefan Kangas [this message]
2021-03-05 17:07                             ` [External] : " Drew Adams
2021-03-05 17:58                               ` Stefan Kangas
2021-03-06 16:44                                 ` Drew Adams
2021-03-06 17:04                                   ` Stefan Kangas
2021-03-06 17:39                                     ` Drew Adams
2021-03-05 18:58                             ` Eli Zaretskii
2021-03-05 19:28                               ` Stefan Kangas
2021-03-05 20:15                                 ` Eli Zaretskii
2021-03-05 20:39                                   ` Stefan Kangas
2021-03-05 20:52                                     ` Eli Zaretskii
2021-03-05 21:43                                       ` Stefan Kangas
2021-03-06  7:33                                         ` Eli Zaretskii
2021-03-06 16:25                                           ` Stefan Kangas
2021-03-06 17:32                                             ` Stefan Kangas
2021-03-06 18:28                                               ` Eli Zaretskii
2021-03-07  3:03                                                 ` Stefan Kangas
2021-03-07  6:45                                                   ` Eli Zaretskii
2021-03-07  7:26                                                     ` Stefan Kangas
2021-03-07  7:42                                                       ` Eli Zaretskii
2021-03-08  9:17                                               ` Juri Linkov
2021-03-08 11:10                                                 ` Stefan Kangas
2021-03-08 17:43                                                   ` Juri Linkov
2021-03-10  1:38                                                     ` Stefan Kangas
2021-03-10 17:16                                                       ` Juri Linkov
2021-03-10 19:35                                                         ` Stefan Kangas
2021-03-10 19:50                                                           ` Juri Linkov
2021-03-10 19:59                                                             ` Eli Zaretskii
2021-03-11  0:46                                                               ` Stefan Kangas
2021-03-11  3:09                                                                 ` Stefan Monnier
2021-03-11  6:25                                                                   ` Eli Zaretskii
2021-03-11 13:25                                                                     ` Stefan Monnier
2021-03-11 13:59                                                                       ` Eli Zaretskii
2021-03-13 14:11                                                                   ` Stefan Kangas
2021-03-11  6:05                                                                 ` Eli Zaretskii
2021-03-13 14:27                                                                   ` Stefan Kangas
2021-03-13 15:16                                                                     ` Eli Zaretskii
2021-03-13 15:59                                                                       ` Stefan Kangas
2021-03-11  0:45                                                             ` Stefan Kangas
2021-03-15  9:19                                                               ` Juri Linkov
2021-03-16  2:37                                                                 ` Stefan Kangas
2021-03-16 23:20                                                                 ` Dmitry Gutov
2021-03-08 15:39                                                 ` [External] : " Drew Adams
2021-03-08 16:40                                                   ` Stefan Kangas
2021-03-08 17:43                                                     ` Juri Linkov
2021-03-09  7:38                                                       ` Stefan Kangas
2021-03-09  9:05                                                         ` Juri Linkov
2021-02-25 19:14                 ` Drew Adams
2021-02-25 19:44             ` martin rudalics
2021-02-24 16:51     ` Eli Zaretskii
2021-02-25  1:56       ` Stefan Kangas
2021-02-25 14:24         ` Eli Zaretskii
2021-02-21 17:45 ` Proposal for an improved `help-for-help' Eli Zaretskii
2021-02-21 18:20   ` [External] : " Drew Adams
2021-02-21 18:48   ` Stefan Kangas
2021-02-21 19:19     ` Eli Zaretskii
2021-02-21 20:04       ` Stefan Kangas
2021-02-21 20:16         ` Eli Zaretskii
2021-02-21 23:27           ` Stefan Kangas
2021-02-22 16:12             ` Eli Zaretskii
2021-03-13 16:26     ` Stefan Kangas
2021-03-14  2:37       ` [External] : " Drew Adams
2021-03-14 23:05       ` Drew Adams
2021-03-14 23:53         ` Stefan Kangas
2021-03-15  1:54           ` Drew Adams
2021-04-07 15:18       ` Stefan Kangas
2021-04-07 16:10         ` Eli Zaretskii
2021-04-07 22:54           ` Howard Melman
2021-04-08  7:15             ` Eli Zaretskii
2021-04-08 12:57               ` Stefan Kangas
2021-04-08 13:35           ` Stefan Kangas
2021-04-08 13:50             ` Eli Zaretskii
2021-04-08 15:27               ` Stefan Kangas
2021-04-08 15:34                 ` Eli Zaretskii
2021-04-08 17:16                   ` Howard Melman
2021-04-08 22:52                   ` Stefan Kangas
2021-04-09  6:23                     ` Eli Zaretskii
2021-04-08 14:08             ` Alan Mackenzie
2021-04-08 14:50               ` Dmitry Gutov
2021-04-08 15:02                 ` Alan Mackenzie
2021-04-08 15:15                   ` Eli Zaretskii
2021-04-08 15:45                     ` Alan Mackenzie
2021-04-08 15:51                       ` Eli Zaretskii
2021-04-08 17:55             ` Howard Melman
2021-04-09 15:42               ` Stefan Kangas
2021-04-08 18:48             ` Gregory Heytings
2021-04-08 23:23               ` Stefan Kangas
2021-04-08 23:35                 ` Gregory Heytings
2021-04-08 23:41                   ` Howard Melman
2021-04-07 16:42         ` [External] : " Drew Adams
2021-04-07 18:33         ` Gregory Heytings
2021-04-07 19:50           ` Gregory Heytings
2021-04-07 22:56           ` Stefan Kangas
2021-04-07 23:26             ` Gregory Heytings
2021-04-08 12:42               ` Stefan Kangas
2021-04-07 19:55         ` Juri Linkov
2021-04-24 13:21         ` Stefan Kangas
2021-04-24 13:27           ` Eli Zaretskii
2021-04-24 16:44           ` Dmitry Gutov
2021-04-24 23:48             ` Stefan Kangas
2021-04-25  7:26               ` Eli Zaretskii
2021-04-25  9:30                 ` Stefan Kangas
2021-04-25 10:25                   ` Eli Zaretskii
2021-04-25 11:49                     ` Stefan Kangas
2021-04-25 12:14                       ` Eli Zaretskii
2021-04-25 16:26                     ` [External] : " Drew Adams
2021-04-25 10:20                 ` Dmitry Gutov
2021-04-25 10:38                   ` Eli Zaretskii
2021-04-25 10:46                     ` Eli Zaretskii
2021-04-25 11:23                     ` Dmitry Gutov
2021-04-25 15:18                       ` Stefan Kangas
2021-04-25 15:28                         ` Dmitry Gutov
2021-04-30 17:39                           ` Stefan Kangas
2021-04-30 20:02                             ` Dmitry Gutov
2021-04-30 20:36                               ` Stefan Monnier
2021-04-30 22:09                                 ` Dmitry Gutov
2021-05-02 10:23                               ` Stefan Kangas
2021-05-02 18:57                                 ` Dmitry Gutov
2021-04-30 17:34                         ` Stefan Kangas
2021-04-25 12:47                   ` Gregory Heytings
2021-04-25 13:05                     ` Eli Zaretskii
2021-04-25 13:09                       ` Eli Zaretskii
2021-04-25 16:22                         ` [External] : " Drew Adams
2021-04-25 16:30                           ` Eli Zaretskii
2021-04-25 13:16                       ` Gregory Heytings
2021-04-25 13:24                         ` Eli Zaretskii
2021-04-25 13:32                           ` Gregory Heytings
2021-04-25 13:44                             ` Eli Zaretskii
2021-04-25 13:58                           ` Dmitry Gutov
2021-04-25 11:12               ` Dmitry Gutov
2021-04-25 15:47               ` DEL vs Backspace (was: Proposal for an improved `help-for-help') Stefan Monnier
2021-04-25 16:49                 ` DEL vs Backspace Lars Ingebrigtsen
2021-04-25 17:25                   ` Stefan Monnier
2021-04-25 17:50                     ` Dmitry Gutov
2021-04-26  0:45                     ` Stefan Kangas
2021-04-26 11:45                       ` Eli Zaretskii
2021-04-26 11:48                         ` Dmitry Gutov
2021-04-26  4:41                   ` Richard Stallman
2021-04-27 20:56               ` Proposal for an improved `help-for-help' Stefan Kangas
2021-04-27 23:15                 ` Dmitry Gutov
2021-04-24 17:18           ` Gregory Heytings
2021-04-24 20:32             ` Juri Linkov
2021-04-25 10:00             ` Stefan Kangas
2021-04-07 17:56       ` Howard Melman
2021-04-07 18:21         ` John Yates
2021-04-07 22:56           ` Stefan Kangas
2021-04-07 22:41         ` Stefan Kangas
2021-04-07 23:15           ` Howard Melman
2021-04-08 12:57             ` Stefan Kangas
2021-02-21 19:27 ` Howard Melman
2021-02-22 15:25   ` Stefan Kangas
2021-02-22 10:01 ` Yuri Khan
2021-02-22 15:25   ` Stefan Kangas
2021-04-25 15:11     ` Stefan Kangas
2021-04-25 15:34       ` Dmitry Gutov
2021-04-25 18:43         ` Stefan Kangas
2021-04-25 14:06   ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADwFkm=iPeaSD3E7meeifvi7QDAnQ9yqQbe5JHe2BiQaiSaw3g@mail.gmail.com' \
    --to=stefan@marxist.se \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).