(while-no-input): Don't splice BODY directly into the `or' form.
[emacs.git] / lisp / ps-samp.el
blobffe434b1815586bc2cc83c6bd568ad64100eb097
1 ;;; ps-samp.el --- ps-print sample setup code
3 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
6 ;; Jacques Duthen (was <duthen@cegelec-red.fr>)
7 ;; Vinicius Jose Latorre <viniciusjl@ig.com.br>
8 ;; Kenichi Handa <handa@m17n.org> (multi-byte characters)
9 ;; Maintainer: Kenichi Handa <handa@m17n.org> (multi-byte characters)
10 ;; Vinicius Jose Latorre <viniciusjl@ig.com.br>
11 ;; Keywords: wp, print, PostScript
12 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify it under
17 ;; the terms of the GNU General Public License as published by the Free
18 ;; Software Foundation; either version 3, or (at your option) any later
19 ;; version.
21 ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY
22 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 ;; details.
26 ;; You should have received a copy of the GNU General Public License along with
27 ;; GNU Emacs; see the file COPYING. If not, write to the Free Software
28 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 ;;; Commentary:
32 ;; See ps-print.el for documentation.
34 ;;; Code:
37 (eval-and-compile (require 'ps-print))
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 ;;; Sample Setup Code:
44 ;; This stuff is for anybody that's brave enough to look this far,
45 ;; and able to figure out how to use it. It isn't really part of
46 ;; ps-print, but I'll leave it here in hopes it might be useful:
48 ;; WARNING!!! The following code is *sample* code only.
49 ;; Don't use it unless you understand what it does!
51 ;; The key `f22' should probably be replaced by `print'. --Stef
53 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
54 ;; `ps-left-headers' specially for mail messages.
55 (defun ps-rmail-mode-hook ()
56 (local-set-key [(f22)] 'ps-rmail-print-message-from-summary)
57 (setq ps-header-lines 3
58 ps-left-header
59 ;; The left headers will display the message's subject, its
60 ;; author, and the name of the folder it was in.
61 '(ps-article-subject ps-article-author buffer-name)))
63 ;; See `ps-gnus-print-article-from-summary'. This function does the
64 ;; same thing for rmail.
65 (defun ps-rmail-print-message-from-summary ()
66 (interactive)
67 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
69 ;; Used in `ps-rmail-print-article-from-summary',
70 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
71 (defun ps-print-message-from-summary (summary-buffer summary-default)
72 (let ((ps-buf (or (and (boundp summary-buffer)
73 (symbol-value summary-buffer))
74 summary-default)))
75 (and (get-buffer ps-buf)
76 (save-excursion
77 (set-buffer ps-buf)
78 (ps-spool-buffer-with-faces)))))
80 ;; Look in an article or mail message for the Subject: line. To be
81 ;; placed in `ps-left-headers'.
82 (defun ps-article-subject ()
83 (save-excursion
84 (goto-char (point-min))
85 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
86 (buffer-substring (match-beginning 1) (match-end 1))
87 "Subject ???")))
89 ;; Look in an article or mail message for the From: line. Sorta-kinda
90 ;; understands RFC-822 addresses and can pull the real name out where
91 ;; it's provided. To be placed in `ps-left-headers'.
92 (defun ps-article-author ()
93 (save-excursion
94 (goto-char (point-min))
95 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
96 (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
97 (cond
99 ;; Try first to match addresses that look like
100 ;; thompson@wg2.waii.com (Jim Thompson)
101 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
102 (substring fromstring (match-beginning 1) (match-end 1)))
104 ;; Next try to match addresses that look like
105 ;; Jim Thompson <thompson@wg2.waii.com> or
106 ;; "Jim Thompson" <thompson@wg2.waii.com>
107 ((string-match "\\(\"?\\)\\(.*\\)\\1[ \t]+<.*>" fromstring)
108 (substring fromstring (match-beginning 2) (match-end 2)))
110 ;; Couldn't find a real name -- show the address instead.
111 (t fromstring)))
112 "From ???")))
114 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
115 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
116 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
117 ;; buffer enters that mode, so it would only work for the first time
118 ;; we ran gnus. The second time, this hook wouldn't get set up. The
119 ;; only alternative is `gnus-article-prepare-hook'.
120 (defun ps-gnus-article-prepare-hook ()
121 (setq ps-header-lines 3
122 ps-left-header
123 ;; The left headers will display the article's subject, its
124 ;; author, and the newsgroup it was in.
125 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
127 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
128 ;; `ps-left-headers' specially for mail messages.
129 (defun ps-vm-mode-hook ()
130 (local-set-key [(f22)] 'ps-vm-print-message-from-summary)
131 (setq ps-header-lines 3
132 ps-left-header
133 ;; The left headers will display the message's subject, its
134 ;; author, and the name of the folder it was in.
135 '(ps-article-subject ps-article-author buffer-name)))
137 ;; Every now and then I forget to switch from the *Summary* buffer to
138 ;; the *Article* before hitting prsc, and a nicely formatted list of
139 ;; article subjects shows up at the printer. This function, bound to
140 ;; prsc for the gnus *Summary* buffer means I don't have to switch
141 ;; buffers first.
142 ;; sb: Updated for Gnus 5.
143 (defun ps-gnus-print-article-from-summary ()
144 (interactive)
145 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
147 ;; See `ps-gnus-print-article-from-summary'. This function does the
148 ;; same thing for vm.
149 (defun ps-vm-print-message-from-summary ()
150 (interactive)
151 (ps-print-message-from-summary 'vm-mail-buffer ""))
153 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
154 ;; prsc.
155 (defun ps-gnus-summary-setup ()
156 (local-set-key [(f22)] 'ps-gnus-print-article-from-summary))
158 ;; Look in an article or mail message for the Subject: line. To be
159 ;; placed in `ps-left-headers'.
160 (defun ps-info-file ()
161 (save-excursion
162 (goto-char (point-min))
163 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
164 (buffer-substring (match-beginning 1) (match-end 1))
165 "File ???")))
167 ;; Look in an article or mail message for the Subject: line. To be
168 ;; placed in `ps-left-headers'.
169 (defun ps-info-node ()
170 (save-excursion
171 (goto-char (point-min))
172 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
173 (buffer-substring (match-beginning 1) (match-end 1))
174 "Node ???")))
176 (defun ps-info-mode-hook ()
177 (setq ps-left-header
178 ;; The left headers will display the node name and file name.
179 '(ps-info-node ps-info-file)))
181 ;; WARNING! The following function is a *sample* only, and is *not*
182 ;; meant to be used as a whole unless you understand what the effects
183 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
184 ;; I'd be very surprised if it was useful to *anybody*, without
185 ;; modification.)
187 (defun ps-jts-ps-setup ()
188 (global-set-key [(f22)] 'ps-spool-buffer-with-faces) ;f22 is prsc
189 (global-set-key [(shift f22)] 'ps-spool-region-with-faces)
190 (global-set-key [(control f22)] 'ps-despool)
191 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
192 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
193 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
194 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
195 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
196 (setq ps-spool-duplex t
197 ps-print-color-p nil
198 ps-lpr-command "lpr"
199 ps-lpr-switches '("-Jjct,duplex_long"))
200 'ps-jts-ps-setup)
202 ;; WARNING! The following function is a *sample* only, and is *not*
203 ;; meant to be used as a whole unless it corresponds to your needs.
204 ;; (In fact, this is a copy of Jack's setup for ps-print --
205 ;; I would not be that surprised if it was useful to *anybody*,
206 ;; without modification.)
208 (defun ps-jack-setup ()
209 (setq ps-print-color-p nil
210 ps-lpr-command "lpr"
211 ps-lpr-switches nil
213 ps-paper-type 'a4
214 ps-landscape-mode t
215 ps-number-of-columns 2
217 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
218 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
219 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
220 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
221 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
222 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
223 ps-header-line-pad .15
224 ps-print-header t
225 ps-print-header-frame t
226 ps-header-lines 2
227 ps-show-n-of-n t
228 ps-spool-duplex nil
230 ps-font-family 'Courier
231 ps-font-size 5.5
232 ps-header-font-family 'Helvetica
233 ps-header-font-size 6
234 ps-header-title-font-size 8)
235 'ps-jack-setup)
238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
240 (provide 'ps-samp)
242 ;; arch-tag: 99c415d3-be39-43c6-aa32-7ee33ba19600
243 ;;; ps-samp.el ends here