Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / a0 / f723101ef9a3c1abd36578843a1ebb511064b6
1 Return-Path: <jani@nikula.org>\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 12D38431FBF\r
6         for <notmuch@notmuchmail.org>; Sat, 29 Sep 2012 15:44:33 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id yNF91DCDK6yv for <notmuch@notmuchmail.org>;\r
16         Sat, 29 Sep 2012 15:44:31 -0700 (PDT)\r
17 Received: from mail-la0-f53.google.com (mail-la0-f53.google.com\r
18         [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id DFD1E431FBC\r
21         for <notmuch@notmuchmail.org>; Sat, 29 Sep 2012 15:44:30 -0700 (PDT)\r
22 Received: by lahl5 with SMTP id l5so1764378lah.26\r
23         for <notmuch@notmuchmail.org>; Sat, 29 Sep 2012 15:44:27 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=google.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state;\r
27         bh=F/r4f7Sko/+5gg0Qbrd2wDMOVTWf1s9WA7cDqQbN6Jk=;\r
28         b=ZqV0pOZsB5Hb5rHGLFnrElo1czx1aKuntWXa1pNDgOB6mxMtaAjKKRwoah/nek5aEb\r
29         JxVDJvXyLoG3/bdwmFrjMXKTAXQWPGLB8tTpMvq5aolD2CYwJoJAJHr4rVx/1CIFe9kv\r
30         lUKRN3xK2Qai6YOouVXC4FHqsVm6XV6iFDEhaxvIazsVuUZy5RHE6VOijCtj+HwpU9vZ\r
31         1vdDvz4LvsCOugM8jzSC+6vXsEclNjX6sBaVaMjyORlOVVin4zm3zmlEwKyjW7z/7z36\r
32         ZOTBMzUbFtGbKYbZMPv7B9HIQz2wXdCSo1ZdOWtyxy2wsPeS7Ti+XJHuynHYGyhN9I1R\r
33         l68g==\r
34 Received: by 10.152.104.44 with SMTP id gb12mr8685384lab.29.1348958667882;\r
35         Sat, 29 Sep 2012 15:44:27 -0700 (PDT)\r
36 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
37         [80.223.81.27])\r
38         by mx.google.com with ESMTPS id i3sm3400208lbg.10.2012.09.29.15.44.26\r
39         (version=SSLv3 cipher=OTHER); Sat, 29 Sep 2012 15:44:27 -0700 (PDT)\r
40 From: Jani Nikula <jani@nikula.org>\r
41 To: notmuch@notmuchmail.org\r
42 Subject: [PATCH] emacs: simplify point placement in notmuch-hello refresh\r
43 Date: Sun, 30 Sep 2012 01:44:24 +0300\r
44 Message-Id: <1348958664-1767-1-git-send-email-jani@nikula.org>\r
45 X-Mailer: git-send-email 1.7.9.5\r
46 X-Gm-Message-State:\r
47  ALoCoQkuff16wuETSKd1EsxI5UhEhqmspvDEE0U124DMyDW8ZJlpcM+QXNesXEBOTcbXhGS+l8dM\r
48 X-BeenThere: notmuch@notmuchmail.org\r
49 X-Mailman-Version: 2.1.13\r
50 Precedence: list\r
51 List-Id: "Use and development of the notmuch mail system."\r
52         <notmuch.notmuchmail.org>\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
56 List-Post: <mailto:notmuch@notmuchmail.org>\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
60 X-List-Received-Date: Sat, 29 Sep 2012 22:44:33 -0000\r
61 \r
62 notmuch-hello (called also through notmuch-hello-update, bound to '='\r
63 by default) tries to find the widget under or following point before\r
64 refresh, and put the point back to the widget afterwards. The code has\r
65 grown quite complicated, and has at least the following issues:\r
66 \r
67 1) All the individual section functions have to include code to\r
68    support point placement. If there is no such support, point is\r
69    dropped to the search box. Only saved searches and all tags\r
70    sections support point placement.\r
71 \r
72 2) Point placement is based on widget-value. If there are two widgets\r
73    with the same widget-value (for example a saved search with the\r
74    same name as a tag) the point is moved to the earlier one, even if\r
75    point was on the later one.\r
76 \r
77 3) When first entering notmuch-hello notmuch-hello-target is nil, and\r
78    point is dropped to the search box.\r
79 \r
80 Moving the point to the search box is annoying because the user is\r
81 required to move the point before being able to enter key bindings.\r
82 \r
83 Simplify the code by removing all point placement based on widgets, as\r
84 it does not work properly, and trying to fix that would unnecessarily\r
85 complicate the code.\r
86 \r
87 Point is simply saved before refresh, and put back to where it\r
88 was. Sometimes, if notmuch-show-empty-saved-searches is nil, and the\r
89 refresh adds or removes saved searches from the list, this has the\r
90 appearance of moving the point relative to the nearest widgets. This\r
91 is a much smaller and less frequent problem than the ones listed\r
92 above.\r
93 \r
94 ---\r
95 \r
96 I've sent this before months ago, and received comments starting at\r
97 id:"87aa2aohjs.fsf@gmail.com". I find the current behaviour annoying,\r
98 and I prefer this simple fix over complicating the existing\r
99 mess. Nobody has stood up to do anything better anyway. Perhaps we\r
100 could take a step forward with this while waiting for Someone(tm) to\r
101 come up with the perfect point placement?\r
102 ---\r
103  emacs/notmuch-hello.el |   70 ++++++++++++------------------------------------\r
104  1 file changed, 17 insertions(+), 53 deletions(-)\r
105 \r
106 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
107 index 684bedc..04d90cf 100644\r
108 --- a/emacs/notmuch-hello.el\r
109 +++ b/emacs/notmuch-hello.el\r
110 @@ -154,11 +154,6 @@ International Bureau of Weights and Measures."\r
111  (defvar notmuch-hello-url "http://notmuchmail.org"\r
112    "The `notmuch' web site.")\r
113  \r
114 -(defvar notmuch-hello-search-pos nil\r
115 -  "Position of search widget, if any.\r
116 -\r
117 -This should only be set by `notmuch-hello-insert-search'.")\r
118 -\r
119  (defvar notmuch-hello-custom-section-options\r
120    '((:filter (string :tag "Filter for each tag"))\r
121      (:filter-count (string :tag "Different filter to generate message counts"))\r
122 @@ -209,11 +204,8 @@ function produces a section simply by adding content to the current\r
123  buffer.  A section should not end with an empty line, because a\r
124  newline will be inserted after each section by `notmuch-hello'.\r
125  \r
126 -Each function should take no arguments.  If the produced section\r
127 -includes `notmuch-hello-target' (i.e. cursor should be positioned\r
128 -inside this section), the function should return this element's\r
129 -position.\r
130 -Otherwise, it should return nil.\r
131 +Each function should take no arguments. The return value is\r
132 +ignored.\r
133  \r
134  For convenience an element can also be a list of the form (FUNC ARG1\r
135  ARG2 .. ARGN) in which case FUNC will be applied to the rest of the\r
136 @@ -240,15 +232,6 @@ supported for \"Customized queries section\" items."\r
137             notmuch-hello-query-section\r
138             (function :tag "Custom section"))))\r
139  \r
140 -(defvar notmuch-hello-target nil\r
141 -  "Button text at position of point before rebuilding the notmuch-buffer.\r
142 -\r
143 -This variable contains the text of the button, if any, the\r
144 -point was positioned at before the notmuch-hello buffer was\r
145 -rebuilt. This should never actually be global and is defined as a\r
146 -defvar only for documentation purposes and to avoid a compiler\r
147 -warning about it occurring as a free variable.")\r
148 -\r
149  (defvar notmuch-hello-hidden-sections nil\r
150    "List of sections titles whose contents are hidden")\r
151  \r
152 @@ -449,8 +432,6 @@ Such a list can be computed with `notmuch-hello-query-counts'."\r
153                      (msg-count (third elem)))\r
154                 (widget-insert (format "%8s "\r
155                                        (notmuch-hello-nice-number msg-count)))\r
156 -               (if (string= name notmuch-hello-target)\r
157 -                   (setq found-target-pos (point-marker)))\r
158                 (widget-create 'push-button\r
159                                :notify #'notmuch-hello-widget-search\r
160                                :notmuch-search-terms query\r
161 @@ -589,7 +570,6 @@ Complete list of currently available key bindings:\r
162  (defun notmuch-hello-insert-search ()\r
163    "Insert a search widget."\r
164    (widget-insert "Search: ")\r
165 -  (setq notmuch-hello-search-pos (point-marker))\r
166    (widget-create 'editable-field\r
167                  ;; Leave some space at the start and end of the\r
168                  ;; search boxes.\r
169 @@ -763,13 +743,7 @@ following:\r
170        (set-buffer "*notmuch-hello*")\r
171      (switch-to-buffer "*notmuch-hello*"))\r
172  \r
173 -  (let ((notmuch-hello-target (if (widget-at)\r
174 -                                 (widget-value (widget-at))\r
175 -                               (condition-case nil\r
176 -                                   (progn\r
177 -                                     (widget-forward 1)\r
178 -                                     (widget-value (widget-at)))\r
179 -                                 (error nil))))\r
180 +  (let ((final-target-pos (point))\r
181         (inhibit-read-only t))\r
182  \r
183      ;; Delete all editable widget fields.  Editable widget fields are\r
184 @@ -788,30 +762,20 @@ following:\r
185        (mapc 'delete-overlay (car all))\r
186        (mapc 'delete-overlay (cdr all)))\r
187  \r
188 -    (let (final-target-pos)\r
189 -      (mapc\r
190 -       (lambda (section)\r
191 -        (let ((point-before (point))\r
192 -              (result (if (functionp section)\r
193 -                          (funcall section)\r
194 -                        (apply (car section) (cdr section)))))\r
195 -          (if (and (not final-target-pos) (integer-or-marker-p result))\r
196 -              (setq final-target-pos result))\r
197 -          ;; don't insert a newline when the previous section didn't show\r
198 -          ;; anything.\r
199 -          (unless (eq (point) point-before)\r
200 -            (widget-insert "\n"))))\r
201 -       notmuch-hello-sections)\r
202 -      (widget-setup)\r
203 -\r
204 -      (when final-target-pos\r
205 -       (goto-char final-target-pos)\r
206 -       (unless (widget-at)\r
207 -         (widget-forward 1)))\r
208 -\r
209 -      (unless (widget-at)\r
210 -       (when notmuch-hello-search-pos\r
211 -         (goto-char notmuch-hello-search-pos)))))\r
212 +    (mapc\r
213 +     (lambda (section)\r
214 +       (let ((point-before (point)))\r
215 +        (if (functionp section)\r
216 +            (funcall section)\r
217 +          (apply (car section) (cdr section)))\r
218 +        ;; don't insert a newline when the previous section didn't\r
219 +        ;; show anything.\r
220 +        (unless (eq (point) point-before)\r
221 +          (widget-insert "\n"))))\r
222 +     notmuch-hello-sections)\r
223 +    (widget-setup)\r
224 +\r
225 +    (goto-char final-target-pos))\r
226    (run-hooks 'notmuch-hello-refresh-hook)\r
227    (setq notmuch-hello-first-run nil))\r
228  \r
229 -- \r
230 1.7.9.5\r
231 \r