Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 64 / e33e93b13114a717f5eb6607f1c50bdec28497
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 arlo.cworth.org (Postfix) with ESMTP id 080AC6DE0BF6\r
6  for <notmuch@notmuchmail.org>; Wed, 10 Feb 2016 10:50:21 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.231\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.231 tagged_above=-999 required=5 tests=[AWL=0.339,\r
12   DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13  FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,\r
14  RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
15  autolearn=disabled\r
16 Received: from arlo.cworth.org ([127.0.0.1])\r
17  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
18  with ESMTP id KwcC-TjxzFOD for <notmuch@notmuchmail.org>;\r
19  Wed, 10 Feb 2016 10:50:18 -0800 (PST)\r
20 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com\r
21  [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 184CB6DE0B36 for\r
22  <notmuch@notmuchmail.org>; Wed, 10 Feb 2016 10:50:18 -0800 (PST)\r
23 Received: by mail-wm0-f65.google.com with SMTP id p63so6034401wmp.1\r
24  for <notmuch@notmuchmail.org>; Wed, 10 Feb 2016 10:50:18 -0800 (PST)\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=Sz9q4FP8+lzIPxRFUhIYBHYeH7zBzHXgmLnxB1JYcPg=;\r
29  b=BTInDxuBVLchMPvv7roA8Xr9Q18mwtLZQXgL+eJcpxY7cpbQQjdTR1+2wKNvv5t73h\r
30  Coto3acKo2XQXNYVdrePH1R7GbdzUiexZ6OYmy9TQuVEKTQAFbR8u1LGeB7y4rfB9tqh\r
31  YLVRZ4GiW4jCXy/tcY0ueOYhPaHdZW9uvp5VDBSH6DYmyGskqwlwApSmwGfwpyZsvhPD\r
32  Vf+Z2k0wXQdpTRPHydSSjecsSJurDHvcBi5R3B8MGI+jq5pyfeDrM3VQS65oDYRd6sWN\r
33  5WlwbIYpEjw8r2l7x50TcnpHpvgnF7JMij3E9lFSky8zP/U2jGT3Vsonqc6UQstMfC8q\r
34  8lXg==\r
35 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
36  d=1e100.net; s=20130820;\r
37  h=x-gm-message-state:from:to:subject:in-reply-to:references\r
38  :user-agent:date:message-id:mime-version:content-type;\r
39  bh=Sz9q4FP8+lzIPxRFUhIYBHYeH7zBzHXgmLnxB1JYcPg=;\r
40  b=jLR4/33TEe1l/6ezUxNMj1+hkc5nLyFhSNsiJf2k+8aFmx4H2GvQjnpJ+Mg9wypNqT\r
41  MdocK2gvwfB/jEe6GOUl3lqAiK5gGpglrTFcUlBh9HYrhQV4dogd0Kw5vF2tbXK+F2mu\r
42  6U2sNXMzoFKRj6rGPp76pjWi2WThf3hMsKlRr01ZvYLocCvBNuOSu/IT1Q67ILJiLL8h\r
43  +AqUwG0qSN0mDPQJZHSiTaRrM1Q1EkGfIgpexa+ptcLGJaD9V81Ov6qSix1dwsIb/2dH\r
44  aRHdu39YztwsUfYbplwUZf8o5p1OG282oxTJdSKi1yc2xfTKhcF92fqIeXphuIcjqi3R\r
45  NEOg==\r
46 X-Gm-Message-State:\r
47  AG10YOTuogozUK/7YOdEu2gQqe2LxGM9V5QBYKRJUVxjveR7Xd9rbTs//2CKNTONdwTiUQ==\r
48 X-Received: by 10.28.174.72 with SMTP id x69mr12665074wme.68.1455130216412;\r
49  Wed, 10 Feb 2016 10:50:16 -0800 (PST)\r
50 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
51  by smtp.gmail.com with ESMTPSA id i12sm4626997wmf.10.2016.02.10.10.50.15\r
52  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
53  Wed, 10 Feb 2016 10:50:15 -0800 (PST)\r
54 From: Mark Walters <markwalters1009@gmail.com>\r
55 To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
56 Subject: Re: [PATCH v2] emacs: Report a lack of matches when calling\r
57  `notmuch-show'.\r
58 In-Reply-To: <1455112878-23497-2-git-send-email-dme@dme.org>\r
59 References: <1455112878-23497-1-git-send-email-dme@dme.org>\r
60  <1455112878-23497-2-git-send-email-dme@dme.org>\r
61 User-Agent: Notmuch/0.18.1+485~gca076ce (http://notmuchmail.org) Emacs/24.4.1\r
62  (x86_64-pc-linux-gnu)\r
63 Date: Wed, 10 Feb 2016 18:50:14 +0000\r
64 Message-ID: <87oabo5rix.fsf@qmul.ac.uk>\r
65 MIME-Version: 1.0\r
66 Content-Type: text/plain\r
67 X-BeenThere: notmuch@notmuchmail.org\r
68 X-Mailman-Version: 2.1.20\r
69 Precedence: list\r
70 List-Id: "Use and development of the notmuch mail system."\r
71  <notmuch.notmuchmail.org>\r
72 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
73  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
74 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
75 List-Post: <mailto:notmuch@notmuchmail.org>\r
76 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
77 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
78  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
79 X-List-Received-Date: Wed, 10 Feb 2016 18:50:21 -0000\r
80 \r
81 \r
82 \r
83 On Wed, 10 Feb 2016, David Edmondson <dme@dme.org> wrote:\r
84 > If the basic query passed to `notmuch-show' generates no results, ring\r
85 > the bell and inform the user that no messages matched the query rather\r
86 > than displaying an empty buffer and showing an obscure error.\r
87 >\r
88 > Similarly when refreshing a `notmuch-show' buffer and no messages match.\r
89 \r
90 This basically looks fine to me and all tests pass. The code movement\r
91 and cleanup all looks fine.  Two minor things, one tiny nit below; and I\r
92 wonder whether just having the buffer say "No search results" (or\r
93 something similar) and leave the user to kill it would be nicer than\r
94 dinging (and more in line with the way search and tree behave).\r
95 \r
96 [In some sense I think this way is right and search and tree are wrong,\r
97 but that is probably difficult to get round as search and tree run\r
98 asynchronously.]\r
99 \r
100 Best wishes\r
101 \r
102 Mark\r
103 \r
104 \r
105 > ---\r
106 >  emacs/notmuch-show.el | 144 +++++++++++++++++++++++++++++---------------------\r
107 >  emacs/notmuch.el      |   6 ++-\r
108 >  2 files changed, 89 insertions(+), 61 deletions(-)\r
109 >\r
110 > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
111 > index 3345878..9a74848 100644\r
112 > --- a/emacs/notmuch-show.el\r
113 > +++ b/emacs/notmuch-show.el\r
114 > @@ -153,27 +153,21 @@ indentation."\r
115 >  \r
116 >  (defvar notmuch-show-thread-id nil)\r
117 >  (make-variable-buffer-local 'notmuch-show-thread-id)\r
118 > -(put 'notmuch-show-thread-id 'permanent-local t)\r
119 >  \r
120 >  (defvar notmuch-show-parent-buffer nil)\r
121 >  (make-variable-buffer-local 'notmuch-show-parent-buffer)\r
122 > -(put 'notmuch-show-parent-buffer 'permanent-local t)\r
123 >  \r
124 >  (defvar notmuch-show-query-context nil)\r
125 >  (make-variable-buffer-local 'notmuch-show-query-context)\r
126 > -(put 'notmuch-show-query-context 'permanent-local t)\r
127 >  \r
128 >  (defvar notmuch-show-process-crypto nil)\r
129 >  (make-variable-buffer-local 'notmuch-show-process-crypto)\r
130 > -(put 'notmuch-show-process-crypto 'permanent-local t)\r
131 >  \r
132 >  (defvar notmuch-show-elide-non-matching-messages nil)\r
133 >  (make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)\r
134 > -(put 'notmuch-show-elide-non-matching-messages 'permanent-local t)\r
135 >  \r
136 >  (defvar notmuch-show-indent-content t)\r
137 >  (make-variable-buffer-local 'notmuch-show-indent-content)\r
138 > -(put 'notmuch-show-indent-content 'permanent-local t)\r
139 >  \r
140 >  (defvar notmuch-show-attachment-debug nil\r
141 >    "If t log stdout and stderr from attachment handlers\r
142 > @@ -1197,71 +1191,101 @@ non-nil.\r
143 >  The optional BUFFER-NAME provides the name of the buffer in\r
144 >  which the message thread is shown. If it is nil (which occurs\r
145 >  when the command is called interactively) the argument to the\r
146 > -function is used."\r
147 > +function is used.\r
148 > +\r
149 > +Returns the buffer containing the messages, or NIL if no messages\r
150 > +matched."\r
151 >    (interactive "sNotmuch show: \nP")\r
152 >    (let ((buffer-name (generate-new-buffer-name\r
153 >                     (or buffer-name\r
154 >                         (concat "*notmuch-" thread-id "*")))))\r
155 >      (switch-to-buffer (get-buffer-create buffer-name))\r
156 > -    ;; Set the default value for `notmuch-show-process-crypto' in this\r
157 > -    ;; buffer.\r
158 > -    (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
159 > -    ;; Set the default value for\r
160 > -    ;; `notmuch-show-elide-non-matching-messages' in this buffer. If\r
161 > -    ;; elide-toggle is set, invert the default.\r
162 > -    (setq notmuch-show-elide-non-matching-messages notmuch-show-only-matching-messages)\r
163 > -    (if elide-toggle\r
164 > -     (setq notmuch-show-elide-non-matching-messages (not notmuch-show-elide-non-matching-messages)))\r
165 > +    ;; No need to track undo information for this buffer.\r
166 > +    (setq buffer-undo-list t)\r
167 > +\r
168 > +    (notmuch-show-mode)\r
169 >  \r
170 > +    ;; Set various buffer local variables to their appropriate initial\r
171 > +    ;; state. Do this after enabling `notmuch-show-mode' so that they\r
172 > +    ;; aren't wiped out.\r
173 >      (setq notmuch-show-thread-id thread-id\r
174 >         notmuch-show-parent-buffer parent-buffer\r
175 > -       notmuch-show-query-context query-context)\r
176 > -    (notmuch-show-build-buffer)\r
177 > -    (notmuch-show-goto-first-wanted-message)\r
178 > -    (current-buffer)))\r
179 > +       notmuch-show-query-context query-context\r
180 >  \r
181 > -(defun notmuch-show-build-buffer ()\r
182 > -  (let ((inhibit-read-only t))\r
183 > +       notmuch-show-process-crypto notmuch-crypto-process-mime\r
184 > +       ;; If `elide-toggle', invert the default value.\r
185 > +       notmuch-show-elide-non-matching-messages\r
186 > +       (if elide-toggle\r
187 > +           (not notmuch-show-only-matching-messages)\r
188 > +         notmuch-show-only-matching-messages))\r
189 >  \r
190 > -    (notmuch-show-mode)\r
191 >      (add-hook 'post-command-hook #'notmuch-show-command-hook nil t)\r
192 > -\r
193 > -    ;; Don't track undo information for this buffer\r
194 > -    (set 'buffer-undo-list t)\r
195 > +    (jit-lock-register #'notmuch-show-buttonise-links)\r
196 >  \r
197 >      (notmuch-tag-clear-cache)\r
198 > -    (erase-buffer)\r
199 > -    (goto-char (point-min))\r
200 > -    (save-excursion\r
201 > -      (let* ((basic-args (list notmuch-show-thread-id))\r
202 > -          (args (if notmuch-show-query-context\r
203 > -                    (append (list "\'") basic-args\r
204 > -                            (list "and (" notmuch-show-query-context ")\'"))\r
205 > -                  (append (list "\'") basic-args (list "\'"))))\r
206 > -          (cli-args (cons "--exclude=false"\r
207 > -                          (when notmuch-show-elide-non-matching-messages\r
208 > -                            (list "--entire-thread=false")))))\r
209 > -\r
210 > -     (notmuch-show-insert-forest (notmuch-query-get-threads (append cli-args args)))\r
211 > -     ;; If the query context reduced the results to nothing, run\r
212 > -     ;; the basic query.\r
213 > -     (when (and (eq (buffer-size) 0)\r
214 > -                notmuch-show-query-context)\r
215 > -       (notmuch-show-insert-forest\r
216 > -        (notmuch-query-get-threads (append cli-args basic-args)))))\r
217 > -\r
218 > -      (jit-lock-register #'notmuch-show-buttonise-links)\r
219 > -\r
220 > -      (notmuch-show-mapc (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))\r
221 > +\r
222 > +    (let ((inhibit-read-only t))\r
223 > +      (if (notmuch-show--build-buffer)\r
224 > +       ;; Messages were inserted into the buffer.\r
225 > +       (current-buffer)\r
226 > +\r
227 > +     ;; No messages were inserted - presumably none matched the\r
228 > +     ;; query.\r
229 > +     (kill-buffer (current-buffer))\r
230 > +     (ding)\r
231 > +     (message "No messages matched the query!")\r
232 > +     nil))))\r
233 > +\r
234 > +(defun notmuch-show--build-buffer (&optional state)\r
235 > +  "Display messages matching the current buffer context.\r
236 > +\r
237 > +Apply the previously saved STATE if supplied, otherwise show the\r
238 > +first relevant message.\r
239 > +\r
240 > +If no messages match the query return NIL."\r
241 > +  (let* ((basic-args (list notmuch-show-thread-id))\r
242 > +      (args (if notmuch-show-query-context\r
243 > +                (append (list "\'") basic-args\r
244 > +                        (list "and (" notmuch-show-query-context ")\'"))\r
245 > +              (append (list "\'") basic-args (list "\'"))))\r
246 > +      (cli-args (cons "--exclude=false"\r
247 > +                      (when notmuch-show-elide-non-matching-messages\r
248 > +                        (list "--entire-thread=false"))))\r
249 > +\r
250 > +      (forest (or (notmuch-query-get-threads (append cli-args args))\r
251 > +                  ;; If a query context reduced the number of\r
252 > +                  ;; results to zero, try again without it.\r
253 > +                  (and notmuch-show-query-context\r
254 > +                       (notmuch-query-get-threads (append cli-args basic-args)))))\r
255 > +\r
256 > +      ;; Must be reset every time we are going to start inserting\r
257 > +      ;; messages into the buffer.\r
258 > +      (notmuch-show-previous-subject ""))\r
259 > +\r
260 > +    (when forest\r
261 > +      (notmuch-show-insert-forest forest)\r
262 > +\r
263 > +      ;; Cache the original tags for each message so that we can display\r
264 > +      ;; changes.\r
265 \r
266 ^^ I think "Store the original tags for each message" would be better,\r
267 particularly as this is nothing to do with the tag cache as used by say\r
268 notmuch-tag-clear-cache.\r
269 \r
270 \r
271 > +      (notmuch-show-mapc\r
272 > +       (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))\r
273 >  \r
274 >        ;; Set the header line to the subject of the first message.\r
275 >        (setq header-line-format\r
276 >           (replace-regexp-in-string "%" "%%"\r
277 > -                         (notmuch-sanitize\r
278 > -                          (notmuch-show-strip-re\r
279 > -                           (notmuch-show-get-subject)))))\r
280 > +                                   (notmuch-sanitize\r
281 > +                                    (notmuch-show-strip-re\r
282 > +                                     (notmuch-show-get-subject)))))\r
283 >  \r
284 > -      (run-hooks 'notmuch-show-hook))))\r
285 > +      (run-hooks 'notmuch-show-hook)\r
286 > +\r
287 > +      (if state\r
288 > +       (notmuch-show-apply-state state)\r
289 > +     ;; With no state to apply, just go to the first message.\r
290 > +     (notmuch-show-goto-first-wanted-message)))\r
291 > +\r
292 > +    ;; Report back to the caller whether any messages matched.\r
293 > +    forest))\r
294 >  \r
295 >  (defun notmuch-show-capture-state ()\r
296 >    "Capture the state of the current buffer.\r
297 > @@ -1320,17 +1344,17 @@ reset based on the original query."\r
298 >    (let ((inhibit-read-only t)\r
299 >       (state (unless reset-state\r
300 >                (notmuch-show-capture-state))))\r
301 > -    ;; erase-buffer does not seem to remove overlays, which can lead\r
302 > +    ;; `erase-buffer' does not seem to remove overlays, which can lead\r
303 >      ;; to weird effects such as remaining images, so remove them\r
304 >      ;; manually.\r
305 >      (remove-overlays)\r
306 >      (erase-buffer)\r
307 > -    (notmuch-show-build-buffer)\r
308 > -    (if state\r
309 > -     (notmuch-show-apply-state state)\r
310 > -      ;; We're resetting state, so navigate to the first open message\r
311 > -      ;; and mark it read, just like opening a new show buffer.\r
312 > -      (notmuch-show-goto-first-wanted-message))))\r
313 > +\r
314 > +    (unless (notmuch-show--build-buffer state)\r
315 > +      ;; No messages were inserted.\r
316 > +      (kill-buffer (current-buffer))\r
317 > +      (ding)\r
318 > +      (message "Refreshing the buffer resulted in no messages!"))))\r
319 >  \r
320 >  (defvar notmuch-show-stash-map\r
321 >    (let ((map (make-sparse-keymap)))\r
322 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
323 > index 463b926..3100b97 100644\r
324 > --- a/emacs/notmuch.el\r
325 > +++ b/emacs/notmuch.el\r
326 > @@ -458,7 +458,11 @@ no messages in the region then return nil."\r
327 >    (notmuch-search-properties-in-region :subject beg end))\r
328 >  \r
329 >  (defun notmuch-search-show-thread (&optional elide-toggle)\r
330 > -  "Display the currently selected thread."\r
331 > +  "Display the currently selected thread.\r
332 > +\r
333 > +With a prefix argument, invert the default value of\r
334 > +`notmuch-show-only-matching-messages' when displaying the\r
335 > +thread."\r
336 >    (interactive "P")\r
337 >    (let ((thread-id (notmuch-search-find-thread-id))\r
338 >       (subject (notmuch-search-find-subject)))\r
339 > -- \r
340 > 2.1.4\r
341 >\r
342 > _______________________________________________\r
343 > notmuch mailing list\r
344 > notmuch@notmuchmail.org\r
345 > https://notmuchmail.org/mailman/listinfo/notmuch\r