Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 22 / 2b7e2871686c124a04c9cb8c58bc5d43a59e18
1 Return-Path: <dmitry.kurochkin@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 88FF1431FB6\r
6         for <notmuch@notmuchmail.org>; Tue, 17 Apr 2012 02:06:36 -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.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id BVIk8pujlIwU for <notmuch@notmuchmail.org>;\r
17         Tue, 17 Apr 2012 02:06:32 -0700 (PDT)\r
18 Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
19         [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id D7EB7431FAE\r
22         for <notmuch@notmuchmail.org>; Tue, 17 Apr 2012 02:06:31 -0700 (PDT)\r
23 Received: by lbdb5 with SMTP id b5so1760128lbd.26\r
24         for <notmuch@notmuchmail.org>; Tue, 17 Apr 2012 02:06:30 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
27         :mime-version:content-type;\r
28         bh=wRBPB2EEMEQaXTLKjKIq4GRxfKv+b6jRCRn/thl/mIg=;\r
29         b=eQNxLBpCsRwvv/eJMAyu1esaqKs2rRAnnvOZWTun6K6f7YCXCBZhx5hWf2xN/Ir0eF\r
30         eQ1ImeGCynmWkNeWFPP/k1KWgERecarVGUzpSyNFmGoPpr1mMT12bKotyPqW4ypWZfRc\r
31         yOOgLI1SMFQ+cQUuYnJOGsBtarLSZze8K61dKaeC93hi3c4JdkDJfOLnYCx3G0u+85il\r
32         X1cnlNJ3fYyaosuQwi3G1RExBKEHbYcCKRg65tsGo6Ep2W6mVFBKf7Ycvj4pju5nobBs\r
33         jn7H3/HRkf8eBZSxsI2w5cUpwLjdYzOlcRII3Bc8/Bca0f9i3//Xiv8ewEIE9+CyLQCW\r
34         37YA==\r
35 Received: by 10.112.85.228 with SMTP id k4mr6500563lbz.76.1334653590068;\r
36         Tue, 17 Apr 2012 02:06:30 -0700 (PDT)\r
37 Received: from localhost ([91.144.186.21])\r
38         by mx.google.com with ESMTPS id nv7sm10584298lab.9.2012.04.17.02.06.28\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Tue, 17 Apr 2012 02:06:29 -0700 (PDT)\r
41 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
42 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
43 Subject: Re: [RFC PATCH 1/4] emacs: simplify point placement in notmuch-hello\r
44 In-Reply-To:\r
45  <bcfdc0d1969997e89e5abe0b320d77ee2109796a.1334651669.git.jani@nikula.org>\r
46 References:\r
47  <bcfdc0d1969997e89e5abe0b320d77ee2109796a.1334651669.git.jani@nikula.org>\r
48 User-Agent: Notmuch/0.12+104~gf9ad237 (http://notmuchmail.org) Emacs/23.4.1\r
49         (x86_64-pc-linux-gnu)\r
50 Date: Tue, 17 Apr 2012 13:04:39 +0400\r
51 Message-ID: <87aa2aohjs.fsf@gmail.com>\r
52 MIME-Version: 1.0\r
53 Content-Type: text/plain; charset=us-ascii\r
54 X-BeenThere: notmuch@notmuchmail.org\r
55 X-Mailman-Version: 2.1.13\r
56 Precedence: list\r
57 List-Id: "Use and development of the notmuch mail system."\r
58         <notmuch.notmuchmail.org>\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
62 List-Post: <mailto:notmuch@notmuchmail.org>\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
66 X-List-Received-Date: Tue, 17 Apr 2012 09:06:36 -0000\r
67 \r
68 Hi Jani.\r
69 \r
70 Jani Nikula <jani@nikula.org> writes:\r
71 \r
72 > notmuch-hello (called also through notmuch-hello-update, bound to '='\r
73 > by default) tries to find the widget under or following point before\r
74 > refresh, and put the point back to the widget afterwards. The code has\r
75 > gotten a bit complicated, and has at least the following issues:\r
76 >\r
77 > 1) All the individual section functions have to include code to\r
78 >    support point placement. If there is no such support, point is\r
79 >    dropped to the search box. Only saved searches and all tags\r
80 >    sections support point placement.\r
81 >\r
82 > 2) Point placement is based on widget-value. If there are two widgets\r
83 >    with the same widget-value (for example a saved search with the\r
84 >    same name as a tag) the point is moved to the earlier one.\r
85 >\r
86 > 3) When first entering notmuch-hello notmuch-hello-target is nil, and\r
87 >    point is dropped to the search box.\r
88 >\r
89 > This patch simplifies the code by removing all point placement based\r
90 > on widgets. Point is simply saved before refresh, and put back to\r
91 > where it was. Sometimes, but not very often, this would have the\r
92 > appearance of moving the point relative to the nearest widgets. IMHO\r
93 > this is a minor problem compared to the issues listed above.\r
94 >\r
95 > A downside is that there's no visual cue (point movement) to indicate\r
96 > that refresh has finished. Then again, neither was there before, if\r
97 > point was at the beginning of a widget.\r
98 \r
99 Thanks for looking into this.  This is an annoying issue indeed.  And I\r
100 was thinking about fixing it myself.\r
101 \r
102 I am not sure I like the approach of moving the cursor to the same\r
103 position.  It is common that buffer content would change significantly\r
104 after a refresh (e.g. after I archived all new mail).  That would mean\r
105 the cursor would just randomly jump somewhere.  IMO we should allow\r
106 smart cursor positioning which means that logic should go to individual\r
107 sections.  I would propose the following plan:\r
108 \r
109 1. Remove special case for search box.  No section should be special.\r
110    Moreover it is possible to remove it (I did it) and in that case the\r
111    cursor would be left at the end of the buffer.  By default, the\r
112    cursor should be moved to the beginning of the buffer.\r
113 \r
114 2. Replace current cursor positioning logic with section specific code.\r
115    I.e. `notmuch-hello' would not do any cursor positioning (except for\r
116    item 1) but queries and tags section would save required state when a\r
117    button is clicked and the same section would use this state to\r
118    restore cursor position on refresh.  What state should be saved would\r
119    depend on the section but we should at least save the section\r
120    name/ID.  If during refresh no section set the cursor position, then\r
121    the cursor is moved to the beginning of the buffer.\r
122 \r
123 3. Provide a custom variable to set the default section to move the\r
124    cursor to.  I.e. set the section name/ID part of the state from item\r
125    2.  Again, details on what the default position inside the section is\r
126    would depend on the section.  For search box, it would be the input\r
127    field.  For queries/tags it would be the first tag.\r
128 \r
129 Item 1 is pretty simple.  The rest may be more tricky.  What do you\r
130 think?\r
131 \r
132 Regards,\r
133   Dmitry\r
134 \r
135 > ---\r
136 >  emacs/notmuch-hello.el |   70 +++++++++++------------------------------------\r
137 >  1 files changed, 17 insertions(+), 53 deletions(-)\r
138 >\r
139 > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
140 > index 71d37b8..9cd907a 100644\r
141 > --- a/emacs/notmuch-hello.el\r
142 > +++ b/emacs/notmuch-hello.el\r
143 > @@ -154,11 +154,6 @@ International Bureau of Weights and Measures."\r
144 >  (defvar notmuch-hello-url "http://notmuchmail.org"\r
145 >    "The `notmuch' web site.")\r
146 >  \r
147 > -(defvar notmuch-hello-search-pos nil\r
148 > -  "Position of search widget, if any.\r
149 > -\r
150 > -This should only be set by `notmuch-hello-insert-search'.")\r
151 > -\r
152 >  (defvar notmuch-hello-custom-section-options\r
153 >    '((:filter (string :tag "Filter for each tag"))\r
154 >      (:filter-count (string :tag "Different filter to generate message counts"))\r
155 > @@ -209,11 +204,8 @@ function produces a section simply by adding content to the current\r
156 >  buffer.  A section should not end with an empty line, because a\r
157 >  newline will be inserted after each section by `notmuch-hello'.\r
158 >  \r
159 > -Each function should take no arguments.  If the produced section\r
160 > -includes `notmuch-hello-target' (i.e. cursor should be positioned\r
161 > -inside this section), the function should return this element's\r
162 > -position.\r
163 > -Otherwise, it should return nil.\r
164 > +Each function should take no arguments. The return value is\r
165 > +ignored.\r
166 >  \r
167 >  For convenience an element can also be a list of the form (FUNC ARG1\r
168 >  ARG2 .. ARGN) in which case FUNC will be applied to the rest of the\r
169 > @@ -240,15 +232,6 @@ supported for \"Customized queries section\" items."\r
170 >           notmuch-hello-query-section\r
171 >           (function :tag "Custom section"))))\r
172 >  \r
173 > -(defvar notmuch-hello-target nil\r
174 > -  "Button text at position of point before rebuilding the notmuch-buffer.\r
175 > -\r
176 > -This variable contains the text of the button, if any, the\r
177 > -point was positioned at before the notmuch-hello buffer was\r
178 > -rebuilt. This should never actually be global and is defined as a\r
179 > -defvar only for documentation purposes and to avoid a compiler\r
180 > -warning about it occurring as a free variable.")\r
181 > -\r
182 >  (defvar notmuch-hello-hidden-sections nil\r
183 >    "List of sections titles whose contents are hidden")\r
184 >  \r
185 > @@ -449,8 +432,6 @@ Such a list can be computed with `notmuch-hello-query-counts'."\r
186 >                    (msg-count (third elem)))\r
187 >               (widget-insert (format "%8s "\r
188 >                                      (notmuch-hello-nice-number msg-count)))\r
189 > -             (if (string= name notmuch-hello-target)\r
190 > -                 (setq found-target-pos (point-marker)))\r
191 >               (widget-create 'push-button\r
192 >                              :notify #'notmuch-hello-widget-search\r
193 >                              :notmuch-search-terms query\r
194 > @@ -589,7 +570,6 @@ Complete list of currently available key bindings:\r
195 >  (defun notmuch-hello-insert-search ()\r
196 >    "Insert a search widget."\r
197 >    (widget-insert "Search: ")\r
198 > -  (setq notmuch-hello-search-pos (point-marker))\r
199 >    (widget-create 'editable-field\r
200 >                ;; Leave some space at the start and end of the\r
201 >                ;; search boxes.\r
202 > @@ -763,13 +743,7 @@ following:\r
203 >        (set-buffer "*notmuch-hello*")\r
204 >      (switch-to-buffer "*notmuch-hello*"))\r
205 >  \r
206 > -  (let ((notmuch-hello-target (if (widget-at)\r
207 > -                               (widget-value (widget-at))\r
208 > -                             (condition-case nil\r
209 > -                                 (progn\r
210 > -                                   (widget-forward 1)\r
211 > -                                   (widget-value (widget-at)))\r
212 > -                               (error nil))))\r
213 > +  (let ((final-target-pos (point))\r
214 >       (inhibit-read-only t))\r
215 >  \r
216 >      ;; Delete all editable widget fields.  Editable widget fields are\r
217 > @@ -788,30 +762,20 @@ following:\r
218 >        (mapc 'delete-overlay (car all))\r
219 >        (mapc 'delete-overlay (cdr all)))\r
220 >  \r
221 > -    (let (final-target-pos)\r
222 > -      (mapc\r
223 > -       (lambda (section)\r
224 > -      (let ((point-before (point))\r
225 > -            (result (if (functionp section)\r
226 > -                        (funcall section)\r
227 > -                      (apply (car section) (cdr section)))))\r
228 > -        (if (and (not final-target-pos) (integer-or-marker-p result))\r
229 > -            (setq final-target-pos result))\r
230 > -        ;; don't insert a newline when the previous section didn't show\r
231 > -        ;; anything.\r
232 > -        (unless (eq (point) point-before)\r
233 > -          (widget-insert "\n"))))\r
234 > -       notmuch-hello-sections)\r
235 > -      (widget-setup)\r
236 > -\r
237 > -      (when final-target-pos\r
238 > -     (goto-char final-target-pos)\r
239 > -     (unless (widget-at)\r
240 > -       (widget-forward 1)))\r
241 > -\r
242 > -      (unless (widget-at)\r
243 > -     (when notmuch-hello-search-pos\r
244 > -       (goto-char notmuch-hello-search-pos)))))\r
245 > +    (mapc\r
246 > +     (lambda (section)\r
247 > +       (let ((point-before (point)))\r
248 > +      (if (functionp section)\r
249 > +          (funcall section)\r
250 > +        (apply (car section) (cdr section)))\r
251 > +      ;; don't insert a newline when the previous section didn't\r
252 > +      ;; show anything.\r
253 > +      (unless (eq (point) point-before)\r
254 > +        (widget-insert "\n"))))\r
255 > +     notmuch-hello-sections)\r
256 > +    (widget-setup)\r
257 > +\r
258 > +    (goto-char final-target-pos))\r
259 >    (run-hooks 'notmuch-hello-refresh-hook)\r
260 >    (setq notmuch-hello-first-run nil))\r
261 >  \r
262 > -- \r
263 > 1.7.1\r
264 >\r
265 > _______________________________________________\r
266 > notmuch mailing list\r
267 > notmuch@notmuchmail.org\r
268 > http://notmuchmail.org/mailman/listinfo/notmuch\r