[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / db / f45c5206b2150983c420a69341957d475073ad
1 Return-Path: <aaronecay@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 8A934429E3B\r
6         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:27:13 -0800 (PST)\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 q5rYiFjpNWdO for <notmuch@notmuchmail.org>;\r
17         Mon, 16 Jan 2012 13:27:12 -0800 (PST)\r
18 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
19         [209.85.216.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 786A2429E35\r
22         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:27:12 -0800 (PST)\r
23 Received: by qcqw6 with SMTP id w6so2242389qcq.26\r
24         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:27:11 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
27         :mime-version:content-type:content-transfer-encoding;\r
28         bh=7ozNwxr4ptHJcRgJOFsK+WnK5/i3LcgBNPSr5IBOkEQ=;\r
29         b=a2k/7kc3MbNDxXdyOejkZKgZ44FzxwMYTmktQXZHKa4raM/Svc9XpMXglPW3/WWWKn\r
30         ixKkZYfxrc18WMRoyMWFxk2cA75ReBDX5Tz3SHWXr3WFiQrrBorouzUoONOkeECU0HEV\r
31         e/a/MkUu1riA4DmqenJCMiZQxwy1OApQomo5c=\r
32 Received: by 10.224.184.73 with SMTP id cj9mr12792938qab.80.1326749230699;\r
33         Mon, 16 Jan 2012 13:27:10 -0800 (PST)\r
34 Received: from localhost (vpl458.wlan.library.upenn.edu. [130.91.141.203])\r
35         by mx.google.com with ESMTPS id\r
36         dh10sm39226003qab.19.2012.01.16.13.27.09\r
37         (version=TLSv1/SSLv3 cipher=OTHER);\r
38         Mon, 16 Jan 2012 13:27:09 -0800 (PST)\r
39 From: Aaron Ecay <aaronecay@gmail.com>\r
40 To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
41 Subject: Re: [PATCH] emacs: Improved printing support.\r
42 In-Reply-To: <1325599946-5936-1-git-send-email-dme@dme.org>\r
43 References: <1325240897-27525-1-git-send-email-dme@dme.org>\r
44         <1325599946-5936-1-git-send-email-dme@dme.org>\r
45 User-Agent: Notmuch/0.11+62~ge41b0d3 (http://notmuchmail.org) Emacs/24.0.92.1\r
46         (i386-apple-darwin10.8.0)\r
47 Date: Mon, 16 Jan 2012 16:27:06 -0500\r
48 Message-ID: <m2vcobbaol.fsf@gmail.com>\r
49 MIME-Version: 1.0\r
50 Content-Type: text/plain; charset=utf-8\r
51 Content-Transfer-Encoding: quoted-printable\r
52 X-BeenThere: notmuch@notmuchmail.org\r
53 X-Mailman-Version: 2.1.13\r
54 Precedence: list\r
55 List-Id: "Use and development of the notmuch mail system."\r
56         <notmuch.notmuchmail.org>\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
60 List-Post: <mailto:notmuch@notmuchmail.org>\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
64 X-List-Received-Date: Mon, 16 Jan 2012 21:27:13 -0000\r
65 \r
66 I don=E2=80=99t have (easy access to) a printer, so I haven=E2=80=99t actua=\r
67 lly exercised\r
68 the printing functionality of this patch.\r
69 \r
70 In general, the patch LGTM.  Specific comments below.\r
71 \r
72 On Tue,  3 Jan 2012 14:12:26 +0000, David Edmondson <dme@dme.org> wrote:\r
73 > Add various functions to print notmuch messages and tie them together\r
74 > with a simple frontend. No keybinding is currently made to encourage\r
75 > paper saving.\r
76 > ---\r
77 >=20\r
78 > Fix the lack of shell quoting for muttprint. Rename the ps-print\r
79 > buffers to have a relevant name.\r
80 >=20\r
81 >  emacs/Makefile.local   |    3 +-\r
82 >  emacs/notmuch-print.el |   79 ++++++++++++++++++++++++++++++++++++++++++=\r
83 ++++++\r
84 >  emacs/notmuch-show.el  |   51 +++++++++++++++++++++++++++++++\r
85 >  3 files changed, 132 insertions(+), 1 deletions(-)\r
86 >  create mode 100644 emacs/notmuch-print.el\r
87 >=20\r
88 > diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
89 \r
90 [...]\r
91 \r
92 > --- /dev/null\r
93 > +++ b/emacs/notmuch-print.el\r
94 > @@ -0,0 +1,79 @@\r
95 > +;; notmuch-print.el --- printing messages from notmuch.\r
96 > +;;\r
97 > +;; Copyright =C2=A9 David Edmondson\r
98 > +;;\r
99 > +;; This file is part of Notmuch.\r
100 > +;;\r
101 > +;; Notmuch is free software: you can redistribute it and/or modify it\r
102 > +;; under the terms of the GNU General Public License as published by\r
103 > +;; the Free Software Foundation, either version 3 of the License, or\r
104 > +;; (at your option) any later version.\r
105 > +;;\r
106 > +;; Notmuch is distributed in the hope that it will be useful, but\r
107 > +;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
108 > +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
109 > +;; General Public License for more details.\r
110 > +;;\r
111 > +;; You should have received a copy of the GNU General Public License\r
112 > +;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
113 > +;;\r
114 > +;; Authors: David Edmondson <dme@dme.org>\r
115 > +\r
116 > +(defcustom notmuch-print-mechanism 'notmuch-print-lpr\r
117 > +  "How should printing be done?"\r
118 > +  :group 'notmuch\r
119 > +  :type '(choice\r
120 > +       (function :tag "Use lpr" notmuch-print-lpr)\r
121 > +       (function :tag "Use ps-print" notmuch-print-ps-print)\r
122 > +       (function :tag "Use ps-print then evince" notmuch-print-ps-print/evin=\r
123 ce)\r
124 > +       (function :tag "Use muttprint" notmuch-print-muttprint)\r
125 > +       (function :tag "Use muttprint then evince" notmuch-print-muttprint/ev=\r
126 ince)\r
127 > +       (function :tag "Using a custom function")))\r
128 > +\r
129 > +(defmacro notmuch-print-with-file (filename &rest body)\r
130 > +  `(with-temp-buffer\r
131 > +     (insert-file-contents ,filename)\r
132 > +     (set-buffer-modified-p nil)\r
133 > +     ,@body))\r
134 > +\r
135 > +(defun notmuch-print-lpr (filename msg)\r
136 > +  (notmuch-print-with-file filename\r
137 > +                        (lpr-buffer)))\r
138 > +\r
139 > +(defun notmuch-print-ps-print (filename msg)\r
140 > +  (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subjec=\r
141 t)))\r
142 > +    (notmuch-print-with-file filename\r
143 > +                          (rename-buffer subject t)\r
144 > +                          (ps-print-buffer))))\r
145 > +\r
146 > +(defun notmuch-print-ps-print/evince (filename msg)\r
147 > +  (let ((ps-file (make-temp-file "notmuch"))\r
148 > +     (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
149 > +    (notmuch-print-with-file filename\r
150 > +                          (rename-buffer subject t)\r
151 > +                          (ps-print-buffer ps-file)\r
152 > +                          (async-shell-command (concat "evince " ps-file)))))\r
153 > +\r
154 > +(defun notmuch-print-muttprint (filename msg)\r
155 > +  (shell-command\r
156 > +   (concat "muttprint "\r
157 > +        "--file " (shell-quote-argument filename) " "\r
158 > +        ;; Show the tags.\r
159 > +        "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/'")))\r
160 > +\r
161 > +(defun notmuch-print-muttprint/evince (filename msg)\r
162 > +  (let ((ps-file (make-temp-file "notmuch")))\r
163 > +    (call-process-shell-command\r
164 > +     (concat "muttprint "\r
165 > +          "--file " (shell-quote-argument filename) " "\r
166 > +          ;; Show the tags.\r
167 > +          "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/' "\r
168 > +          "--printer 'TO_FILE:" (shell-quote-argument ps-file) "'"))\r
169 > +    (async-shell-command (concat "evince " ps-file))))\r
170 > +\r
171 > +(defun notmuch-print-message (filename msg)\r
172 > +  (funcall notmuch-print-mechanism filename msg))\r
173 > +\r
174 > +;;\r
175 \r
176 The above is just a stray comment line, right?\r
177 \r
178 > +\r
179 > +(provide 'notmuch-print)\r
180 > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
181 > index 5502efd..55ccfc5 100644\r
182 > --- a/emacs/notmuch-show.el\r
183 > +++ b/emacs/notmuch-show.el\r
184 > @@ -34,6 +34,7 @@\r
185 >  (require 'notmuch-wash)\r
186 >  (require 'notmuch-mua)\r
187 >  (require 'notmuch-crypto)\r
188 > +(require 'notmuch-print)\r
189 >=20=20\r
190 >  (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
191 >  (declare-function notmuch-fontify-headers "notmuch" nil)\r
192 > @@ -186,6 +187,51 @@ indentation."\r
193 >        mm-handle (> (notmuch-count-attachments mm-handle) 1))))\r
194 >    (message "Done"))\r
195 >=20=20\r
196 > +(defun notmuch-show-with-message-as-text (fn)\r
197 > +  "Apply function `fn' to a text representation of the current\r
198 > +message."\r
199 \r
200 I think the docstring should say what agrs get passed to =E2=80=98fn=E2=80=\r
201 =99.  Also,\r
202 function arguments should be referred to with capital letters, and the\r
203 first line should be a complete sentence.  I=E2=80=99d recommend =E2=80=9CA=\r
204 pply FN to\r
205 (...the rest unchanged)=E2=80=9D for brevity in the first line.\r
206 \r
207 (For anyone who is curious, these and other conventions are documented\r
208 in section D.6 of the Elisp manual.)\r
209 \r
210 > +\r
211 > +  ;; Remake the header to ensure that all information is available.\r
212 > +  (let* ((to (notmuch-show-get-to))\r
213 > +      (cc (notmuch-show-get-cc))\r
214 > +      (from (notmuch-show-get-from))\r
215 > +      (subject (notmuch-show-get-subject))\r
216 > +      (date (notmuch-show-get-date))\r
217 > +      (tags (notmuch-show-get-tags))\r
218 > +      (depth (notmuch-show-get-depth))\r
219 > +\r
220 > +      (header (concat\r
221 > +               "Subject: " subject "\n"\r
222 > +               "To: " to "\n"\r
223 > +               (if (not (string=3D cc ""))\r
224 > +                   (concat "Cc: " cc "\n")\r
225 > +                 "")\r
226 > +               "From: " from "\n"\r
227 > +               "Date: " date "\n"\r
228 > +               (if tags\r
229 > +                   (concat "Tags: "\r
230 > +                           (mapconcat '(lambda (tag) tag) tags ", ") "\n")\r
231 \r
232 #'identity instead of the lambda\r
233 \r
234 > +                 "")))\r
235 > +      (all (buffer-substring (notmuch-show-message-top)\r
236 > +                             (notmuch-show-message-bottom)))\r
237 > +\r
238 > +      (file (make-temp-file "notmuch")))\r
239 > +    (with-temp-file file\r
240 > +      (insert all)\r
241 > +      (indent-rigidly (point-min) (point-max) (- depth))\r
242 > +      ;; Remove the original header.\r
243 > +      (goto-char (point-min))\r
244 > +      (re-search-forward "^$" (point-max) nil)\r
245 > +      (delete-region (point-min) (point))\r
246 > +      (insert header))\r
247 > +    (funcall fn file (notmuch-show-get-message-properties))\r
248 > +    (delete-file file)))\r
249 \r
250 Why does this function write to a file?  It seems that, of the print\r
251 methods, two (ps-print and lpr) don=E2=80=99t use the file at all.  One\r
252 (ps-print/evince) creates yet another file, without depending on the\r
253 first.  The other muttprint functions do use the file.  So:\r
254 - This function would be more general if it didn=E2=80=99t handle file-writ=\r
255 ing\r
256   itself, but rather let each consumer of text-ified messages handle\r
257   that if needed.\r
258 - It would be cleaner if print backends that don=E2=80=99t crucially depend=\r
259  on\r
260   the existence of a file didn=E2=80=99t create one at all.  If muttprint c=\r
261 an\r
262   accept a message on stdin (it looks from the source like it can; it\r
263   gives me some error message about Iconv Perl modules when I try to run\r
264   it, so I can=E2=80=99t be sure), maybe writing to a file isn=E2=80=99t ne=\r
265 cessary at\r
266   all.\r
267 \r
268 > +\r
269 > +(defun notmuch-show-print-message ()\r
270 > +  "Print the current message."\r
271 > +  (interactive)\r
272 > +  (notmuch-show-with-message-as-text 'notmuch-print-message))\r
273 > +\r
274 >  (defun notmuch-show-fontify-header ()\r
275 >    (let ((face (cond\r
276 >              ((looking-at "[Tt]o:")\r
277 > @@ -760,6 +806,8 @@ current buffer, if possible."\r
278 >        (overlay-put headers-overlay 'priority 10))\r
279 >      (overlay-put (make-overlay body-start body-end) 'invisible message-i=\r
280 nvis-spec)\r
281 >=20=20\r
282 > +    (plist-put msg :depth depth)\r
283 > +\r
284 >      ;; Save the properties for this message. Currently this saves the\r
285 >      ;; entire message (augmented it with other stuff), which seems\r
286 >      ;; like overkill. We might save a reduced subset (for example, not\r
287 > @@ -1111,6 +1159,9 @@ Some useful entries are:\r
288 >  (defun notmuch-show-get-to ()\r
289 >    (notmuch-show-get-header :To))\r
290 >=20=20\r
291 > +(defun notmuch-show-get-depth ()\r
292 > +  (notmuch-show-get-prop :depth))\r
293 > +\r
294 >  (defun notmuch-show-set-tags (tags)\r
295 >    "Set the tags of the current message."\r
296 >    (notmuch-show-set-prop :tags tags)\r
297 > --=20\r
298 > 1.7.7.3\r
299 >=20\r
300 > _______________________________________________\r
301 > notmuch mailing list\r
302 > notmuch@notmuchmail.org\r
303 > http://notmuchmail.org/mailman/listinfo/notmuch\r
304 \r
305 --=20\r
306 Aaron Ecay\r