aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2019-08-24 01:02:04 +0200
committerStefan Kangas2020-02-04 02:04:20 +0100
commit557b790e0a3fcb2cd4196a3119da3e92647f8def (patch)
treef2b6aaf62ae10fea500af2c09296eab5f5a1ab37
parentf9504ffba2e2604338c243dd77c877bbb8162e4a (diff)
downloademacs-557b790e0a3fcb2cd4196a3119da3e92647f8def.tar.gz
emacs-557b790e0a3fcb2cd4196a3119da3e92647f8def.zip
Add new help command describe-keymap
* lisp/help-fns.el (describe-keymap): New command to show key bindings for a given keymap. (Bug#30660) * doc/emacs/help.texi (Misc Help): Document the new command. * doc/lispref/keymaps.texi (Scanning Keymaps): Add a cross-reference to the above documentation. * etc/NEWS: Announce the new command. * test/lisp/help-fns-tests.el (help-fns-test-describe-keymap/symbol) (help-fns-test-describe-keymap/value) (help-fns-test-describe-keymap/not-keymap) (help-fns-test-describe-keymap/let-bound) (help-fns-test-describe-keymap/dynamically-bound-no-file): New tests. Co-authored-by: Drew Adams <drew.adams@oracle.com>
-rw-r--r--doc/emacs/help.texi5
-rw-r--r--doc/lispref/keymaps.texi7
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/help-fns.el59
-rw-r--r--test/lisp/help-fns-tests.el28
5 files changed, 102 insertions, 2 deletions
diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index fce6720b934..49c53c5cbc0 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -601,6 +601,11 @@ is @key{ESC}, because @kbd{@key{ESC} C-h} is actually @kbd{C-M-h},
601which marks a defun. However, @w{@kbd{@key{ESC} @key{F1}}} and 601which marks a defun. However, @w{@kbd{@key{ESC} @key{F1}}} and
602@w{@kbd{@key{ESC} ?}} work fine.) 602@w{@kbd{@key{ESC} ?}} work fine.)
603 603
604@findex describe-keymap
605Finally, @kbd{M-x describe-keymap} prompts for the name of a keymap,
606with completion, and displays a listing of all key bindings in that
607keymap.
608
604@node Help Files 609@node Help Files
605@section Help Files 610@section Help Files
606 611
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi
index 259efea3248..4d513132e9f 100644
--- a/doc/lispref/keymaps.texi
+++ b/doc/lispref/keymaps.texi
@@ -1846,8 +1846,11 @@ local map.
1846@cindex scanning keymaps 1846@cindex scanning keymaps
1847@cindex keymaps, scanning 1847@cindex keymaps, scanning
1848 1848
1849 This section describes functions used to scan all the current keymaps 1849 This section describes functions used to scan all the current
1850for the sake of printing help information. 1850keymaps for the sake of printing help information. To display the
1851bindings in a particular keymap, you can use the
1852@code{describe-keymap} command (@pxref{Misc Help, , Other Help
1853Commands, emacs, The GNU Emacs Manual})
1851 1854
1852@defun accessible-keymaps keymap &optional prefix 1855@defun accessible-keymaps keymap &optional prefix
1853This function returns a list of all the keymaps that can be reached (via 1856This function returns a list of all the keymaps that can be reached (via
diff --git a/etc/NEWS b/etc/NEWS
index 1fbcd43ab00..de8e20e2de4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -85,6 +85,11 @@ shows equivalent key bindings for all commands that have them.
85 85
86* Changes in Specialized Modes and Packages in Emacs 28.1 86* Changes in Specialized Modes and Packages in Emacs 28.1
87 87
88** Help
89
90+++
91*** New command 'describe-keymap' describes keybindings in a keymap.
92
88--- 93---
89** The old non-SMIE indentation of 'sh-mode' has been removed. 94** The old non-SMIE indentation of 'sh-mode' has been removed.
90 95
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 0e2ae6b3c3c..017bb3ae748 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -1562,6 +1562,65 @@ BUFFER should be a buffer or a buffer name."
1562 (insert "\nThe parent category table is:") 1562 (insert "\nThe parent category table is:")
1563 (describe-vector table 'help-describe-category-set)))))) 1563 (describe-vector table 'help-describe-category-set))))))
1564 1564
1565;;;###autoload
1566(defun describe-keymap (keymap)
1567 "Describe key bindings in KEYMAP.
1568When called interactively, prompt for a variable that has a
1569keymap value."
1570 (interactive (list
1571 (intern (completing-read "Keymap: " obarray
1572 (lambda (m)
1573 (and (boundp m)
1574 (keymapp (symbol-value m))))
1575 t nil 'variable-name-history))))
1576 (let (used-gentemp)
1577 (unless (and (symbolp keymap)
1578 (boundp keymap)
1579 (keymapp (symbol-value keymap)))
1580 (when (not (keymapp keymap))
1581 (if (symbolp keymap)
1582 (error "Not a keymap variable: %S" keymap)
1583 (error "Not a keymap")))
1584 (let ((sym nil))
1585 (unless sym
1586 (setq sym (cl-gentemp "KEYMAP OBJECT (no variable) "))
1587 (setq used-gentemp t)
1588 (set sym keymap))
1589 (setq keymap sym)))
1590 ;; Follow aliasing.
1591 (setq keymap (or (ignore-errors (indirect-variable keymap)) keymap))
1592 (help-setup-xref (list #'describe-keymap keymap)
1593 (called-interactively-p 'interactive))
1594 (let* ((name (symbol-name keymap))
1595 (doc (documentation-property keymap 'variable-documentation))
1596 (file-name (find-lisp-object-file-name keymap 'defvar)))
1597 (with-help-window (help-buffer)
1598 (with-current-buffer standard-output
1599 (unless used-gentemp
1600 (princ (format-message "%S is a keymap variable" keymap))
1601 (if (not file-name)
1602 (princ ".\n\n")
1603 (princ (format-message
1604 " defined in `%s'.\n\n"
1605 (if (eq file-name 'C-source)
1606 "C source code"
1607 (file-name-nondirectory file-name))))
1608 (save-excursion
1609 (re-search-backward (substitute-command-keys
1610 "`\\([^`']+\\)'")
1611 nil t)
1612 (help-xref-button 1 'help-variable-def
1613 keymap file-name))))
1614 (when (and (not (equal "" doc)) doc)
1615 (princ "Documentation:\n")
1616 (princ (format-message "%s\n\n" doc)))
1617 ;; Use `insert' instead of `princ', so control chars (e.g. \377)
1618 ;; insert correctly.
1619 (insert (substitute-command-keys (concat "\\{" name "}"))))))
1620 ;; Cleanup.
1621 (when used-gentemp
1622 (makunbound keymap))))
1623
1565 1624
1566;;; Replacements for old lib-src/ programs. Don't seem especially useful. 1625;;; Replacements for old lib-src/ programs. Don't seem especially useful.
1567 1626
diff --git a/test/lisp/help-fns-tests.el b/test/lisp/help-fns-tests.el
index ef42d4bda29..1d6c062979f 100644
--- a/test/lisp/help-fns-tests.el
+++ b/test/lisp/help-fns-tests.el
@@ -123,4 +123,32 @@ Return first line of the output of (describe-function-1 FUNC)."
123 (goto-char (point-min)) 123 (goto-char (point-min))
124 (should (looking-at "^font-lock-comment-face is ")))) 124 (should (looking-at "^font-lock-comment-face is "))))
125 125
126
127;;; Tests for describe-keymap
128(ert-deftest help-fns-test-describe-keymap/symbol ()
129 (describe-keymap 'minibuffer-local-must-match-map)
130 (with-current-buffer "*Help*"
131 (should (looking-at "^minibuffer-local-must-match-map is"))))
132
133(ert-deftest help-fns-test-describe-keymap/value ()
134 (describe-keymap minibuffer-local-must-match-map)
135 (with-current-buffer "*Help*"
136 (should (looking-at "^key"))))
137
138(ert-deftest help-fns-test-describe-keymap/not-keymap ()
139 (should-error (describe-keymap nil))
140 (should-error (describe-keymap emacs-version)))
141
142(ert-deftest help-fns-test-describe-keymap/let-bound ()
143 (let ((foobar minibuffer-local-must-match-map))
144 (describe-keymap foobar)
145 (with-current-buffer "*Help*"
146 (should (looking-at "^key")))))
147
148(ert-deftest help-fns-test-describe-keymap/dynamically-bound-no-file ()
149 (setq help-fns-test--describe-keymap-foo minibuffer-local-must-match-map)
150 (describe-keymap 'help-fns-test--describe-keymap-foo)
151 (with-current-buffer "*Help*"
152 (should (looking-at "^help-fns-test--describe-keymap-foo is"))))
153
126;;; help-fns-tests.el ends here 154;;; help-fns-tests.el ends here