[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 96 / 7eb625d3ffddd911147ea478b498d2d0453213
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 883ED40DDCF\r
6         for <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 04:55:20 -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: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham\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 7Op59phRvHJB for <notmuch@notmuchmail.org>;\r
16         Fri, 12 Nov 2010 04:55:08 -0800 (PST)\r
17 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
18  [74.125.82.45])        by olra.theworths.org (Postfix) with ESMTP id 8F8A24196F0       for\r
19  <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 04:55:08 -0800 (PST)\r
20 Received: by wwb39 with SMTP id 39so28016wwb.2\r
21         for <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 04:55:07 -0800 (PST)\r
22 Received: by 10.216.28.15 with SMTP id f15mr3816609wea.39.1289566496478;\r
23         Fri, 12 Nov 2010 04:54:56 -0800 (PST)\r
24 Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
25         [81.149.164.25])\r
26         by mx.google.com with ESMTPS id p4sm2116657wej.28.2010.11.12.04.54.53\r
27         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
28         Fri, 12 Nov 2010 04:54:54 -0800 (PST)\r
29 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
30         id 7EB1C59405B; Fri, 12 Nov 2010 12:53:09 +0000 (GMT)\r
31 From: David Edmondson <dme@dme.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: =?UTF-8?q?=5BPATCH=5D=20emacs=3A=20Improved=20printing=20support=2E?=\r
34 Date: Fri, 12 Nov 2010 12:53:08 +0000\r
35 Message-Id: <1289566388-24300-1-git-send-email-dme@dme.org>\r
36 X-Mailer: git-send-email 1.7.2.3\r
37 In-Reply-To: <87sjz8yq5a.fsf@ut.hh.sledj.net>\r
38 References: <87sjz8yq5a.fsf@ut.hh.sledj.net>\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, 12 Nov 2010 12:55:20 -0000\r
55 \r
56 ---\r
57 \r
58 More usable (I'm trying 'muttprint then evince').\r
59 \r
60  emacs/Makefile.local   |    3 +-\r
61  emacs/notmuch-print.el |   75 ++++++++++++++++++++++++++++++++++++++++++++++++\r
62  emacs/notmuch-show.el  |   51 ++++++++++++++++++++++++++++++++\r
63  3 files changed, 128 insertions(+), 1 deletions(-)\r
64  create mode 100644 emacs/notmuch-print.el\r
65 \r
66 diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
67 index c5280f1..df87427 100644\r
68 --- a/emacs/Makefile.local\r
69 +++ b/emacs/Makefile.local\r
70 @@ -13,7 +13,8 @@ emacs_sources := \\r
71         $(dir)/notmuch-maildir-fcc.el \\r
72         $(dir)/notmuch-message.el \\r
73         $(dir)/coolj.el \\r
74 -       $(dir)/notmuch-lkml.el\r
75 +       $(dir)/notmuch-lkml.el \\r
76 +       $(dir)/notmuch-print.el\r
77  \r
78  emacs_images := \\r
79         $(dir)/notmuch-logo.png\r
80 diff --git a/emacs/notmuch-print.el b/emacs/notmuch-print.el\r
81 new file mode 100644\r
82 index 0000000..62e380c\r
83 --- /dev/null\r
84 +++ b/emacs/notmuch-print.el\r
85 @@ -0,0 +1,75 @@\r
86 +;; notmuch-print.el --- printing messages from notmuch.\r
87 +;;\r
88 +;; Copyright © David Edmondson\r
89 +;;\r
90 +;; This file is part of Notmuch.\r
91 +;;\r
92 +;; Notmuch is free software: you can redistribute it and/or modify it\r
93 +;; under the terms of the GNU General Public License as published by\r
94 +;; the Free Software Foundation, either version 3 of the License, or\r
95 +;; (at your option) any later version.\r
96 +;;\r
97 +;; Notmuch is distributed in the hope that it will be useful, but\r
98 +;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
99 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
100 +;; General Public License for more details.\r
101 +;;\r
102 +;; You should have received a copy of the GNU General Public License\r
103 +;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
104 +;;\r
105 +;; Authors: David Edmondson <dme@dme.org>\r
106 +\r
107 +(defcustom notmuch-print-mechanism 'notmuch-print-lpr\r
108 +  "How should printing be done?"\r
109 +  :group 'notmuch\r
110 +  :type '(choice\r
111 +         (function :tag "Use lpr" notmuch-print-lpr)\r
112 +         (function :tag "Use ps-print" notmuch-print-ps-print)\r
113 +         (function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)\r
114 +         (function :tag "Use muttprint" notmuch-print-muttprint)\r
115 +         (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)\r
116 +         (function :tag "Using a custom function")))\r
117 +\r
118 +(defmacro notmuch-print-with-file (filename &rest body)\r
119 +  `(with-temp-buffer\r
120 +     (insert-file-contents ,filename)\r
121 +     (setq buffer-modified-p nil)\r
122 +     ,@body))\r
123 +\r
124 +(defun notmuch-print-lpr (filename)\r
125 +  (notmuch-print-with-file filename\r
126 +                          (lpr-buffer)))\r
127 +\r
128 +(defun notmuch-print-ps-print (filename)\r
129 +  (notmuch-print-with-file filename\r
130 +                          (ps-print-buffer)))\r
131 +\r
132 +(defun notmuch-print-ps-print/evince (filename)\r
133 +  (let ((ps-file (make-temp-file "notmuch")))\r
134 +    (notmuch-print-with-file filename\r
135 +                            (ps-print-buffer ps-file)\r
136 +                            (async-shell-command (concat "evince " ps-file)))))\r
137 +\r
138 +(defun notmuch-print-muttprint (filename)\r
139 +  (shell-command\r
140 +   (concat "muttprint "\r
141 +          "--file " (shell-quote-argument filename) " "\r
142 +          ;; Show the tags.\r
143 +          "--printed-headers Date_To_From_CC_Newsgroups_*Subject*_/Tags/ ")))\r
144 +\r
145 +(defun notmuch-print-muttprint/evince (filename)\r
146 +  (let ((ps-file (make-temp-file "notmuch")))\r
147 +    (call-process-shell-command\r
148 +     (concat "muttprint "\r
149 +            "--file " (shell-quote-argument filename) " "\r
150 +            ;; Show the tags.\r
151 +            "--printed-headers Date_To_From_CC_Newsgroups_*Subject*_/Tags/ "\r
152 +            "--printer \"TO_FILE:" (shell-quote-argument ps-file) "\""))\r
153 +    (async-shell-command (concat "evince " ps-file))))\r
154 +\r
155 +(defun notmuch-print-message (filename)\r
156 +  (funcall notmuch-print-mechanism filename))\r
157 +\r
158 +;;\r
159 +\r
160 +(provide 'notmuch-print)\r
161 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
162 index aa89cfd..002c2fd 100644\r
163 --- a/emacs/notmuch-show.el\r
164 +++ b/emacs/notmuch-show.el\r
165 @@ -32,6 +32,7 @@\r
166  (require 'notmuch-query)\r
167  (require 'notmuch-wash)\r
168  (require 'notmuch-mua)\r
169 +(require 'notmuch-print)\r
170  \r
171  (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
172  (declare-function notmuch-fontify-headers "notmuch" nil)\r
173 @@ -174,6 +175,51 @@ Set `notmuch-show-address-simplication' to:\r
174        mm-handle (> (notmuch-count-attachments mm-handle) 1))))\r
175    (message "Done"))\r
176  \r
177 +(defun notmuch-show-with-message-as-text (fn)\r
178 +  "Apply function `fn' to a text representation of the current\r
179 +message."\r
180 +\r
181 +  ;; Remake the header to ensure that all information is available.\r
182 +  (let* ((to (notmuch-show-get-to))\r
183 +        (cc (notmuch-show-get-cc))\r
184 +        (from (notmuch-show-get-from))\r
185 +        (subject (notmuch-show-get-subject))\r
186 +        (date (notmuch-show-get-date))\r
187 +        (tags (notmuch-show-get-tags))\r
188 +        (depth (notmuch-show-get-depth))\r
189 +\r
190 +        (header (concat\r
191 +                 "Subject: " subject "\n"\r
192 +                 "To: " to "\n"\r
193 +                 (if (not (string= cc ""))\r
194 +                     (concat "Cc: " cc "\n")\r
195 +                   "")\r
196 +                 "From: " from "\n"\r
197 +                 "Date: " date "\n"\r
198 +                 (if tags\r
199 +                     (concat "Tags: "\r
200 +                             (mapconcat '(lambda (tag) tag) tags ", ") "\n")\r
201 +                   "")))\r
202 +        (all (buffer-substring (notmuch-show-message-top)\r
203 +                               (notmuch-show-message-bottom)))\r
204 +\r
205 +        (file (make-temp-file "notmuch")))\r
206 +    (with-temp-file file\r
207 +      (insert all)\r
208 +      (indent-rigidly (point-min) (point-max) (- depth))\r
209 +      ;; Remove the original header.\r
210 +      (goto-char (point-min))\r
211 +      (re-search-forward "^$" (point-max) nil)\r
212 +      (delete-region (point-min) (point))\r
213 +      (insert header))\r
214 +    (funcall fn file)\r
215 +    (delete-file file)))\r
216 +\r
217 +(defun notmuch-show-print-message ()\r
218 +  "Print the current message."\r
219 +  (interactive)\r
220 +  (notmuch-show-with-message-as-text 'notmuch-print-message))\r
221 +\r
222  (defun notmuch-show-fontify-header ()\r
223    (let ((face (cond\r
224                ((looking-at "[Tt]o:")\r
225 @@ -530,6 +576,8 @@ current buffer, if possible."\r
226      (plist-put msg :message-invis-spec message-invis-spec)\r
227      (overlay-put (make-overlay body-start body-end) 'invisible message-invis-spec)\r
228  \r
229 +    (plist-put msg :depth depth)\r
230 +\r
231      ;; Save the properties for this message. Currently this saves the\r
232      ;; entire message (augmented it with other stuff), which seems\r
233      ;; like overkill. We might save a reduced subset (for example, not\r
234 @@ -831,6 +879,9 @@ All currently available key bindings:\r
235  (defun notmuch-show-get-to ()\r
236    (notmuch-show-get-header :To))\r
237  \r
238 +(defun notmuch-show-get-depth ()\r
239 +  (notmuch-show-get-prop :depth))\r
240 +\r
241  (defun notmuch-show-set-tags (tags)\r
242    "Set the tags of the current message."\r
243    (notmuch-show-set-prop :tags tags)\r
244 -- \r
245 1.7.2.3\r
246 \r