From: Stefan Kangas <stefan@marxist.se>
To: Drew Adams <drew.adams@oracle.com>
Cc: 30660@debbugs.gnu.org, "積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Subject: bug#30660: mention describe-bindings on (info "(emacs) Keymaps")
Date: Sat, 24 Aug 2019 05:01:28 +0200 [thread overview]
Message-ID: <CADwFkmk9d-1pELNOzj0cngTALgBJ_HrLu=JEb5HE3sp6Jcdphg@mail.gmail.com> (raw)
In-Reply-To: <831b5f34-28c7-4753-bed9-0a28de484aa8@default>
[-- Attachment #1: Type: text/plain, Size: 274 bytes --]
Drew Adams <drew.adams@oracle.com> writes:
> KEYMAP can be a keymap, instead of a symbol.
Thanks for the clarifications.
I've now packaged up a proposed patch with some cleanups and
adaptions. It would be great if someone could review this.
Best regards,
Stefan Kangas
[-- Attachment #2: 0001-Add-new-help-function-describe-keymap.patch --]
[-- Type: application/octet-stream, Size: 5165 bytes --]
From 91f4a8f10e2aa0df9ceee1c8c823ef82b856c122 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Sat, 24 Aug 2019 01:02:04 +0200
Subject: [PATCH] Add new help function describe-keymap
This code was written by Drew Adams with minor cleanups and stylistic
changes by Stefan Kangas.
Ref: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30660
* lisp/help-fns.el (describe-keymap): New function to show key
bindings for a given keymap. (Bug#30660)
* lisp/help.el (help-map): Bind the new function to "C-h M".
* lisp/help.el (help-for-help-internal): Document what "C-h M" does
when user types "C-h C-h".
---
lisp/help-fns.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
lisp/help.el | 2 ++
2 files changed, 68 insertions(+)
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 90a3571520..b64bbbe4c6 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -1390,6 +1390,72 @@ describe-categories
(insert "\nThe parent category table is:")
(describe-vector table 'help-describe-category-set))))))
+;;;###autoload
+(defun describe-keymap (keymap &optional search-symbols-p)
+ "Describe key bindings in KEYMAP.
+When called interactively, prompt for a variable that has a
+keymap value. Completion is available for the variable name.
+
+If optional argument SEARCH-SYMBOLS-P is non-nil, and KEYMAP is
+not a symbol, search all variables for one whose value is KEYMAP
+and use that to describe the key bindings. This makes it
+possible to not only see the bindings but also to identify the
+name of the keymap in question."
+ (interactive (list
+ (intern (completing-read "Keymap: " obarray
+ (lambda (m)
+ (and (boundp m)
+ (keymapp (symbol-value m))))
+ t nil 'variable-name-history))))
+ (unless (and (symbolp keymap)
+ (boundp keymap)
+ (keymapp (symbol-value keymap)))
+ (if (not (keymapp keymap))
+ (if (symbolp keymap)
+ (error "Not a keymap variable: %S" keymap)
+ (error "Not a keymap"))
+ (let ((sym nil))
+ (when search-symbols-p
+ (setq sym (catch 'describe-keymap
+ (mapatoms (lambda (symb)
+ (when (and (boundp symb)
+ (eq (symbol-value symb) keymap)
+ (not (eq symb 'keymap))
+ (throw 'describe-keymap symb)))))
+ nil)))
+ (unless sym
+ (setq sym (cl-gentemp "KEYMAP OBJECT (no variable) "))
+ (set sym keymap))
+ (setq keymap sym))))
+ ;; Follow aliasing.
+ (setq keymap (or (ignore-errors (indirect-variable keymap)) keymap))
+ (let* ((name (symbol-name keymap))
+ (doc (documentation-property keymap 'variable-documentation))
+ (file-name (find-lisp-object-file-name keymap 'defvar)))
+ (help-setup-xref (list #'describe-keymap keymap)
+ (called-interactively-p 'interactive))
+ (with-help-window (help-buffer)
+ (princ (format-message "%S" keymap))
+ (princ (format-message
+ " is a keymap variable defined in `%s'.\n\n"
+ (if (eq file-name 'C-source)
+ "C source code"
+ (file-name-nondirectory file-name))))
+ (with-current-buffer standard-output
+ (save-excursion
+ (re-search-backward (substitute-command-keys
+ "`\\([^`']+\\)'")
+ nil t)
+ (help-xref-button 1 'help-variable-def
+ keymap file-name)))
+ (when (and (not (equal "" doc)) doc)
+ (princ "Documentation:\n")
+ (princ (format-message "%s\n\n" doc)))
+ ;; Use `insert' instead of `princ', so control chars (e.g. \377)
+ ;; insert correctly.
+ (with-current-buffer "*Help*"
+ (insert (substitute-command-keys (concat "\\{" name "}")))))))
+
\f
;;; Replacements for old lib-src/ programs. Don't seem especially useful.
diff --git a/lisp/help.el b/lisp/help.el
index e40178de96..18f1219ca0 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -96,6 +96,7 @@ help-map
(define-key map "k" 'describe-key)
(define-key map "l" 'view-lossage)
(define-key map "m" 'describe-mode)
+ (define-key map "M" 'describe-keymap)
(define-key map "o" 'describe-symbol)
(define-key map "n" 'view-emacs-news)
(define-key map "p" 'finder-by-keyword)
@@ -219,6 +220,7 @@ 'help-for-help
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.
+M KEYMAP Describe the given keymap and its bindings.
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.
--
2.22.0
next prev parent reply other threads:[~2019-08-24 3:01 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-28 20:25 bug#30660: mention describe-bindings on (info "(emacs) Keymaps") 積丹尼 Dan Jacobson
2018-02-28 23:29 ` Drew Adams
2019-08-23 7:18 ` Stefan Kangas
2019-08-23 18:44 ` Drew Adams
2019-08-23 22:40 ` Stefan Kangas
2019-08-24 1:46 ` Drew Adams
2019-08-24 3:01 ` Stefan Kangas [this message]
2019-08-24 15:06 ` Drew Adams
2019-10-16 22:42 ` Stefan Kangas
2019-10-14 20:28 ` Lars Ingebrigtsen
2019-10-14 20:33 ` Eli Zaretskii
2019-10-17 9:39 ` Stefan Kangas
2019-10-17 9:42 ` Stefan Kangas
2019-10-17 12:07 ` Robert Pluim
2019-10-17 13:10 ` Eli Zaretskii
2019-10-17 13:30 ` Stefan Kangas
2019-11-07 0:18 ` Stefan Kangas
2019-11-07 0:40 ` Drew Adams
2019-10-17 13:00 ` Eli Zaretskii
2019-11-07 1:00 ` Stefan Kangas
2019-11-11 15:04 ` Stefan Kangas
2019-11-14 11:12 ` Eli Zaretskii
2019-11-17 20:36 ` Stefan Kangas
2019-11-18 16:23 ` Eli Zaretskii
2019-11-19 6:07 ` Richard Stallman
2019-11-19 16:04 ` Eli Zaretskii
2019-11-17 20:51 ` Stefan Kangas
2019-11-18 16:20 ` Eli Zaretskii
2019-11-19 14:14 ` Stefan Kangas
2019-11-19 17:03 ` Eli Zaretskii
[not found] ` <87zhen2h81.fsf@marxist.se>
2020-01-17 8:07 ` Eli Zaretskii
2020-01-18 2:16 ` Stefan Kangas
2020-01-18 8:31 ` Eli Zaretskii
2020-01-18 9:12 ` Stefan Kangas
2020-01-18 9:41 ` Eli Zaretskii
2020-01-18 23:42 ` Stefan Kangas
2020-01-19 2:09 ` Drew Adams
2020-01-31 10:15 ` Eli Zaretskii
2020-02-04 1:32 ` Stefan Kangas
2019-10-14 20:50 ` Drew Adams
2019-10-16 22:48 ` Stefan Kangas
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADwFkmk9d-1pELNOzj0cngTALgBJ_HrLu=JEb5HE3sp6Jcdphg@mail.gmail.com' \
--to=stefan@marxist.se \
--cc=30660@debbugs.gnu.org \
--cc=drew.adams@oracle.com \
--cc=jidanni@jidanni.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.