1 ;;; mh-print.el --- MH-E printing support
3 ;; Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
5 ;; Author: Jeffrey C Honig <jch@honig.net>
6 ;; Maintainer: Bill Wohler <wohler@newt.com>
10 ;; This file is part of GNU Emacs.
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)
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.
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.
33 (eval-when-compile (require 'mh-acros
))
38 (eval-when-compile (require 'mh-seq
))
40 (defvar mh-ps-print-color-option ps-print-color-p
41 "Specify how buffer's text color is printed.
45 nil - Do not print colors.
47 black-white - Print colors on black/white printer.
48 See also `ps-black-white-faces'.
50 Any other value is treated as t. This variable is initialized
51 from `ps-print-color-p'.")
53 (defvar mh-ps-print-func
'ps-spool-buffer-with-faces
54 "Function to use to spool a buffer.
56 Sensible choices are the functions `ps-spool-buffer' and
57 `ps-spool-buffer-with-faces'.")
59 (defun mh-ps-spool-buffer (buffer)
63 (let ((ps-print-color-p mh-ps-print-color-option
)
66 (concat "(" (mh-get-header-field "Subject:") ")")
67 (concat "(" (mh-get-header-field "From:") ")")))
70 "/pagenumberstring load"
71 (concat "(" (mh-get-header-field "Date:") ")"))))
72 (funcall mh-ps-print-func
))))
74 (defun mh-ps-spool-msg (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
)
80 (get-buffer-create mh-temp-buffer
)))))
84 (let ((mh-show-buffer buffer
))
85 (mh-display-msg msg folder
)))
86 (mh-ps-spool-buffer (if buffer buffer mh-show-buffer
)))
88 (kill-buffer buffer
)))))
90 (defun mh-ps-print-range (range file
)
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
97 (mh-ps-spool-msg msg
))
98 (mh-notate msg mh-note-printed mh-cmd-note
))
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
)))
108 (defun mh-ps-print-msg (range)
109 "Print RANGE\\<mh-folder-mode-map>.
111 Check the documentation of `mh-interactive-range' to see how RANGE is
112 read in interactive use.
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
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
))
131 (defun mh-ps-print-msg-file (range file
)
132 "Print RANGE to FILE\\<mh-folder-mode-map>.
134 Check the documentation of `mh-interactive-range' to see how RANGE is
135 read in interactive use.
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
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
))
154 (defun mh-ps-print-toggle-faces ()
155 "Toggle whether printing is done with faces or not.
157 When faces are enabled, the printed message will look very
158 similar to the message in the MH-Show buffer."
160 (if (eq mh-ps-print-func
'ps-spool-buffer-with-faces
)
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")))
168 (defun mh-ps-print-toggle-color ()
169 "Toggle whether color is used in printing messages.
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
179 (if (eq mh-ps-print-color-option nil
)
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
)
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"))))
190 ;; Old non-PS based printing
192 (defun mh-print-msg (range)
193 "Print RANGE the old fashioned way\\<mh-folder-mode-map>.
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').
199 Check the documentation of `mh-interactive-range' to see how
200 RANGE is read in interactive use.
202 Consider using \\[mh-ps-print-msg] instead."
203 (interactive (list (mh-interactive-range "Print")))
204 (message "Printing...")
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
)
211 (setq msgs
(nreverse msgs
))
212 ;; Print scan listing if we have more than one message.
213 (if (> (length msgs
) 1)
215 (mapconcat 'identity
(mh-list-to-string
216 (mh-coalesce-msg-list msgs
)) " "))
218 (format mh-lpr-command-format
220 (format "Folder: %s, Messages: %s"
221 mh-current-folder msgs-string
))
223 (format "Folder: %s, Sequence: %s"
224 mh-current-folder range
)))))
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
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
)
237 (mh-msg-filename msg
)))
239 (format mh-lpr-command-format
240 (format "%s/%s" mh-current-folder msg
)))
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"))
251 ;; indent-tabs-mode: nil
252 ;; sentence-end-double-space: nil
255 ;; arch-tag: 8d84d50b-2a49-4d0d-b51e-ba9c9b6fc679
256 ;;; mh-print.el ends here