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