[PATCH] lib: reword comment about XFOLDER: prefix
[notmuch-archives.git] / 69 / f222fd6dbf03047d501991abdea1dde1d548e9
1 Return-Path: <dme@dme.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 arlo.cworth.org (Postfix) with ESMTP id D23A26DE0B36\r
6  for <notmuch@notmuchmail.org>; Thu, 11 Feb 2016 00:33:36 -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.12\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.12 tagged_above=-999 required=5 tests=[AWL=-0.053,\r
12   DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\r
13  RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_NEUTRAL=0.652,\r
14  UNPARSEABLE_RELAY=0.001] autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id EIMAa3HwO4k2 for <notmuch@notmuchmail.org>;\r
18  Thu, 11 Feb 2016 00:33:34 -0800 (PST)\r
19 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com\r
20  [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 3DA206DE0BF6 for\r
21  <notmuch@notmuchmail.org>; Thu, 11 Feb 2016 00:33:34 -0800 (PST)\r
22 Received: by mail-wm0-f65.google.com with SMTP id p63so9190312wmp.1\r
23  for <notmuch@notmuchmail.org>; Thu, 11 Feb 2016 00:33:34 -0800 (PST)\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25  d=dme-org.20150623.gappssmtp.com; s=20150623;\r
26  h=from:to:subject:date:message-id:in-reply-to:references;\r
27  bh=dk1ZJLD46xW1KACbIWEz+5OrH68bZ4c0ppWpwopj4vw=;\r
28  b=NGKBXzKouEMX/ZAJwpcOgdR5a+w+Y4rHO/+xQ3RF4A1MYYhEvzCikXV8NqaGorRl+T\r
29  js7mcl8CmuzdvZHHmosHa7XxVy/bjrRGoCxXMw42rkOgwFfZTgAI8lPYas98GEWrEZu+\r
30  BzZ1XjZMg7/V6sFm0dhg7zlBtI7SoHQpjQFxGU7cydqhlVftth7uXa6k68Vdn6qzc8WL\r
31  Lx+kvVD37kHbWmNmkC0bv0PTSXEG3fmHSxJO1For9uvQSQxQ4cyDbc+FnBuQt8SJxHgq\r
32  2EJNEI4X96pyewGelPlUadDfthjUQlm85m5y52tEnJkFPOJuVmWgzgq30630Ub/avOOS\r
33  2o9Q==\r
34 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
35  d=1e100.net; s=20130820;\r
36  h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\r
37  :references;\r
38  bh=dk1ZJLD46xW1KACbIWEz+5OrH68bZ4c0ppWpwopj4vw=;\r
39  b=JiueOgVvv3+Qu4aJYXrF1mhBnJpGmXY6rOOgqbEYNzWV84ypp+u/fEKVIzsC3jy8Ko\r
40  fBh0xYdJa4TZBb8TejdHllCt69QA8U9/lm7F06wucNlCpR0H8f26Cf5NInY+yENhsiZx\r
41  m+2yA5lZSzMavxO9SYZZ+7MKpVAF68GZriV+YhCW/KnB2YNaP/RfMK1kqGL+ZMFM7Vgf\r
42  DjnGJsFvmxzo14g6MzcrBWqJ4iIG4Q8U/tjJxjtiBL8h9bslYQnq6lfk6S5nbOU6KqLs\r
43  6myT3m0fq/vYyK9wiEY8p+X9GipcDhLPTwbrHeqUvhX6/NWtAc8B9ut/PhwJnnUsJvGS\r
44  yJIw==\r
45 X-Gm-Message-State:\r
46  AG10YOQY9muAxXAMoo7DMwHAYy5jC8V56GiFybFWVjD5ON+/rtfeM4RVXDqG89//fNlPDQ==\r
47 X-Received: by 10.28.221.68 with SMTP id u65mr16510591wmg.95.1455179612952;\r
48  Thu, 11 Feb 2016 00:33:32 -0800 (PST)\r
49 Received: from disaster-area.hh.sledj.net\r
50  ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
51  by smtp.gmail.com with ESMTPSA id e19sm22903696wmd.1.2016.02.11.00.33.31\r
52  for <notmuch@notmuchmail.org>\r
53  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
54  Thu, 11 Feb 2016 00:33:31 -0800 (PST)\r
55 Received: from localhost (disaster-area.hh.sledj.net [local])\r
56  by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 723b7469\r
57  for <notmuch@notmuchmail.org>; Thu, 11 Feb 2016 08:33:27 +0000 (UTC)\r
58 From: David Edmondson <dme@dme.org>\r
59 To: notmuch@notmuchmail.org\r
60 Subject: [PATCH v3] emacs: Report a lack of matches when calling\r
61  `notmuch-show'.\r
62 Date: Thu, 11 Feb 2016 08:33:27 +0000\r
63 Message-Id: <1455179607-16870-2-git-send-email-dme@dme.org>\r
64 X-Mailer: git-send-email 2.1.4\r
65 In-Reply-To: <1455179607-16870-1-git-send-email-dme@dme.org>\r
66 References: <1455179607-16870-1-git-send-email-dme@dme.org>\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: Thu, 11 Feb 2016 08:33:37 -0000\r
80 \r
81 If the basic query passed to `notmuch-show' generates no results, ring\r
82 the bell and inform the user that no messages matched the query rather\r
83 than displaying an empty buffer and showing an obscure error.\r
84 \r
85 Similarly when refreshing a `notmuch-show' buffer and no messages match.\r
86 ---\r
87  emacs/notmuch-show.el | 144 +++++++++++++++++++++++++++++---------------------\r
88  emacs/notmuch.el      |   6 ++-\r
89  2 files changed, 89 insertions(+), 61 deletions(-)\r
90 \r
91 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
92 index 3345878..4629c64 100644\r
93 --- a/emacs/notmuch-show.el\r
94 +++ b/emacs/notmuch-show.el\r
95 @@ -153,27 +153,21 @@ indentation."\r
96  \r
97  (defvar notmuch-show-thread-id nil)\r
98  (make-variable-buffer-local 'notmuch-show-thread-id)\r
99 -(put 'notmuch-show-thread-id 'permanent-local t)\r
100  \r
101  (defvar notmuch-show-parent-buffer nil)\r
102  (make-variable-buffer-local 'notmuch-show-parent-buffer)\r
103 -(put 'notmuch-show-parent-buffer 'permanent-local t)\r
104  \r
105  (defvar notmuch-show-query-context nil)\r
106  (make-variable-buffer-local 'notmuch-show-query-context)\r
107 -(put 'notmuch-show-query-context 'permanent-local t)\r
108  \r
109  (defvar notmuch-show-process-crypto nil)\r
110  (make-variable-buffer-local 'notmuch-show-process-crypto)\r
111 -(put 'notmuch-show-process-crypto 'permanent-local t)\r
112  \r
113  (defvar notmuch-show-elide-non-matching-messages nil)\r
114  (make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)\r
115 -(put 'notmuch-show-elide-non-matching-messages 'permanent-local t)\r
116  \r
117  (defvar notmuch-show-indent-content t)\r
118  (make-variable-buffer-local 'notmuch-show-indent-content)\r
119 -(put 'notmuch-show-indent-content 'permanent-local t)\r
120  \r
121  (defvar notmuch-show-attachment-debug nil\r
122    "If t log stdout and stderr from attachment handlers\r
123 @@ -1197,71 +1191,101 @@ non-nil.\r
124  The optional BUFFER-NAME provides the name of the buffer in\r
125  which the message thread is shown. If it is nil (which occurs\r
126  when the command is called interactively) the argument to the\r
127 -function is used."\r
128 +function is used.\r
129 +\r
130 +Returns the buffer containing the messages, or NIL if no messages\r
131 +matched."\r
132    (interactive "sNotmuch show: \nP")\r
133    (let ((buffer-name (generate-new-buffer-name\r
134                       (or buffer-name\r
135                           (concat "*notmuch-" thread-id "*")))))\r
136      (switch-to-buffer (get-buffer-create buffer-name))\r
137 -    ;; Set the default value for `notmuch-show-process-crypto' in this\r
138 -    ;; buffer.\r
139 -    (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
140 -    ;; Set the default value for\r
141 -    ;; `notmuch-show-elide-non-matching-messages' in this buffer. If\r
142 -    ;; elide-toggle is set, invert the default.\r
143 -    (setq notmuch-show-elide-non-matching-messages notmuch-show-only-matching-messages)\r
144 -    (if elide-toggle\r
145 -       (setq notmuch-show-elide-non-matching-messages (not notmuch-show-elide-non-matching-messages)))\r
146 +    ;; No need to track undo information for this buffer.\r
147 +    (setq buffer-undo-list t)\r
148 +\r
149 +    (notmuch-show-mode)\r
150  \r
151 +    ;; Set various buffer local variables to their appropriate initial\r
152 +    ;; state. Do this after enabling `notmuch-show-mode' so that they\r
153 +    ;; aren't wiped out.\r
154      (setq notmuch-show-thread-id thread-id\r
155           notmuch-show-parent-buffer parent-buffer\r
156 -         notmuch-show-query-context query-context)\r
157 -    (notmuch-show-build-buffer)\r
158 -    (notmuch-show-goto-first-wanted-message)\r
159 -    (current-buffer)))\r
160 +         notmuch-show-query-context query-context\r
161  \r
162 -(defun notmuch-show-build-buffer ()\r
163 -  (let ((inhibit-read-only t))\r
164 +         notmuch-show-process-crypto notmuch-crypto-process-mime\r
165 +         ;; If `elide-toggle', invert the default value.\r
166 +         notmuch-show-elide-non-matching-messages\r
167 +         (if elide-toggle\r
168 +             (not notmuch-show-only-matching-messages)\r
169 +           notmuch-show-only-matching-messages))\r
170  \r
171 -    (notmuch-show-mode)\r
172      (add-hook 'post-command-hook #'notmuch-show-command-hook nil t)\r
173 -\r
174 -    ;; Don't track undo information for this buffer\r
175 -    (set 'buffer-undo-list t)\r
176 +    (jit-lock-register #'notmuch-show-buttonise-links)\r
177  \r
178      (notmuch-tag-clear-cache)\r
179 -    (erase-buffer)\r
180 -    (goto-char (point-min))\r
181 -    (save-excursion\r
182 -      (let* ((basic-args (list notmuch-show-thread-id))\r
183 -            (args (if notmuch-show-query-context\r
184 -                      (append (list "\'") basic-args\r
185 -                              (list "and (" notmuch-show-query-context ")\'"))\r
186 -                    (append (list "\'") basic-args (list "\'"))))\r
187 -            (cli-args (cons "--exclude=false"\r
188 -                            (when notmuch-show-elide-non-matching-messages\r
189 -                              (list "--entire-thread=false")))))\r
190 -\r
191 -       (notmuch-show-insert-forest (notmuch-query-get-threads (append cli-args args)))\r
192 -       ;; If the query context reduced the results to nothing, run\r
193 -       ;; the basic query.\r
194 -       (when (and (eq (buffer-size) 0)\r
195 -                  notmuch-show-query-context)\r
196 -         (notmuch-show-insert-forest\r
197 -          (notmuch-query-get-threads (append cli-args basic-args)))))\r
198 -\r
199 -      (jit-lock-register #'notmuch-show-buttonise-links)\r
200 -\r
201 -      (notmuch-show-mapc (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))\r
202 +\r
203 +    (let ((inhibit-read-only t))\r
204 +      (if (notmuch-show--build-buffer)\r
205 +         ;; Messages were inserted into the buffer.\r
206 +         (current-buffer)\r
207 +\r
208 +       ;; No messages were inserted - presumably none matched the\r
209 +       ;; query.\r
210 +       (kill-buffer (current-buffer))\r
211 +       (ding)\r
212 +       (message "No messages matched the query!")\r
213 +       nil))))\r
214 +\r
215 +(defun notmuch-show--build-buffer (&optional state)\r
216 +  "Display messages matching the current buffer context.\r
217 +\r
218 +Apply the previously saved STATE if supplied, otherwise show the\r
219 +first relevant message.\r
220 +\r
221 +If no messages match the query return NIL."\r
222 +  (let* ((basic-args (list notmuch-show-thread-id))\r
223 +        (args (if notmuch-show-query-context\r
224 +                  (append (list "\'") basic-args\r
225 +                          (list "and (" notmuch-show-query-context ")\'"))\r
226 +                (append (list "\'") basic-args (list "\'"))))\r
227 +        (cli-args (cons "--exclude=false"\r
228 +                        (when notmuch-show-elide-non-matching-messages\r
229 +                          (list "--entire-thread=false"))))\r
230 +\r
231 +        (forest (or (notmuch-query-get-threads (append cli-args args))\r
232 +                    ;; If a query context reduced the number of\r
233 +                    ;; results to zero, try again without it.\r
234 +                    (and notmuch-show-query-context\r
235 +                         (notmuch-query-get-threads (append cli-args basic-args)))))\r
236 +\r
237 +        ;; Must be reset every time we are going to start inserting\r
238 +        ;; messages into the buffer.\r
239 +        (notmuch-show-previous-subject ""))\r
240 +\r
241 +    (when forest\r
242 +      (notmuch-show-insert-forest forest)\r
243 +\r
244 +      ;; Store the original tags for each message so that we can\r
245 +      ;; display changes.\r
246 +      (notmuch-show-mapc\r
247 +       (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))\r
248  \r
249        ;; Set the header line to the subject of the first message.\r
250        (setq header-line-format\r
251             (replace-regexp-in-string "%" "%%"\r
252 -                           (notmuch-sanitize\r
253 -                            (notmuch-show-strip-re\r
254 -                             (notmuch-show-get-subject)))))\r
255 +                                     (notmuch-sanitize\r
256 +                                      (notmuch-show-strip-re\r
257 +                                       (notmuch-show-get-subject)))))\r
258  \r
259 -      (run-hooks 'notmuch-show-hook))))\r
260 +      (run-hooks 'notmuch-show-hook)\r
261 +\r
262 +      (if state\r
263 +         (notmuch-show-apply-state state)\r
264 +       ;; With no state to apply, just go to the first message.\r
265 +       (notmuch-show-goto-first-wanted-message)))\r
266 +\r
267 +    ;; Report back to the caller whether any messages matched.\r
268 +    forest))\r
269  \r
270  (defun notmuch-show-capture-state ()\r
271    "Capture the state of the current buffer.\r
272 @@ -1320,17 +1344,17 @@ reset based on the original query."\r
273    (let ((inhibit-read-only t)\r
274         (state (unless reset-state\r
275                  (notmuch-show-capture-state))))\r
276 -    ;; erase-buffer does not seem to remove overlays, which can lead\r
277 +    ;; `erase-buffer' does not seem to remove overlays, which can lead\r
278      ;; to weird effects such as remaining images, so remove them\r
279      ;; manually.\r
280      (remove-overlays)\r
281      (erase-buffer)\r
282 -    (notmuch-show-build-buffer)\r
283 -    (if state\r
284 -       (notmuch-show-apply-state state)\r
285 -      ;; We're resetting state, so navigate to the first open message\r
286 -      ;; and mark it read, just like opening a new show buffer.\r
287 -      (notmuch-show-goto-first-wanted-message))))\r
288 +\r
289 +    (unless (notmuch-show--build-buffer state)\r
290 +      ;; No messages were inserted.\r
291 +      (kill-buffer (current-buffer))\r
292 +      (ding)\r
293 +      (message "Refreshing the buffer resulted in no messages!"))))\r
294  \r
295  (defvar notmuch-show-stash-map\r
296    (let ((map (make-sparse-keymap)))\r
297 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
298 index 463b926..3100b97 100644\r
299 --- a/emacs/notmuch.el\r
300 +++ b/emacs/notmuch.el\r
301 @@ -458,7 +458,11 @@ no messages in the region then return nil."\r
302    (notmuch-search-properties-in-region :subject beg end))\r
303  \r
304  (defun notmuch-search-show-thread (&optional elide-toggle)\r
305 -  "Display the currently selected thread."\r
306 +  "Display the currently selected thread.\r
307 +\r
308 +With a prefix argument, invert the default value of\r
309 +`notmuch-show-only-matching-messages' when displaying the\r
310 +thread."\r
311    (interactive "P")\r
312    (let ((thread-id (notmuch-search-find-thread-id))\r
313         (subject (notmuch-search-find-subject)))\r
314 -- \r
315 2.1.4\r
316 \r