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
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
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
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
66 I don=E2=80=99t have (easy access to) a printer, so I haven=E2=80=99t actua=
\r
68 the printing functionality of this patch.
\r
70 In general, the patch LGTM. Specific comments below.
\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
78 > Fix the lack of shell quoting for muttprint. Rename the ps-print
\r
79 > buffers to have a relevant name.
\r
81 > emacs/Makefile.local | 3 +-
\r
82 > emacs/notmuch-print.el | 79 ++++++++++++++++++++++++++++++++++++++++++=
\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
88 > diff --git a/emacs/Makefile.local b/emacs/Makefile.local
\r
93 > +++ b/emacs/notmuch-print.el
\r
95 > +;; notmuch-print.el --- printing messages from notmuch.
\r
97 > +;; Copyright =C2=A9 David Edmondson
\r
99 > +;; This file is part of Notmuch.
\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
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
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
114 > +;; Authors: David Edmondson <dme@dme.org>
\r
116 > +(defcustom notmuch-print-mechanism 'notmuch-print-lpr
\r
117 > + "How should printing be done?"
\r
118 > + :group 'notmuch
\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
124 > + (function :tag "Use muttprint" notmuch-print-muttprint)
\r
125 > + (function :tag "Use muttprint then evince" notmuch-print-muttprint/ev=
\r
127 > + (function :tag "Using a custom function")))
\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
135 > +(defun notmuch-print-lpr (filename msg)
\r
136 > + (notmuch-print-with-file filename
\r
139 > +(defun notmuch-print-ps-print (filename msg)
\r
140 > + (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subjec=
\r
142 > + (notmuch-print-with-file filename
\r
143 > + (rename-buffer subject t)
\r
144 > + (ps-print-buffer))))
\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
154 > +(defun notmuch-print-muttprint (filename msg)
\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
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
171 > +(defun notmuch-print-message (filename msg)
\r
172 > + (funcall notmuch-print-mechanism filename msg))
\r
176 The above is just a stray comment line, right?
\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
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
196 > +(defun notmuch-show-with-message-as-text (fn)
\r
197 > + "Apply function `fn' to a text representation of the current
\r
200 I think the docstring should say what agrs get passed to =E2=80=98fn=E2=80=
\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
205 (...the rest unchanged)=E2=80=9D for brevity in the first line.
\r
207 (For anyone who is curious, these and other conventions are documented
\r
208 in section D.6 of the Elisp manual.)
\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
220 > + (header (concat
\r
221 > + "Subject: " subject "\n"
\r
223 > + (if (not (string=3D cc ""))
\r
224 > + (concat "Cc: " cc "\n")
\r
226 > + "From: " from "\n"
\r
227 > + "Date: " date "\n"
\r
229 > + (concat "Tags: "
\r
230 > + (mapconcat '(lambda (tag) tag) tags ", ") "\n")
\r
232 #'identity instead of the lambda
\r
235 > + (all (buffer-substring (notmuch-show-message-top)
\r
236 > + (notmuch-show-message-bottom)))
\r
238 > + (file (make-temp-file "notmuch")))
\r
239 > + (with-temp-file file
\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
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
256 itself, but rather let each consumer of text-ified messages handle
\r
258 - It would be cleaner if print backends that don=E2=80=99t crucially depend=
\r
260 the existence of a file didn=E2=80=99t create one at all. If muttprint c=
\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
269 > +(defun notmuch-show-print-message ()
\r
270 > + "Print the current message."
\r
272 > + (notmuch-show-with-message-as-text 'notmuch-print-message))
\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
282 > + (plist-put msg :depth depth)
\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
291 > +(defun notmuch-show-get-depth ()
\r
292 > + (notmuch-show-get-prop :depth))
\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
300 > _______________________________________________
\r
301 > notmuch mailing list
\r
302 > notmuch@notmuchmail.org
\r
303 > http://notmuchmail.org/mailman/listinfo/notmuch
\r