[PATCH 2/4] emacs: help: remove duplicate bindings
[notmuch-archives.git] / a0 / f1851e965f7befc858b7265553fae270bc9f01
1 Return-Path: <markwalters1009@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id CF7AB429E57\r
6         for <notmuch@notmuchmail.org>; Sat, 26 Oct 2013 14:04:58 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id 48Nrk3-MgERl for <notmuch@notmuchmail.org>;\r
18         Sat, 26 Oct 2013 14:04:53 -0700 (PDT)\r
19 Received: from mail-we0-f179.google.com (mail-we0-f179.google.com\r
20         [74.125.82.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id AFE23429E47\r
23         for <notmuch@notmuchmail.org>; Sat, 26 Oct 2013 14:04:47 -0700 (PDT)\r
24 Received: by mail-we0-f179.google.com with SMTP id w61so5062816wes.24\r
25         for <notmuch@notmuchmail.org>; Sat, 26 Oct 2013 14:04:46 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
28         bh=+yXaox7AUCm5wiR6xrev3R5WVdGZ2LBVWcjywzsciYg=;\r
29         b=dhzUMmXv9fPcAvBgxCLwvXABr4R6Bg7aQhgg69ccNK2GAG52MS58I60WFhSKk44R8x\r
30         2fWGzsdHbpzibMRiA9GQVTY2cyxsjL0pD15xvvINempMKtfWcpXuG7U6e5MaJRhb7KK/\r
31         +enfSDK01qrPQobsMhln/dStMl19JokdEqn72066z1yDganIJHHm82gBcr44sE70Eu8B\r
32         6QTcdDJWckRwcc04+tS6SpWZp7y9KmXbfra4A0IrqqT0z3RcOw5B7CsWj/P+ilqPmm7N\r
33         OiM25MlFtzz4juOOCBRMPc23FYybftO12pUgJmhfXmM+YLOgDqL9dAV4c8iLdjbkG3x2\r
34         URgg==\r
35 X-Received: by 10.180.182.15 with SMTP id ea15mr3440104wic.16.1382821486349;\r
36         Sat, 26 Oct 2013 14:04:46 -0700 (PDT)\r
37 Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
38         by mx.google.com with ESMTPSA id ev4sm19391972wib.7.2013.10.26.14.04.45\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sat, 26 Oct 2013 14:04:46 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 2/4] emacs: help: remove duplicate bindings\r
45 Date: Sat, 26 Oct 2013 22:04:37 +0100\r
46 Message-Id: <1382821479-23384-3-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.9.1\r
48 In-Reply-To: <1382821479-23384-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1382821479-23384-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sat, 26 Oct 2013 21:04:59 -0000\r
63 \r
64 If the user (or a mode) overrides a keybinding from the common keymap\r
65 in one of the modes then both help lines appear in the help screen\r
66 even though only one of the is applicable.\r
67 \r
68 Fix this by checking if we already have that key binding. We do this\r
69 by constructing an list of (key . docstring) pairs so it is easy to\r
70 check if we have already had that binding. Then the actual print help\r
71 routine changes these pairs into strings "key \t docstring"\r
72 ---\r
73  emacs/notmuch.el |   38 ++++++++++++++++++++++----------------\r
74  1 files changed, 22 insertions(+), 16 deletions(-)\r
75 \r
76 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
77 index f98f8cf..b9db9ba 100644\r
78 --- a/emacs/notmuch.el\r
79 +++ b/emacs/notmuch.el\r
80 @@ -141,11 +141,12 @@ This is basically just `format-kbd-macro' but we also convert ESC to M-."\r
81        (concat desc " "))))\r
82  \r
83  (defun notmuch-describe-keymap (keymap ua-keys &optional prefix tail)\r
84 -  "Return a list of strings, each describing one binding in KEYMAP.\r
85 +  "Return a list of cons cells, each describing one binding in KEYMAP.\r
86  \r
87 -Each string gives a human-readable description of the key and a\r
88 -one-line description of the bound function.  See `notmuch-help'\r
89 -for an overview of how this documentation is extracted.\r
90 +Each cons cell consists of a string giving a human-readable\r
91 +description of the key, and a one-line description of the bound\r
92 +function.  See `notmuch-help' for an overview of how this\r
93 +documentation is extracted.\r
94  \r
95  UA-KEYS should be a key sequence bound to `universal-argument'.\r
96  It will be used to describe bindings of commands that support a\r
97 @@ -158,19 +159,23 @@ prefix argument.  PREFIX and TAIL are used internally."\r
98                   (notmuch-describe-keymap\r
99                    binding ua-keys (notmuch-prefix-key-description key) tail)))\r
100            (t\r
101 -           (unless (not binding)\r
102 -             (when (and ua-keys (symbolp binding)\r
103 -                        (get binding 'notmuch-prefix-doc))\r
104 -               ;; Documentation for prefixed command\r
105 -               (let ((ua-desc (key-description ua-keys)))\r
106 -                 (push (concat ua-desc " " prefix (format-kbd-macro (vector key))\r
107 -                               "\t" (get binding 'notmuch-prefix-doc))\r
108 -                       tail)))\r
109 -             ;; Documentation for command\r
110 -             (push (concat prefix (format-kbd-macro (vector key)) "\t"\r
111 +           (let ((key-string (concat prefix (format-kbd-macro (vector key)))))\r
112 +             ;; We don't include documentation if the key-binding is\r
113 +             ;; over-ridden. Note, over-riding a binding\r
114 +             ;; automatically hides the prefixed version too.\r
115 +             (unless (or (assoc key-string tail) (not binding))\r
116 +               (when (and ua-keys (symbolp binding)\r
117 +                          (get binding 'notmuch-prefix-doc))\r
118 +                 ;; Documentation for prefixed command\r
119 +                 (let ((ua-desc (key-description ua-keys)))\r
120 +                   (push (cons (concat ua-desc " " prefix (format-kbd-macro (vector key)))\r
121 +                               (get binding 'notmuch-prefix-doc))\r
122 +                         tail)))\r
123 +               ;; Documentation for command\r
124 +               (push (cons key-string\r
125                             (or (and (symbolp binding) (get binding 'notmuch-doc))\r
126                                 (notmuch-documentation-first-line binding)))\r
127 -                   tail)))))\r
128 +                     tail))))))\r
129     keymap)\r
130    tail)\r
131  \r
132 @@ -181,7 +186,8 @@ prefix argument.  PREFIX and TAIL are used internally."\r
133        (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1)))\r
134              (keymap (symbol-value (intern keymap-name)))\r
135              (ua-keys (where-is-internal 'universal-argument keymap t))\r
136 -            (desc-list (notmuch-describe-keymap keymap ua-keys))\r
137 +            (desc-alist (notmuch-describe-keymap keymap ua-keys))\r
138 +            (desc-list (mapcar (lambda (arg) (concat (car arg) "\t" (cdr arg))) desc-alist))\r
139              (desc (mapconcat #'identity desc-list "\n")))\r
140         (setq doc (replace-match desc 1 1 doc)))\r
141        (setq beg (match-end 0)))\r
142 -- \r
143 1.7.9.1\r
144 \r