Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 5b / 28ed3c11e0411da8ade509ad29099ccd9e0d76
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 B020D429E53\r
6         for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 08:19:28 -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 nKhQWC4vx+2F for <notmuch@notmuchmail.org>;\r
16         Thu, 24 Oct 2013 08:19:23 -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 74D02429E41\r
20         for <notmuch@notmuchmail.org>; Thu, 24 Oct 2013 08:19:18 -0700 (PDT)\r
21 X-AuditID: 1209190c-b7fd38e0000009aa-24-52693a751991\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id C0.5C.02474.67A39625; Thu, 24 Oct 2013 11:19:18 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id r9OFJFZ8030432; \r
27         Thu, 24 Oct 2013 11:19:15 -0400\r
28 Received: from drake.dyndns.org\r
29         (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [216.15.114.40]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9OFJCh0012917\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Thu, 24 Oct 2013 11:19:14 -0400\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1VZMgq-0006du-Pu; Thu, 24 Oct 2013 11:19:12 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v2 06/11] emacs: Support passing input via\r
41         `notmuch-call-notmuch-*'\r
42 Date: Thu, 24 Oct 2013 11:19:06 -0400\r
43 Message-Id: <1382627951-25252-7-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.8.4.rc3\r
45 In-Reply-To: <1382627951-25252-1-git-send-email-amdragon@mit.edu>\r
46 References: <1382627951-25252-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrVtmlRlksKKJ2aJpurPF6rk8Ftdv\r
49         zmR2YPbYOesuu8et+6/ZPZ6tusUcwBzFZZOSmpNZllqkb5fAlXFs3UrWggUSFW/7t7A1MN4U\r
50         7mLk4JAQMJF42RXbxcgJZIpJXLi3nq2LkYtDSGAfo8TXpxsZIZyNjBJLp09hhnDuMEmcmb2X\r
51         BcKZC5T5f50VpJ9NQENi2/7ljCC2iIC0xM67s8HizALREkcuz2ADsYUFgiUerPrPDGKzCKhK\r
52         /Nt1hgnE5hVwkNhxayo7xB1KEgtPbQPr5RRwlPj5+hrYTCGgml+/z7BMYORfwMiwilE2JbdK\r
53         NzcxM6c4NVm3ODkxLy+1SNdQLzezRC81pXQTIzi0JHl2ML45qHSIUYCDUYmHV+NDepAQa2JZ\r
54         cWXuIUZJDiYlUd57pplBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4p+kB5XhTEiurUovyYVLS\r
55         HCxK4rw3OeyDhATSE0tSs1NTC1KLYLIyHBxKErydlkCNgkWp6akVaZk5JQhpJg5OkOE8QMOX\r
56         gtTwFhck5hZnpkPkTzEqSonzzgNJCIAkMkrz4Hphsf+KURzoFWHecpAqHmDagOt+BTSYCWjw\r
57         lCVpIINLEhFSUg2MLY9dyibl8WZu+vA4LOgE5/TUUJO6EsNrS1Ia9bnbykVzOLzWGVn4yBRN\r
58         7PmQkbTumCnTrojVhUztL597Z8zLrJhgUXy4Mzo09oqC05mVcrtCFSsyzh9mO5V4XvNZvnbT\r
59         PUkBPmaFjyqXGssOF9qYl3/2Pdtitegxf53gJzbJy8e+9z5TuKjEUpyRaKjFXFScCACYcusw\r
60         2AIAAA==\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Thu, 24 Oct 2013 15:19:29 -0000\r
74 \r
75 This adds support for passing a string to write to notmuch's stdin to\r
76 `notmuch-call-notmuch-process' and `notmuch-call-notmuch-sexp'.  Since\r
77 this makes both interfaces a little more complicated, it also unifies\r
78 their documentation better.\r
79 ---\r
80  emacs/notmuch-lib.el | 39 +++++++++++++++++++++++++++++++++------\r
81  1 file changed, 33 insertions(+), 6 deletions(-)\r
82 \r
83 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
84 index 4e0604e..22156f1 100644\r
85 --- a/emacs/notmuch-lib.el\r
86 +++ b/emacs/notmuch-lib.el\r
87 @@ -534,28 +534,55 @@ You may need to restart Emacs or upgrade your notmuch package."))\r
88         ;; `notmuch-logged-error' does not return.\r
89         ))))\r
90  \r
91 +(defun notmuch-call-notmuch--helper (destination args)\r
92 +  "Helper for synchronous notmuch invocation commands.\r
93 +\r
94 +This wraps `call-process'.  DESTINATION has the same meaning as\r
95 +for `call-process'.  ARGS is as described for\r
96 +`notmuch-call-notmuch-process'."\r
97 +\r
98 +  (let (stdin-string)\r
99 +    (while (keywordp (car args))\r
100 +      (case (car args)\r
101 +       (:stdin-string (setq stdin-string (cadr args)\r
102 +                            args (cddr args)))\r
103 +       (otherwise\r
104 +        (error "Unknown keyword argument: %s" (car args)))))\r
105 +    (if (null stdin-string)\r
106 +       (apply #'call-process notmuch-command nil destination nil args)\r
107 +      (insert stdin-string)\r
108 +      (apply #'call-process-region (point-min) (point-max)\r
109 +            notmuch-command t destination nil args))))\r
110 +\r
111  (defun notmuch-call-notmuch-process (&rest args)\r
112 -  "Synchronously invoke \"notmuch\" with the given list of arguments.\r
113 +  "Synchronously invoke `notmuch-command' with ARGS.\r
114 +\r
115 +The caller may provide keyword arguments before ARGS.  Currently\r
116 +supported keyword arguments are:\r
117 +\r
118 +  :stdin-string STRING - Write STRING to stdin\r
119  \r
120  If notmuch exits with a non-zero status, output from the process\r
121  will appear in a buffer named \"*Notmuch errors*\" and an error\r
122  will be signaled."\r
123    (with-temp-buffer\r
124 -    (let ((status (apply #'call-process notmuch-command nil t nil args)))\r
125 +    (let ((status (notmuch-call-notmuch--helper t args)))\r
126        (notmuch-check-exit-status status (cons notmuch-command args)\r
127                                  (buffer-string)))))\r
128  \r
129  (defun notmuch-call-notmuch-sexp (&rest args)\r
130    "Invoke `notmuch-command' with ARGS and return the parsed S-exp output.\r
131  \r
132 -If notmuch exits with a non-zero status, this will pop up a\r
133 -buffer containing notmuch's output and signal an error."\r
134 +This is equivalent to `notmuch-call-notmuch-process', but parses\r
135 +notmuch's output as an S-expression and returns the parsed value.\r
136 +Like `notmuch-call-notmuch-process', if notmuch exits with a\r
137 +non-zero status, this will report its output and signal an\r
138 +error."\r
139  \r
140    (with-temp-buffer\r
141      (let ((err-file (make-temp-file "nmerr")))\r
142        (unwind-protect\r
143 -         (let ((status (apply #'call-process\r
144 -                              notmuch-command nil (list t err-file) nil args)))\r
145 +         (let ((status (notmuch-call-notmuch--helper (list t err-file) args)))\r
146             (notmuch-check-exit-status status (cons notmuch-command args)\r
147                                        (buffer-string) err-file)\r
148             (goto-char (point-min))\r
149 -- \r
150 1.8.4.rc3\r
151 \r