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