diff options
| author | Stefan Kangas | 2019-08-24 01:02:04 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2020-02-04 02:04:20 +0100 |
| commit | 557b790e0a3fcb2cd4196a3119da3e92647f8def (patch) | |
| tree | f2b6aaf62ae10fea500af2c09296eab5f5a1ab37 /lisp | |
| parent | f9504ffba2e2604338c243dd77c877bbb8162e4a (diff) | |
| download | emacs-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>
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/help-fns.el | 59 |
1 files changed, 59 insertions, 0 deletions
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. | ||
| 1568 | When called interactively, prompt for a variable that has a | ||
| 1569 | keymap 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 | ||