Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 64 / 88b7967835eeccc6e7b61497a82479f76b38de
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 olra.theworths.org (Postfix) with ESMTP id A7B62429E21\r
6         for <notmuch@notmuchmail.org>; Tue,  3 Jan 2012 06:12:36 -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.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 9zxfH4lJxgla for <notmuch@notmuchmail.org>;\r
16         Tue,  3 Jan 2012 06:12:35 -0800 (PST)\r
17 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
18         [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 5736D431FD0\r
21         for <notmuch@notmuchmail.org>; Tue,  3 Jan 2012 06:12:35 -0800 (PST)\r
22 Received: by wibhq2 with SMTP id hq2so10819131wib.26\r
23         for <notmuch@notmuchmail.org>; Tue, 03 Jan 2012 06:12:32 -0800 (PST)\r
24 Received: by 10.180.96.72 with SMTP id dq8mr113778815wib.10.1325599952094;\r
25         Tue, 03 Jan 2012 06:12:32 -0800 (PST)\r
26 Received: from hotblack-desiato.hh.sledj.net\r
27         (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
28         by mx.google.com with ESMTPS id\r
29         fv13sm22624432wbb.21.2012.01.03.06.12.30\r
30         (version=TLSv1/SSLv3 cipher=OTHER);\r
31         Tue, 03 Jan 2012 06:12:30 -0800 (PST)\r
32 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
33         id A43AAA05D6; Tue,  3 Jan 2012 14:12:27 +0000 (GMT)\r
34 From: David Edmondson <dme@dme.org>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: =?UTF-8?q?=5BPATCH=5D=20emacs=3A=20Improved=20printing=20support=2E?=\r
37 Date: Tue,  3 Jan 2012 14:12:26 +0000\r
38 Message-Id: <1325599946-5936-1-git-send-email-dme@dme.org>\r
39 X-Mailer: git-send-email 1.7.7.3\r
40 In-Reply-To: <1325240897-27525-1-git-send-email-dme@dme.org>\r
41 References: <1325240897-27525-1-git-send-email-dme@dme.org>\r
42 MIME-Version: 1.0\r
43 Content-Type: text/plain; charset=UTF-8\r
44 Content-Transfer-Encoding: 8bit\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Tue, 03 Jan 2012 14:12:36 -0000\r
58 \r
59 Add various functions to print notmuch messages and tie them together\r
60 with a simple frontend. No keybinding is currently made to encourage\r
61 paper saving.\r
62 ---\r
63 \r
64 Fix the lack of shell quoting for muttprint. Rename the ps-print\r
65 buffers to have a relevant name.\r
66 \r
67  emacs/Makefile.local   |    3 +-\r
68  emacs/notmuch-print.el |   79 ++++++++++++++++++++++++++++++++++++++++++++++++\r
69  emacs/notmuch-show.el  |   51 +++++++++++++++++++++++++++++++\r
70  3 files changed, 132 insertions(+), 1 deletions(-)\r
71  create mode 100644 emacs/notmuch-print.el\r
72 \r
73 diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
74 index 0c58b82..4fee0e8 100644\r
75 --- a/emacs/Makefile.local\r
76 +++ b/emacs/Makefile.local\r
77 @@ -13,7 +13,8 @@ emacs_sources := \\r
78         $(dir)/notmuch-maildir-fcc.el \\r
79         $(dir)/notmuch-message.el \\r
80         $(dir)/notmuch-crypto.el \\r
81 -       $(dir)/coolj.el\r
82 +       $(dir)/coolj.el \\r
83 +       $(dir)/notmuch-print.el\r
84  \r
85  emacs_images := \\r
86         $(srcdir)/$(dir)/notmuch-logo.png\r
87 diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el\r
88 new file mode 100644\r
89 index 0000000..d4b7ed4\r
90 --- /dev/null\r
91 +++ b/emacs/notmuch-print.el\r
92 @@ -0,0 +1,79 @@\r
93 +;; notmuch-print.el --- printing messages from notmuch.\r
94 +;;\r
95 +;; Copyright © David Edmondson\r
96 +;;\r
97 +;; This file is part of Notmuch.\r
98 +;;\r
99 +;; Notmuch is free software: you can redistribute it and/or modify it\r
100 +;; under the terms of the GNU General Public License as published by\r
101 +;; the Free Software Foundation, either version 3 of the License, or\r
102 +;; (at your option) any later version.\r
103 +;;\r
104 +;; Notmuch is distributed in the hope that it will be useful, but\r
105 +;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
106 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
107 +;; General Public License for more details.\r
108 +;;\r
109 +;; You should have received a copy of the GNU General Public License\r
110 +;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
111 +;;\r
112 +;; Authors: David Edmondson <dme@dme.org>\r
113 +\r
114 +(defcustom notmuch-print-mechanism 'notmuch-print-lpr\r
115 +  "How should printing be done?"\r
116 +  :group 'notmuch\r
117 +  :type '(choice\r
118 +         (function :tag "Use lpr" notmuch-print-lpr)\r
119 +         (function :tag "Use ps-print" notmuch-print-ps-print)\r
120 +         (function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)\r
121 +         (function :tag "Use muttprint" notmuch-print-muttprint)\r
122 +         (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)\r
123 +         (function :tag "Using a custom function")))\r
124 +\r
125 +(defmacro notmuch-print-with-file (filename &rest body)\r
126 +  `(with-temp-buffer\r
127 +     (insert-file-contents ,filename)\r
128 +     (set-buffer-modified-p nil)\r
129 +     ,@body))\r
130 +\r
131 +(defun notmuch-print-lpr (filename msg)\r
132 +  (notmuch-print-with-file filename\r
133 +                          (lpr-buffer)))\r
134 +\r
135 +(defun notmuch-print-ps-print (filename msg)\r
136 +  (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
137 +    (notmuch-print-with-file filename\r
138 +                            (rename-buffer subject t)\r
139 +                            (ps-print-buffer))))\r
140 +\r
141 +(defun notmuch-print-ps-print/evince (filename msg)\r
142 +  (let ((ps-file (make-temp-file "notmuch"))\r
143 +       (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
144 +    (notmuch-print-with-file filename\r
145 +                            (rename-buffer subject t)\r
146 +                            (ps-print-buffer ps-file)\r
147 +                            (async-shell-command (concat "evince " ps-file)))))\r
148 +\r
149 +(defun notmuch-print-muttprint (filename msg)\r
150 +  (shell-command\r
151 +   (concat "muttprint "\r
152 +          "--file " (shell-quote-argument filename) " "\r
153 +          ;; Show the tags.\r
154 +          "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/'")))\r
155 +\r
156 +(defun notmuch-print-muttprint/evince (filename msg)\r
157 +  (let ((ps-file (make-temp-file "notmuch")))\r
158 +    (call-process-shell-command\r
159 +     (concat "muttprint "\r
160 +            "--file " (shell-quote-argument filename) " "\r
161 +            ;; Show the tags.\r
162 +            "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/' "\r
163 +            "--printer 'TO_FILE:" (shell-quote-argument ps-file) "'"))\r
164 +    (async-shell-command (concat "evince " ps-file))))\r
165 +\r
166 +(defun notmuch-print-message (filename msg)\r
167 +  (funcall notmuch-print-mechanism filename msg))\r
168 +\r
169 +;;\r
170 +\r
171 +(provide 'notmuch-print)\r
172 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
173 index 5502efd..55ccfc5 100644\r
174 --- a/emacs/notmuch-show.el\r
175 +++ b/emacs/notmuch-show.el\r
176 @@ -34,6 +34,7 @@\r
177  (require 'notmuch-wash)\r
178  (require 'notmuch-mua)\r
179  (require 'notmuch-crypto)\r
180 +(require 'notmuch-print)\r
181  \r
182  (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
183  (declare-function notmuch-fontify-headers "notmuch" nil)\r
184 @@ -186,6 +187,51 @@ indentation."\r
185        mm-handle (> (notmuch-count-attachments mm-handle) 1))))\r
186    (message "Done"))\r
187  \r
188 +(defun notmuch-show-with-message-as-text (fn)\r
189 +  "Apply function `fn' to a text representation of the current\r
190 +message."\r
191 +\r
192 +  ;; Remake the header to ensure that all information is available.\r
193 +  (let* ((to (notmuch-show-get-to))\r
194 +        (cc (notmuch-show-get-cc))\r
195 +        (from (notmuch-show-get-from))\r
196 +        (subject (notmuch-show-get-subject))\r
197 +        (date (notmuch-show-get-date))\r
198 +        (tags (notmuch-show-get-tags))\r
199 +        (depth (notmuch-show-get-depth))\r
200 +\r
201 +        (header (concat\r
202 +                 "Subject: " subject "\n"\r
203 +                 "To: " to "\n"\r
204 +                 (if (not (string= cc ""))\r
205 +                     (concat "Cc: " cc "\n")\r
206 +                   "")\r
207 +                 "From: " from "\n"\r
208 +                 "Date: " date "\n"\r
209 +                 (if tags\r
210 +                     (concat "Tags: "\r
211 +                             (mapconcat '(lambda (tag) tag) tags ", ") "\n")\r
212 +                   "")))\r
213 +        (all (buffer-substring (notmuch-show-message-top)\r
214 +                               (notmuch-show-message-bottom)))\r
215 +\r
216 +        (file (make-temp-file "notmuch")))\r
217 +    (with-temp-file file\r
218 +      (insert all)\r
219 +      (indent-rigidly (point-min) (point-max) (- depth))\r
220 +      ;; Remove the original header.\r
221 +      (goto-char (point-min))\r
222 +      (re-search-forward "^$" (point-max) nil)\r
223 +      (delete-region (point-min) (point))\r
224 +      (insert header))\r
225 +    (funcall fn file (notmuch-show-get-message-properties))\r
226 +    (delete-file file)))\r
227 +\r
228 +(defun notmuch-show-print-message ()\r
229 +  "Print the current message."\r
230 +  (interactive)\r
231 +  (notmuch-show-with-message-as-text 'notmuch-print-message))\r
232 +\r
233  (defun notmuch-show-fontify-header ()\r
234    (let ((face (cond\r
235                ((looking-at "[Tt]o:")\r
236 @@ -760,6 +806,8 @@ current buffer, if possible."\r
237        (overlay-put headers-overlay 'priority 10))\r
238      (overlay-put (make-overlay body-start body-end) 'invisible message-invis-spec)\r
239  \r
240 +    (plist-put msg :depth depth)\r
241 +\r
242      ;; Save the properties for this message. Currently this saves the\r
243      ;; entire message (augmented it with other stuff), which seems\r
244      ;; like overkill. We might save a reduced subset (for example, not\r
245 @@ -1111,6 +1159,9 @@ Some useful entries are:\r
246  (defun notmuch-show-get-to ()\r
247    (notmuch-show-get-header :To))\r
248  \r
249 +(defun notmuch-show-get-depth ()\r
250 +  (notmuch-show-get-prop :depth))\r
251 +\r
252  (defun notmuch-show-set-tags (tags)\r
253    "Set the tags of the current message."\r
254    (notmuch-show-set-prop :tags tags)\r
255 -- \r
256 1.7.7.3\r
257 \r