[PATCH 4/6] emacs: Support overriding help and describing prefix action
authorAustin Clements <amdragon@MIT.EDU>
Sun, 6 Oct 2013 03:22:46 +0000 (23:22 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:57:15 +0000 (09:57 -0800)
93/3529132b5d68fd09ef746e64f21722a32c80da [new file with mode: 0644]

diff --git a/93/3529132b5d68fd09ef746e64f21722a32c80da b/93/3529132b5d68fd09ef746e64f21722a32c80da
new file mode 100644 (file)
index 0000000..9bede2f
--- /dev/null
@@ -0,0 +1,163 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 6F1CD431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Oct 2013 20:23:03 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id qmOxs4DTKSO6 for <notmuch@notmuchmail.org>;\r
+       Sat,  5 Oct 2013 20:22:57 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0F962431FBC\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Oct 2013 20:22:56 -0700 (PDT)\r
+X-AuditID: 12074423-b7fc98e0000009a2-82-5250d78fe7e2\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 4E.46.02466.F87D0525; Sat,  5 Oct 2013 23:22:55 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r963MrQe012799; \r
+       Sat, 5 Oct 2013 23:22:54 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r963MpQI024420\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 5 Oct 2013 23:22:53 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1VSevj-00037t-QP; Sat, 05 Oct 2013 23:22:51 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/6] emacs: Support overriding help and describing prefix\r
+       action\r
+Date: Sat,  5 Oct 2013 23:22:46 -0400\r
+Message-Id: <1381029768-11883-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <1381029768-11883-1-git-send-email-amdragon@mit.edu>\r
+References: <1381029768-11883-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixG6nott/PSDIoP2ppsX1mzOZHRg9nq26\r
+       xRzAGMVlk5Kak1mWWqRvl8CVMe3KM8aC//IVi868YmlgfC7ZxcjJISFgItH87QEzhC0mceHe\r
+       ejYQW0hgH6PEi82WXYxcQPYGRokJ19tZIZzbTBIX55xih3DmMkrMPfYXrJ1NQENi2/7ljCC2\r
+       iIC0xM67s4E6ODiYBdQk/nSpgISFBQIkbrTOZwexWQRUJXq3H2YBsXkFHCT2XWhjgbhCSWLh\r
+       qW2sIDangKPE5lNvGCEucpC4vvw54wRG/gWMDKsYZVNyq3RzEzNzilOTdYuTE/PyUot0zfRy\r
+       M0v0UlNKNzGCg8ZFeQfjn4NKhxgFOBiVeHgdvAKChFgTy4orcw8xSnIwKYnyTr8KFOJLyk+p\r
+       zEgszogvKs1JLT7EKMHBrCTCy1IAlONNSaysSi3Kh0lJc7AoifPe4rAPEhJITyxJzU5NLUgt\r
+       gsnKcHAoSfD2XANqFCxKTU+tSMvMKUFIM3FwggznARo+GaSGt7ggMbc4Mx0if4pRUUqcdzZI\r
+       QgAkkVGaB9cLi+pXjOJArwjzbgep4gEmBLjuV0CDmYAGR0n4ggwuSURISTUwsp0qypv+fdMG\r
+       gcCu8tXbndU5+N8378huWeD16mnRflvhdRUSsW3/eUSWMK9zW7nTgTHkAe/23FkzzVy4Rebz\r
+       nw97s+Wqh0rq2qcWjnvOr1t9Z57vkr7ZGfF3hGX5edxYZ8zatijynf16B6/impWRqVGVW9Yy\r
+       sRqs/XuK44ybkXDA8YZPf2/2KbEUZyQaajEXFScCAIcdGEHFAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 06 Oct 2013 03:23:03 -0000\r
+\r
+Traditionally, function documentation strings are intended primarily\r
+for programmers, rather than users.  They're written from the\r
+perspective of calling the function, not interactively invoking it.\r
+They're only ever displayed along with the function prototype (and\r
+often refer to argument names).  And built-in help commands like\r
+`describe-bindings' show the name of the command, not its\r
+documentation.\r
+\r
+The notmuch help system is like `describe-bindings', but tries to be\r
+more user-friendly by displaying documentation strings, rather than\r
+Elisp command names.  For most commands, this is fine, but for some\r
+the "programmer description" is inappropriate for interactive use.\r
+This is particularly noticeable for commands that take an optional\r
+prefix argument.\r
+\r
+This patch adds support for two symbol properties: notmuch-doc and\r
+notmuch-prefix-doc, which let a command override its interactive\r
+documentation and provide separate documentation for its prefixed\r
+invocation.  If notmuch-prefix-doc is present, we add an extra line to\r
+the help giving the prefixed key sequence along with the documentation\r
+for the prefixed command.\r
+---\r
+ emacs/notmuch.el | 29 ++++++++++++++++++++++++-----\r
+ 1 file changed, 24 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index a36849f..278bd35 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -140,7 +140,7 @@ This is basically just `format-kbd-macro' but we also convert ESC to M-."\r
+       "M-"\r
+       (concat desc " "))))\r
\r
+-(defun notmuch-describe-keymap (keymap &optional prefix tail)\r
++(defun notmuch-describe-keymap (keymap ua-keys &optional prefix tail)\r
+   "Return a list of strings, each describing one key in KEYMAP.\r
\r
+ Each string gives a human-readable description of the key and the\r
+@@ -151,10 +151,19 @@ first line of documentation for the bound function."\r
+          ((keymapp binding)\r
+           (setq tail\r
+                 (notmuch-describe-keymap\r
+-                 binding (notmuch-prefix-key-description key) tail)))\r
++                 binding ua-keys (notmuch-prefix-key-description key) tail)))\r
+          (t\r
++          (when (and ua-keys (symbolp binding)\r
++                     (get binding 'notmuch-prefix-doc))\r
++            ;; Documentation for prefixed command\r
++            (let ((ua-desc (key-description ua-keys)))\r
++              (push (concat ua-desc " " prefix (format-kbd-macro (vector key))\r
++                            "\t" (get binding 'notmuch-prefix-doc))\r
++                    tail)))\r
++          ;; Documentation for command\r
+           (push (concat prefix (format-kbd-macro (vector key)) "\t"\r
+-                        (notmuch-documentation-first-line binding))\r
++                        (or (and (symbolp binding) (get binding 'notmuch-doc))\r
++                            (notmuch-documentation-first-line binding)))\r
+                 tail))))\r
+    keymap)\r
+   tail)\r
+@@ -165,14 +174,24 @@ first line of documentation for the bound function."\r
+     (while (string-match "\\\\{\\([^}[:space:]]*\\)}" doc beg)\r
+       (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1)))\r
+            (keymap (symbol-value (intern keymap-name)))\r
+-           (desc-list (notmuch-describe-keymap keymap))\r
++           (ua-keys (where-is-internal 'universal-argument keymap t))\r
++           (desc-list (notmuch-describe-keymap keymap ua-keys))\r
+            (desc (mapconcat #'identity desc-list "\n")))\r
+       (setq doc (replace-match desc 1 1 doc)))\r
+       (setq beg (match-end 0)))\r
+     doc))\r
\r
+ (defun notmuch-help ()\r
+-  "Display help for the current notmuch mode."\r
++  "Display help for the current notmuch mode.\r
++\r
++This is similar to `describe-function' for the current major\r
++mode, but bindings tables are shown with documentation strings\r
++rather than command names.  By default, this uses the first line\r
++of each command's documentation string.  A command can override\r
++this by setting the 'notmuch-doc property of its command symbol.\r
++A command that supports a prefix argument can explicitly document\r
++its prefixed behavior by setting the 'notmuch-prefix-doc property\r
++of its command symbol."\r
+   (interactive)\r
+   (let* ((mode major-mode)\r
+        (doc (substitute-command-keys (notmuch-substitute-command-keys (documentation mode t)))))\r
+-- \r
+1.8.4.rc3\r
+\r