Mercurial > emacs
comparison lisp/mh-e/mh-print.el @ 90261:7beb78bc1f8e
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-97
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 616-696)
- Add lisp/mh-e/.arch-inventory
- Update from CVS
- Merge from gnus--rel--5.10
- Update from CVS: lisp/smerge-mode.el: Add 'tools' to file keywords.
- lisp/gnus/ChangeLog: Remove duplicate entry
* gnus--rel--5.10 (patch 147-181)
- Update from CVS
- Merge from emacs--cvs-trunk--0
- Update from CVS: lisp/mml.el (mml-preview): Doc fix.
- Update from CVS: texi/message.texi: Fix default values.
- Update from CVS: texi/gnus.texi (RSS): Addition.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 16 Jan 2006 08:37:27 +0000 |
parents | 5e2d3828e89f 5012e59a73c7 |
children | 7432ca837c8d |
comparison
equal
deleted
inserted
replaced
90260:0ca0d9181b5e | 90261:7beb78bc1f8e |
---|---|
1 ;;; mh-print.el --- MH-E printing support | 1 ;;; mh-print.el --- MH-E printing support |
2 | 2 |
3 ;; Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. | 3 ;; Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Jeffrey C Honig <jch@honig.net> | 5 ;; Author: Jeffrey C Honig <jch@honig.net> |
6 ;; Maintainer: Bill Wohler <wohler@newt.com> | 6 ;; Maintainer: Bill Wohler <wohler@newt.com> |
7 ;; Keywords: mail | 7 ;; Keywords: mail |
8 ;; See: mh-e.el | 8 ;; See: mh-e.el |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | 25 ;; Boston, MA 02110-1301, USA. |
26 | 26 |
27 ;;; Commentary: | 27 ;;; Commentary: |
28 ;; Pp Print to lpr | Default inline settings | |
29 ;; Pf Print to file | Generate a postscript file | |
30 ;; Ps Print show buffer | Fails if no show buffer | |
31 ;; | |
32 ;; PA Toggle inline/attachments | |
33 ;; PC Toggle color | |
34 ;; PF Toggle faces | |
35 | 28 |
36 ;;; Change Log: | 29 ;;; Change Log: |
37 | 30 |
38 ;;; Code: | 31 ;;; Code: |
39 | 32 |
33 ;;(message "> mh-print") | |
40 (eval-when-compile (require 'mh-acros)) | 34 (eval-when-compile (require 'mh-acros)) |
41 (mh-require-cl) | 35 (mh-require-cl) |
42 (require 'ps-print) | 36 (require 'ps-print) |
37 (require 'mh-buffers) | |
43 (require 'mh-utils) | 38 (require 'mh-utils) |
44 (require 'mh-funcs) | 39 (require 'mh-funcs) |
45 (eval-when-compile (require 'mh-seq)) | 40 (eval-when-compile (require 'mh-seq)) |
46 | 41 ;;(message "< mh-print") |
47 (defvar mh-ps-print-mime nil | |
48 "Control printing of MIME parts. | |
49 The three possible states are: | |
50 1. nil to not print inline parts | |
51 2. t to print inline parts | |
52 3. non-zero to print inline parts and attachments") | |
53 | 42 |
54 (defvar mh-ps-print-color-option ps-print-color-p | 43 (defvar mh-ps-print-color-option ps-print-color-p |
55 "MH-E's version of `\\[ps-print-color-p]'.") | 44 "Specify how buffer's text color is printed. |
45 | |
46 Valid values are: | |
47 | |
48 nil - Do not print colors. | |
49 t - Print colors. | |
50 black-white - Print colors on black/white printer. | |
51 See also `ps-black-white-faces'. | |
52 | |
53 Any other value is treated as t. This variable is initialized | |
54 from `ps-print-color-p'.") | |
56 | 55 |
57 (defvar mh-ps-print-func 'ps-spool-buffer-with-faces | 56 (defvar mh-ps-print-func 'ps-spool-buffer-with-faces |
58 "Function to use to spool a buffer. | 57 "Function to use to spool a buffer. |
58 | |
59 Sensible choices are the functions `ps-spool-buffer' and | 59 Sensible choices are the functions `ps-spool-buffer' and |
60 `ps-spool-buffer-with-faces'.") | 60 `ps-spool-buffer-with-faces'.") |
61 | 61 |
62 ;; XXX - If buffer is already being displayed, use that buffer | |
63 ;; XXX - What about showing MIME content? | |
64 ;; XXX - Default print buffer is bogus | |
65 (defun mh-ps-spool-buffer (buffer) | 62 (defun mh-ps-spool-buffer (buffer) |
66 "Send BUFFER to printer queue." | 63 "Spool BUFFER." |
67 (message "mh-ps-spool-buffer %s" buffer) | |
68 (save-excursion | 64 (save-excursion |
69 (set-buffer buffer) | 65 (set-buffer buffer) |
70 (let ((ps-print-color-p mh-ps-print-color-option) | 66 (let ((ps-print-color-p mh-ps-print-color-option) |
71 (ps-left-header | 67 (ps-left-header |
72 (list | 68 (list |
73 (concat "(" | 69 (concat "(" (mh-get-header-field "Subject:") ")") |
74 (mh-get-header-field "Subject:") ")") | 70 (concat "(" (mh-get-header-field "From:") ")"))) |
75 (concat "(" | 71 (ps-right-header |
76 (mh-get-header-field "From:") ")"))) | 72 (list |
77 (ps-right-header | 73 "/pagenumberstring load" |
78 (list | 74 (concat "(" (mh-get-header-field "Date:") ")")))) |
79 "/pagenumberstring load" | 75 (funcall mh-ps-print-func)))) |
80 (concat "(" | 76 |
81 (mh-get-header-field "Date:") ")")))) | 77 (defun mh-ps-spool-msg (msg) |
82 (funcall mh-ps-print-func)))) | 78 "Spool MSG." |
83 | 79 (let* ((folder mh-current-folder) |
84 (defun mh-ps-spool-a-msg (msg buffer) | 80 (buffer (mh-in-show-buffer (mh-show-buffer) |
85 "Print MSG. | 81 (if (not (equal (mh-msg-filename msg folder) |
86 First the message is decoded in BUFFER before the results are sent to the | 82 buffer-file-name)) |
87 printer." | 83 (get-buffer-create mh-temp-buffer))))) |
88 (message "mh-ps-spool-a-msg msg %s buffer %s" | |
89 msg buffer) | |
90 (let ((mh-show-buffer mh-show-buffer) | |
91 (folder mh-current-folder) | |
92 ;; The following is commented out because | |
93 ;; `clean-message-header-flag' isn't used anywhere. I | |
94 ;; commented rather than deleted in case somebody had some | |
95 ;; future plans for it. --SY. | |
96 ;(clean-message-header-flag mh-clean-message-header-flag) | |
97 ) | |
98 (unwind-protect | 84 (unwind-protect |
99 (progn | 85 (save-excursion |
100 (setq mh-show-buffer buffer) | 86 (if buffer |
101 (save-excursion | 87 (let ((mh-show-buffer buffer)) |
102 ;; | 88 (mh-display-msg msg folder))) |
103 ;; XXX - Use setting of mh-ps-print-mime | 89 (mh-ps-spool-buffer (if buffer buffer mh-show-buffer))) |
104 ;; | 90 (if buffer |
105 (mh-display-msg msg folder) | 91 (kill-buffer buffer))))) |
106 (mh-ps-spool-buffer mh-show-buffer) | 92 |
107 (kill-buffer mh-show-buffer)))))) | 93 (defun mh-ps-print-range (range file) |
94 "Print RANGE to FILE. | |
95 | |
96 This is the function that actually does the work. | |
97 If FILE is nil, then the messages are spooled to the printer." | |
98 (mh-iterate-on-range msg range | |
99 (unwind-protect | |
100 (mh-ps-spool-msg msg)) | |
101 (mh-notate msg mh-note-printed mh-cmd-note)) | |
102 (ps-despool file)) | |
103 | |
104 (defun mh-ps-print-preprint (prefix-arg) | |
105 "Provide a better default file name for `ps-print-preprint'. | |
106 Pass along the PREFIX-ARG to it." | |
107 (let ((buffer-file-name (format "mh-%s" (substring (buffer-name) 1)))) | |
108 (ps-print-preprint prefix-arg))) | |
108 | 109 |
109 ;;;###mh-autoload | 110 ;;;###mh-autoload |
110 (defun mh-ps-print-msg (range) | 111 (defun mh-ps-print-msg (range) |
111 "Print the messages in RANGE. | 112 "Print RANGE\\<mh-folder-mode-map>. |
112 | 113 |
113 Check the documentation of `mh-interactive-range' to see how RANGE is read in | 114 Check the documentation of `mh-interactive-range' to see how RANGE is |
114 interactive use." | 115 read in interactive use. |
116 | |
117 This command will print inline text attachments but will not decrypt | |
118 messages. However, when a message is displayed in an MH-Show buffer, | |
119 then that buffer is used verbatim for printing with the caveat that | |
120 only text attachments, if opened inline, are printed. Therefore, | |
121 encrypted messages can be printed by showing and decrypting them | |
122 first. | |
123 | |
124 MH-E uses the \"ps-print\" package to do the printing, so you can | |
125 customize the printing further by going to the `ps-print' | |
126 customization group. This command does not use the options | |
127 `mh-lpr-command-format' or `mh-print-background-flag'. See also the | |
128 commands \\[mh-ps-print-toggle-color] and | |
129 \\[mh-ps-print-toggle-faces]." | |
115 (interactive (list (mh-interactive-range "Print"))) | 130 (interactive (list (mh-interactive-range "Print"))) |
116 (message "mh-ps-print-msg range %s keys %s" | 131 (mh-ps-print-range range nil)) |
117 range (this-command-keys)) | 132 |
118 (mh-iterate-on-range msg range | 133 ;;;###mh-autoload |
119 (let ((buffer (get-buffer-create mh-temp-buffer))) | 134 (defun mh-ps-print-msg-file (range file) |
120 (unwind-protect | 135 "Print RANGE to FILE\\<mh-folder-mode-map>. |
121 (mh-ps-spool-a-msg msg buffer) | 136 |
122 (kill-buffer buffer))) | 137 Check the documentation of `mh-interactive-range' to see how RANGE is |
123 (mh-notate nil mh-note-printed mh-cmd-note)) | 138 read in interactive use. |
124 (ps-despool nil)) | 139 |
125 | 140 This command will print inline text attachments but will not decrypt |
126 (defun mh-ps-print-preprint (prefix-arg) | 141 messages. However, when a message is displayed in an MH-Show buffer, |
127 "Replacement for `ps-print-preprint'. | 142 then that buffer is used verbatim for printing with the caveat that |
128 The original function does not handle the fact that MH folders are directories | 143 only text attachments, if opened inline, are printed. Therefore, |
129 nicely, when generating the default file name. This function works around | 144 encrypted messages can be printed by showing and decrypting them |
130 that. The function is passed the interactive PREFIX-ARG." | 145 first. |
131 (let ((buffer-file-name (format "/tmp/%s" (substring (buffer-name) 1)))) | 146 |
132 (ps-print-preprint prefix-arg))) | 147 MH-E uses the \"ps-print\" package to do the printing, so you can |
133 | 148 customize the printing further by going to the `ps-print' |
134 ;;;###mh-autoload | 149 customization group. This command does not use the options |
135 (defun mh-ps-print-msg-file (file range) | 150 `mh-lpr-command-format' or `mh-print-background-flag'. See also the |
136 "Print to FILE the messages in RANGE. | 151 commands \\[mh-ps-print-toggle-color] and |
137 | 152 \\[mh-ps-print-toggle-faces]." |
138 Check the documentation of `mh-interactive-range' to see how RANGE is read in | 153 (interactive (list (mh-interactive-range "Print") (mh-ps-print-preprint 1))) |
139 interactive use." | 154 (mh-ps-print-range range file)) |
140 (interactive (list | |
141 (mh-ps-print-preprint 1) | |
142 (mh-interactive-range "Print"))) | |
143 (mh-iterate-on-range msg range | |
144 (let ((buffer (get-buffer-create mh-temp-buffer))) | |
145 (unwind-protect | |
146 (mh-ps-spool-a-msg msg buffer) | |
147 (kill-buffer buffer))) | |
148 (mh-notate nil mh-note-printed mh-cmd-note)) | |
149 (ps-despool file)) | |
150 | |
151 ;;;###mh-autoload | |
152 (defun mh-ps-print-msg-show (file) | |
153 "Print current show buffer to FILE." | |
154 (interactive (list (mh-ps-print-preprint current-prefix-arg))) | |
155 (message "mh-ps-print-msg-show file %s keys %s mh-show-buffer %s" | |
156 file (this-command-keys) mh-show-buffer) | |
157 (let ((msg (mh-get-msg-num t)) | |
158 (folder mh-current-folder) | |
159 (show-buffer mh-show-buffer) | |
160 (show-window (get-buffer-window mh-show-buffer))) | |
161 (if (and show-buffer show-window) | |
162 (mh-in-show-buffer (show-buffer) | |
163 (if (equal (mh-msg-filename msg folder) buffer-file-name) | |
164 (progn | |
165 (mh-ps-spool-buffer show-buffer) | |
166 (ps-despool file)) | |
167 (message "Current message is not being shown(1)."))) | |
168 (message "Current message is not being shown(2).")))) | |
169 | 155 |
170 ;;;###mh-autoload | 156 ;;;###mh-autoload |
171 (defun mh-ps-print-toggle-faces () | 157 (defun mh-ps-print-toggle-faces () |
172 "Toggle whether printing is done with faces or not." | 158 "Toggle whether printing is done with faces or not. |
159 | |
160 When faces are enabled, the printed message will look very | |
161 similar to the message in the MH-Show buffer." | |
173 (interactive) | 162 (interactive) |
174 (if (eq mh-ps-print-func 'ps-spool-buffer-with-faces) | 163 (if (eq mh-ps-print-func 'ps-spool-buffer-with-faces) |
175 (progn | 164 (progn |
176 (setq mh-ps-print-func 'ps-spool-buffer) | 165 (setq mh-ps-print-func 'ps-spool-buffer) |
177 (message "Printing without faces")) | 166 (message "Printing without faces")) |
178 (setq mh-ps-print-func 'ps-spool-buffer-with-faces) | 167 (setq mh-ps-print-func 'ps-spool-buffer-with-faces) |
179 (message "Printing with faces"))) | 168 (message "Printing with faces"))) |
180 | 169 |
181 ;;;###mh-autoload | 170 ;;;###mh-autoload |
182 (defun mh-ps-print-toggle-color () | 171 (defun mh-ps-print-toggle-color () |
183 "Toggle whether color is used in printing messages." | 172 "Toggle whether color is used in printing messages. |
173 | |
174 Colors are emulated on black-and-white printers with shades of | |
175 gray. This might produce illegible output, even if your screen | |
176 colors only use shades of gray. If this is the case, try using | |
177 this command to toggle between color, no color, and a black and | |
178 white representation of the colors and see which works best. You | |
179 change this setting permanently by customizing the option | |
180 `ps-print-color-p'." | |
184 (interactive) | 181 (interactive) |
185 (if (eq mh-ps-print-color-option nil) | 182 (if (eq mh-ps-print-color-option nil) |
186 (progn | 183 (progn |
187 (setq mh-ps-print-color-option 'black-white) | 184 (setq mh-ps-print-color-option 'black-white) |
188 (message "Colors will be printed as black & white.")) | 185 (message "Colors will be printed as black & white")) |
189 (if (eq mh-ps-print-color-option 'black-white) | 186 (if (eq mh-ps-print-color-option 'black-white) |
190 (progn | 187 (progn |
191 (setq mh-ps-print-color-option t) | 188 (setq mh-ps-print-color-option t) |
192 (message "Colors will be printed.")) | 189 (message "Colors will be printed")) |
193 (setq mh-ps-print-color-option nil) | 190 (setq mh-ps-print-color-option nil) |
194 (message "Colors will not be printed.")))) | 191 (message "Colors will not be printed")))) |
195 | 192 |
196 ;;; XXX: Check option 3. Documentation doesn't sound right. | 193 ;; Old non-PS based printing |
197 ;;;###mh-autoload | |
198 (defun mh-ps-print-toggle-mime () | |
199 "Cycle through available choices on how MIME parts should be printed. | |
200 The available settings are: | |
201 1. Print only inline MIME parts. | |
202 2. Print all MIME parts. | |
203 3. Print no MIME parts." | |
204 (interactive) | |
205 (if (eq mh-ps-print-mime nil) | |
206 (progn | |
207 (setq mh-ps-print-mime t) | |
208 (message "Inline parts will be printed, attachments will not be printed.")) | |
209 (if (eq mh-ps-print-mime t) | |
210 (progn | |
211 (setq mh-ps-print-mime 1) | |
212 (message "Both Inline parts and attachments will be printed.")) | |
213 (setq mh-ps-print-mime nil) | |
214 (message "Neither inline parts nor attachments will be printed.")))) | |
215 | |
216 ;;; Old non-PS based printing | |
217 ;;;###mh-autoload | 194 ;;;###mh-autoload |
218 (defun mh-print-msg (range) | 195 (defun mh-print-msg (range) |
219 "Print RANGE on printer. | 196 "Print RANGE the old fashioned way\\<mh-folder-mode-map>. |
220 | 197 |
221 Check the documentation of `mh-interactive-range' to see how RANGE is read in | 198 The message is formatted with \"mhl\" (see option |
222 interactive use. | 199 `mh-mhl-format-file') and printed with the \"lpr\" command (see |
223 | 200 option `mh-lpr-command-format'). |
224 The variable `mh-lpr-command-format' is used to generate the print command. | 201 |
225 The messages are formatted by mhl. See the variable `mhl-formfile'." | 202 Check the documentation of `mh-interactive-range' to see how |
203 RANGE is read in interactive use. | |
204 | |
205 Consider using \\[mh-ps-print-msg] instead." | |
226 (interactive (list (mh-interactive-range "Print"))) | 206 (interactive (list (mh-interactive-range "Print"))) |
227 (message "Printing...") | 207 (message "Printing...") |
228 (let (msgs) | 208 (let (msgs) |
229 ;; Gather message numbers and add them to "printed" sequence. | 209 ;; Gather message numbers and add them to "printed" sequence. |
230 (mh-iterate-on-range msg range | 210 (mh-iterate-on-range msg range |
252 (call-process shell-file-name nil nil nil "-c" scan-command)))) | 232 (call-process shell-file-name nil nil nil "-c" scan-command)))) |
253 ;; Print the messages | 233 ;; Print the messages |
254 (dolist (msg msgs) | 234 (dolist (msg msgs) |
255 (let* ((mhl-command (format "%s %s %s" | 235 (let* ((mhl-command (format "%s %s %s" |
256 (expand-file-name "mhl" mh-lib-progs) | 236 (expand-file-name "mhl" mh-lib-progs) |
257 (if mhl-formfile | 237 (if mh-mhl-format-file |
258 (format " -form %s" mhl-formfile) | 238 (format " -form %s" mh-mhl-format-file) |
259 "") | 239 "") |
260 (mh-msg-filename msg))) | 240 (mh-msg-filename msg))) |
261 (lpr-command | 241 (lpr-command |
262 (format mh-lpr-command-format | 242 (format mh-lpr-command-format |
263 (format "%s/%s" mh-current-folder msg))) | 243 (format "%s/%s" mh-current-folder msg))) |
268 (call-process shell-file-name nil nil nil "-c" print-command))))) | 248 (call-process shell-file-name nil nil nil "-c" print-command))))) |
269 (message "Printing...done")) | 249 (message "Printing...done")) |
270 | 250 |
271 (provide 'mh-print) | 251 (provide 'mh-print) |
272 | 252 |
273 ;;; Local Variables: | 253 ;; Local Variables: |
274 ;;; indent-tabs-mode: nil | 254 ;; indent-tabs-mode: nil |
275 ;;; sentence-end-double-space: nil | 255 ;; sentence-end-double-space: nil |
276 ;;; End: | 256 ;; End: |
277 | 257 |
278 ;; arch-tag: 8d84d50b-2a49-4d0d-b51e-ba9c9b6fc679 | 258 ;; arch-tag: 8d84d50b-2a49-4d0d-b51e-ba9c9b6fc679 |
279 ;;; mh-print.el ends here | 259 ;;; mh-print.el ends here |