From 4a112fd7a6f0dcbd1b99b811b324123f5699bdfb Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 8 Mar 2021 03:29:42 +0100 Subject: Add new face 'help-key-binding' for keybindings in help * lisp/faces.el (help-key-binding): New face. * lisp/help.el (help-for-help): Rename from 'help-for-help-internal'. Use 'substitute-command-keys' syntax. (help): Make into alias for 'help-for-help'. (help-for-help-internal): Make into obsolete alias for 'help-for-help'. (help--key-description-fontified): New function to add the 'help-key-binding' face. (help-key-description, substitute-command-keys) (describe-map-tree, help--describe-command) (help--describe-translation, describe-map): * lisp/help-fns.el (help-fns--key-bindings, describe-mode): Use above new function. * lisp/isearch.el (isearch-help-for-help-internal): Use `substitute-command-keys' syntax. * lisp/help-macro.el (make-help-screen): Use 'substitute-command-keys' and 'help--key-description-fontified'. Simplify. * src/keymap.c (describe_key_maybe_fontify): New function to add the 'help-key-binding' face to keybindings. (describe_vector): Use above new keybinding. (syms_of_keymap) : New DEFSYMs. (fontify_key_properties): New static variable. * lisp/tooltip.el (tooltip-show): Avoid overriding faces in specified tooltip text. * test/lisp/help-tests.el (with-substitute-command-keys-test): Don't test for text properties. (help-tests-substitute-command-keys/add-key-face) (help-tests-substitute-command-keys/add-key-face-listing): New tests. --- test/lisp/help-tests.el | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'test/lisp/help-tests.el') diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el index 8034764741c..b2fec5c1bde 100644 --- a/test/lisp/help-tests.el +++ b/test/lisp/help-tests.el @@ -26,6 +26,7 @@ (require 'ert) (eval-when-compile (require 'cl-lib)) +(require 'text-property-search) ; for `text-property-search-forward' (ert-deftest help-split-fundoc-SECTION () "Test new optional arg SECTION." @@ -60,9 +61,8 @@ (defmacro with-substitute-command-keys-test (&rest body) `(cl-flet* ((test (lambda (orig result) - (should (equal-including-properties - (substitute-command-keys orig) - result)))) + (should (equal (substitute-command-keys orig) + result)))) (test-re (lambda (orig regexp) (should (string-match (concat "^" regexp "$") @@ -222,6 +222,24 @@ M-s next-matching-history-element (define-minor-mode help-tests-minor-mode "Minor mode for testing shadowing.") +(ert-deftest help-tests-substitute-command-keys/add-key-face () + (should (equal (substitute-command-keys "\\[next-line]") + (propertize "C-n" + 'face 'help-key-binding + 'font-lock-face 'help-key-binding)))) + +(ert-deftest help-tests-substitute-command-keys/add-key-face-listing () + (with-temp-buffer + (insert (substitute-command-keys "\\{help-tests-minor-mode-map}")) + (goto-char (point-min)) + (text-property-search-forward 'face 'help-key-binding) + (should (looking-at "C-e")) + ;; Don't fontify trailing whitespace. + (should-not (get-text-property (+ (point) 3) 'face)) + (text-property-search-forward 'face 'help-key-binding) + (should (looking-at "x")) + (should-not (get-text-property (+ (point) 1) 'face)))) + (ert-deftest help-tests-substitute-command-keys/test-mode () (with-substitute-command-keys-test (with-temp-buffer -- cgit v1.2.3 From caf8eb0381d1fa9f2b683db7018c5438ff99c83a Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 25 May 2021 21:22:22 +0200 Subject: Update help-tests.el after minibuffer map change --- test/lisp/help-tests.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/lisp/help-tests.el') diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el index b2fec5c1bde..871417da3d2 100644 --- a/test/lisp/help-tests.el +++ b/test/lisp/help-tests.el @@ -110,14 +110,19 @@ C- file-cache-minibuffer-complete switch-to-completions previous-line-or-history-element +M-g Prefix Command M-v switch-to-completions +M-g ESC Prefix Command + M-< minibuffer-beginning-of-buffer M-n next-history-element M-p previous-history-element M-r previous-matching-history-element M-s next-matching-history-element +M-g M-c switch-to-completions + "))) (ert-deftest help-tests-substitute-command-keys/keymap-change () -- cgit v1.2.3