From: Austin Clements Date: Thu, 29 Aug 2013 16:25:55 +0000 (+2000) Subject: [PATCH 7/9] emacs: Make notmuch-help work with arbitrary keymaps X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7820d6d536469edcbe9c6b4f5aee95c1d0187625;p=notmuch-archives.git [PATCH 7/9] emacs: Make notmuch-help work with arbitrary keymaps --- diff --git a/b4/9a40ec1d6ba536a15a2f150f0579897ad157f0 b/b4/9a40ec1d6ba536a15a2f150f0579897ad157f0 new file mode 100644 index 000000000..55b1db065 --- /dev/null +++ b/b4/9a40ec1d6ba536a15a2f150f0579897ad157f0 @@ -0,0 +1,159 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 3F0FB431FAE + for ; Thu, 29 Aug 2013 09:26:20 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 7ANK1-Ini9Ul for ; + Thu, 29 Aug 2013 09:26:16 -0700 (PDT) +Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu + [18.9.25.12]) + by olra.theworths.org (Postfix) with ESMTP id EC5EF431FCB + for ; Thu, 29 Aug 2013 09:26:05 -0700 (PDT) +X-AuditID: 1209190c-b7fac8e000006335-33-521f761d1598 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP + id 89.CE.25397.D167F125; Thu, 29 Aug 2013 12:26:05 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r7TGQ4xt023053; + Thu, 29 Aug 2013 12:26:04 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r7TGQ1Cl015001 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 29 Aug 2013 12:26:02 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1VF52n-0007Wz-4n; Thu, 29 Aug 2013 12:26:01 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 7/9] emacs: Make notmuch-help work with arbitrary keymaps +Date: Thu, 29 Aug 2013 12:25:55 -0400 +Message-Id: <1377793557-28878-8-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1377793557-28878-1-git-send-email-amdragon@mit.edu> +References: <1377793557-28878-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrCtbJh9ksPCjlsX1mzOZHRg9nq26 + xRzAGMVlk5Kak1mWWqRvl8CVcWU1X8F9qYoNk26xNTBuE+1i5OSQEDCROPtoDhuELSZx4d56 + IJuLQ0hgH6PEvjcXmCCcjYwSazrnsUM4d5gkZv49ygjhzGWUeH29kx2kn01AQ2Lb/uWMILaI + gLTEzruzWbsYOTiYBdQk/nSpgISFBTwlLv59AlbOIqAq8f3VfzCbV8BBYu38ucwQZyhKdD+b + AHYSp4CjRP/dtywgthBQzZ+LT9knMPIvYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuol5tZ + opeaUrqJERw0kjw7GN8cVDrEKMDBqMTD2xEoHyTEmlhWXJl7iFGSg0lJlDewBCjEl5SfUpmR + WJwRX1Sak1p8iFGCg1lJhPctJ1CONyWxsiq1KB8mJc3BoiTO+/Tp2UAhgfTEktTs1NSC1CKY + rAwHh5IEb3wpUKNgUWp6akVaZk4JQpqJgxNkOA/Q8HKQGt7igsTc4sx0iPwpRkUpcd48kIQA + SCKjNA+uFxbVrxjFgV4R5pUEqeIBJgS47ldAg5mABk/IlwMZXJKIkJJqYGwzDFXZVVfg8LHl + 0tEn/ca1KYwCzd8vTb3UmJHnuWNL1jsP9Yurar8xp1rYRmbPe1Zv6rUlcyvbkoYeFf7S3qCT + vnpOW3Yet3PRrGTf9+74ki8cNU5S01d5rL30qKxu9un9oeuZrHYsPtC3vaTsRt7PGSG1k4vv + TNCIr3rRqPE0wJAr76xgmRJLcUaioRZzUXEiADIvnLHFAgAA +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 29 Aug 2013 16:26:20 -0000 + +This converts notmuch-help to use map-keymap for all keymap traversal. +This generally cleans up and simplifies construction of keymap +documentation, and also makes notmuch-help support anything that can +be in a keymap, including more esoteric stuff like multiple +inheritance. +--- + emacs/notmuch.el | 58 +++++++++++++++++++++--------------------------------- + 1 file changed, 22 insertions(+), 36 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 80446be..0304096 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -140,48 +140,34 @@ This is basically just `format-kbd-macro' but we also convert ESC to M-." + "M-" + (concat desc " ")))) + +-;; I would think that emacs would have code handy for walking a keymap +-;; and generating strings for each key, and I would prefer to just call +-;; that. But I couldn't find any (could be all implemented in C I +-;; suppose), so I wrote my own here. +-(defun notmuch-substitute-one-command-key-with-prefix (prefix binding) +- "For a key binding, return a string showing a human-readable +-representation of the prefixed key as well as the first line of +-documentation from the bound function. +- +-For a mouse binding, return nil." +- (let ((key (car binding)) +- (action (cdr binding))) +- (if (mouse-event-p key) +- nil +- (if (keymapp action) +- (let ((substitute (apply-partially 'notmuch-substitute-one-command-key-with-prefix (notmuch-prefix-key-description key))) +- (as-list)) +- (map-keymap (lambda (a b) +- (push (cons a b) as-list)) +- action) +- (mapconcat substitute as-list "\n")) +- (concat prefix (format-kbd-macro (vector key)) +- "\t" +- (notmuch-documentation-first-line action)))))) +- +-(defun notmuch-substitute-command-keys-one (key) +- ;; A `keymap' key indicates inheritance from a parent keymap - the +- ;; inherited mappings follow, so there is nothing to print for +- ;; `keymap' itself. +- (when (not (eq key 'keymap)) +- (notmuch-substitute-one-command-key-with-prefix nil key))) ++(defun notmuch-describe-keymap (keymap &optional prefix tail) ++ "Return a list of strings, each describing one key in KEYMAP. ++ ++Each string gives a human-readable description of the key and the ++first line of documentation for the bound function." ++ (map-keymap ++ (lambda (key binding) ++ (cond ((mouse-event-p key) nil) ++ ((keymapp binding) ++ (setq tail ++ (notmuch-describe-keymap ++ binding (notmuch-prefix-key-description key) tail))) ++ (t ++ (push (concat prefix (format-kbd-macro (vector key)) "\t" ++ (notmuch-documentation-first-line binding)) ++ tail)))) ++ keymap) ++ tail) + + (defun notmuch-substitute-command-keys (doc) + "Like `substitute-command-keys' but with documentation, not function names." + (let ((beg 0)) + (while (string-match "\\\\{\\([^}[:space:]]*\\)}" doc beg) + (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1))) +- (keymap (symbol-value (intern keymap-name)))) +- (setq doc (replace-match +- (mapconcat #'notmuch-substitute-command-keys-one +- (cdr keymap) "\n") +- 1 1 doc))) ++ (keymap (symbol-value (intern keymap-name))) ++ (desc-list (notmuch-describe-keymap keymap)) ++ (desc (mapconcat #'identity desc-list "\n"))) ++ (setq doc (replace-match desc 1 1 doc))) + (setq beg (match-end 0))) + doc)) + +-- +1.7.10.4 +