]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-print.el
fd86288acc62761442a297ef3b2cf6aa37f884ac
[notmuch] / emacs / notmuch-print.el
1 ;; notmuch-print.el --- printing messages from notmuch.
2 ;;
3 ;; Copyright © David Edmondson
4 ;;
5 ;; This file is part of Notmuch.
6 ;;
7 ;; Notmuch is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11 ;;
12 ;; Notmuch is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.
19 ;;
20 ;; Authors: David Edmondson <dme@dme.org>
21
22 (declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props))
23
24 (defcustom notmuch-print-mechanism 'notmuch-print-lpr
25   "How should printing be done?"
26   :group 'notmuch
27   :type '(choice
28           (function :tag "Use lpr" notmuch-print-lpr)
29           (function :tag "Use ps-print" notmuch-print-ps-print)
30           (function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)
31           (function :tag "Use muttprint" notmuch-print-muttprint)
32           (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)
33           (function :tag "Using a custom function")))
34
35 ;; Utility functions:
36
37 (defun notmuch-print-run-evince (file)
38   "View FILE using 'evince'."
39   (start-process "evince" nil "evince" file))
40
41 (defun notmuch-print-run-muttprint (&optional output)
42   "Pass the contents of the current buffer to 'muttprint'.
43
44 Optional OUTPUT allows passing a list of flags to muttprint."
45   (apply #'call-process-region (point-min) (point-max)
46          ;; Reads from stdin.
47          "muttprint"
48          nil nil nil
49          ;; Show the tags.
50          "--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"
51          output))
52
53 ;; User-visible functions:
54
55 (defun notmuch-print-lpr (msg)
56   "Print a message buffer using lpr."
57   (lpr-buffer))
58
59 (defun notmuch-print-ps-print (msg)
60   "Print a message buffer using the ps-print package."
61   (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))
62     (rename-buffer subject t)
63     (ps-print-buffer)))
64
65 (defun notmuch-print-ps-print/evince (msg)
66   "Preview a message buffer using ps-print and evince."
67   (let ((ps-file (make-temp-file "notmuch"))
68         (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))
69     (rename-buffer subject t)
70     (ps-print-buffer ps-file)
71     (notmuch-print-run-evince ps-file)))
72
73 (defun notmuch-print-muttprint (msg)
74   "Print a message using muttprint."
75   (notmuch-print-run-muttprint))
76
77 (defun notmuch-print-muttprint/evince (msg)
78   "Preview a message buffer using muttprint and evince."
79   (let ((ps-file (make-temp-file "notmuch")))
80     (notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))
81     (notmuch-print-run-evince ps-file)))
82
83 (defun notmuch-print-message (msg)
84   "Print a message using the user-selected mechanism."
85   (funcall notmuch-print-mechanism msg))
86
87 (provide 'notmuch-print)