Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 6a / 66b7b6684248b72673bf50685cf0a66c15c26f
1 Return-Path: <amdragon@mit.edu>\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 15AE2431FC3\r
6         for <notmuch@notmuchmail.org>; Thu, 30 May 2013 10:14:19 -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 576CL6XWLBfQ for <notmuch@notmuchmail.org>;\r
16         Thu, 30 May 2013 10:14:13 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
18         [18.9.25.12])\r
19         by olra.theworths.org (Postfix) with ESMTP id 405B3431FD2\r
20         for <notmuch@notmuchmail.org>; Thu, 30 May 2013 10:13:56 -0700 (PDT)\r
21 X-AuditID: 1209190c-b7f566d000004c69-af-51a788d2e626\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 9E.95.19561.2D887A15; Thu, 30 May 2013 13:13:54 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r4UHDgfo027512; \r
27         Thu, 30 May 2013 13:13:43 -0400\r
28 Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
29         [76.21.105.205]) (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r4UHDcFC009861\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 30 May 2013 13:13:41 -0400\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Ui6Py-0005r4-C1; Thu, 30 May 2013 13:13:38 -0400\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v2 3/5] emacs: Use async process helper for search\r
40 Date: Thu, 30 May 2013 13:13:34 -0400\r
41 Message-Id: <1369934016-22308-4-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 In-Reply-To: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
44 References: <1369934016-22308-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker:\r
46  H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsUixCmqrHupY3mgQfNnWYvVc3ksrt+cyWzx\r
47         ZuU8Vgdmj52z7rJ7HP66kMXj2apbzAHMUVw2Kak5mWWpRfp2CVwZd38sZi+YrVxx4dtD1gbG\r
48         29JdjJwcEgImEvemXmeDsMUkLtxbD2RzcQgJ7GOU2PHkPguEs5FRon3fDKjMaSaJCZNOMUE4\r
49         cxkllj6fxQ7SzyagIbFt/3JGEFtEQFpi593ZrCA2s0CcxJYp/8HiwgJOEq/a/4PtYxFQlZh3\r
50         7x8LiM0r4CBxZcYrZog7FCW6n00Aq+EUcJTYMfk02BwhoJpLe78yTWDkX8DIsIpRNiW3Sjc3\r
51         MTOnODVZtzg5MS8vtUjXUC83s0QvNaV0EyM4vCR5djC+Oah0iFGAg1GJhzcjaXmgEGtiWXFl\r
52         7iFGSQ4mJVHe9a1AIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8Bc5AOd6UxMqq1KJ8mJQ0B4uS\r
53         OO/llJv+QgLpiSWp2ampBalFMFkZDg4lCd7r7UCNgkWp6akVaZk5JQhpJg5OkOE8QMMvgNTw\r
54         Fhck5hZnpkPkTzEqSonzrgVJCIAkMkrz4Hph8f+KURzoFWHelSBVPMDUAdf9CmgwE9DgJ9Zg\r
55         g0sSEVJSDYyCdnzJfEp119QyG65PZ/NmZFl+KmLaxTN/ggv+7/q8TJqd9cn59qbzfx0Vnx7c\r
56         E6GzzKD08/+WSQV6Cw//d3Wy73z4/LqSW5zuGS7p6PBpe9Njor9YTEoVNlfeJXy8fdfbfyv4\r
57         +1I+GMxlKv5szdnFvkfl8M4tyxSmT3smGFh3MbJwA/enanUlluKMREMt5qLiRAAB3a2C2gIA        AA==\r
58 Cc: tomi.ollila@iki.fi\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Thu, 30 May 2013 17:14:19 -0000\r
72 \r
73 Previously, search started the async notmuch process directly.  Now,\r
74 it uses `notmuch-start-notmuch'.  This simplifies the process sentinel\r
75 a bit and means that we no longer have to worry about errors\r
76 interleaved with the JSON output.\r
77 \r
78 We also update the tests of Emacs error handling, since the error\r
79 output is now separated from the search results buffer.\r
80 ---\r
81  emacs/notmuch.el |   19 +++++--------------\r
82  test/emacs       |   36 ++++++++++++++++++++++++++++++++----\r
83  2 files changed, 37 insertions(+), 18 deletions(-)\r
84 \r
85 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
86 index 4c1a6ca..b8d9c44 100644\r
87 --- a/emacs/notmuch.el\r
88 +++ b/emacs/notmuch.el\r
89 @@ -653,15 +653,8 @@ of the result."\r
90                     ;; For version mismatch, there's no point in\r
91                     ;; showing the search buffer\r
92                     (when (or (= exit-status 20) (= exit-status 21))\r
93 -                     (kill-buffer))\r
94 -                   (condition-case err\r
95 -                       (notmuch-check-async-exit-status proc msg)\r
96 -                     ;; Suppress the error signal since strange\r
97 -                     ;; things happen if a sentinel signals.  Mimic\r
98 -                     ;; the top-level's handling of error messages.\r
99 -                     (error\r
100 -                      (message "%s" (error-message-string err))\r
101 -                      (throw 'return nil)))\r
102 +                     (kill-buffer)\r
103 +                     (throw 'return nil))\r
104                     (if (and atbob\r
105                              (not (string= notmuch-search-target-thread "found")))\r
106                         (set 'never-found-target-thread t)))))\r
107 @@ -938,10 +931,9 @@ Other optional parameters are used as follows:\r
108        (erase-buffer)\r
109        (goto-char (point-min))\r
110        (save-excursion\r
111 -       (let ((proc (start-process\r
112 -                    "notmuch-search" buffer\r
113 -                    notmuch-command "search"\r
114 -                    "--format=json" "--format-version=1"\r
115 +       (let ((proc (notmuch-start-notmuch\r
116 +                    "notmuch-search" buffer #'notmuch-search-process-sentinel\r
117 +                    "search" "--format=json" "--format-version=1"\r
118                      (if oldest-first\r
119                          "--sort=oldest-first"\r
120                        "--sort=newest-first")\r
121 @@ -951,7 +943,6 @@ Other optional parameters are used as follows:\r
122               ;; should be called no matter how the process dies.\r
123               (parse-buf (generate-new-buffer " *notmuch search parse*")))\r
124           (process-put proc 'parse-buf parse-buf)\r
125 -         (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
126           (set-process-filter proc 'notmuch-search-process-filter)\r
127           (set-process-query-on-exit-flag proc nil))))\r
128      (run-hooks 'notmuch-search-hook)))\r
129 diff --git a/test/emacs b/test/emacs\r
130 index f033bdf..d38ae8c 100755\r
131 --- a/test/emacs\r
132 +++ b/test/emacs\r
133 @@ -853,11 +853,10 @@ test_expect_success "Rendering HTML mail with images" \\r
134      'cat OUTPUT && grep -q smiley OUTPUT'\r
135  \r
136  \r
137 -test_begin_subtest "Search handles subprocess errors"\r
138 +test_begin_subtest "Search handles subprocess error exit codes"\r
139  cat > notmuch_fail <<EOF\r
140  #!/bin/sh\r
141  echo This is output\r
142 -echo This is an error >&2\r
143  exit 1\r
144  EOF\r
145  chmod a+x notmuch_fail\r
146 @@ -874,8 +873,6 @@ sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
147  test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
148  Error: Unexpected output from notmuch search:\r
149  This is output\r
150 -Error: Unexpected output from notmuch search:\r
151 -This is an error\r
152  End of search results.\r
153  ---\r
154  $PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
155 @@ -885,4 +882,35 @@ $PWD/notmuch_fail exited with status 1\r
156  command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox\r
157  exit status: 1"\r
158  \r
159 +test_begin_subtest "Search handles subprocess warnings"\r
160 +cat > notmuch_fail <<EOF\r
161 +#!/bin/sh\r
162 +echo This is output\r
163 +echo This is a warning >&2\r
164 +echo This is another warning >&2\r
165 +exit 0\r
166 +EOF\r
167 +chmod a+x notmuch_fail\r
168 +test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
169 +              (with-current-buffer \"*Messages*\" (erase-buffer))\r
170 +              (with-current-buffer \"*Notmuch errors*\" (erase-buffer))\r
171 +              (notmuch-search \"tag:inbox\")\r
172 +              (notmuch-test-wait)\r
173 +              (with-current-buffer \"*Messages*\"\r
174 +                 (test-output \"MESSAGES\"))\r
175 +              (with-current-buffer \"*Notmuch errors*\"\r
176 +                 (test-output \"ERROR\"))\r
177 +              (test-output))"\r
178 +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
179 +test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
180 +Error: Unexpected output from notmuch search:\r
181 +This is output\r
182 +End of search results.\r
183 +---\r
184 +This is a warning (see *Notmuch errors* for more details)\r
185 +---\r
186 +[XXX]\r
187 +This is a warning\r
188 +This is another warning"\r
189 +\r
190  test_done\r
191 -- \r
192 1.7.10.4\r
193 \r