]> code.delx.au - gnu-emacs/blob - lisp/printing.el
New tips in Tips section.
[gnu-emacs] / lisp / printing.el
1 ;;; printing.el --- printing utilities
2
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
7 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
8 ;; Time-stamp: <2004/03/10 20:37:21 vinicius>
9 ;; Keywords: wp, print, PostScript
10 ;; Version: 6.7.2
11 ;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/
12
13 (defconst pr-version "6.7.2"
14 "printing.el, v 6.7.2 <2004/02/29 vinicius>
15
16 Please send all bug fixes and enhancements to
17 Vinicius Jose Latorre <vinicius@cpqd.com.br>
18 ")
19
20 ;; This file is part of GNU Emacs.
21
22 ;; GNU Emacs is free software; you can redistribute it and/or modify it under
23 ;; the terms of the GNU General Public License as published by the Free
24 ;; Software Foundation; either version 2, or (at your option) any later
25 ;; version.
26
27 ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY
28 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
29 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
30 ;; details.
31
32 ;; You should have received a copy of the GNU General Public License along with
33 ;; GNU Emacs; see the file COPYING. If not, write to the Free Software
34 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35
36 ;;; Commentary:
37
38 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;
40 ;; Introduction
41 ;; ------------
42 ;;
43 ;; This package provides some printing utilities that includes
44 ;; previewing/printing a PostScript file, printing a text file and
45 ;; previewing/printing some major modes (like mh-folder-mode,
46 ;; rmail-summary-mode, gnus-summary-mode, etc).
47 ;;
48 ;; `printing' was inspired on:
49 ;;
50 ;; print-nt.el Frederic Corne <frederic.corne@erli.fr>
51 ;; Special printing functions for Windows NT
52 ;;
53 ;; mh-e-init.el Tom Vogels <tov@ece.cmu.edu>
54 ;; PS-print for mail messages
55 ;;
56 ;; win32-ps-print.el Matthew O. Persico <mpersico@erols.com>
57 ;; PostScript printing with ghostscript
58 ;;
59 ;; ps-print-interface.el Volker Franz <volker.franz@tuebingen.mpg.de>
60 ;; Graphical front end for ps-print and previewing
61 ;;
62 ;; `printing' is prepared to run on GNU, Unix and NT systems.
63 ;; On GNU or Unix system, `printing' depends on gs and gv utilities.
64 ;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe).
65 ;; To obtain ghostscript, ghostview and GSview see the URL
66 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'.
67 ;;
68 ;; `printing' also depends on ps-print and lpr GNU Emacs packages.
69 ;; To download the latest ps-print package see
70 ;; `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'.
71 ;; Please, see README file for ps-print installation instructions.
72 ;;
73 ;;
74 ;; Novices (First Users)
75 ;; ---------------------
76 ;;
77 ;; First of all, take a glance of printing documentation only to have an idea
78 ;; of what `printing' is capable.
79 ;;
80 ;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
81 ;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'. These variables
82 ;; are the main variables for printing processing.
83 ;;
84 ;; Now, please, see these variables documentation more in deep. You can do
85 ;; this by typing C-h v pr-ps-name RET (for example) if you already loaded
86 ;; printing package, or by browsing printing.el source file.
87 ;;
88 ;; If the documentation isn't clear or if you find a way to improve the
89 ;; documentation, please, send an email to maintainer. All printing users
90 ;; will thank you.
91 ;;
92 ;; One way to set variables is by calling `pr-customize', customize all
93 ;; variables and save the customization by future sessions (see Options
94 ;; section). Other way is by coding your settings on Emacs init file (that is,
95 ;; .emacs file), see below for a first setting template that it should be
96 ;; inserted on your ~/.emacs file (or c:/_emacs, if you're using Windows 9x/NT
97 ;; or MS-DOS):
98 ;;
99 ;; * Example of setting for Windows system:
100 ;;
101 ;; (require 'printing) ; load printing package
102 ;; (setq pr-path-alist
103 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
104 ;; (ghostview "c:/gs/gsview-dir")
105 ;; (mpage "c:/mpage-dir")
106 ;; ))
107 ;; (setq pr-txt-name 'prt_06a)
108 ;; (setq pr-txt-printer-alist
109 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
110 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
111 ;; (PRN "" nil "PRN")
112 ;; (standard "redpr.exe" nil "")
113 ;; ))
114 ;; (setq pr-ps-name 'lps_06b)
115 ;; (setq pr-ps-printer-alist
116 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
117 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
118 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
119 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
120 ;; (LPT1 "" nil "" "LPT1:")
121 ;; (PRN "" nil "" "PRN")
122 ;; (standard "redpr.exe" nil "" "")
123 ;; ))
124 ;; (pr-update-menus t) ; update now printer and utility menus
125 ;;
126 ;; * Example of setting for GNU or Unix system:
127 ;;
128 ;; (require 'printing) ; load printing package
129 ;; (setq pr-path-alist
130 ;; '((unix "." "~/bin" ghostview mpage PATH)
131 ;; (ghostview "$HOME/bin/gsview-dir")
132 ;; (mpage "$HOME/bin/mpage-dir")
133 ;; ))
134 ;; (setq pr-txt-name 'prt_06a)
135 ;; (setq pr-txt-printer-alist
136 ;; '((prt_06a "lpr" nil "prt_06a")
137 ;; (prt_07c nil nil "prt_07c")
138 ;; ))
139 ;; (setq pr-ps-name 'lps_06b)
140 ;; (setq pr-ps-printer-alist
141 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
142 ;; (lps_07c "lpr" nil nil "lps_07c")
143 ;; (lps_08c nil nil nil "lps_08c")
144 ;; ))
145 ;; (pr-update-menus t) ; update now printer and utility menus
146 ;;
147 ;;
148 ;; NOTE 1: Don't forget to download and install ghostscript utilities (see
149 ;; Utilities section).
150 ;;
151 ;; NOTE 2: The `printer-name' and `ps-printer-name' variables don't need to be
152 ;; set, as they are implicit set by `pr-ps-printer-alist' and
153 ;; `pr-txt-printer-alist'.
154 ;;
155 ;; NOTE 3: The duplex feature will only work on PostScript printers that
156 ;; support this feature.
157 ;; You can check if your PostScript printer supports duplex feature
158 ;; by checking the printer manual. Or you can try these steps:
159 ;; 1. Open a buffer (or use the *scratch* buffer).
160 ;; 2. Type:
161 ;; First line (on first page)
162 ;; ^L
163 ;; Second line (on second page)
164 ;; 3. Print this buffer with duplex turned on.
165 ;; If it's printed 2 (two) sheets of paper, then your PostScript
166 ;; printer doesn't have duplex feature; otherwise, it's ok, your
167 ;; printer does have duplex feature.
168 ;;
169 ;; NOTE 4: See Tips section.
170 ;;
171 ;;
172 ;; Tips
173 ;; ----
174 ;;
175 ;; 1. If your have a local printer, that is, a printer which is connected
176 ;; directly to your computer, don't forget to connect the printer to your
177 ;; computer before printing.
178 ;;
179 ;; 2. If you try to print a file and it seems that the file was printed, but
180 ;; there is no paper in the printer, then try to set `pr-delete-temp-file'
181 ;; to nil. Probably `printing' is deleting the temporary file before your
182 ;; local system can get it to send to the printer.
183 ;;
184 ;; 3. Don't try to print a dynamic buffer, that is, a buffer which is
185 ;; modifying while `printing' tries to print. Eventually you got an error
186 ;; message. Instead, save the dynamic buffer to a file or copy it in
187 ;; another buffer and, then, print the file or the new static buffer.
188 ;; An example of dynamic buffer is the *Messages* buffer.
189 ;;
190 ;;
191 ;; Using `printing'
192 ;; ----------------
193 ;;
194 ;; To use `printing' insert in your ~/.emacs file (or c:/_emacs, if you're
195 ;; using Windows 9x/NT or MS-DOS):
196 ;;
197 ;; (require 'printing)
198 ;;
199 ;; When `printing' is loaded:
200 ;; * On Emacs 20:
201 ;; it replaces the Tools/Print menu by Tools/Printing menu.
202 ;; * On Emacs 21:
203 ;; it replaces the File/Print* menu entries by File/Print menu.
204 ;; Please, see section Menu Layout below for menu explanation.
205 ;;
206 ;; To use `printing' utilities you can use the Printing menu options, type M-x
207 ;; followed by one of the commands below, or type a key associated with the
208 ;; command you want (if there is a key binding).
209 ;;
210 ;; `printing' has the following commands:
211 ;;
212 ;; pr-interface
213 ;; pr-ps-directory-preview
214 ;; pr-ps-directory-using-ghostscript
215 ;; pr-ps-directory-print
216 ;; pr-ps-directory-ps-print
217 ;; pr-ps-buffer-preview
218 ;; pr-ps-buffer-using-ghostscript
219 ;; pr-ps-buffer-print
220 ;; pr-ps-buffer-ps-print
221 ;; pr-ps-region-preview
222 ;; pr-ps-region-using-ghostscript
223 ;; pr-ps-region-print
224 ;; pr-ps-region-ps-print
225 ;; pr-ps-mode-preview
226 ;; pr-ps-mode-using-ghostscript
227 ;; pr-ps-mode-print
228 ;; pr-ps-mode-ps-print
229 ;; pr-ps-file-preview
230 ;; pr-ps-file-up-preview
231 ;; pr-ps-file-using-ghostscript
232 ;; pr-ps-file-print
233 ;; pr-ps-file-ps-print
234 ;; pr-ps-file-up-ps-print
235 ;; pr-ps-fast-fire
236 ;; pr-despool-preview
237 ;; pr-despool-using-ghostscript
238 ;; pr-despool-print
239 ;; pr-despool-ps-print
240 ;; pr-printify-directory
241 ;; pr-printify-buffer
242 ;; pr-printify-region
243 ;; pr-txt-directory
244 ;; pr-txt-buffer
245 ;; pr-txt-region
246 ;; pr-txt-mode
247 ;; pr-txt-fast-fire
248 ;; pr-toggle-file-duplex
249 ;; pr-toggle-file-tumble
250 ;; pr-toggle-file-landscape
251 ;; pr-toggle-ghostscript
252 ;; pr-toggle-faces
253 ;; pr-toggle-spool
254 ;; pr-toggle-duplex
255 ;; pr-toggle-tumble
256 ;; pr-toggle-landscape
257 ;; pr-toggle-upside-down
258 ;; pr-toggle-line
259 ;; pr-toggle-zebra
260 ;; pr-toggle-header
261 ;; pr-toggle-lock
262 ;; pr-toggle-region
263 ;; pr-toggle-mode
264 ;; pr-customize
265 ;; lpr-customize
266 ;; pr-help
267 ;; pr-ps-name
268 ;; pr-txt-name
269 ;; pr-ps-utility
270 ;; pr-show-ps-setup
271 ;; pr-show-pr-setup
272 ;; pr-show-lpr-setup
273 ;;
274 ;; The general meanings of above commands are:
275 ;;
276 ;; PREFIX:
277 ;; `pr-interface' buffer interface for printing package.
278 ;; `pr-help' help for printing package.
279 ;; `pr-ps-name' interactively select a PostScript printer.
280 ;; `pr-txt-name' interactively select a text printer.
281 ;; `pr-ps-utility' interactively select a PostScript utility.
282 ;; `pr-show-*-setup' show current settings.
283 ;; `pr-ps-*' deal with PostScript code generation.
284 ;; `pr-txt-*' deal with text generation.
285 ;; `pr-toggle-*' toggle on/off some boolean variable.
286 ;; `pr-despool-*' despool the PostScript spooling buffer.
287 ;; `pr-printify-*' replace nonprintable ASCII by printable ASCII
288 ;; representation.
289 ;;
290 ;; SUFFIX:
291 ;; `*-customize' customization.
292 ;; `*-preview' preview a PostScript file.
293 ;; `*-using-ghostscript' use ghostscript to print.
294 ;; `*-fast-fire' fast fire command (see it for documentation).
295 ;; `*-print' send PostScript directly to printer.
296 ;; `*-ps-print' send PostScript directly to printer or use
297 ;; ghostscript to print. It depends on
298 ;; `pr-print-using-ghostscript' option.
299 ;;
300 ;; INFIX/SUFFIX:
301 ;; `*-directory*' process a directory.
302 ;; `*-buffer*' process a buffer.
303 ;; `*-region*' process a region.
304 ;; `*-mode*' process a major mode (see explanation below).
305 ;; `*-file-*' process a PostScript file.
306 ;; `*-file-up-*' process a PostScript file using a filter utility.
307 ;;
308 ;; Here are some examples:
309 ;;
310 ;; `pr-ps-buffer-using-ghostscript'
311 ;; Use ghostscript to print a buffer.
312 ;;
313 ;; `pr-ps-file-print'
314 ;; Print a PostScript file.
315 ;;
316 ;; `pr-toggle-spool'
317 ;; Toggle spooling buffer.
318 ;;
319 ;; So you can preview through ghostview, use ghostscript to print (if you don't
320 ;; have a PostScript printer) or send directly to printer a PostScript code
321 ;; generated by `ps-print' package.
322 ;;
323 ;; Besides operating one buffer or region each time, you also can postpone
324 ;; previewing or printing by saving the PostScript code generated in a
325 ;; temporary Emacs buffer. This way you can save banner pages between
326 ;; successive printing. You can toggle on/off spooling by invoking
327 ;; `pr-toggle-spool' interactively or through menu bar.
328 ;;
329 ;; If you type, for example:
330 ;;
331 ;; C-u M-x pr-ps-buffer-print RET
332 ;;
333 ;; The `pr-ps-buffer-print' command prompts you for a n-up printing number and
334 ;; a file name, and save the PostScript code generated to the file name instead
335 ;; of sending to printer.
336 ;;
337 ;; This behavior is similar with the commands that deal with PostScript code
338 ;; generation, that is, with `pr-ps-*' and `pr-despool-*' commands. If
339 ;; spooling is on, only `pr-despool-*' commands prompt for a file name and save
340 ;; the PostScript code spooled in this file.
341 ;;
342 ;; Besides the behavior described above, the `*-directory*' commands also
343 ;; prompt for a directory and a file name regexp. So, it's possible to process
344 ;; all or certain files on a directory at once (see also documentation for
345 ;; `pr-list-directory').
346 ;;
347 ;; `printing' has also a special way to handle some major mode through
348 ;; `*-mode*' commands. So it's possible to customize a major mode printing,
349 ;; it's only needed to declare the customization in `pr-mode-alist' (see
350 ;; section Options) and invoke some of `*-mode*' commands. An example for
351 ;; major mode usage is when you're using gnus (or mh, or rmail, etc.) and
352 ;; you're in the *Summary* buffer, if you forget to switch to the *Article*
353 ;; buffer before printing, you'll get a nicely formatted list of article
354 ;; subjects shows up at the printer. With major mode printing you don't need
355 ;; to switch from gnus *Summary* buffer first.
356 ;;
357 ;; Current global keyboard mapping for GNU Emacs is:
358 ;;
359 ;; (global-set-key [print] 'pr-ps-fast-fire)
360 ;; (global-set-key [M-print] 'pr-ps-mode-using-ghostscript)
361 ;; (global-set-key [C-print] 'pr-txt-fast-fire)
362 ;;
363 ;; And for XEmacs is:
364 ;;
365 ;; (global-set-key 'f22 'pr-ps-fast-fire)
366 ;; (global-set-key '(meta f22) 'pr-ps-mode-using-ghostscript)
367 ;; (global-set-key '(control f22) 'pr-txt-fast-fire)
368 ;;
369 ;; As a suggestion of global keyboard mapping for some `printing' commands:
370 ;;
371 ;; (global-set-key "\C-ci" 'pr-interface)
372 ;; (global-set-key "\C-cbp" 'pr-ps-buffer-print)
373 ;; (global-set-key "\C-cbx" 'pr-ps-buffer-preview)
374 ;; (global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
375 ;; (global-set-key "\C-crp" 'pr-ps-region-print)
376 ;; (global-set-key "\C-crx" 'pr-ps-region-preview)
377 ;; (global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
378 ;;
379 ;;
380 ;; Options
381 ;; -------
382 ;;
383 ;; Below it's shown a brief description of `printing' options, please, see the
384 ;; options declaration in the code for a long documentation.
385 ;;
386 ;; `pr-path-style' Specify which path style to use for external
387 ;; commands.
388 ;;
389 ;; `pr-path-alist' Specify an alist for command paths.
390 ;;
391 ;; `pr-txt-name' Specify a printer for printing a text file.
392 ;;
393 ;; `pr-txt-printer-alist' Specify an alist of all text printers.
394 ;;
395 ;; `pr-ps-name' Specify a printer for printing a PostScript
396 ;; file.
397 ;;
398 ;; `pr-ps-printer-alist' Specify an alist for all PostScript printers.
399 ;;
400 ;; `pr-temp-dir' Specify a directory for temporary files during
401 ;; printing.
402 ;;
403 ;; `pr-ps-temp-file' Specify PostScript temporary file name.
404 ;;
405 ;; `pr-gv-command' Specify path and name of the gsview/gv
406 ;; utility.
407 ;;
408 ;; `pr-gs-command' Specify path and name of the ghostscript
409 ;; utility.
410 ;;
411 ;; `pr-gs-switches' Specify ghostscript switches.
412 ;;
413 ;; `pr-gs-device' Specify ghostscript device switch value.
414 ;;
415 ;; `pr-gs-resolution' Specify ghostscript resolution switch value.
416 ;;
417 ;; `pr-print-using-ghostscript' Non-nil means print using ghostscript.
418 ;;
419 ;; `pr-faces-p' Non-nil means print with face attributes.
420 ;;
421 ;; `pr-spool-p' Non-nil means spool printing in a buffer.
422 ;;
423 ;; `pr-file-landscape' Non-nil means print PostScript file in
424 ;; landscape orientation.
425 ;;
426 ;; `pr-file-duplex' Non-nil means print PostScript file in duplex
427 ;; mode.
428 ;;
429 ;; `pr-file-tumble' Non-nil means print PostScript file in tumble
430 ;; mode.
431 ;;
432 ;; `pr-auto-region' Non-nil means region is automagically detected.
433 ;;
434 ;; `pr-auto-mode' Non-nil means major-mode specific printing is
435 ;; prefered over normal printing.
436 ;;
437 ;; `pr-mode-alist' Specify an alist for a major-mode and printing
438 ;; function.
439 ;;
440 ;; `pr-ps-utility' Specify PostScript utility processing.
441 ;;
442 ;; `pr-ps-utility-alist' Specify an alist for PostScript utility
443 ;; processing.
444 ;;
445 ;; `pr-menu-lock' Non-nil means menu is locked while selecting
446 ;; toggle options.
447 ;;
448 ;; `pr-menu-char-height' Specify menu char height in pixels.
449 ;;
450 ;; `pr-menu-char-width' Specify menu char width in pixels.
451 ;;
452 ;; `pr-setting-database' Specify an alist for settings in general.
453 ;;
454 ;; `pr-visible-entry-list' Specify a list of Printing menu visible
455 ;; entries.
456 ;;
457 ;; `pr-delete-temp-file' Non-nil means delete temporary files.
458 ;;
459 ;; `pr-list-directory' Non-nil means list directory when processing a
460 ;; directory.
461 ;;
462 ;; `pr-buffer-name' Specify the name of the buffer interface for
463 ;; printing package.
464 ;;
465 ;; `pr-buffer-name-ignore' Specify a regexp list for buffer names to be
466 ;; ignored in interface buffer.
467 ;;
468 ;; `pr-buffer-verbose' Non-nil means to be verbose when editing a
469 ;; field in interface buffer.
470 ;;
471 ;; `pr-shell-file-name' Specify file name to load inferior shells
472 ;; from.
473 ;;
474 ;; To set the above options you may:
475 ;;
476 ;; a) insert the code in your ~/.emacs, like:
477 ;;
478 ;; (setq pr-faces-p t)
479 ;;
480 ;; This way always keep your default settings when you enter a new Emacs
481 ;; session.
482 ;;
483 ;; b) or use `set-variable' in your Emacs session, like:
484 ;;
485 ;; M-x set-variable RET pr-faces-p RET t RET
486 ;;
487 ;; This way keep your settings only during the current Emacs session.
488 ;;
489 ;; c) or use customization, for example:
490 ;; click on menu-bar *Help* option,
491 ;; then click on *Customize*,
492 ;; then click on *Browse Customization Groups*,
493 ;; expand *PostScript* group,
494 ;; expand *Printing* group
495 ;; and then customize `printing' options.
496 ;; Through this way, you may choose if the settings are kept or not when
497 ;; you leave out the current Emacs session.
498 ;;
499 ;; d) or see the option value:
500 ;;
501 ;; C-h v pr-faces-p RET
502 ;;
503 ;; and click the *customize* hypertext button.
504 ;; Through this way, you may choose if the settings are kept or not when
505 ;; you leave out the current Emacs session.
506 ;;
507 ;; e) or invoke:
508 ;;
509 ;; M-x pr-customize RET
510 ;;
511 ;; and then customize `printing' options.
512 ;; Through this way, you may choose if the settings are kept or not when
513 ;; you leave out the current Emacs session.
514 ;;
515 ;; f) or use menu bar, for example:
516 ;; click on menu-bar *File* option,
517 ;; then click on *Printing*,
518 ;; then click on *Customize*,
519 ;; then click on *printing*
520 ;; and then customize `printing' options.
521 ;; Through this way, you may choose if the settings are kept or not when
522 ;; you leave out the current Emacs session.
523 ;;
524 ;;
525 ;; Menu Layout
526 ;; -----------
527 ;;
528 ;; The `printing' menu (Tools/Printing or File/Print) has the following layout:
529 ;;
530 ;; +-----------------------------+
531 ;; A 0 | Printing Interface |
532 ;; +-----------------------------+ +-A---------+ +-B------+
533 ;; I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
534 ;; 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
535 ;; 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
536 ;; +-----------------------------+ |Mode >|-- B |Other...|
537 ;; II 4 | Printify >|-----\ |File >|--\ +--------+
538 ;; 5 | Print >|---\ | |Despool... | |
539 ;; 6 | Text Printer: name >|-\ | | +-----------+ |
540 ;; +-----------------------------+ | | | +---------+ +------------+
541 ;; III 7 |[ ]Landscape | | | \-|Directory| | No Prep... | Ia
542 ;; 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
543 ;; 9 |[ ]Print Header Frame | | | |Region | | name >|- C
544 ;; 10 |[ ]Line Number | | | +---------+ +------------+
545 ;; 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
546 ;; 12 |[ ]Duplex | | \---|Directory| | 2-up... |
547 ;; 13 |[ ]Tumble | \--\ |Buffer | | 4-up... |
548 ;; 14 |[ ]Upside-Down | | |Region | | Other... |
549 ;; 15 | Print All Pages >|--\ | |Mode | +------------+
550 ;; +-----------------------------+ | | +---------+ |[ ]Landscape| Id
551 ;; IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
552 ;; 17 |[ ]Print with faces | | \--|( )name A| |[ ]Tumble | If
553 ;; 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
554 ;; +-----------------------------+ | |... |
555 ;; V 19 |[ ]Auto Region | | |(*)name |
556 ;; 20 |[ ]Auto Mode | | |... |
557 ;; 21 |[ ]Menu Lock | | +---------+ +--------------+
558 ;; +-----------------------------+ \------------------|(*)All Pages |
559 ;; VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
560 ;; 23 | Show Settings >|-------|printing| |( )Odd Pages |
561 ;; 24 | Help | |ps-print| |( )Even Sheets|
562 ;; +-----------------------------+ |lpr | |( )Odd Sheets |
563 ;; +--------+ +--------------+
564 ;;
565 ;; See `pr-visible-entry-list' for hiding some parts of the menu.
566 ;;
567 ;; The menu has the following sections:
568 ;;
569 ;; A. Interface:
570 ;;
571 ;; 0. You can use a buffer interface instead of menus. It looks like the
572 ;; customization buffer. Basically, it has the same options found in the
573 ;; menu and some extra options, all this on a buffer.
574 ;;
575 ;; I. PostScript printing:
576 ;;
577 ;; 1. You can generate a PostScript file (if you type C-u before activating
578 ;; menu) or PostScript temporary file for a directory, a buffer, a region
579 ;; or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
580 ;; after file generation, ghostview is activated using the file generated
581 ;; as argument. This option is disabled if spooling is on (option 16).
582 ;; Also, if you already have a PostScript file you can preview it.
583 ;; Instead of previewing each buffer, region or major mode at once, you
584 ;; can save temporarily the PostScript code generated in a buffer and
585 ;; preview it later. The option `Despool...' despools the PostScript
586 ;; spooling buffer in a temporary file and uses ghostview to preview it.
587 ;; If you type C-u before choosing this option, the PostScript code
588 ;; generated is saved in a file instead of saving in a temporary file.
589 ;; To spool the PostScript code generated you need to turn on the option
590 ;; 16. The option `Despool...' is enabled if spooling is on (option
591 ;; 16).
592 ;;
593 ;; NOTE 1: It's possible to customize a major mode printing, just declare
594 ;; the customization in `pr-mode-alist' and invoke some of
595 ;; `*-mode*' commands or select Mode option in Printing menu. An
596 ;; example for major mode usage is when you're using gnus (or mh,
597 ;; or rmail, etc.) and you're in the *Summary* buffer, if you
598 ;; forget to switch to the *Article* buffer before printing,
599 ;; you'll get a nicely formatted list of article subjects shows
600 ;; up at the printer. With major mode printing you don't need to
601 ;; switch from gnus *Summary* buffer first.
602 ;;
603 ;; NOTE 2: There are the following options for PostScript file
604 ;; processing:
605 ;; Ia. Print the file *No Preprocessing*, that is, send it
606 ;; directly to PostScript printer.
607 ;; Ib. PostScript utility processing selection.
608 ;; See `pr-ps-utility-alist' and `pr-setting-database' for
609 ;; documentation.
610 ;; Ic. Do n-up processing before printing.
611 ;; Id. Toggle on/off landscape for PostScript file processing.
612 ;; Ie. Toggle on/off duplex for PostScript file processing.
613 ;; If. Toggle on/off tumble for PostScript file processing.
614 ;;
615 ;; NOTE 3: Don't forget to download and install the utilities declared on
616 ;; `pr-ps-utility-alist'.
617 ;;
618 ;; 2. Operate the same way as option 1, but it sends directly the PostScript
619 ;; code (or put in a file, if you've typed C-u) or it uses ghostscript to
620 ;; print the PostScript file generated. It depends on option 18, if it's
621 ;; turned on, it uses ghostscript; otherwise, it sends directly to
622 ;; printer. If spooling is on (option 16), the PostScript code is saved
623 ;; temporarily in a buffer instead of printing it or saving it in a file.
624 ;; Also, if you already have a PostScript file you can print it. Instead
625 ;; of printing each buffer, region or major mode at once, you can save
626 ;; temporarily the PostScript code generated in a buffer and print it
627 ;; later. The option `Despool...' despools the PostScript spooling
628 ;; buffer directly on a printer. If you type C-u before choosing this
629 ;; option, the PostScript code generated is saved in a file instead of
630 ;; sending to printer. To spool the PostScript code generated you need
631 ;; to turn on the option 16. This option is enabled if spooling is on
632 ;; (option 16). See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
633 ;;
634 ;; 3. You can select a new PostScript printer to send PostScript code
635 ;; generated. For selection it's used all PostScript printers defined
636 ;; in `pr-ps-printer-alist' variable (see it for documentation).
637 ;; See also `pr-setting-database'.
638 ;;
639 ;; II. Text printing:
640 ;;
641 ;; 4. If you have control characters (character code from \000 to \037) in a
642 ;; buffer and you want to print them in a text printer, select this
643 ;; option. All control characters in your buffer or region will be
644 ;; replaced by a printable representation. The printable representations
645 ;; use ^ (for ASCII control characters) or hex. The characters tab,
646 ;; linefeed, space, return and formfeed are not affected. You don't need
647 ;; to select this option if you use any option of section I, the
648 ;; PostScript engine treats control characters properly.
649 ;;
650 ;; 5. If you want to print a directory, buffer, region or major mode in a
651 ;; text printer, select this option. See also the NOTE 1 on option 1.
652 ;;
653 ;; 6. You can select a new text printer to send text generated. For
654 ;; selection it's used all text printers defined in
655 ;; `pr-txt-printer-alist' variable (see it for documentation).
656 ;; See also `pr-setting-database'.
657 ;;
658 ;; III. PostScript page toggle options:
659 ;;
660 ;; 7. If you want a PostScript landscape printing, turn on this option.
661 ;;
662 ;; 8. If you want to have a header in each page in your PostScript code,
663 ;; turn on this option.
664 ;;
665 ;; 9. If you want to draw a gaudy frame around the header, turn on this
666 ;; option. This option is enabled if print header is on (option 8).
667 ;;
668 ;; 10. If you want that the line number is printed in your PostScript code,
669 ;; turn on this option.
670 ;;
671 ;; 11. If you want background zebra stripes in your PostScript code, turn on
672 ;; this option.
673 ;;
674 ;; 12. If you want a duplex printing and your PostScript printer has this
675 ;; feature, turn on this option.
676 ;;
677 ;; 13. If you turned on duplex printing, you can choose if you want to have
678 ;; a printing suitable for binding on the left or right (tumble off), or
679 ;; to have a printing suitable for binding at top or bottom (tumble on).
680 ;; This option is enabled if duplex is on (option 12).
681 ;;
682 ;; 14. If you want a PostScript upside-down printing, turn on this option.
683 ;;
684 ;; 15. With this option, you can choose if you want to print all pages, odd
685 ;; pages, even pages, odd sheets or even sheets.
686 ;; See also `ps-even-or-odd-pages'.
687 ;;
688 ;; IV. PostScript processing toggle options:
689 ;;
690 ;; 16. If you want to spool the PostScript code generated, turn on this
691 ;; option. To spool the PostScript code generated use option 2. You
692 ;; can despool later by choosing option 1 or 2, sub-option `Despool...'.
693 ;;
694 ;; 17. If you use colors in your buffers and want to see these colors on
695 ;; your PostScript code generated, turn on this option. If you have a
696 ;; black/white PostScript printer, these colors are displayed in gray
697 ;; scale by PostScript printer interpreter.
698 ;;
699 ;; 18. If you don't have a PostScript printer to send PostScript files, turn
700 ;; on this option. When this option is on, the ghostscript is used to
701 ;; print PostScript files. In GNU or Unix system, if ghostscript is set
702 ;; as a PostScript filter, you don't need to turn on this option.
703 ;;
704 ;; V. Printing customization:
705 ;;
706 ;; 19. If you want that region is automagically detected, turn on this
707 ;; option. Note that this will only work if you're using transient mark
708 ;; mode. When this option is on, the `*-buffer*' commands will behave
709 ;; like `*-region*' commands, that is, `*-buffer*' commands will print
710 ;; only the region marked instead of all buffer.
711 ;;
712 ;; 20. Turn this option on if you want that when current major-mode is
713 ;; declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
714 ;; behave like `*-mode*' commands.
715 ;;
716 ;; 21. If you want that Printing menu stays open while you are setting
717 ;; toggle options, turn on this option. The variables
718 ;; `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
719 ;; menu position, so don't forget to adjust these variables if menu
720 ;; position is not ok.
721 ;;
722 ;; VI. Customization:
723 ;;
724 ;; 22. Besides all options in section III, IV and V, you can customize much
725 ;; more PostScript options in `ps-print' option. Or you can customize
726 ;; some `lpr' options for text printing. Or customize `printing'
727 ;; options.
728 ;;
729 ;; 23. Show current settings for `printing', `ps-print' or `lpr'.
730 ;;
731 ;; 24. Quick help for printing menu layout.
732 ;;
733 ;;
734 ;; Option Settings
735 ;; ---------------
736 ;;
737 ;; Below it's shown only the main options that affect all `printing' package.
738 ;; Check all the settings below *BEFORE* running `printing' commands.
739 ;;
740 ;; * Example of setting for GNU or Unix system:
741 ;;
742 ;; (require 'printing)
743 ;; (setq pr-path-alist
744 ;; '((unix "." "~/bin" ghostview mpage PATH)
745 ;; (ghostview "$HOME/bin/gsview-dir")
746 ;; (mpage "$HOME/bin/mpage-dir")
747 ;; ))
748 ;; (setq pr-txt-name 'prt_06a)
749 ;; (setq pr-txt-printer-alist
750 ;; '((prt_06a "lpr" nil "prt_06a")
751 ;; (prt_07c nil nil "prt_07c")
752 ;; ))
753 ;; (setq pr-ps-name 'lps_06b)
754 ;; (setq pr-ps-printer-alist
755 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
756 ;; (lps_07c "lpr" nil nil "lps_07c")
757 ;; (lps_08c nil nil nil "lps_08c")
758 ;; ))
759 ;; (setq pr-temp-dir "/tmp/")
760 ;; (setq pr-gv-command "gv")
761 ;; (setq pr-gs-command "gs")
762 ;; (setq pr-gs-switches '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
763 ;; (setq pr-gs-device "uniprint")
764 ;; (setq pr-gs-resolution 300)
765 ;; (setq pr-ps-utility 'mpage)
766 ;; (setq pr-ps-utility-alist
767 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
768 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
769 ;; (inherits-from: . no-duplex))
770 ;; ))
771 ;; (setq pr-setting-database
772 ;; '((no-duplex
773 ;; nil nil nil
774 ;; (pr-file-duplex . nil)
775 ;; (pr-file-tumble . nil))
776 ;; ))
777 ;; (pr-update-menus t) ; update now printer and utility menus
778 ;;
779 ;; * Example of setting for Windows system:
780 ;;
781 ;; (require 'printing)
782 ;; (setq pr-path-alist
783 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
784 ;; (ghostview "c:/gs/gsview-dir")
785 ;; (mpage "c:/mpage-dir")
786 ;; ))
787 ;; (setq pr-txt-name 'prt_06a)
788 ;; (setq pr-txt-printer-alist
789 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
790 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
791 ;; (PRN "" nil "PRN")
792 ;; (standard "redpr.exe" nil "")
793 ;; ))
794 ;; (setq pr-ps-name 'lps_06b)
795 ;; (setq pr-ps-printer-alist
796 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
797 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
798 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
799 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
800 ;; (LPT1 "" nil "" "LPT1:")
801 ;; (PRN "" nil "" "PRN")
802 ;; (standard "redpr.exe" nil "" "")
803 ;; ))
804 ;; (setq pr-temp-dir "C:/WINDOWS/TEMP/")
805 ;; (setq pr-gv-command "c:/gs/gsview/gsview32.exe")
806 ;; (setq pr-gs-command "c:/gs/gswin32.exe")
807 ;; (setq pr-gs-switches '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts"))
808 ;; (setq pr-gs-device "mswinpr2")
809 ;; (setq pr-gs-resolution 300)
810 ;; (setq pr-ps-utility 'psnup)
811 ;; (setq pr-ps-utility-alist
812 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " "
813 ;; nil (inherits-from: . no-duplex))
814 ;; ))
815 ;; (setq pr-setting-database
816 ;; '((no-duplex
817 ;; nil nil nil
818 ;; (pr-file-duplex . nil)
819 ;; (pr-file-tumble . nil))
820 ;; ))
821 ;; (pr-update-menus t) ; update now printer and utility menus
822 ;;
823 ;; NOTE: Don't forget to download and install the utilities declared on
824 ;; `pr-ps-utility-alist'.
825 ;;
826 ;;
827 ;; Utilities
828 ;; ---------
829 ;;
830 ;; `printing' package has the following utilities:
831 ;;
832 ;; `pr-setup' Return the current `printing' setup.
833 ;;
834 ;; `lpr-setup' Return the current `lpr' setup.
835 ;;
836 ;; `pr-update-menus' Update utility, PostScript and text printer menus.
837 ;;
838 ;; Below are some URL where you can find good utilities.
839 ;;
840 ;; * For `printing' package:
841 ;;
842 ;; printing `http://www.cpqd.com.br/~vinicius/emacs/printing.el.gz'
843 ;; ps-print `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'
844 ;;
845 ;; * For GNU or Unix system:
846 ;;
847 ;; gs, gv `http://www.gnu.org/software/ghostscript/ghostscript.html'
848 ;; enscript `http://people.ssh.fi/mtr/genscript/'
849 ;; psnup `http://www.dcs.ed.ac.uk/home/ajcd/psutils/index.html'
850 ;; mpage `http://www.mesa.nl/pub/mpage/'
851 ;;
852 ;; * For Windows system:
853 ;;
854 ;; gswin32, gsview32
855 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'
856 ;; enscript `http://people.ssh.fi/mtr/genscript/'
857 ;; psnup `http://www.dcs.ed.ac.uk/home/ajcd/psutils/index.html'
858 ;; redmon `http://www.cs.wisc.edu/~ghost/redmon/'
859 ;;
860 ;;
861 ;; Acknowledgments
862 ;; ---------------
863 ;;
864 ;; Thanks to Drew Adams <drew.adams@oracle.com> for directory processing and
865 ;; `pr-path-alist' suggestions.
866 ;;
867 ;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests.
868 ;;
869 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging
870 ;; and for suggestions:
871 ;; - even/odd pages printing.
872 ;; - ghostscript parameters for `pr-ps-printer-alist'.
873 ;; - default printer name.
874 ;; - completion functions.
875 ;; - automagic region detection.
876 ;; - menu entry hiding.
877 ;; - fast fire PostScript printing command.
878 ;; - `pr-path-style' variable.
879 ;;
880 ;; Thanks to Kim F. Storm <storm@filanet.dk> for beta-test and for suggestions:
881 ;; - PostScript Print and PostScript Print Preview merge.
882 ;; - Tools/Printing menu.
883 ;; - replace *-using-preview by *-using-ghostscript.
884 ;; - printer selection.
885 ;; - extra parameters for `pr-ps-printer-alist'.
886 ;;
887 ;; Thanks to:
888 ;; Frederic Corne <frederic.corne@erli.fr> print-nt.el
889 ;; Tom Vogels <tov@ece.cmu.edu> mh-e-init.el
890 ;; Matthew O. Persico <mpersico@erols.com> win32-ps-print.el
891 ;; Volker Franz <volker.franz@tuebingen.mpg.de> ps-print-interface.el
892 ;; And to all people who contributed with them.
893 ;;
894 ;;
895 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
896
897 ;;; Code:
898
899
900 (require 'lpr)
901 (require 'ps-print)
902
903
904 (and (string< ps-print-version "6.5.7")
905 (error "`printing' requires `ps-print' package version 6.5.7 or later."))
906
907
908 (eval-and-compile
909 (defconst pr-cygwin-system
910 (and ps-windows-system (getenv "OSTYPE")
911 (string-match "cygwin" (getenv "OSTYPE")))))
912
913
914 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
915 ;; To avoid compilation gripes
916
917
918 (eval-and-compile
919
920 (or (fboundp 'subst-char-in-string)
921 (defun subst-char-in-string (fromchar tochar string &optional inplace)
922 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
923 Unless optional argument INPLACE is non-nil, return a new string."
924 (let ((i (length string))
925 (newstr (if inplace string (copy-sequence string))))
926 (while (> (setq i (1- i)) 0)
927 (if (eq (aref newstr i) fromchar)
928 (aset newstr i tochar)))
929 newstr)))
930
931 ;; GNU Emacs
932 (defalias 'pr-e-frame-char-height 'frame-char-height)
933 (defalias 'pr-e-frame-char-width 'frame-char-width)
934 (defalias 'pr-e-mouse-pixel-position 'mouse-pixel-position)
935 ;; XEmacs
936 (defalias 'pr-x-add-submenu 'add-submenu)
937 (defalias 'pr-x-event-function 'event-function)
938 (defalias 'pr-x-event-object 'event-object)
939 (defalias 'pr-x-find-menu-item 'find-menu-item)
940 (defalias 'pr-x-font-height 'font-height)
941 (defalias 'pr-x-font-width 'font-width)
942 (defalias 'pr-x-get-popup-menu-response 'get-popup-menu-response)
943 (defalias 'pr-x-make-event 'make-event)
944 (defalias 'pr-x-misc-user-event-p 'misc-user-event-p)
945 (defalias 'pr-x-relabel-menu-item 'relabel-menu-item)
946 (defalias 'pr-x-event-x-pixel 'event-x-pixel)
947 (defalias 'pr-x-event-y-pixel 'event-y-pixel)
948
949 (cond
950 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
951 (defvar deactivate-mark nil)
952 (defalias 'pr-f-set-keymap-parents 'set-keymap-parent)
953 (defalias 'pr-f-set-keymap-name 'ignore)
954 (defalias 'pr-f-read-string 'read-string)
955 (defun pr-keep-region-active ()
956 (setq deactivate-mark nil)))
957
958 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
959 (defvar current-menubar nil)
960 (defvar current-mouse-event nil)
961 (defvar zmacs-region-stays nil)
962 (defalias 'pr-f-set-keymap-parents 'set-keymap-parents)
963 (defalias 'pr-f-set-keymap-name 'set-keymap-name)
964 (defun pr-f-read-string (prompt initial history default)
965 (let ((str (read-string prompt initial)))
966 (if (and str (not (string= str "")))
967 str
968 default)))
969 (defun pr-keep-region-active ()
970 (setq zmacs-region-stays t)))))
971
972
973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
974 ;; Customization Functions
975
976
977 (defun pr-alist-custom-set (symbol value)
978 "Set the value of custom variables for printer & utility selection."
979 (set symbol value)
980 (and (featurep 'printing) ; update only after printing is loaded
981 (pr-update-menus t)))
982
983
984 (defun pr-ps-utility-custom-set (symbol value)
985 "Update utility menu entry."
986 (set symbol value)
987 (and (featurep 'printing) ; update only after printing is loaded
988 (pr-menu-set-utility-title value)))
989
990
991 (defun pr-ps-name-custom-set (symbol value)
992 "Update `PostScript Printer:' menu entry."
993 (set symbol value)
994 (and (featurep 'printing) ; update only after printing is loaded
995 (pr-menu-set-ps-title value)))
996
997
998 (defun pr-txt-name-custom-set (symbol value)
999 "Update `Text Printer:' menu entry."
1000 (set symbol value)
1001 (and (featurep 'printing) ; update only after printing is loaded
1002 (pr-menu-set-txt-title value)))
1003
1004
1005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1006 ;; User Interface (I)
1007
1008
1009 (defgroup printing nil
1010 "Printing Utilities group"
1011 :tag "Printing Utilities"
1012 :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
1013 :prefix "pr-"
1014 :group 'wp
1015 :group 'postscript)
1016
1017
1018 (defcustom pr-path-style
1019 (if (and (not pr-cygwin-system)
1020 ps-windows-system)
1021 'windows
1022 'unix)
1023 "*Specify which path style to use for external commands.
1024
1025 Valid values are:
1026
1027 windows Windows 9x/NT style (\\)
1028
1029 unix Unix style (/)"
1030 :type '(choice :tag "Path style"
1031 (const :tag "Windows 9x/NT Style (\\)" :value windows)
1032 (const :tag "Unix Style (/)" :value unix))
1033 :group 'printing)
1034
1035
1036 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1037 ;; Internal Functions (I)
1038
1039
1040 (defun pr-dosify-path (path)
1041 "Replace unix-style directory separator character with dos/windows one."
1042 (interactive "sPath: ")
1043 (if (eq pr-path-style 'windows)
1044 (subst-char-in-string ?/ ?\\ path)
1045 path))
1046
1047
1048 (defun pr-unixify-path (path)
1049 "Replace dos/windows-style directory separator character with unix one."
1050 (interactive "sPath: ")
1051 (if (eq pr-path-style 'windows)
1052 (subst-char-in-string ?\\ ?/ path)
1053 path))
1054
1055
1056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1057 ;; User Interface (II)
1058
1059
1060 (defcustom pr-path-alist
1061 '((unix PATH)
1062 (cygwin PATH)
1063 (windows PATH))
1064 "*Specify an alist for command paths.
1065
1066 It's used to find commands used for printing package, like gv, gs, gsview.exe,
1067 mpage, print.exe, etc. See also `pr-command' function.
1068
1069 Each element has the form:
1070
1071 (ENTRY DIRECTORY...)
1072
1073 Where:
1074
1075 ENTRY It's a symbol, used to identify this entry.
1076 There must exist at least one of the following entries:
1077
1078 unix this entry is used when Emacs is running on GNU or
1079 Unix system.
1080
1081 cygwin this entry is used when Emacs is running on Windows
1082 95/98/NT/2000 with Cygwin.
1083
1084 windows this entry is used when Emacs is running on Windows
1085 95/98/NT/2000.
1086
1087 DIRECTORY It should be a string or a symbol. If it's a symbol, it should
1088 exist an equal entry in `pr-path-alist'. If it's a string,
1089 it's considered a directory specification.
1090
1091 The directory specification may contain:
1092 $var environment variable expansion
1093 ~/ tilde expansion
1094 ./ current directory
1095 ../ previous directory
1096
1097 For example, let's say the home directory is /home/my and the
1098 current directory is /home/my/dir, so:
1099
1100 THE ENTRY IS EXPANDED TO
1101 ~/entry /home/my/entry
1102 ./entry /home/my/dir/entry
1103 ../entry /home/my/entry
1104 $HOME/entry /home/my/entry
1105 $HOME/~/other/../my/entry /home/my/entry
1106
1107 SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
1108 list and there isn't a `PATH' entry in `pr-path-alist' or the
1109 `PATH' entry has a null directory list, the PATH environment
1110 variable is used.
1111
1112 Examples:
1113
1114 * On GNU or Unix system:
1115
1116 '((unix \".\" \"~/bin\" ghostview mpage PATH)
1117 (ghostview \"$HOME/bin/gsview-dir\")
1118 (mpage \"$HOME/bin/mpage-dir\")
1119 )
1120
1121 * On Windows system:
1122
1123 '((windows \"c:/applications/executables\" PATH ghostview mpage)
1124 (ghostview \"c:/gs/gsview-dir\")
1125 (mpage \"c:/mpage-dir\")
1126 )"
1127 :type '(repeat
1128 (cons :tag ""
1129 (symbol :tag "Identifier ")
1130 (repeat :tag "Directory List"
1131 (choice :menu-tag "Directory"
1132 :tag "Directory"
1133 (string :value "")
1134 (symbol :value symbol)))))
1135 :group 'printing)
1136
1137
1138 (defcustom pr-txt-name 'default
1139 "*Specify a printer for printing a text file.
1140
1141 The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
1142 documentation).
1143
1144 This variable should be modified by customization engine. If this variable is
1145 modified by other means (for example, a lisp function), use `pr-update-menus'
1146 function (see it for documentation) to update text printer menu."
1147 :type 'symbol
1148 :set 'pr-txt-name-custom-set
1149 :group 'printing)
1150
1151
1152 (defcustom pr-txt-printer-alist
1153 (list (list 'default lpr-command nil
1154 (cond ((boundp 'printer-name) printer-name)
1155 (ps-windows-system "PRN")
1156 (t nil)
1157 )))
1158 ;; Examples:
1159 ;; * On GNU or Unix system:
1160 ;; '((prt_06a "lpr" nil "prt_06a")
1161 ;; (prt_07c nil nil "prt_07c")
1162 ;; )
1163 ;; * On Windows system:
1164 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
1165 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
1166 ;; (PRN "" nil "PRN")
1167 ;; (standard "redpr.exe" nil "")
1168 ;; )
1169 "*Specify an alist of all text printers (text printer database).
1170
1171 The alist element has the form:
1172
1173 (SYMBOL COMMAND SWITCHES NAME)
1174
1175 Where:
1176
1177 SYMBOL It's a symbol to identify a text printer. It's for
1178 `pr-txt-name' variable setting and for menu selection.
1179 Examples:
1180 'prt_06a
1181 'my_printer
1182
1183 COMMAND Name of the program for printing a text file. On MS-DOS and
1184 MS-Windows systems, if the value is an empty string, then Emacs
1185 will write directly to the printer port given by NAME (see text
1186 below), that is, the NAME should be something like \"PRN\" or
1187 \"LPT1:\".
1188 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1189 COMMAND shouldn't be an empty string.
1190 The programs `print' and `nprint' (the standard print programs
1191 on Windows NT and Novell Netware respectively) are handled
1192 specially, using NAME as the destination for output; any other
1193 program is treated like `lpr' except that an explicit filename
1194 is given as the last argument.
1195 If COMMAND is nil, it's used the default printing program:
1196 `print' for Windows system, `lp' for lp system and `lpr' for
1197 all other systems. See also `pr-path-alist'.
1198 Examples:
1199 \"print\"
1200 \"lpr\"
1201 \"lp\"
1202
1203 SWITCHES List of sexp's to pass as extra options for text printer
1204 program. It is recommended to set NAME (see text below)
1205 instead of including an explicit switch on this list.
1206 Example:
1207 . for lpr
1208 '(\"-#3\" \"-l\")
1209 nil
1210
1211 NAME A string that specifies a text printer name.
1212 On Unix-like systems, a string value should be a name
1213 understood by lpr's -P option (or lp's -d option).
1214 On MS-DOS and MS-Windows systems, it is the name of a printer
1215 device or port. Typical non-default settings would be \"LPT1:\"
1216 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1217 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1218 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1219 printer. You can also set it to a name of a file, in which
1220 case the output gets appended to that file. If you want to
1221 discard the printed output, set this to \"NUL\".
1222 Examples:
1223 . for print.exe
1224 \"/D:\\\\\\\\host\\\\share-name\"
1225 \"LPT1:\"
1226 \"PRN\"
1227
1228 . for lpr or lp
1229 \"share-name\"
1230
1231 This variable should be modified by customization engine. If this variable is
1232 modified by other means (for example, a lisp function), use `pr-update-menus'
1233 function (see it for documentation) to update text printer menu.
1234
1235 Examples:
1236
1237 * On GNU or Unix system:
1238
1239 '((prt_06a \"lpr\" nil \"prt_06a\")
1240 (prt_07c nil nil \"prt_07c\")
1241 )
1242
1243 * On Windows system:
1244
1245 '((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1246 (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
1247 (PRN \"\" nil \"PRN\")
1248 (standard \"redpr.exe\" nil \"\")
1249 )"
1250 :type '(repeat
1251 (list :tag "Text Printer"
1252 (symbol :tag "Printer Symbol Name")
1253 (string :tag "Printer Command")
1254 (repeat :tag "Printer Switches"
1255 (sexp :tag "Switch" :value ""))
1256 (choice :menu-tag "Printer Name"
1257 :tag "Printer Name"
1258 (const :tag "None" nil)
1259 string)))
1260 :set 'pr-alist-custom-set
1261 :group 'printing)
1262
1263
1264 (defcustom pr-ps-name 'default
1265 "*Specify a printer for printing a PostScript file.
1266
1267 This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
1268 documentation).
1269
1270 This variable should be modified by customization engine. If this variable is
1271 modified by other means (for example, a lisp function), use `pr-update-menus'
1272 function (see it for documentation) to update PostScript printer menu."
1273 :type 'symbol
1274 :set 'pr-ps-name-custom-set
1275 :group 'printing)
1276
1277
1278 (defcustom pr-ps-printer-alist
1279 (list (list 'default lpr-command nil
1280 (cond (ps-windows-system nil)
1281 (ps-lp-system "-d")
1282 (t "-P"))
1283 (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
1284 ;; Examples:
1285 ;; * On GNU or Unix system:
1286 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
1287 ;; (lps_07c "lpr" nil nil "lps_07c")
1288 ;; (lps_08c nil nil nil "lps_08c")
1289 ;; )
1290 ;; * On Windows system:
1291 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
1292 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
1293 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
1294 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
1295 ;; (LPT1 "" nil "" "LPT1:")
1296 ;; (PRN "" nil "" "PRN")
1297 ;; (standard "redpr.exe" nil "" "")
1298 ;; )
1299 "*Specify an alist for all PostScript printers (PostScript printer database).
1300
1301 The alist element has the form:
1302
1303 (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
1304
1305 Where:
1306
1307 SYMBOL It's a symbol to identify a PostScript printer. It's for
1308 `pr-ps-name' variable setting and for menu selection.
1309 Examples:
1310 'prt_06a
1311 'my_printer
1312
1313 COMMAND Name of the program for printing a PostScript file. On MS-DOS
1314 and MS-Windows systems, if the value is an empty string then
1315 Emacs will write directly to the printer port given by NAME
1316 (see text below), that is, the NAME should be something like
1317 \"PRN\" or \"LPT1:\".
1318 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1319 COMMAND shouldn't be an empty string.
1320 The programs `print' and `nprint' (the standard print programs
1321 on Windows NT and Novell Netware respectively) are handled
1322 specially, using NAME as the destination for output; any other
1323 program is treated like `lpr' except that an explicit filename
1324 is given as the last argument.
1325 If COMMAND is nil, it's used the default printing program:
1326 `print' for Windows system, `lp' for lp system and `lpr' for
1327 all other systems. See also `pr-path-alist'.
1328 Examples:
1329 \"print\"
1330 \"lpr\"
1331 \"lp\"
1332 \"cp\"
1333
1334 SWITCHES List of sexp's to pass as extra options for PostScript printer
1335 program. It is recommended to set NAME (see text below)
1336 instead of including an explicit switch on this list.
1337 Example:
1338 . for lpr
1339 '(\"-#3\" \"-l\")
1340 nil
1341
1342 PRINTER-SWITCH A string that specifies PostScript printer name switch. If
1343 it's necessary to have a space between PRINTER-SWITCH and NAME,
1344 it should be inserted at the end of PRINTER-SWITCH string.
1345 If PRINTER-SWITCH is nil, it's used the default printer name
1346 switch: `/D:' for Windows system, `-d' for lp system and `-P'
1347 for all other systems.
1348 Examples:
1349 . for lpr
1350 \"-P \"
1351
1352 . for lp
1353 \"-d \"
1354
1355 . for print.exe
1356 \"/D:\"
1357
1358 NAME A string that specifies a PostScript printer name.
1359 On Unix-like systems, a string value should be a name
1360 understood by lpr's -P option (or lp's -d option).
1361 On MS-DOS and MS-Windows systems, it is the name of a printer
1362 device or port. Typical non-default settings would be \"LPT1:\"
1363 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1364 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1365 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1366 printer. You can also set it to a name of a file, in which
1367 case the output gets appended to that file. If you want to
1368 discard the printed output, set this to \"NUL\".
1369 Examples:
1370 . for cp.exe
1371 \"\\\\\\\\host\\\\share-name\"
1372
1373 . for print.exe
1374 \"/D:\\\\\\\\host\\\\share-name\"
1375 \"\\\\\\\\host\\\\share-name\"
1376 \"LPT1:\"
1377 \"PRN\"
1378
1379 . for lpr or lp
1380 \"share-name\"
1381
1382 DEFAULT It's a way to set default values when this entry is selected.
1383 It's a cons like:
1384
1385 (VARIABLE . VALUE)
1386
1387 That associates VARIABLE with VALUE. when this entry is
1388 selected, it's executed the following command:
1389
1390 (set VARIABLE (eval VALUE))
1391
1392 Note that VALUE can be any valid lisp expression. So, don't
1393 forget to quote symbols and constant lists.
1394 If VARIABLE is the special keyword `inherits-from:', VALUE must
1395 be a symbol name setting defined in `pr-setting-database' from
1396 which the current setting inherits the context. Take care with
1397 circular inheritance.
1398 Examples:
1399 '(ps-landscape-mode . nil)
1400 '(ps-spool-duplex . t)
1401 '(pr-gs-device . (my-gs-device t))
1402
1403 This variable should be modified by customization engine. If this variable is
1404 modified by other means (for example, a lisp function), use `pr-update-menus'
1405 function (see it for documentation) to update PostScript printer menu.
1406
1407 Examples:
1408
1409 * On GNU or Unix system:
1410
1411 '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
1412 (lps_07c \"lpr\" nil nil \"lps_07c\")
1413 (lps_08c nil nil nil \"lps_08c\")
1414 )
1415
1416 * On Windows system:
1417
1418 '((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
1419 (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
1420 (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
1421 (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
1422 (LPT1 \"\" nil \"\" \"LPT1:\")
1423 (PRN \"\" nil \"\" \"PRN\")
1424 (standard \"redpr.exe\" nil \"\" \"\")
1425 )"
1426 :type '(repeat
1427 (list
1428 :tag "PostScript Printer"
1429 (symbol :tag "Printer Symbol Name")
1430 (string :tag "Printer Command")
1431 (repeat :tag "Printer Switches"
1432 (sexp :tag "Switch" :value ""))
1433 (choice :menu-tag "Printer Name Switch"
1434 :tag "Printer Name Switch"
1435 (const :tag "None" nil)
1436 string)
1437 (choice :menu-tag "Printer Name"
1438 :tag "Printer Name"
1439 (const :tag "None" nil)
1440 string)
1441 (repeat
1442 :tag "Default Value List"
1443 :inline t
1444 (cons
1445 :tag ""
1446 (choice
1447 :menu-tag "Variable"
1448 :tag "Variable"
1449 (const :tag "Landscape" ps-landscape-mode)
1450 (const :tag "Print Header" ps-print-header)
1451 (const :tag "Print Header Frame" ps-print-header-frame)
1452 (const :tag "Line Number" ps-line-number)
1453 (const :tag "Zebra Stripes" ps-zebra-stripes)
1454 (const :tag "Duplex" ps-spool-duplex)
1455 (const :tag "Tumble" ps-spool-tumble)
1456 (const :tag "Upside-Down" ps-print-upside-down)
1457 (const :tag "PS File Landscape" pr-file-landscape)
1458 (const :tag "PS File Duplex" pr-file-duplex)
1459 (const :tag "PS File Tumble" pr-file-tumble)
1460 (const :tag "Auto Region" pr-auto-region)
1461 (const :tag "Auto Mode" pr-auto-mode)
1462 (const :tag "Ghostscript Device" pr-gs-device)
1463 (const :tag "Ghostscript Resolution" pr-gs-resolution)
1464 (const :tag "inherits-from:" inherits-from:)
1465 (variable :tag "Other"))
1466 (sexp :tag "Value")))
1467 ))
1468 :set 'pr-alist-custom-set
1469 :group 'printing)
1470
1471
1472 (defcustom pr-temp-dir
1473 (pr-dosify-path
1474 (if (boundp 'temporary-file-directory)
1475 (symbol-value 'temporary-file-directory)
1476 ;; hacked from `temporary-file-directory' variable in files.el
1477 (file-name-as-directory
1478 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
1479 (cond (ps-windows-system "c:/temp")
1480 ((memq system-type '(vax-vms axp-vms)) "SYS$SCRATCH:")
1481 (t "/tmp")
1482 )))))
1483 "*Specify a directory for temporary files during printing."
1484 :type '(directory :tag "Temporary Directory")
1485 :group 'printing)
1486
1487
1488 (defcustom pr-ps-temp-file "prspool.ps"
1489 "*Specify PostScript temporary file name."
1490 :type '(file :tag "PostScript Temporary File Name")
1491 :group 'printing)
1492
1493
1494 (defcustom pr-gv-command
1495 (if ps-windows-system
1496 "gsview32.exe"
1497 "gv")
1498 "*Specify path and name of the gsview/gv utility.
1499
1500 See also `pr-path-alist'."
1501 :type '(string :tag "Ghostview Utility")
1502 :group 'printing)
1503
1504
1505 (defcustom pr-gs-command
1506 (if ps-windows-system
1507 "gswin32.exe"
1508 "gs")
1509 "*Specify path and name of the ghostscript utility.
1510
1511 See also `pr-path-alist'."
1512 :type '(string :tag "Ghostscript Utility")
1513 :group 'printing)
1514
1515
1516 (defcustom pr-gs-switches
1517 (if ps-windows-system
1518 '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
1519 '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
1520 "*Specify ghostscript switches. See the documentation on GS for more info.
1521
1522 It's a list of strings, where each string is one or more ghostscript switches.
1523
1524 A note on the gs switches:
1525
1526 -q quiet
1527 -dNOPAUSE don't wait for user intervention
1528 -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
1529 -c quit it's added at the end to terminate gs
1530
1531 To see ghostscript documentation for more information:
1532
1533 * On GNU or Unix system:
1534 - for full documentation, type: man gs
1535 - for brief documentation, type: gs -h
1536
1537 * On Windows system:
1538 - for full documentation, see in a browser the file
1539 c:/gstools/gs5.50/index.html, that is, the file index.html which is
1540 located in the same directory as gswin32.exe.
1541 - for brief documentation, type: gswin32.exe -h"
1542 :type '(repeat (string :tag "Ghostscript Switch"))
1543 :group 'printing)
1544
1545
1546 (defcustom pr-gs-device
1547 (if ps-windows-system
1548 "mswinpr2"
1549 "uniprint")
1550 "*Specify the ghostscript device switch value (-sDEVICE=).
1551
1552 A note on the gs switches:
1553
1554 -sDEVICE=djet500 the printer - works with HP DeskJet 540
1555
1556 See `pr-gs-switches' for documentation.
1557 See also `pr-ps-printer-alist'."
1558 :type '(string :tag "Ghostscript Device")
1559 :group 'printing)
1560
1561
1562 (defcustom pr-gs-resolution 300
1563 "*Specify ghostscript resolution switch value (-r).
1564
1565 A note on the gs switches:
1566
1567 -r300 resolution 300x300
1568
1569 See `pr-gs-switches' for documentation.
1570 See also `pr-ps-printer-alist'."
1571 :type '(integer :tag "Ghostscript Resolution")
1572 :group 'printing)
1573
1574
1575 (defcustom pr-print-using-ghostscript nil
1576 "*Non-nil means print using ghostscript.
1577
1578 This is useful if you don't have a PostScript printer, so you could use the
1579 ghostscript to print a PostScript file.
1580
1581 In GNU or Unix system, if ghostscript is set as a PostScript filter, this
1582 variable should be nil."
1583 :type 'boolean
1584 :group 'printing)
1585
1586
1587 (defcustom pr-faces-p nil
1588 "*Non-nil means print with face attributes."
1589 :type 'boolean
1590 :group 'printing)
1591
1592
1593 (defcustom pr-spool-p nil
1594 "*Non-nil means spool printing in a buffer."
1595 :type 'boolean
1596 :group 'printing)
1597
1598
1599 (defcustom pr-file-landscape nil
1600 "*Non-nil means print PostScript file in landscape orientation."
1601 :type 'boolean
1602 :group 'printing)
1603
1604
1605 (defcustom pr-file-duplex nil
1606 "*Non-nil means print PostScript file in duplex mode."
1607 :type 'boolean
1608 :group 'printing)
1609
1610
1611 (defcustom pr-file-tumble nil
1612 "*Non-nil means print PostScript file in tumble mode.
1613
1614 If tumble is off, produces a printing suitable for binding on the left or
1615 right.
1616 If tumble is on, produces a printing suitable for binding at the top or
1617 bottom."
1618 :type 'boolean
1619 :group 'printing)
1620
1621
1622 (defcustom pr-auto-region t
1623 "*Non-nil means region is automagically detected.
1624
1625 Note that this will only work if you're using transient mark mode.
1626
1627 When this variable is non-nil, the `*-buffer*' commands will behave like
1628 `*-region*' commands, that is, `*-buffer*' commands will print only the region
1629 marked instead of all buffer."
1630 :type 'boolean
1631 :group 'printing)
1632
1633
1634 (defcustom pr-auto-mode t
1635 "*Non-nil means major-mode specific printing is prefered over normal printing.
1636
1637 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
1638 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
1639 `*-buffer*' commands will print the current buffer and `*-region*' commands
1640 will print the current region."
1641 :type 'boolean
1642 :group 'printing)
1643
1644
1645 (defcustom pr-mode-alist
1646 '((mh-folder-mode ; mh summary buffer
1647 pr-mh-lpr-1 pr-mh-print-1
1648 2
1649 (ps-article-author ps-article-subject)
1650 ("/pagenumberstring load" pr-article-date)
1651 nil
1652 )
1653 (mh-letter-mode ; mh letter buffer
1654 pr-mh-lpr-2 pr-mh-print-2
1655 2
1656 (ps-article-author ps-article-subject)
1657 ("/pagenumberstring load" pr-article-date)
1658 nil
1659 )
1660 (rmail-summary-mode ; rmail summary buffer
1661 pr-rmail-lpr pr-rmail-print
1662 3
1663 (ps-article-subject ps-article-author buffer-name)
1664 nil
1665 nil
1666 )
1667 (rmail-mode ; rmail buffer
1668 pr-rmail-lpr pr-rmail-print
1669 3
1670 (ps-article-subject ps-article-author buffer-name)
1671 nil
1672 nil
1673 )
1674 (gnus-summary-mode ; gnus summary buffer
1675 pr-gnus-lpr pr-gnus-print
1676 3
1677 (ps-article-subject ps-article-author gnus-newsgroup-name)
1678 nil
1679 nil
1680 )
1681 (gnus-article-mode ; gnus article buffer
1682 pr-gnus-lpr pr-gnus-print
1683 3
1684 (ps-article-subject ps-article-author gnus-newsgroup-name)
1685 nil
1686 nil
1687 )
1688 (Info-mode ; Info buffer
1689 pr-mode-lpr pr-mode-print
1690 2
1691 (ps-info-node ps-info-file)
1692 nil
1693 nil
1694 )
1695 (vm-mode ; vm mode
1696 pr-vm-lpr pr-vm-print
1697 3
1698 (ps-article-subject ps-article-author buffer-name)
1699 nil
1700 nil
1701 )
1702 )
1703 "*Specify an alist for a major-mode and printing functions.
1704
1705 To customize a major mode printing, just declare the customization in
1706 `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
1707 mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
1708 *Summary* buffer, if you forget to switch to the *Article* buffer before
1709 printing, you'll get a nicely formatted list of article subjects shows up at
1710 the printer. With major mode printing you don't need to switch from gnus
1711 *Summary* buffer first.
1712
1713 The elements have the following form:
1714
1715 (MAJOR-MODE
1716 LPR-PRINT PS-PRINT
1717 HEADER-LINES
1718 LEFT-HEADER
1719 RIGHT-HEADER
1720 KILL-LOCAL-VARIABLE
1721 DEFAULT...)
1722
1723 Where:
1724
1725 MAJOR-MODE It's the major mode symbol.
1726
1727 LPR-PRINT It's a symbol function for text printing. It's invoked with
1728 one argument:
1729 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
1730
1731 Usually LPR-PRINT function prepares the environment or buffer
1732 and then call the function `pr-mode-lpr' which it's used to
1733 process the buffer and send it to text printer.
1734
1735 The `pr-mode-lpr' definition is:
1736
1737 (pr-mode-lpr HEADER-LIST &optional FROM TO)
1738
1739 Where HEADER-LIST is like the argument passed to LPR-PRINT.
1740 FROM and TO are the beginning and end markers, respectively,
1741 for a region. If FROM is nil, it's used (point-min); if TO is
1742 nil, it's used (point-max).
1743
1744 PS-PRINT It's a symbol function for PostScript printing. It's invoked
1745 with 3 arguments: n-up printing, file name and the list:
1746 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
1747
1748 Usually PS-PRINT function prepares the environment or buffer
1749 and then call the function `pr-mode-print' which it's used to
1750 process the buffer and send it to PostScript printer.
1751
1752 The `pr-mode-print' definition is:
1753
1754 (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
1755
1756 Where N-UP, FILENAME and HEADER-LIST are like the arguments
1757 passed to PS-PRINT. FROM and TO are the beginning and end
1758 markers, respectively, for a region. If TO is nil, it's used
1759 (point-max).
1760
1761 HEADER-LINES It's the number of header lines; if is nil, it uses
1762 `ps-header-lines' value.
1763
1764 LEFT-HEADER It's the left header part, it's a list of string, variable
1765 symbol or function symbol (with no argument); if is nil, it
1766 uses `ps-left-header' value.
1767
1768 RIGHT-HEADER It's the right header part, it's a list of string, variable
1769 symbol or function symbol (with no argument); if is nil, it
1770 uses `ps-right-header' value.
1771
1772 KILL-LOCAL-VARIABLE
1773 Non-nil means to kill all buffer local variable declared in
1774 DEFAULT (see below).
1775
1776 DEFAULT It's a way to set default values when this entry is selected.
1777 It's a cons like:
1778
1779 (VARIABLE-SYM . VALUE)
1780
1781 That associates VARIABLE-SYM with VALUE. when this entry is
1782 selected, it's executed the following command:
1783
1784 (set (make-local-variable VARIABLE-SYM) (eval VALUE))
1785
1786 Note that VALUE can be any valid lisp expression. So, don't
1787 forget to quote symbols and constant lists.
1788 If VARIABLE is the special keyword `inherits-from:', VALUE must
1789 be a symbol name setting defined in `pr-setting-database' from
1790 which the current setting inherits the context. Take care with
1791 circular inheritance.
1792 Examples:
1793 '(ps-landscape-mode . nil)
1794 '(ps-spool-duplex . t)
1795 '(pr-gs-device . (my-gs-device t))"
1796 :type '(repeat
1797 (list
1798 :tag ""
1799 (symbol :tag "Major Mode")
1800 (function :tag "Text Printing Function")
1801 (function :tag "PS Printing Function")
1802 (choice :menu-tag "Number of Header Lines"
1803 :tag "Number of Header Lines"
1804 (integer :tag "Number")
1805 (const :tag "Default Number" nil))
1806 (repeat :tag "Left Header List"
1807 (choice :menu-tag "Left Header"
1808 :tag "Left Header"
1809 string symbol))
1810 (repeat :tag "Right Header List"
1811 (choice :menu-tag "Right Header"
1812 :tag "Right Header"
1813 string symbol))
1814 (boolean :tag "Kill Local Variable At End")
1815 (repeat
1816 :tag "Default Value List"
1817 :inline t
1818 (cons
1819 :tag ""
1820 (choice
1821 :menu-tag "Variable"
1822 :tag "Variable"
1823 (const :tag "Landscape" ps-landscape-mode)
1824 (const :tag "Print Header" ps-print-header)
1825 (const :tag "Print Header Frame" ps-print-header-frame)
1826 (const :tag "Line Number" ps-line-number)
1827 (const :tag "Zebra Stripes" ps-zebra-stripes)
1828 (const :tag "Duplex" ps-spool-duplex)
1829 (const :tag "Tumble" ps-spool-tumble)
1830 (const :tag "Upside-Down" ps-print-upside-down)
1831 (const :tag "PS File Landscape" pr-file-landscape)
1832 (const :tag "PS File Duplex" pr-file-duplex)
1833 (const :tag "PS File Tumble" pr-file-tumble)
1834 (const :tag "Auto Region" pr-auto-region)
1835 (const :tag "Auto Mode" pr-auto-mode)
1836 (const :tag "Ghostscript Device" pr-gs-device)
1837 (const :tag "Ghostscript Resolution" pr-gs-resolution)
1838 (const :tag "inherits-from:" inherits-from:)
1839 (variable :tag "Other"))
1840 (sexp :tag "Value")))
1841 ))
1842 :group 'printing)
1843
1844
1845 (defcustom pr-ps-utility 'mpage
1846 "*Specify PostScript utility symbol.
1847
1848 This utility symbol should be defined on `pr-ps-utility-alist' (see it for
1849 documentation).
1850
1851 This variable should be modified by customization engine. If this variable is
1852 modified by other means (for example, a lisp function), use `pr-update-menus'
1853 function (see it for documentation) to update PostScript utility menu.
1854
1855 NOTE: Don't forget to download and install the utilities declared on
1856 `pr-ps-utility-alist'."
1857 :type '(symbol :tag "PS File Utility")
1858 :set 'pr-ps-utility-custom-set
1859 :group 'printing)
1860
1861
1862 (defcustom pr-ps-utility-alist
1863 '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
1864 (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
1865 (inherits-from: . no-duplex))
1866 )
1867 ;; Examples:
1868 ;; * On GNU or Unix system:
1869 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
1870 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
1871 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
1872 ;; )
1873 ;; * On Windows system:
1874 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
1875 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
1876 ;; )
1877 "*Specify an alist for PostScript utility processing (PS utility database).
1878
1879 The alist element has the form:
1880
1881 (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
1882 SWITCHES DEFAULT...)
1883
1884 Where:
1885
1886 SYMBOL It's a symbol to identify a PostScript utility. It's for
1887 `pr-ps-utility' variable setting and for menu selection.
1888 Examples:
1889 'mpage
1890 'psnup
1891
1892 UTILITY Name of utility for processing a PostScript file.
1893 See also `pr-path-alist'.
1894 Examples:
1895 . for GNU or Unix system:
1896 \"mpage\"
1897 \"psnup -q\"
1898
1899 . for Windows system:
1900 \"c:/psutils/psnup -q\"
1901
1902 MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
1903 program. These options are necessary to process the utility
1904 program and must be placed before any other switches.
1905 Example:
1906 . for psnup:
1907 '(\"-q\")
1908
1909 PAPERSIZE It's a format string to specify paper size switch.
1910 Example:
1911 . for mpage
1912 \"-b%s\"
1913
1914 N-UP It's a format string to specify n-up switch.
1915 Example:
1916 . for psnup
1917 \"-%d\"
1918
1919 LANDSCAPE It's a string to specify landscape switch. If the utility
1920 doesn't have landscape switch, set to nil.
1921 Example:
1922 . for psnup
1923 \"-l\"
1924
1925 DUPLEX It's a string to specify duplex switch. If the utility doesn't
1926 have duplex switch, set to nil.
1927 Example:
1928 . for psnup
1929 nil
1930
1931 TUMBLE It's a string to specify tumble switch. If the utility doesn't
1932 have tumble switch, set to nil.
1933 Example:
1934 . for psnup
1935 nil
1936
1937 OUTPUT It's a string to specify how to generate an output file. Some
1938 utilities accept an output file option, but some others need
1939 output redirection or some other way to specify an output file.
1940 Example:
1941 . for psnup
1942 \" \" ; psnup ... input output
1943
1944 . for mpage
1945 \">\" ; mpage ... input > output
1946
1947 SWITCHES List of sexp's to pass as extra options to the PostScript utility
1948 program.
1949 Example:
1950 . for psnup
1951 '(\"-q\")
1952 nil
1953
1954 DEFAULT It's a way to set default values when this entry is selected.
1955 It's a cons like:
1956
1957 (VARIABLE . VALUE)
1958
1959 That associates VARIABLE with VALUE. when this entry is
1960 selected, it's executed the following command:
1961
1962 (set VARIABLE (eval VALUE))
1963
1964 Note that VALUE can be any valid lisp expression. So, don't
1965 forget to quote symbols and constant lists.
1966 If VARIABLE is the special keyword `inherits-from:', VALUE must
1967 be a symbol name setting defined in `pr-setting-database' from
1968 which the current setting inherits the context. Take care with
1969 circular inheritance.
1970 Examples:
1971 '(pr-file-landscape . nil)
1972 '(pr-file-duplex . t)
1973 '(pr-gs-device . (my-gs-device t))
1974
1975 This variable should be modified by customization engine. If this variable is
1976 modified by other means (for example, a lisp function), use `pr-update-menus'
1977 function (see it for documentation) to update PostScript utility menu.
1978
1979 NOTE: Don't forget to download and install the utilities declared on
1980 `pr-ps-utility-alist'.
1981
1982 Examples:
1983
1984 * On GNU or Unix system:
1985
1986 '((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
1987 (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
1988 (pr-file-duplex . nil) (pr-file-tumble . nil))
1989 )
1990
1991 * On Windows system:
1992
1993 '((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
1994 nil (pr-file-duplex . nil) (pr-file-tumble . nil))
1995 )"
1996 :type '(repeat
1997 (list :tag "PS File Utility"
1998 (symbol :tag "Utility Symbol")
1999 (string :tag "Utility Name")
2000 (repeat :tag "Must Utility Switches"
2001 (sexp :tag "Switch" :value ""))
2002 (choice :menu-tag "Paper Size"
2003 :tag "Paper Size"
2004 (const :tag "No Paper Size" nil)
2005 (string :tag "Paper Size Format"))
2006 (choice :menu-tag "N-Up"
2007 :tag "N-Up"
2008 (const :tag "No N-Up" nil)
2009 (string :tag "N-Up Format"))
2010 (choice :menu-tag "Landscape"
2011 :tag "Landscape"
2012 (const :tag "No Landscape" nil)
2013 (string :tag "Landscape Switch"))
2014 (choice :menu-tag "Duplex"
2015 :tag "Duplex"
2016 (const :tag "No Duplex" nil)
2017 (string :tag "Duplex Switch"))
2018 (choice :menu-tag "Tumble"
2019 :tag "Tumble"
2020 (const :tag "No Tumble" nil)
2021 (string :tag "Tumble Switch"))
2022 (string :tag "Output Separator")
2023 (repeat :tag "Utility Switches"
2024 (sexp :tag "Switch" :value ""))
2025 (repeat
2026 :tag "Default Value List"
2027 :inline t
2028 (cons
2029 :tag ""
2030 (choice
2031 :menu-tag "Variable"
2032 :tag "Variable"
2033 (const :tag "PS File Landscape" pr-file-landscape)
2034 (const :tag "PS File Duplex" pr-file-duplex)
2035 (const :tag "PS File Tumble" pr-file-tumble)
2036 (const :tag "Ghostscript Device" pr-gs-device)
2037 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2038 (const :tag "inherits-from:" inherits-from:)
2039 (variable :tag "Other"))
2040 (sexp :tag "Value")))
2041 ))
2042 :set 'pr-alist-custom-set
2043 :group 'printing)
2044
2045
2046 (defcustom pr-menu-lock t
2047 "*Non-nil means menu is locked while selecting toggle options.
2048
2049 See also `pr-menu-char-height' and `pr-menu-char-width'."
2050 :type 'boolean
2051 :group 'printing)
2052
2053
2054 (defcustom pr-menu-char-height
2055 (cond ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2056 (pr-e-frame-char-height))
2057 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2058 (pr-x-font-height (face-font 'default))))
2059 "*Specify menu char height in pixels.
2060
2061 This variable is used to guess which vertical position should be locked the
2062 menu, so don't forget to adjust it if menu position is not ok.
2063
2064 See also `pr-menu-lock' and `pr-menu-char-width'."
2065 :type 'integer
2066 :group 'printing)
2067
2068
2069 (defcustom pr-menu-char-width
2070 (cond ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2071 (pr-e-frame-char-width))
2072 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2073 (pr-x-font-width (face-font 'default))))
2074 "*Specify menu char width in pixels.
2075
2076 This variable is used to guess which horizontal position should be locked the
2077 menu, so don't forget to adjust it if menu position is not ok.
2078
2079 See also `pr-menu-lock' and `pr-menu-char-height'."
2080 :type 'integer
2081 :group 'printing)
2082
2083
2084 (defcustom pr-setting-database
2085 '((no-duplex ; setting symbol name
2086 nil nil nil ; inherits local kill-local
2087 (pr-file-duplex . nil) ; settings
2088 (pr-file-tumble . nil))
2089 )
2090 "*Specify an alist for settings in general.
2091
2092 The elements have the following form:
2093
2094 (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
2095
2096 Where:
2097
2098 SYMBOL It's a symbol to identify the setting group.
2099
2100 INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
2101 setting from which the current setting inherits the context.
2102 If INHERITS is nil, means that there is no inheritance.
2103 This is a simple inheritance mechanism.
2104
2105 Let's see an example to illustrate the inheritance mechanism:
2106
2107 (setq pr-setting-database
2108 '((no-duplex ; setting symbol name
2109 nil ; inherits
2110 nil nil ; local kill-local
2111 (pr-file-duplex . nil) ; settings
2112 (pr-file-tumble . nil)
2113 )
2114 (no-duplex-and-landscape ; setting symbol name
2115 no-duplex ; inherits
2116 nil nil ; local kill-local
2117 (pr-file-landscape . nil) ; settings
2118 )))
2119
2120 The example above has two setting groups: no-duplex and
2121 no-duplex-and-landscape. When setting no-duplex is activated
2122 through `inherits-from:' (see `pr-ps-utility', `pr-mode-alist'
2123 and `pr-ps-printer-alist'), the variables pr-file-duplex and
2124 pr-file-tumble are both set to nil.
2125
2126 Now when setting no-duplex-and-landscape is activated through
2127 `inherits-from:', the variable pr-file-landscape is set to nil
2128 and also the settings for no-duplex are done, because
2129 no-duplex-and-landscape inherits settings from no-duplex.
2130
2131 Take care with circular inheritance. It's an error if circular
2132 inheritance happens.
2133
2134 LOCAL Non-nil means that all settings for SYMBOL group will be
2135 declared local buffer.
2136
2137 KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
2138 killed at end. It has effect only when LOCAL is non-nil.
2139
2140 SETTING It's a cons like:
2141
2142 (VARIABLE . VALUE)
2143
2144 That associates VARIABLE with VALUE. when this entry is
2145 selected, it's executed the following command:
2146
2147 * If LOCAL is non-nil:
2148 (set (make-local-variable VARIABLE) (eval VALUE))
2149
2150 * If LOCAL is nil:
2151 (set VARIABLE (eval VALUE))
2152
2153 Note that VALUE can be any valid lisp expression. So, don't
2154 forget to quote symbols and constant lists.
2155 This setting is ignored if VARIABLE is equal to keyword
2156 `inherits-from:'.
2157 Examples:
2158 '(ps-landscape-mode . nil)
2159 '(ps-spool-duplex . t)
2160 '(pr-gs-device . (my-gs-device t))"
2161 :type '(repeat
2162 (list
2163 :tag ""
2164 (symbol :tag "Setting Name")
2165 (choice :menu-tag "Inheritance"
2166 :tag "Inheritance"
2167 (const :tag "No Inheritance" nil)
2168 (symbol :tag "Inherits From"))
2169 (boolean :tag "Local Buffer Setting")
2170 (boolean :tag "Kill Local Variable At End")
2171 (repeat
2172 :tag "Setting List"
2173 :inline t
2174 (cons
2175 :tag ""
2176 (choice
2177 :menu-tag "Variable"
2178 :tag "Variable"
2179 (const :tag "Landscape" ps-landscape-mode)
2180 (const :tag "Print Header" ps-print-header)
2181 (const :tag "Print Header Frame" ps-print-header-frame)
2182 (const :tag "Line Number" ps-line-number)
2183 (const :tag "Zebra Stripes" ps-zebra-stripes)
2184 (const :tag "Duplex" ps-spool-duplex)
2185 (const :tag "Tumble" ps-spool-tumble)
2186 (const :tag "Upside-Down" ps-print-upside-down)
2187 (const :tag "PS File Landscape" pr-file-landscape)
2188 (const :tag "PS File Duplex" pr-file-duplex)
2189 (const :tag "PS File Tumble" pr-file-tumble)
2190 (const :tag "Auto Region" pr-auto-region)
2191 (const :tag "Auto Mode" pr-auto-mode)
2192 (const :tag "Ghostscript Device" pr-gs-device)
2193 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2194 (variable :tag "Other"))
2195 (sexp :tag "Value")))
2196 ))
2197 :group 'printing)
2198
2199
2200 (defcustom pr-visible-entry-list
2201 '(postscript text postscript-options postscript-process printing help)
2202 "*Specify a list of Printing menu visible entries.
2203
2204 Valid values with the corresponding menu parts are:
2205
2206 +------------------------------+
2207 | Printing Interface |
2208 +------------------------------+
2209 `postscript' | PostScript Preview >|
2210 | PostScript Print >|
2211 | PostScript Printer: name >|
2212 +------------------------------+
2213 `text' | Printify >|
2214 | Print >|
2215 | Text Printer: name >|
2216 +------------------------------+
2217 `postscript-options' |[ ] Landscape |
2218 |[ ] Print Header |
2219 |[ ] Print Header Frame |
2220 |[ ] Line Number |
2221 |[ ] Zebra Stripes |
2222 |[ ] Duplex |
2223 |[ ] Tumble |
2224 |[ ] Upside-Down |
2225 | Print All Pages >|
2226 +------------------------------+
2227 `postscript-process' |[ ] Spool Buffer |
2228 |[ ] Print with faces |
2229 |[ ] Print via Ghostscript |
2230 +------------------------------+
2231 `printing' |[ ] Auto Region |
2232 |[ ] Auto Mode |
2233 |[ ] Menu Lock |
2234 +------------------------------+
2235 `help' | Customize >|
2236 | Show Settings >|
2237 | Help |
2238 +------------------------------+
2239
2240 Any other value is ignored."
2241 :type '(repeat :tag "Menu Visible Part"
2242 (choice :menu-tag "Menu Part"
2243 :tag "Menu Part"
2244 (const postscript)
2245 (const text)
2246 (const postscript-options)
2247 (const postscript-process)
2248 (const printing)
2249 (const help)))
2250 :group 'printing)
2251
2252
2253 (defcustom pr-delete-temp-file t
2254 "*Non-nil means delete temporary files.
2255
2256 Set `pr-delete-temp-file' to nil, if the following message (or a similar)
2257 happens when printing:
2258
2259 Error: could not open \"c:\\temp\\prspool.ps\" for reading."
2260 :type 'boolean
2261 :group 'printing)
2262
2263
2264 (defcustom pr-list-directory nil
2265 "*Non-nil means list directory when processing a directory.
2266
2267 That is, any subdirectories (and the superdirectory) of the directory (given as
2268 argument of functions below) are also printed (as dired-mode listings).
2269
2270 It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
2271 `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
2272 and `pr-txt-directory'."
2273 :type 'boolean
2274 :group 'printing)
2275
2276
2277 (defcustom pr-buffer-name "*Printing Interface*"
2278 "*Specify the name of the buffer interface for printing package.
2279
2280 It's used by `pr-interface'."
2281 :type 'string
2282 :group 'printing)
2283
2284
2285 (defcustom pr-buffer-name-ignore
2286 (list (regexp-quote pr-buffer-name) ; ignore printing interface buffer
2287 "^ .*$") ; ignore invisible buffers
2288 "*Specify a regexp list for buffer names to be ignored in interface buffer.
2289
2290 NOTE: Case is important for matching, that is, `case-fold-search' is always
2291 nil.
2292
2293 It's used by `pr-interface'."
2294 :type '(repeat (regexp :tag "Buffer Name Regexp"))
2295 :group 'printing)
2296
2297
2298 (defcustom pr-buffer-verbose t
2299 "*Non-nil means to be verbose when editing a field in interface buffer.
2300
2301 It's used by `pr-interface'."
2302 :type 'boolean
2303 :group 'printing)
2304
2305
2306 (defcustom pr-shell-file-name
2307 (if (eq pr-path-style 'windows)
2308 "cmdproxy.exe"
2309 shell-file-name)
2310 "*Specify file name to load inferior shells from."
2311 :type 'string
2312 :group 'printing)
2313
2314
2315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2316 ;; Internal Variables
2317
2318
2319 (defvar pr-txt-command nil
2320 "Name of program for printing a text file.
2321 See `pr-txt-printer-alist'.")
2322
2323
2324 (defvar pr-txt-switches nil
2325 "List of sexp's to pass as extra options to the text printer program.
2326 See `pr-txt-printer-alist'.")
2327
2328
2329 (defvar pr-txt-printer nil
2330 "Specify text printer name.
2331 See `pr-txt-printer-alist'.")
2332
2333
2334 (defvar pr-ps-command nil
2335 "Name of program for printing a PostScript file.
2336 See `pr-ps-printer-alist'.")
2337
2338
2339 (defvar pr-ps-switches nil
2340 "List of sexp's to pass as extra options to the PostScript printer program.
2341 See `pr-ps-printer-alist'.")
2342
2343
2344 (defvar pr-ps-printer-switch nil
2345 "Specify PostScript printer name switch.
2346 See `pr-ps-printer-alist'.")
2347
2348
2349 (defvar pr-ps-printer nil
2350 "Specify PostScript printer name.
2351 See `pr-ps-printer-alist'.")
2352
2353
2354 (defvar pr-menu-bar nil
2355 "Specify Printing menu-bar entry.")
2356
2357
2358 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2359 ;; Keys & Menus
2360
2361
2362 (defmacro pr-xemacs-global-menubar (&rest body)
2363 `(save-excursion
2364 (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
2365 ;; be sure to access global menubar
2366 (set-buffer temp)
2367 ,@body
2368 (kill-buffer temp))))
2369
2370
2371 (defsubst pr-visible-p (key)
2372 (memq key pr-visible-entry-list))
2373
2374
2375 (defsubst pr-mode-alist-p ()
2376 (cdr (assq major-mode pr-mode-alist)))
2377
2378
2379 (defsubst pr-auto-mode-p ()
2380 (and pr-auto-mode (pr-mode-alist-p)))
2381
2382
2383 (defsubst pr-using-ghostscript-p ()
2384 (and pr-print-using-ghostscript (not pr-spool-p)))
2385
2386
2387 (eval-and-compile
2388 (defun pr-get-symbol (name)
2389 ;; Recent versions of easy-menu downcase names before interning them.
2390 (and (fboundp 'easy-menu-name-match)
2391 (setq name (downcase name)))
2392 (or (intern-soft name)
2393 (make-symbol name)))
2394
2395 (cond
2396 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2397 (defsubst pr-region-active-p ()
2398 (and pr-auto-region transient-mark-mode mark-active)))
2399
2400 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2401 (defsubst pr-region-active-p ()
2402 (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p)))))
2403
2404
2405 (defconst pr-menu-spec
2406 (cond
2407 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2408 '(
2409 ["Printing Interface" pr-interface
2410 :help "Use buffer interface instead of menu interface"]
2411 "--"
2412 ("PostScript Preview" :visible (pr-visible-p 'postscript)
2413 :help "Preview PostScript instead of sending to printer"
2414 ("Directory" :active (not pr-spool-p)
2415 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
2416 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
2417 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
2418 ["Other..." (pr-ps-directory-preview nil nil nil t)
2419 :keys "\\[pr-ps-buffer-preview]"])
2420 ("Buffer" :active (not pr-spool-p)
2421 ["1-up" (pr-ps-buffer-preview 1 t) t]
2422 ["2-up" (pr-ps-buffer-preview 2 t) t]
2423 ["4-up" (pr-ps-buffer-preview 4 t) t]
2424 ["Other..." (pr-ps-buffer-preview nil t)
2425 :keys "\\[pr-ps-buffer-preview]"])
2426 ("Region" :active (and (not pr-spool-p) (ps-mark-active-p))
2427 ["1-up" (pr-ps-region-preview 1 t) t]
2428 ["2-up" (pr-ps-region-preview 2 t) t]
2429 ["4-up" (pr-ps-region-preview 4 t) t]
2430 ["Other..." (pr-ps-region-preview nil t)
2431 :keys "\\[pr-ps-region-preview]"])
2432 ("Mode" :active (and (not pr-spool-p) (pr-mode-alist-p))
2433 ["1-up" (pr-ps-mode-preview 1 t) t]
2434 ["2-up" (pr-ps-mode-preview 2 t) t]
2435 ["4-up" (pr-ps-mode-preview 4 t) t]
2436 ["Other..." (pr-ps-mode-preview nil t)
2437 :keys "\\[pr-ps-mode-preview]"])
2438 ("File"
2439 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
2440 :keys "\\[pr-ps-file-preview]"
2441 :help "Preview PostScript file"]
2442 "--"
2443 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2444 :help "Select PostScript utility"]
2445 "--"
2446 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
2447 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
2448 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
2449 ["Other..." (pr-ps-file-up-preview nil t t)
2450 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
2451 "--"
2452 ["Landscape" pr-toggle-file-landscape
2453 :style toggle :selected pr-file-landscape
2454 :help "Toggle landscape for PostScript file"
2455 :active pr-ps-utility-alist]
2456 ["Duplex" pr-toggle-file-duplex
2457 :style toggle :selected pr-file-duplex
2458 :help "Toggle duplex for PostScript file"
2459 :active pr-ps-utility-alist]
2460 ["Tumble" pr-toggle-file-tumble
2461 :style toggle :selected pr-file-tumble
2462 :help "Toggle tumble for PostScript file"
2463 :active (and pr-file-duplex pr-ps-utility-alist)])
2464 ["Despool..." (call-interactively 'pr-despool-preview)
2465 :active pr-spool-p :keys "\\[pr-despool-preview]"
2466 :help "Despool PostScript buffer to printer or file (C-u)"])
2467 ("PostScript Print" :visible (pr-visible-p 'postscript)
2468 :help "Send PostScript to printer or file (C-u)"
2469 ("Directory"
2470 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
2471 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
2472 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
2473 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
2474 :keys "\\[pr-ps-buffer-ps-print]"])
2475 ("Buffer"
2476 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
2477 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
2478 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
2479 ["Other..." (pr-ps-buffer-ps-print nil t)
2480 :keys "\\[pr-ps-buffer-ps-print]"])
2481 ("Region" :active (ps-mark-active-p)
2482 ["1-up" (pr-ps-region-ps-print 1 t) t]
2483 ["2-up" (pr-ps-region-ps-print 2 t) t]
2484 ["4-up" (pr-ps-region-ps-print 4 t) t]
2485 ["Other..." (pr-ps-region-ps-print nil t)
2486 :keys "\\[pr-ps-region-ps-print]"])
2487 ("Mode" :active (pr-mode-alist-p)
2488 ["1-up" (pr-ps-mode-ps-print 1 t) t]
2489 ["2-up" (pr-ps-mode-ps-print 2 t) t]
2490 ["4-up" (pr-ps-mode-ps-print 4 t) t]
2491 ["Other..." (pr-ps-mode-ps-print nil t)
2492 :keys "\\[pr-ps-mode-ps-print]"])
2493 ("File"
2494 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
2495 :keys "\\[pr-ps-file-ps-print]"
2496 :help "Send PostScript file to printer"]
2497 "--"
2498 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2499 :help "Select PostScript utility"]
2500 "--"
2501 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
2502 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
2503 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
2504 ["Other..." (pr-ps-file-up-ps-print nil t t)
2505 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
2506 "--"
2507 ["Landscape" pr-toggle-file-landscape
2508 :style toggle :selected pr-file-landscape
2509 :help "Toggle landscape for PostScript file"
2510 :active pr-ps-utility-alist]
2511 ["Duplex" pr-toggle-file-duplex
2512 :style toggle :selected pr-file-duplex
2513 :help "Toggle duplex for PostScript file"
2514 :active pr-ps-utility-alist]
2515 ["Tumble" pr-toggle-file-tumble
2516 :style toggle :selected pr-file-tumble
2517 :help "Toggle tumble for PostScript file"
2518 :active (and pr-file-duplex pr-ps-utility-alist)])
2519 ["Despool..." (call-interactively 'pr-despool-ps-print)
2520 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
2521 :help "Despool PostScript buffer to printer or file (C-u)"])
2522 ["PostScript Printers" pr-update-menus
2523 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
2524 :help "Select PostScript printer"]
2525 "--"
2526 ("Printify" :visible (pr-visible-p 'text)
2527 :help "Replace non-printing chars with printable representations."
2528 ["Directory" pr-printify-directory t]
2529 ["Buffer" pr-printify-buffer t]
2530 ["Region" pr-printify-region (ps-mark-active-p)])
2531 ("Print" :visible (pr-visible-p 'text)
2532 :help "Send text to printer"
2533 ["Directory" pr-txt-directory t]
2534 ["Buffer" pr-txt-buffer t]
2535 ["Region" pr-txt-region (ps-mark-active-p)]
2536 ["Mode" pr-txt-mode (pr-mode-alist-p)])
2537 ["Text Printers" pr-update-menus
2538 :active pr-txt-printer-alist :included (pr-visible-p 'text)
2539 :help "Select text printer"]
2540 "--"
2541 ["Landscape" pr-toggle-landscape
2542 :style toggle :selected ps-landscape-mode
2543 :included (pr-visible-p 'postscript-options)]
2544 ["Print Header" pr-toggle-header
2545 :style toggle :selected ps-print-header
2546 :included (pr-visible-p 'postscript-options)]
2547 ["Print Header Frame" pr-toggle-header-frame
2548 :style toggle :selected ps-print-header-frame :active ps-print-header
2549 :included (pr-visible-p 'postscript-options)]
2550 ["Line Number" pr-toggle-line
2551 :style toggle :selected ps-line-number
2552 :included (pr-visible-p 'postscript-options)]
2553 ["Zebra Stripes" pr-toggle-zebra
2554 :style toggle :selected ps-zebra-stripes
2555 :included (pr-visible-p 'postscript-options)]
2556 ["Duplex" pr-toggle-duplex
2557 :style toggle :selected ps-spool-duplex
2558 :included (pr-visible-p 'postscript-options)]
2559 ["Tumble" pr-toggle-tumble
2560 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
2561 :included (pr-visible-p 'postscript-options)]
2562 ["Upside-Down" pr-toggle-upside-down
2563 :style toggle :selected ps-print-upside-down
2564 :included (pr-visible-p 'postscript-options)]
2565 ("Print All Pages" :visible (pr-visible-p 'postscript-options)
2566 :help "Select odd/even pages/sheets to print"
2567 ["All Pages" (pr-even-or-odd-pages nil)
2568 :style radio :selected (eq ps-even-or-odd-pages nil)]
2569 ["Even Pages" (pr-even-or-odd-pages 'even-page)
2570 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
2571 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
2572 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
2573 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
2574 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
2575 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
2576 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
2577 "--"
2578 ["Spool Buffer" pr-toggle-spool
2579 :style toggle :selected pr-spool-p
2580 :included (pr-visible-p 'postscript-process)
2581 :help "Toggle PostScript spooling"]
2582 ["Print with faces" pr-toggle-faces
2583 :style toggle :selected pr-faces-p
2584 :included (pr-visible-p 'postscript-process)
2585 :help "Toggle PostScript printing with faces"]
2586 ["Print via Ghostscript" pr-toggle-ghostscript
2587 :style toggle :selected pr-print-using-ghostscript
2588 :included (pr-visible-p 'postscript-process)
2589 :help "Toggle PostScript generation using ghostscript"]
2590 "--"
2591 ["Auto Region" pr-toggle-region
2592 :style toggle :selected pr-auto-region
2593 :included (pr-visible-p 'printing)]
2594 ["Auto Mode" pr-toggle-mode
2595 :style toggle :selected pr-auto-mode
2596 :included (pr-visible-p 'printing)]
2597 ["Menu Lock" pr-toggle-lock
2598 :style toggle :selected pr-menu-lock
2599 :included (pr-visible-p 'printing)]
2600 "--"
2601 ("Customize" :visible (pr-visible-p 'help)
2602 ["printing" pr-customize t]
2603 ["ps-print" ps-print-customize t]
2604 ["lpr" lpr-customize t])
2605 ("Show Settings" :visible (pr-visible-p 'help)
2606 ["printing" pr-show-pr-setup t]
2607 ["ps-print" pr-show-ps-setup t]
2608 ["lpr" pr-show-lpr-setup t])
2609 ["Help" pr-help :active t :included (pr-visible-p 'help)]
2610 ))
2611
2612
2613 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2614 ;; Menu mapping:
2615 ;; unfortunately XEmacs doesn't support :active or :visible
2616 ;; for submenus, only for items.
2617 ;; It uses :included instead of :active or :visible.
2618 ;; Also, XEmacs doesn't support :help tag.
2619 '(
2620 ["Printing Interface" pr-interface]
2621 "--"
2622 ("PostScript Preview" :included (pr-visible-p 'postscript)
2623 ("Directory" :included (not pr-spool-p)
2624 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
2625 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
2626 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
2627 ["Other..." (pr-ps-directory-preview nil nil nil t)
2628 :keys "\\[pr-ps-buffer-preview]"])
2629 ("Buffer" :included (not pr-spool-p)
2630 ["1-up" (pr-ps-buffer-preview 1 t) t]
2631 ["2-up" (pr-ps-buffer-preview 2 t) t]
2632 ["4-up" (pr-ps-buffer-preview 4 t) t]
2633 ["Other..." (pr-ps-buffer-preview nil t)
2634 :keys "\\[pr-ps-buffer-preview]"])
2635 ("Region" :included (and (not pr-spool-p) (ps-mark-active-p))
2636 ["1-up" (pr-ps-region-preview 1 t) t]
2637 ["2-up" (pr-ps-region-preview 2 t) t]
2638 ["4-up" (pr-ps-region-preview 4 t) t]
2639 ["Other..." (pr-ps-region-preview nil t)
2640 :keys "\\[pr-ps-region-preview]"])
2641 ("Mode" :included (and (not pr-spool-p) (pr-mode-alist-p))
2642 ["1-up" (pr-ps-mode-preview 1 t) t]
2643 ["2-up" (pr-ps-mode-preview 2 t) t]
2644 ["4-up" (pr-ps-mode-preview 4 t) t]
2645 ["Other..." (pr-ps-mode-preview nil t)
2646 :keys "\\[pr-ps-mode-preview]"])
2647 ("File"
2648 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
2649 :keys "\\[pr-ps-file-preview]"]
2650 "--"
2651 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist]
2652 "--"
2653 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
2654 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
2655 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
2656 ["Other..." (pr-ps-file-up-preview nil t t)
2657 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
2658 "--"
2659 ["Landscape" pr-toggle-file-landscape
2660 :style toggle :selected pr-file-landscape
2661 :active pr-ps-utility-alist]
2662 ["Duplex" pr-toggle-file-duplex
2663 :style toggle :selected pr-file-duplex
2664 :active pr-ps-utility-alist]
2665 ["Tumble" pr-toggle-file-tumble
2666 :style toggle :selected pr-file-tumble
2667 :active (and pr-file-duplex pr-ps-utility-alist)])
2668 ["Despool..." (call-interactively 'pr-despool-preview)
2669 :active pr-spool-p :keys "\\[pr-despool-preview]"])
2670 ("PostScript Print" :included (pr-visible-p 'postscript)
2671 ("Directory"
2672 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
2673 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
2674 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
2675 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
2676 :keys "\\[pr-ps-buffer-ps-print]"])
2677 ("Buffer"
2678 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
2679 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
2680 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
2681 ["Other..." (pr-ps-buffer-ps-print nil t)
2682 :keys "\\[pr-ps-buffer-ps-print]"])
2683 ("Region" :included (ps-mark-active-p)
2684 ["1-up" (pr-ps-region-ps-print 1 t) t]
2685 ["2-up" (pr-ps-region-ps-print 2 t) t]
2686 ["4-up" (pr-ps-region-ps-print 4 t) t]
2687 ["Other..." (pr-ps-region-ps-print nil t)
2688 :keys "\\[pr-ps-region-ps-print]"])
2689 ("Mode" :included (pr-mode-alist-p)
2690 ["1-up" (pr-ps-mode-ps-print 1 t) t]
2691 ["2-up" (pr-ps-mode-ps-print 2 t) t]
2692 ["4-up" (pr-ps-mode-ps-print 4 t) t]
2693 ["Other..." (pr-ps-mode-ps-print nil t)
2694 :keys "\\[pr-ps-mode-ps-print]"])
2695 ("File"
2696 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
2697 :keys "\\[pr-ps-file-ps-print]"]
2698 "--"
2699 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist]
2700 "--"
2701 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
2702 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
2703 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
2704 ["Other..." (pr-ps-file-up-ps-print nil t t)
2705 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
2706 "--"
2707 ["Landscape" pr-toggle-file-landscape
2708 :style toggle :selected pr-file-landscape
2709 :active pr-ps-utility-alist]
2710 ["Duplex" pr-toggle-file-duplex
2711 :style toggle :selected pr-file-duplex
2712 :active pr-ps-utility-alist]
2713 ["Tumble" pr-toggle-file-tumble
2714 :style toggle :selected pr-file-tumble
2715 :active (and pr-file-duplex pr-ps-utility-alist)])
2716 ["Despool..." (call-interactively 'pr-despool-ps-print)
2717 :active pr-spool-p :keys "\\[pr-despool-ps-print]"])
2718 ["PostScript Printers" pr-update-menus
2719 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)]
2720 "--"
2721 ("Printify" :included (pr-visible-p 'text)
2722 ["Directory" pr-printify-directory t]
2723 ["Buffer" pr-printify-buffer t]
2724 ["Region" pr-printify-region (ps-mark-active-p)])
2725 ("Print" :included (pr-visible-p 'text)
2726 ["Directory" pr-txt-directory t]
2727 ["Buffer" pr-txt-buffer t]
2728 ["Region" pr-txt-region (ps-mark-active-p)]
2729 ["Mode" pr-txt-mode (pr-mode-alist-p)])
2730 ["Text Printers" pr-update-menus
2731 :active pr-txt-printer-alist :included (pr-visible-p 'text)]
2732 "--"
2733 ["Landscape" pr-toggle-landscape
2734 :style toggle :selected ps-landscape-mode
2735 :included (pr-visible-p 'postscript-options)]
2736 ["Print Header" pr-toggle-header
2737 :style toggle :selected ps-print-header
2738 :included (pr-visible-p 'postscript-options)]
2739 ["Print Header Frame" pr-toggle-header-frame
2740 :style toggle :selected ps-print-header-frame :active ps-print-header
2741 :included (pr-visible-p 'postscript-options)]
2742 ["Line Number" pr-toggle-line
2743 :style toggle :selected ps-line-number
2744 :included (pr-visible-p 'postscript-options)]
2745 ["Zebra Stripes" pr-toggle-zebra
2746 :style toggle :selected ps-zebra-stripes
2747 :included (pr-visible-p 'postscript-options)]
2748 ["Duplex" pr-toggle-duplex
2749 :style toggle :selected ps-spool-duplex
2750 :included (pr-visible-p 'postscript-options)]
2751 ["Tumble" pr-toggle-tumble
2752 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
2753 :included (pr-visible-p 'postscript-options)]
2754 ["Upside-Down" pr-toggle-upside-down
2755 :style toggle :selected ps-print-upside-down
2756 :included (pr-visible-p 'postscript-options)]
2757 ("Print All Pages" :included (pr-visible-p 'postscript-options)
2758 ["All Pages" (pr-even-or-odd-pages nil)
2759 :style radio :selected (eq ps-even-or-odd-pages nil)]
2760 ["Even Pages" (pr-even-or-odd-pages 'even-page)
2761 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
2762 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
2763 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
2764 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
2765 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
2766 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
2767 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
2768 "--"
2769 ["Spool Buffer" pr-toggle-spool
2770 :style toggle :selected pr-spool-p
2771 :included (pr-visible-p 'postscript-process)]
2772 ["Print with faces" pr-toggle-faces
2773 :style toggle :selected pr-faces-p
2774 :included (pr-visible-p 'postscript-process)]
2775 ["Print via Ghostscript" pr-toggle-ghostscript
2776 :style toggle :selected pr-print-using-ghostscript
2777 :included (pr-visible-p 'postscript-process)]
2778 "--"
2779 ["Auto Region" pr-toggle-region
2780 :style toggle :selected pr-auto-region
2781 :included (pr-visible-p 'printing)]
2782 ["Auto Mode" pr-toggle-mode
2783 :style toggle :selected pr-auto-mode
2784 :included (pr-visible-p 'printing)]
2785 ["Menu Lock" pr-toggle-lock
2786 :style toggle :selected pr-menu-lock
2787 :included (pr-visible-p 'printing)]
2788 "--"
2789 ("Customize" :included (pr-visible-p 'help)
2790 ["printing" pr-customize t]
2791 ["ps-print" ps-print-customize t]
2792 ["lpr" lpr-customize t])
2793 ("Show Settings" :included (pr-visible-p 'help)
2794 ["printing" pr-show-pr-setup t]
2795 ["ps-print" pr-show-ps-setup t]
2796 ["lpr" pr-show-lpr-setup t])
2797 ["Help" pr-help :active t :included (pr-visible-p 'help)]
2798 ))
2799 ))
2800
2801
2802 (cond
2803 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2804 ;; Menu binding
2805 (require 'easymenu)
2806 ;; Replace existing "print" item by "Printing" item.
2807 ;; If you're changing this file, you'll load it a second,
2808 ;; third... time, but "print" item exists only in the first load.
2809 (defvar pr-menu-print-item "print")
2810 (cond
2811 ;; Emacs 20
2812 ((string< emacs-version "21.")
2813 (easy-menu-change '("tools") "Printing" pr-menu-spec pr-menu-print-item)
2814 (when pr-menu-print-item
2815 (easy-menu-remove-item nil '("tools") pr-menu-print-item)
2816 (setq pr-menu-print-item nil
2817 pr-menu-bar (vector 'menu-bar 'tools
2818 (pr-get-symbol "Printing")))))
2819 ;; Emacs 21
2820 (pr-menu-print-item
2821 (easy-menu-change '("files") "Print" pr-menu-spec "print-buffer")
2822 (let ((items '("print-buffer" "print-region"
2823 "ps-print-buffer-faces" "ps-print-region-faces"
2824 "ps-print-buffer" "ps-print-region")))
2825 (while items
2826 (easy-menu-remove-item nil '("files") (car items))
2827 (setq items (cdr items)))
2828 (setq pr-menu-print-item nil
2829 pr-menu-bar (vector 'menu-bar 'files
2830 (pr-get-symbol "Print")))))
2831 (t
2832 (easy-menu-change '("files") "Print" pr-menu-spec)))
2833
2834 ;; Key binding
2835 (global-set-key [print] 'pr-ps-fast-fire)
2836 (global-set-key [M-print] 'pr-ps-mode-using-ghostscript)
2837 (global-set-key [C-print] 'pr-txt-fast-fire))
2838
2839
2840 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2841 ;; Menu binding
2842 (pr-xemacs-global-menubar
2843 (pr-x-add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
2844
2845 ;; Key binding
2846 (global-set-key 'f22 'pr-ps-fast-fire)
2847 (global-set-key '(meta f22) 'pr-ps-mode-using-ghostscript)
2848 (global-set-key '(control f22) 'pr-txt-fast-fire))))
2849
2850
2851 ;;; You can also use something like:
2852 ;;;(global-set-key "\C-ci" 'pr-interface)
2853 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
2854 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
2855 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
2856 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
2857 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
2858 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
2859
2860
2861 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2862 ;; Help Message
2863
2864
2865 (defconst pr-help-message
2866 (concat "printing.el version " pr-version
2867 " ps-print.el version " ps-print-version
2868 "\n\n
2869 Menu Layout
2870 -----------
2871
2872 The `printing' menu (Tools/Printing or File/Print) has the following layout:
2873
2874 +-----------------------------+
2875 A 0 | Printing Interface |
2876 +-----------------------------+ +-A---------+ +-B------+
2877 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
2878 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
2879 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
2880 +-----------------------------+ |Mode >|-- B |Other...|
2881 II 4 | Printify >|-----\\ |File >|--\\ +--------+
2882 5 | Print >|---\\ | |Despool... | |
2883 6 | Text Printer: name >|-\\ | | +-----------+ |
2884 +-----------------------------+ | | | +---------+ +------------+
2885 III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
2886 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
2887 9 |[ ]Print Header Frame | | | |Region | | name >|- C
2888 10 |[ ]Line Number | | | +---------+ +------------+
2889 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
2890 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
2891 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
2892 14 |[ ]Upside-Down | | |Region | | Other... |
2893 15 | Print All Pages >|--\\ | |Mode | +------------+
2894 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
2895 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
2896 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
2897 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
2898 +-----------------------------+ | |... |
2899 V 19 |[ ]Auto Region | | |(*)name |
2900 20 |[ ]Auto Mode | | |... |
2901 21 |[ ]Menu Lock | | +---------+ +--------------+
2902 +-----------------------------+ \\------------------|(*)All Pages |
2903 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
2904 23 | Show Settings >|-------|printing| |( )Odd Pages |
2905 24 | Help | |ps-print| |( )Even Sheets|
2906 +-----------------------------+ |lpr | |( )Odd Sheets |
2907 +--------+ +--------------+
2908
2909 See `pr-visible-entry-list' for hiding some parts of the menu.
2910
2911 The menu has the following sections:
2912
2913 A. Interface:
2914
2915 0. You can use a buffer interface instead of menus. It looks like the
2916 customization buffer. Basically, it has the same options found in the
2917 menu and some extra options, all this on a buffer.
2918
2919 I. PostScript printing:
2920
2921 1. You can generate a PostScript file (if you type C-u before activating
2922 menu) or PostScript temporary file for a directory, a buffer, a region
2923 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
2924 after file generation, ghostview is activated using the file generated
2925 as argument. This option is disabled if spooling is on (option 16).
2926 Also, if you already have a PostScript file you can preview it.
2927 Instead of previewing each buffer, region or major mode at once, you
2928 can save temporarily the PostScript code generated in a buffer and
2929 preview it later. The option `Despool...' despools the PostScript
2930 spooling buffer in a temporary file and uses ghostview to preview it.
2931 If you type C-u before choosing this option, the PostScript code
2932 generated is saved in a file instead of saving in a temporary file. To
2933 spool the PostScript code generated you need to turn on the option 16.
2934 The option `Despool...' is enabled if spooling is on (option 16).
2935
2936 NOTE 1: It's possible to customize a major mode printing, just declare
2937 the customization in `pr-mode-alist' and invoke some of
2938 `*-mode*' commands or select Mode option in Printing menu. An
2939 example for major mode usage is when you're using gnus (or mh,
2940 or rmail, etc.) and you're in the *Summary* buffer, if you
2941 forget to switch to the *Article* buffer before printing,
2942 you'll get a nicely formatted list of article subjects shows
2943 up at the printer. With major mode printing you don't need to
2944 switch from gnus *Summary* buffer first.
2945
2946 NOTE 2: There are the following options for PostScript file processing:
2947 Ia. Print the file *No Preprocessing*, that is, send it
2948 directly to PostScript printer.
2949 Ib. PostScript utility processing selection.
2950 See `pr-ps-utility-alist' and `pr-setting-database' for
2951 documentation.
2952 Ic. Do n-up processing before printing.
2953 Id. Toggle on/off landscape for PostScript file processing.
2954 Ie. Toggle on/off duplex for PostScript file processing.
2955 If. Toggle on/off tumble for PostScript file processing.
2956
2957 NOTE 3: Don't forget to download and install the utilities declared on
2958 `pr-ps-utility-alist'.
2959
2960 2. Operate the same way as option 1, but it sends directly the PostScript
2961 code (or put in a file, if you've typed C-u) or it uses ghostscript to
2962 print the PostScript file generated. It depends on option 18, if it's
2963 turned on, it uses ghostscript; otherwise, it sends directly to
2964 printer. If spooling is on (option 16), the PostScript code is saved
2965 temporarily in a buffer instead of printing it or saving it in a file.
2966 Also, if you already have a PostScript file you can print it.
2967 Instead of printing each buffer, region or major mode at once, you can
2968 save temporarily the PostScript code generated in a buffer and print it
2969 later. The option `Despool...' despools the PostScript spooling buffer
2970 directly on a printer. If you type C-u before choosing this option,
2971 the PostScript code generated is saved in a file instead of sending it to
2972 the printer. To spool the PostScript code generated you need to turn on
2973 option 16. This option is enabled if spooling is on (option 16).
2974 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
2975
2976 3. You can select a new PostScript printer to send PostScript code
2977 generated. For selection it's used all PostScript printers defined
2978 in `pr-ps-printer-alist' variable (see it for documentation).
2979 See also `pr-setting-database'.
2980
2981 II. Text printing:
2982
2983 4. If you have control characters (character code from \\000 to \\037) in a
2984 buffer and you want to print them in a text printer, select this
2985 option. All control characters in your buffer or region will be
2986 replaced by a printable representation. The printable representations
2987 use ^ (for ASCII control characters) or hex. The characters tab,
2988 linefeed, space, return and formfeed are not affected.
2989 You don't need to select this option if you use any option of section
2990 I, the PostScript engine treats control characters properly.
2991
2992 5. If you want to print a directory, buffer, region or major mode in a
2993 text printer, select this option. See also the NOTE 1 on option 1.
2994
2995 6. You can select a new text printer to send text generated. For
2996 selection it's used all text printers defined in `pr-txt-printer-alist'
2997 variable (see it for documentation).
2998 See also `pr-setting-database'.
2999
3000 III. PostScript page toggle options:
3001
3002 7. If you want a PostScript landscape printing, turn on this option.
3003
3004 8. If you want to have a header in each page in your PostScript code,
3005 turn on this option.
3006
3007 9. If you want to draw a gaudy frame around the header, turn on this
3008 option. This option is enabled if print header is on (option 8).
3009
3010 10. If you want that the line number is printed in your PostScript code,
3011 turn on this option.
3012
3013 11. If you want background zebra stripes in your PostScript code, turn on
3014 this option.
3015
3016 12. If you want a duplex printing and your PostScript printer has this
3017 feature, turn on this option.
3018
3019 13. If you turned on duplex printing, you can choose if you want to have a
3020 printing suitable for binding on the left or right (tumble off), or to
3021 have a printing suitable for binding at top or bottom (tumble on).
3022 This option is enabled if duplex is on (option 12).
3023
3024 14. If you want a PostScript upside-down printing, turn on this option.
3025
3026 15. With this option, you can choose if you want to print all pages, odd
3027 pages, even pages, odd sheets or even sheets.
3028 See also `ps-even-or-odd-pages'.
3029
3030 IV. PostScript processing toggle options:
3031
3032 16. If you want to spool the PostScript code generated, turn on this
3033 option. To spool the PostScript code generated use option 2. You can
3034 despool later by choosing option 1 or 2, sub-option `Despool...'.
3035
3036 17. If you use colors in your buffers and want to see these colors on your
3037 PostScript code generated, turn on this option. If you have a
3038 black/white PostScript printer, these colors are displayed in gray
3039 scale by PostScript printer interpreter.
3040
3041 18. If you don't have a PostScript printer to send PostScript files, turn
3042 on this option. When this option is on, the ghostscript is used to
3043 print PostScript files. In GNU or Unix system, if ghostscript is set
3044 as a PostScript filter, you don't need to turn on this option.
3045
3046 V. Printing customization:
3047
3048 19. If you want that region is automagically detected, turn on this
3049 option. Note that this will only work if you're using transient mark
3050 mode. When this option is on, the `*-buffer*' commands will behave
3051 like `*-region*' commands, that is, `*-buffer*' commands will print
3052 only the region marked instead of all buffer.
3053
3054 20. Turn this option on if you want that when current major-mode is
3055 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3056 behave like `*-mode*' commands.
3057
3058 21. If you want that Printing menu stays open while you are setting
3059 toggle options, turn on this option. The variables
3060 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3061 menu position, so don't forget to adjust these variables if menu
3062 position is not ok.
3063
3064 VI. Customization:
3065
3066 22. Besides all options in section III, IV and V, you can customize much
3067 more PostScript options in `ps-print' option. Or you can customize
3068 some `lpr' options for text printing. Or customize `printing'
3069 options.
3070
3071 23. Show current settings for `printing', `ps-print' or `lpr'.
3072
3073 24. Quick help for printing menu layout.
3074 ")
3075 "Printing help message.")
3076
3077
3078 (defconst pr-interface-help-message
3079 (concat "printing.el version " pr-version
3080 " ps-print.el version " ps-print-version
3081 "\n\n
3082 The printing interface buffer has the same functionality as the printing menu.
3083 The major difference is that the states (like sending PostScript generated to a
3084 file, n-up printing, etc.) are set and saved between priting buffer
3085 activation. Also, the landscape, duplex and tumble values are the same for
3086 PostScript file and directory/buffer/region/mode processing; using menu, there
3087 are different value sets for PostScript file and directory/buffer/region/mode
3088 processing.
3089
3090 The printing interface buffer has the following sections:
3091
3092 1. Print:
3093
3094 Here you can choose to print/preview a buffer, a directory or a PostScript
3095 file:
3096
3097 1a. Buffer:
3098
3099 * Buffer List:
3100 Select a buffer from the current buffer list.
3101
3102 * Region:
3103 If it's on, this means that the selected buffer has an active region,
3104 so you can turn on/off, as you wish.
3105 If it's off when a buffer is selected, this means that the selected
3106 buffer has no active region, so it'll not be possible to turn it on.
3107 If you want to process the region, let this option on.
3108 If you want to process the whole buffer, let this option off.
3109
3110 * Mode:
3111 If it's on, this means that the selected buffer major mode is declared
3112 for major mode processing, so you can turn on/off, as you wish.
3113 If it's off when a buffer is selected, this means that the selected
3114 buffer major mode isn't declared for major mode processing, so it'll
3115 not be possible to turn it on.
3116 If you want the major mode processing, let this option on.
3117 If you don't want the major mode processing, let this option off.
3118
3119 NOTE 1: It's possible to customize a major mode printing, just declare
3120 the customization in `pr-mode-alist' and invoke some of
3121 `*-mode*' commands or select Mode option in Printing menu. An
3122 example for major mode usage is when you're using gnus (or mh,
3123 or rmail, etc.) and you're in the *Summary* buffer, if you
3124 forget to switch to the *Article* buffer before printing,
3125 you'll get a nicely formatted list of article subjects shows
3126 up at the printer. With major mode printing you don't need to
3127 switch from gnus *Summary* buffer first.
3128
3129 1b. Directory:
3130
3131 * Directory:
3132 Specify a valid directory path.
3133
3134 * File Regexp:
3135 Specify a file name regexp. All file names in the directory that
3136 match with regexp will be printed/previewed. An empty file name
3137 regexp means to print/preview all files in the directory.
3138
3139 * List Directory Entry:
3140 If it's turned on, list directory entries besides file entries.
3141
3142 1c. PostScript file:
3143
3144 * PostScript File:
3145 Specify an existent PostScript file to print/preview.
3146
3147 * PostScript Utility:
3148 Select a PostScript utility.
3149 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3150
3151 NOTE 2: Don't forget to download and install the utilities declared on
3152 `pr-ps-utility-alist'.
3153
3154 * No Preprocessing:
3155 If it's turned on, don't use the PostScript utility to preprocess the
3156 PostScript file before printing/previewing.
3157
3158 2. PostScript printer:
3159
3160 * PostScript Printer:
3161 You can select a new PostScript printer to send PostScript code
3162 generated. For selection it's used all PostScript printers defined
3163 in `pr-ps-printer-alist' variable (see it for documentation).
3164 See also `pr-setting-database'.
3165
3166 * Despool:
3167 If spooling is on, you can turn it on/off, as you wish.
3168 If spooling is off, it'll not be possible to turn it on.
3169 If it's turned on, specify to despools the PostScript spooling buffer in
3170 a temporary file or in the selected PostScript file when
3171 printing/previewing.
3172
3173 * Preview:
3174 Preview the PostScript generated.
3175
3176 * Print:
3177 Print the PostScript generated.
3178
3179 * Quit:
3180 Quit from printing interface buffer.
3181
3182 * Send to Printer/Temporary File:
3183 If it's turned on, the PostScript generated is sent directly to
3184 PostScript printer or, for previewing, to a temporary file.
3185
3186 * Send to File:
3187 Specify a file name to send the PostScript generated.
3188
3189 * N-Up:
3190 Specify n-up printing.
3191
3192 3. Text printer:
3193
3194 * Text Printer:
3195 Select a new text printer to send text generated. For selection it's used
3196 all text printers defined in `pr-txt-printer-alist' variable (see it for
3197 documentation). See also `pr-setting-database'.
3198
3199 * Printify:
3200 If you have control characters (character code from \\000 to \\037) in a
3201 buffer and you want to print them in a text printer, select this
3202 option. All control characters in your buffer or region will be
3203 replaced by a printable representation. The printable representations
3204 use ^ (for ASCII control characters) or hex. The characters tab,
3205 linefeed, space, return and formfeed are not affected.
3206 You don't need to select this option if you use any option of section
3207 I, the PostScript engine treats control characters properly.
3208
3209 * Print:
3210 To print a directory, buffer, region or major mode in a
3211 text printer, select this option. See also the NOTE 1 on section 1.
3212
3213 * Quit:
3214 Quit from printing interface buffer.
3215
3216 4. Settings:
3217
3218 There are 3 setting columns:
3219
3220 4a. First column (left column):
3221
3222 * Landscape:
3223 PostScript landscape printing.
3224
3225 * Print Header:
3226 To have a header in each page in your PostScript code.
3227
3228 * Print Header Frame:
3229 To draw a gaudy frame around the header.
3230
3231 * Line Number:
3232 The line number is printed in your PostScript code.
3233
3234 * Zebra Stripes:
3235 Background zebra stripes in your PostScript code.
3236
3237 * Duplex:
3238 Duplex printing (if your PostScript printer has this feature).
3239
3240 * Tumble:
3241 If duplex printing is on, you can choose if you want to have a
3242 printing suitable for binding on the left or right (tumble off), or to
3243 have a printing suitable for binding at top or bottom (tumble on).
3244
3245 * Upside-Down:
3246 PostScript upside-down printing.
3247
3248 4b. Second column (middle column):
3249
3250 * Auto Region:
3251 If you want that region is automagically detected, turn on this
3252 option. Note that this will only work if you're using transient mark
3253 mode. When this option is on, the `*-buffer*' commands will behave
3254 like `*-region*' commands, that is, `*-buffer*' commands will print
3255 only the region marked instead of all buffer.
3256
3257 * Auto Mode:
3258 Turn this option on if you want that when current major-mode is
3259 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3260 behave like `*-mode*' commands.
3261
3262 * Menu Lock:
3263 If you want that Printing menu stays open while you are setting
3264 toggle options, turn on this option. The variables
3265 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3266 menu position, so don't forget to adjust these variables if menu
3267 position is not ok.
3268
3269 * Spool Buffer:
3270 To spool the PostScript code generated. You can despool later by
3271 setting Despool option on PostScript printer section.
3272
3273 * Print with faces:
3274 If you use colors in your buffers and want to see these colors on your
3275 PostScript code generated, turn on this option. If you have a
3276 black/white PostScript printer, these colors are displayed in gray
3277 scale by PostScript printer interpreter.
3278
3279 * Print via Ghostscript:
3280 If you don't have a PostScript printer to send PostScript files, turn
3281 on this option. When this option is on, the ghostscript is used to
3282 print PostScript files. In GNU or Unix system, if ghostscript is set
3283 as a PostScript filter, you don't need to turn on this option.
3284
3285 * Parity Page Menu:
3286 To print all pages, odd pages, even pages, odd sheets or even sheets.
3287 See also `ps-even-or-odd-pages'.
3288
3289 4c. Third column (right column):
3290
3291 * Verbose:
3292 That is, to be verbose when editing a field in interface buffer.
3293
3294 5. Customize:
3295
3296 Besides all options in section 4, you can customize much more PostScript
3297 options in `ps-print' option. Or you can customize some `lpr' options for
3298 text printing. Or customize `printing' options.
3299
3300 6. Show settings:
3301
3302 Show current settings for `printing', `ps-print' or `lpr'.
3303
3304 7. Help:
3305
3306 Quick help for printing interface buffer and printing menu layout. You can
3307 also quit the printing interface buffer or kill all printing help buffer.
3308 ")
3309 "Printing buffer interface help message.")
3310
3311
3312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3313 ;; Commands
3314
3315
3316 ;;;###autoload
3317 (defun pr-interface (&optional buffer)
3318 "Activate the printing interface buffer.
3319
3320 If BUFFER is nil, the current buffer is used for printing.
3321
3322 For more information, type \\[pr-interface-help]."
3323 (interactive)
3324 (save-excursion
3325 (set-buffer (or buffer (current-buffer)))
3326 (pr-create-interface)))
3327
3328
3329 ;;;###autoload
3330 (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3331 "Preview directory using ghostview.
3332
3333 Interactively, the command prompts for N-UP printing number, a directory, a
3334 file name regexp for matching and, when you use a prefix argument (C-u), the
3335 command prompts the user for a file name, and saves the PostScript image in
3336 that file instead of saving it in a temporary file.
3337
3338 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3339 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3340 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3341 save the image in a temporary file. If FILENAME is a string, save the
3342 PostScript image in a file with that name. If FILENAME is t, prompts for a
3343 file name.
3344
3345 See also documentation for `pr-list-directory'."
3346 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3347 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3348 (pr-prompt "PS preview dir"))
3349 (setq filename (pr-ps-file filename))
3350 (pr-ps-file-list n-up dir file-regexp filename)
3351 (or pr-spool-p
3352 (pr-ps-file-preview filename)))
3353
3354
3355 ;;;###autoload
3356 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3357 "Print directory using PostScript through ghostscript.
3358
3359 Interactively, the command prompts for N-UP printing number, a directory, a
3360 file name regexp for matching and, when you use a prefix argument (C-u), the
3361 command prompts the user for a file name, and saves the PostScript image in
3362 that file instead of saving it in a temporary file.
3363
3364 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3365 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3366 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3367 save the image in a temporary file. If FILENAME is a string, save the
3368 PostScript image in a file with that name. If FILENAME is t, prompts for a
3369 file name.
3370
3371 See also documentation for `pr-list-directory'."
3372 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3373 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3374 (pr-prompt "PS print dir GS"))
3375 (let ((file (pr-ps-file filename)))
3376 (pr-ps-file-list n-up dir file-regexp file)
3377 (pr-ps-file-using-ghostscript file)
3378 (or filename (pr-delete-file file))))
3379
3380
3381 ;;;###autoload
3382 (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
3383 "Print directory using PostScript printer.
3384
3385 Interactively, the command prompts for N-UP printing number, a directory, a
3386 file name regexp for matching and, when you use a prefix argument (C-u), the
3387 command prompts the user for a file name, and saves the PostScript image in
3388 that file instead of saving it in a temporary file.
3389
3390 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3391 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3392 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3393 save the image in a temporary file. If FILENAME is a string, save the
3394 PostScript image in a file with that name. If FILENAME is t, prompts for a
3395 file name.
3396
3397 See also documentation for `pr-list-directory'."
3398 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
3399 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3400 (pr-prompt "PS print dir"))
3401 (let ((file (pr-ps-file filename)))
3402 (pr-ps-file-list n-up dir file-regexp file)
3403 (pr-ps-file-print file)
3404 (or filename (pr-delete-file file))))
3405
3406
3407 ;;;###autoload
3408 (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
3409 "Print directory using PostScript printer or through ghostscript.
3410
3411 It depends on `pr-print-using-ghostscript'.
3412
3413 Interactively, the command prompts for N-UP printing number, a directory, a
3414 file name regexp for matching and, when you use a prefix argument (C-u), the
3415 command prompts the user for a file name, and saves the PostScript image in
3416 that file instead of saving it in a temporary file.
3417
3418 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3419 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3420 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3421 save the image in a temporary file. If FILENAME is a string, save the
3422 PostScript image in a file with that name. If FILENAME is t, prompts for a
3423 file name.
3424
3425 See also documentation for `pr-list-directory'."
3426 (interactive (pr-interactive-ps-dir-args
3427 (pr-prompt (pr-prompt-gs "PS print dir"))))
3428 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3429 (pr-prompt (pr-prompt-gs "PS print dir")))
3430 (if (pr-using-ghostscript-p)
3431 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
3432 (pr-ps-directory-print n-up dir file-regexp filename)))
3433
3434
3435 ;;;###autoload
3436 (defun pr-ps-buffer-preview (n-up &optional filename)
3437 "Preview buffer using ghostview.
3438
3439 Interactively, the command prompts for N-UP printing number and, when you use a
3440 prefix argument (C-u), the command prompts the user for a file name, and saves
3441 the PostScript image in that file instead of saving it in a temporary file.
3442
3443 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3444 argument FILENAME is treated as follows: if it's nil, save the image in a
3445 temporary file. If FILENAME is a string, save the PostScript image in a file
3446 with that name. If FILENAME is t, prompts for a file name."
3447 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
3448 (if (pr-auto-mode-p)
3449 (pr-ps-mode-preview n-up filename)
3450 (pr-ps-preview (pr-region-active-symbol) n-up filename
3451 (pr-region-active-string "PS preview"))))
3452
3453
3454 ;;;###autoload
3455 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
3456 "Print buffer using PostScript through ghostscript.
3457
3458 Interactively, the command prompts for N-UP printing number and, when you use a
3459 prefix argument (C-u), the command prompts the user for a file name, and saves
3460 the PostScript image in that file instead of sending it to the printer.
3461
3462 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3463 argument FILENAME is treated as follows: if it's nil, send the image to the
3464 printer. If FILENAME is a string, save the PostScript image in a file with
3465 that name. If FILENAME is t, prompts for a file name."
3466 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
3467 (if (pr-auto-mode-p)
3468 (pr-ps-mode-using-ghostscript n-up filename)
3469 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3470 (pr-region-active-string "PS print GS"))))
3471
3472
3473 ;;;###autoload
3474 (defun pr-ps-buffer-print (n-up &optional filename)
3475 "Print buffer using PostScript printer.
3476
3477 Interactively, the command prompts for N-UP printing number and, when you use a
3478 prefix argument (C-u), the command prompts the user for a file name, and saves
3479 the PostScript image in that file instead of sending it to the printer.
3480
3481 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3482 argument FILENAME is treated as follows: if it's nil, send the image to the
3483 printer. If FILENAME is a string, save the PostScript image in a file with
3484 that name. If FILENAME is t, prompts for a file name."
3485 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
3486 (if (pr-auto-mode-p)
3487 (pr-ps-mode-print n-up filename)
3488 (pr-ps-print (pr-region-active-symbol) n-up filename
3489 (pr-region-active-string "PS print"))))
3490
3491
3492 ;;;###autoload
3493 (defun pr-ps-buffer-ps-print (n-up &optional filename)
3494 "Print buffer using PostScript printer or through ghostscript.
3495
3496 It depends on `pr-print-using-ghostscript'.
3497
3498 Interactively, the command prompts for N-UP printing number and, when you use a
3499 prefix argument (C-u), the command prompts the user for a file name, and saves
3500 the PostScript image in that file instead of sending it to the printer.
3501
3502 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3503 argument FILENAME is treated as follows: if it's nil, send the image to the
3504 printer. If FILENAME is a string, save the PostScript image in a file with
3505 that name. If FILENAME is t, prompts for a file name."
3506 (interactive (pr-interactive-n-up-file
3507 (pr-prompt (pr-prompt-gs "PS print"))))
3508 (cond ((pr-auto-mode-p)
3509 (pr-ps-mode-ps-print n-up filename))
3510 ((pr-using-ghostscript-p)
3511 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3512 (pr-region-active-string "PS print GS")))
3513 (t
3514 (pr-ps-print (pr-region-active-symbol) n-up filename
3515 (pr-region-active-string "PS print")))))
3516
3517
3518 ;;;###autoload
3519 (defun pr-ps-region-preview (n-up &optional filename)
3520 "Preview region using ghostview.
3521
3522 See also `pr-ps-buffer-preview'."
3523 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
3524 (if (pr-auto-mode-p)
3525 (let ((pr-auto-region t))
3526 (pr-ps-mode-preview n-up filename))
3527 (pr-ps-preview 'region n-up filename "PS preview region")))
3528
3529
3530 ;;;###autoload
3531 (defun pr-ps-region-using-ghostscript (n-up &optional filename)
3532 "Print region using PostScript through ghostscript.
3533
3534 See also `pr-ps-buffer-using-ghostscript'."
3535 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
3536 (if (pr-auto-mode-p)
3537 (let ((pr-auto-region t))
3538 (pr-ps-mode-using-ghostscript n-up filename))
3539 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
3540
3541
3542 ;;;###autoload
3543 (defun pr-ps-region-print (n-up &optional filename)
3544 "Print region using PostScript printer.
3545
3546 See also `pr-ps-buffer-print'."
3547 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
3548 (if (pr-auto-mode-p)
3549 (let ((pr-auto-region t))
3550 (pr-ps-mode-print n-up filename))
3551 (pr-ps-print 'region n-up filename "PS print region")))
3552
3553
3554 ;;;###autoload
3555 (defun pr-ps-region-ps-print (n-up &optional filename)
3556 "Print region using PostScript printer or through ghostscript.
3557
3558 See also `pr-ps-buffer-ps-print'."
3559 (interactive (pr-interactive-n-up-file
3560 (pr-prompt-region (pr-prompt-gs "PS print"))))
3561 (cond ((pr-auto-mode-p)
3562 (let ((pr-auto-region t))
3563 (pr-ps-mode-ps-print n-up filename)))
3564 ((pr-using-ghostscript-p)
3565 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
3566 (t
3567 (pr-ps-print 'region n-up filename "PS print region"))))
3568
3569
3570 ;;;###autoload
3571 (defun pr-ps-mode-preview (n-up &optional filename)
3572 "Preview major mode using ghostview.
3573
3574 See also `pr-ps-buffer-preview'."
3575 (interactive (pr-interactive-n-up-file "PS preview mode"))
3576 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
3577 (let ((file (pr-ps-file filename)))
3578 (and (pr-ps-mode n-up file)
3579 (not pr-spool-p)
3580 (pr-ps-file-preview file))))
3581
3582
3583 ;;;###autoload
3584 (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
3585 "Print major mode using PostScript through ghostscript.
3586
3587 See also `pr-ps-buffer-using-ghostscript'."
3588 (interactive (pr-interactive-n-up-file "PS print GS mode"))
3589 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
3590 (let ((file (pr-ps-file filename)))
3591 (when (and (pr-ps-mode n-up file)
3592 (not pr-spool-p))
3593 (pr-ps-file-using-ghostscript file)
3594 (or filename (pr-delete-file file)))))
3595
3596
3597 ;;;###autoload
3598 (defun pr-ps-mode-print (n-up &optional filename)
3599 "Print major mode using PostScript printer.
3600
3601 See also `pr-ps-buffer-print'."
3602 (interactive (pr-interactive-n-up-file "PS print mode"))
3603 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
3604 (pr-ps-mode n-up filename))
3605
3606
3607 ;;;###autoload
3608 (defun pr-ps-mode-ps-print (n-up &optional filename)
3609 "Print major mode using PostScript or through ghostscript.
3610
3611 See also `pr-ps-buffer-ps-print'."
3612 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
3613 (if (pr-using-ghostscript-p)
3614 (pr-ps-mode-using-ghostscript n-up filename)
3615 (pr-ps-mode-print n-up filename)))
3616
3617
3618 ;;;###autoload
3619 (defun pr-printify-directory (&optional dir file-regexp)
3620 "Replace nonprinting characters in directory with printable representations.
3621 The printable representations use ^ (for ASCII control characters) or hex.
3622 The characters tab, linefeed, space, return and formfeed are not affected.
3623
3624 Interactively, the command prompts for a directory and a file name regexp for
3625 matching.
3626
3627 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3628 prompts for FILE(name)-REGEXP.
3629
3630 See also documentation for `pr-list-directory'."
3631 (interactive (pr-interactive-dir-args "Printify dir"))
3632 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
3633 (pr-file-list dir file-regexp 'pr-printify-buffer))
3634
3635
3636 ;;;###autoload
3637 (defun pr-printify-buffer ()
3638 "Replace nonprinting characters in buffer with printable representations.
3639 The printable representations use ^ (for ASCII control characters) or hex.
3640 The characters tab, linefeed, space, return and formfeed are not affected."
3641 (interactive "*")
3642 (if (pr-region-active-p)
3643 (pr-printify-region)
3644 (printify-region (point-min) (point-max))))
3645
3646
3647 ;;;###autoload
3648 (defun pr-printify-region ()
3649 "Replace nonprinting characters in region with printable representations.
3650 The printable representations use ^ (for ASCII control characters) or hex.
3651 The characters tab, linefeed, space, return and formfeed are not affected."
3652 (interactive "*")
3653 (printify-region (point) (mark)))
3654
3655
3656 ;;;###autoload
3657 (defun pr-txt-directory (&optional dir file-regexp)
3658 "Print directory using text printer.
3659
3660 Interactively, the command prompts for a directory and a file name regexp for
3661 matching.
3662
3663 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3664 prompts for FILE(name)-REGEXP.
3665
3666 See also documentation for `pr-list-directory'."
3667 (interactive (pr-interactive-dir-args "Print dir"))
3668 (pr-set-dir-args 'dir 'file-regexp "Print dir")
3669 (pr-file-list dir file-regexp 'pr-txt-buffer))
3670
3671
3672 ;;;###autoload
3673 (defun pr-txt-buffer ()
3674 "Print buffer using text printer."
3675 (interactive)
3676 (cond ((pr-auto-mode-p)
3677 (pr-txt-mode))
3678 ((pr-region-active-p)
3679 (pr-txt-region))
3680 (t
3681 (pr-txt-print (point-min) (point-max)))))
3682
3683
3684 ;;;###autoload
3685 (defun pr-txt-region ()
3686 "Print region using text printer."
3687 (interactive)
3688 (if (pr-auto-mode-p)
3689 (let ((pr-auto-region t))
3690 (pr-txt-mode))
3691 (pr-txt-print (point) (mark))))
3692
3693
3694 ;;;###autoload
3695 (defun pr-txt-mode ()
3696 "Print major mode using text printer."
3697 (interactive)
3698 (let ((args (pr-mode-alist-p)))
3699 (if args
3700 (funcall (car args) (nthcdr 2 args))
3701 (ding)
3702 (message "`%s' major mode not declared." major-mode))))
3703
3704
3705 ;;;###autoload
3706 (defun pr-despool-preview (&optional filename)
3707 "Preview spooled PostScript.
3708
3709 Interactively, when you use a prefix argument (C-u), the command prompts the
3710 user for a file name, and saves the spooled PostScript image in that file
3711 instead of saving it in a temporary file.
3712
3713 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3714 save the image in a temporary file. If FILENAME is a string, save the
3715 PostScript image in a file with that name."
3716 (interactive (list (ps-print-preprint current-prefix-arg)))
3717 (let ((file (pr-ps-file filename)))
3718 (when (stringp file)
3719 (pr-despool-print file)
3720 (pr-ps-file-preview file))))
3721
3722
3723 ;;;###autoload
3724 (defun pr-despool-using-ghostscript (&optional filename)
3725 "Print spooled PostScript using ghostscript.
3726
3727 Interactively, when you use a prefix argument (C-u), the command prompts the
3728 user for a file name, and saves the spooled PostScript image in that file
3729 instead of sending it to the printer.
3730
3731 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3732 send the image to the printer. If FILENAME is a string, save the PostScript
3733 image in a file with that name."
3734 (interactive (list (ps-print-preprint current-prefix-arg)))
3735 (let ((file (pr-ps-file filename)))
3736 (when (stringp file)
3737 (pr-despool-print file)
3738 (pr-ps-file-using-ghostscript file)
3739 (or filename (pr-delete-file file)))))
3740
3741
3742 ;;;###autoload
3743 (defun pr-despool-print (&optional filename)
3744 "Send the spooled PostScript to the printer.
3745
3746 Interactively, when you use a prefix argument (C-u), the command prompts the
3747 user for a file name, and saves the spooled PostScript image in that file
3748 instead of sending it to the printer.
3749
3750 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3751 send the image to the printer. If FILENAME is a string, save the PostScript
3752 image in a file with that name."
3753 (interactive (list (ps-print-preprint current-prefix-arg)))
3754 (let ((ps-lpr-command (pr-command pr-ps-command))
3755 (ps-lpr-switches pr-ps-switches)
3756 (ps-printer-name-option pr-ps-printer-switch)
3757 (ps-printer-name pr-ps-printer))
3758 (ps-despool filename)))
3759
3760
3761 ;;;###autoload
3762 (defun pr-despool-ps-print (&optional filename)
3763 "Send the spooled PostScript to the printer or use ghostscript to print it.
3764
3765 Interactively, when you use a prefix argument (C-u), the command prompts the
3766 user for a file name, and saves the spooled PostScript image in that file
3767 instead of sending it to the printer.
3768
3769 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3770 send the image to the printer. If FILENAME is a string, save the PostScript
3771 image in a file with that name."
3772 (interactive (list (ps-print-preprint current-prefix-arg)))
3773 (if pr-print-using-ghostscript
3774 (pr-despool-using-ghostscript filename)
3775 (pr-despool-print filename)))
3776
3777
3778 ;;;###autoload
3779 (defun pr-ps-file-preview (filename)
3780 "Preview PostScript file FILENAME."
3781 (interactive (list (pr-ps-infile-preprint "Preview ")))
3782 (and (stringp filename) (file-exists-p filename)
3783 (let ((shell-file-name pr-shell-file-name))
3784 (start-process-shell-command "PREVIEW" "*Messages*"
3785 (pr-command pr-gv-command) filename))))
3786
3787
3788 ;;;###autoload
3789 (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
3790 "Preview PostScript file FILENAME."
3791 (interactive (pr-interactive-n-up-inout "PS preview"))
3792 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
3793 "PS preview ")))
3794 (pr-ps-utility-process n-up ifilename outfile)
3795 (pr-ps-file-preview outfile)))
3796
3797
3798 ;;;###autoload
3799 (defun pr-ps-file-using-ghostscript (filename)
3800 "Print PostScript file FILENAME using ghostscript."
3801 (interactive (list (pr-ps-infile-preprint "Print preview ")))
3802 (and (stringp filename) (file-exists-p filename)
3803 (let* ((file (pr-expand-file-name filename))
3804 (tempfile (pr-dosify-path (make-temp-name file))))
3805 ;; gs use
3806 (pr-shell-command
3807 (concat (pr-command pr-gs-command)
3808 " -sDEVICE=" pr-gs-device
3809 " -r" (int-to-string pr-gs-resolution)
3810 " " (pr-switches-string pr-gs-switches "pr-gs-switches")
3811 " -sOutputFile=" tempfile " " file " -c quit"))
3812 ;; printing
3813 (pr-ps-file-print tempfile)
3814 ;; deleting
3815 (pr-delete-file tempfile))))
3816
3817
3818 ;;;###autoload
3819 (defun pr-ps-file-print (filename)
3820 "Print PostScript file FILENAME."
3821 (interactive (list (pr-ps-infile-preprint "Print ")))
3822 (and (stringp filename) (file-exists-p filename)
3823 ;; printing
3824 (let ((file (pr-expand-file-name filename)))
3825 (if (string= pr-ps-command "")
3826 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
3827 (save-excursion
3828 (set-buffer ps-spool-buffer)
3829 (erase-buffer)
3830 (insert-file-contents-literally file))
3831 (pr-despool-print))
3832 (pr-shell-command
3833 (concat (pr-command pr-ps-command) " "
3834 (pr-switches-string pr-ps-switches "pr-gs-switches") " "
3835 (if (string-match "cp" pr-ps-command)
3836 ;; for "cp" (cmd in out)
3837 (concat "\"" file "\" "
3838 pr-ps-printer-switch pr-ps-printer)
3839 ;; else, for others (cmd out in)
3840 (concat pr-ps-printer-switch pr-ps-printer
3841 " \"" file "\""))))))))
3842
3843
3844 ;;;###autoload
3845 (defun pr-ps-file-ps-print (filename)
3846 "Send PostScript file FILENAME to printer or use ghostscript to print it."
3847 (interactive (list (pr-ps-infile-preprint
3848 (if pr-print-using-ghostscript
3849 "Print preview "
3850 "Print "))))
3851 (if pr-print-using-ghostscript
3852 (pr-ps-file-using-ghostscript filename)
3853 (pr-ps-file-print filename)))
3854
3855
3856 ;;;###autoload
3857 (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
3858 "Process a PostScript file IFILENAME and send it to printer.
3859
3860 Interactively, the command prompts for N-UP printing number, for an input
3861 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
3862 command prompts the user for an output PostScript file name OFILENAME, and
3863 saves the PostScript image in that file instead of sending it to the printer.
3864
3865 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3866 argument IFILENAME is treated as follows: if it's t, prompts for an input
3867 PostScript file name; otherwise, it *must* be a string that it's an input
3868 PostScript file name. The argument OFILENAME is treated as follows: if it's
3869 nil, send the image to the printer. If OFILENAME is a string, save the
3870 PostScript image in a file with that name. If OFILENAME is t, prompts for a
3871 file name."
3872 (interactive (pr-interactive-n-up-inout
3873 (if pr-print-using-ghostscript
3874 "PS print GS"
3875 "PS print")))
3876 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
3877 (if pr-print-using-ghostscript
3878 "PS print GS "
3879 "PS print "))))
3880 (pr-ps-utility-process n-up ifilename outfile)
3881 (unless ofilename
3882 (pr-ps-file-ps-print outfile)
3883 (pr-delete-file outfile))))
3884
3885
3886 ;;;###autoload
3887 (defun pr-toggle-file-duplex ()
3888 "Toggle duplex for PostScript file."
3889 (interactive)
3890 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
3891 '("PostScript Print" "File")))
3892
3893
3894 ;;;###autoload
3895 (defun pr-toggle-file-tumble ()
3896 "Toggle tumble for PostScript file.
3897
3898 If tumble is off, produces a printing suitable for binding on the left or
3899 right.
3900 If tumble is on, produces a printing suitable for binding at the top or
3901 bottom."
3902 (interactive)
3903 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
3904 '("PostScript Print" "File")))
3905
3906
3907 ;;;###autoload
3908 (defun pr-toggle-file-landscape ()
3909 "Toggle landscape for PostScript file."
3910 (interactive)
3911 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
3912 '("PostScript Print" "File")))
3913
3914
3915 ;;;###autoload
3916 (defun pr-toggle-ghostscript ()
3917 "Toggle printing using ghostscript."
3918 (interactive)
3919 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
3920 'postscript-process 2 12 'toggle))
3921
3922
3923 ;;;###autoload
3924 (defun pr-toggle-faces ()
3925 "Toggle printing with faces."
3926 (interactive)
3927 (pr-toggle 'pr-faces-p "Printing with faces"
3928 'postscript-process 1 12 'toggle))
3929
3930
3931 ;;;###autoload
3932 (defun pr-toggle-spool ()
3933 "Toggle spooling."
3934 (interactive)
3935 (pr-toggle 'pr-spool-p "Spooling printing"
3936 'postscript-process 0 12 'toggle))
3937
3938
3939 ;;;###autoload
3940 (defun pr-toggle-duplex ()
3941 "Toggle duplex."
3942 (interactive)
3943 (pr-toggle 'ps-spool-duplex "Printing duplex"
3944 'postcsript-options 5 12 'toggle))
3945
3946
3947 ;;;###autoload
3948 (defun pr-toggle-tumble ()
3949 "Toggle tumble.
3950
3951 If tumble is off, produces a printing suitable for binding on the left or
3952 right.
3953 If tumble is on, produces a printing suitable for binding at the top or
3954 bottom."
3955 (interactive)
3956 (pr-toggle 'ps-spool-tumble "Tumble"
3957 'postscript-options 6 12 'toggle))
3958
3959
3960 ;;;###autoload
3961 (defun pr-toggle-landscape ()
3962 "Toggle landscape."
3963 (interactive)
3964 (pr-toggle 'ps-landscape-mode "Landscape"
3965 'postscript-options 0 12 'toggle))
3966
3967
3968 ;;;###autoload
3969 (defun pr-toggle-upside-down ()
3970 "Toggle upside-down."
3971 (interactive)
3972 (pr-toggle 'ps-print-upside-down "Upside-Down"
3973 'postscript-options 7 12 'toggle))
3974
3975
3976 ;;;###autoload
3977 (defun pr-toggle-line ()
3978 "Toggle line number."
3979 (interactive)
3980 (pr-toggle 'ps-line-number "Line number"
3981 'postscript-options 3 12 'toggle))
3982
3983
3984 ;;;###autoload
3985 (defun pr-toggle-zebra ()
3986 "Toggle zebra stripes."
3987 (interactive)
3988 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
3989 'postscript-options 4 12 'toggle))
3990
3991
3992 ;;;###autoload
3993 (defun pr-toggle-header ()
3994 "Toggle printing header."
3995 (interactive)
3996 (pr-toggle 'ps-print-header "Print header"
3997 'postscript-options 1 12 'toggle))
3998
3999
4000 ;;;###autoload
4001 (defun pr-toggle-header-frame ()
4002 "Toggle printing header frame."
4003 (interactive)
4004 (pr-toggle 'ps-print-header-frame "Print header frame"
4005 'postscript-options 2 12 'toggle))
4006
4007
4008 ;;;###autoload
4009 (defun pr-toggle-lock ()
4010 "Toggle menu lock."
4011 (interactive)
4012 (pr-toggle 'pr-menu-lock "Menu lock"
4013 'printing 2 12 'toggle))
4014
4015
4016 ;;;###autoload
4017 (defun pr-toggle-region ()
4018 "Toggle auto region."
4019 (interactive)
4020 (pr-toggle 'pr-auto-region "Auto region"
4021 'printing 0 12 'toggle))
4022
4023
4024 ;;;###autoload
4025 (defun pr-toggle-mode ()
4026 "Toggle auto mode."
4027 (interactive)
4028 (pr-toggle 'pr-auto-mode "Auto mode"
4029 'printing 1 12 'toggle))
4030
4031
4032 ;;;###autoload
4033 (defun pr-customize (&rest ignore)
4034 "Customization of the `printing' group."
4035 (interactive)
4036 (customize-group 'printing))
4037
4038
4039 ;;;###autoload
4040 (defun lpr-customize (&rest ignore)
4041 "Customization of the `lpr' group."
4042 (interactive)
4043 (customize-group 'lpr))
4044
4045
4046 ;;;###autoload
4047 (defun pr-help (&rest ignore)
4048 "Help for the printing package."
4049 (interactive)
4050 (pr-show-setup pr-help-message "*Printing Help*"))
4051
4052
4053 ;;;###autoload
4054 (defun pr-ps-name ()
4055 "Interactively select a PostScript printer."
4056 (interactive)
4057 (pr-menu-set-ps-title
4058 (pr-complete-alist "PostScript printer" pr-ps-printer-alist pr-ps-name)))
4059
4060
4061 ;;;###autoload
4062 (defun pr-txt-name ()
4063 "Interactively select a text printer."
4064 (interactive)
4065 (pr-menu-set-txt-title
4066 (pr-complete-alist "Text printer" pr-txt-printer-alist pr-txt-name)))
4067
4068
4069 ;;;###autoload
4070 (defun pr-ps-utility ()
4071 "Interactively select a PostScript utility."
4072 (interactive)
4073 (pr-menu-set-utility-title
4074 (pr-complete-alist "Postscript utility" pr-ps-utility-alist pr-ps-utility)))
4075
4076
4077 ;;;###autoload
4078 (defun pr-show-ps-setup (&rest ignore)
4079 "Show current ps-print settings."
4080 (interactive)
4081 (pr-show-setup (ps-setup) "*PS Setup*"))
4082
4083
4084 ;;;###autoload
4085 (defun pr-show-pr-setup (&rest ignore)
4086 "Show current printing settings."
4087 (interactive)
4088 (pr-show-setup (pr-setup) "*PR Setup*"))
4089
4090
4091 ;;;###autoload
4092 (defun pr-show-lpr-setup (&rest ignore)
4093 "Show current lpr settings."
4094 (interactive)
4095 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4096
4097
4098 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4099 ;; Fast Commands
4100
4101
4102 ;;;###autoload
4103 (defun pr-ps-fast-fire (n-up &optional select)
4104 "Fast fire function for PostScript printing.
4105
4106 If a region is active, the region will be printed instead of the whole buffer.
4107 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4108 `pr-mode-alist' will be used, that is, the current buffer or region will be
4109 printed using `pr-ps-mode-ps-print'.
4110
4111
4112 Interactively, you have the following situations:
4113
4114 M-x pr-ps-fast-fire RET
4115 The command prompts the user for a N-UP value and printing will
4116 immediatelly be done using the current active printer.
4117
4118 C-u M-x pr-ps-fast-fire RET
4119 C-u 0 M-x pr-ps-fast-fire RET
4120 The command prompts the user for a N-UP value and also for a current
4121 PostScript printer, then printing will immediatelly be done using the new
4122 current active printer.
4123
4124 C-u 1 M-x pr-ps-fast-fire RET
4125 The command prompts the user for a N-UP value and also for a file name,
4126 and saves the PostScript image in that file instead of sending it to the
4127 printer.
4128
4129 C-u 2 M-x pr-ps-fast-fire RET
4130 The command prompts the user for a N-UP value, then for a current
4131 PostScript printer and, finally, for a file name. Then change the active
4132 printer to that choosen by user and saves the PostScript image in
4133 that file instead of sending it to the printer.
4134
4135
4136 Noninteractively, the argument N-UP should be a positive integer greater than
4137 zero and the argument SELECT is treated as follows:
4138
4139 If it's nil, send the image to the printer.
4140
4141 If it's a list or an integer lesser or equal to zero, the command prompts
4142 the user for a current PostScript printer, then printing will immediatelly
4143 be done using the new current active printer.
4144
4145 If it's an integer equal to 1, the command prompts the user for a file name
4146 and saves the PostScript image in that file instead of sending it to the
4147 printer.
4148
4149 If it's an integer greater or equal to 2, the command prompts the user for a
4150 current PostScript printer and for a file name. Then change the active
4151 printer to that choosen by user and saves the PostScript image in that file
4152 instead of sending it to the printer.
4153
4154 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4155 active printer and printing will immediatelly be done using the new active
4156 printer.
4157
4158 Otherwise, send the image to the printer.
4159
4160
4161 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4162 are both set to t."
4163 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4164 current-prefix-arg))
4165 (let ((pr-auto-region t)
4166 (pr-auto-mode t)
4167 filename)
4168 (cond ((null select))
4169 ((listp select)
4170 (pr-ps-name))
4171 ((and (symbolp select)
4172 (assq select pr-ps-printer-alist))
4173 (pr-menu-set-ps-title select))
4174 ((integerp select)
4175 (and (/= select 1)
4176 (pr-ps-name))
4177 (and (>= select 1) (not pr-spool-p)
4178 (setq filename (pr-ps-outfile-preprint
4179 (if pr-print-using-ghostscript
4180 "Fast GS "
4181 "Fast "))))))
4182 (pr-ps-buffer-ps-print
4183 (if (integerp n-up)
4184 (min (max n-up 1) 100)
4185 (error "n-up must be an integer greater than zero."))
4186 filename)))
4187
4188
4189 ;;;###autoload
4190 (defun pr-txt-fast-fire (&optional select-printer)
4191 "Fast fire function for text printing.
4192
4193 If a region is active, the region will be printed instead of the whole buffer.
4194 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4195 `pr-mode-alist' will be used, that is, the current buffer or region will be
4196 printed using `pr-txt-mode'.
4197
4198 Interactively, when you use a prefix argument (C-u), the command prompts the
4199 user for a new active text printer.
4200
4201 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4202
4203 If it's nil, the printing is sent to the current active text printer.
4204
4205 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4206 active printer and printing will immediatelly be done using the new active
4207 printer.
4208
4209 If it's non-nil, the command prompts the user for a new active text printer.
4210
4211 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4212 are both set to t."
4213 (interactive (list current-prefix-arg))
4214 (cond ((null select-printer))
4215 ((and (symbolp select-printer)
4216 (assq select-printer pr-txt-printer-alist))
4217 (pr-menu-set-txt-title select-printer))
4218 (t
4219 (pr-txt-name)))
4220 (let ((pr-auto-region t)
4221 (pr-auto-mode t))
4222 (pr-txt-buffer)))
4223
4224
4225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4226 ;; Utilities
4227
4228
4229 (defun pr-setup ()
4230 "Return the current `printing' setup.
4231
4232 This is *not* an interactive command.
4233 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4234
4235 M-: (insert (pr-setup)) RET
4236
4237 Or choose the menu option Printing/Show Settings/printing."
4238 (let (ps-prefix-quote)
4239 (mapconcat
4240 #'ps-print-quote
4241 (list
4242 (concat "\n;;; printing.el version " pr-version "\n")
4243 '(19 . pr-shell-file-name)
4244 '(19 . pr-path-style)
4245 '(19 . pr-path-alist)
4246 nil
4247 '(21 . pr-txt-name)
4248 '(21 . pr-txt-printer-alist)
4249 nil
4250 '(20 . pr-ps-name)
4251 '(20 . pr-ps-printer-alist)
4252 nil
4253 '(20 . pr-temp-dir)
4254 '(20 . pr-ps-temp-file)
4255 '(20 . pr-delete-temp-file)
4256 '(20 . pr-list-directory)
4257 nil
4258 '(17 . pr-gv-command)
4259 '(17 . pr-gs-command)
4260 '(17 . pr-gs-switches)
4261 '(17 . pr-gs-device)
4262 '(17 . pr-gs-resolution)
4263 nil
4264 '(27 . pr-print-using-ghostscript)
4265 '(27 . pr-faces-p)
4266 '(27 . pr-spool-p)
4267 '(27 . pr-file-landscape)
4268 '(27 . pr-file-duplex)
4269 '(27 . pr-file-tumble)
4270 '(27 . pr-auto-region)
4271 '(27 . pr-auto-mode)
4272 nil
4273 '(20 . pr-ps-utility)
4274 '(20 . pr-ps-utility-alist)
4275 nil
4276 '(14 . pr-mode-alist)
4277 nil
4278 '(20 . pr-menu-lock)
4279 '(20 . pr-menu-char-height)
4280 '(20 . pr-menu-char-width)
4281 nil
4282 '(20 . pr-setting-database)
4283 nil
4284 '(22 . pr-visible-entry-list)
4285 nil
4286 '(22 . pr-buffer-verbose)
4287 '(22 . pr-buffer-name)
4288 '(22 . pr-buffer-name-ignore)
4289 ")\n\n;;; printing.el - end of settings\n")
4290 "\n")))
4291
4292
4293 (defun lpr-setup ()
4294 "Return the current `lpr' setup.
4295
4296 This is *not* an interactive command.
4297 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4298
4299 M-: (insert (lpr-setup)) RET
4300
4301 Or choose the menu option Printing/Show Settings/lpr."
4302 (let (ps-prefix-quote)
4303 (mapconcat
4304 #'ps-print-quote
4305 '("\n;;; lpr.el settings\n"
4306 (25 . printer-name)
4307 (25 . lpr-switches)
4308 (25 . lpr-add-switches)
4309 (25 . lpr-command)
4310 (25 . lpr-headers-switches)
4311 (25 . print-region-function)
4312 (25 . lpr-page-header-program)
4313 (25 . lpr-page-header-switches)
4314 ")\n\n;;; lpr.el - end of settings\n")
4315 "\n")))
4316
4317
4318 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4319 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4320
4321
4322 (defalias 'pr-mh-get-msg-num 'mh-get-msg-num)
4323 (defalias 'pr-mh-show 'mh-show)
4324 (defalias 'pr-mh-start-of-uncleaned-message 'mh-start-of-uncleaned-message)
4325 (defvar mh-show-buffer nil)
4326
4327
4328 (defun pr-article-date ()
4329 "Find the date of an article or mail message in current buffer.
4330 Return only the dayname, if present, weekday, month, and year."
4331 (save-excursion
4332 (goto-char (point-min))
4333 (if (re-search-forward
4334 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4335 (buffer-substring (match-beginning 1) (match-end 1))
4336 (format-time-string "%Y/%m/%d"))))
4337
4338
4339 (defun pr-mh-current-message ()
4340 "Go to mh-inbox current message."
4341 (let ((msg (or (pr-mh-get-msg-num nil) 0)))
4342 (pr-mh-show)
4343 (set-buffer mh-show-buffer)
4344 (goto-char (point-min))
4345 (pr-mh-start-of-uncleaned-message)
4346 (message "Printing message %d" msg)))
4347
4348
4349 (defun pr-mh-print-1 (n-up filename header-list)
4350 "Print mh-inbox current message in PostScript."
4351 (save-excursion
4352 (save-window-excursion
4353 (pr-mh-current-message)
4354 (pr-mode-print n-up filename header-list (point)))))
4355
4356
4357 (defun pr-mh-lpr-1 (header-list)
4358 "Print mh-inbox current message in text printer."
4359 (save-excursion
4360 (save-window-excursion
4361 (pr-mh-current-message)
4362 (pr-mode-lpr header-list (point)))))
4363
4364
4365 (defalias 'pr-mh-print-2 'pr-mode-print)
4366
4367
4368 (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
4369
4370
4371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4372 ;; rmail (hacked from ps-print.el)
4373
4374
4375 (defun pr-rmail-lpr (header-list)
4376 "Print RMAIL current message in text printer."
4377 (pr-lpr-message-from-summary header-list
4378 'rmail-buffer 'rmail-summary-buffer))
4379
4380
4381 (defun pr-rmail-print (n-up filename header-list)
4382 "Print RMAIL current message in PostScript."
4383 (pr-ps-message-from-summary n-up filename header-list
4384 'rmail-buffer 'rmail-summary-buffer))
4385
4386
4387 (defun pr-ps-message-from-summary (n-up filename header-list
4388 summary-buffer summary-default)
4389 "Print current message in PostScript."
4390 (let ((buf (or (and (boundp summary-buffer)
4391 (symbol-value summary-buffer))
4392 (symbol-value summary-default))))
4393 (and (get-buffer buf)
4394 (save-excursion
4395 (set-buffer buf)
4396 (pr-mode-print n-up filename header-list)))))
4397
4398
4399 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
4400 "Print current message in text printer."
4401 (let ((buf (or (and (boundp summary-buffer)
4402 (symbol-value summary-buffer))
4403 (symbol-value summary-default))))
4404 (and (get-buffer buf)
4405 (save-excursion
4406 (set-buffer buf)
4407 (pr-mode-lpr header-list)))))
4408
4409
4410 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4411 ;; gnus (hacked from ps-print.el)
4412
4413
4414 (defvar pr-gnus-article "*Article*")
4415
4416
4417 (defun pr-gnus-print (n-up filename header-list)
4418 "Print *Article* current message in PostScript."
4419 (pr-ps-message-from-summary n-up filename header-list
4420 'gnus-article-buffer 'pr-gnus-article))
4421
4422
4423 (defun pr-gnus-lpr (header-list)
4424 "Print *Article* current message in text printer."
4425 (pr-lpr-message-from-summary header-list
4426 'gnus-article-buffer 'pr-gnus-article))
4427
4428
4429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4430 ;; vm (hacked from ps-print.el)
4431
4432
4433 (defvar pr-vm-summary "")
4434
4435
4436 (defun pr-vm-print (n-up filename header-list)
4437 "Print current vm message in PostScript."
4438 (pr-ps-message-from-summary n-up filename header-list
4439 'vm-mail-buffer 'pr-vm-summary))
4440
4441
4442 (defun pr-vm-lpr (header-list)
4443 "Print current vm message in text printer."
4444 (pr-lpr-message-from-summary header-list
4445 'vm-mail-buffer 'pr-vm-summary))
4446
4447
4448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4449 ;; Mode Functions
4450
4451
4452 (defun pr-ps-mode (n-up filename)
4453 "If current major mode is declared, print it in PostScript."
4454 (let ((args (pr-mode-alist-p)))
4455 (if args
4456 (let ((fun (cdr args)))
4457 (funcall (car fun) n-up filename (cdr fun))
4458 t)
4459 (ding)
4460 (message "`%s' major mode not declared." major-mode)
4461 nil)))
4462
4463
4464 (defmacro pr-local-variable (header-list &rest body)
4465 `(save-excursion
4466 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
4467 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
4468 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
4469 ps-razzle-dazzle)
4470 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
4471 ,@body
4472 (and (nth 3 ,header-list)
4473 (pr-kill-local-variable local-var-list))))))
4474
4475
4476 (defun pr-mode-print (n-up filename header-list &optional from to)
4477 "Print current major mode in PostScript."
4478 (pr-local-variable
4479 header-list
4480 (let ((file (pr-ps-file filename))
4481 (start (cond (from)
4482 ((pr-region-active-p) (region-beginning))
4483 (t nil)
4484 )))
4485 (pr-text2ps (pr-region-active-symbol start) n-up file start
4486 (cond (to)
4487 ((pr-region-active-p) (region-end))
4488 (from (point-max))
4489 ))
4490 (unless (or pr-spool-p filename)
4491 (pr-ps-file-print file)
4492 (pr-delete-file file)))))
4493
4494
4495 (defun pr-mode-lpr (header-list &optional from to)
4496 "Print current major mode in text printer."
4497 (pr-local-variable
4498 header-list
4499 (pr-txt-print (cond (from)
4500 ((pr-region-active-p) (region-beginning))
4501 (t (point-min)))
4502 (cond (to)
4503 ((pr-region-active-p) (region-end))
4504 (t (point-max))))))
4505
4506
4507 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4508 ;; Menu Lock
4509
4510
4511 (defconst pr-menu-entry-alist
4512 '((postscript . 3)
4513 (text . 3)
4514 (postscript-options . 9)
4515 (postscript-process . 3)
4516 (printing . 3)
4517 (help . 3)
4518 )
4519 "Alist that associates menu part with number of items per part.
4520
4521 It's used by `pr-menu-index'.
4522
4523 Each element has the form:
4524
4525 (MENU-PART . NUMBER-OF-ITEMS)
4526
4527 See `pr-visible-entry-alist'.")
4528
4529
4530 (defun pr-menu-index (entry index)
4531 (let ((base-list
4532 (cond ((eq entry 'text)
4533 '(postscript))
4534 ((eq entry 'postscript-options)
4535 '(postscript text))
4536 ((eq entry 'postscript-process)
4537 '(postscript text postscript-options))
4538 ((eq entry 'printing)
4539 '(postscript text postscript-options postscript-process))
4540 (t
4541 nil)
4542 ))
4543 key)
4544 (while base-list
4545 (setq key (car base-list)
4546 base-list (cdr base-list))
4547 (and (pr-visible-p key)
4548 (setq index (+ index
4549 (cdr (assq key pr-menu-entry-alist)))))))
4550 (+ index 2))
4551
4552
4553 (defvar pr-menu-position nil)
4554 (defvar pr-menu-state nil)
4555
4556
4557 (eval-and-compile
4558 (cond
4559 ((eq ps-print-emacs-type 'xemacs)
4560 ;; XEmacs
4561 (defun pr-menu-position (entry index horizontal)
4562 (pr-x-make-event
4563 'button-release
4564 (list 'button 1
4565 'x (- (pr-x-event-x-pixel current-mouse-event) ; X
4566 (* horizontal pr-menu-char-width))
4567 'y (- (pr-x-event-y-pixel current-mouse-event) ; Y
4568 (* (pr-menu-index entry index) pr-menu-char-height)))))
4569 )
4570 (ps-windows-system
4571 ;; GNU Emacs for Windows 9x/NT
4572 (defun pr-menu-position (entry index horizontal)
4573 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4574 (list
4575 (list (car pos) ; X
4576 (- (cdr pos) ; Y
4577 (* (pr-menu-index entry index) pr-menu-char-height)))
4578 (selected-frame)))) ; frame
4579 )
4580 (t
4581 ;; GNU Emacs
4582 (defun pr-menu-position (entry index horizontal)
4583 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4584 (list
4585 (list (- (car pos) ; X
4586 (* horizontal pr-menu-char-width))
4587 (- (cdr pos) ; Y
4588 (* (pr-menu-index entry index) pr-menu-char-height)))
4589 (selected-frame)))) ; frame
4590 ))
4591
4592 (cond
4593 ((eq ps-print-emacs-type 'emacs)
4594 ;; GNU Emacs
4595 (defun pr-menu-lookup (path)
4596 (let ((ipath pr-menu-bar))
4597 (lookup-key global-map
4598 (if path
4599 (vconcat ipath
4600 (mapcar 'pr-get-symbol
4601 (if (listp path)
4602 path
4603 (list path))))
4604 ipath))))
4605
4606 ;; GNU Emacs
4607 (defun pr-menu-lock (entry index horizontal state path)
4608 (when (and (not (interactive-p)) pr-menu-lock)
4609 (or (and pr-menu-position (eq state pr-menu-state))
4610 (setq pr-menu-position (pr-menu-position entry index horizontal)
4611 pr-menu-state state))
4612 (let* ((menu (pr-menu-lookup path))
4613 (result (x-popup-menu pr-menu-position menu)))
4614 (and result
4615 (let ((command (lookup-key menu (vconcat result))))
4616 (if (fboundp command)
4617 (funcall command)
4618 (eval command)))))
4619 (setq pr-menu-position nil))))
4620
4621
4622 ((eq ps-print-emacs-type 'xemacs)
4623 ;; XEmacs
4624 (defun pr-menu-lookup (path)
4625 (car (pr-x-find-menu-item current-menubar (cons "Printing" path))))
4626
4627 ;; XEmacs
4628 (defun pr-menu-lock (entry index horizontal state path)
4629 (when (and (not (interactive-p)) pr-menu-lock)
4630 (or (and pr-menu-position (eq state pr-menu-state))
4631 (setq pr-menu-position (pr-menu-position entry index horizontal)
4632 pr-menu-state state))
4633 (let* ((menu (pr-menu-lookup path))
4634 (result (pr-x-get-popup-menu-response menu pr-menu-position)))
4635 (and (pr-x-misc-user-event-p result)
4636 (funcall (pr-x-event-function result)
4637 (pr-x-event-object result))))
4638 (setq pr-menu-position nil))))))
4639
4640
4641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4642 ;; Printer & Utility Selection
4643
4644
4645 (defun pr-update-var (var-sym alist)
4646 (or (assq (symbol-value var-sym) alist)
4647 (set var-sym (car (car alist)))))
4648
4649
4650 (defun pr-update-menus (&optional force)
4651 "Update utility, PostScript and text printer menus.
4652
4653 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
4654 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
4655 otherwise, update PostScript printer menu iff `pr-ps-printer-menu-modified' is
4656 non-nil, update text printer menu iff `pr-txt-printer-menu-modified' is
4657 non-nil, and update PostScript File menus iff `pr-ps-utility-menu-modified' is
4658 non-nil."
4659 (interactive)
4660 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
4661 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
4662 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
4663 (pr-do-update-menus force))
4664
4665
4666 (defvar pr-ps-printer-menu-modified t
4667 "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
4668 (defvar pr-txt-printer-menu-modified t
4669 "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
4670 (defvar pr-ps-utility-menu-modified t
4671 "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
4672
4673
4674 (defconst pr-even-or-odd-alist
4675 '((nil . "Print All Pages")
4676 (even-page . "Print Even Pages")
4677 (odd-page . "Print Odd Pages")
4678 (even-sheet . "Print Even Sheets")
4679 (odd-sheet . "Print Odd Sheets")))
4680
4681
4682 (defun pr-menu-create (name alist var-sym fun entry index)
4683 (cons name
4684 (mapcar
4685 #'(lambda (elt)
4686 (let ((sym (car elt)))
4687 (vector
4688 (symbol-name sym)
4689 (list fun (list 'quote sym) nil (list 'quote entry) index)
4690 :style 'radio
4691 :selected (list 'eq var-sym (list 'quote sym)))))
4692 alist)))
4693
4694
4695 (eval-and-compile
4696 (cond
4697 ((eq ps-print-emacs-type 'emacs)
4698 ;; GNU Emacs
4699 (defalias 'pr-update-mode-line 'force-mode-line-update)
4700
4701 ;; GNU Emacs
4702 (defun pr-do-update-menus (&optional force)
4703 (pr-menu-alist pr-ps-printer-alist
4704 'pr-ps-name
4705 'pr-menu-set-ps-title
4706 "PostScript Printers"
4707 'pr-ps-printer-menu-modified
4708 force
4709 "PostScript Printers"
4710 'postscript 2)
4711 (pr-menu-alist pr-txt-printer-alist
4712 'pr-txt-name
4713 'pr-menu-set-txt-title
4714 "Text Printers"
4715 'pr-txt-printer-menu-modified
4716 force
4717 "Text Printers"
4718 'text 2)
4719 (let ((save-var pr-ps-utility-menu-modified))
4720 (pr-menu-alist pr-ps-utility-alist
4721 'pr-ps-utility
4722 'pr-menu-set-utility-title
4723 '("PostScript Print" "File" "PostScript Utility")
4724 'save-var
4725 force
4726 "PostScript Utility"
4727 nil 1))
4728 (pr-menu-alist pr-ps-utility-alist
4729 'pr-ps-utility
4730 'pr-menu-set-utility-title
4731 '("PostScript Preview" "File" "PostScript Utility")
4732 'pr-ps-utility-menu-modified
4733 force
4734 "PostScript Utility"
4735 nil 1)
4736 (pr-even-or-odd-pages ps-even-or-odd-pages force))
4737
4738 ;; GNU Emacs
4739 (defvar pr-temp-menu nil)
4740
4741 ;; GNU Emacs
4742 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
4743 entry index)
4744 (when (and alist (or force (symbol-value modified-sym)))
4745 (easy-menu-define pr-temp-menu nil ""
4746 (pr-menu-create name alist var-sym fun entry index))
4747 (let ((item (pr-menu-get-item menu-path)))
4748 (and item
4749 (let* ((binding (nthcdr 3 item))
4750 (key-binding (cdr binding)))
4751 (setcar binding pr-temp-menu)
4752 (and key-binding (listp (car key-binding))
4753 (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
4754 (funcall fun (symbol-value var-sym) item))))
4755 (set modified-sym nil)))
4756
4757 ;; GNU Emacs
4758 (defun pr-menu-set-ps-title (value &optional item entry index)
4759 (pr-menu-set-item-name (or item
4760 (pr-menu-get-item "PostScript Printers"))
4761 (format "PostScript Printer: %s" value))
4762 (pr-ps-set-printer value)
4763 (and index
4764 (pr-menu-lock entry index 12 'toggle nil)))
4765
4766 ;; GNU Emacs
4767 (defun pr-menu-set-txt-title (value &optional item entry index)
4768 (pr-menu-set-item-name (or item
4769 (pr-menu-get-item "Text Printers"))
4770 (format "Text Printer: %s" value))
4771 (pr-txt-set-printer value)
4772 (and index
4773 (pr-menu-lock entry index 12 'toggle nil)))
4774
4775 ;; GNU Emacs
4776 (defun pr-menu-set-utility-title (value &optional item entry index)
4777 (let ((name (symbol-name value)))
4778 (if item
4779 (pr-menu-set-item-name item name)
4780 (pr-menu-set-item-name
4781 (pr-menu-get-item
4782 '("PostScript Print" "File" "PostScript Utility"))
4783 name)
4784 (pr-menu-set-item-name
4785 (pr-menu-get-item
4786 '("PostScript Preview" "File" "PostScript Utility"))
4787 name)))
4788 (pr-ps-set-utility value)
4789 (and index
4790 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
4791
4792 ;; GNU Emacs
4793 (defun pr-even-or-odd-pages (value &optional no-lock)
4794 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
4795 (cdr (assq value pr-even-or-odd-alist)))
4796 (setq ps-even-or-odd-pages value)
4797 (or no-lock
4798 (pr-menu-lock 'postscript-options 8 12 'toggle nil))))
4799
4800
4801 ((eq ps-print-emacs-type 'xemacs)
4802 ;; XEmacs
4803 (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
4804
4805 ;; XEmacs
4806 (defvar pr-ps-name-old "PostScript Printers")
4807 (defvar pr-txt-name-old "Text Printers")
4808 (defvar pr-ps-utility-old "PostScript Utility")
4809 (defvar pr-even-or-odd-old "Print All Pages")
4810
4811 ;; XEmacs
4812 (defun pr-do-update-menus (&optional force)
4813 (pr-menu-alist pr-ps-printer-alist
4814 'pr-ps-name
4815 'pr-menu-set-ps-title
4816 '("Printing")
4817 'pr-ps-printer-menu-modified
4818 force
4819 pr-ps-name-old
4820 'postscript 2)
4821 (pr-menu-alist pr-txt-printer-alist
4822 'pr-txt-name
4823 'pr-menu-set-txt-title
4824 '("Printing")
4825 'pr-txt-printer-menu-modified
4826 force
4827 pr-txt-name-old
4828 'text 2)
4829 (let ((save-var pr-ps-utility-menu-modified))
4830 (pr-menu-alist pr-ps-utility-alist
4831 'pr-ps-utility
4832 'pr-menu-set-utility-title
4833 '("Printing" "PostScript Print" "File")
4834 'save-var
4835 force
4836 pr-ps-utility-old
4837 nil 1))
4838 (pr-menu-alist pr-ps-utility-alist
4839 'pr-ps-utility
4840 'pr-menu-set-utility-title
4841 '("Printing" "PostScript Preview" "File")
4842 'pr-ps-utility-menu-modified
4843 force
4844 pr-ps-utility-old
4845 nil 1)
4846 (pr-even-or-odd-pages ps-even-or-odd-pages force))
4847
4848 ;; XEmacs
4849 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
4850 entry index)
4851 (when (and alist (or force (symbol-value modified-sym)))
4852 (pr-xemacs-global-menubar
4853 (pr-x-add-submenu menu-path
4854 (pr-menu-create name alist var-sym
4855 fun entry index)))
4856 (funcall fun (symbol-value var-sym))
4857 (set modified-sym nil)))
4858
4859 ;; XEmacs
4860 (defun pr-menu-set-ps-title (value &optional item entry index)
4861 (pr-relabel-menu-item (format "PostScript Printer: %s" value)
4862 'pr-ps-name-old)
4863 (pr-ps-set-printer value)
4864 (and index
4865 (pr-menu-lock entry index 12 'toggle nil)))
4866
4867 ;; XEmacs
4868 (defun pr-menu-set-txt-title (value &optional item entry index)
4869 (pr-relabel-menu-item (format "Text Printer: %s" value)
4870 'pr-txt-name-old)
4871 (pr-txt-set-printer value)
4872 (and index
4873 (pr-menu-lock entry index 12 'toggle nil)))
4874
4875 ;; XEmacs
4876 (defun pr-menu-set-utility-title (value &optional item entry index)
4877 (pr-xemacs-global-menubar
4878 (let ((newname (format "%s" value)))
4879 (pr-x-relabel-menu-item
4880 (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
4881 newname)
4882 (pr-x-relabel-menu-item
4883 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
4884 newname)
4885 (setq pr-ps-utility-old newname)))
4886 (pr-ps-set-utility value)
4887 (and index
4888 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
4889
4890 ;; XEmacs
4891 (defun pr-even-or-odd-pages (value &optional no-lock)
4892 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
4893 'pr-even-or-odd-old)
4894 (setq ps-even-or-odd-pages value)
4895 (or no-lock
4896 (pr-menu-lock 'postscript-options 8 12 'toggle nil))))))
4897
4898 ;; XEmacs
4899 (defun pr-relabel-menu-item (newname var-sym)
4900 (pr-xemacs-global-menubar
4901 (pr-x-relabel-menu-item
4902 (list "Printing" (symbol-value var-sym))
4903 newname)
4904 (set var-sym newname)))
4905
4906 ;; GNU Emacs
4907 (defun pr-menu-set-item-name (item name)
4908 (and item
4909 (setcar (nthcdr 2 item) name))) ; ITEM-NAME
4910
4911 ;; GNU Emacs
4912 (defun pr-menu-get-item (name-list)
4913 ;; NAME-LIST is a string or a list of strings.
4914 (let ((ipath pr-menu-bar)
4915 (len (and (listp name-list) (length name-list))))
4916 (and len (= len 1)
4917 (setq name-list (car name-list)))
4918 (cond
4919 ((null name-list)
4920 ;; nil
4921 nil)
4922 ((listp name-list)
4923 ;; list and (length list) > 1
4924 (let* ((copy (copy-sequence name-list))
4925 (name (pr-get-symbol (nth (1- len) copy)))
4926 (path (progn
4927 (setcdr (nthcdr (- len 2) copy) nil)
4928 copy))
4929 (menu (lookup-key
4930 global-map
4931 (if path
4932 (vconcat ipath
4933 (mapcar 'pr-get-symbol path))
4934 ipath))))
4935 (assq name (nthcdr 2 menu))))
4936 (t
4937 ;; string
4938 (let ((name (pr-get-symbol name-list))
4939 (menu (lookup-key global-map ipath)))
4940 (assq name (nthcdr 2 menu)))))))
4941
4942
4943 (defun pr-ps-set-utility (value)
4944 (let ((item (cdr (assq value pr-ps-utility-alist))))
4945 (or item
4946 (error
4947 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'."
4948 value))
4949 (setq pr-ps-utility value)
4950 (pr-eval-alist (nthcdr 9 item)))
4951 (pr-update-mode-line))
4952
4953
4954 (defun pr-ps-set-printer (value)
4955 (let ((ps (cdr (assq value pr-ps-printer-alist))))
4956 (or ps
4957 (error
4958 "Invalid PostScript printer name `%s' for variable `pr-ps-name'."
4959 value))
4960 (setq pr-ps-name value
4961 pr-ps-command (pr-dosify-path (nth 0 ps))
4962 pr-ps-switches (nth 1 ps)
4963 pr-ps-printer-switch (nth 2 ps)
4964 pr-ps-printer (pr-dosify-path (nth 3 ps)))
4965 (or (stringp pr-ps-command)
4966 (setq pr-ps-command
4967 (cond (ps-windows-system "print")
4968 (ps-lp-system "lp")
4969 (t "lpr")
4970 )))
4971 (or (stringp pr-ps-printer-switch)
4972 (setq pr-ps-printer-switch
4973 (cond (ps-windows-system "/D:")
4974 (ps-lp-system "-d")
4975 (t "-P")
4976 )))
4977 (pr-eval-alist (nthcdr 4 ps)))
4978 (pr-update-mode-line))
4979
4980
4981 (defun pr-txt-set-printer (value)
4982 (let ((txt (cdr (assq value pr-txt-printer-alist))))
4983 (or txt
4984 (error "Invalid text printer name `%s' for variable `pr-txt-name'."
4985 value))
4986 (setq pr-txt-name value
4987 pr-txt-command (pr-dosify-path (nth 0 txt))
4988 pr-txt-switches (nth 1 txt)
4989 pr-txt-printer (pr-dosify-path (nth 2 txt))))
4990 (or (stringp pr-txt-command)
4991 (setq pr-txt-command
4992 (cond (ps-windows-system "print")
4993 (ps-lp-system "lp")
4994 (t "lpr")
4995 )))
4996 (pr-update-mode-line))
4997
4998
4999 (defun pr-eval-alist (alist)
5000 (mapcar #'(lambda (option)
5001 (let ((var-sym (car option))
5002 (value (cdr option)))
5003 (if (eq var-sym 'inherits-from:)
5004 (pr-eval-setting-alist value 'global)
5005 (set var-sym (eval value)))))
5006 alist))
5007
5008
5009 (defun pr-eval-local-alist (alist)
5010 (let (local-list)
5011 (mapcar #'(lambda (option)
5012 (let ((var-sym (car option))
5013 (value (cdr option)))
5014 (setq local-list
5015 (if (eq var-sym 'inherits-from:)
5016 (nconc (pr-eval-setting-alist value) local-list)
5017 (set (make-local-variable var-sym) (eval value))
5018 (cons var-sym local-list)))))
5019 alist)
5020 local-list))
5021
5022
5023 (defun pr-eval-setting-alist (key &optional global old)
5024 (let ((setting (cdr (assq key pr-setting-database))))
5025 (and setting
5026 (let ((inherits (nth 0 setting))
5027 (local (nth 1 setting))
5028 (kill (nth 2 setting))
5029 local-list)
5030 (and local global
5031 (progn
5032 (ding)
5033 (message "There are local buffer settings for `%S'." key)
5034 (setq global nil)))
5035 (and inherits
5036 (if (memq inherits old)
5037 (error "Circular inheritance for `%S'." inherits)
5038 (setq local-list
5039 (pr-eval-setting-alist inherits global
5040 (cons inherits old)))))
5041 (mapcar
5042 (cond ((not local) ; global settings
5043 #'(lambda (option)
5044 (let ((var-sym (car option)))
5045 (or (eq var-sym 'inherits-from:)
5046 (set var-sym (eval (cdr option)))))))
5047 (kill ; local settings with killing
5048 #'(lambda (option)
5049 (let ((var-sym (car option)))
5050 (unless (eq var-sym 'inherits-from:)
5051 (setq local-list (cons var-sym local-list))
5052 (set (make-local-variable var-sym)
5053 (eval (cdr option)))))))
5054 (t ; local settings without killing
5055 #'(lambda (option)
5056 (let ((var-sym (car option)))
5057 (or (eq var-sym 'inherits-from:)
5058 (set (make-local-variable var-sym)
5059 (eval (cdr option))))))))
5060 (nthcdr 3 setting))
5061 local-list))))
5062
5063
5064 (defun pr-kill-local-variable (local-var-list)
5065 (mapcar 'kill-local-variable local-var-list))
5066
5067
5068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5069 ;; Internal Functions (II)
5070
5071
5072 (defun pr-prompt (str)
5073 (if (pr-auto-mode-p)
5074 (concat str " mode")
5075 (pr-region-active-string str)))
5076
5077
5078 (defun pr-prompt-region (str)
5079 (concat str (if (pr-auto-mode-p)
5080 " mode"
5081 " region")))
5082
5083
5084 (defun pr-prompt-gs (str)
5085 (if (pr-using-ghostscript-p)
5086 (concat str " GS")
5087 str))
5088
5089
5090 (defun pr-region-active-symbol (&optional region-p)
5091 (if (or region-p (pr-region-active-p))
5092 'region
5093 'buffer))
5094
5095
5096 (defun pr-region-active-string (prefix)
5097 (concat prefix
5098 (if (pr-region-active-p)
5099 " region"
5100 " buffer")))
5101
5102
5103 (defun pr-show-setup (settings buffer-name)
5104 (with-output-to-temp-buffer buffer-name
5105 (princ settings)
5106 (print-help-return-message)))
5107
5108
5109 (defun pr-complete-alist (prompt alist default)
5110 (let ((collection (mapcar #'(lambda (elt)
5111 (setq elt (car elt))
5112 (cons (symbol-name elt) elt))
5113 alist)))
5114 (cdr (assoc (completing-read (concat prompt ": ")
5115 collection nil t
5116 (symbol-name default) nil
5117 (symbol-name default))
5118 collection))))
5119
5120
5121 (defun pr-delete-file (file)
5122 (and pr-delete-temp-file (delete-file file)))
5123
5124
5125 (defun pr-expand-file-name (filename)
5126 (pr-dosify-path (expand-file-name filename)))
5127
5128
5129 (defun pr-ps-outfile-preprint (&optional mess)
5130 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5131 (res (read-file-name prompt default-directory "" nil)))
5132 (while (cond ((not (file-writable-p res))
5133 (ding)
5134 (setq prompt "is unwritable"))
5135 ((file-directory-p res)
5136 (ding)
5137 (setq prompt "is a directory"))
5138 ((file-exists-p res)
5139 (ding)
5140 (setq prompt "exists")
5141 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5142 res))))
5143 (t nil))
5144 (setq res (read-file-name
5145 (format "File %s; PostScript file: " prompt)
5146 (file-name-directory res) nil nil
5147 (file-name-nondirectory res))))
5148 (pr-expand-file-name res)))
5149
5150
5151 (defun pr-ps-infile-preprint (&optional mess)
5152 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5153 (res (read-file-name prompt default-directory "" nil)))
5154 (while (cond ((not (file-exists-p res))
5155 (ding)
5156 (setq prompt "doesn't exist"))
5157 ((not (file-readable-p res))
5158 (ding)
5159 (setq prompt "is unreadable"))
5160 ((file-directory-p res)
5161 (ding)
5162 (setq prompt "is a directory"))
5163 (t nil))
5164 (setq res (read-file-name
5165 (format "File %s; PostScript file: " prompt)
5166 (file-name-directory res) nil nil
5167 (file-name-nondirectory res))))
5168 (pr-expand-file-name res)))
5169
5170
5171 (defun pr-toggle (var-sym mess entry index horizontal state &optional path)
5172 (set var-sym (not (symbol-value var-sym)))
5173 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5174 (pr-menu-lock entry index horizontal state path))
5175
5176
5177 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
5178 ;; n-up
5179 (or (symbol-value n-up-sym)
5180 (set n-up-sym (pr-interactive-n-up prompt)))
5181 (and (eq (symbol-value infile-sym) t)
5182 (set infile-sym (and (not (interactive-p))
5183 (pr-ps-infile-preprint prompt))))
5184 ;; input file
5185 (or (symbol-value infile-sym)
5186 (error "%s: input PostScript file name is missing" prompt))
5187 (set infile-sym (pr-dosify-path (symbol-value infile-sym)))
5188 ;; output file
5189 (and (eq (symbol-value outfile-sym) t)
5190 (set outfile-sym (and (not (interactive-p))
5191 current-prefix-arg
5192 (pr-ps-outfile-preprint prompt))))
5193 (and (symbol-value outfile-sym)
5194 (set outfile-sym (pr-dosify-path (symbol-value outfile-sym))))
5195 (pr-ps-file (symbol-value outfile-sym)))
5196
5197
5198 (defun pr-ps-utility-process (n-up infile outfile)
5199 (let (item)
5200 (and (stringp infile) (file-exists-p infile)
5201 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
5202 (pr-shell-command
5203 (concat (pr-command (nth 0 item)) " "
5204 (pr-switches-string (nth 1 item)
5205 "pr-ps-utility-alist entry")
5206 " "
5207 (pr-switches-string (nth 8 item)
5208 "pr-ps-utility-alist entry")
5209 " "
5210 (and (nth 2 item)
5211 (format (nth 2 item) ps-paper-type))
5212 " " (format (nth 3 item) n-up) " "
5213 (and pr-file-landscape (nth 4 item)) " "
5214 (and pr-file-duplex (nth 5 item)) " "
5215 (and pr-file-tumble (nth 6 item))
5216 " \"" (pr-expand-file-name infile) "\" "
5217 (nth 7 item)
5218 " \"" (pr-expand-file-name outfile) "\"")))))
5219
5220
5221 (defun pr-shell-command (command)
5222 (let ((shell-file-name pr-shell-file-name))
5223 (shell-command command)))
5224
5225
5226 (defun pr-txt-print (from to)
5227 (let ((lpr-command (pr-command pr-txt-command))
5228 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5229 (printer-name pr-txt-printer))
5230 (lpr-region from to)))
5231
5232
5233 (defun pr-switches-string (switches mess)
5234 (mapconcat 'identity (pr-switches switches mess) " "))
5235
5236
5237 (defun pr-switches (switches mess)
5238 (or (listp switches)
5239 (error "%S should have a list of strings." mess))
5240 (ps-flatten-list ; dynamic evaluation
5241 (mapcar 'ps-eval-switch switches)))
5242
5243
5244 (defun pr-ps-preview (kind n-up filename mess)
5245 (pr-set-n-up-and-filename 'n-up 'filename mess)
5246 (let ((file (pr-ps-file filename)))
5247 (pr-text2ps kind n-up file)
5248 (or pr-spool-p (pr-ps-file-preview file))))
5249
5250
5251 (defun pr-ps-using-ghostscript (kind n-up filename mess)
5252 (pr-set-n-up-and-filename 'n-up 'filename mess)
5253 (let ((file (pr-ps-file filename)))
5254 (pr-text2ps kind n-up file)
5255 (unless (or pr-spool-p filename)
5256 (pr-ps-file-using-ghostscript file)
5257 (pr-delete-file file))))
5258
5259
5260 (defun pr-ps-print (kind n-up filename mess)
5261 (pr-set-n-up-and-filename 'n-up 'filename mess)
5262 (let ((file (pr-ps-file filename)))
5263 (pr-text2ps kind n-up file)
5264 (unless (or pr-spool-p filename)
5265 (pr-ps-file-print file)
5266 (pr-delete-file file))))
5267
5268
5269 (defun pr-ps-file (&optional filename)
5270 (pr-dosify-path (or filename
5271 (convert-standard-filename
5272 (expand-file-name pr-ps-temp-file pr-temp-dir)))))
5273
5274
5275 (defun pr-interactive-n-up (mess)
5276 (or (stringp mess) (setq mess "*"))
5277 (save-match-data
5278 (let* ((fmt-prompt "%s[%s] N-up printing: (default 1) ")
5279 (prompt "")
5280 (str (pr-f-read-string (format fmt-prompt prompt mess) "1" nil "1"))
5281 int)
5282 (while (if (string-match "^\\s *[0-9]+$" str)
5283 (setq int (string-to-int str)
5284 prompt (cond ((< int 1) "Integer below 1; ")
5285 ((> int 100) "Integer above 100; ")
5286 (t nil)))
5287 (setq prompt "Invalid integer syntax; "))
5288 (ding)
5289 (setq str
5290 (pr-f-read-string (format fmt-prompt prompt mess) str nil "1")))
5291 int)))
5292
5293
5294 (defun pr-interactive-dir (mess)
5295 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5296 default-directory)))
5297 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
5298 (dir (read-file-name (format fmt-prompt "")
5299 "" dir-name nil dir-name))
5300 prompt)
5301 (while (cond ((not (file-directory-p dir))
5302 (ding)
5303 (setq prompt "It's not a directory! "))
5304 ((not (file-readable-p dir))
5305 (ding)
5306 (setq prompt "Directory is unreadable! "))
5307 (t nil))
5308 (setq dir-name (file-name-directory dir)
5309 dir (read-file-name (format fmt-prompt prompt)
5310 "" dir-name nil dir-name)))
5311 (file-name-as-directory dir)))
5312
5313
5314 (defun pr-interactive-regexp (mess)
5315 (pr-f-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
5316
5317
5318 (defun pr-interactive-dir-args (mess)
5319 (list
5320 ;; get directory argument
5321 (pr-interactive-dir mess)
5322 ;; get file name regexp
5323 (pr-interactive-regexp mess)))
5324
5325
5326 (defun pr-interactive-ps-dir-args (mess)
5327 (list
5328 ;; get n-up argument
5329 (pr-interactive-n-up mess)
5330 ;; get directory argument
5331 (pr-interactive-dir mess)
5332 ;; get file name regexp
5333 (pr-interactive-regexp mess)
5334 ;; get output file name
5335 (and (not pr-spool-p)
5336 (ps-print-preprint current-prefix-arg))))
5337
5338
5339 (defun pr-interactive-n-up-file (mess)
5340 (list
5341 ;; get n-up argument
5342 (pr-interactive-n-up mess)
5343 ;; get output file name
5344 (and (not pr-spool-p)
5345 (ps-print-preprint current-prefix-arg))))
5346
5347
5348 (defun pr-interactive-n-up-inout (mess)
5349 (list
5350 ;; get n-up argument
5351 (pr-interactive-n-up mess)
5352 ;; get input file name
5353 (pr-ps-infile-preprint (concat mess " "))
5354 ;; get output file name
5355 (ps-print-preprint current-prefix-arg)))
5356
5357
5358 (defun pr-set-outfilename (filename-sym)
5359 (and (not pr-spool-p)
5360 (eq (symbol-value filename-sym) t)
5361 (set filename-sym (and (not (interactive-p))
5362 current-prefix-arg
5363 (ps-print-preprint current-prefix-arg))))
5364 (and (symbol-value filename-sym)
5365 (set filename-sym (pr-dosify-path (symbol-value filename-sym)))))
5366
5367
5368 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5369 ;; n-up
5370 (or (symbol-value n-up-sym)
5371 (set n-up-sym (pr-interactive-n-up mess)))
5372 ;; output file
5373 (pr-set-outfilename filename-sym))
5374
5375
5376 (defun pr-set-dir-args (dir-sym regexp-sym mess)
5377 ;; directory
5378 (or (symbol-value dir-sym)
5379 (set dir-sym (pr-interactive-dir mess)))
5380 ;; file name regexp
5381 (or (symbol-value regexp-sym)
5382 (set regexp-sym (pr-interactive-regexp mess))))
5383
5384
5385 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5386 ;; n-up
5387 (or (symbol-value n-up-sym)
5388 (set n-up-sym (pr-interactive-n-up mess)))
5389 ;; directory & file name regexp
5390 (pr-set-dir-args dir-sym regexp-sym mess)
5391 ;; output file
5392 (pr-set-outfilename filename-sym))
5393
5394
5395 (defun pr-find-buffer-visiting (file)
5396 (if (not (file-directory-p file))
5397 (find-buffer-visiting (if ps-windows-system
5398 (downcase file)
5399 file))
5400 (let ((truename (file-truename file))
5401 (blist (buffer-list))
5402 found)
5403 (while (and (not found) blist)
5404 (save-excursion
5405 (set-buffer (car blist))
5406 (and (eq major-mode 'dired-mode)
5407 (save-excursion
5408 (goto-char (point-min))
5409 (string= (buffer-substring-no-properties
5410 (+ (point-min) 2)
5411 (progn
5412 (end-of-line)
5413 (1- (point))))
5414 truename))
5415 (setq found (car blist))))
5416 (setq blist (cdr blist)))
5417 found)))
5418
5419
5420 (defun pr-file-list (dir file-regexp fun)
5421 (mapcar #'(lambda (file)
5422 (and (or pr-list-directory
5423 (not (file-directory-p file)))
5424 (let ((buffer (pr-find-buffer-visiting file))
5425 pop-up-windows
5426 pop-up-frames)
5427 (and (or buffer
5428 (file-readable-p file))
5429 (save-excursion
5430 (set-buffer (or buffer
5431 (find-file-noselect file)))
5432 (funcall fun)
5433 (or buffer
5434 (kill-buffer (current-buffer))))))))
5435 (directory-files dir t file-regexp)))
5436
5437
5438 (defun pr-delete-file-if-exists (filename)
5439 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5440 (delete-file filename)))
5441
5442
5443 (defun pr-ps-file-list (n-up dir file-regexp filename)
5444 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5445 (let ((pr-spool-p t))
5446 (pr-file-list dir file-regexp
5447 #'(lambda ()
5448 (if (pr-auto-mode-p)
5449 (pr-ps-mode n-up filename)
5450 (pr-text2ps 'buffer n-up filename)))))
5451 (or pr-spool-p
5452 (pr-despool-print filename)))
5453
5454
5455 (defun pr-text2ps (kind n-up filename &optional from to)
5456 (let ((ps-n-up-printing n-up)
5457 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5458 'setpagedevice)))
5459 (pr-delete-file-if-exists filename)
5460 (cond (pr-faces-p
5461 (cond (pr-spool-p
5462 ;; pr-faces-p and pr-spool-p
5463 ;; here FILENAME arg is ignored
5464 (cond ((eq kind 'buffer)
5465 (ps-spool-buffer-with-faces))
5466 ((eq kind 'region)
5467 (ps-spool-region-with-faces (or from (point))
5468 (or to (mark))))
5469 ))
5470 ;; pr-faces-p and not pr-spool-p
5471 ((eq kind 'buffer)
5472 (ps-print-buffer-with-faces filename))
5473 ((eq kind 'region)
5474 (ps-print-region-with-faces (or from (point))
5475 (or to (mark)) filename))
5476 ))
5477 (pr-spool-p
5478 ;; not pr-faces-p and pr-spool-p
5479 ;; here FILENAME arg is ignored
5480 (cond ((eq kind 'buffer)
5481 (ps-spool-buffer))
5482 ((eq kind 'region)
5483 (ps-spool-region (or from (point)) (or to (mark))))
5484 ))
5485 ;; not pr-faces-p and not pr-spool-p
5486 ((eq kind 'buffer)
5487 (ps-print-buffer filename))
5488 ((eq kind 'region)
5489 (ps-print-region (or from (point)) (or to (mark)) filename))
5490 )))
5491
5492
5493 (defun pr-command (command)
5494 "Return absolute file name specification for COMMAND.
5495
5496 If COMMAND is an empty string, return it.
5497
5498 If COMMAND is already an absolute file name specification, return it.
5499 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5500 otherwise, gives an error.
5501
5502 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5503 `unix' are used (see `pr-path-alist' for documentation).
5504
5505 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5506 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5507 (if (string= command "")
5508 command
5509 (pr-dosify-path
5510 (or (pr-find-command command)
5511 (pr-path-command (cond (pr-cygwin-system 'cygwin)
5512 (ps-windows-system 'windows)
5513 (t 'unix))
5514 (file-name-nondirectory command)
5515 nil)
5516 (error "Command not found: %s"
5517 (file-name-nondirectory command))))))
5518
5519
5520 (defun pr-path-command (symbol command sym-list)
5521 (let ((lpath (cdr (assq symbol pr-path-alist)))
5522 cmd)
5523 ;; PATH expansion
5524 (and (eq symbol 'PATH) (null lpath)
5525 (setq lpath (parse-colon-path (getenv "PATH"))))
5526 (while (and lpath
5527 (not
5528 (setq cmd
5529 (let ((path (car lpath)))
5530 (cond
5531 ;; symbol expansion
5532 ((symbolp path)
5533 (and (not (memq path sym-list))
5534 (pr-path-command path command
5535 (cons path sym-list))))
5536 ;; normal path
5537 ((stringp path)
5538 (pr-find-command
5539 (expand-file-name
5540 (substitute-in-file-name
5541 (concat (file-name-as-directory path)
5542 command)))))
5543 )))))
5544 (setq lpath (cdr lpath)))
5545 cmd))
5546
5547
5548 (defun pr-find-command (cmd)
5549 (if ps-windows-system
5550 ;; windows system
5551 (let ((ext (cons (file-name-extension cmd t)
5552 (list ".exe" ".bat" ".com")))
5553 found)
5554 (setq cmd (file-name-sans-extension cmd))
5555 (while (and ext
5556 (setq found (concat cmd (car ext)))
5557 (not (and (file-regular-p found)
5558 (file-executable-p found))))
5559 (setq ext (cdr ext)
5560 found nil))
5561 found)
5562 ;; non-windows systems
5563 (and (file-regular-p cmd)
5564 (file-executable-p cmd)
5565 cmd)))
5566
5567
5568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5569 ;; Printing Interface (inspired on ps-print-interface.el)
5570
5571
5572 (require 'widget)
5573 (require 'wid-edit)
5574 (require 'cus-edit)
5575
5576
5577 (defvar pr-i-window-configuration nil)
5578
5579 (defvar pr-i-buffer nil)
5580 (defvar pr-i-region nil)
5581 (defvar pr-i-mode nil)
5582 (defvar pr-i-despool nil)
5583 (defvar pr-i-ps-as-is t)
5584 (defvar pr-i-n-up 1)
5585 (defvar pr-i-directory "./")
5586 (defvar pr-i-regexp "")
5587 (defvar pr-i-ps-file "")
5588 (defvar pr-i-out-file "")
5589 (defvar pr-i-answer-yes nil)
5590 (defvar pr-i-process 'buffer)
5591 (defvar pr-i-ps-send 'printer)
5592
5593
5594 (defvar pr-interface-map nil
5595 "Keymap for pr-interface.")
5596
5597 (if pr-interface-map
5598 nil
5599 (setq pr-interface-map (make-sparse-keymap))
5600 (cond ((eq ps-print-emacs-type 'xemacs) ; XEmacs
5601 (pr-f-set-keymap-parents pr-interface-map (list widget-keymap))
5602 (pr-f-set-keymap-name pr-interface-map 'pr-interface-map))
5603 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
5604 (pr-f-set-keymap-parents pr-interface-map widget-keymap)))
5605 (define-key pr-interface-map "q" 'pr-interface-quit)
5606 (define-key pr-interface-map "?" 'pr-interface-help))
5607
5608
5609 (defmacro pr-interface-save (&rest body)
5610 `(save-excursion
5611 (set-buffer pr-i-buffer)
5612 ,@body))
5613
5614
5615 (defun pr-create-interface ()
5616 "Create the front end for printing package."
5617 (setq pr-i-buffer (buffer-name (current-buffer))
5618 pr-i-region (ps-mark-active-p)
5619 pr-i-mode (pr-mode-alist-p)
5620 pr-i-window-configuration (current-window-configuration))
5621
5622 (put 'pr-i-process 'pr-widget-list nil)
5623 (put 'pr-i-ps-send 'pr-widget-list nil)
5624
5625 (delete-other-windows)
5626 (kill-buffer (get-buffer-create pr-buffer-name))
5627 (switch-to-buffer (get-buffer-create pr-buffer-name))
5628
5629 ;; header
5630 (let ((versions (concat "printing v" pr-version
5631 " ps-print v" ps-print-version)))
5632 (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
5633 (pr-insert-italic "\nCurrent Directory : " 1)
5634 (pr-insert-italic default-directory)
5635
5636 (pr-insert-section-1) ; 1. Print
5637 (pr-insert-section-2) ; 2. PostScript Printer
5638 (pr-insert-section-3) ; 3. Text Printer
5639
5640 ;; separator
5641 (widget-insert "\n\n " (make-string 77 ?-))
5642
5643 (pr-insert-section-4) ; 4. Settings
5644 (pr-insert-section-5) ; 5. Customize
5645 (pr-insert-section-6) ; 6. Show Settings
5646 (pr-insert-section-7) ; 7. Help
5647
5648 (use-local-map pr-interface-map)
5649 (widget-setup)
5650 (goto-char (point-min))
5651
5652 (and pr-i-region ; let region activated
5653 (pr-keep-region-active)))
5654
5655
5656 (defun pr-insert-section-1 ()
5657 ;; 1. Print:
5658 (pr-insert-italic "\nPrint :" 1)
5659
5660 ;; 1a. Buffer:
5661 ;; 1a. Buffer: Buffer List
5662 (pr-insert-radio-button 'pr-i-process 'buffer)
5663 (pr-insert-menu "Buffer List" 'pr-i-buffer
5664 (let ((blist (buffer-list))
5665 case-fold-search choices)
5666 (while blist
5667 (let ((name (buffer-name (car blist)))
5668 (ignore pr-buffer-name-ignore)
5669 found)
5670 (setq blist (cdr blist))
5671 (while (and ignore (not found))
5672 (setq found (string-match (car ignore) name)
5673 ignore (cdr ignore)))
5674 (or found
5675 (setq choices
5676 (cons (list 'quote
5677 (list 'choice-item
5678 :format "%[%t%]"
5679 name))
5680 choices)))))
5681 (nreverse choices))
5682 " Buffer : " nil
5683 '(progn
5684 (pr-interface-save
5685 (setq pr-i-region (ps-mark-active-p)
5686 pr-i-mode (pr-mode-alist-p)))
5687 (pr-update-checkbox 'pr-i-region)
5688 (pr-update-checkbox 'pr-i-mode)))
5689 ;; 1a. Buffer: Region
5690 (put 'pr-i-region 'pr-widget
5691 (pr-insert-checkbox
5692 "\n "
5693 'pr-i-region
5694 #'(lambda (widget &rest ignore)
5695 (let ((region-p (pr-interface-save
5696 (ps-mark-active-p))))
5697 (cond ((null (widget-value widget)) ; widget is nil
5698 (setq pr-i-region nil))
5699 (region-p ; widget is true and there is a region
5700 (setq pr-i-region t)
5701 (widget-value-set widget t)
5702 (widget-setup)) ; MUST be called after widget-value-set
5703 (t ; widget is true and there is no region
5704 (ding)
5705 (message "There is no region active")
5706 (setq pr-i-region nil)
5707 (widget-value-set widget nil)
5708 (widget-setup))))) ; MUST be called after widget-value-set
5709 " Region"))
5710 ;; 1a. Buffer: Mode
5711 (put 'pr-i-mode 'pr-widget
5712 (pr-insert-checkbox
5713 " "
5714 'pr-i-mode
5715 #'(lambda (widget &rest ignore)
5716 (let ((mode-p (pr-interface-save
5717 (pr-mode-alist-p))))
5718 (cond
5719 ((null (widget-value widget)) ; widget is nil
5720 (setq pr-i-mode nil))
5721 (mode-p ; widget is true and there is a `mode'
5722 (setq pr-i-mode t)
5723 (widget-value-set widget t)
5724 (widget-setup)) ; MUST be called after widget-value-set
5725 (t ; widget is true and there is no `mode'
5726 (ding)
5727 (message
5728 "This buffer isn't in a mode that printing treats specially.")
5729 (setq pr-i-mode nil)
5730 (widget-value-set widget nil)
5731 (widget-setup))))) ; MUST be called after widget-value-set
5732 " Mode\n"))
5733
5734 ;; 1b. Directory:
5735 (pr-insert-radio-button 'pr-i-process 'directory)
5736 (widget-create
5737 'directory
5738 :size 58
5739 :format " Directory : %v"
5740 :notify 'pr-interface-directory
5741 :action (lambda (widget &optional event)
5742 (if (pr-interface-directory widget)
5743 (pr-widget-field-action widget event)
5744 (ding)
5745 (message "Please specify a readable directory")))
5746 pr-i-directory)
5747 ;; 1b. Directory: File Regexp
5748 (widget-create 'regexp
5749 :size 58
5750 :format "\n File Regexp : %v\n"
5751 :notify (lambda (widget &rest ignore)
5752 (setq pr-i-regexp (widget-value widget)))
5753 pr-i-regexp)
5754 ;; 1b. Directory: List Directory Entry
5755 (widget-insert " ")
5756 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
5757
5758 ;; 1c. PostScript File:
5759 (pr-insert-radio-button 'pr-i-process 'file)
5760 (widget-create
5761 'file
5762 :size 51
5763 :format " PostScript File : %v"
5764 :notify 'pr-interface-infile
5765 :action (lambda (widget &rest event)
5766 (if (pr-interface-infile widget)
5767 (pr-widget-field-action widget event)
5768 (ding)
5769 (message "Please specify a readable PostScript file")))
5770 pr-i-ps-file)
5771 ;; 1c. PostScript File: PostScript Utility
5772 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
5773 (pr-choice-alist pr-ps-utility-alist)
5774 "\n PostScript Utility : "
5775 " ")
5776 ;; 1c. PostScript File: No Preprocessing
5777 (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
5778
5779
5780 (defun pr-insert-section-2 ()
5781 ;; 2. PostScript Printer:
5782 ;; 2. PostScript Printer: PostScript Printer List
5783 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
5784 (pr-insert-menu "PostScript Printer" 'pr-ps-name
5785 (pr-choice-alist pr-ps-printer-alist))
5786 ;; 2. PostScript Printer: Despool
5787 (put 'pr-i-despool 'pr-widget
5788 (pr-insert-checkbox
5789 " "
5790 'pr-i-despool
5791 #'(lambda (widget &rest ignore)
5792 (if pr-spool-p
5793 (setq pr-i-despool (not pr-i-despool))
5794 (ding)
5795 (message "Can despool only when spooling is actually selected")
5796 (setq pr-i-despool nil))
5797 (widget-value-set widget pr-i-despool)
5798 (widget-setup)) ; MUST be called after widget-value-set
5799 " Despool "))
5800 ;; 2. PostScript Printer: Preview Print Quit
5801 (pr-insert-button 'pr-interface-preview "Preview" " ")
5802 (pr-insert-button 'pr-interface-ps-print "Print" " ")
5803 (pr-insert-button 'pr-interface-quit "Quit")
5804 ;; 2. PostScript Printer: Send to Printer/Temporary File
5805 (pr-insert-radio-button 'pr-i-ps-send 'printer)
5806 (widget-insert " Send to Printer/Temporary File")
5807 ;; 2. PostScript Printer: Send to File
5808 (pr-insert-radio-button 'pr-i-ps-send 'file)
5809 (widget-create
5810 'file
5811 :size 57
5812 :format " Send to File : %v"
5813 :notify 'pr-interface-outfile
5814 :action (lambda (widget &rest event)
5815 (if (and (pr-interface-outfile widget)
5816 (or (not (file-exists-p pr-i-out-file))
5817 (setq pr-i-answer-yes
5818 (y-or-n-p "File exists; overwrite? "))))
5819 (pr-widget-field-action widget event)
5820 (ding)
5821 (message "Please specify a writable PostScript file")))
5822 pr-i-out-file)
5823 ;; 2. PostScript Printer: N-Up
5824 (widget-create
5825 'integer
5826 :size 3
5827 :format "\n N-Up : %v"
5828 :notify (lambda (widget &rest ignore)
5829 (let ((value (if (string= (widget-apply widget :value-get) "")
5830 0
5831 (widget-value widget))))
5832 (if (and (integerp value)
5833 (<= 1 value) (<= value 100))
5834 (progn
5835 (message " ")
5836 (setq pr-i-n-up value))
5837 (ding)
5838 (message "Please specify an integer between 1 and 100"))))
5839 pr-i-n-up))
5840
5841
5842 (defun pr-insert-section-3 ()
5843 ;; 3. Text Printer:
5844 (pr-insert-italic "\n\nText Printer : " 2 14)
5845 (pr-insert-menu "Text Printer" 'pr-txt-name
5846 (pr-choice-alist pr-txt-printer-alist)
5847 nil " ")
5848 (pr-insert-button 'pr-interface-printify "Printify" " ")
5849 (pr-insert-button 'pr-interface-txt-print "Print" " ")
5850 (pr-insert-button 'pr-interface-quit "Quit"))
5851
5852
5853 (defun pr-insert-section-4 ()
5854 ;; 4. Settings:
5855 ;; 4. Settings: Landscape Auto Region Verbose
5856 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
5857 #'(lambda (&rest ignore)
5858 (setq ps-landscape-mode (not ps-landscape-mode)
5859 pr-file-landscape ps-landscape-mode))
5860 " Landscape ")
5861 (pr-insert-toggle 'pr-auto-region " Auto Region ")
5862 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
5863
5864 ;; 4. Settings: Print Header Auto Mode
5865 (pr-insert-toggle 'ps-print-header " Print Header ")
5866 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
5867
5868 ;; 4. Settings: Print Header Frame Menu Lock
5869 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
5870 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
5871
5872 ;; 4. Settings: Line Number
5873 (pr-insert-toggle 'ps-line-number " Line Number\n ")
5874
5875 ;; 4. Settings: Zebra Stripes Spool Buffer
5876 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
5877 (pr-insert-checkbox " "
5878 'pr-spool-p
5879 #'(lambda (&rest ignore)
5880 (setq pr-spool-p (not pr-spool-p))
5881 (unless pr-spool-p
5882 (setq pr-i-despool nil)
5883 (pr-update-checkbox 'pr-i-despool)))
5884 " Spool Buffer")
5885
5886 ;; 4. Settings: Duplex Print with faces
5887 (pr-insert-checkbox "\n "
5888 'ps-spool-duplex
5889 #'(lambda (&rest ignore)
5890 (setq ps-spool-duplex (not ps-spool-duplex)
5891 pr-file-duplex ps-spool-duplex))
5892 " Duplex ")
5893 (pr-insert-toggle 'pr-faces-p " Print with faces")
5894
5895 ;; 4. Settings: Tumble Print via Ghostscript
5896 (pr-insert-checkbox "\n "
5897 'ps-spool-tumble
5898 #'(lambda (&rest ignore)
5899 (setq ps-spool-tumble (not ps-spool-tumble)
5900 pr-file-tumble ps-spool-tumble))
5901 " Tumble ")
5902 (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
5903
5904 ;; 4. Settings: Upside-Down Page Parity
5905 (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
5906 (pr-insert-italic "\n\nSelect Pages : " 2 14)
5907 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
5908 (mapcar #'(lambda (alist)
5909 (list 'quote
5910 (list 'choice-item
5911 :format "%[%t%]"
5912 :tag (cdr alist)
5913 :value (car alist))))
5914 pr-even-or-odd-alist)))
5915
5916
5917 (defun pr-insert-section-5 ()
5918 ;; 5. Customize:
5919 (pr-insert-italic "\n\nCustomize : " 2 11)
5920 (pr-insert-button 'pr-customize "printing" " ")
5921 (pr-insert-button #'(lambda (&rest ignore) (ps-print-customize))
5922 "ps-print" " ")
5923 (pr-insert-button 'lpr-customize "lpr"))
5924
5925
5926 (defun pr-insert-section-6 ()
5927 ;; 6. Show Settings:
5928 (pr-insert-italic "\nShow Settings : " 1 14)
5929 (pr-insert-button 'pr-show-pr-setup "printing" " ")
5930 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
5931 (pr-insert-button 'pr-show-lpr-setup "lpr"))
5932
5933
5934 (defun pr-insert-section-7 ()
5935 ;; 7. Help:
5936 (pr-insert-italic "\nHelp : " 1 5)
5937 (pr-insert-button 'pr-interface-help "Interface Help" " ")
5938 (pr-insert-button 'pr-help "Menu Help" " ")
5939 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
5940 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
5941
5942
5943 (defun pr-kill-help (&rest ignore)
5944 "Kill all printing help buffer."
5945 (interactive)
5946 (let ((help '("*Printing Interface Help*" "*Printing Help*"
5947 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
5948 (while help
5949 (let ((buffer (get-buffer (car help))))
5950 (setq help (cdr help))
5951 (when buffer
5952 (delete-windows-on buffer)
5953 (kill-buffer buffer)))))
5954 (recenter (- (window-height) 2)))
5955
5956
5957 (defun pr-interface-quit (&rest ignore)
5958 "Kill the printing buffer interface and quit."
5959 (interactive)
5960 (kill-buffer pr-buffer-name)
5961 (set-window-configuration pr-i-window-configuration))
5962
5963
5964 (defun pr-interface-help (&rest ignore)
5965 "printing buffer interface help."
5966 (interactive)
5967 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
5968
5969
5970 (defun pr-interface-txt-print (&rest ignore)
5971 "Print using lpr package."
5972 (interactive)
5973 (condition-case data
5974 (cond
5975 ((eq pr-i-process 'directory)
5976 (pr-i-directory)
5977 (pr-interface-save
5978 (pr-txt-directory pr-i-directory pr-i-regexp)))
5979 ((eq pr-i-process 'buffer)
5980 (pr-interface-save
5981 (cond (pr-i-region
5982 (let ((pr-auto-mode pr-i-mode))
5983 (pr-txt-region)))
5984 (pr-i-mode
5985 (let (pr-auto-region)
5986 (pr-txt-mode)))
5987 (t
5988 (let (pr-auto-mode pr-auto-region)
5989 (pr-txt-buffer)))
5990 )))
5991 ((eq pr-i-process 'file)
5992 (error "Please specify a text file"))
5993 (t
5994 (error "Internal error: `pr-i-process' = %S" pr-i-process))
5995 )
5996 ;; handlers
5997 ((quit error)
5998 (ding)
5999 (message (error-message-string data)))))
6000
6001
6002 (defun pr-interface-printify (&rest ignore)
6003 "Printify a buffer."
6004 (interactive)
6005 (condition-case data
6006 (cond
6007 ((eq pr-i-process 'directory)
6008 (pr-i-directory)
6009 (pr-interface-save
6010 (pr-printify-directory pr-i-directory pr-i-regexp)))
6011 ((eq pr-i-process 'buffer)
6012 (pr-interface-save
6013 (if pr-i-region
6014 (pr-printify-region)
6015 (pr-printify-buffer))))
6016 ((eq pr-i-process 'file)
6017 (error "Cannot printify a PostScript file"))
6018 (t
6019 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6020 )
6021 ;; handlers
6022 ((quit error)
6023 (ding)
6024 (message (error-message-string data)))))
6025
6026
6027 (defun pr-interface-ps-print (&rest ignore)
6028 "Print using ps-print package."
6029 (interactive)
6030 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6031 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6032 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6033 'pr-ps-buffer-ps-print))
6034
6035
6036 (defun pr-interface-preview (&rest ignore)
6037 "Preview a PostScript file."
6038 (interactive)
6039 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6040 'pr-ps-file-preview 'pr-ps-file-up-preview
6041 'pr-ps-region-preview 'pr-ps-mode-preview
6042 'pr-ps-buffer-preview))
6043
6044
6045 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6046 ps-mode ps-buffer)
6047 (condition-case data
6048 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6049 (pr-i-ps-send))))
6050 (cond
6051 ((and pr-i-despool pr-spool-p)
6052 (pr-interface-save
6053 (funcall ps-despool outfile))
6054 (setq pr-i-despool nil)
6055 (pr-update-checkbox 'pr-i-despool))
6056 ((eq pr-i-process 'directory)
6057 (pr-i-directory)
6058 (pr-interface-save
6059 (funcall ps-directory
6060 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6061 ((eq pr-i-process 'file)
6062 (cond ((or (file-directory-p pr-i-ps-file)
6063 (not (file-readable-p pr-i-ps-file)))
6064 (error "Please specify a readable PostScript file"))
6065 (pr-i-ps-as-is
6066 (pr-interface-save
6067 (funcall ps-file pr-i-ps-file)))
6068 (t
6069 (pr-interface-save
6070 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6071 ))
6072 ((eq pr-i-process 'buffer)
6073 (pr-interface-save
6074 (cond (pr-i-region
6075 (let ((pr-auto-mode pr-i-mode))
6076 (funcall ps-region pr-i-n-up outfile)))
6077 (pr-i-mode
6078 (let (pr-auto-region)
6079 (funcall ps-mode pr-i-n-up outfile)))
6080 (t
6081 (let (pr-auto-mode pr-auto-region)
6082 (funcall ps-buffer pr-i-n-up outfile)))
6083 )))
6084 (t
6085 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6086 ))
6087 ;; handlers
6088 ((quit error)
6089 (ding)
6090 (message (error-message-string data)))))
6091
6092
6093 (defun pr-i-ps-send ()
6094 (cond ((eq pr-i-ps-send 'printer)
6095 nil)
6096 ((not (eq pr-i-ps-send 'file))
6097 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6098 ((or (file-directory-p pr-i-out-file)
6099 (not (file-writable-p pr-i-out-file)))
6100 (error "Please specify a writable PostScript file"))
6101 ((or (not (file-exists-p pr-i-out-file))
6102 pr-i-answer-yes
6103 (setq pr-i-answer-yes
6104 (y-or-n-p (format "File `%s' exists; overwrite? "
6105 pr-i-out-file))))
6106 pr-i-out-file)
6107 (t
6108 (error "File already exists"))))
6109
6110
6111 (defun pr-i-directory ()
6112 (or (and (file-directory-p pr-i-directory)
6113 (file-readable-p pr-i-directory))
6114 (error "Please specify be a readable directory")))
6115
6116
6117 (defun pr-interface-directory (widget &rest ignore)
6118 (and pr-buffer-verbose
6119 (message "You can use M-TAB or ESC TAB for file completion"))
6120 (let ((dir (widget-value widget)))
6121 (and (file-directory-p dir)
6122 (file-readable-p dir)
6123 (setq pr-i-directory dir))))
6124
6125
6126 (defun pr-interface-infile (widget &rest ignore)
6127 (and pr-buffer-verbose
6128 (message "You can use M-TAB or ESC TAB for file completion"))
6129 (let ((file (widget-value widget)))
6130 (and (not (file-directory-p file))
6131 (file-readable-p file)
6132 (setq pr-i-ps-file file))))
6133
6134
6135 (defun pr-interface-outfile (widget &rest ignore)
6136 (setq pr-i-answer-yes nil)
6137 (and pr-buffer-verbose
6138 (message "You can use M-TAB or ESC TAB for file completion"))
6139 (let ((file (widget-value widget)))
6140 (and (not (file-directory-p file))
6141 (file-writable-p file)
6142 (setq pr-i-out-file file))))
6143
6144
6145 (defun pr-widget-field-action (widget event)
6146 (and (get-buffer "*Completions*") ; clean frame window
6147 (delete-windows-on "*Completions*"))
6148 (message " ") ; clean echo area
6149 (widget-field-action widget event))
6150
6151
6152 (defun pr-insert-italic (str &optional from to)
6153 (let ((len (length str)))
6154 (put-text-property (if from (max from 0) 0)
6155 (if to (max to len) len)
6156 'face 'italic str)
6157 (widget-insert str)))
6158
6159
6160 (defun pr-insert-checkbox (before var-sym fun label)
6161 (widget-insert before)
6162 (prog1
6163 (widget-create 'checkbox
6164 :notify fun
6165 (symbol-value var-sym))
6166 (widget-insert label)))
6167
6168
6169 (defun pr-insert-toggle (var-sym label)
6170 (widget-create 'checkbox
6171 :notify `(lambda (&rest ignore)
6172 (setq ,var-sym (not ,var-sym)))
6173 (symbol-value var-sym))
6174 (widget-insert label))
6175
6176
6177 (defun pr-insert-button (fun label &optional separator)
6178 (widget-create 'push-button
6179 :notify fun
6180 label)
6181 (and separator
6182 (widget-insert separator)))
6183
6184
6185 (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6186 (and before (widget-insert before))
6187 (eval `(widget-create 'menu-choice
6188 :tag ,tag
6189 :format "%v"
6190 :inline t
6191 :value ,var-sym
6192 :notify (lambda (widget &rest ignore)
6193 (setq ,var-sym (widget-value widget))
6194 ,@body)
6195 :void '(choice-item :format "%[%t%]"
6196 :tag "Can not display value!")
6197 ,@choices))
6198 (and after (widget-insert after)))
6199
6200
6201 (defun pr-insert-radio-button (var-sym sym)
6202 (widget-insert "\n")
6203 (let ((wid-list (get var-sym 'pr-widget-list))
6204 (wid (eval `(widget-create
6205 'radio-button
6206 :format " %[%v%]"
6207 :value (eq ,var-sym (quote ,sym))
6208 :notify (lambda (&rest ignore)
6209 (setq ,var-sym (quote ,sym))
6210 (pr-update-radio-button (quote ,var-sym)))))))
6211 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6212
6213
6214 (defun pr-update-radio-button (var-sym)
6215 (let ((wid-list (get var-sym 'pr-widget-list)))
6216 (while wid-list
6217 (let ((wid (car (car wid-list)))
6218 (value (cdr (car wid-list))))
6219 (setq wid-list (cdr wid-list))
6220 (widget-value-set wid (eq (symbol-value var-sym) value))))
6221 (widget-setup)))
6222
6223
6224 (defun pr-update-checkbox (var-sym)
6225 (let ((wid (get var-sym 'pr-widget)))
6226 (when wid
6227 (widget-value-set wid (symbol-value var-sym))
6228 (widget-setup))))
6229
6230
6231 (defun pr-choice-alist (alist)
6232 (let ((max (apply 'max (mapcar #'(lambda (alist)
6233 (length (symbol-name (car alist))))
6234 alist))))
6235 (mapcar #'(lambda (alist)
6236 (let* ((sym (car alist))
6237 (name (symbol-name sym)))
6238 (list
6239 'quote
6240 (list
6241 'choice-item
6242 :format "%[%t%]"
6243 :tag (concat name
6244 (make-string (- max (length name)) ?_))
6245 :value sym))))
6246 alist)))
6247
6248
6249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6250
6251
6252 (pr-update-menus t)
6253
6254
6255 (provide 'printing)
6256
6257
6258 ;;; arch-tag: 9ce9ac3f-0f60-4370-900b-1943215d9d18
6259 ;;; printing.el ends here