]> code.delx.au - gnu-emacs/blob - lisp/mh-e/mh-print.el
(rcirc-ignore-list): New option.
[gnu-emacs] / lisp / mh-e / mh-print.el
1 ;;; mh-print.el --- MH-E printing support
2
3 ;; Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 ;; Author: Jeffrey C Honig <jch@honig.net>
6 ;; Maintainer: Bill Wohler <wohler@newt.com>
7 ;; Keywords: mail
8 ;; See: mh-e.el
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;;; Change Log:
30
31 ;;; Code:
32
33 (eval-when-compile (require 'mh-acros))
34 (mh-require-cl)
35 (require 'ps-print)
36 (require 'mh-utils)
37 (require 'mh-funcs)
38 (eval-when-compile (require 'mh-seq))
39
40 (defvar mh-ps-print-color-option ps-print-color-p
41 "Specify how buffer's text color is printed.
42
43 Valid values are:
44
45 nil - Do not print colors.
46 t - Print colors.
47 black-white - Print colors on black/white printer.
48 See also `ps-black-white-faces'.
49
50 Any other value is treated as t. This variable is initialized
51 from `ps-print-color-p'.")
52
53 (defvar mh-ps-print-func 'ps-spool-buffer-with-faces
54 "Function to use to spool a buffer.
55
56 Sensible choices are the functions `ps-spool-buffer' and
57 `ps-spool-buffer-with-faces'.")
58
59 (defun mh-ps-spool-buffer (buffer)
60 "Spool BUFFER."
61 (save-excursion
62 (set-buffer buffer)
63 (let ((ps-print-color-p mh-ps-print-color-option)
64 (ps-left-header
65 (list
66 (concat "(" (mh-get-header-field "Subject:") ")")
67 (concat "(" (mh-get-header-field "From:") ")")))
68 (ps-right-header
69 (list
70 "/pagenumberstring load"
71 (concat "(" (mh-get-header-field "Date:") ")"))))
72 (funcall mh-ps-print-func))))
73
74 (defun mh-ps-spool-msg (msg)
75 "Spool MSG."
76 (let* ((folder mh-current-folder)
77 (buffer (mh-in-show-buffer (mh-show-buffer)
78 (if (not (equal (mh-msg-filename msg folder)
79 buffer-file-name))
80 (get-buffer-create mh-temp-buffer)))))
81 (unwind-protect
82 (save-excursion
83 (if buffer
84 (let ((mh-show-buffer buffer))
85 (mh-display-msg msg folder)))
86 (mh-ps-spool-buffer (if buffer buffer mh-show-buffer)))
87 (if buffer
88 (kill-buffer buffer)))))
89
90 (defun mh-ps-print-range (range file)
91 "Print RANGE to FILE.
92
93 This is the function that actually does the work.
94 If FILE is nil, then the messages are spooled to the printer."
95 (mh-iterate-on-range msg range
96 (unwind-protect
97 (mh-ps-spool-msg msg))
98 (mh-notate msg mh-note-printed mh-cmd-note))
99 (ps-despool file))
100
101 (defun mh-ps-print-preprint (prefix-arg)
102 "Provide a better default file name for `ps-print-preprint'.
103 Pass along the PREFIX-ARG to it."
104 (let ((buffer-file-name (format "mh-%s" (substring (buffer-name) 1))))
105 (ps-print-preprint prefix-arg)))
106
107 ;;;###mh-autoload
108 (defun mh-ps-print-msg (range)
109 "Print RANGE\\<mh-folder-mode-map>.
110
111 Check the documentation of `mh-interactive-range' to see how RANGE is
112 read in interactive use.
113
114 This command will print inline text attachments but will not decrypt
115 messages. However, when a message is displayed in an MH-Show buffer,
116 then that buffer is used verbatim for printing with the caveat that
117 only text attachments, if opened inline, are printed. Therefore,
118 encrypted messages can be printed by showing and decrypting them
119 first.
120
121 MH-E uses the \"ps-print\" package to do the printing, so you can
122 customize the printing further by going to the `ps-print'
123 customization group. This command does not use the options
124 `mh-lpr-command-format' or `mh-print-background-flag'. See also the
125 commands \\[mh-ps-print-toggle-color] and
126 \\[mh-ps-print-toggle-faces]."
127 (interactive (list (mh-interactive-range "Print")))
128 (mh-ps-print-range range nil))
129
130 ;;;###mh-autoload
131 (defun mh-ps-print-msg-file (range file)
132 "Print RANGE to FILE\\<mh-folder-mode-map>.
133
134 Check the documentation of `mh-interactive-range' to see how RANGE is
135 read in interactive use.
136
137 This command will print inline text attachments but will not decrypt
138 messages. However, when a message is displayed in an MH-Show buffer,
139 then that buffer is used verbatim for printing with the caveat that
140 only text attachments, if opened inline, are printed. Therefore,
141 encrypted messages can be printed by showing and decrypting them
142 first.
143
144 MH-E uses the \"ps-print\" package to do the printing, so you can
145 customize the printing further by going to the `ps-print'
146 customization group. This command does not use the options
147 `mh-lpr-command-format' or `mh-print-background-flag'. See also the
148 commands \\[mh-ps-print-toggle-color] and
149 \\[mh-ps-print-toggle-faces]."
150 (interactive (list (mh-interactive-range "Print") (mh-ps-print-preprint 1)))
151 (mh-ps-print-range range file))
152
153 ;;;###mh-autoload
154 (defun mh-ps-print-toggle-faces ()
155 "Toggle whether printing is done with faces or not.
156
157 When faces are enabled, the printed message will look very
158 similar to the message in the MH-Show buffer."
159 (interactive)
160 (if (eq mh-ps-print-func 'ps-spool-buffer-with-faces)
161 (progn
162 (setq mh-ps-print-func 'ps-spool-buffer)
163 (message "Printing without faces"))
164 (setq mh-ps-print-func 'ps-spool-buffer-with-faces)
165 (message "Printing with faces")))
166
167 ;;;###mh-autoload
168 (defun mh-ps-print-toggle-color ()
169 "Toggle whether color is used in printing messages.
170
171 Colors are emulated on black-and-white printers with shades of
172 gray. This might produce illegible output, even if your screen
173 colors only use shades of gray. If this is the case, try using
174 this command to toggle between color, no color, and a black and
175 white representation of the colors and see which works best. You
176 change this setting permanently by customizing the option
177 `ps-print-color-p'."
178 (interactive)
179 (if (eq mh-ps-print-color-option nil)
180 (progn
181 (setq mh-ps-print-color-option 'black-white)
182 (message "Colors will be printed as black & white"))
183 (if (eq mh-ps-print-color-option 'black-white)
184 (progn
185 (setq mh-ps-print-color-option t)
186 (message "Colors will be printed"))
187 (setq mh-ps-print-color-option nil)
188 (message "Colors will not be printed"))))
189
190 ;; Old non-PS based printing
191 ;;;###mh-autoload
192 (defun mh-print-msg (range)
193 "Print RANGE the old fashioned way\\<mh-folder-mode-map>.
194
195 The message is formatted with \"mhl\" (see option
196 `mh-mhl-format-file') and printed with the \"lpr\" command (see
197 option `mh-lpr-command-format').
198
199 Check the documentation of `mh-interactive-range' to see how
200 RANGE is read in interactive use.
201
202 Consider using \\[mh-ps-print-msg] instead."
203 (interactive (list (mh-interactive-range "Print")))
204 (message "Printing...")
205 (let (msgs)
206 ;; Gather message numbers and add them to "printed" sequence.
207 (mh-iterate-on-range msg range
208 (mh-add-msgs-to-seq msg 'printed t)
209 (mh-notate nil mh-note-printed mh-cmd-note)
210 (push msg msgs))
211 (setq msgs (nreverse msgs))
212 ;; Print scan listing if we have more than one message.
213 (if (> (length msgs) 1)
214 (let* ((msgs-string
215 (mapconcat 'identity (mh-list-to-string
216 (mh-coalesce-msg-list msgs)) " "))
217 (lpr-command
218 (format mh-lpr-command-format
219 (cond ((listp range)
220 (format "Folder: %s, Messages: %s"
221 mh-current-folder msgs-string))
222 ((symbolp range)
223 (format "Folder: %s, Sequence: %s"
224 mh-current-folder range)))))
225 (scan-command
226 (format "scan %s | %s" msgs-string lpr-command)))
227 (if mh-print-background-flag
228 (mh-exec-cmd-daemon shell-file-name nil "-c" scan-command)
229 (call-process shell-file-name nil nil nil "-c" scan-command))))
230 ;; Print the messages
231 (dolist (msg msgs)
232 (let* ((mhl-command (format "%s %s %s"
233 (expand-file-name "mhl" mh-lib-progs)
234 (if mh-mhl-format-file
235 (format " -form %s" mh-mhl-format-file)
236 "")
237 (mh-msg-filename msg)))
238 (lpr-command
239 (format mh-lpr-command-format
240 (format "%s/%s" mh-current-folder msg)))
241 (print-command
242 (format "%s | %s" mhl-command lpr-command)))
243 (if mh-print-background-flag
244 (mh-exec-cmd-daemon shell-file-name nil "-c" print-command)
245 (call-process shell-file-name nil nil nil "-c" print-command)))))
246 (message "Printing...done"))
247
248 (provide 'mh-print)
249
250 ;; Local Variables:
251 ;; indent-tabs-mode: nil
252 ;; sentence-end-double-space: nil
253 ;; End:
254
255 ;; arch-tag: 8d84d50b-2a49-4d0d-b51e-ba9c9b6fc679
256 ;;; mh-print.el ends here