(Fstart_kbd_macro): Remove redundant assignment.
[emacs.git] / lisp / printing.el
blobeb55586591bb4071bd184956b463b577346e0c02
1 ;;; printing.el --- printing utilities
3 ;; Copyright (C) 2000, 2001, 2002
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))))
2347 (eval-and-compile
2348 (defun pr-get-symbol (name)
2349 ;; Recent versions of easy-menu downcase names before interning them.
2350 (and (fboundp 'easy-menu-name-match)
2351 (setq name (downcase name)))
2352 (or (intern-soft name)
2353 (make-symbol name)))
2357 (defsubst pr-visible-p (key)
2358 (memq key pr-visible-entry-list))
2361 (defsubst pr-mode-alist-p ()
2362 (cdr (assq major-mode pr-mode-alist)))
2365 (defsubst pr-auto-mode-p ()
2366 (and pr-auto-mode (pr-mode-alist-p)))
2369 (defsubst pr-using-ghostscript-p ()
2370 (and pr-print-using-ghostscript (not pr-spool-p)))
2373 (eval-and-compile
2374 (cond
2375 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2376 (defsubst pr-region-active-p ()
2377 (and pr-auto-region transient-mark-mode mark-active)))
2379 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2380 (defsubst pr-region-active-p ()
2381 (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p)))))
2384 (defconst pr-menu-spec
2385 (cond
2386 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2388 ["Printing Interface" pr-interface
2389 :help "Use buffer interface instead of menu interface"]
2390 "--"
2391 ("PostScript Preview" :visible (pr-visible-p 'postscript)
2392 :help "Preview PostScript instead of sending to printer"
2393 ("Directory" :active (not pr-spool-p)
2394 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
2395 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
2396 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
2397 ["Other..." (pr-ps-directory-preview nil nil nil t)
2398 :keys "\\[pr-ps-buffer-preview]"])
2399 ("Buffer" :active (not pr-spool-p)
2400 ["1-up" (pr-ps-buffer-preview 1 t) t]
2401 ["2-up" (pr-ps-buffer-preview 2 t) t]
2402 ["4-up" (pr-ps-buffer-preview 4 t) t]
2403 ["Other..." (pr-ps-buffer-preview nil t)
2404 :keys "\\[pr-ps-buffer-preview]"])
2405 ("Region" :active (and (not pr-spool-p) (ps-mark-active-p))
2406 ["1-up" (pr-ps-region-preview 1 t) t]
2407 ["2-up" (pr-ps-region-preview 2 t) t]
2408 ["4-up" (pr-ps-region-preview 4 t) t]
2409 ["Other..." (pr-ps-region-preview nil t)
2410 :keys "\\[pr-ps-region-preview]"])
2411 ("Mode" :active (and (not pr-spool-p) (pr-mode-alist-p))
2412 ["1-up" (pr-ps-mode-preview 1 t) t]
2413 ["2-up" (pr-ps-mode-preview 2 t) t]
2414 ["4-up" (pr-ps-mode-preview 4 t) t]
2415 ["Other..." (pr-ps-mode-preview nil t)
2416 :keys "\\[pr-ps-mode-preview]"])
2417 ("File"
2418 ["As Is..." (call-interactively 'pr-ps-file-preview)
2419 :keys "\\[pr-ps-file-preview]"
2420 :help "Preview PostScript file"]
2421 "--"
2422 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2423 :help "Select PostScript utility"]
2424 "--"
2425 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
2426 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
2427 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
2428 ["Other..." (pr-ps-file-up-preview nil t t)
2429 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
2430 "--"
2431 ["Landscape" pr-toggle-file-landscape
2432 :style toggle :selected pr-file-landscape
2433 :help "Toggle landscape for PostScript file"
2434 :active pr-ps-utility-alist]
2435 ["Duplex" pr-toggle-file-duplex
2436 :style toggle :selected pr-file-duplex
2437 :help "Toggle duplex for PostScript file"
2438 :active pr-ps-utility-alist]
2439 ["Tumble" pr-toggle-file-tumble
2440 :style toggle :selected pr-file-tumble
2441 :help "Toggle tumble for PostScript file"
2442 :active (and pr-file-duplex pr-ps-utility-alist)])
2443 ["Despool..." (call-interactively 'pr-despool-preview)
2444 :active pr-spool-p :keys "\\[pr-despool-preview]"
2445 :help "Despool PostScript buffer to printer or file (C-u)"])
2446 ("PostScript Print" :visible (pr-visible-p 'postscript)
2447 :help "Send PostScript to printer or file (C-u)"
2448 ("Directory"
2449 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
2450 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
2451 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
2452 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
2453 :keys "\\[pr-ps-buffer-ps-print]"])
2454 ("Buffer"
2455 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
2456 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
2457 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
2458 ["Other..." (pr-ps-buffer-ps-print nil t)
2459 :keys "\\[pr-ps-buffer-ps-print]"])
2460 ("Region" :active (ps-mark-active-p)
2461 ["1-up" (pr-ps-region-ps-print 1 t) t]
2462 ["2-up" (pr-ps-region-ps-print 2 t) t]
2463 ["4-up" (pr-ps-region-ps-print 4 t) t]
2464 ["Other..." (pr-ps-region-ps-print nil t)
2465 :keys "\\[pr-ps-region-ps-print]"])
2466 ("Mode" :active (pr-mode-alist-p)
2467 ["1-up" (pr-ps-mode-ps-print 1 t) t]
2468 ["2-up" (pr-ps-mode-ps-print 2 t) t]
2469 ["4-up" (pr-ps-mode-ps-print 4 t) t]
2470 ["Other..." (pr-ps-mode-ps-print nil t)
2471 :keys "\\[pr-ps-mode-ps-print]"])
2472 ("File"
2473 ["As Is..." (call-interactively 'pr-ps-file-ps-print)
2474 :keys "\\[pr-ps-file-ps-print]"
2475 :help "Send PostScript file to printer"]
2476 "--"
2477 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2478 :help "Select PostScript utility"]
2479 "--"
2480 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
2481 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
2482 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
2483 ["Other..." (pr-ps-file-up-ps-print nil t t)
2484 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
2485 "--"
2486 ["Landscape" pr-toggle-file-landscape
2487 :style toggle :selected pr-file-landscape
2488 :help "Toggle landscape for PostScript file"
2489 :active pr-ps-utility-alist]
2490 ["Duplex" pr-toggle-file-duplex
2491 :style toggle :selected pr-file-duplex
2492 :help "Toggle duplex for PostScript file"
2493 :active pr-ps-utility-alist]
2494 ["Tumble" pr-toggle-file-tumble
2495 :style toggle :selected pr-file-tumble
2496 :help "Toggle tumble for PostScript file"
2497 :active (and pr-file-duplex pr-ps-utility-alist)])
2498 ["Despool..." (call-interactively 'pr-despool-ps-print)
2499 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
2500 :help "Despool PostScript buffer to printer or file (C-u)"])
2501 ["PostScript Printers" pr-update-menus
2502 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
2503 :help "Select PostScript printer"]
2504 "--"
2505 ("Printify" :visible (pr-visible-p 'text)
2506 :help "Replace non-printing chars with printable representations."
2507 ["Directory" pr-printify-directory t]
2508 ["Buffer" pr-printify-buffer t]
2509 ["Region" pr-printify-region (ps-mark-active-p)])
2510 ("Print" :visible (pr-visible-p 'text)
2511 :help "Send text to printer"
2512 ["Directory" pr-txt-directory t]
2513 ["Buffer" pr-txt-buffer t]
2514 ["Region" pr-txt-region (ps-mark-active-p)]
2515 ["Mode" pr-txt-mode (pr-mode-alist-p)])
2516 ["Text Printers" pr-update-menus
2517 :active pr-txt-printer-alist :included (pr-visible-p 'text)
2518 :help "Select text printer"]
2519 "--"
2520 ["Landscape" pr-toggle-landscape
2521 :style toggle :selected ps-landscape-mode
2522 :included (pr-visible-p 'postscript-options)]
2523 ["Print Header" pr-toggle-header
2524 :style toggle :selected ps-print-header
2525 :included (pr-visible-p 'postscript-options)]
2526 ["Print Header Frame" pr-toggle-header-frame
2527 :style toggle :selected ps-print-header-frame :active ps-print-header
2528 :included (pr-visible-p 'postscript-options)]
2529 ["Line Number" pr-toggle-line
2530 :style toggle :selected ps-line-number
2531 :included (pr-visible-p 'postscript-options)]
2532 ["Zebra Stripes" pr-toggle-zebra
2533 :style toggle :selected ps-zebra-stripes
2534 :included (pr-visible-p 'postscript-options)]
2535 ["Duplex" pr-toggle-duplex
2536 :style toggle :selected ps-spool-duplex
2537 :included (pr-visible-p 'postscript-options)]
2538 ["Tumble" pr-toggle-tumble
2539 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
2540 :included (pr-visible-p 'postscript-options)]
2541 ["Upside-Down" pr-toggle-upside-down
2542 :style toggle :selected ps-print-upside-down
2543 :included (pr-visible-p 'postscript-options)]
2544 ("Print All Pages" :visible (pr-visible-p 'postscript-options)
2545 :help "Select odd/even pages/sheets to print"
2546 ["All Pages" (pr-even-or-odd-pages nil)
2547 :style radio :selected (eq ps-even-or-odd-pages nil)]
2548 ["Even Pages" (pr-even-or-odd-pages 'even-page)
2549 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
2550 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
2551 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
2552 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
2553 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
2554 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
2555 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
2556 "--"
2557 ["Spool Buffer" pr-toggle-spool
2558 :style toggle :selected pr-spool-p
2559 :included (pr-visible-p 'postscript-process)
2560 :help "Toggle PostScript spooling"]
2561 ["Print with-faces" pr-toggle-faces
2562 :style toggle :selected pr-faces-p
2563 :included (pr-visible-p 'postscript-process)
2564 :help "Toggle PostScript printing with faces"]
2565 ["Print Using Ghostscript" pr-toggle-ghostscript
2566 :style toggle :selected pr-print-using-ghostscript
2567 :included (pr-visible-p 'postscript-process)
2568 :help "Toggle PostScript generation using ghostscript"]
2569 "--"
2570 ["Auto Region" pr-toggle-region
2571 :style toggle :selected pr-auto-region
2572 :included (pr-visible-p 'printing)]
2573 ["Auto Mode" pr-toggle-mode
2574 :style toggle :selected pr-auto-mode
2575 :included (pr-visible-p 'printing)]
2576 ["Menu Lock" pr-toggle-lock
2577 :style toggle :selected pr-menu-lock
2578 :included (pr-visible-p 'printing)]
2579 "--"
2580 ("Customize" :visible (pr-visible-p 'help)
2581 ["printing" pr-customize t]
2582 ["ps-print" ps-print-customize t]
2583 ["lpr" lpr-customize t])
2584 ("Show Settings" :visible (pr-visible-p 'help)
2585 ["printing" pr-show-pr-setup t]
2586 ["ps-print" pr-show-ps-setup t]
2587 ["lpr" pr-show-lpr-setup t])
2588 ["Help" pr-help :active t :included (pr-visible-p 'help)]
2592 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2593 ;; Menu mapping:
2594 ;; unfortunately XEmacs doesn't support :active or :visible
2595 ;; for submenus, only for items.
2596 ;; It uses :included instead of :active or :visible.
2597 ;; Also, XEmacs doesn't support :help tag.
2599 ["Printing Interface" pr-interface]
2600 "--"
2601 ("PostScript Preview" :included (pr-visible-p 'postscript)
2602 ("Directory" :included (not pr-spool-p)
2603 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
2604 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
2605 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
2606 ["Other..." (pr-ps-directory-preview nil nil nil t)
2607 :keys "\\[pr-ps-buffer-preview]"])
2608 ("Buffer" :included (not pr-spool-p)
2609 ["1-up" (pr-ps-buffer-preview 1 t) t]
2610 ["2-up" (pr-ps-buffer-preview 2 t) t]
2611 ["4-up" (pr-ps-buffer-preview 4 t) t]
2612 ["Other..." (pr-ps-buffer-preview nil t)
2613 :keys "\\[pr-ps-buffer-preview]"])
2614 ("Region" :included (and (not pr-spool-p) (ps-mark-active-p))
2615 ["1-up" (pr-ps-region-preview 1 t) t]
2616 ["2-up" (pr-ps-region-preview 2 t) t]
2617 ["4-up" (pr-ps-region-preview 4 t) t]
2618 ["Other..." (pr-ps-region-preview nil t)
2619 :keys "\\[pr-ps-region-preview]"])
2620 ("Mode" :included (and (not pr-spool-p) (pr-mode-alist-p))
2621 ["1-up" (pr-ps-mode-preview 1 t) t]
2622 ["2-up" (pr-ps-mode-preview 2 t) t]
2623 ["4-up" (pr-ps-mode-preview 4 t) t]
2624 ["Other..." (pr-ps-mode-preview nil t)
2625 :keys "\\[pr-ps-mode-preview]"])
2626 ("File"
2627 ["As Is..." (call-interactively 'pr-ps-file-preview)
2628 :keys "\\[pr-ps-file-preview]"]
2629 "--"
2630 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist]
2631 "--"
2632 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
2633 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
2634 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
2635 ["Other..." (pr-ps-file-up-preview nil t t)
2636 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
2637 "--"
2638 ["Landscape" pr-toggle-file-landscape
2639 :style toggle :selected pr-file-landscape
2640 :active pr-ps-utility-alist]
2641 ["Duplex" pr-toggle-file-duplex
2642 :style toggle :selected pr-file-duplex
2643 :active pr-ps-utility-alist]
2644 ["Tumble" pr-toggle-file-tumble
2645 :style toggle :selected pr-file-tumble
2646 :active (and pr-file-duplex pr-ps-utility-alist)])
2647 ["Despool..." (call-interactively 'pr-despool-preview)
2648 :active pr-spool-p :keys "\\[pr-despool-preview]"])
2649 ("PostScript Print" :included (pr-visible-p 'postscript)
2650 ("Directory"
2651 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
2652 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
2653 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
2654 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
2655 :keys "\\[pr-ps-buffer-ps-print]"])
2656 ("Buffer"
2657 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
2658 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
2659 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
2660 ["Other..." (pr-ps-buffer-ps-print nil t)
2661 :keys "\\[pr-ps-buffer-ps-print]"])
2662 ("Region" :included (ps-mark-active-p)
2663 ["1-up" (pr-ps-region-ps-print 1 t) t]
2664 ["2-up" (pr-ps-region-ps-print 2 t) t]
2665 ["4-up" (pr-ps-region-ps-print 4 t) t]
2666 ["Other..." (pr-ps-region-ps-print nil t)
2667 :keys "\\[pr-ps-region-ps-print]"])
2668 ("Mode" :included (pr-mode-alist-p)
2669 ["1-up" (pr-ps-mode-ps-print 1 t) t]
2670 ["2-up" (pr-ps-mode-ps-print 2 t) t]
2671 ["4-up" (pr-ps-mode-ps-print 4 t) t]
2672 ["Other..." (pr-ps-mode-ps-print nil t)
2673 :keys "\\[pr-ps-mode-ps-print]"])
2674 ("File"
2675 ["As Is..." (call-interactively 'pr-ps-file-ps-print)
2676 :keys "\\[pr-ps-file-ps-print]"]
2677 "--"
2678 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist]
2679 "--"
2680 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
2681 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
2682 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
2683 ["Other..." (pr-ps-file-up-ps-print nil t t)
2684 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
2685 "--"
2686 ["Landscape" pr-toggle-file-landscape
2687 :style toggle :selected pr-file-landscape
2688 :active pr-ps-utility-alist]
2689 ["Duplex" pr-toggle-file-duplex
2690 :style toggle :selected pr-file-duplex
2691 :active pr-ps-utility-alist]
2692 ["Tumble" pr-toggle-file-tumble
2693 :style toggle :selected pr-file-tumble
2694 :active (and pr-file-duplex pr-ps-utility-alist)])
2695 ["Despool..." (call-interactively 'pr-despool-ps-print)
2696 :active pr-spool-p :keys "\\[pr-despool-ps-print]"])
2697 ["PostScript Printers" pr-update-menus
2698 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)]
2699 "--"
2700 ("Printify" :included (pr-visible-p 'text)
2701 ["Directory" pr-printify-directory t]
2702 ["Buffer" pr-printify-buffer t]
2703 ["Region" pr-printify-region (ps-mark-active-p)])
2704 ("Print" :included (pr-visible-p 'text)
2705 ["Directory" pr-txt-directory t]
2706 ["Buffer" pr-txt-buffer t]
2707 ["Region" pr-txt-region (ps-mark-active-p)]
2708 ["Mode" pr-txt-mode (pr-mode-alist-p)])
2709 ["Text Printers" pr-update-menus
2710 :active pr-txt-printer-alist :included (pr-visible-p 'text)]
2711 "--"
2712 ["Landscape" pr-toggle-landscape
2713 :style toggle :selected ps-landscape-mode
2714 :included (pr-visible-p 'postscript-options)]
2715 ["Print Header" pr-toggle-header
2716 :style toggle :selected ps-print-header
2717 :included (pr-visible-p 'postscript-options)]
2718 ["Print Header Frame" pr-toggle-header-frame
2719 :style toggle :selected ps-print-header-frame :active ps-print-header
2720 :included (pr-visible-p 'postscript-options)]
2721 ["Line Number" pr-toggle-line
2722 :style toggle :selected ps-line-number
2723 :included (pr-visible-p 'postscript-options)]
2724 ["Zebra Stripes" pr-toggle-zebra
2725 :style toggle :selected ps-zebra-stripes
2726 :included (pr-visible-p 'postscript-options)]
2727 ["Duplex" pr-toggle-duplex
2728 :style toggle :selected ps-spool-duplex
2729 :included (pr-visible-p 'postscript-options)]
2730 ["Tumble" pr-toggle-tumble
2731 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
2732 :included (pr-visible-p 'postscript-options)]
2733 ["Upside-Down" pr-toggle-upside-down
2734 :style toggle :selected ps-print-upside-down
2735 :included (pr-visible-p 'postscript-options)]
2736 ("Print All Pages" :included (pr-visible-p 'postscript-options)
2737 ["All Pages" (pr-even-or-odd-pages nil)
2738 :style radio :selected (eq ps-even-or-odd-pages nil)]
2739 ["Even Pages" (pr-even-or-odd-pages 'even-page)
2740 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
2741 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
2742 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
2743 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
2744 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
2745 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
2746 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
2747 "--"
2748 ["Spool Buffer" pr-toggle-spool
2749 :style toggle :selected pr-spool-p
2750 :included (pr-visible-p 'postscript-process)]
2751 ["Print with-faces" pr-toggle-faces
2752 :style toggle :selected pr-faces-p
2753 :included (pr-visible-p 'postscript-process)]
2754 ["Print Using Ghostscript" pr-toggle-ghostscript
2755 :style toggle :selected pr-print-using-ghostscript
2756 :included (pr-visible-p 'postscript-process)]
2757 "--"
2758 ["Auto Region" pr-toggle-region
2759 :style toggle :selected pr-auto-region
2760 :included (pr-visible-p 'printing)]
2761 ["Auto Mode" pr-toggle-mode
2762 :style toggle :selected pr-auto-mode
2763 :included (pr-visible-p 'printing)]
2764 ["Menu Lock" pr-toggle-lock
2765 :style toggle :selected pr-menu-lock
2766 :included (pr-visible-p 'printing)]
2767 "--"
2768 ("Customize" :included (pr-visible-p 'help)
2769 ["printing" pr-customize t]
2770 ["ps-print" ps-print-customize t]
2771 ["lpr" lpr-customize t])
2772 ("Show Settings" :included (pr-visible-p 'help)
2773 ["printing" pr-show-pr-setup t]
2774 ["ps-print" pr-show-ps-setup t]
2775 ["lpr" pr-show-lpr-setup t])
2776 ["Help" pr-help :active t :included (pr-visible-p 'help)]
2781 (cond
2782 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
2783 ;; Menu binding
2784 (require 'easymenu)
2785 ;; Replace existing "print" item by "Printing" item.
2786 ;; If you're changing this file, you'll load it a second,
2787 ;; third... time, but "print" item exists only in the first load.
2788 (defvar pr-menu-print-item "print")
2789 (cond
2790 ;; Emacs 20
2791 ((string< emacs-version "21.")
2792 (easy-menu-change '("tools") "Printing" pr-menu-spec pr-menu-print-item)
2793 (when pr-menu-print-item
2794 (easy-menu-remove-item nil '("tools") pr-menu-print-item)
2795 (setq pr-menu-print-item nil
2796 pr-menu-bar (vector 'menu-bar 'tools
2797 (pr-get-symbol "Printing")))))
2798 ;; Emacs 21
2799 (pr-menu-print-item
2800 (easy-menu-change '("files") "Print" pr-menu-spec "print-buffer")
2801 (let ((items '("print-buffer" "print-region"
2802 "ps-print-buffer-faces" "ps-print-region-faces"
2803 "ps-print-buffer" "ps-print-region")))
2804 (while items
2805 (easy-menu-remove-item nil '("files") (car items))
2806 (setq items (cdr items)))
2807 (setq pr-menu-print-item nil
2808 pr-menu-bar (vector 'menu-bar 'files
2809 (pr-get-symbol "Print")))))
2811 (easy-menu-change '("files") "Print" pr-menu-spec)))
2813 ;; Key binding
2814 (global-set-key [print] 'pr-ps-fast-fire)
2815 (global-set-key [M-print] 'pr-ps-mode-using-ghostscript)
2816 (global-set-key [C-print] 'pr-txt-fast-fire))
2819 ((eq ps-print-emacs-type 'xemacs) ; XEmacs
2820 ;; Menu binding
2821 (pr-xemacs-global-menubar
2822 (pr-x-add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
2824 ;; Key binding
2825 (global-set-key 'f22 'pr-ps-fast-fire)
2826 (global-set-key '(meta f22) 'pr-ps-mode-using-ghostscript)
2827 (global-set-key '(control f22) 'pr-txt-fast-fire))))
2830 ;;; You can also use something like:
2831 ;;;(global-set-key "\C-ci" 'pr-interface)
2832 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
2833 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
2834 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
2835 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
2836 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
2837 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
2840 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2841 ;; Help Message
2844 (defconst pr-help-message
2845 (concat "printing.el version " pr-version
2846 " ps-print.el version " ps-print-version
2847 "\n\n
2848 Menu Layout
2849 -----------
2851 The `printing' menu (Tools/Printing or File/Print) has the following layout:
2853 +-----------------------------+
2854 A 0 | Printing Interface |
2855 +-----------------------------+ +-A---------+ +-B------+
2856 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
2857 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
2858 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
2859 +-----------------------------+ |Mode >|-- B |Other...|
2860 II 4 | Printify >|-----\\ |File >|--\\ +--------+
2861 5 | Print >|---\\ | |Despool... | |
2862 6 | Text Printer: name >|-\\ | | +-----------+ |
2863 +-----------------------------+ | | | +---------+ +------------+
2864 III 7 |[ ]Landscape | | | \\-|Directory| | As Is... | Ia
2865 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
2866 9 |[ ]Print Header Frame | | | |Region | | name >|- C
2867 10 |[ ]Line Number | | | +---------+ +------------+
2868 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
2869 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
2870 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
2871 14 |[ ]Upside-Down | | |Region | | Other... |
2872 15 | Print All Pages >|--\\ | |Mode | +------------+
2873 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
2874 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
2875 17 |[ ]Print with-faces | | \\--|( )name A| |[ ]Tumble | If
2876 18 |[ ]Print Using Ghostscript | | |( )name B| +------------+
2877 +-----------------------------+ | |... |
2878 V 19 |[ ]Auto Region | | |(*)name |
2879 20 |[ ]Auto Mode | | |... |
2880 21 |[ ]Menu Lock | | +---------+ +--------------+
2881 +-----------------------------+ \\------------------|(*)All Pages |
2882 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
2883 23 | Show Settings >|-------|printing| |( )Odd Pages |
2884 24 | Help | |ps-print| |( )Even Sheets|
2885 +-----------------------------+ |lpr | |( )Odd Sheets |
2886 +--------+ +--------------+
2888 See `pr-visible-entry-list' for hiding some parts of the menu.
2890 The menu has the following sections:
2892 A. Interface:
2894 0. You can use a buffer interface instead of menus. It looks like the
2895 customization buffer. Basically, it has the same options found in the
2896 menu and some extra options, all this on a buffer.
2898 I. PostScript printing:
2900 1. You can generate a PostScript file (if you type C-u before activating
2901 menu) or PostScript temporary file for a directory, a buffer, a region
2902 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
2903 after file generation, ghostview is activated using the file generated
2904 as argument. This option is disabled if spooling is on (option 16).
2905 Also, if you already have a PostScript file you can preview it.
2906 Instead of previewing each buffer, region or major mode at once, you
2907 can save temporarily the PostScript code generated in a buffer and
2908 preview it later. The option `Despool...' despools the PostScript
2909 spooling buffer in a temporary file and uses ghostview to preview it.
2910 If you type C-u before choosing this option, the PostScript code
2911 generated is saved in a file instead of saving in a temporary file. To
2912 spool the PostScript code generated you need to turn on the option 16.
2913 The option `Despool...' is enabled if spooling is on (option 16).
2915 NOTE 1: It's possible to customize a major mode printing, just declare
2916 the customization in `pr-mode-alist' and invoke some of
2917 `*-mode*' commands or select Mode option in Printing menu. An
2918 example for major mode usage is when you're using gnus (or mh,
2919 or rmail, etc.) and you're in the *Summary* buffer, if you
2920 forget to switch to the *Article* buffer before printing,
2921 you'll get a nicely formatted list of article subjects shows
2922 up at the printer. With major mode printing you don't need to
2923 switch from gnus *Summary* buffer first.
2925 NOTE 2: There are the following options for PostScript file processing:
2926 Ia. Print the file *as is*, that is, send it directly to
2927 PostScript printer.
2928 Ib. PostScript utility processing selection.
2929 See `pr-ps-utility-alist' and `pr-setting-database' for
2930 documentation.
2931 Ic. Do n-up processing before printing.
2932 Id. Toggle on/off landscape for PostScript file processing.
2933 Ie. Toggle on/off duplex for PostScript file processing.
2934 If. Toggle on/off tumble for PostScript file processing.
2936 NOTE 3: Don't forget to download and install the utilities declared on
2937 `pr-ps-utility-alist'.
2939 2. Operate the same way as option 1, but it sends directly the PostScript
2940 code (or put in a file, if you've typed C-u) or it uses ghostscript to
2941 print the PostScript file generated. It depends on option 18, if it's
2942 turned on, it uses ghostscript; otherwise, it sends directly to
2943 printer. If spooling is on (option 16), the PostScript code is saved
2944 temporarily in a buffer instead of printing it or saving it in a file.
2945 Also, if you already have a PostScript file you can print it.
2946 Instead of printing each buffer, region or major mode at once, you can
2947 save temporarily the PostScript code generated in a buffer and print it
2948 later. The option `Despool...' despools the PostScript spooling buffer
2949 directly on a printer. If you type C-u before choosing this option,
2950 the PostScript code generated is saved in a file instead of sending to
2951 printer. To spool the PostScript code generated you need to turn on
2952 the option 16. This option is enabled if spooling is on (option 16).
2953 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
2955 3. You can select a new PostScript printer to send PostScript code
2956 generated. For selection it's used all PostScript printers defined
2957 in `pr-ps-printer-alist' variable (see it for documentation).
2958 See also `pr-setting-database'.
2960 II. Text printing:
2962 4. If you have control characters (character code from \\000 to \\037) in a
2963 buffer and you want to print them in a text printer, select this
2964 option. All control characters in your buffer or region will be
2965 replaced by a printable representation. The printable representations
2966 use ^ (for ASCII control characters) or hex. The characters tab,
2967 linefeed, space, return and formfeed are not affected.
2968 You don't need to select this option if you use any option of section
2969 I, the PostScript engine treats control characters properly.
2971 5. If you want to print a directory, buffer, region or major mode in a
2972 text printer, select this option. See also the NOTE 1 on option 1.
2974 6. You can select a new text printer to send text generated. For
2975 selection it's used all text printers defined in `pr-txt-printer-alist'
2976 variable (see it for documentation).
2977 See also `pr-setting-database'.
2979 III. PostScript page toggle options:
2981 7. If you want a PostScript landscape printing, turn on this option.
2983 8. If you want to have a header in each page in your PostScript code,
2984 turn on this option.
2986 9. If you want to draw a gaudy frame around the header, turn on this
2987 option. This option is enabled if print header is on (option 8).
2989 10. If you want that the line number is printed in your PostScript code,
2990 turn on this option.
2992 11. If you want background zebra stripes in your PostScript code, turn on
2993 this option.
2995 12. If you want a duplex printing and your PostScript printer has this
2996 feature, turn on this option.
2998 13. If you turned on duplex printing, you can choose if you want to have a
2999 printing suitable for binding on the left or right (tumble off), or to
3000 have a printing suitable for binding at top or bottom (tumble on).
3001 This option is enabled if duplex is on (option 12).
3003 14. If you want a PostScript upside-down printing, turn on this option.
3005 15. With this option, you can choose if you want to print all pages, odd
3006 pages, even pages, odd sheets or even sheets.
3007 See also `ps-even-or-odd-pages'.
3009 IV. PostScript processing toggle options:
3011 16. If you want to spool the PostScript code generated, turn on this
3012 option. To spool the PostScript code generated use option 2. You can
3013 despool later by choosing option 1 or 2, sub-option `Despool...'.
3015 17. If you use colors in your buffers and want to see these colors on your
3016 PostScript code generated, turn on this option. If you have a
3017 black/white PostScript printer, these colors are displayed in gray
3018 scale by PostScript printer interpreter.
3020 18. If you don't have a PostScript printer to send PostScript files, turn
3021 on this option. When this option is on, the ghostscript is used to
3022 print PostScript files. In GNU or Unix system, if ghostscript is set
3023 as a PostScript filter, you don't need to turn on this option.
3025 V. Printing customization:
3027 19. If you want that region is automagically detected, turn on this
3028 option. Note that this will only work if you're using transient mark
3029 mode. When this option is on, the `*-buffer*' commands will behave
3030 like `*-region*' commands, that is, `*-buffer*' commands will print
3031 only the region marked instead of all buffer.
3033 20. Turn this option on if you want that when current major-mode is
3034 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3035 behave like `*-mode*' commands.
3037 21. If you want that Printing menu stays poped while you are setting
3038 toggle options, turn on this option. The variables
3039 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3040 menu position, so don't forget to adjust these variables if menu
3041 position is not ok.
3043 VI. Customization:
3045 22. Besides all options in section III, IV and V, you can customize much
3046 more PostScript options in `ps-print' option. Or you can customize
3047 some `lpr' options for text printing. Or customize `printing'
3048 options.
3050 23. Show current settings for `printing', `ps-print' or `lpr'.
3052 24. Quick help for printing menu layout.
3054 "Printing help message.")
3057 (defconst pr-interface-help-message
3058 (concat "printing.el version " pr-version
3059 " ps-print.el version " ps-print-version
3060 "\n\n
3061 The printing interface buffer has the same functionality as the printing menu.
3062 The major difference is that the states (like sending PostScript generated to a
3063 file, n-up printing, etc.) are set and saved between priting buffer
3064 activation. Also, the landscape, duplex and tumble values are the same for
3065 PostScript file and directory/buffer/region/mode processing; using menu, there
3066 are different value sets for PostScript file and directory/buffer/region/mode
3067 processing.
3069 The printing interface buffer has the following sections:
3071 1. Print:
3073 Here you can choose to print/preview a buffer, a directory or a PostScript
3074 file:
3076 1a. Buffer:
3078 * Buffer List:
3079 Select a buffer from the current buffer list.
3081 * Region:
3082 If it's on, this means that the selected buffer has an active region,
3083 so you can turn on/off, as you wish.
3084 If it's off when a buffer is selected, this means that the selected
3085 buffer has no active region, so it'll not be possible to turn it on.
3086 If you want to process the region, let this option on.
3087 If you want to process the whole buffer, let this option off.
3089 * Mode:
3090 If it's on, this means that the selected buffer major mode is declared
3091 for major mode processing, so you can turn on/off, as you wish.
3092 If it's off when a buffer is selected, this means that the selected
3093 buffer major mode isn't declared for major mode processing, so it'll
3094 not be possible to turn it on.
3095 If you want the major mode processing, let this option on.
3096 If you don't want the major mode processing, let this option off.
3098 NOTE 1: It's possible to customize a major mode printing, just declare
3099 the customization in `pr-mode-alist' and invoke some of
3100 `*-mode*' commands or select Mode option in Printing menu. An
3101 example for major mode usage is when you're using gnus (or mh,
3102 or rmail, etc.) and you're in the *Summary* buffer, if you
3103 forget to switch to the *Article* buffer before printing,
3104 you'll get a nicely formatted list of article subjects shows
3105 up at the printer. With major mode printing you don't need to
3106 switch from gnus *Summary* buffer first.
3108 1b. Directory:
3110 * Directory:
3111 Specify a valid directory path.
3113 * File Regexp:
3114 Specify a file name regexp. All file names in the directory that
3115 match with regexp will be printed/previewed. An empty file name
3116 regexp means to print/preview all files in the directory.
3118 * List Directory Entry:
3119 If it's turned on, list directory entries besides file entries.
3121 1c. PostScript file:
3123 * PostScript File:
3124 Specify an existent PostScript file to print/preview.
3126 * PostScript Utility:
3127 Select a PostScript utility.
3128 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3130 NOTE 2: Don't forget to download and install the utilities declared on
3131 `pr-ps-utility-alist'.
3133 * Use It AS-IS :
3134 If it's turned on, don't use the PostScript utility to preprocess the
3135 PostScript file before printing/previewing.
3137 2. PostScript printer:
3139 * PostScript Printer:
3140 You can select a new PostScript printer to send PostScript code
3141 generated. For selection it's used all PostScript printers defined
3142 in `pr-ps-printer-alist' variable (see it for documentation).
3143 See also `pr-setting-database'.
3145 * Despool:
3146 If spooling is on, you can turn it on/off, as you wish.
3147 If spooling is off, it'll not be possible to turn it on.
3148 If it's turned on, specify to despools the PostScript spooling buffer in
3149 a temporary file or in the selected PostScript file when
3150 printing/previewing.
3152 * Preview:
3153 Preview the PostScript generated.
3155 * Print:
3156 Print the PostScript generated.
3158 * Quit:
3159 Quit from printing interface buffer.
3161 * Send to Printer/Temporary File:
3162 If it's turned on, the PostScript generated is sent directly to
3163 PostScript printer or, for previewing, to a temporary file.
3165 * Send to File:
3166 Specify a file name to send the PostScript generated.
3168 * N-Up:
3169 Specify n-up printing.
3171 3. Text printer:
3173 * Text Printer:
3174 Select a new text printer to send text generated. For selection it's used
3175 all text printers defined in `pr-txt-printer-alist' variable (see it for
3176 documentation). See also `pr-setting-database'.
3178 * Printify:
3179 If you have control characters (character code from \\000 to \\037) in a
3180 buffer and you want to print them in a text printer, select this
3181 option. All control characters in your buffer or region will be
3182 replaced by a printable representation. The printable representations
3183 use ^ (for ASCII control characters) or hex. The characters tab,
3184 linefeed, space, return and formfeed are not affected.
3185 You don't need to select this option if you use any option of section
3186 I, the PostScript engine treats control characters properly.
3188 * Print:
3189 To print a directory, buffer, region or major mode in a
3190 text printer, select this option. See also the NOTE 1 on section 1.
3192 * Quit:
3193 Quit from printing interface buffer.
3195 4. Settings:
3197 There are 3 setting columns:
3199 4a. First column (left column):
3201 * Landscape:
3202 PostScript landscape printing.
3204 * Print Header:
3205 To have a header in each page in your PostScript code.
3207 * Print Header Frame:
3208 To draw a gaudy frame around the header.
3210 * Line Number:
3211 The line number is printed in your PostScript code.
3213 * Zebra Stripes:
3214 Background zebra stripes in your PostScript code.
3216 * Duplex:
3217 Duplex printing (if your PostScript printer has this feature).
3219 * Tumble:
3220 If duplex printing is on, you can choose if you want to have a
3221 printing suitable for binding on the left or right (tumble off), or to
3222 have a printing suitable for binding at top or bottom (tumble on).
3224 * Upside-Down:
3225 PostScript upside-down printing.
3227 4b. Second column (middle column):
3229 * Auto Region:
3230 If you want that region is automagically detected, turn on this
3231 option. Note that this will only work if you're using transient mark
3232 mode. When this option is on, the `*-buffer*' commands will behave
3233 like `*-region*' commands, that is, `*-buffer*' commands will print
3234 only the region marked instead of all buffer.
3236 * Auto Mode:
3237 Turn this option on if you want that when current major-mode is
3238 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3239 behave like `*-mode*' commands.
3241 * Menu Lock:
3242 If you want that Printing menu stays poped while you are setting
3243 toggle options, turn on this option. The variables
3244 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3245 menu position, so don't forget to adjust these variables if menu
3246 position is not ok.
3248 * Spool Buffer:
3249 To spool the PostScript code generated. You can despool later by
3250 setting Despool option on PostScript printer section.
3252 * Print with-faces:
3253 If you use colors in your buffers and want to see these colors on your
3254 PostScript code generated, turn on this option. If you have a
3255 black/white PostScript printer, these colors are displayed in gray
3256 scale by PostScript printer interpreter.
3258 * Print Using Ghostscript:
3259 If you don't have a PostScript printer to send PostScript files, turn
3260 on this option. When this option is on, the ghostscript is used to
3261 print PostScript files. In GNU or Unix system, if ghostscript is set
3262 as a PostScript filter, you don't need to turn on this option.
3264 * Parity Page Menu:
3265 To print all pages, odd pages, even pages, odd sheets or even sheets.
3266 See also `ps-even-or-odd-pages'.
3268 4c. Third column (right column):
3270 * Verbose:
3271 That is, to be verbose when editing a field in interface buffer.
3273 5. Customize:
3275 Besides all options in section 4, you can customize much more PostScript
3276 options in `ps-print' option. Or you can customize some `lpr' options for
3277 text printing. Or customize `printing' options.
3279 6. Show settings:
3281 Show current settings for `printing', `ps-print' or `lpr'.
3283 7. Help:
3285 Quick help for printing interface buffer and printing menu layout. You can
3286 also quit the printing interface buffer or kill all printing help buffer.
3288 "Printing buffer interface help message.")
3291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3292 ;; Commands
3295 ;;;###autoload
3296 (defun pr-interface (&optional buffer)
3297 "Activate the printing interface buffer.
3299 If BUFFER is nil, it uses the current buffer for printing.
3301 For more informations, type \\[pr-interface-help]."
3302 (interactive)
3303 (save-excursion
3304 (set-buffer (or buffer (current-buffer)))
3305 (pr-create-interface)))
3308 ;;;###autoload
3309 (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3310 "Preview directory using ghostview.
3312 Interactively, the command prompts for N-UP printing number, a directory, a
3313 file name regexp for matching and, when you use a prefix argument (C-u), the
3314 command prompts the user for a file name, and saves the PostScript image in
3315 that file instead of saving it in a temporary file.
3317 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3318 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3319 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3320 save the image in a temporary file. If FILENAME is a string, save the
3321 PostScript image in a file with that name. If FILENAME is t, prompts for a
3322 file name.
3324 See also documentation for `pr-list-directory'."
3325 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3326 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3327 (pr-prompt "PS preview dir"))
3328 (setq filename (pr-ps-file filename))
3329 (pr-ps-file-list n-up dir file-regexp filename)
3330 (or pr-spool-p
3331 (pr-ps-file-preview filename)))
3334 ;;;###autoload
3335 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3336 "Print directory using PostScript through ghostscript.
3338 Interactively, the command prompts for N-UP printing number, a directory, a
3339 file name regexp for matching and, when you use a prefix argument (C-u), the
3340 command prompts the user for a file name, and saves the PostScript image in
3341 that file instead of saving it in a temporary file.
3343 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3344 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3345 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3346 save the image in a temporary file. If FILENAME is a string, save the
3347 PostScript image in a file with that name. If FILENAME is t, prompts for a
3348 file name.
3350 See also documentation for `pr-list-directory'."
3351 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3352 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3353 (pr-prompt "PS print dir GS"))
3354 (let ((file (pr-ps-file filename)))
3355 (pr-ps-file-list n-up dir file-regexp file)
3356 (pr-ps-file-using-ghostscript file)
3357 (or filename (pr-delete-file file))))
3360 ;;;###autoload
3361 (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
3362 "Print directory using PostScript printer.
3364 Interactively, the command prompts for N-UP printing number, a directory, a
3365 file name regexp for matching and, when you use a prefix argument (C-u), the
3366 command prompts the user for a file name, and saves the PostScript image in
3367 that file instead of saving it in a temporary file.
3369 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3370 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3371 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3372 save the image in a temporary file. If FILENAME is a string, save the
3373 PostScript image in a file with that name. If FILENAME is t, prompts for a
3374 file name.
3376 See also documentation for `pr-list-directory'."
3377 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
3378 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3379 (pr-prompt "PS print dir"))
3380 (let ((file (pr-ps-file filename)))
3381 (pr-ps-file-list n-up dir file-regexp file)
3382 (pr-ps-file-print file)
3383 (or filename (pr-delete-file file))))
3386 ;;;###autoload
3387 (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
3388 "Print directory using PostScript printer or through ghostscript.
3390 It depends on `pr-print-using-ghostscript'.
3392 Interactively, the command prompts for N-UP printing number, a directory, a
3393 file name regexp for matching and, when you use a prefix argument (C-u), the
3394 command prompts the user for a file name, and saves the PostScript image in
3395 that file instead of saving it in a temporary file.
3397 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3398 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3399 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3400 save the image in a temporary file. If FILENAME is a string, save the
3401 PostScript image in a file with that name. If FILENAME is t, prompts for a
3402 file name.
3404 See also documentation for `pr-list-directory'."
3405 (interactive (pr-interactive-ps-dir-args
3406 (pr-prompt (pr-prompt-gs "PS print dir"))))
3407 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3408 (pr-prompt (pr-prompt-gs "PS print dir")))
3409 (if (pr-using-ghostscript-p)
3410 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
3411 (pr-ps-directory-print n-up dir file-regexp filename)))
3414 ;;;###autoload
3415 (defun pr-ps-buffer-preview (n-up &optional filename)
3416 "Preview buffer using ghostview.
3418 Interactively, the command prompts for N-UP printing number and, when you use a
3419 prefix argument (C-u), the command prompts the user for a file name, and saves
3420 the PostScript image in that file instead of saving it in a temporary file.
3422 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3423 argument FILENAME is treated as follows: if it's nil, save the image in a
3424 temporary file. If FILENAME is a string, save the PostScript image in a file
3425 with that name. If FILENAME is t, prompts for a file name."
3426 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
3427 (if (pr-auto-mode-p)
3428 (pr-ps-mode-preview n-up filename)
3429 (pr-ps-preview (pr-region-active-symbol) n-up filename
3430 (pr-region-active-string "PS preview"))))
3433 ;;;###autoload
3434 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
3435 "Print buffer using PostScript through ghostscript.
3437 Interactively, the command prompts for N-UP printing number and, when you use a
3438 prefix argument (C-u), the command prompts the user for a file name, and saves
3439 the PostScript image in that file instead of sending it to the printer.
3441 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3442 argument FILENAME is treated as follows: if it's nil, send the image to the
3443 printer. If FILENAME is a string, save the PostScript image in a file with
3444 that name. If FILENAME is t, prompts for a file name."
3445 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
3446 (if (pr-auto-mode-p)
3447 (pr-ps-mode-using-ghostscript n-up filename)
3448 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3449 (pr-region-active-string "PS print GS"))))
3452 ;;;###autoload
3453 (defun pr-ps-buffer-print (n-up &optional filename)
3454 "Print buffer using PostScript printer.
3456 Interactively, the command prompts for N-UP printing number and, when you use a
3457 prefix argument (C-u), the command prompts the user for a file name, and saves
3458 the PostScript image in that file instead of sending it to the printer.
3460 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3461 argument FILENAME is treated as follows: if it's nil, send the image to the
3462 printer. If FILENAME is a string, save the PostScript image in a file with
3463 that name. If FILENAME is t, prompts for a file name."
3464 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
3465 (if (pr-auto-mode-p)
3466 (pr-ps-mode-print n-up filename)
3467 (pr-ps-print (pr-region-active-symbol) n-up filename
3468 (pr-region-active-string "PS print"))))
3471 ;;;###autoload
3472 (defun pr-ps-buffer-ps-print (n-up &optional filename)
3473 "Print buffer using PostScript printer or through ghostscript.
3475 It depends on `pr-print-using-ghostscript'.
3477 Interactively, the command prompts for N-UP printing number and, when you use a
3478 prefix argument (C-u), the command prompts the user for a file name, and saves
3479 the PostScript image in that file instead of sending it to the printer.
3481 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3482 argument FILENAME is treated as follows: if it's nil, send the image to the
3483 printer. If FILENAME is a string, save the PostScript image in a file with
3484 that name. If FILENAME is t, prompts for a file name."
3485 (interactive (pr-interactive-n-up-file
3486 (pr-prompt (pr-prompt-gs "PS print"))))
3487 (cond ((pr-auto-mode-p)
3488 (pr-ps-mode-ps-print n-up filename))
3489 ((pr-using-ghostscript-p)
3490 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3491 (pr-region-active-string "PS print GS")))
3493 (pr-ps-print (pr-region-active-symbol) n-up filename
3494 (pr-region-active-string "PS print")))))
3497 ;;;###autoload
3498 (defun pr-ps-region-preview (n-up &optional filename)
3499 "Preview region using ghostview.
3501 See also `pr-ps-buffer-preview'."
3502 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
3503 (if (pr-auto-mode-p)
3504 (let ((pr-auto-region t))
3505 (pr-ps-mode-preview n-up filename))
3506 (pr-ps-preview 'region n-up filename "PS preview region")))
3509 ;;;###autoload
3510 (defun pr-ps-region-using-ghostscript (n-up &optional filename)
3511 "Print region using PostScript through ghostscript.
3513 See also `pr-ps-buffer-using-ghostscript'."
3514 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
3515 (if (pr-auto-mode-p)
3516 (let ((pr-auto-region t))
3517 (pr-ps-mode-using-ghostscript n-up filename))
3518 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
3521 ;;;###autoload
3522 (defun pr-ps-region-print (n-up &optional filename)
3523 "Print region using PostScript printer.
3525 See also `pr-ps-buffer-print'."
3526 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
3527 (if (pr-auto-mode-p)
3528 (let ((pr-auto-region t))
3529 (pr-ps-mode-print n-up filename))
3530 (pr-ps-print 'region n-up filename "PS print region")))
3533 ;;;###autoload
3534 (defun pr-ps-region-ps-print (n-up &optional filename)
3535 "Print region using PostScript printer or through ghostscript.
3537 See also `pr-ps-buffer-ps-print'."
3538 (interactive (pr-interactive-n-up-file
3539 (pr-prompt-region (pr-prompt-gs "PS print"))))
3540 (cond ((pr-auto-mode-p)
3541 (let ((pr-auto-region t))
3542 (pr-ps-mode-ps-print n-up filename)))
3543 ((pr-using-ghostscript-p)
3544 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
3546 (pr-ps-print 'region n-up filename "PS print region"))))
3549 ;;;###autoload
3550 (defun pr-ps-mode-preview (n-up &optional filename)
3551 "Preview major mode using ghostview.
3553 See also `pr-ps-buffer-preview'."
3554 (interactive (pr-interactive-n-up-file "PS preview mode"))
3555 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
3556 (let ((file (pr-ps-file filename)))
3557 (and (pr-ps-mode n-up file)
3558 (not pr-spool-p)
3559 (pr-ps-file-preview file))))
3562 ;;;###autoload
3563 (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
3564 "Print major mode using PostScript through ghostscript.
3566 See also `pr-ps-buffer-using-ghostscript'."
3567 (interactive (pr-interactive-n-up-file "PS print GS mode"))
3568 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
3569 (let ((file (pr-ps-file filename)))
3570 (when (and (pr-ps-mode n-up file)
3571 (not pr-spool-p))
3572 (pr-ps-file-using-ghostscript file)
3573 (or filename (pr-delete-file file)))))
3576 ;;;###autoload
3577 (defun pr-ps-mode-print (n-up &optional filename)
3578 "Print major mode using PostScript printer.
3580 See also `pr-ps-buffer-print'."
3581 (interactive (pr-interactive-n-up-file "PS print mode"))
3582 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
3583 (pr-ps-mode n-up filename))
3586 ;;;###autoload
3587 (defun pr-ps-mode-ps-print (n-up &optional filename)
3588 "Print major mode using PostScript or through ghostscript.
3590 See also `pr-ps-buffer-ps-print'."
3591 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
3592 (if (pr-using-ghostscript-p)
3593 (pr-ps-mode-using-ghostscript n-up filename)
3594 (pr-ps-mode-print n-up filename)))
3597 ;;;###autoload
3598 (defun pr-printify-directory (&optional dir file-regexp)
3599 "Replace nonprinting characters in directory with printable representations.
3600 The printable representations use ^ (for ASCII control characters) or hex.
3601 The characters tab, linefeed, space, return and formfeed are not affected.
3603 Interactively, the command prompts for a directory and a file name regexp for
3604 matching.
3606 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3607 prompts for FILE(name)-REGEXP.
3609 See also documentation for `pr-list-directory'."
3610 (interactive (pr-interactive-dir-args "Printify dir"))
3611 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
3612 (pr-file-list dir file-regexp 'pr-printify-buffer))
3615 ;;;###autoload
3616 (defun pr-printify-buffer ()
3617 "Replace nonprinting characters in buffer with printable representations.
3618 The printable representations use ^ (for ASCII control characters) or hex.
3619 The characters tab, linefeed, space, return and formfeed are not affected."
3620 (interactive "*")
3621 (if (pr-region-active-p)
3622 (pr-printify-region)
3623 (printify-region (point-min) (point-max))))
3626 ;;;###autoload
3627 (defun pr-printify-region ()
3628 "Replace nonprinting characters in region with printable representations.
3629 The printable representations use ^ (for ASCII control characters) or hex.
3630 The characters tab, linefeed, space, return and formfeed are not affected."
3631 (interactive "*")
3632 (printify-region (point) (mark)))
3635 ;;;###autoload
3636 (defun pr-txt-directory (&optional dir file-regexp)
3637 "Print directory using text printer.
3639 Interactively, the command prompts for a directory and a file name regexp for
3640 matching.
3642 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3643 prompts for FILE(name)-REGEXP.
3645 See also documentation for `pr-list-directory'."
3646 (interactive (pr-interactive-dir-args "Print dir"))
3647 (pr-set-dir-args 'dir 'file-regexp "Print dir")
3648 (pr-file-list dir file-regexp 'pr-txt-buffer))
3651 ;;;###autoload
3652 (defun pr-txt-buffer ()
3653 "Print buffer using text printer."
3654 (interactive)
3655 (cond ((pr-auto-mode-p)
3656 (pr-txt-mode))
3657 ((pr-region-active-p)
3658 (pr-txt-region))
3660 (pr-txt-print (point-min) (point-max)))))
3663 ;;;###autoload
3664 (defun pr-txt-region ()
3665 "Print region using text printer."
3666 (interactive)
3667 (if (pr-auto-mode-p)
3668 (let ((pr-auto-region t))
3669 (pr-txt-mode))
3670 (pr-txt-print (point) (mark))))
3673 ;;;###autoload
3674 (defun pr-txt-mode ()
3675 "Print major mode using text printer."
3676 (interactive)
3677 (let ((args (pr-mode-alist-p)))
3678 (if args
3679 (funcall (car args) (nthcdr 2 args))
3680 (ding)
3681 (message "`%s' major mode not declared." major-mode))))
3684 ;;;###autoload
3685 (defun pr-despool-preview (&optional filename)
3686 "Preview spooled PostScript.
3688 Interactively, when you use a prefix argument (C-u), the command prompts the
3689 user for a file name, and saves the spooled PostScript image in that file
3690 instead of saving it in a temporary file.
3692 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3693 save the image in a temporary file. If FILENAME is a string, save the
3694 PostScript image in a file with that name."
3695 (interactive (list (ps-print-preprint current-prefix-arg)))
3696 (let ((file (pr-ps-file filename)))
3697 (when (stringp file)
3698 (pr-despool-print file)
3699 (pr-ps-file-preview file))))
3702 ;;;###autoload
3703 (defun pr-despool-using-ghostscript (&optional filename)
3704 "Print spooled PostScript using ghostscript.
3706 Interactively, when you use a prefix argument (C-u), the command prompts the
3707 user for a file name, and saves the spooled PostScript image in that file
3708 instead of sending it to the printer.
3710 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3711 send the image to the printer. If FILENAME is a string, save the PostScript
3712 image in a file with that name."
3713 (interactive (list (ps-print-preprint current-prefix-arg)))
3714 (let ((file (pr-ps-file filename)))
3715 (when (stringp file)
3716 (pr-despool-print file)
3717 (pr-ps-file-using-ghostscript file)
3718 (or filename (pr-delete-file file)))))
3721 ;;;###autoload
3722 (defun pr-despool-print (&optional filename)
3723 "Send the spooled PostScript to the printer.
3725 Interactively, when you use a prefix argument (C-u), the command prompts the
3726 user for a file name, and saves the spooled PostScript image in that file
3727 instead of sending it to the printer.
3729 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3730 send the image to the printer. If FILENAME is a string, save the PostScript
3731 image in a file with that name."
3732 (interactive (list (ps-print-preprint current-prefix-arg)))
3733 (let ((ps-lpr-command (pr-command pr-ps-command))
3734 (ps-lpr-switches pr-ps-switches)
3735 (ps-printer-name-option pr-ps-printer-switch)
3736 (ps-printer-name pr-ps-printer))
3737 (ps-despool filename)))
3740 ;;;###autoload
3741 (defun pr-despool-ps-print (&optional filename)
3742 "Send the spooled PostScript to the printer or use ghostscript to print it.
3744 Interactively, when you use a prefix argument (C-u), the command prompts the
3745 user for a file name, and saves the spooled PostScript image in that file
3746 instead of sending it to the printer.
3748 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3749 send the image to the printer. If FILENAME is a string, save the PostScript
3750 image in a file with that name."
3751 (interactive (list (ps-print-preprint current-prefix-arg)))
3752 (if pr-print-using-ghostscript
3753 (pr-despool-using-ghostscript filename)
3754 (pr-despool-print filename)))
3757 ;;;###autoload
3758 (defun pr-ps-file-preview (filename)
3759 "Preview PostScript file FILENAME."
3760 (interactive (list (pr-ps-infile-preprint "Preview ")))
3761 (and (stringp filename) (file-exists-p filename)
3762 (let ((shell-file-name pr-shell-file-name))
3763 (start-process-shell-command "PREVIEW" "*Messages*"
3764 (pr-command pr-gv-command) filename))))
3767 ;;;###autoload
3768 (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
3769 "Preview PostScript file FILENAME."
3770 (interactive (pr-interactive-n-up-inout "PS preview"))
3771 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
3772 "PS preview ")))
3773 (pr-ps-utility-process n-up ifilename outfile)
3774 (pr-ps-file-preview outfile)))
3777 ;;;###autoload
3778 (defun pr-ps-file-using-ghostscript (filename)
3779 "Print PostScript file FILENAME using ghostscript."
3780 (interactive (list (pr-ps-infile-preprint "Print preview ")))
3781 (and (stringp filename) (file-exists-p filename)
3782 (let* ((file (pr-expand-file-name filename))
3783 (tempfile (pr-dosify-path (make-temp-name file))))
3784 ;; gs use
3785 (pr-shell-command
3786 (concat (pr-command pr-gs-command)
3787 " -sDEVICE=" pr-gs-device
3788 " -r" (int-to-string pr-gs-resolution)
3789 " " (pr-switches-string pr-gs-switches "pr-gs-switches")
3790 " -sOutputFile=" tempfile " " file " -c quit"))
3791 ;; printing
3792 (pr-ps-file-print tempfile)
3793 ;; deleting
3794 (pr-delete-file tempfile))))
3797 ;;;###autoload
3798 (defun pr-ps-file-print (filename)
3799 "Print PostScript file FILENAME."
3800 (interactive (list (pr-ps-infile-preprint "Print ")))
3801 (and (stringp filename) (file-exists-p filename)
3802 ;; printing
3803 (let ((file (pr-expand-file-name filename)))
3804 (if (string-equal pr-ps-command "")
3805 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
3806 (save-excursion
3807 (set-buffer ps-spool-buffer)
3808 (erase-buffer)
3809 (insert-file-contents-literally file))
3810 (pr-despool-print))
3811 (pr-shell-command
3812 (concat (pr-command pr-ps-command) " "
3813 (pr-switches-string pr-ps-switches "pr-gs-switches") " "
3814 (if (string-match "cp" pr-ps-command)
3815 ;; for "cp" (cmd in out)
3816 (concat "\"" file "\" "
3817 pr-ps-printer-switch pr-ps-printer)
3818 ;; else, for others (cmd out in)
3819 (concat pr-ps-printer-switch pr-ps-printer
3820 " \"" file "\""))))))))
3823 ;;;###autoload
3824 (defun pr-ps-file-ps-print (filename)
3825 "Send PostScript file FILENAME to printer or use ghostscript to print it."
3826 (interactive (list (pr-ps-infile-preprint
3827 (if pr-print-using-ghostscript
3828 "Print preview "
3829 "Print "))))
3830 (if pr-print-using-ghostscript
3831 (pr-ps-file-using-ghostscript filename)
3832 (pr-ps-file-print filename)))
3835 ;;;###autoload
3836 (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
3837 "Process a PostScript file IFILENAME and send it to printer.
3839 Interactively, the command prompts for N-UP printing number, for an input
3840 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
3841 command prompts the user for an output PostScript file name OFILENAME, and
3842 saves the PostScript image in that file instead of sending it to the printer.
3844 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3845 argument IFILENAME is treated as follows: if it's t, prompts for an input
3846 PostScript file name; otherwise, it *must* be a string that it's an input
3847 PostScript file name. The argument OFILENAME is treated as follows: if it's
3848 nil, send the image to the printer. If OFILENAME is a string, save the
3849 PostScript image in a file with that name. If OFILENAME is t, prompts for a
3850 file name."
3851 (interactive (pr-interactive-n-up-inout
3852 (if pr-print-using-ghostscript
3853 "PS print GS"
3854 "PS print")))
3855 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
3856 (if pr-print-using-ghostscript
3857 "PS print GS "
3858 "PS print "))))
3859 (pr-ps-utility-process n-up ifilename outfile)
3860 (unless ofilename
3861 (pr-ps-file-ps-print outfile)
3862 (pr-delete-file outfile))))
3865 ;;;###autoload
3866 (defun pr-toggle-file-duplex ()
3867 "Toggle duplex for PostScript file."
3868 (interactive)
3869 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
3870 '("PostScript Print" "File")))
3873 ;;;###autoload
3874 (defun pr-toggle-file-tumble ()
3875 "Toggle tumble for PostScript file.
3877 If tumble is off, produces a printing suitable for binding on the left or
3878 right.
3879 If tumble is on, produces a printing suitable for binding at the top or
3880 bottom."
3881 (interactive)
3882 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
3883 '("PostScript Print" "File")))
3886 ;;;###autoload
3887 (defun pr-toggle-file-landscape ()
3888 "Toggle landscape for PostScript file."
3889 (interactive)
3890 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
3891 '("PostScript Print" "File")))
3894 ;;;###autoload
3895 (defun pr-toggle-ghostscript ()
3896 "Toggle printing using ghostscript."
3897 (interactive)
3898 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
3899 'postscript-process 2 12 'toggle))
3902 ;;;###autoload
3903 (defun pr-toggle-faces ()
3904 "Toggle printing with faces."
3905 (interactive)
3906 (pr-toggle 'pr-faces-p "Printing with-faces"
3907 'postscript-process 1 12 'toggle))
3910 ;;;###autoload
3911 (defun pr-toggle-spool ()
3912 "Toggle spooling."
3913 (interactive)
3914 (pr-toggle 'pr-spool-p "Spooling printing"
3915 'postscript-process 0 12 'toggle))
3918 ;;;###autoload
3919 (defun pr-toggle-duplex ()
3920 "Toggle duplex."
3921 (interactive)
3922 (pr-toggle 'ps-spool-duplex "Printing duplex"
3923 'postcsript-options 5 12 'toggle))
3926 ;;;###autoload
3927 (defun pr-toggle-tumble ()
3928 "Toggle tumble.
3930 If tumble is off, produces a printing suitable for binding on the left or
3931 right.
3932 If tumble is on, produces a printing suitable for binding at the top or
3933 bottom."
3934 (interactive)
3935 (pr-toggle 'ps-spool-tumble "Tumble"
3936 'postscript-options 6 12 'toggle))
3939 ;;;###autoload
3940 (defun pr-toggle-landscape ()
3941 "Toggle landscape."
3942 (interactive)
3943 (pr-toggle 'ps-landscape-mode "Landscape"
3944 'postscript-options 0 12 'toggle))
3947 ;;;###autoload
3948 (defun pr-toggle-upside-down ()
3949 "Toggle upside-down."
3950 (interactive)
3951 (pr-toggle 'ps-print-upside-down "Upside-Down"
3952 'postscript-options 7 12 'toggle))
3955 ;;;###autoload
3956 (defun pr-toggle-line ()
3957 "Toggle line number."
3958 (interactive)
3959 (pr-toggle 'ps-line-number "Line number"
3960 'postscript-options 3 12 'toggle))
3963 ;;;###autoload
3964 (defun pr-toggle-zebra ()
3965 "Toggle zebra stripes."
3966 (interactive)
3967 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
3968 'postscript-options 4 12 'toggle))
3971 ;;;###autoload
3972 (defun pr-toggle-header ()
3973 "Toggle printing header."
3974 (interactive)
3975 (pr-toggle 'ps-print-header "Print header"
3976 'postscript-options 1 12 'toggle))
3979 ;;;###autoload
3980 (defun pr-toggle-header-frame ()
3981 "Toggle printing header frame."
3982 (interactive)
3983 (pr-toggle 'ps-print-header-frame "Print header frame"
3984 'postscript-options 2 12 'toggle))
3987 ;;;###autoload
3988 (defun pr-toggle-lock ()
3989 "Toggle menu lock."
3990 (interactive)
3991 (pr-toggle 'pr-menu-lock "Menu lock"
3992 'printing 2 12 'toggle))
3995 ;;;###autoload
3996 (defun pr-toggle-region ()
3997 "Toggle auto region."
3998 (interactive)
3999 (pr-toggle 'pr-auto-region "Auto region"
4000 'printing 0 12 'toggle))
4003 ;;;###autoload
4004 (defun pr-toggle-mode ()
4005 "Toggle auto mode."
4006 (interactive)
4007 (pr-toggle 'pr-auto-mode "Auto mode"
4008 'printing 1 12 'toggle))
4011 ;;;###autoload
4012 (defun pr-customize (&rest ignore)
4013 "Customization of `printing' group."
4014 (interactive)
4015 (customize-group 'printing))
4018 ;;;###autoload
4019 (defun lpr-customize (&rest ignore)
4020 "Customization of `lpr' group."
4021 (interactive)
4022 (customize-group 'lpr))
4025 ;;;###autoload
4026 (defun pr-help (&rest ignore)
4027 "Help for printing package."
4028 (interactive)
4029 (pr-show-setup pr-help-message "*Printing Help*"))
4032 ;;;###autoload
4033 (defun pr-ps-name ()
4034 "Select interactively a PostScript printer."
4035 (interactive)
4036 (pr-menu-set-ps-title
4037 (pr-complete-alist "PostScript printer" pr-ps-printer-alist pr-ps-name)))
4040 ;;;###autoload
4041 (defun pr-txt-name ()
4042 "Select interactively a text printer."
4043 (interactive)
4044 (pr-menu-set-txt-title
4045 (pr-complete-alist "Text printer" pr-txt-printer-alist pr-txt-name)))
4048 ;;;###autoload
4049 (defun pr-ps-utility ()
4050 "Select interactively a PostScript utility."
4051 (interactive)
4052 (pr-menu-set-utility-title
4053 (pr-complete-alist "Postscript utility" pr-ps-utility-alist pr-ps-utility)))
4056 ;;;###autoload
4057 (defun pr-show-ps-setup (&rest ignore)
4058 "Show current ps-print settings."
4059 (interactive)
4060 (pr-show-setup (ps-setup) "*PS Setup*"))
4063 ;;;###autoload
4064 (defun pr-show-pr-setup (&rest ignore)
4065 "Show current printing settings."
4066 (interactive)
4067 (pr-show-setup (pr-setup) "*PR Setup*"))
4070 ;;;###autoload
4071 (defun pr-show-lpr-setup (&rest ignore)
4072 "Show current lpr settings."
4073 (interactive)
4074 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4078 ;; Fast Commands
4081 ;;;###autoload
4082 (defun pr-ps-fast-fire (n-up &optional select)
4083 "Fast fire function for PostScript printing.
4085 If a region is active, the region will be printed instead of the whole buffer.
4086 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4087 `pr-mode-alist' will be used, that is, the current buffer or region will be
4088 printed using `pr-ps-mode-ps-print'.
4091 Interactively, you have the following situations:
4093 M-x pr-ps-fast-fire RET
4094 The command prompts the user for a N-UP value and printing will
4095 immediatelly be done using the current active printer.
4097 C-u M-x pr-ps-fast-fire RET
4098 C-u 0 M-x pr-ps-fast-fire RET
4099 The command prompts the user for a N-UP value and also for a current
4100 PostScript printer, then printing will immediatelly be done using the new
4101 current active printer.
4103 C-u 1 M-x pr-ps-fast-fire RET
4104 The command prompts the user for a N-UP value and also for a file name,
4105 and saves the PostScript image in that file instead of sending it to the
4106 printer.
4108 C-u 2 M-x pr-ps-fast-fire RET
4109 The command prompts the user for a N-UP value, then for a current
4110 PostScript printer and, finally, for a file name. Then change the active
4111 printer to that choosen by user and saves the PostScript image in
4112 that file instead of sending it to the printer.
4115 Noninteractively, the argument N-UP should be a positive integer greater than
4116 zero and the argument SELECT is treated as follows:
4118 If it's nil, send the image to the printer.
4120 If it's a list or an integer lesser or equal to zero, the command prompts
4121 the user for a current PostScript printer, then printing will immediatelly
4122 be done using the new current active printer.
4124 If it's an integer equal to 1, the command prompts the user for a file name
4125 and saves the PostScript image in that file instead of sending it to the
4126 printer.
4128 If it's an integer greater or equal to 2, the command prompts the user for a
4129 current PostScript printer and for a file name. Then change the active
4130 printer to that choosen by user and saves the PostScript image in that file
4131 instead of sending it to the printer.
4133 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4134 active printer and printing will immediatelly be done using the new active
4135 printer.
4137 Otherwise, send the image to the printer.
4140 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4141 are both set to t."
4142 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4143 current-prefix-arg))
4144 (let ((pr-auto-region t)
4145 (pr-auto-mode t)
4146 filename)
4147 (cond ((null select))
4148 ((listp select)
4149 (pr-ps-name))
4150 ((and (symbolp select)
4151 (assq select pr-ps-printer-alist))
4152 (pr-menu-set-ps-title select))
4153 ((integerp select)
4154 (and (/= select 1)
4155 (pr-ps-name))
4156 (and (>= select 1) (not pr-spool-p)
4157 (setq filename (pr-ps-outfile-preprint
4158 (if pr-print-using-ghostscript
4159 "Fast GS "
4160 "Fast "))))))
4161 (pr-ps-buffer-ps-print
4162 (if (integerp n-up)
4163 (min (max n-up 1) 100)
4164 (error "n-up must be an integer greater than zero."))
4165 filename)))
4168 ;;;###autoload
4169 (defun pr-txt-fast-fire (&optional select-printer)
4170 "Fast fire function for text printing.
4172 If a region is active, the region will be printed instead of the whole buffer.
4173 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4174 `pr-mode-alist' will be used, that is, the current buffer or region will be
4175 printed using `pr-txt-mode'.
4177 Interactively, when you use a prefix argument (C-u), the command prompts the
4178 user for a new active text printer.
4180 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4182 If it's nil, the printing is sent to the current active text printer.
4184 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4185 active printer and printing will immediatelly be done using the new active
4186 printer.
4188 If it's non-nil, the command prompts the user for a new active text printer.
4190 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4191 are both set to t."
4192 (interactive (list current-prefix-arg))
4193 (cond ((null select-printer))
4194 ((and (symbolp select-printer)
4195 (assq select-printer pr-txt-printer-alist))
4196 (pr-menu-set-txt-title select-printer))
4198 (pr-txt-name)))
4199 (let ((pr-auto-region t)
4200 (pr-auto-mode t))
4201 (pr-txt-buffer)))
4204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4205 ;; Utilities
4208 (defun pr-setup ()
4209 "Return the current `printing' setup.
4211 This is *not* an interactive command.
4212 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4214 M-: (insert (pr-setup)) RET
4216 Or choose the menu option Printing/Show Settings/printing."
4217 (let (ps-prefix-quote)
4218 (mapconcat
4219 #'ps-print-quote
4220 (list
4221 (concat "\n;;; printing.el version " pr-version "\n")
4222 '(19 . pr-shell-file-name)
4223 '(19 . pr-path-style)
4224 '(19 . pr-path-alist)
4226 '(21 . pr-txt-name)
4227 '(21 . pr-txt-printer-alist)
4229 '(20 . pr-ps-name)
4230 '(20 . pr-ps-printer-alist)
4232 '(20 . pr-temp-dir)
4233 '(20 . pr-ps-temp-file)
4234 '(20 . pr-delete-temp-file)
4235 '(20 . pr-list-directory)
4237 '(17 . pr-gv-command)
4238 '(17 . pr-gs-command)
4239 '(17 . pr-gs-switches)
4240 '(17 . pr-gs-device)
4241 '(17 . pr-gs-resolution)
4243 '(27 . pr-print-using-ghostscript)
4244 '(27 . pr-faces-p)
4245 '(27 . pr-spool-p)
4246 '(27 . pr-file-landscape)
4247 '(27 . pr-file-duplex)
4248 '(27 . pr-file-tumble)
4249 '(27 . pr-auto-region)
4250 '(27 . pr-auto-mode)
4252 '(20 . pr-ps-utility)
4253 '(20 . pr-ps-utility-alist)
4255 '(14 . pr-mode-alist)
4257 '(20 . pr-menu-lock)
4258 '(20 . pr-menu-char-height)
4259 '(20 . pr-menu-char-width)
4261 '(20 . pr-setting-database)
4263 '(22 . pr-visible-entry-list)
4265 '(22 . pr-buffer-verbose)
4266 '(22 . pr-buffer-name)
4267 '(22 . pr-buffer-name-ignore)
4268 ")\n\n;;; printing.el - end of settings\n")
4269 "\n")))
4272 (defun lpr-setup ()
4273 "Return the current `lpr' setup.
4275 This is *not* an interactive command.
4276 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4278 M-: (insert (lpr-setup)) RET
4280 Or choose the menu option Printing/Show Settings/lpr."
4281 (let (ps-prefix-quote)
4282 (mapconcat
4283 #'ps-print-quote
4284 '("\n;;; lpr.el settings\n"
4285 (25 . printer-name)
4286 (25 . lpr-switches)
4287 (25 . lpr-add-switches)
4288 (25 . lpr-command)
4289 (25 . lpr-headers-switches)
4290 (25 . print-region-function)
4291 (25 . lpr-page-header-program)
4292 (25 . lpr-page-header-switches)
4293 ")\n\n;;; lpr.el - end of settings\n")
4294 "\n")))
4297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4298 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4301 (defalias 'pr-mh-get-msg-num 'mh-get-msg-num)
4302 (defalias 'pr-mh-show 'mh-show)
4303 (defalias 'pr-mh-start-of-uncleaned-message 'mh-start-of-uncleaned-message)
4304 (defvar mh-show-buffer nil)
4307 (defun pr-article-date ()
4308 "Find the date of an article or mail message in current buffer.
4309 Return only the dayname, if present, weekday, month, and year."
4310 (save-excursion
4311 (goto-char (point-min))
4312 (if (re-search-forward
4313 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4314 (buffer-substring (match-beginning 1) (match-end 1))
4315 (format-time-string "%Y/%m/%d"))))
4318 (defun pr-mh-current-message ()
4319 "Go to mh-inbox current message."
4320 (let ((msg (or (pr-mh-get-msg-num nil) 0)))
4321 (pr-mh-show)
4322 (set-buffer mh-show-buffer)
4323 (goto-char (point-min))
4324 (pr-mh-start-of-uncleaned-message)
4325 (message "Printing message %d" msg)))
4328 (defun pr-mh-print-1 (n-up filename header-list)
4329 "Print mh-inbox current message in PostScript."
4330 (save-excursion
4331 (save-window-excursion
4332 (pr-mh-current-message)
4333 (pr-mode-print n-up filename header-list (point)))))
4336 (defun pr-mh-lpr-1 (header-list)
4337 "Print mh-inbox current message in text printer."
4338 (save-excursion
4339 (save-window-excursion
4340 (pr-mh-current-message)
4341 (pr-mode-lpr header-list (point)))))
4344 (defalias 'pr-mh-print-2 'pr-mode-print)
4347 (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
4350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4351 ;; rmail (hacked from ps-print.el)
4354 (defun pr-rmail-lpr (header-list)
4355 "Print RMAIL current message in text printer."
4356 (pr-lpr-message-from-summary header-list
4357 'rmail-buffer 'rmail-summary-buffer))
4360 (defun pr-rmail-print (n-up filename header-list)
4361 "Print RMAIL current message in PostScript."
4362 (pr-ps-message-from-summary n-up filename header-list
4363 'rmail-buffer 'rmail-summary-buffer))
4366 (defun pr-ps-message-from-summary (n-up filename header-list
4367 summary-buffer summary-default)
4368 "Print current message in PostScript."
4369 (let ((buf (or (and (boundp summary-buffer)
4370 (symbol-value summary-buffer))
4371 (symbol-value summary-default))))
4372 (and (get-buffer buf)
4373 (save-excursion
4374 (set-buffer buf)
4375 (pr-mode-print n-up filename header-list)))))
4378 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
4379 "Print current message in text printer."
4380 (let ((buf (or (and (boundp summary-buffer)
4381 (symbol-value summary-buffer))
4382 (symbol-value summary-default))))
4383 (and (get-buffer buf)
4384 (save-excursion
4385 (set-buffer buf)
4386 (pr-mode-lpr header-list)))))
4389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4390 ;; gnus (hacked from ps-print.el)
4393 (defvar pr-gnus-article "*Article*")
4396 (defun pr-gnus-print (n-up filename header-list)
4397 "Print *Article* current message in PostScript."
4398 (pr-ps-message-from-summary n-up filename header-list
4399 'gnus-article-buffer 'pr-gnus-article))
4402 (defun pr-gnus-lpr (header-list)
4403 "Print *Article* current message in text printer."
4404 (pr-lpr-message-from-summary header-list
4405 'gnus-article-buffer 'pr-gnus-article))
4408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4409 ;; vm (hacked from ps-print.el)
4412 (defvar pr-vm-summary "")
4415 (defun pr-vm-print (n-up filename header-list)
4416 "Print current vm message in PostScript."
4417 (pr-ps-message-from-summary n-up filename header-list
4418 'vm-mail-buffer 'pr-vm-summary))
4421 (defun pr-vm-lpr (header-list)
4422 "Print current vm message in text printer."
4423 (pr-lpr-message-from-summary header-list
4424 'vm-mail-buffer 'pr-vm-summary))
4427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4428 ;; Mode Functions
4431 (defun pr-ps-mode (n-up filename)
4432 "If current major mode is declared, print it in PostScript."
4433 (let ((args (pr-mode-alist-p)))
4434 (if args
4435 (let ((fun (cdr args)))
4436 (funcall (car fun) n-up filename (cdr fun))
4438 (ding)
4439 (message "`%s' major mode not declared." major-mode)
4440 nil)))
4443 (defmacro pr-local-variable (header-list &rest body)
4444 `(save-excursion
4445 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
4446 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
4447 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
4448 ps-razzle-dazzle)
4449 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
4450 ,@body
4451 (and (nth 3 ,header-list)
4452 (pr-kill-local-variable local-var-list))))))
4455 (defun pr-mode-print (n-up filename header-list &optional from to)
4456 "Print current major mode in PostScript."
4457 (pr-local-variable
4458 header-list
4459 (let ((file (pr-ps-file filename))
4460 (start (cond (from)
4461 ((pr-region-active-p) (region-beginning))
4462 (t nil)
4464 (pr-text2ps (pr-region-active-symbol start) n-up file start
4465 (cond (to)
4466 ((pr-region-active-p) (region-end))
4467 (from (point-max))
4469 (unless (or pr-spool-p filename)
4470 (pr-ps-file-print file)
4471 (pr-delete-file file)))))
4474 (defun pr-mode-lpr (header-list &optional from to)
4475 "Print current major mode in text printer."
4476 (pr-local-variable
4477 header-list
4478 (pr-txt-print (cond (from)
4479 ((pr-region-active-p) (region-beginning))
4480 (t (point-min)))
4481 (cond (to)
4482 ((pr-region-active-p) (region-end))
4483 (t (point-max))))))
4486 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4487 ;; Menu Lock
4490 (defconst pr-menu-entry-alist
4491 '((postscript . 3)
4492 (text . 3)
4493 (postscript-options . 9)
4494 (postscript-process . 3)
4495 (printing . 3)
4496 (help . 3)
4498 "Alist that associates menu part with number of items per part.
4500 It's used by `pr-menu-index'.
4502 Each element has the form:
4504 (MENU-PART . NUMBER-OF-ITEMS)
4506 See `pr-visible-entry-alist'.")
4509 (defun pr-menu-index (entry index)
4510 (let ((base-list
4511 (cond ((eq entry 'text)
4512 '(postscript))
4513 ((eq entry 'postscript-options)
4514 '(postscript text))
4515 ((eq entry 'postscript-process)
4516 '(postscript text postscript-options))
4517 ((eq entry 'printing)
4518 '(postscript text postscript-options postscript-process))
4520 nil)
4522 key)
4523 (while base-list
4524 (setq key (car base-list)
4525 base-list (cdr base-list))
4526 (and (pr-visible-p key)
4527 (setq index (+ index
4528 (cdr (assq key pr-menu-entry-alist)))))))
4529 (+ index 2))
4532 (eval-and-compile
4533 (cond
4534 ((eq ps-print-emacs-type 'xemacs)
4535 ;; XEmacs
4536 (defun pr-menu-position (entry index horizontal)
4537 (pr-x-make-event
4538 'button-release
4539 (list 'button 1
4540 'x (- (pr-x-event-x-pixel current-mouse-event) ; X
4541 (* horizontal pr-menu-char-width))
4542 'y (- (pr-x-event-y-pixel current-mouse-event) ; Y
4543 (* (pr-menu-index entry index) pr-menu-char-height)))))
4545 (ps-windows-system
4546 ;; GNU Emacs for Windows 9x/NT
4547 (defun pr-menu-position (entry index horizontal)
4548 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4549 (list
4550 (list (car pos) ; X
4551 (- (cdr pos) ; Y
4552 (* (pr-menu-index entry index) pr-menu-char-height)))
4553 (selected-frame)))) ; frame
4556 ;; GNU Emacs
4557 (defun pr-menu-position (entry index horizontal)
4558 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4559 (list
4560 (list (- (car pos) ; X
4561 (* horizontal pr-menu-char-width))
4562 (- (cdr pos) ; Y
4563 (* (pr-menu-index entry index) pr-menu-char-height)))
4564 (selected-frame)))) ; frame
4568 (defvar pr-menu-position nil)
4569 (defvar pr-menu-state nil)
4572 (cond
4573 ((eq ps-print-emacs-type 'emacs)
4574 ;; GNU Emacs
4575 (defun pr-menu-lock (entry index horizontal state path)
4576 (when (and (not (interactive-p)) pr-menu-lock)
4577 (or (and pr-menu-position (eq state pr-menu-state))
4578 (setq pr-menu-position (pr-menu-position entry index horizontal)
4579 pr-menu-state state))
4580 (let* ((menu (pr-menu-lookup path))
4581 (result (x-popup-menu pr-menu-position menu)))
4582 (and result
4583 (let ((command (lookup-key menu (vconcat result))))
4584 (if (fboundp command)
4585 (funcall command)
4586 (eval command)))))
4587 (setq pr-menu-position nil)))
4589 ;; GNU Emacs
4590 (defun pr-menu-lookup (path)
4591 (let ((ipath pr-menu-bar))
4592 (lookup-key global-map
4593 (if path
4594 (vconcat ipath
4595 (mapcar 'pr-get-symbol
4596 (if (listp path)
4597 path
4598 (list path))))
4599 ipath)))))
4602 ((eq ps-print-emacs-type 'xemacs)
4603 ;; XEmacs
4604 (defun pr-menu-lock (entry index horizontal state path)
4605 (when (and (not (interactive-p)) pr-menu-lock)
4606 (or (and pr-menu-position (eq state pr-menu-state))
4607 (setq pr-menu-position (pr-menu-position entry index horizontal)
4608 pr-menu-state state))
4609 (let* ((menu (pr-menu-lookup path))
4610 (result (pr-x-get-popup-menu-response menu pr-menu-position)))
4611 (and (pr-x-misc-user-event-p result)
4612 (funcall (pr-x-event-function result)
4613 (pr-x-event-object result))))
4614 (setq pr-menu-position nil)))
4616 ;; XEmacs
4617 (defun pr-menu-lookup (path)
4618 (car (pr-x-find-menu-item current-menubar (cons "Printing" path))))))
4621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4622 ;; Printer & Utility Selection
4625 (defun pr-update-var (var-sym alist)
4626 (or (assq (symbol-value var-sym) alist)
4627 (set var-sym (car (car alist)))))
4630 (defun pr-update-menus (&optional force)
4631 "Update utility, PostScript and text printer menus.
4633 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
4634 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
4635 otherwise, update PostScript printer menu iff `pr-ps-printer-menu-modified' is
4636 non-nil, update text printer menu iff `pr-txt-printer-menu-modified' is
4637 non-nil, and update PostScript File menus iff `pr-ps-utility-menu-modified' is
4638 non-nil."
4639 (interactive)
4640 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
4641 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
4642 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
4643 (pr-do-update-menus force))
4646 (defvar pr-ps-printer-menu-modified t
4647 "Non-nil means `pr-ps-printer-alist' was modified and need to update menu.")
4648 (defvar pr-txt-printer-menu-modified t
4649 "Non-nil means `pr-txt-printer-alist' was modified and need to update menu.")
4650 (defvar pr-ps-utility-menu-modified t
4651 "Non-nil means `pr-ps-utility-alist' was modified and need to update menu.")
4654 (defconst pr-even-or-odd-alist
4655 '((nil . "Print All Pages")
4656 (even-page . "Print Even Pages")
4657 (odd-page . "Print Odd Pages")
4658 (even-sheet . "Print Even Sheets")
4659 (odd-sheet . "Print Odd Sheets")))
4662 (defun pr-menu-create (name alist var-sym fun entry index)
4663 (cons name
4664 (mapcar
4665 #'(lambda (elt)
4666 (let ((sym (car elt)))
4667 (vector
4668 (symbol-name sym)
4669 (list fun (list 'quote sym) nil (list 'quote entry) index)
4670 :style 'radio
4671 :selected (list 'eq var-sym (list 'quote sym)))))
4672 alist)))
4675 (eval-and-compile
4676 (cond
4677 ((eq ps-print-emacs-type 'emacs)
4678 ;; GNU Emacs
4679 (defalias 'pr-update-mode-line 'force-mode-line-update)
4681 ;; GNU Emacs
4682 (defun pr-do-update-menus (&optional force)
4683 (pr-menu-alist pr-ps-printer-alist
4684 'pr-ps-name
4685 'pr-menu-set-ps-title
4686 "PostScript Printers"
4687 'pr-ps-printer-menu-modified
4688 force
4689 "PostScript Printers"
4690 'postscript 2)
4691 (pr-menu-alist pr-txt-printer-alist
4692 'pr-txt-name
4693 'pr-menu-set-txt-title
4694 "Text Printers"
4695 'pr-txt-printer-menu-modified
4696 force
4697 "Text Printers"
4698 'text 2)
4699 (let ((save-var pr-ps-utility-menu-modified))
4700 (pr-menu-alist pr-ps-utility-alist
4701 'pr-ps-utility
4702 'pr-menu-set-utility-title
4703 '("PostScript Print" "File" "PostScript Utility")
4704 'save-var
4705 force
4706 "PostScript Utility"
4707 nil 1))
4708 (pr-menu-alist pr-ps-utility-alist
4709 'pr-ps-utility
4710 'pr-menu-set-utility-title
4711 '("PostScript Preview" "File" "PostScript Utility")
4712 'pr-ps-utility-menu-modified
4713 force
4714 "PostScript Utility"
4715 nil 1)
4716 (pr-even-or-odd-pages ps-even-or-odd-pages force))
4718 ;; GNU Emacs
4719 (defvar pr-temp-menu nil)
4721 ;; GNU Emacs
4722 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
4723 entry index)
4724 (when (and alist (or force (symbol-value modified-sym)))
4725 (easy-menu-define pr-temp-menu nil ""
4726 (pr-menu-create name alist var-sym fun entry index))
4727 (let ((item (pr-menu-get-item menu-path)))
4728 (and item
4729 (let* ((binding (nthcdr 3 item))
4730 (key-binding (cdr binding)))
4731 (setcar binding pr-temp-menu)
4732 (and key-binding (listp (car key-binding))
4733 (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
4734 (funcall fun (symbol-value var-sym) item))))
4735 (set modified-sym nil)))
4737 ;; GNU Emacs
4738 (defun pr-menu-set-ps-title (value &optional item entry index)
4739 (pr-menu-set-item-name (or item
4740 (pr-menu-get-item "PostScript Printers"))
4741 (format "PostScript Printer: %s" value))
4742 (pr-ps-set-printer value)
4743 (and index
4744 (pr-menu-lock entry index 12 'toggle nil)))
4746 ;; GNU Emacs
4747 (defun pr-menu-set-txt-title (value &optional item entry index)
4748 (pr-menu-set-item-name (or item
4749 (pr-menu-get-item "Text Printers"))
4750 (format "Text Printer: %s" value))
4751 (pr-txt-set-printer value)
4752 (and index
4753 (pr-menu-lock entry index 12 'toggle nil)))
4755 ;; GNU Emacs
4756 (defun pr-menu-set-utility-title (value &optional item entry index)
4757 (let ((name (symbol-name value)))
4758 (if item
4759 (pr-menu-set-item-name item name)
4760 (pr-menu-set-item-name
4761 (pr-menu-get-item
4762 '("PostScript Print" "File" "PostScript Utility"))
4763 name)
4764 (pr-menu-set-item-name
4765 (pr-menu-get-item
4766 '("PostScript Preview" "File" "PostScript Utility"))
4767 name)))
4768 (pr-ps-set-utility value)
4769 (and index
4770 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
4772 ;; GNU Emacs
4773 (defun pr-even-or-odd-pages (value &optional no-lock)
4774 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
4775 (cdr (assq value pr-even-or-odd-alist)))
4776 (setq ps-even-or-odd-pages value)
4777 (or no-lock
4778 (pr-menu-lock 'postscript-options 8 12 'toggle nil))))
4781 ((eq ps-print-emacs-type 'xemacs)
4782 ;; XEmacs
4783 (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
4785 ;; XEmacs
4786 (defvar pr-ps-name-old "PostScript Printers")
4787 (defvar pr-txt-name-old "Text Printers")
4788 (defvar pr-ps-utility-old "PostScript Utility")
4789 (defvar pr-even-or-odd-old "Print All Pages")
4791 ;; XEmacs
4792 (defun pr-do-update-menus (&optional force)
4793 (pr-menu-alist pr-ps-printer-alist
4794 'pr-ps-name
4795 'pr-menu-set-ps-title
4796 '("Printing")
4797 'pr-ps-printer-menu-modified
4798 force
4799 pr-ps-name-old
4800 'postscript 2)
4801 (pr-menu-alist pr-txt-printer-alist
4802 'pr-txt-name
4803 'pr-menu-set-txt-title
4804 '("Printing")
4805 'pr-txt-printer-menu-modified
4806 force
4807 pr-txt-name-old
4808 'text 2)
4809 (let ((save-var pr-ps-utility-menu-modified))
4810 (pr-menu-alist pr-ps-utility-alist
4811 'pr-ps-utility
4812 'pr-menu-set-utility-title
4813 '("Printing" "PostScript Print" "File")
4814 'save-var
4815 force
4816 pr-ps-utility-old
4817 nil 1))
4818 (pr-menu-alist pr-ps-utility-alist
4819 'pr-ps-utility
4820 'pr-menu-set-utility-title
4821 '("Printing" "PostScript Preview" "File")
4822 'pr-ps-utility-menu-modified
4823 force
4824 pr-ps-utility-old
4825 nil 1)
4826 (pr-even-or-odd-pages ps-even-or-odd-pages force))
4828 ;; XEmacs
4829 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
4830 entry index)
4831 (when (and alist (or force (symbol-value modified-sym)))
4832 (pr-xemacs-global-menubar
4833 (pr-x-add-submenu menu-path
4834 (pr-menu-create name alist var-sym
4835 fun entry index)))
4836 (funcall fun (symbol-value var-sym))
4837 (set modified-sym nil)))
4839 ;; XEmacs
4840 (defun pr-menu-set-ps-title (value &optional item entry index)
4841 (pr-relabel-menu-item (format "PostScript Printer: %s" value)
4842 'pr-ps-name-old)
4843 (pr-ps-set-printer value)
4844 (and index
4845 (pr-menu-lock entry index 12 'toggle nil)))
4847 ;; XEmacs
4848 (defun pr-menu-set-txt-title (value &optional item entry index)
4849 (pr-relabel-menu-item (format "Text Printer: %s" value)
4850 'pr-txt-name-old)
4851 (pr-txt-set-printer value)
4852 (and index
4853 (pr-menu-lock entry index 12 'toggle nil)))
4855 ;; XEmacs
4856 (defun pr-menu-set-utility-title (value &optional item entry index)
4857 (pr-xemacs-global-menubar
4858 (let ((newname (format "%s" value)))
4859 (pr-x-relabel-menu-item
4860 (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
4861 newname)
4862 (pr-x-relabel-menu-item
4863 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
4864 newname)
4865 (setq pr-ps-utility-old newname)))
4866 (pr-ps-set-utility value)
4867 (and index
4868 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
4870 ;; XEmacs
4871 (defun pr-even-or-odd-pages (value &optional no-lock)
4872 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
4873 'pr-even-or-odd-old)
4874 (setq ps-even-or-odd-pages value)
4875 (or no-lock
4876 (pr-menu-lock 'postscript-options 8 12 'toggle nil))))))
4878 ;; XEmacs
4879 (defun pr-relabel-menu-item (newname var-sym)
4880 (pr-xemacs-global-menubar
4881 (pr-x-relabel-menu-item
4882 (list "Printing" (symbol-value var-sym))
4883 newname)
4884 (set var-sym newname)))
4887 (defun pr-menu-set-item-name (item name)
4888 (and item
4889 (setcar (nthcdr 2 item) name))) ; ITEM-NAME
4892 (defun pr-menu-get-item (name-list)
4893 ;; NAME-LIST is a string or a list of strings.
4894 (let ((ipath pr-menu-bar)
4895 (len (and (listp name-list) (length name-list))))
4896 (and len (= len 1)
4897 (setq name-list (car name-list)))
4898 (cond
4899 ((null name-list)
4900 ;; nil
4901 nil)
4902 ((listp name-list)
4903 ;; list and (length list) > 1
4904 (let* ((copy (copy-sequence name-list))
4905 (name (pr-get-symbol (nth (1- len) copy)))
4906 (path (progn
4907 (setcdr (nthcdr (- len 2) copy) nil)
4908 copy))
4909 (menu (lookup-key
4910 global-map
4911 (if path
4912 (vconcat ipath
4913 (mapcar 'pr-get-symbol path))
4914 ipath))))
4915 (assq name (nthcdr 2 menu))))
4917 ;; string
4918 (let ((name (pr-get-symbol name-list))
4919 (menu (lookup-key global-map ipath)))
4920 (assq name (nthcdr 2 menu)))))))
4923 (defun pr-ps-set-utility (value)
4924 (let ((item (cdr (assq value pr-ps-utility-alist))))
4925 (or item
4926 (error
4927 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'."
4928 value))
4929 (setq pr-ps-utility value)
4930 (pr-eval-alist (nthcdr 9 item)))
4931 (pr-update-mode-line))
4934 (defun pr-ps-set-printer (value)
4935 (let ((ps (cdr (assq value pr-ps-printer-alist))))
4936 (or ps
4937 (error
4938 "Invalid PostScript printer name `%s' for variable `pr-ps-name'."
4939 value))
4940 (setq pr-ps-name value
4941 pr-ps-command (pr-dosify-path (nth 0 ps))
4942 pr-ps-switches (nth 1 ps)
4943 pr-ps-printer-switch (nth 2 ps)
4944 pr-ps-printer (pr-dosify-path (nth 3 ps)))
4945 (or (stringp pr-ps-command)
4946 (setq pr-ps-command
4947 (cond (ps-windows-system "print")
4948 (ps-lp-system "lp")
4949 (t "lpr")
4951 (or (stringp pr-ps-printer-switch)
4952 (setq pr-ps-printer-switch
4953 (cond (ps-windows-system "/D:")
4954 (ps-lp-system "-d")
4955 (t "-P")
4957 (pr-eval-alist (nthcdr 4 ps)))
4958 (pr-update-mode-line))
4961 (defun pr-txt-set-printer (value)
4962 (let ((txt (cdr (assq value pr-txt-printer-alist))))
4963 (or txt
4964 (error "Invalid text printer name `%s' for variable `pr-txt-name'."
4965 value))
4966 (setq pr-txt-name value
4967 pr-txt-command (pr-dosify-path (nth 0 txt))
4968 pr-txt-switches (nth 1 txt)
4969 pr-txt-printer (pr-dosify-path (nth 2 txt))))
4970 (or (stringp pr-txt-command)
4971 (setq pr-txt-command
4972 (cond (ps-windows-system "print")
4973 (ps-lp-system "lp")
4974 (t "lpr")
4976 (pr-update-mode-line))
4979 (defun pr-eval-alist (alist)
4980 (mapcar #'(lambda (option)
4981 (let ((var-sym (car option))
4982 (value (cdr option)))
4983 (if (eq var-sym 'inherits-from:)
4984 (pr-eval-setting-alist value 'global)
4985 (set var-sym (eval value)))))
4986 alist))
4989 (defun pr-eval-local-alist (alist)
4990 (let (local-list)
4991 (mapcar #'(lambda (option)
4992 (let ((var-sym (car option))
4993 (value (cdr option)))
4994 (setq local-list
4995 (if (eq var-sym 'inherits-from:)
4996 (nconc (pr-eval-setting-alist value) local-list)
4997 (set (make-local-variable var-sym) (eval value))
4998 (cons var-sym local-list)))))
4999 alist)
5000 local-list))
5003 (defun pr-eval-setting-alist (key &optional global old)
5004 (let ((setting (cdr (assq key pr-setting-database))))
5005 (and setting
5006 (let ((inherits (nth 0 setting))
5007 (local (nth 1 setting))
5008 (kill (nth 2 setting))
5009 local-list)
5010 (and local global
5011 (progn
5012 (ding)
5013 (message "There are local buffer settings for `%S'." key)
5014 (setq global nil)))
5015 (and inherits
5016 (if (memq inherits old)
5017 (error "Circular inheritance for `%S'." inherits)
5018 (setq local-list
5019 (pr-eval-setting-alist inherits global
5020 (cons inherits old)))))
5021 (mapcar
5022 (cond ((not local) ; global settings
5023 #'(lambda (option)
5024 (let ((var-sym (car option)))
5025 (or (eq var-sym 'inherits-from:)
5026 (set var-sym (eval (cdr option)))))))
5027 (kill ; local settings with killing
5028 #'(lambda (option)
5029 (let ((var-sym (car option)))
5030 (unless (eq var-sym 'inherits-from:)
5031 (setq local-list (cons var-sym local-list))
5032 (set (make-local-variable var-sym)
5033 (eval (cdr option)))))))
5034 (t ; local settings without killing
5035 #'(lambda (option)
5036 (let ((var-sym (car option)))
5037 (or (eq var-sym 'inherits-from:)
5038 (set (make-local-variable var-sym)
5039 (eval (cdr option))))))))
5040 (nthcdr 3 setting))
5041 local-list))))
5044 (defun pr-kill-local-variable (local-var-list)
5045 (mapcar 'kill-local-variable local-var-list))
5048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5049 ;; Internal Functions (II)
5052 (defun pr-prompt (str)
5053 (if (pr-auto-mode-p)
5054 (concat str " mode")
5055 (pr-region-active-string str)))
5058 (defun pr-prompt-region (str)
5059 (concat str (if (pr-auto-mode-p)
5060 " mode"
5061 " region")))
5064 (defun pr-prompt-gs (str)
5065 (if (pr-using-ghostscript-p)
5066 (concat str " GS")
5067 str))
5070 (defun pr-region-active-symbol (&optional region-p)
5071 (if (or region-p (pr-region-active-p))
5072 'region
5073 'buffer))
5076 (defun pr-region-active-string (prefix)
5077 (concat prefix
5078 (if (pr-region-active-p)
5079 " region"
5080 " buffer")))
5083 (defun pr-show-setup (settings buffer-name)
5084 (with-output-to-temp-buffer buffer-name
5085 (princ settings)
5086 (print-help-return-message)))
5089 (defun pr-complete-alist (prompt alist default)
5090 (let ((collection (mapcar #'(lambda (elt)
5091 (setq elt (car elt))
5092 (cons (symbol-name elt) elt))
5093 alist)))
5094 (cdr (assoc (completing-read (concat prompt ": ")
5095 collection nil t
5096 (symbol-name default) nil
5097 (symbol-name default))
5098 collection))))
5101 (defun pr-delete-file (file)
5102 (and pr-delete-temp-file (delete-file file)))
5105 (defun pr-expand-file-name (filename)
5106 (pr-dosify-path (expand-file-name filename)))
5109 (defun pr-ps-outfile-preprint (&optional mess)
5110 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5111 (res (read-file-name prompt default-directory "" nil)))
5112 (while (cond ((not (file-writable-p res))
5113 (ding)
5114 (setq prompt "is unwritable"))
5115 ((file-directory-p res)
5116 (ding)
5117 (setq prompt "is a directory"))
5118 ((file-exists-p res)
5119 (ding)
5120 (setq prompt "exists")
5121 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5122 res))))
5123 (t nil))
5124 (setq res (read-file-name
5125 (format "File %s; PostScript file: " prompt)
5126 (file-name-directory res) nil nil
5127 (file-name-nondirectory res))))
5128 (pr-expand-file-name res)))
5131 (defun pr-ps-infile-preprint (&optional mess)
5132 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5133 (res (read-file-name prompt default-directory "" nil)))
5134 (while (cond ((not (file-exists-p res))
5135 (ding)
5136 (setq prompt "doesn't exist"))
5137 ((not (file-readable-p res))
5138 (ding)
5139 (setq prompt "is unreadable"))
5140 ((file-directory-p res)
5141 (ding)
5142 (setq prompt "is a directory"))
5143 (t nil))
5144 (setq res (read-file-name
5145 (format "File %s; PostScript file: " prompt)
5146 (file-name-directory res) nil nil
5147 (file-name-nondirectory res))))
5148 (pr-expand-file-name res)))
5151 (defun pr-toggle (var-sym mess entry index horizontal state &optional path)
5152 (set var-sym (not (symbol-value var-sym)))
5153 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5154 (pr-menu-lock entry index horizontal state path))
5157 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
5158 ;; n-up
5159 (or (symbol-value n-up-sym)
5160 (set n-up-sym (pr-interactive-n-up prompt)))
5161 (and (eq (symbol-value infile-sym) t)
5162 (set infile-sym (and (not (interactive-p))
5163 (pr-ps-infile-preprint prompt))))
5164 ;; input file
5165 (or (symbol-value infile-sym)
5166 (error "%s: input PostScript file name is missing" prompt))
5167 (set infile-sym (pr-dosify-path (symbol-value infile-sym)))
5168 ;; output file
5169 (and (eq (symbol-value outfile-sym) t)
5170 (set outfile-sym (and (not (interactive-p))
5171 current-prefix-arg
5172 (pr-ps-outfile-preprint prompt))))
5173 (and (symbol-value outfile-sym)
5174 (set outfile-sym (pr-dosify-path (symbol-value outfile-sym))))
5175 (pr-ps-file (symbol-value outfile-sym)))
5178 (defun pr-ps-utility-process (n-up infile outfile)
5179 (let (item)
5180 (and (stringp infile) (file-exists-p infile)
5181 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
5182 (pr-shell-command
5183 (concat (pr-command (nth 0 item)) " "
5184 (pr-switches-string (nth 1 item)
5185 "pr-ps-utility-alist entry")
5187 (pr-switches-string (nth 8 item)
5188 "pr-ps-utility-alist entry")
5190 (and (nth 2 item)
5191 (format (nth 2 item) ps-paper-type))
5192 " " (format (nth 3 item) n-up) " "
5193 (and pr-file-landscape (nth 4 item)) " "
5194 (and pr-file-duplex (nth 5 item)) " "
5195 (and pr-file-tumble (nth 6 item))
5196 " \"" (pr-expand-file-name infile) "\" "
5197 (nth 7 item)
5198 " \"" (pr-expand-file-name outfile) "\"")))))
5201 (defun pr-shell-command (command)
5202 (let ((shell-file-name pr-shell-file-name))
5203 (shell-command command)))
5206 (defun pr-txt-print (from to)
5207 (let ((lpr-command (pr-command pr-txt-command))
5208 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5209 (printer-name pr-txt-printer))
5210 (lpr-region from to)))
5213 (defun pr-switches-string (switches mess)
5214 (mapconcat 'identity (pr-switches switches mess) " "))
5217 (defun pr-switches (switches mess)
5218 (or (listp switches)
5219 (error "%S should have a list of strings." mess))
5220 (ps-flatten-list ; dynamic evaluation
5221 (mapcar 'ps-eval-switch switches)))
5224 (defun pr-ps-preview (kind n-up filename mess)
5225 (pr-set-n-up-and-filename 'n-up 'filename mess)
5226 (let ((file (pr-ps-file filename)))
5227 (pr-text2ps kind n-up file)
5228 (or pr-spool-p (pr-ps-file-preview file))))
5231 (defun pr-ps-using-ghostscript (kind n-up filename mess)
5232 (pr-set-n-up-and-filename 'n-up 'filename mess)
5233 (let ((file (pr-ps-file filename)))
5234 (pr-text2ps kind n-up file)
5235 (unless (or pr-spool-p filename)
5236 (pr-ps-file-using-ghostscript file)
5237 (pr-delete-file file))))
5240 (defun pr-ps-print (kind n-up filename mess)
5241 (pr-set-n-up-and-filename 'n-up 'filename mess)
5242 (let ((file (pr-ps-file filename)))
5243 (pr-text2ps kind n-up file)
5244 (unless (or pr-spool-p filename)
5245 (pr-ps-file-print file)
5246 (pr-delete-file file))))
5249 (defun pr-ps-file (&optional filename)
5250 (pr-dosify-path (or filename
5251 (convert-standard-filename
5252 (expand-file-name pr-ps-temp-file pr-temp-dir)))))
5255 (defun pr-interactive-n-up (mess)
5256 (or (stringp mess) (setq mess "*"))
5257 (save-match-data
5258 (let* ((fmt-prompt "%s[%s] N-up printing: (default 1) ")
5259 (prompt "")
5260 (str (pr-f-read-string (format fmt-prompt prompt mess) "1" nil "1"))
5261 int)
5262 (while (if (string-match "^\\s *[0-9]+$" str)
5263 (setq int (string-to-int str)
5264 prompt (cond ((< int 1) "Integer below 1; ")
5265 ((> int 100) "Integer above 100; ")
5266 (t nil)))
5267 (setq prompt "Invalid integer syntax; "))
5268 (ding)
5269 (setq str
5270 (pr-f-read-string (format fmt-prompt prompt mess) str nil "1")))
5271 int)))
5274 (defun pr-interactive-dir (mess)
5275 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5276 default-directory)))
5277 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
5278 (dir (read-file-name (format fmt-prompt "")
5279 "" dir-name nil dir-name))
5280 prompt)
5281 (while (cond ((not (file-directory-p dir))
5282 (ding)
5283 (setq prompt "It's not a directory! "))
5284 ((not (file-readable-p dir))
5285 (ding)
5286 (setq prompt "Directory is unreadable! "))
5287 (t nil))
5288 (setq dir-name (file-name-directory dir)
5289 dir (read-file-name (format fmt-prompt prompt)
5290 "" dir-name nil dir-name)))
5291 (file-name-as-directory dir)))
5294 (defun pr-interactive-regexp (mess)
5295 (pr-f-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
5298 (defun pr-interactive-dir-args (mess)
5299 (list
5300 ;; get directory argument
5301 (pr-interactive-dir mess)
5302 ;; get file name regexp
5303 (pr-interactive-regexp mess)))
5306 (defun pr-interactive-ps-dir-args (mess)
5307 (list
5308 ;; get n-up argument
5309 (pr-interactive-n-up mess)
5310 ;; get directory argument
5311 (pr-interactive-dir mess)
5312 ;; get file name regexp
5313 (pr-interactive-regexp mess)
5314 ;; get output file name
5315 (and (not pr-spool-p)
5316 (ps-print-preprint current-prefix-arg))))
5319 (defun pr-interactive-n-up-file (mess)
5320 (list
5321 ;; get n-up argument
5322 (pr-interactive-n-up mess)
5323 ;; get output file name
5324 (and (not pr-spool-p)
5325 (ps-print-preprint current-prefix-arg))))
5328 (defun pr-interactive-n-up-inout (mess)
5329 (list
5330 ;; get n-up argument
5331 (pr-interactive-n-up mess)
5332 ;; get input file name
5333 (pr-ps-infile-preprint (concat mess " "))
5334 ;; get output file name
5335 (ps-print-preprint current-prefix-arg)))
5338 (defun pr-set-outfilename (filename-sym)
5339 (and (not pr-spool-p)
5340 (eq (symbol-value filename-sym) t)
5341 (set filename-sym (and (not (interactive-p))
5342 current-prefix-arg
5343 (ps-print-preprint current-prefix-arg))))
5344 (and (symbol-value filename-sym)
5345 (set filename-sym (pr-dosify-path (symbol-value filename-sym)))))
5348 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5349 ;; n-up
5350 (or (symbol-value n-up-sym)
5351 (set n-up-sym (pr-interactive-n-up mess)))
5352 ;; output file
5353 (pr-set-outfilename filename-sym))
5356 (defun pr-set-dir-args (dir-sym regexp-sym mess)
5357 ;; directory
5358 (or (symbol-value dir-sym)
5359 (set dir-sym (pr-interactive-dir mess)))
5360 ;; file name regexp
5361 (or (symbol-value regexp-sym)
5362 (set regexp-sym (pr-interactive-regexp mess))))
5365 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5366 ;; n-up
5367 (or (symbol-value n-up-sym)
5368 (set n-up-sym (pr-interactive-n-up mess)))
5369 ;; directory & file name regexp
5370 (pr-set-dir-args dir-sym regexp-sym mess)
5371 ;; output file
5372 (pr-set-outfilename filename-sym))
5375 (defun pr-find-buffer-visiting (file)
5376 (if (not (file-directory-p file))
5377 (find-buffer-visiting (if ps-windows-system
5378 (downcase file)
5379 file))
5380 (let ((truename (file-truename file))
5381 (blist (buffer-list))
5382 found)
5383 (while (and (not found) blist)
5384 (save-excursion
5385 (set-buffer (car blist))
5386 (and (eq major-mode 'dired-mode)
5387 (save-excursion
5388 (goto-char (point-min))
5389 (string= (buffer-substring-no-properties
5390 (+ (point-min) 2)
5391 (progn
5392 (end-of-line)
5393 (1- (point))))
5394 truename))
5395 (setq found (car blist))))
5396 (setq blist (cdr blist)))
5397 found)))
5400 (defun pr-file-list (dir file-regexp fun)
5401 (mapcar #'(lambda (file)
5402 (and (or pr-list-directory
5403 (not (file-directory-p file)))
5404 (let ((buffer (pr-find-buffer-visiting file))
5405 pop-up-windows
5406 pop-up-frames)
5407 (and (or buffer
5408 (file-readable-p file))
5409 (save-excursion
5410 (set-buffer (or buffer
5411 (find-file-noselect file)))
5412 (funcall fun)
5413 (or buffer
5414 (kill-buffer (current-buffer))))))))
5415 (directory-files dir t file-regexp)))
5418 (defun pr-delete-file-if-exists (filename)
5419 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5420 (delete-file filename)))
5423 (defun pr-ps-file-list (n-up dir file-regexp filename)
5424 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5425 (let ((pr-spool-p t))
5426 (pr-file-list dir file-regexp
5427 #'(lambda ()
5428 (if (pr-auto-mode-p)
5429 (pr-ps-mode n-up filename)
5430 (pr-text2ps 'buffer n-up filename)))))
5431 (or pr-spool-p
5432 (pr-despool-print filename)))
5435 (defun pr-text2ps (kind n-up filename &optional from to)
5436 (let ((ps-n-up-printing n-up)
5437 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5438 'setpagedevice)))
5439 (pr-delete-file-if-exists filename)
5440 (cond (pr-faces-p
5441 (cond (pr-spool-p
5442 ;; pr-faces-p and pr-spool-p
5443 ;; here FILENAME arg is ignored
5444 (cond ((eq kind 'buffer)
5445 (ps-spool-buffer-with-faces))
5446 ((eq kind 'region)
5447 (ps-spool-region-with-faces (or from (point))
5448 (or to (mark))))
5450 ;; pr-faces-p and not pr-spool-p
5451 ((eq kind 'buffer)
5452 (ps-print-buffer-with-faces filename))
5453 ((eq kind 'region)
5454 (ps-print-region-with-faces (or from (point))
5455 (or to (mark)) filename))
5457 (pr-spool-p
5458 ;; not pr-faces-p and pr-spool-p
5459 ;; here FILENAME arg is ignored
5460 (cond ((eq kind 'buffer)
5461 (ps-spool-buffer))
5462 ((eq kind 'region)
5463 (ps-spool-region (or from (point)) (or to (mark))))
5465 ;; not pr-faces-p and not pr-spool-p
5466 ((eq kind 'buffer)
5467 (ps-print-buffer filename))
5468 ((eq kind 'region)
5469 (ps-print-region (or from (point)) (or to (mark)) filename))
5473 (defun pr-command (command)
5474 "Return absolute file name specification for COMMAND.
5476 If COMMAND is already an absolute file name specification, return it.
5477 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5478 otherwise, gives an error.
5480 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5481 `unix' are used (see `pr-path-alist' for documentation).
5483 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5484 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5485 (pr-dosify-path
5486 (or (pr-find-command command)
5487 (pr-path-command (cond (pr-cygwin-system 'cygwin)
5488 (ps-windows-system 'windows)
5489 (t 'unix))
5490 (file-name-nondirectory command)
5491 nil)
5492 (error "Command not found: %s" (file-name-nondirectory command)))))
5495 (defun pr-path-command (symbol command sym-list)
5496 (let ((lpath (cdr (assq symbol pr-path-alist)))
5497 cmd)
5498 ;; PATH expansion
5499 (and (eq symbol 'PATH) (null lpath)
5500 (setq lpath (parse-colon-path (getenv "PATH"))))
5501 (while (and lpath
5502 (not
5503 (setq cmd
5504 (let ((path (car lpath)))
5505 (cond
5506 ;; symbol expansion
5507 ((symbolp path)
5508 (and (not (memq path sym-list))
5509 (pr-path-command path command
5510 (cons path sym-list))))
5511 ;; normal path
5512 ((stringp path)
5513 (pr-find-command
5514 (expand-file-name
5515 (substitute-in-file-name
5516 (concat (file-name-as-directory path)
5517 command)))))
5518 )))))
5519 (setq lpath (cdr lpath)))
5520 cmd))
5523 (defun pr-find-command (cmd)
5524 (if ps-windows-system
5525 ;; windows system
5526 (let ((ext (cons (file-name-extension cmd t)
5527 (list ".exe" ".bat" ".com")))
5528 found)
5529 (setq cmd (file-name-sans-extension cmd))
5530 (while (and ext
5531 (setq found (concat cmd (car ext)))
5532 (not (and (file-regular-p found)
5533 (file-executable-p found))))
5534 (setq ext (cdr ext)
5535 found nil))
5536 found)
5537 ;; non-windows systems
5538 (and (file-regular-p cmd)
5539 (file-executable-p cmd)
5540 cmd)))
5543 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5544 ;; Printing Interface (inspired on ps-print-interface.el)
5547 (require 'widget)
5548 (require 'wid-edit)
5549 (require 'cus-edit)
5552 (defvar pr-i-window-configuration nil)
5554 (defvar pr-i-buffer nil)
5555 (defvar pr-i-region nil)
5556 (defvar pr-i-mode nil)
5557 (defvar pr-i-despool nil)
5558 (defvar pr-i-ps-as-is t)
5559 (defvar pr-i-n-up 1)
5560 (defvar pr-i-directory "./")
5561 (defvar pr-i-regexp "")
5562 (defvar pr-i-ps-file "")
5563 (defvar pr-i-out-file "")
5564 (defvar pr-i-answer-yes nil)
5565 (defvar pr-i-process 'buffer)
5566 (defvar pr-i-ps-send 'printer)
5569 (defvar pr-interface-map nil
5570 "Keymap for pr-interface.")
5572 (if pr-interface-map
5574 (setq pr-interface-map (make-sparse-keymap))
5575 (cond ((eq ps-print-emacs-type 'xemacs) ; XEmacs
5576 (pr-f-set-keymap-parents pr-interface-map (list widget-keymap))
5577 (pr-f-set-keymap-name pr-interface-map 'pr-interface-map))
5578 ((eq ps-print-emacs-type 'emacs) ; GNU Emacs
5579 (pr-f-set-keymap-parents pr-interface-map widget-keymap)))
5580 (define-key pr-interface-map "q" 'pr-interface-quit)
5581 (define-key pr-interface-map "?" 'pr-interface-help))
5584 (defmacro pr-interface-save (&rest body)
5585 `(save-excursion
5586 (set-buffer pr-i-buffer)
5587 ,@body))
5590 (defun pr-create-interface ()
5591 "Create the front end for printing package."
5592 (setq pr-i-buffer (buffer-name (current-buffer))
5593 pr-i-region (ps-mark-active-p)
5594 pr-i-mode (pr-mode-alist-p)
5595 pr-i-window-configuration (current-window-configuration))
5597 (put 'pr-i-process 'pr-widget-list nil)
5598 (put 'pr-i-ps-send 'pr-widget-list nil)
5600 (delete-other-windows)
5601 (kill-buffer (get-buffer-create pr-buffer-name))
5602 (switch-to-buffer (get-buffer-create pr-buffer-name))
5604 ;; header
5605 (let ((versions (concat "printing v" pr-version
5606 " ps-print v" ps-print-version)))
5607 (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
5608 (pr-insert-italic "\nCurrent Directory : " 1)
5609 (pr-insert-italic default-directory)
5611 (pr-insert-section-1) ; 1. Print
5612 (pr-insert-section-2) ; 2. PostScript Printer
5613 (pr-insert-section-3) ; 3. Text Printer
5615 ;; separator
5616 (widget-insert "\n\n " (make-string 77 ?-))
5618 (pr-insert-section-4) ; 4. Settings
5619 (pr-insert-section-5) ; 5. Customize
5620 (pr-insert-section-6) ; 6. Show Settings
5621 (pr-insert-section-7) ; 7. Help
5623 (use-local-map pr-interface-map)
5624 (widget-setup)
5625 (goto-char (point-min))
5627 (and pr-i-region ; let region activated
5628 (pr-keep-region-active)))
5631 (defun pr-insert-section-1 ()
5632 ;; 1. Print:
5633 (pr-insert-italic "\nPrint :" 1)
5635 ;; 1a. Buffer:
5636 ;; 1a. Buffer: Buffer List
5637 (pr-insert-radio-button 'pr-i-process 'buffer)
5638 (pr-insert-menu "Buffer List" 'pr-i-buffer
5639 (let ((blist (buffer-list))
5640 case-fold-search choices)
5641 (while blist
5642 (let ((name (buffer-name (car blist)))
5643 (ignore pr-buffer-name-ignore)
5644 found)
5645 (setq blist (cdr blist))
5646 (while (and ignore (not found))
5647 (setq found (string-match (car ignore) name)
5648 ignore (cdr ignore)))
5649 (or found
5650 (setq choices
5651 (cons (list 'quote
5652 (list 'choice-item
5653 :format "%[%t%]"
5654 name))
5655 choices)))))
5656 (nreverse choices))
5657 " Buffer : " nil
5658 '(progn
5659 (pr-interface-save
5660 (setq pr-i-region (ps-mark-active-p)
5661 pr-i-mode (pr-mode-alist-p)))
5662 (pr-update-checkbox 'pr-i-region)
5663 (pr-update-checkbox 'pr-i-mode)))
5664 ;; 1a. Buffer: Region
5665 (put 'pr-i-region 'pr-widget
5666 (pr-insert-checkbox
5667 "\n "
5668 'pr-i-region
5669 #'(lambda (widget &rest ignore)
5670 (let ((region-p (pr-interface-save
5671 (ps-mark-active-p))))
5672 (cond ((null (widget-value widget)) ; widget is nil
5673 (setq pr-i-region nil))
5674 (region-p ; widget is true and there is a region
5675 (setq pr-i-region t)
5676 (widget-value-set widget t)
5677 (widget-setup)) ; MUST be called after widget-value-set
5678 (t ; widget is true and there is no region
5679 (ding)
5680 (message "There is no region active")
5681 (setq pr-i-region nil)
5682 (widget-value-set widget nil)
5683 (widget-setup))))) ; MUST be called after widget-value-set
5684 " Region"))
5685 ;; 1a. Buffer: Mode
5686 (put 'pr-i-mode 'pr-widget
5687 (pr-insert-checkbox
5689 'pr-i-mode
5690 #'(lambda (widget &rest ignore)
5691 (let ((mode-p (pr-interface-save
5692 (pr-mode-alist-p))))
5693 (cond
5694 ((null (widget-value widget)) ; widget is nil
5695 (setq pr-i-mode nil))
5696 (mode-p ; widget is true and there is a `mode'
5697 (setq pr-i-mode t)
5698 (widget-value-set widget t)
5699 (widget-setup)) ; MUST be called after widget-value-set
5700 (t ; widget is true and there is no `mode'
5701 (ding)
5702 (message
5703 "This buffer isn't in a mode that printing treats specially.")
5704 (setq pr-i-mode nil)
5705 (widget-value-set widget nil)
5706 (widget-setup))))) ; MUST be called after widget-value-set
5707 " Mode\n"))
5709 ;; 1b. Directory:
5710 (pr-insert-radio-button 'pr-i-process 'directory)
5711 (widget-create
5712 'directory
5713 :size 58
5714 :format " Directory : %v"
5715 :notify 'pr-interface-directory
5716 :action (lambda (widget &optional event)
5717 (if (pr-interface-directory widget)
5718 (pr-widget-field-action widget event)
5719 (ding)
5720 (message "It should be a readable directory")))
5721 pr-i-directory)
5722 ;; 1b. Directory: File Regexp
5723 (widget-create 'regexp
5724 :size 58
5725 :format "\n File Regexp : %v\n"
5726 :notify (lambda (widget &rest ignore)
5727 (setq pr-i-regexp (widget-value widget)))
5728 pr-i-regexp)
5729 ;; 1b. Directory: List Directory Entry
5730 (widget-insert " ")
5731 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
5733 ;; 1c. PostScript File:
5734 (pr-insert-radio-button 'pr-i-process 'file)
5735 (widget-create
5736 'file
5737 :size 51
5738 :format " PostScript File : %v"
5739 :notify 'pr-interface-infile
5740 :action (lambda (widget &rest event)
5741 (if (pr-interface-infile widget)
5742 (pr-widget-field-action widget event)
5743 (ding)
5744 (message "It should be a readable PostScript file")))
5745 pr-i-ps-file)
5746 ;; 1c. PostScript File: PostScript Utility
5747 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
5748 (pr-choice-alist pr-ps-utility-alist)
5749 "\n PostScript Utility : "
5750 " ")
5751 ;; 1c. PostScript File: Use It AS-IS
5752 (pr-insert-toggle 'pr-i-ps-as-is " Use It ")
5753 (pr-insert-italic "AS-IS"))
5756 (defun pr-insert-section-2 ()
5757 ;; 2. PostScript Printer:
5758 ;; 2. PostScript Printer: PostScript Printer List
5759 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
5760 (pr-insert-menu "PostScript Printer" 'pr-ps-name
5761 (pr-choice-alist pr-ps-printer-alist))
5762 ;; 2. PostScript Printer: Despool
5763 (put 'pr-i-despool 'pr-widget
5764 (pr-insert-checkbox
5766 'pr-i-despool
5767 #'(lambda (widget &rest ignore)
5768 (if pr-spool-p
5769 (setq pr-i-despool (not pr-i-despool))
5770 (ding)
5771 (message "It despool only when it's spooling")
5772 (setq pr-i-despool nil))
5773 (widget-value-set widget pr-i-despool)
5774 (widget-setup)) ; MUST be called after widget-value-set
5775 " Despool "))
5776 ;; 2. PostScript Printer: Preview Print Quit
5777 (pr-insert-button 'pr-interface-preview "Preview" " ")
5778 (pr-insert-button 'pr-interface-ps-print "Print" " ")
5779 (pr-insert-button 'pr-interface-quit "Quit")
5780 ;; 2. PostScript Printer: Send to Printer/Temporary File
5781 (pr-insert-radio-button 'pr-i-ps-send 'printer)
5782 (widget-insert " Send to Printer/Temporary File")
5783 ;; 2. PostScript Printer: Send to File
5784 (pr-insert-radio-button 'pr-i-ps-send 'file)
5785 (widget-create
5786 'file
5787 :size 57
5788 :format " Send to File : %v"
5789 :notify 'pr-interface-outfile
5790 :action (lambda (widget &rest event)
5791 (if (and (pr-interface-outfile widget)
5792 (or (not (file-exists-p pr-i-out-file))
5793 (setq pr-i-answer-yes
5794 (y-or-n-p "File exists; overwrite? "))))
5795 (pr-widget-field-action widget event)
5796 (ding)
5797 (message "It should be a writable PostScript file")))
5798 pr-i-out-file)
5799 ;; 2. PostScript Printer: N-Up
5800 (widget-create
5801 'integer
5802 :size 3
5803 :format "\n N-Up : %v"
5804 :notify (lambda (widget &rest ignore)
5805 (let ((value (if (string= (widget-apply widget :value-get) "")
5807 (widget-value widget))))
5808 (if (and (integerp value)
5809 (<= 1 value) (<= value 100))
5810 (progn
5811 (message " ")
5812 (setq pr-i-n-up value))
5813 (ding)
5814 (message "It should be an integer between 1 and 100"))))
5815 pr-i-n-up))
5818 (defun pr-insert-section-3 ()
5819 ;; 3. Text Printer:
5820 (pr-insert-italic "\n\nText Printer : " 2 14)
5821 (pr-insert-menu "Text Printer" 'pr-txt-name
5822 (pr-choice-alist pr-txt-printer-alist)
5823 nil " ")
5824 (pr-insert-button 'pr-interface-printify "Printify" " ")
5825 (pr-insert-button 'pr-interface-txt-print "Print" " ")
5826 (pr-insert-button 'pr-interface-quit "Quit"))
5829 (defun pr-insert-section-4 ()
5830 ;; 4. Settings:
5831 ;; 4. Settings: Landscape Auto Region Verbose
5832 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
5833 #'(lambda (&rest ignore)
5834 (setq ps-landscape-mode (not ps-landscape-mode)
5835 pr-file-landscape ps-landscape-mode))
5836 " Landscape ")
5837 (pr-insert-toggle 'pr-auto-region " Auto Region ")
5838 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
5840 ;; 4. Settings: Print Header Auto Mode
5841 (pr-insert-toggle 'ps-print-header " Print Header ")
5842 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
5844 ;; 4. Settings: Print Header Frame Menu Lock
5845 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
5846 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
5848 ;; 4. Settings: Line Number
5849 (pr-insert-toggle 'ps-line-number " Line Number\n ")
5851 ;; 4. Settings: Zebra Stripes Spool Buffer
5852 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
5853 (pr-insert-checkbox " "
5854 'pr-spool-p
5855 #'(lambda (&rest ignore)
5856 (setq pr-spool-p (not pr-spool-p))
5857 (unless pr-spool-p
5858 (setq pr-i-despool nil)
5859 (pr-update-checkbox 'pr-i-despool)))
5860 " Spool Buffer")
5862 ;; 4. Settings: Duplex Print with-faces
5863 (pr-insert-checkbox "\n "
5864 'ps-spool-duplex
5865 #'(lambda (&rest ignore)
5866 (setq ps-spool-duplex (not ps-spool-duplex)
5867 pr-file-duplex ps-spool-duplex))
5868 " Duplex ")
5869 (pr-insert-toggle 'pr-faces-p " Print with-faces")
5871 ;; 4. Settings: Tumble Print Using Ghostscript
5872 (pr-insert-checkbox "\n "
5873 'ps-spool-tumble
5874 #'(lambda (&rest ignore)
5875 (setq ps-spool-tumble (not ps-spool-tumble)
5876 pr-file-tumble ps-spool-tumble))
5877 " Tumble ")
5878 (pr-insert-toggle 'pr-print-using-ghostscript " Print Using Ghostscript\n ")
5880 ;; 4. Settings: Upside-Down Page Parity
5881 (pr-insert-toggle 'ps-print-upside-down " Upside-Down ")
5882 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
5883 (mapcar #'(lambda (alist)
5884 (list 'quote
5885 (list 'choice-item
5886 :format "%[%t%]"
5887 :tag (cdr alist)
5888 :value (car alist))))
5889 pr-even-or-odd-alist)))
5892 (defun pr-insert-section-5 ()
5893 ;; 5. Customize:
5894 (pr-insert-italic "\n\nCustomize : " 2 11)
5895 (pr-insert-button 'pr-customize "printing" " ")
5896 (pr-insert-button #'(lambda (&rest ignore) (ps-print-customize))
5897 "ps-print" " ")
5898 (pr-insert-button 'lpr-customize "lpr"))
5901 (defun pr-insert-section-6 ()
5902 ;; 6. Show Settings:
5903 (pr-insert-italic "\nShow Settings : " 1 14)
5904 (pr-insert-button 'pr-show-pr-setup "printing" " ")
5905 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
5906 (pr-insert-button 'pr-show-lpr-setup "lpr"))
5909 (defun pr-insert-section-7 ()
5910 ;; 7. Help:
5911 (pr-insert-italic "\nHelp : " 1 5)
5912 (pr-insert-button 'pr-interface-help "Interface Help" " ")
5913 (pr-insert-button 'pr-help "Menu Help" " ")
5914 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
5915 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
5918 (defun pr-kill-help (&rest ignore)
5919 "Kill all printing help buffer."
5920 (interactive)
5921 (let ((help '("*Printing Interface Help*" "*Printing Help*"
5922 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
5923 (while help
5924 (let ((buffer (get-buffer (car help))))
5925 (setq help (cdr help))
5926 (when buffer
5927 (delete-windows-on buffer)
5928 (kill-buffer buffer)))))
5929 (recenter (- (window-height) 2)))
5932 (defun pr-interface-quit (&rest ignore)
5933 "Kill the printing buffer interface and quit."
5934 (interactive)
5935 (kill-buffer pr-buffer-name)
5936 (set-window-configuration pr-i-window-configuration))
5939 (defun pr-interface-help (&rest ignore)
5940 "printing buffer interface help."
5941 (interactive)
5942 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
5945 (defun pr-interface-txt-print (&rest ignore)
5946 "Print using lpr package."
5947 (interactive)
5948 (condition-case data
5949 (cond
5950 ((eq pr-i-process 'directory)
5951 (pr-i-directory)
5952 (pr-interface-save
5953 (pr-txt-directory pr-i-directory pr-i-regexp)))
5954 ((eq pr-i-process 'buffer)
5955 (pr-interface-save
5956 (cond (pr-i-region
5957 (let ((pr-auto-mode pr-i-mode))
5958 (pr-txt-region)))
5959 (pr-i-mode
5960 (let (pr-auto-region)
5961 (pr-txt-mode)))
5963 (let (pr-auto-mode pr-auto-region)
5964 (pr-txt-buffer)))
5966 ((eq pr-i-process 'file)
5967 (error "It should be a text file"))
5969 (error "Internal error: `pr-i-process' = %S" pr-i-process))
5971 ;; handlers
5972 ((quit error)
5973 (ding)
5974 (message (error-message-string data)))))
5977 (defun pr-interface-printify (&rest ignore)
5978 "Printify a buffer."
5979 (interactive)
5980 (condition-case data
5981 (cond
5982 ((eq pr-i-process 'directory)
5983 (pr-i-directory)
5984 (pr-interface-save
5985 (pr-printify-directory pr-i-directory pr-i-regexp)))
5986 ((eq pr-i-process 'buffer)
5987 (pr-interface-save
5988 (if pr-i-region
5989 (pr-printify-region)
5990 (pr-printify-buffer))))
5991 ((eq pr-i-process 'file)
5992 (error "It can't printify a PostScript file"))
5994 (error "Internal error: `pr-i-process' = %S" pr-i-process))
5996 ;; handlers
5997 ((quit error)
5998 (ding)
5999 (message (error-message-string data)))))
6002 (defun pr-interface-ps-print (&rest ignore)
6003 "Print using ps-print package."
6004 (interactive)
6005 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6006 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6007 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6008 'pr-ps-buffer-ps-print))
6011 (defun pr-interface-preview (&rest ignore)
6012 "Preview a PostScript file."
6013 (interactive)
6014 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6015 'pr-ps-file-preview 'pr-ps-file-up-preview
6016 'pr-ps-region-preview 'pr-ps-mode-preview
6017 'pr-ps-buffer-preview))
6020 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6021 ps-mode ps-buffer)
6022 (condition-case data
6023 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6024 (pr-i-ps-send))))
6025 (cond
6026 ((and pr-i-despool pr-spool-p)
6027 (pr-interface-save
6028 (funcall ps-despool outfile))
6029 (setq pr-i-despool nil)
6030 (pr-update-checkbox 'pr-i-despool))
6031 ((eq pr-i-process 'directory)
6032 (pr-i-directory)
6033 (pr-interface-save
6034 (funcall ps-directory
6035 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6036 ((eq pr-i-process 'file)
6037 (cond ((or (file-directory-p pr-i-ps-file)
6038 (not (file-readable-p pr-i-ps-file)))
6039 (error "It should be a readable PostScript file"))
6040 (pr-i-ps-as-is
6041 (pr-interface-save
6042 (funcall ps-file pr-i-ps-file)))
6044 (pr-interface-save
6045 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6047 ((eq pr-i-process 'buffer)
6048 (pr-interface-save
6049 (cond (pr-i-region
6050 (let ((pr-auto-mode pr-i-mode))
6051 (funcall ps-region pr-i-n-up outfile)))
6052 (pr-i-mode
6053 (let (pr-auto-region)
6054 (funcall ps-mode pr-i-n-up outfile)))
6056 (let (pr-auto-mode pr-auto-region)
6057 (funcall ps-buffer pr-i-n-up outfile)))
6060 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6062 ;; handlers
6063 ((quit error)
6064 (ding)
6065 (message (error-message-string data)))))
6068 (defun pr-i-ps-send ()
6069 (cond ((eq pr-i-ps-send 'printer)
6070 nil)
6071 ((not (eq pr-i-ps-send 'file))
6072 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6073 ((or (file-directory-p pr-i-out-file)
6074 (not (file-writable-p pr-i-out-file)))
6075 (error "It should be a writable PostScript file"))
6076 ((or (not (file-exists-p pr-i-out-file))
6077 pr-i-answer-yes
6078 (setq pr-i-answer-yes
6079 (y-or-n-p (format "File `%s' exists; overwrite? "
6080 pr-i-out-file))))
6081 pr-i-out-file)
6083 (error "File already exists"))))
6086 (defun pr-i-directory ()
6087 (or (and (file-directory-p pr-i-directory)
6088 (file-readable-p pr-i-directory))
6089 (error "It should be a readable directory")))
6092 (defun pr-interface-directory (widget &rest ignore)
6093 (and pr-buffer-verbose
6094 (message "Type M-TAB or ESC TAB for file completion"))
6095 (let ((dir (widget-value widget)))
6096 (and (file-directory-p dir)
6097 (file-readable-p dir)
6098 (setq pr-i-directory dir))))
6101 (defun pr-interface-infile (widget &rest ignore)
6102 (and pr-buffer-verbose
6103 (message "Type M-TAB or ESC TAB for file completion"))
6104 (let ((file (widget-value widget)))
6105 (and (not (file-directory-p file))
6106 (file-readable-p file)
6107 (setq pr-i-ps-file file))))
6110 (defun pr-interface-outfile (widget &rest ignore)
6111 (setq pr-i-answer-yes nil)
6112 (and pr-buffer-verbose
6113 (message "Type M-TAB or ESC TAB for file completion"))
6114 (let ((file (widget-value widget)))
6115 (and (not (file-directory-p file))
6116 (file-writable-p file)
6117 (setq pr-i-out-file file))))
6120 (defun pr-widget-field-action (widget event)
6121 (and (get-buffer "*Completions*") ; clean frame window
6122 (delete-windows-on "*Completions*"))
6123 (message " ") ; clean echo area
6124 (widget-field-action widget event))
6127 (defun pr-insert-italic (str &optional from to)
6128 (let ((len (length str)))
6129 (put-text-property (if from (max from 0) 0)
6130 (if to (max to len) len)
6131 'face 'italic str)
6132 (widget-insert str)))
6135 (defun pr-insert-checkbox (before var-sym fun label)
6136 (widget-insert before)
6137 (prog1
6138 (widget-create 'checkbox
6139 :notify fun
6140 (symbol-value var-sym))
6141 (widget-insert label)))
6144 (defun pr-insert-toggle (var-sym label)
6145 (widget-create 'checkbox
6146 :notify `(lambda (&rest ignore)
6147 (setq ,var-sym (not ,var-sym)))
6148 (symbol-value var-sym))
6149 (widget-insert label))
6152 (defun pr-insert-button (fun label &optional separator)
6153 (widget-create 'push-button
6154 :notify fun
6155 label)
6156 (and separator
6157 (widget-insert separator)))
6160 (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6161 (and before (widget-insert before))
6162 (eval `(widget-create 'menu-choice
6163 :tag ,tag
6164 :format "%v"
6165 :inline t
6166 :value ,var-sym
6167 :notify (lambda (widget &rest ignore)
6168 (setq ,var-sym (widget-value widget))
6169 ,@body)
6170 :void '(choice-item :format "%[%t%]"
6171 :tag "Can not display value!")
6172 ,@choices))
6173 (and after (widget-insert after)))
6176 (defun pr-insert-radio-button (var-sym sym)
6177 (widget-insert "\n")
6178 (let ((wid-list (get var-sym 'pr-widget-list))
6179 (wid (eval `(widget-create
6180 'radio-button
6181 :format " %[%v%]"
6182 :value (eq ,var-sym (quote ,sym))
6183 :notify (lambda (&rest ignore)
6184 (setq ,var-sym (quote ,sym))
6185 (pr-update-radio-button (quote ,var-sym)))))))
6186 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6189 (defun pr-update-radio-button (var-sym)
6190 (let ((wid-list (get var-sym 'pr-widget-list)))
6191 (while wid-list
6192 (let ((wid (car (car wid-list)))
6193 (value (cdr (car wid-list))))
6194 (setq wid-list (cdr wid-list))
6195 (widget-value-set wid (eq (symbol-value var-sym) value))))
6196 (widget-setup)))
6199 (defun pr-update-checkbox (var-sym)
6200 (let ((wid (get var-sym 'pr-widget)))
6201 (when wid
6202 (widget-value-set wid (symbol-value var-sym))
6203 (widget-setup))))
6206 (defun pr-choice-alist (alist)
6207 (let ((max (apply 'max (mapcar #'(lambda (alist)
6208 (length (symbol-name (car alist))))
6209 alist))))
6210 (mapcar #'(lambda (alist)
6211 (let* ((sym (car alist))
6212 (name (symbol-name sym)))
6213 (list
6214 'quote
6215 (list
6216 'choice-item
6217 :format "%[%t%]"
6218 :tag (concat name
6219 (make-string (- max (length name)) ?_))
6220 :value sym))))
6221 alist)))
6224 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6227 (pr-update-menus t)
6230 (provide 'printing)
6233 ;;; printing.el ends here