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