Make sure x_default_search_path is always set even
[emacs.git] / lisp / printing.el
blob18252155e49a2d59b29eccfbe57f680bdea2c6f3
1 ;;; printing.el --- printing utilities
3 ;; Copyright (C) 2000, 2001, 2003, 2004, 2005,
4 ;; 2006 Free Software Foundation, Inc.
6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8 ;; Time-stamp: <2006/09/15 18:53:14 vinicius>
9 ;; Keywords: wp, print, PostScript
10 ;; Version: 6.8.4
11 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
13 (defconst pr-version "6.8.4"
14 "printing.el, v 6.8.4 <2005/06/11 vinicius>
16 Please send all bug fixes and enhancements to
17 Vinicius Jose Latorre <viniciusjl@ig.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
36 ;;; Commentary:
38 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;; Introduction
41 ;; ------------
43 ;; With `printing' you can preview or print a PostScript file. You can also
44 ;; print a text file using PostScript, and preview or print buffers that use
45 ;; certain special modes like mh-folder-mode, rmail-summary-mode,
46 ;; gnus-summary-mode, etc. This package also includes a PostScript/text
47 ;; printer database.
49 ;; There are two user interfaces:
51 ;; * Menu interface:
52 ;; The `printing' menu replaces the usual print options in the menu bar.
53 ;; This is the default user interface.
55 ;; * Buffer interface:
56 ;; You can use a buffer interface instead of menus. It looks like a
57 ;; customization buffer. Basically, it has the same options found in the
58 ;; menu and some extra options, all this on a buffer.
60 ;; `printing' is prepared to run on GNU, Unix and NT systems.
61 ;; On GNU or Unix system, `printing' depends on gs and gv utilities.
62 ;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe).
63 ;; To obtain ghostscript, ghostview and GSview see the URL
64 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'.
66 ;; `printing' depends on ps-print package to generate PostScript files, to
67 ;; spool and to despool PostScript buffer. So, `printing' provides an
68 ;; interface to ps-print package and it also provides some extra stuff.
70 ;; To download the latest ps-print package see
71 ;; `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'.
72 ;; Please, see README file for ps-print installation instructions.
74 ;; `printing' was inspired on:
76 ;; print-nt.el Frederic Corne <frederic.corne@erli.fr>
77 ;; Special printing functions for Windows NT
79 ;; mh-e-init.el Tom Vogels <tov@ece.cmu.edu>
80 ;; PS-print for mail messages
82 ;; win32-ps-print.el Matthew O. Persico <mpersico@erols.com>
83 ;; PostScript printing with ghostscript
85 ;; ps-print-interface.el Volker Franz <volker.franz@tuebingen.mpg.de>
86 ;; Graphical front end for ps-print and previewing
89 ;; Log Messages
90 ;; ------------
92 ;; The buffer *Printing Command Output* is where the `printing' log messages
93 ;; are inserted. All program called by `printing' has a log entry in the
94 ;; buffer *Printing Command Output*. A log entry has the following form:
96 ;; PROGRAM (ARG...)
97 ;; MESSAGE
98 ;; Exit status: CODE
100 ;; Where
101 ;; PROGRAM is the program activated by `printing',
102 ;; ARG is an argument passed to PROGRAM (it can have more than one argument),
103 ;; MESSAGE is an error message returned by PROGRAM (it can have no message, if
104 ;; PROGRAM is successful),
105 ;; and CODE is a numeric exit status or a signal description string.
107 ;; For example, after previewing a PostScript file, *Printing Command Output*
108 ;; will have the following entry:
110 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
111 ;; Exit status: 0
113 ;; In the example above, the previewing was successful. If during previewing,
114 ;; you quit gv execution (by typing C-g during Emacs session), the log entry
115 ;; would be:
117 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
118 ;; Exit status: Quit
120 ;; So, if something goes wrong, a good place to take a look is the buffer
121 ;; *Printing Command Output*. Don't forget to see also the buffer *Messages*,
122 ;; it can help.
125 ;; Novices (First Users)
126 ;; ---------------------
128 ;; First of all, see printing documentation only to get an idea of what
129 ;; `printing' is capable.
131 ;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
132 ;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'. These variables
133 ;; are the main variables for printing processing.
135 ;; Now, please, see these variables documentation deeper. You can do this by
136 ;; typing C-h v pr-ps-name RET (for example) if you already loaded printing
137 ;; package, or by browsing printing.el source file.
139 ;; If the documentation isn't clear or if you find a way to improve the
140 ;; documentation, please, send an email to maintainer. All printing users
141 ;; will thank you.
143 ;; One way to set variables is by calling `pr-customize', customize all
144 ;; variables and save the customization by future sessions (see Options
145 ;; section). Other way is by coding your settings on Emacs init file (that is,
146 ;; ~/.emacs file), see below for a first setting template that it should be
147 ;; inserted on your ~/.emacs file (or c:/_emacs, if you're using Windows 9x/NT
148 ;; or MS-DOS):
150 ;; * Example of setting for Windows system:
152 ;; (require 'printing) ; load printing package
153 ;; (setq pr-path-alist
154 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
155 ;; (ghostview "c:/gs/gsview-dir")
156 ;; (mpage "c:/mpage-dir")
157 ;; ))
158 ;; (setq pr-txt-name 'prt_06a)
159 ;; (setq pr-txt-printer-alist
160 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
161 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
162 ;; (PRN "" nil "PRN")
163 ;; (standard "redpr.exe" nil "")
164 ;; ))
165 ;; (setq pr-ps-name 'lps_06b)
166 ;; (setq pr-ps-printer-alist
167 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
168 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
169 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
170 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
171 ;; (LPT1 "" nil "" "LPT1:")
172 ;; (PRN "" nil "" "PRN")
173 ;; (standard "redpr.exe" nil "" "")
174 ;; ))
175 ;; (pr-update-menus t) ; update now printer and utility menus
177 ;; * Example of setting for GNU or Unix system:
179 ;; (require 'printing) ; load printing package
180 ;; (setq pr-path-alist
181 ;; '((unix "." "~/bin" ghostview mpage PATH)
182 ;; (ghostview "$HOME/bin/gsview-dir")
183 ;; (mpage "$HOME/bin/mpage-dir")
184 ;; ))
185 ;; (setq pr-txt-name 'prt_06a)
186 ;; (setq pr-txt-printer-alist
187 ;; '((prt_06a "lpr" nil "prt_06a")
188 ;; (prt_07c nil nil "prt_07c")
189 ;; ))
190 ;; (setq pr-ps-name 'lps_06b)
191 ;; (setq pr-ps-printer-alist
192 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
193 ;; (lps_07c "lpr" nil nil "lps_07c")
194 ;; (lps_08c nil nil nil "lps_08c")
195 ;; ))
196 ;; (pr-update-menus t) ; update now printer and utility menus
199 ;; NOTE 1: Don't forget to download and install ghostscript utilities (see
200 ;; Utilities section).
202 ;; NOTE 2: The `printer-name' and `ps-printer-name' variables don't need to be
203 ;; set, as they are implicit set by `pr-ps-printer-alist' and
204 ;; `pr-txt-printer-alist'.
206 ;; NOTE 3: The duplex feature will only work on PostScript printers that
207 ;; support this feature.
208 ;; You can check if your PostScript printer supports duplex feature
209 ;; by checking the printer manual. Or you can try these steps:
210 ;; 1. Open a buffer (or use the *scratch* buffer).
211 ;; 2. Type:
212 ;; First line (on first page)
213 ;; ^L
214 ;; Second line (on second page)
215 ;; 3. Print this buffer with duplex turned on.
216 ;; If it's printed 2 (two) sheets of paper, then your PostScript
217 ;; printer doesn't have duplex feature; otherwise, it's ok, your
218 ;; printer does have duplex feature.
220 ;; NOTE 4: See Tips section.
223 ;; Tips
224 ;; ----
226 ;; 1. If you have a local printer, that is, a printer which is connected
227 ;; directly to your computer, don't forget to connect the printer to your
228 ;; computer before printing.
230 ;; 2. If you try to print a file and it seems that the file was printed, but
231 ;; there is no paper in the printer, then try to set `pr-delete-temp-file'
232 ;; to nil. Probably `printing' is deleting the temporary file before your
233 ;; local system can get it to send to the printer.
235 ;; 3. Don't try to print a dynamic buffer, that is, a buffer which is
236 ;; modifying while `printing' tries to print. Eventually you got an error
237 ;; message. Instead, save the dynamic buffer to a file or copy it in
238 ;; another buffer and, then, print the file or the new static buffer.
239 ;; An example of dynamic buffer is the *Messages* buffer.
241 ;; 4. When running Emacs on Windows (with or without cygwin), check if your
242 ;; printer is a text printer or not by typing in a DOS window:
244 ;; print /D:\\host\printer somefile.txt
246 ;; Where, `host' is the machine where the printer is directly connected,
247 ;; `printer' is the printer name and `somefile.txt' is a text file.
249 ;; If the printer `\\host\printer' doesn't print the content of
250 ;; `somefile.txt' or, instead, it returns the following message:
252 ;; PostScript Error Handler
253 ;; Offending Command = CCC
254 ;; Stack =
256 ;; Where `CCC' is whatever is at the beginning of the text to be printed.
258 ;; Therefore, the printer `\\host\printer' is not a text printer, but a
259 ;; PostScript printer. So, please, don't include this printer in
260 ;; `pr-txt-printer-alist' (which see).
262 ;; 5. You can use gsprint instead of ghostscript to print monochrome PostScript
263 ;; files in Windows. The gsprint utility documentation says that it is more
264 ;; efficient than ghostscript to print monochrome PostScript.
266 ;; To print non-monochrome PostScript file, the efficiency of ghostscript
267 ;; is similar to gsprint.
269 ;; Also the gsprint utility comes together with gsview distribution.
271 ;; For more information about gsprint see
272 ;; `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
274 ;; As an example of gsprint declaration:
276 ;; (setq pr-ps-printer-alist
277 ;; '((A "gsprint" ("-all" "-twoup") "-printer " "my-b/w-printer-name")
278 ;; (B "gsprint" ("-all" "-twoup") nil "-printer my-b/w-printer-name")
279 ;; ;; some other printer declaration
280 ;; ))
282 ;; The example above declares that printer A prints all pages (-all) and two
283 ;; pages per sheet (-twoup). The printer B declaration does the same as the
284 ;; printer A declaration, the only difference is the printer name selection.
286 ;; There are other command line options like:
288 ;; -mono Render in monochrome as 1bit/pixel (only black and white).
289 ;; -grey Render in greyscale as 8bits/pixel.
290 ;; -color Render in color as 24bits/pixel.
292 ;; The default is `-mono'. So, printer A and B in the example above are
293 ;; using implicitly the `-mono' option. Note that in `-mono' no gray tone
294 ;; or color is printed, this includes the zebra stripes, that is, in `-mono'
295 ;; the zebra stripes are not printed.
297 ;; See also documentation for `pr-ps-printer-alist'.
300 ;; Using `printing'
301 ;; ----------------
303 ;; To use `printing' insert in your ~/.emacs file (or c:/_emacs, if you're
304 ;; using Windows 9x/NT or MS-DOS):
306 ;; (require 'printing)
307 ;; ;; ...some user settings...
308 ;; (pr-update-menus t)
310 ;; During `pr-update-menus' evaluation:
311 ;; * On Emacs 20:
312 ;; it replaces the Tools/Print menu by Tools/Printing menu.
313 ;; * On Emacs 21:
314 ;; it replaces the File/Print* menu entries by File/Print menu.
315 ;; Please, see section Menu Layout below for menu explanation.
317 ;; To use `printing' utilities you can use the Printing menu options, type M-x
318 ;; followed by one of the commands below, or type a key associated with the
319 ;; command you want (if there is a key binding).
321 ;; `printing' has the following commands:
323 ;; pr-interface
324 ;; pr-ps-directory-preview
325 ;; pr-ps-directory-using-ghostscript
326 ;; pr-ps-directory-print
327 ;; pr-ps-directory-ps-print
328 ;; pr-ps-buffer-preview
329 ;; pr-ps-buffer-using-ghostscript
330 ;; pr-ps-buffer-print
331 ;; pr-ps-buffer-ps-print
332 ;; pr-ps-region-preview
333 ;; pr-ps-region-using-ghostscript
334 ;; pr-ps-region-print
335 ;; pr-ps-region-ps-print
336 ;; pr-ps-mode-preview
337 ;; pr-ps-mode-using-ghostscript
338 ;; pr-ps-mode-print
339 ;; pr-ps-mode-ps-print
340 ;; pr-ps-file-preview
341 ;; pr-ps-file-up-preview
342 ;; pr-ps-file-using-ghostscript
343 ;; pr-ps-file-print
344 ;; pr-ps-file-ps-print
345 ;; pr-ps-file-up-ps-print
346 ;; pr-ps-fast-fire
347 ;; pr-despool-preview
348 ;; pr-despool-using-ghostscript
349 ;; pr-despool-print
350 ;; pr-despool-ps-print
351 ;; pr-printify-directory
352 ;; pr-printify-buffer
353 ;; pr-printify-region
354 ;; pr-txt-directory
355 ;; pr-txt-buffer
356 ;; pr-txt-region
357 ;; pr-txt-mode
358 ;; pr-txt-fast-fire
359 ;; pr-toggle-file-duplex
360 ;; pr-toggle-file-tumble
361 ;; pr-toggle-file-landscape
362 ;; pr-toggle-ghostscript
363 ;; pr-toggle-faces
364 ;; pr-toggle-spool
365 ;; pr-toggle-duplex
366 ;; pr-toggle-tumble
367 ;; pr-toggle-landscape
368 ;; pr-toggle-upside-down
369 ;; pr-toggle-line
370 ;; pr-toggle-zebra
371 ;; pr-toggle-header
372 ;; pr-toggle-lock
373 ;; pr-toggle-region
374 ;; pr-toggle-mode
375 ;; pr-customize
376 ;; lpr-customize
377 ;; pr-help
378 ;; pr-ps-name
379 ;; pr-txt-name
380 ;; pr-ps-utility
381 ;; pr-show-ps-setup
382 ;; pr-show-pr-setup
383 ;; pr-show-lpr-setup
385 ;; The general meanings of above commands are:
387 ;; PREFIX:
388 ;; `pr-interface' buffer interface for printing package.
389 ;; `pr-help' help for printing package.
390 ;; `pr-ps-name' interactively select a PostScript printer.
391 ;; `pr-txt-name' interactively select a text printer.
392 ;; `pr-ps-utility' interactively select a PostScript utility.
393 ;; `pr-show-*-setup' show current settings.
394 ;; `pr-ps-*' deal with PostScript code generation.
395 ;; `pr-txt-*' deal with text generation.
396 ;; `pr-toggle-*' toggle on/off some boolean variable.
397 ;; `pr-despool-*' despool the PostScript spooling buffer.
398 ;; `pr-printify-*' replace nonprintable ASCII by printable ASCII
399 ;; representation.
401 ;; SUFFIX:
402 ;; `*-customize' customization.
403 ;; `*-preview' preview a PostScript file.
404 ;; `*-using-ghostscript' use ghostscript to print.
405 ;; `*-fast-fire' fast fire command (see it for documentation).
406 ;; `*-print' send PostScript directly to printer.
407 ;; `*-ps-print' send PostScript directly to printer or use
408 ;; ghostscript to print. It depends on
409 ;; `pr-print-using-ghostscript' option.
411 ;; INFIX/SUFFIX:
412 ;; `*-directory*' process a directory.
413 ;; `*-buffer*' process a buffer.
414 ;; `*-region*' process a region.
415 ;; `*-mode*' process a major mode (see explanation below).
416 ;; `*-file-*' process a PostScript file.
417 ;; `*-file-up-*' process a PostScript file using a filter utility.
419 ;; Here are some examples:
421 ;; `pr-ps-buffer-using-ghostscript'
422 ;; Use ghostscript to print a buffer.
424 ;; `pr-ps-file-print'
425 ;; Print a PostScript file.
427 ;; `pr-toggle-spool'
428 ;; Toggle spooling buffer.
430 ;; So you can preview through ghostview, use ghostscript to print (if you don't
431 ;; have a PostScript printer) or send directly to printer a PostScript code
432 ;; generated by `ps-print' package.
434 ;; Besides operating one buffer or region each time, you also can postpone
435 ;; previewing or printing by saving the PostScript code generated in a
436 ;; temporary Emacs buffer. This way you can save banner pages between
437 ;; successive printing. You can toggle on/off spooling by invoking
438 ;; `pr-toggle-spool' interactively or through menu bar.
440 ;; If you type, for example:
442 ;; C-u M-x pr-ps-buffer-print RET
444 ;; The `pr-ps-buffer-print' command prompts you for a n-up printing number and
445 ;; a file name, and save the PostScript code generated to the file name instead
446 ;; of sending to printer.
448 ;; This behavior is similar with the commands that deal with PostScript code
449 ;; generation, that is, with `pr-ps-*' and `pr-despool-*' commands. If
450 ;; spooling is on, only `pr-despool-*' commands prompt for a file name and save
451 ;; the PostScript code spooled in this file.
453 ;; Besides the behavior described above, the `*-directory*' commands also
454 ;; prompt for a directory and a file name regexp. So, it's possible to process
455 ;; all or certain files on a directory at once (see also documentation for
456 ;; `pr-list-directory').
458 ;; `printing' has also a special way to handle some major mode through
459 ;; `*-mode*' commands. So it's possible to customize a major mode printing,
460 ;; it's only needed to declare the customization in `pr-mode-alist' (see
461 ;; section Options) and invoke some of `*-mode*' commands. An example for
462 ;; major mode usage is when you're using gnus (or mh, or rmail, etc.) and
463 ;; you're in the *Summary* buffer, if you forget to switch to the *Article*
464 ;; buffer before printing, you'll get a nicely formatted list of article
465 ;; subjects shows up at the printer. With major mode printing you don't need
466 ;; to switch from gnus *Summary* buffer first.
468 ;; Current global keyboard mapping for GNU Emacs is:
470 ;; (global-set-key [print] 'pr-ps-fast-fire)
471 ;; (global-set-key [M-print] 'pr-ps-mode-using-ghostscript)
472 ;; (global-set-key [S-print] 'pr-ps-mode-using-ghostscript)
473 ;; (global-set-key [C-print] 'pr-txt-fast-fire)
474 ;; (global-set-key [C-M-print] 'pr-txt-fast-fire)
476 ;; And for XEmacs is:
478 ;; (global-set-key 'f22 'pr-ps-fast-fire)
479 ;; (global-set-key '(meta f22) 'pr-ps-mode-using-ghostscript)
480 ;; (global-set-key '(shift f22) 'pr-ps-mode-using-ghostscript)
481 ;; (global-set-key '(control f22) 'pr-txt-fast-fire)
482 ;; (global-set-key '(control meta f22) 'pr-txt-fast-fire)
484 ;; As a suggestion of global keyboard mapping for some `printing' commands:
486 ;; (global-set-key "\C-ci" 'pr-interface)
487 ;; (global-set-key "\C-cbp" 'pr-ps-buffer-print)
488 ;; (global-set-key "\C-cbx" 'pr-ps-buffer-preview)
489 ;; (global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
490 ;; (global-set-key "\C-crp" 'pr-ps-region-print)
491 ;; (global-set-key "\C-crx" 'pr-ps-region-preview)
492 ;; (global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
495 ;; Options
496 ;; -------
498 ;; Below it's shown a brief description of `printing' options, please, see the
499 ;; options declaration in the code for a long documentation.
501 ;; `pr-path-style' Specify which path style to use for external
502 ;; commands.
504 ;; `pr-path-alist' Specify an alist for command paths.
506 ;; `pr-txt-name' Specify a printer for printing a text file.
508 ;; `pr-txt-printer-alist' Specify an alist of all text printers.
510 ;; `pr-ps-name' Specify a printer for printing a PostScript
511 ;; file.
513 ;; `pr-ps-printer-alist' Specify an alist for all PostScript printers.
515 ;; `pr-temp-dir' Specify a directory for temporary files during
516 ;; printing.
518 ;; `pr-ps-temp-file' Specify PostScript temporary file name prefix.
520 ;; `pr-file-modes' Specify the file permission bits for newly
521 ;; created files.
523 ;; `pr-gv-command' Specify path and name of the gsview/gv
524 ;; utility.
526 ;; `pr-gs-command' Specify path and name of the ghostscript
527 ;; utility.
529 ;; `pr-gs-switches' Specify ghostscript switches.
531 ;; `pr-gs-device' Specify ghostscript device switch value.
533 ;; `pr-gs-resolution' Specify ghostscript resolution switch value.
535 ;; `pr-print-using-ghostscript' Non-nil means print using ghostscript.
537 ;; `pr-faces-p' Non-nil means print with face attributes.
539 ;; `pr-spool-p' Non-nil means spool printing in a buffer.
541 ;; `pr-file-landscape' Non-nil means print PostScript file in
542 ;; landscape orientation.
544 ;; `pr-file-duplex' Non-nil means print PostScript file in duplex
545 ;; mode.
547 ;; `pr-file-tumble' Non-nil means print PostScript file in tumble
548 ;; mode.
550 ;; `pr-auto-region' Non-nil means region is automagically detected.
552 ;; `pr-auto-mode' Non-nil means major-mode specific printing is
553 ;; prefered over normal printing.
555 ;; `pr-mode-alist' Specify an alist for a major-mode and printing
556 ;; function.
558 ;; `pr-ps-utility' Specify PostScript utility processing.
560 ;; `pr-ps-utility-alist' Specify an alist for PostScript utility
561 ;; processing.
563 ;; `pr-menu-lock' Non-nil means menu is locked while selecting
564 ;; toggle options.
566 ;; `pr-menu-char-height' Specify menu char height in pixels.
568 ;; `pr-menu-char-width' Specify menu char width in pixels.
570 ;; `pr-setting-database' Specify an alist for settings in general.
572 ;; `pr-visible-entry-list' Specify a list of Printing menu visible
573 ;; entries.
575 ;; `pr-delete-temp-file' Non-nil means delete temporary files.
577 ;; `pr-list-directory' Non-nil means list directory when processing a
578 ;; directory.
580 ;; `pr-buffer-name' Specify the name of the buffer interface for
581 ;; printing package.
583 ;; `pr-buffer-name-ignore' Specify a regexp list for buffer names to be
584 ;; ignored in interface buffer.
586 ;; `pr-buffer-verbose' Non-nil means to be verbose when editing a
587 ;; field in interface buffer.
589 ;; To set the above options you may:
591 ;; a) insert the code in your ~/.emacs, like:
593 ;; (setq pr-faces-p t)
595 ;; This way always keep your default settings when you enter a new Emacs
596 ;; session.
598 ;; b) or use `set-variable' in your Emacs session, like:
600 ;; M-x set-variable RET pr-faces-p RET t RET
602 ;; This way keep your settings only during the current Emacs session.
604 ;; c) or use customization, for example:
605 ;; click on menu-bar *Help* option,
606 ;; then click on *Customize*,
607 ;; then click on *Browse Customization Groups*,
608 ;; expand *PostScript* group,
609 ;; expand *Printing* group
610 ;; and then customize `printing' options.
611 ;; Through this way, you may choose if the settings are kept or not when
612 ;; you leave out the current Emacs session.
614 ;; d) or see the option value:
616 ;; C-h v pr-faces-p RET
618 ;; and click the *customize* hypertext button.
619 ;; Through this way, you may choose if the settings are kept or not when
620 ;; you leave out the current Emacs session.
622 ;; e) or invoke:
624 ;; M-x pr-customize RET
626 ;; and then customize `printing' options.
627 ;; Through this way, you may choose if the settings are kept or not when
628 ;; you leave out the current Emacs session.
630 ;; f) or use menu bar, for example:
631 ;; click on menu-bar *File* option,
632 ;; then click on *Printing*,
633 ;; then click on *Customize*,
634 ;; then click on *printing*
635 ;; and then customize `printing' options.
636 ;; Through this way, you may choose if the settings are kept or not when
637 ;; you leave out the current Emacs session.
640 ;; Menu Layout
641 ;; -----------
643 ;; The `printing' menu (Tools/Printing or File/Print) has the following layout:
645 ;; +-----------------------------+
646 ;; A 0 | Printing Interface |
647 ;; +-----------------------------+ +-A---------+ +-B------+
648 ;; I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
649 ;; 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
650 ;; 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
651 ;; +-----------------------------+ |Mode >|-- B |Other...|
652 ;; II 4 | Printify >|-----\ |File >|--\ +--------+
653 ;; 5 | Print >|---\ | |Despool... | |
654 ;; 6 | Text Printer: name >|-\ | | +-----------+ |
655 ;; +-----------------------------+ | | | +---------+ +------------+
656 ;; III 7 |[ ]Landscape | | | \-|Directory| | No Prep... | Ia
657 ;; 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
658 ;; 9 |[ ]Print Header Frame | | | |Region | | name >|- C
659 ;; 10 |[ ]Line Number | | | +---------+ +------------+
660 ;; 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
661 ;; 12 |[ ]Duplex | | \---|Directory| | 2-up... |
662 ;; 13 |[ ]Tumble | \--\ |Buffer | | 4-up... |
663 ;; 14 |[ ]Upside-Down | | |Region | | Other... |
664 ;; 15 | Print All Pages >|--\ | |Mode | +------------+
665 ;; +-----------------------------+ | | +---------+ |[ ]Landscape| Id
666 ;; IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
667 ;; 17 |[ ]Print with faces | | \--|( )name A| |[ ]Tumble | If
668 ;; 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
669 ;; +-----------------------------+ | |... |
670 ;; V 19 |[ ]Auto Region | | |(*)name |
671 ;; 20 |[ ]Auto Mode | | |... |
672 ;; 21 |[ ]Menu Lock | | +---------+ +--------------+
673 ;; +-----------------------------+ \------------------|(*)All Pages |
674 ;; VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
675 ;; 23 | Show Settings >|-------|printing| |( )Odd Pages |
676 ;; 24 | Help | |ps-print| |( )Even Sheets|
677 ;; +-----------------------------+ |lpr | |( )Odd Sheets |
678 ;; +--------+ +--------------+
680 ;; See `pr-visible-entry-list' for hiding some parts of the menu.
682 ;; The menu has the following sections:
684 ;; A. Interface:
686 ;; 0. You can use a buffer interface instead of menus. It looks like the
687 ;; customization buffer. Basically, it has the same options found in the
688 ;; menu and some extra options, all this on a buffer.
690 ;; I. PostScript printing:
692 ;; 1. You can generate a PostScript file (if you type C-u before activating
693 ;; menu) or PostScript temporary file for a directory, a buffer, a region
694 ;; or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
695 ;; after file generation, ghostview is activated using the file generated
696 ;; as argument. This option is disabled if spooling is on (option 16).
697 ;; Also, if you already have a PostScript file you can preview it.
698 ;; Instead of previewing each buffer, region or major mode at once, you
699 ;; can save temporarily the PostScript code generated in a buffer and
700 ;; preview it later. The option `Despool...' despools the PostScript
701 ;; spooling buffer in a temporary file and uses ghostview to preview it.
702 ;; If you type C-u before choosing this option, the PostScript code
703 ;; generated is saved in a file instead of saving in a temporary file.
704 ;; To spool the PostScript code generated you need to turn on the option
705 ;; 16. The option `Despool...' is enabled if spooling is on (option
706 ;; 16).
708 ;; NOTE 1: It's possible to customize a major mode printing, just declare
709 ;; the customization in `pr-mode-alist' and invoke some of
710 ;; `*-mode*' commands or select Mode option in Printing menu. An
711 ;; example for major mode usage is when you're using gnus (or mh,
712 ;; or rmail, etc.) and you're in the *Summary* buffer, if you
713 ;; forget to switch to the *Article* buffer before printing,
714 ;; you'll get a nicely formatted list of article subjects shows
715 ;; up at the printer. With major mode printing you don't need to
716 ;; switch from gnus *Summary* buffer first.
718 ;; NOTE 2: There are the following options for PostScript file
719 ;; processing:
720 ;; Ia. Print the file *No Preprocessing*, that is, send it
721 ;; directly to PostScript printer.
722 ;; Ib. PostScript utility processing selection.
723 ;; See `pr-ps-utility-alist' and `pr-setting-database' for
724 ;; documentation.
725 ;; Ic. Do n-up processing before printing.
726 ;; Id. Toggle on/off landscape for PostScript file processing.
727 ;; Ie. Toggle on/off duplex for PostScript file processing.
728 ;; If. Toggle on/off tumble for PostScript file processing.
730 ;; NOTE 3: Don't forget to download and install the utilities declared on
731 ;; `pr-ps-utility-alist'.
733 ;; 2. Operate the same way as option 1, but it sends directly the PostScript
734 ;; code (or put in a file, if you've typed C-u) or it uses ghostscript to
735 ;; print the PostScript file generated. It depends on option 18, if it's
736 ;; turned on, it uses ghostscript; otherwise, it sends directly to
737 ;; printer. If spooling is on (option 16), the PostScript code is saved
738 ;; temporarily in a buffer instead of printing it or saving it in a file.
739 ;; Also, if you already have a PostScript file you can print it. Instead
740 ;; of printing each buffer, region or major mode at once, you can save
741 ;; temporarily the PostScript code generated in a buffer and print it
742 ;; later. The option `Despool...' despools the PostScript spooling
743 ;; buffer directly on a printer. If you type C-u before choosing this
744 ;; option, the PostScript code generated is saved in a file instead of
745 ;; sending to printer. To spool the PostScript code generated you need
746 ;; to turn on the option 16. This option is enabled if spooling is on
747 ;; (option 16). See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
749 ;; 3. You can select a new PostScript printer to send PostScript code
750 ;; generated. For selection it's used all PostScript printers defined
751 ;; in `pr-ps-printer-alist' variable (see it for documentation).
752 ;; See also `pr-setting-database'.
754 ;; II. Text printing:
756 ;; 4. If you have control characters (character code from \000 to \037) in a
757 ;; buffer and you want to print them in a text printer, select this
758 ;; option. All control characters in your buffer or region will be
759 ;; replaced by a printable representation. The printable representations
760 ;; use ^ (for ASCII control characters) or hex. The characters tab,
761 ;; linefeed, space, return and formfeed are not affected. You don't need
762 ;; to select this option if you use any option of section I, the
763 ;; PostScript engine treats control characters properly.
765 ;; 5. If you want to print a directory, buffer, region or major mode in a
766 ;; text printer, select this option. See also the NOTE 1 on option 1.
768 ;; 6. You can select a new text printer to send text generated. For
769 ;; selection it's used all text printers defined in
770 ;; `pr-txt-printer-alist' variable (see it for documentation).
771 ;; See also `pr-setting-database'.
773 ;; III. PostScript page toggle options:
775 ;; 7. If you want a PostScript landscape printing, turn on this option.
777 ;; 8. If you want to have a header in each page in your PostScript code,
778 ;; turn on this option.
780 ;; 9. If you want to draw a gaudy frame around the header, turn on this
781 ;; option. This option is enabled if print header is on (option 8).
783 ;; 10. If you want that the line number is printed in your PostScript code,
784 ;; turn on this option.
786 ;; 11. If you want background zebra stripes in your PostScript code, turn on
787 ;; this option.
789 ;; 12. If you want a duplex printing and your PostScript printer has this
790 ;; feature, turn on this option.
792 ;; 13. If you turned on duplex printing, you can choose if you want to have
793 ;; a printing suitable for binding on the left or right (tumble off), or
794 ;; to have a printing suitable for binding at top or bottom (tumble on).
795 ;; This option is enabled if duplex is on (option 12).
797 ;; 14. If you want a PostScript upside-down printing, turn on this option.
799 ;; 15. With this option, you can choose if you want to print all pages, odd
800 ;; pages, even pages, odd sheets or even sheets.
801 ;; See also `ps-even-or-odd-pages'.
803 ;; IV. PostScript processing toggle options:
805 ;; 16. If you want to spool the PostScript code generated, turn on this
806 ;; option. To spool the PostScript code generated use option 2. You
807 ;; can despool later by choosing option 1 or 2, sub-option `Despool...'.
809 ;; 17. If you use colors in your buffers and want to see these colors on
810 ;; your PostScript code generated, turn on this option. If you have a
811 ;; black/white PostScript printer, these colors are displayed in gray
812 ;; scale by PostScript printer interpreter.
814 ;; 18. If you don't have a PostScript printer to send PostScript files, turn
815 ;; on this option. When this option is on, the ghostscript is used to
816 ;; print PostScript files. In GNU or Unix system, if ghostscript is set
817 ;; as a PostScript filter, you don't need to turn on this option.
819 ;; V. Printing customization:
821 ;; 19. If you want that region is automagically detected, turn on this
822 ;; option. Note that this will only work if you're using transient mark
823 ;; mode. When this option is on, the `*-buffer*' commands will behave
824 ;; like `*-region*' commands, that is, `*-buffer*' commands will print
825 ;; only the region marked instead of all buffer.
827 ;; 20. Turn this option on if you want that when current major-mode is
828 ;; declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
829 ;; behave like `*-mode*' commands.
831 ;; 21. If you want that Printing menu stays open while you are setting
832 ;; toggle options, turn on this option. The variables
833 ;; `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
834 ;; menu position, so don't forget to adjust these variables if menu
835 ;; position is not ok.
837 ;; VI. Customization:
839 ;; 22. Besides all options in section III, IV and V, you can customize much
840 ;; more PostScript options in `ps-print' option. Or you can customize
841 ;; some `lpr' options for text printing. Or customize `printing'
842 ;; options.
844 ;; 23. Show current settings for `printing', `ps-print' or `lpr'.
846 ;; 24. Quick help for printing menu layout.
849 ;; Option Settings
850 ;; ---------------
852 ;; Below it's shown only the main options that affect all `printing' package.
853 ;; Check all the settings below *BEFORE* running `printing' commands.
855 ;; * Example of setting for GNU or Unix system:
857 ;; (require 'printing)
858 ;; (setq pr-path-alist
859 ;; '((unix "." "~/bin" ghostview mpage PATH)
860 ;; (ghostview "$HOME/bin/gsview-dir")
861 ;; (mpage "$HOME/bin/mpage-dir")
862 ;; ))
863 ;; (setq pr-txt-name 'prt_06a)
864 ;; (setq pr-txt-printer-alist
865 ;; '((prt_06a "lpr" nil "prt_06a")
866 ;; (prt_07c nil nil "prt_07c")
867 ;; ))
868 ;; (setq pr-ps-name 'lps_06b)
869 ;; (setq pr-ps-printer-alist
870 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
871 ;; (lps_07c "lpr" nil nil "lps_07c")
872 ;; (lps_08c nil nil nil "lps_08c")
873 ;; ))
874 ;; (setq pr-temp-dir "/tmp/")
875 ;; (setq pr-gv-command "gv")
876 ;; (setq pr-gs-command "gs")
877 ;; (setq pr-gs-switches '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
878 ;; (setq pr-gs-device "uniprint")
879 ;; (setq pr-gs-resolution 300)
880 ;; (setq pr-ps-utility 'mpage)
881 ;; (setq pr-ps-utility-alist
882 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
883 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
884 ;; (inherits-from: . no-duplex))
885 ;; ))
886 ;; (setq pr-setting-database
887 ;; '((no-duplex
888 ;; nil nil nil
889 ;; (pr-file-duplex . nil)
890 ;; (pr-file-tumble . nil))
891 ;; ))
892 ;; (pr-update-menus t) ; update now printer and utility menus
894 ;; * Example of setting for Windows system:
896 ;; (require 'printing)
897 ;; (setq pr-path-alist
898 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
899 ;; (ghostview "c:/gs/gsview-dir")
900 ;; (mpage "c:/mpage-dir")
901 ;; ))
902 ;; (setq pr-txt-name 'prt_06a)
903 ;; (setq pr-txt-printer-alist
904 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
905 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
906 ;; (PRN "" nil "PRN")
907 ;; (standard "redpr.exe" nil "")
908 ;; ))
909 ;; (setq pr-ps-name 'lps_06b)
910 ;; (setq pr-ps-printer-alist
911 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
912 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
913 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
914 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
915 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
916 ;; (LPT1 "" nil "" "LPT1:")
917 ;; (PRN "" nil "" "PRN")
918 ;; (standard "redpr.exe" nil "" "")
919 ;; ))
920 ;; (setq pr-temp-dir "C:/WINDOWS/TEMP/")
921 ;; (setq pr-gv-command "c:/gs/gsview/gsview32.exe")
922 ;; (setq pr-gs-command "c:/gs/gswin32.exe")
923 ;; (setq pr-gs-switches '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts"))
924 ;; (setq pr-gs-device "mswinpr2")
925 ;; (setq pr-gs-resolution 300)
926 ;; (setq pr-ps-utility 'psnup)
927 ;; (setq pr-ps-utility-alist
928 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " "
929 ;; nil (inherits-from: . no-duplex))
930 ;; ))
931 ;; (setq pr-setting-database
932 ;; '((no-duplex
933 ;; nil nil nil
934 ;; (pr-file-duplex . nil)
935 ;; (pr-file-tumble . nil))
936 ;; ))
937 ;; (pr-update-menus t) ; update now printer and utility menus
939 ;; NOTE: Don't forget to download and install the utilities declared on
940 ;; `pr-ps-utility-alist'.
943 ;; Utilities
944 ;; ---------
946 ;; `printing' package has the following utilities:
948 ;; `pr-setup' Return the current `printing' setup.
950 ;; `lpr-setup' Return the current `lpr' setup.
952 ;; `pr-update-menus' Update utility, PostScript and text printer menus.
954 ;; `pr-menu-bind' Install `printing' menu in the menubar.
957 ;; Below are some URL where you can find good utilities.
959 ;; * For `printing' package:
961 ;; printing `http://www.cpqd.com.br/~vinicius/emacs/printing.el.gz'
962 ;; ps-print `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'
964 ;; * For GNU or Unix system:
966 ;; gs, gv `http://www.gnu.org/software/ghostscript/ghostscript.html'
967 ;; enscript `http://people.ssh.fi/mtr/genscript/'
968 ;; psnup `http://www.knackered.org/angus/psutils/'
969 ;; mpage `http://www.mesa.nl/pub/mpage/'
971 ;; * For Windows system:
973 ;; gswin32, gsview32
974 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'
975 ;; gsprint `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
976 ;; enscript `http://people.ssh.fi/mtr/genscript/'
977 ;; psnup `http://gnuwin32.sourceforge.net/packages/psutils.htm'
978 ;; redmon `http://www.cs.wisc.edu/~ghost/redmon/'
981 ;; Acknowledgments
982 ;; ---------------
984 ;; Thanks to Stefan Monnier <monnier@iro.umontreal.ca> for GNU Emacs and XEmacs
985 ;; printing menu (in `pr-menu-spec') merging suggestion.
987 ;; Thanks to Lennart Borgman <lennart.borgman.073@student.lu.se> for gsprint
988 ;; suggestion (see tip 5 in section Tips).
990 ;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions:
991 ;; - directory processing.
992 ;; - `pr-path-alist' variable.
993 ;; - doc fix.
994 ;; - a lot of tests on Windows.
996 ;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests.
998 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging
999 ;; and for suggestions:
1000 ;; - even/odd pages printing.
1001 ;; - ghostscript parameters for `pr-ps-printer-alist'.
1002 ;; - default printer name.
1003 ;; - completion functions.
1004 ;; - automagic region detection.
1005 ;; - menu entry hiding.
1006 ;; - fast fire PostScript printing command.
1007 ;; - `pr-path-style' variable.
1009 ;; Thanks to Kim F. Storm <storm@filanet.dk> for beta-test and for suggestions:
1010 ;; - PostScript Print and PostScript Print Preview merge.
1011 ;; - Tools/Printing menu.
1012 ;; - replace *-using-preview by *-using-ghostscript.
1013 ;; - printer selection.
1014 ;; - extra parameters for `pr-ps-printer-alist'.
1016 ;; Thanks to:
1017 ;; Frederic Corne <frederic.corne@erli.fr> print-nt.el
1018 ;; Tom Vogels <tov@ece.cmu.edu> mh-e-init.el
1019 ;; Matthew O. Persico <mpersico@erols.com> win32-ps-print.el
1020 ;; Volker Franz <volker.franz@tuebingen.mpg.de> ps-print-interface.el
1021 ;; And to all people who contributed with them.
1024 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1026 ;;; Code:
1029 (require 'lpr)
1030 (require 'ps-print)
1033 (and (string< ps-print-version "6.6.4")
1034 (error "`printing' requires `ps-print' package version 6.6.4 or later"))
1037 (defconst pr-cygwin-system
1038 (and ps-windows-system (getenv "OSTYPE")
1039 (string-match "cygwin" (getenv "OSTYPE"))))
1042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1043 ;; To avoid compilation gripes
1046 (or (fboundp 'subst-char-in-string) ; hacked from subr.el
1047 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1048 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1049 Unless optional argument INPLACE is non-nil, return a new string."
1050 (let ((i (length string))
1051 (newstr (if inplace string (copy-sequence string))))
1052 (while (> (setq i (1- i)) 0)
1053 (if (eq (aref newstr i) fromchar)
1054 (aset newstr i tochar)))
1055 newstr)))
1058 (or (fboundp 'make-temp-file) ; hacked from subr.el
1059 (defun make-temp-file (prefix &optional dir-flag suffix)
1060 "Create a temporary file.
1061 The returned file name (created by appending some random characters at the end
1062 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1063 is guaranteed to point to a newly created empty file.
1064 You can then use `write-region' to write new data into the file.
1066 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1068 If SUFFIX is non-nil, add that at the end of the file name."
1069 (let ((umask (default-file-modes))
1070 file)
1071 (unwind-protect
1072 (progn
1073 ;; Create temp files with strict access rights. It's easy to
1074 ;; loosen them later, whereas it's impossible to close the
1075 ;; time-window of loose permissions otherwise.
1076 (set-default-file-modes ?\700)
1077 (while (condition-case ()
1078 (progn
1079 (setq file
1080 (make-temp-name
1081 (expand-file-name prefix temporary-file-directory)))
1082 (if suffix
1083 (setq file (concat file suffix)))
1084 (if dir-flag
1085 (make-directory file)
1086 (write-region "" nil file nil 'silent nil 'excl))
1087 nil)
1088 (file-already-exists t))
1089 ;; the file was somehow created by someone else between
1090 ;; `make-temp-name' and `write-region', let's try again.
1091 nil)
1092 file)
1093 ;; Reset the umask.
1094 (set-default-file-modes umask)))))
1097 ;; GNU Emacs
1098 (defalias 'pr-e-frame-char-height 'frame-char-height)
1099 (defalias 'pr-e-frame-char-width 'frame-char-width)
1100 (defalias 'pr-e-mouse-pixel-position 'mouse-pixel-position)
1101 ;; XEmacs
1102 (defalias 'pr-x-add-submenu 'add-submenu)
1103 (defalias 'pr-x-event-function 'event-function)
1104 (defalias 'pr-x-event-object 'event-object)
1105 (defalias 'pr-x-find-menu-item 'find-menu-item)
1106 (defalias 'pr-x-font-height 'font-height)
1107 (defalias 'pr-x-font-width 'font-width)
1108 (defalias 'pr-x-get-popup-menu-response 'get-popup-menu-response)
1109 (defalias 'pr-x-make-event 'make-event)
1110 (defalias 'pr-x-misc-user-event-p 'misc-user-event-p)
1111 (defalias 'pr-x-relabel-menu-item 'relabel-menu-item)
1112 (defalias 'pr-x-event-x-pixel 'event-x-pixel)
1113 (defalias 'pr-x-event-y-pixel 'event-y-pixel)
1115 (cond
1116 ((featurep 'xemacs) ; XEmacs
1117 (defvar current-menubar nil)
1118 (defvar current-mouse-event nil)
1119 (defvar zmacs-region-stays nil)
1120 (defalias 'pr-f-set-keymap-parents 'set-keymap-parents)
1121 (defalias 'pr-f-set-keymap-name 'set-keymap-name)
1122 (defun pr-f-read-string (prompt initial history default)
1123 (let ((str (read-string prompt initial)))
1124 (if (and str (not (string= str "")))
1126 default)))
1127 (defun pr-keep-region-active ()
1128 (setq zmacs-region-stays t)))
1130 (t ; GNU Emacs
1131 (defvar deactivate-mark nil)
1132 (defalias 'pr-f-set-keymap-parents 'set-keymap-parent)
1133 (defalias 'pr-f-set-keymap-name 'ignore)
1134 (defalias 'pr-f-read-string 'read-string)
1135 (defun pr-keep-region-active ()
1136 (setq deactivate-mark nil))))
1139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1140 ;; Customization Functions
1143 (defun pr-alist-custom-set (symbol value)
1144 "Set the value of custom variables for printer & utility selection."
1145 (set symbol value)
1146 (and (featurep 'printing) ; update only after printing is loaded
1147 (pr-update-menus t)))
1150 (defun pr-ps-utility-custom-set (symbol value)
1151 "Update utility menu entry."
1152 (set symbol value)
1153 (and (featurep 'printing) ; update only after printing is loaded
1154 (pr-menu-set-utility-title value)))
1157 (defun pr-ps-name-custom-set (symbol value)
1158 "Update `PostScript Printer:' menu entry."
1159 (set symbol value)
1160 (and (featurep 'printing) ; update only after printing is loaded
1161 (pr-menu-set-ps-title value)))
1164 (defun pr-txt-name-custom-set (symbol value)
1165 "Update `Text Printer:' menu entry."
1166 (set symbol value)
1167 (and (featurep 'printing) ; update only after printing is loaded
1168 (pr-menu-set-txt-title value)))
1171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1172 ;; User Interface (I)
1175 (defgroup printing nil
1176 "Printing Utilities group."
1177 :tag "Printing Utilities"
1178 :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
1179 :prefix "pr-"
1180 :version "20"
1181 :group 'wp
1182 :group 'postscript)
1185 (defcustom pr-path-style
1186 (if (and (not pr-cygwin-system)
1187 ps-windows-system)
1188 'windows
1189 'unix)
1190 "*Specify which path style to use for external commands.
1192 Valid values are:
1194 windows Windows 9x/NT style (\\)
1196 unix Unix style (/)"
1197 :type '(choice :tag "Path style"
1198 (const :tag "Windows 9x/NT Style (\\)" :value windows)
1199 (const :tag "Unix Style (/)" :value unix))
1200 :version "20"
1201 :group 'printing)
1204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1205 ;; Internal Functions (I)
1208 (defun pr-dosify-file-name (path)
1209 "Replace unix-style directory separator character with dos/windows one."
1210 (interactive "sPath: ")
1211 (if (eq pr-path-style 'windows)
1212 (subst-char-in-string ?/ ?\\ path)
1213 path))
1216 (defun pr-unixify-file-name (path)
1217 "Replace dos/windows-style directory separator character with unix one."
1218 (interactive "sPath: ")
1219 (if (eq pr-path-style 'windows)
1220 (subst-char-in-string ?\\ ?/ path)
1221 path))
1224 (defun pr-standard-file-name (path)
1225 "Ensure the proper directory separator depending on the OS.
1226 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
1227 separator; otherwise, ensure unix-style directory separator."
1228 (if (or pr-cygwin-system ps-windows-system)
1229 (subst-char-in-string ?/ ?\\ path)
1230 (subst-char-in-string ?\\ ?/ path)))
1233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1234 ;; User Interface (II)
1237 (defcustom pr-path-alist
1238 '((unix PATH)
1239 (cygwin PATH)
1240 (windows PATH))
1241 "*Specify an alist for command paths.
1243 It's used to find commands used for printing package, like gv, gs, gsview.exe,
1244 mpage, print.exe, etc. See also `pr-command' function.
1246 Each element has the form:
1248 (ENTRY DIRECTORY...)
1250 Where:
1252 ENTRY It's a symbol, used to identify this entry.
1253 There must exist at least one of the following entries:
1255 unix this entry is used when Emacs is running on GNU or
1256 Unix system.
1258 cygwin this entry is used when Emacs is running on Windows
1259 95/98/NT/2000 with Cygwin.
1261 windows this entry is used when Emacs is running on Windows
1262 95/98/NT/2000.
1264 DIRECTORY It should be a string or a symbol. If it's a symbol, it should
1265 exist an equal entry in `pr-path-alist'. If it's a string,
1266 it's considered a directory specification.
1268 The directory specification may contain:
1269 $var environment variable expansion
1270 ~/ tilde expansion
1271 ./ current directory
1272 ../ previous directory
1274 For example, let's say the home directory is /home/my and the
1275 current directory is /home/my/dir, so:
1277 THE ENTRY IS EXPANDED TO
1278 ~/entry /home/my/entry
1279 ./entry /home/my/dir/entry
1280 ../entry /home/my/entry
1281 $HOME/entry /home/my/entry
1282 $HOME/~/other/../my/entry /home/my/entry
1284 SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
1285 list and there isn't a `PATH' entry in `pr-path-alist' or the
1286 `PATH' entry has a null directory list, the PATH environment
1287 variable is used.
1289 Examples:
1291 * On GNU or Unix system:
1293 '((unix \".\" \"~/bin\" ghostview mpage PATH)
1294 (ghostview \"$HOME/bin/gsview-dir\")
1295 (mpage \"$HOME/bin/mpage-dir\")
1298 * On Windows system:
1300 '((windows \"c:/applications/executables\" PATH ghostview mpage)
1301 (ghostview \"c:/gs/gsview-dir\")
1302 (mpage \"c:/mpage-dir\")
1304 :type '(repeat
1305 (cons :tag ""
1306 (symbol :tag "Identifier ")
1307 (repeat :tag "Directory List"
1308 (choice :menu-tag "Directory"
1309 :tag "Directory"
1310 (string :value "")
1311 (symbol :value symbol)))))
1312 :version "20"
1313 :group 'printing)
1316 (defcustom pr-txt-name 'default
1317 "*Specify a printer for printing a text file.
1319 The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
1320 documentation).
1322 This variable should be modified by customization engine. If this variable is
1323 modified by other means (for example, a lisp function), use `pr-update-menus'
1324 function (see it for documentation) to update text printer menu."
1325 :type 'symbol
1326 :set 'pr-txt-name-custom-set
1327 :version "20"
1328 :group 'printing)
1331 (defcustom pr-txt-printer-alist
1332 (list (list 'default lpr-command nil
1333 (cond ((boundp 'printer-name) printer-name)
1334 (ps-windows-system "PRN")
1335 (t nil)
1337 ;; Examples:
1338 ;; * On GNU or Unix system:
1339 ;; '((prt_06a "lpr" nil "prt_06a")
1340 ;; (prt_07c nil nil "prt_07c")
1341 ;; )
1342 ;; * On Windows system:
1343 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
1344 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
1345 ;; (PRN "" nil "PRN")
1346 ;; (standard "redpr.exe" nil "")
1347 ;; )
1348 "*Specify an alist of all text printers (text printer database).
1350 The alist element has the form:
1352 (SYMBOL COMMAND SWITCHES NAME)
1354 Where:
1356 SYMBOL It's a symbol to identify a text printer. It's for
1357 `pr-txt-name' variable setting and for menu selection.
1358 Examples:
1359 'prt_06a
1360 'my_printer
1362 COMMAND Name of the program for printing a text file. On MS-DOS and
1363 MS-Windows systems, if the value is an empty string, then Emacs
1364 will write directly to the printer port given by NAME (see text
1365 below), that is, the NAME should be something like \"PRN\" or
1366 \"LPT1:\".
1367 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1368 COMMAND shouldn't be an empty string.
1369 The programs `print' and `nprint' (the standard print programs
1370 on Windows NT and Novell Netware respectively) are handled
1371 specially, using NAME as the destination for output; any other
1372 program is treated like `lpr' except that an explicit filename
1373 is given as the last argument.
1374 If COMMAND is nil, it's used the default printing program:
1375 `print' for Windows system, `lp' for lp system and `lpr' for
1376 all other systems. See also `pr-path-alist'.
1377 Examples:
1378 \"print\"
1379 \"lpr\"
1380 \"lp\"
1382 SWITCHES List of sexp's to pass as extra options for text printer
1383 program. It is recommended to set NAME (see text below)
1384 instead of including an explicit switch on this list.
1385 Example:
1386 . for lpr
1387 '(\"-#3\" \"-l\")
1390 NAME A string that specifies a text printer name.
1391 On Unix-like systems, a string value should be a name
1392 understood by lpr's -P option (or lp's -d option).
1393 On MS-DOS and MS-Windows systems, it is the name of a printer
1394 device or port. Typical non-default settings would be \"LPT1:\"
1395 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1396 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1397 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1398 printer. You can also set it to a name of a file, in which
1399 case the output gets appended to that file. If you want to
1400 discard the printed output, set this to \"NUL\".
1401 Examples:
1402 . for print.exe
1403 \"/D:\\\\\\\\host\\\\share-name\"
1404 \"LPT1:\"
1405 \"PRN\"
1407 . for lpr or lp
1408 \"share-name\"
1410 This variable should be modified by customization engine. If this variable is
1411 modified by other means (for example, a lisp function), use `pr-update-menus'
1412 function (see it for documentation) to update text printer menu.
1414 Examples:
1416 * On GNU or Unix system:
1418 '((prt_06a \"lpr\" nil \"prt_06a\")
1419 (prt_07c nil nil \"prt_07c\")
1422 * On Windows system:
1424 '((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1425 (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
1426 (PRN \"\" nil \"PRN\")
1427 (standard \"redpr.exe\" nil \"\")
1430 Useful links:
1432 * Information about the print command (print.exe)
1433 `http://www.computerhope.com/printhlp.htm'
1435 * RedMon - Redirection Port Monitor (redpr.exe)
1436 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1438 * Redirection Port Monitor (redpr.exe on-line help)
1439 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1441 * UNIX man pages: lpr (or type `man lpr')
1442 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1443 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1445 * UNIX man pages: lp (or type `man lp')
1446 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1447 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1449 :type '(repeat
1450 (list :tag "Text Printer"
1451 (symbol :tag "Printer Symbol Name")
1452 (string :tag "Printer Command")
1453 (repeat :tag "Printer Switches"
1454 (sexp :tag "Switch" :value ""))
1455 (choice :menu-tag "Printer Name"
1456 :tag "Printer Name"
1457 (const :tag "None" nil)
1458 string)))
1459 :set 'pr-alist-custom-set
1460 :version "20"
1461 :group 'printing)
1464 (defcustom pr-ps-name 'default
1465 "*Specify a printer for printing a PostScript file.
1467 This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
1468 documentation).
1470 This variable should be modified by customization engine. If this variable is
1471 modified by other means (for example, a lisp function), use `pr-update-menus'
1472 function (see it for documentation) to update PostScript printer menu."
1473 :type 'symbol
1474 :set 'pr-ps-name-custom-set
1475 :version "20"
1476 :group 'printing)
1479 (defcustom pr-ps-printer-alist
1480 (list (list 'default lpr-command nil
1481 (cond (ps-windows-system nil)
1482 (ps-lp-system "-d")
1483 (t "-P"))
1484 (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
1485 ;; Examples:
1486 ;; * On GNU or Unix system:
1487 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
1488 ;; (lps_07c "lpr" nil nil "lps_07c")
1489 ;; (lps_08c nil nil nil "lps_08c")
1490 ;; )
1491 ;; * On Windows system:
1492 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
1493 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
1494 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
1495 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
1496 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
1497 ;; (LPT1 "" nil "" "LPT1:")
1498 ;; (PRN "" nil "" "PRN")
1499 ;; (standard "redpr.exe" nil "" "")
1500 ;; )
1501 "*Specify an alist for all PostScript printers (PostScript printer database).
1503 The alist element has the form:
1505 (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
1507 Where:
1509 SYMBOL It's a symbol to identify a PostScript printer. It's for
1510 `pr-ps-name' variable setting and for menu selection.
1511 Examples:
1512 'prt_06a
1513 'my_printer
1515 COMMAND Name of the program for printing a PostScript file. On MS-DOS
1516 and MS-Windows systems, if the value is an empty string then
1517 Emacs will write directly to the printer port given by NAME
1518 (see text below), that is, the NAME should be something like
1519 \"PRN\" or \"LPT1:\".
1520 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1521 COMMAND shouldn't be an empty string.
1522 The programs `print' and `nprint' (the standard print programs
1523 on Windows NT and Novell Netware respectively) are handled
1524 specially, using NAME as the destination for output; any other
1525 program is treated like `lpr' except that an explicit filename
1526 is given as the last argument.
1527 If COMMAND is nil, it's used the default printing program:
1528 `print' for Windows system, `lp' for lp system and `lpr' for
1529 all other systems. See also `pr-path-alist'.
1530 Examples:
1531 \"print\"
1532 \"lpr\"
1533 \"lp\"
1534 \"cp\"
1535 \"gsprint\"
1537 SWITCHES List of sexp's to pass as extra options for PostScript printer
1538 program. It is recommended to set NAME (see text below)
1539 instead of including an explicit switch on this list.
1540 Example:
1541 . for lpr
1542 '(\"-#3\" \"-l\")
1545 . for gsprint.exe
1546 '(\"-all\" \"-twoup\")
1548 PRINTER-SWITCH A string that specifies PostScript printer name switch. If
1549 it's necessary to have a space between PRINTER-SWITCH and NAME,
1550 it should be inserted at the end of PRINTER-SWITCH string.
1551 If PRINTER-SWITCH is nil, it's used the default printer name
1552 switch: `/D:' for Windows system, `-d' for lp system and `-P'
1553 for all other systems.
1554 Examples:
1555 . for lpr
1556 \"-P \"
1558 . for lp
1559 \"-d \"
1561 . for print.exe
1562 \"/D:\"
1564 . for gsprint.exe
1565 \"-printer \"
1567 NAME A string that specifies a PostScript printer name.
1568 On Unix-like systems, a string value should be a name
1569 understood by lpr's -P option (or lp's -d option).
1570 On MS-DOS and MS-Windows systems, it is the name of a printer
1571 device or port. Typical non-default settings would be \"LPT1:\"
1572 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1573 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1574 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1575 printer. You can also set it to a name of a file, in which
1576 case the output gets appended to that file. If you want to
1577 discard the printed output, set this to \"NUL\".
1578 Examples:
1579 . for cp.exe
1580 \"\\\\\\\\host\\\\share-name\"
1582 . for print.exe or gsprint.exe
1583 \"/D:\\\\\\\\host\\\\share-name\"
1584 \"\\\\\\\\host\\\\share-name\"
1585 \"LPT1:\"
1586 \"PRN\"
1588 . for lpr or lp
1589 \"share-name\"
1591 DEFAULT It's a way to set default values when this entry is selected.
1592 It's a cons like:
1594 (VARIABLE . VALUE)
1596 That associates VARIABLE with VALUE. when this entry is
1597 selected, it's executed the following command:
1599 (set VARIABLE (eval VALUE))
1601 Note that VALUE can be any valid lisp expression. So, don't
1602 forget to quote symbols and constant lists.
1603 If VARIABLE is the special keyword `inherits-from:', VALUE must
1604 be a symbol name setting defined in `pr-setting-database' from
1605 which the current setting inherits the context. Take care with
1606 circular inheritance.
1607 Examples:
1608 '(ps-landscape-mode . nil)
1609 '(ps-spool-duplex . t)
1610 '(pr-gs-device . (my-gs-device t))
1612 This variable should be modified by customization engine. If this variable is
1613 modified by other means (for example, a lisp function), use `pr-update-menus'
1614 function (see it for documentation) to update PostScript printer menu.
1616 Examples:
1618 * On GNU or Unix system:
1620 '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
1621 (lps_07c \"lpr\" nil nil \"lps_07c\")
1622 (lps_08c nil nil nil \"lps_08c\")
1625 * On Windows system:
1627 '((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
1628 (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
1629 (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
1630 (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
1631 (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
1632 (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
1633 (LPT1 \"\" nil \"\" \"LPT1:\")
1634 (PRN \"\" nil \"\" \"PRN\")
1635 (standard \"redpr.exe\" nil \"\" \"\")
1639 gsprint:
1641 You can use gsprint instead of ghostscript to print monochrome PostScript files
1642 in Windows. The gsprint utility documentation says that it is more efficient
1643 than ghostscript to print monochrome PostScript.
1645 To print non-monochrome PostScript file, the efficiency of ghostscript is
1646 similar to gsprint.
1648 Also the gsprint utility comes together with gsview distribution.
1650 As an example of gsprint declaration:
1652 (setq pr-ps-printer-alist
1653 '((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
1654 (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
1655 ;; some other printer declaration
1658 The example above declares that printer A prints all pages (-all) and two pages
1659 per sheet (-twoup). The printer B declaration does the same as the printer A
1660 declaration, the only difference is the printer name selection.
1662 There are other command line options like:
1664 -mono Render in monochrome as 1bit/pixel (only black and white).
1665 -grey Render in greyscale as 8bits/pixel.
1666 -color Render in color as 24bits/pixel.
1668 The default is `-mono'. So, printer A and B in the example above are using
1669 implicitly the `-mono' option. Note that in `-mono' no gray tone or color is
1670 printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
1671 are not printed.
1674 Useful links:
1676 * GSPRINT - Ghostscript print to Windows printer
1677 `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
1679 * Introduction to Ghostscript
1680 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
1682 * How to use Ghostscript
1683 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
1685 * Information about the print command (print.exe)
1686 `http://www.computerhope.com/printhlp.htm'
1688 * RedMon - Redirection Port Monitor (redpr.exe)
1689 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1691 * Redirection Port Monitor (redpr.exe on-line help)
1692 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1694 * UNIX man pages: lpr (or type `man lpr')
1695 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1696 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1698 * UNIX man pages: lp (or type `man lp')
1699 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1700 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1702 * GNU utilities for Win32 (cp.exe)
1703 `http://unxutils.sourceforge.net/'
1705 :type '(repeat
1706 (list
1707 :tag "PostScript Printer"
1708 (symbol :tag "Printer Symbol Name")
1709 (string :tag "Printer Command")
1710 (repeat :tag "Printer Switches"
1711 (sexp :tag "Switch" :value ""))
1712 (choice :menu-tag "Printer Name Switch"
1713 :tag "Printer Name Switch"
1714 (const :tag "None" nil)
1715 string)
1716 (choice :menu-tag "Printer Name"
1717 :tag "Printer Name"
1718 (const :tag "None" nil)
1719 string)
1720 (repeat
1721 :tag "Default Value List"
1722 :inline t
1723 (cons
1724 :tag ""
1725 (choice
1726 :menu-tag "Variable"
1727 :tag "Variable"
1728 (const :tag "Landscape" ps-landscape-mode)
1729 (const :tag "Print Header" ps-print-header)
1730 (const :tag "Print Header Frame" ps-print-header-frame)
1731 (const :tag "Line Number" ps-line-number)
1732 (const :tag "Zebra Stripes" ps-zebra-stripes)
1733 (const :tag "Duplex" ps-spool-duplex)
1734 (const :tag "Tumble" ps-spool-tumble)
1735 (const :tag "Upside-Down" ps-print-upside-down)
1736 (const :tag "PS File Landscape" pr-file-landscape)
1737 (const :tag "PS File Duplex" pr-file-duplex)
1738 (const :tag "PS File Tumble" pr-file-tumble)
1739 (const :tag "Auto Region" pr-auto-region)
1740 (const :tag "Auto Mode" pr-auto-mode)
1741 (const :tag "Ghostscript Device" pr-gs-device)
1742 (const :tag "Ghostscript Resolution" pr-gs-resolution)
1743 (const :tag "inherits-from:" inherits-from:)
1744 (variable :tag "Other"))
1745 (sexp :tag "Value")))
1747 :set 'pr-alist-custom-set
1748 :version "20"
1749 :group 'printing)
1752 (defcustom pr-temp-dir
1753 (pr-dosify-file-name
1754 (if (boundp 'temporary-file-directory)
1755 (symbol-value 'temporary-file-directory)
1756 ;; hacked from `temporary-file-directory' variable in files.el
1757 (file-name-as-directory
1758 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
1759 (cond (ps-windows-system "c:/temp")
1760 ((memq system-type '(vax-vms axp-vms)) "SYS$SCRATCH:")
1761 (t "/tmp")
1762 )))))
1763 "*Specify a directory for temporary files during printing.
1765 See also `pr-ps-temp-file' and `pr-file-modes'."
1766 :type '(directory :tag "Temporary Directory")
1767 :version "20"
1768 :group 'printing)
1771 (defcustom pr-ps-temp-file "prspool-"
1772 "*Specify PostScript temporary file name prefix.
1774 See also `pr-temp-dir' and `pr-file-modes'."
1775 :type '(file :tag "PostScript Temporary File Name")
1776 :version "21"
1777 :group 'printing)
1780 ;; It uses 0600 as default instead of (default-file-modes).
1781 ;; So, by default, only the session owner have permission to deal with files
1782 ;; generated by `printing'.
1783 (defcustom pr-file-modes ?\600
1784 "*Specify the file permission bits for newly created files.
1786 It should be an integer; only the low 9 bits are used.
1788 See also `pr-temp-dir' and `pr-ps-temp-file'."
1789 :type '(integer :tag "File Permission Bits")
1790 :version "21.3"
1791 :group 'printing)
1794 (defcustom pr-gv-command
1795 (if ps-windows-system
1796 "gsview32.exe"
1797 "gv")
1798 "*Specify path and name of the gsview/gv utility.
1800 See also `pr-path-alist'.
1802 Useful links:
1804 * GNU gv manual
1805 `http://www.gnu.org/software/gv/manual/gv.html'
1807 * GSview Help
1808 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'
1810 * GSview Help - Common Problems
1811 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'
1813 * GSview Readme (compilation & installation)
1814 `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'
1816 * GSview (main site)
1817 `http://www.cs.wisc.edu/~ghost/gsview/index.htm'
1819 * Ghostscript, Ghostview and GSview
1820 `http://www.cs.wisc.edu/~ghost/'
1822 * Ghostview
1823 `http://www.cs.wisc.edu/~ghost/gv/index.htm'
1825 * gv 3.5, June 1997
1826 `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'
1828 * MacGSView (MacOS)
1829 `http://www.cs.wisc.edu/~ghost/macos/index.htm'
1831 :type '(string :tag "Ghostview Utility")
1832 :version "20"
1833 :group 'printing)
1836 (defcustom pr-gs-command
1837 (if ps-windows-system
1838 "gswin32.exe"
1839 "gs")
1840 "*Specify path and name of the ghostscript utility.
1842 See also `pr-path-alist'.
1844 Useful links:
1846 * Ghostscript, Ghostview and GSview
1847 `http://www.cs.wisc.edu/~ghost/'
1849 * Introduction to Ghostscript
1850 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
1852 * How to use Ghostscript
1853 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
1855 * Printer compatibility
1856 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
1858 :type '(string :tag "Ghostscript Utility")
1859 :version "20"
1860 :group 'printing)
1863 (defcustom pr-gs-switches
1864 (if ps-windows-system
1865 '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
1866 '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
1867 "*Specify ghostscript switches. See the documentation on GS for more info.
1869 It's a list of strings, where each string is one or more ghostscript switches.
1871 A note on the gs switches:
1873 -q quiet
1874 -dNOPAUSE don't wait for user intervention
1875 -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
1876 -c quit it's added at the end to terminate gs
1878 To see ghostscript documentation for more information:
1880 * On GNU or Unix system:
1881 - for full documentation, type: man gs
1882 - for brief documentation, type: gs -h
1884 * On Windows system:
1885 - for full documentation, see in a browser the file
1886 c:/gstools/gs5.50/index.html, that is, the file index.html which is
1887 located in the same directory as gswin32.exe.
1888 - for brief documentation, type: gswin32.exe -h
1890 Useful links:
1892 * Introduction to Ghostscript
1893 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
1895 * How to use Ghostscript
1896 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
1898 * Printer compatibility
1899 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
1901 :type '(repeat (string :tag "Ghostscript Switch"))
1902 :version "20"
1903 :group 'printing)
1906 (defcustom pr-gs-device
1907 (if ps-windows-system
1908 "mswinpr2"
1909 "uniprint")
1910 "*Specify the ghostscript device switch value (-sDEVICE=).
1912 A note on the gs switches:
1914 -sDEVICE=djet500 the printer - works with HP DeskJet 540
1916 See `pr-gs-switches' for documentation.
1917 See also `pr-ps-printer-alist'."
1918 :type '(string :tag "Ghostscript Device")
1919 :version "20"
1920 :group 'printing)
1923 (defcustom pr-gs-resolution 300
1924 "*Specify ghostscript resolution switch value (-r).
1926 A note on the gs switches:
1928 -r300 resolution 300x300
1930 See `pr-gs-switches' for documentation.
1931 See also `pr-ps-printer-alist'."
1932 :type '(integer :tag "Ghostscript Resolution")
1933 :version "20"
1934 :group 'printing)
1937 (defcustom pr-print-using-ghostscript nil
1938 "*Non-nil means print using ghostscript.
1940 This is useful if you don't have a PostScript printer, so you could use the
1941 ghostscript to print a PostScript file.
1943 In GNU or Unix system, if ghostscript is set as a PostScript filter, this
1944 variable should be nil."
1945 :type 'boolean
1946 :version "20"
1947 :group 'printing)
1950 (defcustom pr-faces-p nil
1951 "*Non-nil means print with face attributes."
1952 :type 'boolean
1953 :version "20"
1954 :group 'printing)
1957 (defcustom pr-spool-p nil
1958 "*Non-nil means spool printing in a buffer."
1959 :type 'boolean
1960 :version "20"
1961 :group 'printing)
1964 (defcustom pr-file-landscape nil
1965 "*Non-nil means print PostScript file in landscape orientation."
1966 :type 'boolean
1967 :version "20"
1968 :group 'printing)
1971 (defcustom pr-file-duplex nil
1972 "*Non-nil means print PostScript file in duplex mode."
1973 :type 'boolean
1974 :version "20"
1975 :group 'printing)
1978 (defcustom pr-file-tumble nil
1979 "*Non-nil means print PostScript file in tumble mode.
1981 If tumble is off, produces a printing suitable for binding on the left or
1982 right.
1983 If tumble is on, produces a printing suitable for binding at the top or
1984 bottom."
1985 :type 'boolean
1986 :version "20"
1987 :group 'printing)
1990 (defcustom pr-auto-region t
1991 "*Non-nil means region is automagically detected.
1993 Note that this will only work if you're using transient mark mode.
1995 When this variable is non-nil, the `*-buffer*' commands will behave like
1996 `*-region*' commands, that is, `*-buffer*' commands will print only the region
1997 marked instead of all buffer."
1998 :type 'boolean
1999 :version "20"
2000 :group 'printing)
2003 (defcustom pr-auto-mode t
2004 "*Non-nil means major-mode specific printing is prefered over normal printing.
2006 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
2007 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
2008 `*-buffer*' commands will print the current buffer and `*-region*' commands
2009 will print the current region."
2010 :type 'boolean
2011 :version "20"
2012 :group 'printing)
2015 (defcustom pr-mode-alist
2016 '((mh-folder-mode ; mh summary buffer
2017 pr-mh-lpr-1 pr-mh-print-1
2019 (ps-article-author ps-article-subject)
2020 ("/pagenumberstring load" pr-article-date)
2023 (mh-letter-mode ; mh letter buffer
2024 pr-mh-lpr-2 pr-mh-print-2
2026 (ps-article-author ps-article-subject)
2027 ("/pagenumberstring load" pr-article-date)
2030 (rmail-summary-mode ; rmail summary buffer
2031 pr-rmail-lpr pr-rmail-print
2033 (ps-article-subject ps-article-author buffer-name)
2037 (rmail-mode ; rmail buffer
2038 pr-rmail-lpr pr-rmail-print
2040 (ps-article-subject ps-article-author buffer-name)
2044 (gnus-summary-mode ; gnus summary buffer
2045 pr-gnus-lpr pr-gnus-print
2047 (ps-article-subject ps-article-author gnus-newsgroup-name)
2051 (gnus-article-mode ; gnus article buffer
2052 pr-gnus-lpr pr-gnus-print
2054 (ps-article-subject ps-article-author gnus-newsgroup-name)
2058 (Info-mode ; Info buffer
2059 pr-mode-lpr pr-mode-print
2061 (ps-info-node ps-info-file)
2065 (vm-mode ; vm mode
2066 pr-vm-lpr pr-vm-print
2068 (ps-article-subject ps-article-author buffer-name)
2073 "*Specify an alist for a major-mode and printing functions.
2075 To customize a major mode printing, just declare the customization in
2076 `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
2077 mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
2078 *Summary* buffer, if you forget to switch to the *Article* buffer before
2079 printing, you'll get a nicely formatted list of article subjects shows up at
2080 the printer. With major mode printing you don't need to switch from gnus
2081 *Summary* buffer first.
2083 The elements have the following form:
2085 (MAJOR-MODE
2086 LPR-PRINT PS-PRINT
2087 HEADER-LINES
2088 LEFT-HEADER
2089 RIGHT-HEADER
2090 KILL-LOCAL-VARIABLE
2091 DEFAULT...)
2093 Where:
2095 MAJOR-MODE It's the major mode symbol.
2097 LPR-PRINT It's a symbol function for text printing. It's invoked with
2098 one argument:
2099 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2101 Usually LPR-PRINT function prepares the environment or buffer
2102 and then call the function `pr-mode-lpr' which it's used to
2103 process the buffer and send it to text printer.
2105 The `pr-mode-lpr' definition is:
2107 (pr-mode-lpr HEADER-LIST &optional FROM TO)
2109 Where HEADER-LIST is like the argument passed to LPR-PRINT.
2110 FROM and TO are the beginning and end markers, respectively,
2111 for a region. If FROM is nil, it's used (point-min); if TO is
2112 nil, it's used (point-max).
2114 PS-PRINT It's a symbol function for PostScript printing. It's invoked
2115 with 3 arguments: n-up printing, file name and the list:
2116 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2118 Usually PS-PRINT function prepares the environment or buffer
2119 and then call the function `pr-mode-print' which it's used to
2120 process the buffer and send it to PostScript printer.
2122 The `pr-mode-print' definition is:
2124 (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
2126 Where N-UP, FILENAME and HEADER-LIST are like the arguments
2127 passed to PS-PRINT. FROM and TO are the beginning and end
2128 markers, respectively, for a region. If TO is nil, it's used
2129 (point-max).
2131 HEADER-LINES It's the number of header lines; if is nil, it uses
2132 `ps-header-lines' value.
2134 LEFT-HEADER It's the left header part, it's a list of string, variable
2135 symbol or function symbol (with no argument); if is nil, it
2136 uses `ps-left-header' value.
2138 RIGHT-HEADER It's the right header part, it's a list of string, variable
2139 symbol or function symbol (with no argument); if is nil, it
2140 uses `ps-right-header' value.
2142 KILL-LOCAL-VARIABLE
2143 Non-nil means to kill all buffer local variable declared in
2144 DEFAULT (see below).
2146 DEFAULT It's a way to set default values when this entry is selected.
2147 It's a cons like:
2149 (VARIABLE-SYM . VALUE)
2151 That associates VARIABLE-SYM with VALUE. when this entry is
2152 selected, it's executed the following command:
2154 (set (make-local-variable VARIABLE-SYM) (eval VALUE))
2156 Note that VALUE can be any valid lisp expression. So, don't
2157 forget to quote symbols and constant lists.
2158 If VARIABLE is the special keyword `inherits-from:', VALUE must
2159 be a symbol name setting defined in `pr-setting-database' from
2160 which the current setting inherits the context. Take care with
2161 circular inheritance.
2162 Examples:
2163 '(ps-landscape-mode . nil)
2164 '(ps-spool-duplex . t)
2165 '(pr-gs-device . (my-gs-device t))"
2166 :type '(repeat
2167 (list
2168 :tag ""
2169 (symbol :tag "Major Mode")
2170 (function :tag "Text Printing Function")
2171 (function :tag "PS Printing Function")
2172 (choice :menu-tag "Number of Header Lines"
2173 :tag "Number of Header Lines"
2174 (integer :tag "Number")
2175 (const :tag "Default Number" nil))
2176 (repeat :tag "Left Header List"
2177 (choice :menu-tag "Left Header"
2178 :tag "Left Header"
2179 string symbol))
2180 (repeat :tag "Right Header List"
2181 (choice :menu-tag "Right Header"
2182 :tag "Right Header"
2183 string symbol))
2184 (boolean :tag "Kill Local Variable At End")
2185 (repeat
2186 :tag "Default Value List"
2187 :inline t
2188 (cons
2189 :tag ""
2190 (choice
2191 :menu-tag "Variable"
2192 :tag "Variable"
2193 (const :tag "Landscape" ps-landscape-mode)
2194 (const :tag "Print Header" ps-print-header)
2195 (const :tag "Print Header Frame" ps-print-header-frame)
2196 (const :tag "Line Number" ps-line-number)
2197 (const :tag "Zebra Stripes" ps-zebra-stripes)
2198 (const :tag "Duplex" ps-spool-duplex)
2199 (const :tag "Tumble" ps-spool-tumble)
2200 (const :tag "Upside-Down" ps-print-upside-down)
2201 (const :tag "PS File Landscape" pr-file-landscape)
2202 (const :tag "PS File Duplex" pr-file-duplex)
2203 (const :tag "PS File Tumble" pr-file-tumble)
2204 (const :tag "Auto Region" pr-auto-region)
2205 (const :tag "Auto Mode" pr-auto-mode)
2206 (const :tag "Ghostscript Device" pr-gs-device)
2207 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2208 (const :tag "inherits-from:" inherits-from:)
2209 (variable :tag "Other"))
2210 (sexp :tag "Value")))
2212 :version "20"
2213 :group 'printing)
2216 (defcustom pr-ps-utility 'mpage
2217 "*Specify PostScript utility symbol.
2219 This utility symbol should be defined on `pr-ps-utility-alist' (see it for
2220 documentation).
2222 This variable should be modified by customization engine. If this variable is
2223 modified by other means (for example, a lisp function), use `pr-update-menus'
2224 function (see it for documentation) to update PostScript utility menu.
2226 NOTE: Don't forget to download and install the utilities declared on
2227 `pr-ps-utility-alist'."
2228 :type '(symbol :tag "PS File Utility")
2229 :set 'pr-ps-utility-custom-set
2230 :version "20"
2231 :group 'printing)
2234 (defcustom pr-ps-utility-alist
2235 '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2236 (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2237 (inherits-from: . no-duplex))
2239 ;; Examples:
2240 ;; * On GNU or Unix system:
2241 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2242 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2243 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2244 ;; )
2245 ;; * On Windows system:
2246 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2247 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2248 ;; )
2249 "*Specify an alist for PostScript utility processing (PS utility database).
2251 The alist element has the form:
2253 (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
2254 SWITCHES DEFAULT...)
2256 Where:
2258 SYMBOL It's a symbol to identify a PostScript utility. It's for
2259 `pr-ps-utility' variable setting and for menu selection.
2260 Examples:
2261 'mpage
2262 'psnup
2264 UTILITY Name of utility for processing a PostScript file.
2265 See also `pr-path-alist'.
2266 Examples:
2267 . for GNU or Unix system:
2268 \"mpage\"
2269 \"psnup -q\"
2271 . for Windows system:
2272 \"c:/psutils/psnup -q\"
2274 MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
2275 program. These options are necessary to process the utility
2276 program and must be placed before any other switches.
2277 Example:
2278 . for psnup:
2279 '(\"-q\")
2281 PAPERSIZE It's a format string to specify paper size switch.
2282 Example:
2283 . for mpage
2284 \"-b%s\"
2286 N-UP It's a format string to specify n-up switch.
2287 Example:
2288 . for psnup
2289 \"-%d\"
2291 LANDSCAPE It's a string to specify landscape switch. If the utility
2292 doesn't have landscape switch, set to nil.
2293 Example:
2294 . for psnup
2295 \"-l\"
2297 DUPLEX It's a string to specify duplex switch. If the utility doesn't
2298 have duplex switch, set to nil.
2299 Example:
2300 . for psnup
2303 TUMBLE It's a string to specify tumble switch. If the utility doesn't
2304 have tumble switch, set to nil.
2305 Example:
2306 . for psnup
2309 OUTPUT It's a string to specify how to generate an output file. Some
2310 utilities accept an output file option, but some others need
2311 output redirection or some other way to specify an output file.
2312 Example:
2313 . for psnup
2314 \" \" ; psnup ... input output
2316 . for mpage
2317 \">\" ; mpage ... input > output
2319 SWITCHES List of sexp's to pass as extra options to the PostScript utility
2320 program.
2321 Example:
2322 . for psnup
2323 '(\"-q\")
2326 DEFAULT It's a way to set default values when this entry is selected.
2327 It's a cons like:
2329 (VARIABLE . VALUE)
2331 That associates VARIABLE with VALUE. when this entry is
2332 selected, it's executed the following command:
2334 (set VARIABLE (eval VALUE))
2336 Note that VALUE can be any valid lisp expression. So, don't
2337 forget to quote symbols and constant lists.
2338 If VARIABLE is the special keyword `inherits-from:', VALUE must
2339 be a symbol name setting defined in `pr-setting-database' from
2340 which the current setting inherits the context. Take care with
2341 circular inheritance.
2342 Examples:
2343 '(pr-file-landscape . nil)
2344 '(pr-file-duplex . t)
2345 '(pr-gs-device . (my-gs-device t))
2347 This variable should be modified by customization engine. If this variable is
2348 modified by other means (for example, a lisp function), use `pr-update-menus'
2349 function (see it for documentation) to update PostScript utility menu.
2351 NOTE: Don't forget to download and install the utilities declared on
2352 `pr-ps-utility-alist'.
2354 Examples:
2356 * On GNU or Unix system:
2358 '((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
2359 (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
2360 (pr-file-duplex . nil) (pr-file-tumble . nil))
2363 * On Windows system:
2365 '((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
2366 nil (pr-file-duplex . nil) (pr-file-tumble . nil))
2369 Useful links:
2371 * mpage download (GNU or Unix)
2372 `http://www.mesa.nl/pub/mpage/'
2374 * mpage documentation (GNU or Unix - or type `man mpage')
2375 `http://www.cs.umd.edu/faq/guides/manual_unix/node48.html'
2376 `http://www.rt.com/man/mpage.1.html'
2378 * psnup (Windows, GNU or Unix)
2379 `http://www.knackered.org/angus/psutils/'
2380 `http://gershwin.ens.fr/vdaniel/Doc-Locale/Outils-Gnu-Linux/PsUtils/'
2382 * psnup (PsUtils for Windows)
2383 `http://gnuwin32.sourceforge.net/packages/psutils.htm'
2385 * psnup documentation (GNU or Unix - or type `man psnup')
2386 `http://linux.about.com/library/cmd/blcmdl1_psnup.htm'
2387 `http://amath.colorado.edu/computing/software/man/psnup.html'
2389 * GNU Enscript (Windows, GNU or Unix)
2390 `http://people.ssh.com/mtr/genscript/'
2392 * GNU Enscript documentation (Windows, GNU or Unix)
2393 `http://people.ssh.com/mtr/genscript/enscript.man.html'
2394 (on GNU or Unix, type `man enscript')
2396 :type '(repeat
2397 (list :tag "PS File Utility"
2398 (symbol :tag "Utility Symbol")
2399 (string :tag "Utility Name")
2400 (repeat :tag "Must Utility Switches"
2401 (sexp :tag "Switch" :value ""))
2402 (choice :menu-tag "Paper Size"
2403 :tag "Paper Size"
2404 (const :tag "No Paper Size" nil)
2405 (string :tag "Paper Size Format"))
2406 (choice :menu-tag "N-Up"
2407 :tag "N-Up"
2408 (const :tag "No N-Up" nil)
2409 (string :tag "N-Up Format"))
2410 (choice :menu-tag "Landscape"
2411 :tag "Landscape"
2412 (const :tag "No Landscape" nil)
2413 (string :tag "Landscape Switch"))
2414 (choice :menu-tag "Duplex"
2415 :tag "Duplex"
2416 (const :tag "No Duplex" nil)
2417 (string :tag "Duplex Switch"))
2418 (choice :menu-tag "Tumble"
2419 :tag "Tumble"
2420 (const :tag "No Tumble" nil)
2421 (string :tag "Tumble Switch"))
2422 (string :tag "Output Separator")
2423 (repeat :tag "Utility Switches"
2424 (sexp :tag "Switch" :value ""))
2425 (repeat
2426 :tag "Default Value List"
2427 :inline t
2428 (cons
2429 :tag ""
2430 (choice
2431 :menu-tag "Variable"
2432 :tag "Variable"
2433 (const :tag "PS File Landscape" pr-file-landscape)
2434 (const :tag "PS File Duplex" pr-file-duplex)
2435 (const :tag "PS File Tumble" pr-file-tumble)
2436 (const :tag "Ghostscript Device" pr-gs-device)
2437 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2438 (const :tag "inherits-from:" inherits-from:)
2439 (variable :tag "Other"))
2440 (sexp :tag "Value")))
2442 :set 'pr-alist-custom-set
2443 :version "20"
2444 :group 'printing)
2447 (defcustom pr-menu-lock t
2448 "*Non-nil means menu is locked while selecting toggle options.
2450 See also `pr-menu-char-height' and `pr-menu-char-width'."
2451 :type 'boolean
2452 :version "20"
2453 :group 'printing)
2456 (defcustom pr-menu-char-height
2457 (cond ((featurep 'xemacs) ; XEmacs
2458 (pr-x-font-height (face-font 'default)))
2459 (t ; GNU Emacs
2460 (pr-e-frame-char-height)))
2461 "*Specify menu char height in pixels.
2463 This variable is used to guess which vertical position should be locked the
2464 menu, so don't forget to adjust it if menu position is not ok.
2466 See also `pr-menu-lock' and `pr-menu-char-width'."
2467 :type 'integer
2468 :version "20"
2469 :group 'printing)
2472 (defcustom pr-menu-char-width
2473 (cond ((featurep 'xemacs) ; XEmacs
2474 (pr-x-font-width (face-font 'default)))
2475 (t ; GNU Emacs
2476 (pr-e-frame-char-width)))
2477 "*Specify menu char width in pixels.
2479 This variable is used to guess which horizontal position should be locked the
2480 menu, so don't forget to adjust it if menu position is not ok.
2482 See also `pr-menu-lock' and `pr-menu-char-height'."
2483 :type 'integer
2484 :version "20"
2485 :group 'printing)
2488 (defcustom pr-setting-database
2489 '((no-duplex ; setting symbol name
2490 nil nil nil ; inherits local kill-local
2491 (pr-file-duplex . nil) ; settings
2492 (pr-file-tumble . nil))
2494 "*Specify an alist for settings in general.
2496 The elements have the following form:
2498 (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
2500 Where:
2502 SYMBOL It's a symbol to identify the setting group.
2504 INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
2505 setting from which the current setting inherits the context.
2506 If INHERITS is nil, means that there is no inheritance.
2507 This is a simple inheritance mechanism.
2509 Let's see an example to illustrate the inheritance mechanism:
2511 (setq pr-setting-database
2512 '((no-duplex ; setting symbol name
2513 nil ; inherits
2514 nil nil ; local kill-local
2515 (pr-file-duplex . nil) ; settings
2516 (pr-file-tumble . nil)
2518 (no-duplex-and-landscape ; setting symbol name
2519 no-duplex ; inherits
2520 nil nil ; local kill-local
2521 (pr-file-landscape . nil) ; settings
2524 The example above has two setting groups: no-duplex and
2525 no-duplex-and-landscape. When setting no-duplex is activated
2526 through `inherits-from:' (see `pr-ps-utility', `pr-mode-alist'
2527 and `pr-ps-printer-alist'), the variables pr-file-duplex and
2528 pr-file-tumble are both set to nil.
2530 Now when setting no-duplex-and-landscape is activated through
2531 `inherits-from:', the variable pr-file-landscape is set to nil
2532 and also the settings for no-duplex are done, because
2533 no-duplex-and-landscape inherits settings from no-duplex.
2535 Take care with circular inheritance. It's an error if circular
2536 inheritance happens.
2538 LOCAL Non-nil means that all settings for SYMBOL group will be
2539 declared local buffer.
2541 KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
2542 killed at end. It has effect only when LOCAL is non-nil.
2544 SETTING It's a cons like:
2546 (VARIABLE . VALUE)
2548 That associates VARIABLE with VALUE. when this entry is
2549 selected, it's executed the following command:
2551 * If LOCAL is non-nil:
2552 (set (make-local-variable VARIABLE) (eval VALUE))
2554 * If LOCAL is nil:
2555 (set VARIABLE (eval VALUE))
2557 Note that VALUE can be any valid lisp expression. So, don't
2558 forget to quote symbols and constant lists.
2559 This setting is ignored if VARIABLE is equal to keyword
2560 `inherits-from:'.
2561 Examples:
2562 '(ps-landscape-mode . nil)
2563 '(ps-spool-duplex . t)
2564 '(pr-gs-device . (my-gs-device t))"
2565 :type '(repeat
2566 (list
2567 :tag ""
2568 (symbol :tag "Setting Name")
2569 (choice :menu-tag "Inheritance"
2570 :tag "Inheritance"
2571 (const :tag "No Inheritance" nil)
2572 (symbol :tag "Inherits From"))
2573 (boolean :tag "Local Buffer Setting")
2574 (boolean :tag "Kill Local Variable At End")
2575 (repeat
2576 :tag "Setting List"
2577 :inline t
2578 (cons
2579 :tag ""
2580 (choice
2581 :menu-tag "Variable"
2582 :tag "Variable"
2583 (const :tag "Landscape" ps-landscape-mode)
2584 (const :tag "Print Header" ps-print-header)
2585 (const :tag "Print Header Frame" ps-print-header-frame)
2586 (const :tag "Line Number" ps-line-number)
2587 (const :tag "Zebra Stripes" ps-zebra-stripes)
2588 (const :tag "Duplex" ps-spool-duplex)
2589 (const :tag "Tumble" ps-spool-tumble)
2590 (const :tag "Upside-Down" ps-print-upside-down)
2591 (const :tag "PS File Landscape" pr-file-landscape)
2592 (const :tag "PS File Duplex" pr-file-duplex)
2593 (const :tag "PS File Tumble" pr-file-tumble)
2594 (const :tag "Auto Region" pr-auto-region)
2595 (const :tag "Auto Mode" pr-auto-mode)
2596 (const :tag "Ghostscript Device" pr-gs-device)
2597 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2598 (variable :tag "Other"))
2599 (sexp :tag "Value")))
2601 :version "20"
2602 :group 'printing)
2605 (defcustom pr-visible-entry-list
2606 '(postscript text postscript-options postscript-process printing help)
2607 "*Specify a list of Printing menu visible entries.
2609 Valid values with the corresponding menu parts are:
2611 +------------------------------+
2612 | Printing Interface |
2613 +------------------------------+
2614 `postscript' | PostScript Preview >|
2615 | PostScript Print >|
2616 | PostScript Printer: name >|
2617 +------------------------------+
2618 `text' | Printify >|
2619 | Print >|
2620 | Text Printer: name >|
2621 +------------------------------+
2622 `postscript-options' |[ ] Landscape |
2623 |[ ] Print Header |
2624 |[ ] Print Header Frame |
2625 |[ ] Line Number |
2626 |[ ] Zebra Stripes |
2627 |[ ] Duplex |
2628 |[ ] Tumble |
2629 |[ ] Upside-Down |
2630 | Print All Pages >|
2631 +------------------------------+
2632 `postscript-process' |[ ] Spool Buffer |
2633 |[ ] Print with faces |
2634 |[ ] Print via Ghostscript |
2635 +------------------------------+
2636 `printing' |[ ] Auto Region |
2637 |[ ] Auto Mode |
2638 |[ ] Menu Lock |
2639 +------------------------------+
2640 `help' | Customize >|
2641 | Show Settings >|
2642 | Help |
2643 +------------------------------+
2645 Any other value is ignored."
2646 :type '(repeat :tag "Menu Visible Part"
2647 (choice :menu-tag "Menu Part"
2648 :tag "Menu Part"
2649 (const postscript)
2650 (const text)
2651 (const postscript-options)
2652 (const postscript-process)
2653 (const printing)
2654 (const help)))
2655 :version "20"
2656 :group 'printing)
2659 (defcustom pr-delete-temp-file t
2660 "*Non-nil means delete temporary files.
2662 Set `pr-delete-temp-file' to nil, if the following message (or a similar)
2663 happens when printing:
2665 Error: could not open \"c:\\temp\\prspool.ps\" for reading."
2666 :type 'boolean
2667 :version "20"
2668 :group 'printing)
2671 (defcustom pr-list-directory nil
2672 "*Non-nil means list directory when processing a directory.
2674 That is, any subdirectories (and the superdirectory) of the directory (given as
2675 argument of functions below) are also printed (as dired-mode listings).
2677 It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
2678 `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
2679 and `pr-txt-directory'."
2680 :type 'boolean
2681 :version "20"
2682 :group 'printing)
2685 (defcustom pr-buffer-name "*Printing Interface*"
2686 "*Specify the name of the buffer interface for printing package.
2688 It's used by `pr-interface'."
2689 :type 'string
2690 :version "20"
2691 :group 'printing)
2694 (defcustom pr-buffer-name-ignore
2695 (list (regexp-quote pr-buffer-name) ; ignore printing interface buffer
2696 "^ .*$") ; ignore invisible buffers
2697 "*Specify a regexp list for buffer names to be ignored in interface buffer.
2699 NOTE: Case is important for matching, that is, `case-fold-search' is always
2700 nil.
2702 It's used by `pr-interface'."
2703 :type '(repeat (regexp :tag "Buffer Name Regexp"))
2704 :version "20"
2705 :group 'printing)
2708 (defcustom pr-buffer-verbose t
2709 "*Non-nil means to be verbose when editing a field in interface buffer.
2711 It's used by `pr-interface'."
2712 :type 'boolean
2713 :version "20"
2714 :group 'printing)
2717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2718 ;; Internal Variables
2721 (defvar pr-txt-command nil
2722 "Name of program for printing a text file.
2723 See `pr-txt-printer-alist'.")
2726 (defvar pr-txt-switches nil
2727 "List of sexp's to pass as extra options to the text printer program.
2728 See `pr-txt-printer-alist'.")
2731 (defvar pr-txt-printer nil
2732 "Specify text printer name.
2733 See `pr-txt-printer-alist'.")
2736 (defvar pr-ps-command nil
2737 "Name of program for printing a PostScript file.
2738 See `pr-ps-printer-alist'.")
2741 (defvar pr-ps-switches nil
2742 "List of sexp's to pass as extra options to the PostScript printer program.
2743 See `pr-ps-printer-alist'.")
2746 (defvar pr-ps-printer-switch nil
2747 "Specify PostScript printer name switch.
2748 See `pr-ps-printer-alist'.")
2751 (defvar pr-ps-printer nil
2752 "Specify PostScript printer name.
2753 See `pr-ps-printer-alist'.")
2756 (defvar pr-menu-bar nil
2757 "Specify Printing menu-bar entry.")
2760 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2761 ;; Macros
2764 (defmacro pr-save-file-modes (&rest body)
2765 "Set temporally file modes to `pr-file-modes'."
2766 `(let ((pr--default-file-modes (default-file-modes))) ; save default
2767 (set-default-file-modes pr-file-modes)
2768 ,@body
2769 (set-default-file-modes pr--default-file-modes))) ; restore default
2772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2773 ;; Keys & Menus
2776 (defmacro pr-xemacs-global-menubar (&rest body)
2777 `(save-excursion
2778 (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
2779 ;; be sure to access global menubar
2780 (set-buffer temp)
2781 ,@body
2782 (kill-buffer temp))))
2785 (defsubst pr-visible-p (key)
2786 (memq key pr-visible-entry-list))
2789 (defsubst pr-mode-alist-p ()
2790 (cdr (assq major-mode pr-mode-alist)))
2793 (defsubst pr-auto-mode-p ()
2794 (and pr-auto-mode (pr-mode-alist-p)))
2797 (defsubst pr-using-ghostscript-p ()
2798 (and pr-print-using-ghostscript (not pr-spool-p)))
2801 (defalias 'pr-get-symbol
2802 (if (fboundp 'easy-menu-intern) ; hacked from easymenu.el
2803 'easy-menu-intern
2804 (lambda (s) (if (stringp s) (intern s) s))))
2806 (cond
2807 ((featurep 'xemacs) ; XEmacs
2808 (defvar zmacs-region-stays nil) ; to avoid compilation gripes
2809 (defun pr-region-active-p ()
2810 (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p))))
2812 (t ; GNU Emacs
2813 (defun pr-region-active-p ()
2814 (and pr-auto-region transient-mark-mode mark-active))))
2817 (defconst pr-menu-spec
2818 ;; Menu mapping:
2819 ;; unfortunately XEmacs doesn't support :active for submenus,
2820 ;; only for items.
2821 ;; So, it uses :included instead of :active.
2822 ;; Also, XEmacs doesn't support :help tag.
2823 (let ((pr-:active (if (featurep 'xemacs)
2824 :included ; XEmacs
2825 :active)) ; GNU Emacs
2826 (pr-:help (if (featurep 'xemacs)
2827 'ignore ; XEmacs
2828 #'(lambda (text) (list :help text))))) ; GNU Emacs
2830 ["Printing Interface" pr-interface
2831 ,@(funcall
2832 pr-:help "Use buffer interface instead of menu interface")]
2833 "--"
2834 ("PostScript Preview" :included (pr-visible-p 'postscript)
2835 ,@(funcall
2836 pr-:help "Preview PostScript instead of sending to printer")
2837 ("Directory" ,pr-:active (not pr-spool-p)
2838 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
2839 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
2840 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
2841 ["Other..." (pr-ps-directory-preview nil nil nil t)
2842 :keys "\\[pr-ps-buffer-preview]"])
2843 ("Buffer" ,pr-:active (not pr-spool-p)
2844 ["1-up" (pr-ps-buffer-preview 1 t) t]
2845 ["2-up" (pr-ps-buffer-preview 2 t) t]
2846 ["4-up" (pr-ps-buffer-preview 4 t) t]
2847 ["Other..." (pr-ps-buffer-preview nil t)
2848 :keys "\\[pr-ps-buffer-preview]"])
2849 ("Region" ,pr-:active (and (not pr-spool-p) (ps-mark-active-p))
2850 ["1-up" (pr-ps-region-preview 1 t) t]
2851 ["2-up" (pr-ps-region-preview 2 t) t]
2852 ["4-up" (pr-ps-region-preview 4 t) t]
2853 ["Other..." (pr-ps-region-preview nil t)
2854 :keys "\\[pr-ps-region-preview]"])
2855 ("Mode" ,pr-:active (and (not pr-spool-p) (pr-mode-alist-p))
2856 ["1-up" (pr-ps-mode-preview 1 t) t]
2857 ["2-up" (pr-ps-mode-preview 2 t) t]
2858 ["4-up" (pr-ps-mode-preview 4 t) t]
2859 ["Other..." (pr-ps-mode-preview nil t)
2860 :keys "\\[pr-ps-mode-preview]"])
2861 ("File"
2862 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
2863 :keys "\\[pr-ps-file-preview]"
2864 ,@(funcall
2865 pr-:help "Preview PostScript file")]
2866 "--"
2867 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2868 ,@(funcall
2869 pr-:help "Select PostScript utility")]
2870 "--"
2871 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
2872 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
2873 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
2874 ["Other..." (pr-ps-file-up-preview nil t t)
2875 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
2876 "--"
2877 ["Landscape" pr-toggle-file-landscape-menu
2878 :style toggle :selected pr-file-landscape
2879 ,@(funcall
2880 pr-:help "Toggle landscape for PostScript file")
2881 :active pr-ps-utility-alist]
2882 ["Duplex" pr-toggle-file-duplex-menu
2883 :style toggle :selected pr-file-duplex
2884 ,@(funcall
2885 pr-:help "Toggle duplex for PostScript file")
2886 :active pr-ps-utility-alist]
2887 ["Tumble" pr-toggle-file-tumble-menu
2888 :style toggle :selected pr-file-tumble
2889 ,@(funcall
2890 pr-:help "Toggle tumble for PostScript file")
2891 :active (and pr-file-duplex pr-ps-utility-alist)])
2892 ["Despool..." (call-interactively 'pr-despool-preview)
2893 :active pr-spool-p :keys "\\[pr-despool-preview]"
2894 ,@(funcall
2895 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
2896 ("PostScript Print" :included (pr-visible-p 'postscript)
2897 ,@(funcall
2898 pr-:help "Send PostScript to printer or file (C-u)")
2899 ("Directory"
2900 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
2901 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
2902 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
2903 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
2904 :keys "\\[pr-ps-buffer-ps-print]"])
2905 ("Buffer"
2906 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
2907 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
2908 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
2909 ["Other..." (pr-ps-buffer-ps-print nil t)
2910 :keys "\\[pr-ps-buffer-ps-print]"])
2911 ("Region" ,pr-:active (ps-mark-active-p)
2912 ["1-up" (pr-ps-region-ps-print 1 t) t]
2913 ["2-up" (pr-ps-region-ps-print 2 t) t]
2914 ["4-up" (pr-ps-region-ps-print 4 t) t]
2915 ["Other..." (pr-ps-region-ps-print nil t)
2916 :keys "\\[pr-ps-region-ps-print]"])
2917 ("Mode" ,pr-:active (pr-mode-alist-p)
2918 ["1-up" (pr-ps-mode-ps-print 1 t) t]
2919 ["2-up" (pr-ps-mode-ps-print 2 t) t]
2920 ["4-up" (pr-ps-mode-ps-print 4 t) t]
2921 ["Other..." (pr-ps-mode-ps-print nil t)
2922 :keys "\\[pr-ps-mode-ps-print]"])
2923 ("File"
2924 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
2925 :keys "\\[pr-ps-file-ps-print]"
2926 ,@(funcall
2927 pr-:help "Send PostScript file to printer")]
2928 "--"
2929 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2930 ,@(funcall
2931 pr-:help "Select PostScript utility")]
2932 "--"
2933 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
2934 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
2935 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
2936 ["Other..." (pr-ps-file-up-ps-print nil t t)
2937 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
2938 "--"
2939 ["Landscape" pr-toggle-file-landscape-menu
2940 :style toggle :selected pr-file-landscape
2941 ,@(funcall
2942 pr-:help "Toggle landscape for PostScript file")
2943 :active pr-ps-utility-alist]
2944 ["Duplex" pr-toggle-file-duplex-menu
2945 :style toggle :selected pr-file-duplex
2946 ,@(funcall
2947 pr-:help "Toggle duplex for PostScript file")
2948 :active pr-ps-utility-alist]
2949 ["Tumble" pr-toggle-file-tumble-menu
2950 :style toggle :selected pr-file-tumble
2951 ,@(funcall
2952 pr-:help "Toggle tumble for PostScript file")
2953 :active (and pr-file-duplex pr-ps-utility-alist)])
2954 ["Despool..." (call-interactively 'pr-despool-ps-print)
2955 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
2956 ,@(funcall
2957 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
2958 ["PostScript Printers" pr-update-menus
2959 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
2960 ,@(funcall
2961 pr-:help "Select PostScript printer")]
2962 "--"
2963 ("Printify" :included (pr-visible-p 'text)
2964 ,@(funcall
2965 pr-:help
2966 "Replace non-printing chars with printable representations.")
2967 ["Directory" pr-printify-directory t]
2968 ["Buffer" pr-printify-buffer t]
2969 ["Region" pr-printify-region (ps-mark-active-p)])
2970 ("Print" :included (pr-visible-p 'text)
2971 ,@(funcall
2972 pr-:help "Send text to printer")
2973 ["Directory" pr-txt-directory t]
2974 ["Buffer" pr-txt-buffer t]
2975 ["Region" pr-txt-region (ps-mark-active-p)]
2976 ["Mode" pr-txt-mode (pr-mode-alist-p)])
2977 ["Text Printers" pr-update-menus
2978 :active pr-txt-printer-alist :included (pr-visible-p 'text)
2979 ,@(funcall
2980 pr-:help "Select text printer")]
2981 "--"
2982 ["Landscape" pr-toggle-landscape-menu
2983 :style toggle :selected ps-landscape-mode
2984 :included (pr-visible-p 'postscript-options)]
2985 ["Print Header" pr-toggle-header-menu
2986 :style toggle :selected ps-print-header
2987 :included (pr-visible-p 'postscript-options)]
2988 ["Print Header Frame" pr-toggle-header-frame-menu
2989 :style toggle :selected ps-print-header-frame :active ps-print-header
2990 :included (pr-visible-p 'postscript-options)]
2991 ["Line Number" pr-toggle-line-menu
2992 :style toggle :selected ps-line-number
2993 :included (pr-visible-p 'postscript-options)]
2994 ["Zebra Stripes" pr-toggle-zebra-menu
2995 :style toggle :selected ps-zebra-stripes
2996 :included (pr-visible-p 'postscript-options)]
2997 ["Duplex" pr-toggle-duplex-menu
2998 :style toggle :selected ps-spool-duplex
2999 :included (pr-visible-p 'postscript-options)]
3000 ["Tumble" pr-toggle-tumble-menu
3001 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
3002 :included (pr-visible-p 'postscript-options)]
3003 ["Upside-Down" pr-toggle-upside-down-menu
3004 :style toggle :selected ps-print-upside-down
3005 :included (pr-visible-p 'postscript-options)]
3006 ("Print All Pages" :included (pr-visible-p 'postscript-options)
3007 ,@(funcall
3008 pr-:help "Select odd/even pages/sheets to print")
3009 ["All Pages" (pr-even-or-odd-pages nil)
3010 :style radio :selected (eq ps-even-or-odd-pages nil)]
3011 ["Even Pages" (pr-even-or-odd-pages 'even-page)
3012 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
3013 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
3014 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
3015 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
3016 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
3017 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
3018 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
3019 "--"
3020 ["Spool Buffer" pr-toggle-spool-menu
3021 :style toggle :selected pr-spool-p
3022 :included (pr-visible-p 'postscript-process)
3023 ,@(funcall
3024 pr-:help "Toggle PostScript spooling")]
3025 ["Print with faces" pr-toggle-faces-menu
3026 :style toggle :selected pr-faces-p
3027 :included (pr-visible-p 'postscript-process)
3028 ,@(funcall
3029 pr-:help "Toggle PostScript printing with faces")]
3030 ["Print via Ghostscript" pr-toggle-ghostscript-menu
3031 :style toggle :selected pr-print-using-ghostscript
3032 :included (pr-visible-p 'postscript-process)
3033 ,@(funcall
3034 pr-:help "Toggle PostScript generation using ghostscript")]
3035 "--"
3036 ["Auto Region" pr-toggle-region-menu
3037 :style toggle :selected pr-auto-region
3038 :included (pr-visible-p 'printing)]
3039 ["Auto Mode" pr-toggle-mode-menu
3040 :style toggle :selected pr-auto-mode
3041 :included (pr-visible-p 'printing)]
3042 ["Menu Lock" pr-toggle-lock-menu
3043 :style toggle :selected pr-menu-lock
3044 :included (pr-visible-p 'printing)]
3045 "--"
3046 ("Customize" :included (pr-visible-p 'help)
3047 ["printing" pr-customize t]
3048 ["ps-print" ps-print-customize t]
3049 ["lpr" lpr-customize t])
3050 ("Show Settings" :included (pr-visible-p 'help)
3051 ["printing" pr-show-pr-setup t]
3052 ["ps-print" pr-show-ps-setup t]
3053 ["lpr" pr-show-lpr-setup t])
3054 ["Help" pr-help :active t :included (pr-visible-p 'help)]
3058 (defvar pr-menu-print-item "print"
3059 "Non-nil means that menu binding was not done.
3061 Used by `pr-menu-bind' and `pr-update-menus'.")
3064 (defun pr-menu-bind ()
3065 "Install `printing' menu in the menubar.
3067 On Emacs 20, it replaces the Tools/Print menu by Tools/Printing menu.
3069 On Emacs 21 and 22, it replaces the File/Print* menu entries by File/Print
3070 menu.
3072 Calls `pr-update-menus' to adjust menus."
3073 (interactive)
3074 (cond
3075 ((featurep 'xemacs) ; XEmacs
3076 ;; Menu binding
3077 (pr-xemacs-global-menubar
3078 (pr-x-add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
3079 (setq pr-menu-print-item nil))
3082 (t ; GNU Emacs
3083 ;; Menu binding
3084 (require 'easymenu)
3085 ;; Replace existing "print" item by "Printing" item.
3086 ;; If you're changing this file, you'll load it a second,
3087 ;; third... time, but "print" item exists only in the first load.
3088 (cond
3089 ;; Emacs 20
3090 ((string< emacs-version "21.")
3091 (easy-menu-change '("tools") "Printing" pr-menu-spec pr-menu-print-item)
3092 (when pr-menu-print-item
3093 (easy-menu-remove-item nil '("tools") pr-menu-print-item)
3094 (setq pr-menu-print-item nil
3095 pr-menu-bar (vector 'menu-bar 'tools
3096 (pr-get-symbol "Printing")))))
3097 ;; Emacs 21 & 22
3099 (let* ((has-file (lookup-key global-map (vector 'menu-bar 'file)))
3100 (item-file (if has-file '("file") '("files"))))
3101 (cond
3102 (pr-menu-print-item
3103 (easy-menu-change item-file "Print" pr-menu-spec "print-buffer")
3104 (let ((items '("print-buffer" "print-region"
3105 "ps-print-buffer-faces" "ps-print-region-faces"
3106 "ps-print-buffer" "ps-print-region")))
3107 (while items
3108 (easy-menu-remove-item nil item-file (car items))
3109 (setq items (cdr items)))
3110 (setq pr-menu-print-item nil
3111 pr-menu-bar (vector 'menu-bar
3112 (if has-file 'file 'files)
3113 (pr-get-symbol "Print")))))
3115 (easy-menu-change item-file "Print" pr-menu-spec))))))))
3116 (pr-update-menus t))
3119 ;; Key binding
3120 (let ((pr-print-key (if (featurep 'xemacs)
3121 'f22 ; XEmacs
3122 'print))) ; GNU Emacs
3123 (global-set-key `[,pr-print-key] 'pr-ps-fast-fire)
3124 ;; Well, M-print and S-print are used because in my keyboard S-print works
3125 ;; and M-print doesn't. But M-print can work in other keyboard.
3126 (global-set-key `[(meta ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3127 (global-set-key `[(shift ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3128 ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
3129 ;; and C-print doesn't. But C-print can work in other keyboard.
3130 (global-set-key `[(control ,pr-print-key)] 'pr-txt-fast-fire)
3131 (global-set-key `[(control meta ,pr-print-key)] 'pr-txt-fast-fire))
3134 ;;; You can also use something like:
3135 ;;;(global-set-key "\C-ci" 'pr-interface)
3136 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
3137 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
3138 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
3139 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
3140 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
3141 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
3144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3145 ;; Help Message
3148 (defconst pr-help-message
3149 (concat "printing.el version " pr-version
3150 " ps-print.el version " ps-print-version
3151 "\n\n
3152 Menu Layout
3153 -----------
3155 The `printing' menu (Tools/Printing or File/Print) has the following layout:
3157 +-----------------------------+
3158 A 0 | Printing Interface |
3159 +-----------------------------+ +-A---------+ +-B------+
3160 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
3161 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
3162 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
3163 +-----------------------------+ |Mode >|-- B |Other...|
3164 II 4 | Printify >|-----\\ |File >|--\\ +--------+
3165 5 | Print >|---\\ | |Despool... | |
3166 6 | Text Printer: name >|-\\ | | +-----------+ |
3167 +-----------------------------+ | | | +---------+ +------------+
3168 III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
3169 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
3170 9 |[ ]Print Header Frame | | | |Region | | name >|- C
3171 10 |[ ]Line Number | | | +---------+ +------------+
3172 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
3173 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
3174 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
3175 14 |[ ]Upside-Down | | |Region | | Other... |
3176 15 | Print All Pages >|--\\ | |Mode | +------------+
3177 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
3178 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
3179 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
3180 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
3181 +-----------------------------+ | |... |
3182 V 19 |[ ]Auto Region | | |(*)name |
3183 20 |[ ]Auto Mode | | |... |
3184 21 |[ ]Menu Lock | | +---------+ +--------------+
3185 +-----------------------------+ \\------------------|(*)All Pages |
3186 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
3187 23 | Show Settings >|-------|printing| |( )Odd Pages |
3188 24 | Help | |ps-print| |( )Even Sheets|
3189 +-----------------------------+ |lpr | |( )Odd Sheets |
3190 +--------+ +--------------+
3192 See `pr-visible-entry-list' for hiding some parts of the menu.
3194 The menu has the following sections:
3196 A. Interface:
3198 0. You can use a buffer interface instead of menus. It looks like the
3199 customization buffer. Basically, it has the same options found in the
3200 menu and some extra options, all this on a buffer.
3202 I. PostScript printing:
3204 1. You can generate a PostScript file (if you type C-u before activating
3205 menu) or PostScript temporary file for a directory, a buffer, a region
3206 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
3207 after file generation, ghostview is activated using the file generated
3208 as argument. This option is disabled if spooling is on (option 16).
3209 Also, if you already have a PostScript file you can preview it.
3210 Instead of previewing each buffer, region or major mode at once, you
3211 can save temporarily the PostScript code generated in a buffer and
3212 preview it later. The option `Despool...' despools the PostScript
3213 spooling buffer in a temporary file and uses ghostview to preview it.
3214 If you type C-u before choosing this option, the PostScript code
3215 generated is saved in a file instead of saving in a temporary file. To
3216 spool the PostScript code generated you need to turn on the option 16.
3217 The option `Despool...' is enabled if spooling is on (option 16).
3219 NOTE 1: It's possible to customize a major mode printing, just declare
3220 the customization in `pr-mode-alist' and invoke some of
3221 `*-mode*' commands or select Mode option in Printing menu. An
3222 example for major mode usage is when you're using gnus (or mh,
3223 or rmail, etc.) and you're in the *Summary* buffer, if you
3224 forget to switch to the *Article* buffer before printing,
3225 you'll get a nicely formatted list of article subjects shows
3226 up at the printer. With major mode printing you don't need to
3227 switch from gnus *Summary* buffer first.
3229 NOTE 2: There are the following options for PostScript file processing:
3230 Ia. Print the file *No Preprocessing*, that is, send it
3231 directly to PostScript printer.
3232 Ib. PostScript utility processing selection.
3233 See `pr-ps-utility-alist' and `pr-setting-database' for
3234 documentation.
3235 Ic. Do n-up processing before printing.
3236 Id. Toggle on/off landscape for PostScript file processing.
3237 Ie. Toggle on/off duplex for PostScript file processing.
3238 If. Toggle on/off tumble for PostScript file processing.
3240 NOTE 3: Don't forget to download and install the utilities declared on
3241 `pr-ps-utility-alist'.
3243 2. Operate the same way as option 1, but it sends directly the PostScript
3244 code (or put in a file, if you've typed C-u) or it uses ghostscript to
3245 print the PostScript file generated. It depends on option 18, if it's
3246 turned on, it uses ghostscript; otherwise, it sends directly to
3247 printer. If spooling is on (option 16), the PostScript code is saved
3248 temporarily in a buffer instead of printing it or saving it in a file.
3249 Also, if you already have a PostScript file you can print it.
3250 Instead of printing each buffer, region or major mode at once, you can
3251 save temporarily the PostScript code generated in a buffer and print it
3252 later. The option `Despool...' despools the PostScript spooling buffer
3253 directly on a printer. If you type C-u before choosing this option,
3254 the PostScript code generated is saved in a file instead of sending it to
3255 the printer. To spool the PostScript code generated you need to turn on
3256 option 16. This option is enabled if spooling is on (option 16).
3257 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
3259 3. You can select a new PostScript printer to send PostScript code
3260 generated. For selection it's used all PostScript printers defined
3261 in `pr-ps-printer-alist' variable (see it for documentation).
3262 See also `pr-setting-database'.
3264 II. Text printing:
3266 4. If you have control characters (character code from \\000 to \\037) in a
3267 buffer and you want to print them in a text printer, select this
3268 option. All control characters in your buffer or region will be
3269 replaced by a printable representation. The printable representations
3270 use ^ (for ASCII control characters) or hex. The characters tab,
3271 linefeed, space, return and formfeed are not affected.
3272 You don't need to select this option if you use any option of section
3273 I, the PostScript engine treats control characters properly.
3275 5. If you want to print a directory, buffer, region or major mode in a
3276 text printer, select this option. See also the NOTE 1 on option 1.
3278 6. You can select a new text printer to send text generated. For
3279 selection it's used all text printers defined in `pr-txt-printer-alist'
3280 variable (see it for documentation).
3281 See also `pr-setting-database'.
3283 III. PostScript page toggle options:
3285 7. If you want a PostScript landscape printing, turn on this option.
3287 8. If you want to have a header in each page in your PostScript code,
3288 turn on this option.
3290 9. If you want to draw a gaudy frame around the header, turn on this
3291 option. This option is enabled if print header is on (option 8).
3293 10. If you want that the line number is printed in your PostScript code,
3294 turn on this option.
3296 11. If you want background zebra stripes in your PostScript code, turn on
3297 this option.
3299 12. If you want a duplex printing and your PostScript printer has this
3300 feature, turn on this option.
3302 13. If you turned on duplex printing, you can choose if you want to have a
3303 printing suitable for binding on the left or right (tumble off), or to
3304 have a printing suitable for binding at top or bottom (tumble on).
3305 This option is enabled if duplex is on (option 12).
3307 14. If you want a PostScript upside-down printing, turn on this option.
3309 15. With this option, you can choose if you want to print all pages, odd
3310 pages, even pages, odd sheets or even sheets.
3311 See also `ps-even-or-odd-pages'.
3313 IV. PostScript processing toggle options:
3315 16. If you want to spool the PostScript code generated, turn on this
3316 option. To spool the PostScript code generated use option 2. You can
3317 despool later by choosing option 1 or 2, sub-option `Despool...'.
3319 17. If you use colors in your buffers and want to see these colors on your
3320 PostScript code generated, turn on this option. If you have a
3321 black/white PostScript printer, these colors are displayed in gray
3322 scale by PostScript printer interpreter.
3324 18. If you don't have a PostScript printer to send PostScript files, turn
3325 on this option. When this option is on, the ghostscript is used to
3326 print PostScript files. In GNU or Unix system, if ghostscript is set
3327 as a PostScript filter, you don't need to turn on this option.
3329 V. Printing customization:
3331 19. If you want that region is automagically detected, turn on this
3332 option. Note that this will only work if you're using transient mark
3333 mode. When this option is on, the `*-buffer*' commands will behave
3334 like `*-region*' commands, that is, `*-buffer*' commands will print
3335 only the region marked instead of all buffer.
3337 20. Turn this option on if you want that when current major-mode is
3338 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3339 behave like `*-mode*' commands.
3341 21. If you want that Printing menu stays open while you are setting
3342 toggle options, turn on this option. The variables
3343 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3344 menu position, so don't forget to adjust these variables if menu
3345 position is not ok.
3347 VI. Customization:
3349 22. Besides all options in section III, IV and V, you can customize much
3350 more PostScript options in `ps-print' option. Or you can customize
3351 some `lpr' options for text printing. Or customize `printing'
3352 options.
3354 23. Show current settings for `printing', `ps-print' or `lpr'.
3356 24. Quick help for printing menu layout.
3358 "Printing help message.")
3361 (defconst pr-interface-help-message
3362 (concat "printing.el version " pr-version
3363 " ps-print.el version " ps-print-version
3364 "\n\n
3365 The printing interface buffer has the same functionality as the printing menu.
3366 The major difference is that the states (like sending PostScript generated to a
3367 file, n-up printing, etc.) are set and saved between priting buffer
3368 activation. Also, the landscape, duplex and tumble values are the same for
3369 PostScript file and directory/buffer/region/mode processing; using menu, there
3370 are different value sets for PostScript file and directory/buffer/region/mode
3371 processing.
3373 The printing interface buffer has the following sections:
3375 1. Print:
3377 Here you can choose to print/preview a buffer, a directory or a PostScript
3378 file:
3380 1a. Buffer:
3382 * Buffer List:
3383 Select a buffer from the current buffer list.
3385 * Region:
3386 If it's on, this means that the selected buffer has an active region,
3387 so you can turn on/off, as you wish.
3388 If it's off when a buffer is selected, this means that the selected
3389 buffer has no active region, so it'll not be possible to turn it on.
3390 If you want to process the region, let this option on.
3391 If you want to process the whole buffer, let this option off.
3393 * Mode:
3394 If it's on, this means that the selected buffer major mode is declared
3395 for major mode processing, so you can turn on/off, as you wish.
3396 If it's off when a buffer is selected, this means that the selected
3397 buffer major mode isn't declared for major mode processing, so it'll
3398 not be possible to turn it on.
3399 If you want the major mode processing, let this option on.
3400 If you don't want the major mode processing, let this option off.
3402 NOTE 1: It's possible to customize a major mode printing, just declare
3403 the customization in `pr-mode-alist' and invoke some of
3404 `*-mode*' commands or select Mode option in Printing menu. An
3405 example for major mode usage is when you're using gnus (or mh,
3406 or rmail, etc.) and you're in the *Summary* buffer, if you
3407 forget to switch to the *Article* buffer before printing,
3408 you'll get a nicely formatted list of article subjects shows
3409 up at the printer. With major mode printing you don't need to
3410 switch from gnus *Summary* buffer first.
3412 1b. Directory:
3414 * Directory:
3415 Specify a valid directory path.
3417 * File Regexp:
3418 Specify a file name regexp. All file names in the directory that
3419 match with regexp will be printed/previewed. An empty file name
3420 regexp means to print/preview all files in the directory.
3422 * List Directory Entry:
3423 If it's turned on, list directory entries besides file entries.
3425 1c. PostScript file:
3427 * PostScript File:
3428 Specify an existent PostScript file to print/preview.
3430 * PostScript Utility:
3431 Select a PostScript utility.
3432 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3434 NOTE 2: Don't forget to download and install the utilities declared on
3435 `pr-ps-utility-alist'.
3437 * No Preprocessing:
3438 If it's turned on, don't use the PostScript utility to preprocess the
3439 PostScript file before printing/previewing.
3441 2. PostScript printer:
3443 * PostScript Printer:
3444 You can select a new PostScript printer to send PostScript code
3445 generated. For selection it's used all PostScript printers defined
3446 in `pr-ps-printer-alist' variable (see it for documentation).
3447 See also `pr-setting-database'.
3449 * Despool:
3450 If spooling is on, you can turn it on/off, as you wish.
3451 If spooling is off, it'll not be possible to turn it on.
3452 If it's turned on, specify to despools the PostScript spooling buffer in
3453 a temporary file or in the selected PostScript file when
3454 printing/previewing.
3456 * Preview:
3457 Preview the PostScript generated.
3459 * Print:
3460 Print the PostScript generated.
3462 * Quit:
3463 Quit from printing interface buffer.
3465 * Send to Printer/Temporary File:
3466 If it's turned on, the PostScript generated is sent directly to
3467 PostScript printer or, for previewing, to a temporary file.
3469 * Send to File:
3470 Specify a file name to send the PostScript generated.
3472 * N-Up:
3473 Specify n-up printing.
3475 3. Text printer:
3477 * Text Printer:
3478 Select a new text printer to send text generated. For selection it's used
3479 all text printers defined in `pr-txt-printer-alist' variable (see it for
3480 documentation). See also `pr-setting-database'.
3482 * Printify:
3483 If you have control characters (character code from \\000 to \\037) in a
3484 buffer and you want to print them in a text printer, select this
3485 option. All control characters in your buffer or region will be
3486 replaced by a printable representation. The printable representations
3487 use ^ (for ASCII control characters) or hex. The characters tab,
3488 linefeed, space, return and formfeed are not affected.
3489 You don't need to select this option if you use any option of section
3490 I, the PostScript engine treats control characters properly.
3492 * Print:
3493 To print a directory, buffer, region or major mode in a
3494 text printer, select this option. See also the NOTE 1 on section 1.
3496 * Quit:
3497 Quit from printing interface buffer.
3499 4. Settings:
3501 There are 3 setting columns:
3503 4a. First column (left column):
3505 * Landscape:
3506 PostScript landscape printing.
3508 * Print Header:
3509 To have a header in each page in your PostScript code.
3511 * Print Header Frame:
3512 To draw a gaudy frame around the header.
3514 * Line Number:
3515 The line number is printed in your PostScript code.
3517 * Zebra Stripes:
3518 Background zebra stripes in your PostScript code.
3520 * Duplex:
3521 Duplex printing (if your PostScript printer has this feature).
3523 * Tumble:
3524 If duplex printing is on, you can choose if you want to have a
3525 printing suitable for binding on the left or right (tumble off), or to
3526 have a printing suitable for binding at top or bottom (tumble on).
3528 * Upside-Down:
3529 PostScript upside-down printing.
3531 4b. Second column (middle column):
3533 * Auto Region:
3534 If you want that region is automagically detected, turn on this
3535 option. Note that this will only work if you're using transient mark
3536 mode. When this option is on, the `*-buffer*' commands will behave
3537 like `*-region*' commands, that is, `*-buffer*' commands will print
3538 only the region marked instead of all buffer.
3540 * Auto Mode:
3541 Turn this option on if you want that when current major-mode is
3542 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3543 behave like `*-mode*' commands.
3545 * Menu Lock:
3546 If you want that Printing menu stays open while you are setting
3547 toggle options, turn on this option. The variables
3548 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3549 menu position, so don't forget to adjust these variables if menu
3550 position is not ok.
3552 * Spool Buffer:
3553 To spool the PostScript code generated. You can despool later by
3554 setting Despool option on PostScript printer section.
3556 * Print with faces:
3557 If you use colors in your buffers and want to see these colors on your
3558 PostScript code generated, turn on this option. If you have a
3559 black/white PostScript printer, these colors are displayed in gray
3560 scale by PostScript printer interpreter.
3562 * Print via Ghostscript:
3563 If you don't have a PostScript printer to send PostScript files, turn
3564 on this option. When this option is on, the ghostscript is used to
3565 print PostScript files. In GNU or Unix system, if ghostscript is set
3566 as a PostScript filter, you don't need to turn on this option.
3568 * Parity Page Menu:
3569 To print all pages, odd pages, even pages, odd sheets or even sheets.
3570 See also `ps-even-or-odd-pages'.
3572 4c. Third column (right column):
3574 * Verbose:
3575 That is, to be verbose when editing a field in interface buffer.
3577 5. Customize:
3579 Besides all options in section 4, you can customize much more PostScript
3580 options in `ps-print' option. Or you can customize some `lpr' options for
3581 text printing. Or customize `printing' options.
3583 6. Show settings:
3585 Show current settings for `printing', `ps-print' or `lpr'.
3587 7. Help:
3589 Quick help for printing interface buffer and printing menu layout. You can
3590 also quit the printing interface buffer or kill all printing help buffer.
3592 "Printing buffer interface help message.")
3595 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3596 ;; Commands
3599 ;;;###autoload
3600 (defun pr-interface (&optional buffer)
3601 "Activate the printing interface buffer.
3603 If BUFFER is nil, the current buffer is used for printing.
3605 For more information, type \\[pr-interface-help]."
3606 (interactive)
3607 (save-excursion
3608 (set-buffer (or buffer (current-buffer)))
3609 (pr-create-interface)))
3612 ;;;###autoload
3613 (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3614 "Preview directory using ghostview.
3616 Interactively, the command prompts for N-UP printing number, a directory, a
3617 file name regexp for matching and, when you use a prefix argument (C-u), the
3618 command prompts the user for a file name, and saves the PostScript image in
3619 that file instead of saving it in a temporary file.
3621 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3622 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3623 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3624 save the image in a temporary file. If FILENAME is a string, save the
3625 PostScript image in a file with that name. If FILENAME is t, prompts for a
3626 file name.
3628 See also documentation for `pr-list-directory'."
3629 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3630 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3631 (pr-prompt "PS preview dir"))
3632 (setq filename (pr-ps-file filename))
3633 (pr-ps-file-list n-up dir file-regexp filename)
3634 (or pr-spool-p
3635 (pr-ps-file-preview filename)))
3638 ;;;###autoload
3639 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3640 "Print directory using PostScript through ghostscript.
3642 Interactively, the command prompts for N-UP printing number, a directory, a
3643 file name regexp for matching and, when you use a prefix argument (C-u), the
3644 command prompts the user for a file name, and saves the PostScript image in
3645 that file instead of saving it in a temporary file.
3647 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3648 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3649 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3650 save the image in a temporary file. If FILENAME is a string, save the
3651 PostScript image in a file with that name. If FILENAME is t, prompts for a
3652 file name.
3654 See also documentation for `pr-list-directory'."
3655 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3656 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3657 (pr-prompt "PS print dir GS"))
3658 (let ((file (pr-ps-file filename)))
3659 (pr-ps-file-list n-up dir file-regexp file)
3660 (pr-ps-file-using-ghostscript file)
3661 (or filename (pr-delete-file file))))
3664 ;;;###autoload
3665 (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
3666 "Print directory using PostScript printer.
3668 Interactively, the command prompts for N-UP printing number, a directory, a
3669 file name regexp for matching and, when you use a prefix argument (C-u), the
3670 command prompts the user for a file name, and saves the PostScript image in
3671 that file instead of saving it in a temporary file.
3673 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3674 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3675 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3676 save the image in a temporary file. If FILENAME is a string, save the
3677 PostScript image in a file with that name. If FILENAME is t, prompts for a
3678 file name.
3680 See also documentation for `pr-list-directory'."
3681 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
3682 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3683 (pr-prompt "PS print dir"))
3684 (let ((file (pr-ps-file filename)))
3685 (pr-ps-file-list n-up dir file-regexp file)
3686 (pr-ps-file-print file)
3687 (or filename (pr-delete-file file))))
3690 ;;;###autoload
3691 (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
3692 "Print directory using PostScript printer or through ghostscript.
3694 It depends on `pr-print-using-ghostscript'.
3696 Interactively, the command prompts for N-UP printing number, a directory, a
3697 file name regexp for matching and, when you use a prefix argument (C-u), the
3698 command prompts the user for a file name, and saves the PostScript image in
3699 that file instead of saving it in a temporary file.
3701 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3702 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3703 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3704 save the image in a temporary file. If FILENAME is a string, save the
3705 PostScript image in a file with that name. If FILENAME is t, prompts for a
3706 file name.
3708 See also documentation for `pr-list-directory'."
3709 (interactive (pr-interactive-ps-dir-args
3710 (pr-prompt (pr-prompt-gs "PS print dir"))))
3711 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3712 (pr-prompt (pr-prompt-gs "PS print dir")))
3713 (if (pr-using-ghostscript-p)
3714 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
3715 (pr-ps-directory-print n-up dir file-regexp filename)))
3718 ;;;###autoload
3719 (defun pr-ps-buffer-preview (n-up &optional filename)
3720 "Preview buffer using ghostview.
3722 Interactively, the command prompts for N-UP printing number and, when you use a
3723 prefix argument (C-u), the command prompts the user for a file name, and saves
3724 the PostScript image in that file instead of saving it in a temporary file.
3726 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3727 argument FILENAME is treated as follows: if it's nil, save the image in a
3728 temporary file. If FILENAME is a string, save the PostScript image in a file
3729 with that name. If FILENAME is t, prompts for a file name."
3730 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
3731 (if (pr-auto-mode-p)
3732 (pr-ps-mode-preview n-up filename)
3733 (pr-ps-preview (pr-region-active-symbol) n-up filename
3734 (pr-region-active-string "PS preview"))))
3737 ;;;###autoload
3738 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
3739 "Print buffer using PostScript through ghostscript.
3741 Interactively, the command prompts for N-UP printing number and, when you use a
3742 prefix argument (C-u), the command prompts the user for a file name, and saves
3743 the PostScript image in that file instead of sending it to the printer.
3745 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3746 argument FILENAME is treated as follows: if it's nil, send the image to the
3747 printer. If FILENAME is a string, save the PostScript image in a file with
3748 that name. If FILENAME is t, prompts for a file name."
3749 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
3750 (if (pr-auto-mode-p)
3751 (pr-ps-mode-using-ghostscript n-up filename)
3752 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3753 (pr-region-active-string "PS print GS"))))
3756 ;;;###autoload
3757 (defun pr-ps-buffer-print (n-up &optional filename)
3758 "Print buffer using PostScript printer.
3760 Interactively, the command prompts for N-UP printing number and, when you use a
3761 prefix argument (C-u), the command prompts the user for a file name, and saves
3762 the PostScript image in that file instead of sending it to the printer.
3764 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3765 argument FILENAME is treated as follows: if it's nil, send the image to the
3766 printer. If FILENAME is a string, save the PostScript image in a file with
3767 that name. If FILENAME is t, prompts for a file name."
3768 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
3769 (if (pr-auto-mode-p)
3770 (pr-ps-mode-print n-up filename)
3771 (pr-ps-print (pr-region-active-symbol) n-up filename
3772 (pr-region-active-string "PS print"))))
3775 ;;;###autoload
3776 (defun pr-ps-buffer-ps-print (n-up &optional filename)
3777 "Print buffer using PostScript printer or through ghostscript.
3779 It depends on `pr-print-using-ghostscript'.
3781 Interactively, the command prompts for N-UP printing number and, when you use a
3782 prefix argument (C-u), the command prompts the user for a file name, and saves
3783 the PostScript image in that file instead of sending it to the printer.
3785 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3786 argument FILENAME is treated as follows: if it's nil, send the image to the
3787 printer. If FILENAME is a string, save the PostScript image in a file with
3788 that name. If FILENAME is t, prompts for a file name."
3789 (interactive (pr-interactive-n-up-file
3790 (pr-prompt (pr-prompt-gs "PS print"))))
3791 (cond ((pr-auto-mode-p)
3792 (pr-ps-mode-ps-print n-up filename))
3793 ((pr-using-ghostscript-p)
3794 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3795 (pr-region-active-string "PS print GS")))
3797 (pr-ps-print (pr-region-active-symbol) n-up filename
3798 (pr-region-active-string "PS print")))))
3801 ;;;###autoload
3802 (defun pr-ps-region-preview (n-up &optional filename)
3803 "Preview region using ghostview.
3805 See also `pr-ps-buffer-preview'."
3806 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
3807 (if (pr-auto-mode-p)
3808 (let ((pr-auto-region t))
3809 (pr-ps-mode-preview n-up filename))
3810 (pr-ps-preview 'region n-up filename "PS preview region")))
3813 ;;;###autoload
3814 (defun pr-ps-region-using-ghostscript (n-up &optional filename)
3815 "Print region using PostScript through ghostscript.
3817 See also `pr-ps-buffer-using-ghostscript'."
3818 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
3819 (if (pr-auto-mode-p)
3820 (let ((pr-auto-region t))
3821 (pr-ps-mode-using-ghostscript n-up filename))
3822 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
3825 ;;;###autoload
3826 (defun pr-ps-region-print (n-up &optional filename)
3827 "Print region using PostScript printer.
3829 See also `pr-ps-buffer-print'."
3830 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
3831 (if (pr-auto-mode-p)
3832 (let ((pr-auto-region t))
3833 (pr-ps-mode-print n-up filename))
3834 (pr-ps-print 'region n-up filename "PS print region")))
3837 ;;;###autoload
3838 (defun pr-ps-region-ps-print (n-up &optional filename)
3839 "Print region using PostScript printer or through ghostscript.
3841 See also `pr-ps-buffer-ps-print'."
3842 (interactive (pr-interactive-n-up-file
3843 (pr-prompt-region (pr-prompt-gs "PS print"))))
3844 (cond ((pr-auto-mode-p)
3845 (let ((pr-auto-region t))
3846 (pr-ps-mode-ps-print n-up filename)))
3847 ((pr-using-ghostscript-p)
3848 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
3850 (pr-ps-print 'region n-up filename "PS print region"))))
3853 ;;;###autoload
3854 (defun pr-ps-mode-preview (n-up &optional filename)
3855 "Preview major mode using ghostview.
3857 See also `pr-ps-buffer-preview'."
3858 (interactive (pr-interactive-n-up-file "PS preview mode"))
3859 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
3860 (let ((file (pr-ps-file filename)))
3861 (and (pr-ps-mode n-up file)
3862 (not pr-spool-p)
3863 (pr-ps-file-preview file))))
3866 ;;;###autoload
3867 (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
3868 "Print major mode using PostScript through ghostscript.
3870 See also `pr-ps-buffer-using-ghostscript'."
3871 (interactive (pr-interactive-n-up-file "PS print GS mode"))
3872 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
3873 (let ((file (pr-ps-file filename)))
3874 (when (and (pr-ps-mode n-up file)
3875 (not pr-spool-p))
3876 (pr-ps-file-using-ghostscript file)
3877 (or filename (pr-delete-file file)))))
3880 ;;;###autoload
3881 (defun pr-ps-mode-print (n-up &optional filename)
3882 "Print major mode using PostScript printer.
3884 See also `pr-ps-buffer-print'."
3885 (interactive (pr-interactive-n-up-file "PS print mode"))
3886 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
3887 (pr-ps-mode n-up filename))
3890 ;;;###autoload
3891 (defun pr-ps-mode-ps-print (n-up &optional filename)
3892 "Print major mode using PostScript or through ghostscript.
3894 See also `pr-ps-buffer-ps-print'."
3895 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
3896 (if (pr-using-ghostscript-p)
3897 (pr-ps-mode-using-ghostscript n-up filename)
3898 (pr-ps-mode-print n-up filename)))
3901 ;;;###autoload
3902 (defun pr-printify-directory (&optional dir file-regexp)
3903 "Replace nonprinting characters in directory with printable representations.
3904 The printable representations use ^ (for ASCII control characters) or hex.
3905 The characters tab, linefeed, space, return and formfeed are not affected.
3907 Interactively, the command prompts for a directory and a file name regexp for
3908 matching.
3910 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3911 prompts for FILE(name)-REGEXP.
3913 See also documentation for `pr-list-directory'."
3914 (interactive (pr-interactive-dir-args "Printify dir"))
3915 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
3916 (pr-file-list dir file-regexp 'pr-printify-buffer))
3919 ;;;###autoload
3920 (defun pr-printify-buffer ()
3921 "Replace nonprinting characters in buffer with printable representations.
3922 The printable representations use ^ (for ASCII control characters) or hex.
3923 The characters tab, linefeed, space, return and formfeed are not affected."
3924 (interactive "*")
3925 (if (pr-region-active-p)
3926 (pr-printify-region)
3927 (printify-region (point-min) (point-max))))
3930 ;;;###autoload
3931 (defun pr-printify-region ()
3932 "Replace nonprinting characters in region with printable representations.
3933 The printable representations use ^ (for ASCII control characters) or hex.
3934 The characters tab, linefeed, space, return and formfeed are not affected."
3935 (interactive "*")
3936 (printify-region (point) (mark)))
3939 ;;;###autoload
3940 (defun pr-txt-directory (&optional dir file-regexp)
3941 "Print directory using text printer.
3943 Interactively, the command prompts for a directory and a file name regexp for
3944 matching.
3946 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3947 prompts for FILE(name)-REGEXP.
3949 See also documentation for `pr-list-directory'."
3950 (interactive (pr-interactive-dir-args "Print dir"))
3951 (pr-set-dir-args 'dir 'file-regexp "Print dir")
3952 (pr-file-list dir file-regexp 'pr-txt-buffer))
3955 ;;;###autoload
3956 (defun pr-txt-buffer ()
3957 "Print buffer using text printer."
3958 (interactive)
3959 (cond ((pr-auto-mode-p)
3960 (pr-txt-mode))
3961 ((pr-region-active-p)
3962 (pr-txt-region))
3964 (pr-txt-print (point-min) (point-max)))))
3967 ;;;###autoload
3968 (defun pr-txt-region ()
3969 "Print region using text printer."
3970 (interactive)
3971 (if (pr-auto-mode-p)
3972 (let ((pr-auto-region t))
3973 (pr-txt-mode))
3974 (pr-txt-print (point) (mark))))
3977 ;;;###autoload
3978 (defun pr-txt-mode ()
3979 "Print major mode using text printer."
3980 (interactive)
3981 (let ((args (pr-mode-alist-p)))
3982 (if args
3983 (funcall (car args) (nthcdr 2 args))
3984 (ding)
3985 (message "`%s' major mode not declared." major-mode))))
3988 ;;;###autoload
3989 (defun pr-despool-preview (&optional filename)
3990 "Preview spooled PostScript.
3992 Interactively, when you use a prefix argument (C-u), the command prompts the
3993 user for a file name, and saves the spooled PostScript image in that file
3994 instead of saving it in a temporary file.
3996 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3997 save the image in a temporary file. If FILENAME is a string, save the
3998 PostScript image in a file with that name."
3999 (interactive (list (ps-print-preprint current-prefix-arg)))
4000 (let ((file (pr-ps-file filename)))
4001 (when (stringp file)
4002 (pr-despool-print file)
4003 (pr-ps-file-preview file))))
4006 ;;;###autoload
4007 (defun pr-despool-using-ghostscript (&optional filename)
4008 "Print spooled PostScript using ghostscript.
4010 Interactively, when you use a prefix argument (C-u), the command prompts the
4011 user for a file name, and saves the spooled PostScript image in that file
4012 instead of sending it to the printer.
4014 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4015 send the image to the printer. If FILENAME is a string, save the PostScript
4016 image in a file with that name."
4017 (interactive (list (ps-print-preprint current-prefix-arg)))
4018 (let ((file (pr-ps-file filename)))
4019 (when (stringp file)
4020 (pr-despool-print file)
4021 (pr-ps-file-using-ghostscript file)
4022 (or filename (pr-delete-file file)))))
4025 ;;;###autoload
4026 (defun pr-despool-print (&optional filename)
4027 "Send the spooled PostScript to the printer.
4029 Interactively, when you use a prefix argument (C-u), the command prompts the
4030 user for a file name, and saves the spooled PostScript image in that file
4031 instead of sending it to the printer.
4033 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4034 send the image to the printer. If FILENAME is a string, save the PostScript
4035 image in a file with that name."
4036 (interactive (list (ps-print-preprint current-prefix-arg)))
4037 (pr-save-file-modes
4038 (let ((ps-lpr-command (pr-command pr-ps-command))
4039 (ps-lpr-switches pr-ps-switches)
4040 (ps-printer-name-option pr-ps-printer-switch)
4041 (ps-printer-name pr-ps-printer))
4042 (ps-despool filename))))
4045 ;;;###autoload
4046 (defun pr-despool-ps-print (&optional filename)
4047 "Send the spooled PostScript to the printer or use ghostscript to print it.
4049 Interactively, when you use a prefix argument (C-u), the command prompts the
4050 user for a file name, and saves the spooled PostScript image in that file
4051 instead of sending it to the printer.
4053 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4054 send the image to the printer. If FILENAME is a string, save the PostScript
4055 image in a file with that name."
4056 (interactive (list (ps-print-preprint current-prefix-arg)))
4057 (if pr-print-using-ghostscript
4058 (pr-despool-using-ghostscript filename)
4059 (pr-despool-print filename)))
4062 ;;;###autoload
4063 (defun pr-ps-file-preview (filename)
4064 "Preview PostScript file FILENAME."
4065 (interactive (list (pr-ps-infile-preprint "Preview ")))
4066 (and (stringp filename) (file-exists-p filename)
4067 (pr-call-process pr-gv-command filename)))
4070 ;;;###autoload
4071 (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
4072 "Preview PostScript file FILENAME."
4073 (interactive (pr-interactive-n-up-inout "PS preview"))
4074 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4075 "PS preview ")))
4076 (pr-ps-utility-process n-up ifilename outfile)
4077 (pr-ps-file-preview outfile)))
4080 ;;;###autoload
4081 (defun pr-ps-file-using-ghostscript (filename)
4082 "Print PostScript file FILENAME using ghostscript."
4083 (interactive (list (pr-ps-infile-preprint "Print preview ")))
4084 (and (stringp filename) (file-exists-p filename)
4085 (let* ((file (pr-expand-file-name filename))
4086 (tempfile (pr-dosify-file-name (make-temp-file file))))
4087 ;; gs use
4088 (pr-call-process pr-gs-command
4089 (format "-sDEVICE=%s" pr-gs-device)
4090 (format "-r%d" pr-gs-resolution)
4091 (pr-switches-string pr-gs-switches "pr-gs-switches")
4092 (format "-sOutputFile=\"%s\"" tempfile)
4093 file
4094 "-c quit")
4095 ;; printing
4096 (pr-ps-file-print tempfile)
4097 ;; deleting
4098 (pr-delete-file tempfile))))
4101 ;;;###autoload
4102 (defun pr-ps-file-print (filename)
4103 "Print PostScript file FILENAME."
4104 (interactive (list (pr-ps-infile-preprint "Print ")))
4105 (and (stringp filename) (file-exists-p filename)
4106 ;; printing
4107 (let ((file (pr-expand-file-name filename)))
4108 (if (string= pr-ps-command "")
4109 ;; default action
4110 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
4111 (save-excursion
4112 (set-buffer ps-spool-buffer)
4113 (erase-buffer)
4114 (insert-file-contents-literally file))
4115 (pr-despool-print))
4116 ;; use `pr-ps-command' to print
4117 (apply 'pr-call-process
4118 pr-ps-command
4119 (pr-switches-string pr-ps-switches "pr-ps-switches")
4120 (if (string-match "cp" pr-ps-command)
4121 ;; for "cp" (cmd in out)
4122 (list file
4123 (concat pr-ps-printer-switch pr-ps-printer))
4124 ;; else, for others (cmd out in)
4125 (list (concat pr-ps-printer-switch pr-ps-printer)
4126 file)))))))
4129 ;;;###autoload
4130 (defun pr-ps-file-ps-print (filename)
4131 "Send PostScript file FILENAME to printer or use ghostscript to print it."
4132 (interactive (list (pr-ps-infile-preprint
4133 (if pr-print-using-ghostscript
4134 "Print preview "
4135 "Print "))))
4136 (if pr-print-using-ghostscript
4137 (pr-ps-file-using-ghostscript filename)
4138 (pr-ps-file-print filename)))
4141 ;;;###autoload
4142 (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
4143 "Process a PostScript file IFILENAME and send it to printer.
4145 Interactively, the command prompts for N-UP printing number, for an input
4146 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
4147 command prompts the user for an output PostScript file name OFILENAME, and
4148 saves the PostScript image in that file instead of sending it to the printer.
4150 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4151 argument IFILENAME is treated as follows: if it's t, prompts for an input
4152 PostScript file name; otherwise, it *must* be a string that it's an input
4153 PostScript file name. The argument OFILENAME is treated as follows: if it's
4154 nil, send the image to the printer. If OFILENAME is a string, save the
4155 PostScript image in a file with that name. If OFILENAME is t, prompts for a
4156 file name."
4157 (interactive (pr-interactive-n-up-inout
4158 (if pr-print-using-ghostscript
4159 "PS print GS"
4160 "PS print")))
4161 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4162 (if pr-print-using-ghostscript
4163 "PS print GS "
4164 "PS print "))))
4165 (pr-ps-utility-process n-up ifilename outfile)
4166 (unless ofilename
4167 (pr-ps-file-ps-print outfile)
4168 (pr-delete-file outfile))))
4171 ;;;###autoload
4172 (defun pr-toggle-file-duplex ()
4173 "Toggle duplex for PostScript file."
4174 (interactive)
4175 (pr-toggle-file-duplex-menu t))
4178 ;;;###autoload
4179 (defun pr-toggle-file-tumble ()
4180 "Toggle tumble for PostScript file.
4182 If tumble is off, produces a printing suitable for binding on the left or
4183 right.
4184 If tumble is on, produces a printing suitable for binding at the top or
4185 bottom."
4186 (interactive)
4187 (pr-toggle-file-tumble-menu t))
4190 ;;;###autoload
4191 (defun pr-toggle-file-landscape ()
4192 "Toggle landscape for PostScript file."
4193 (interactive)
4194 (pr-toggle-file-landscape-menu t))
4197 ;;;###autoload
4198 (defun pr-toggle-ghostscript ()
4199 "Toggle printing using ghostscript."
4200 (interactive)
4201 (pr-toggle-ghostscript-menu t))
4204 ;;;###autoload
4205 (defun pr-toggle-faces ()
4206 "Toggle printing with faces."
4207 (interactive)
4208 (pr-toggle-faces-menu t))
4211 ;;;###autoload
4212 (defun pr-toggle-spool ()
4213 "Toggle spooling."
4214 (interactive)
4215 (pr-toggle-spool-menu t))
4218 ;;;###autoload
4219 (defun pr-toggle-duplex ()
4220 "Toggle duplex."
4221 (interactive)
4222 (pr-toggle-duplex-menu t))
4225 ;;;###autoload
4226 (defun pr-toggle-tumble ()
4227 "Toggle tumble.
4229 If tumble is off, produces a printing suitable for binding on the left or
4230 right.
4231 If tumble is on, produces a printing suitable for binding at the top or
4232 bottom."
4233 (interactive)
4234 (pr-toggle-tumble-menu t))
4237 ;;;###autoload
4238 (defun pr-toggle-landscape ()
4239 "Toggle landscape."
4240 (interactive)
4241 (pr-toggle-landscape-menu t))
4244 ;;;###autoload
4245 (defun pr-toggle-upside-down ()
4246 "Toggle upside-down."
4247 (interactive)
4248 (pr-toggle-upside-down-menu t))
4251 ;;;###autoload
4252 (defun pr-toggle-line ()
4253 "Toggle line number."
4254 (interactive)
4255 (pr-toggle-line-menu t))
4258 ;;;###autoload
4259 (defun pr-toggle-zebra ()
4260 "Toggle zebra stripes."
4261 (interactive)
4262 (pr-toggle-zebra-menu t))
4265 ;;;###autoload
4266 (defun pr-toggle-header ()
4267 "Toggle printing header."
4268 (interactive)
4269 (pr-toggle-header-menu t))
4272 ;;;###autoload
4273 (defun pr-toggle-header-frame ()
4274 "Toggle printing header frame."
4275 (interactive)
4276 (pr-toggle-header-frame-menu t))
4279 ;;;###autoload
4280 (defun pr-toggle-lock ()
4281 "Toggle menu lock."
4282 (interactive)
4283 (pr-toggle-lock-menu t))
4286 ;;;###autoload
4287 (defun pr-toggle-region ()
4288 "Toggle auto region."
4289 (interactive)
4290 (pr-toggle-region-menu t))
4293 ;;;###autoload
4294 (defun pr-toggle-mode ()
4295 "Toggle auto mode."
4296 (interactive)
4297 (pr-toggle-mode-menu t))
4300 ;;;###autoload
4301 (defun pr-customize (&rest ignore)
4302 "Customization of the `printing' group."
4303 (interactive)
4304 (customize-group 'printing))
4307 ;;;###autoload
4308 (defun lpr-customize (&rest ignore)
4309 "Customization of the `lpr' group."
4310 (interactive)
4311 (customize-group 'lpr))
4314 ;;;###autoload
4315 (defun pr-help (&rest ignore)
4316 "Help for the printing package."
4317 (interactive)
4318 (pr-show-setup pr-help-message "*Printing Help*"))
4321 ;;;###autoload
4322 (defun pr-ps-name ()
4323 "Interactively select a PostScript printer."
4324 (interactive)
4325 (pr-menu-set-ps-title
4326 (pr-complete-alist "PostScript printer"
4327 pr-ps-printer-alist pr-ps-name)))
4330 ;;;###autoload
4331 (defun pr-txt-name ()
4332 "Interactively select a text printer."
4333 (interactive)
4334 (pr-menu-set-txt-title
4335 (pr-complete-alist "Text printer"
4336 pr-txt-printer-alist pr-txt-name)))
4339 ;;;###autoload
4340 (defun pr-ps-utility ()
4341 "Interactively select a PostScript utility."
4342 (interactive)
4343 (pr-menu-set-utility-title
4344 (pr-complete-alist "Postscript utility"
4345 pr-ps-utility-alist pr-ps-utility)))
4348 ;;;###autoload
4349 (defun pr-show-ps-setup (&rest ignore)
4350 "Show current ps-print settings."
4351 (interactive)
4352 (pr-show-setup (ps-setup) "*PS Setup*"))
4355 ;;;###autoload
4356 (defun pr-show-pr-setup (&rest ignore)
4357 "Show current printing settings."
4358 (interactive)
4359 (pr-show-setup (pr-setup) "*PR Setup*"))
4362 ;;;###autoload
4363 (defun pr-show-lpr-setup (&rest ignore)
4364 "Show current lpr settings."
4365 (interactive)
4366 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4370 ;; Fast Commands
4373 ;;;###autoload
4374 (defun pr-ps-fast-fire (n-up &optional select)
4375 "Fast fire function for PostScript printing.
4377 If a region is active, the region will be printed instead of the whole buffer.
4378 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4379 `pr-mode-alist' will be used, that is, the current buffer or region will be
4380 printed using `pr-ps-mode-ps-print'.
4383 Interactively, you have the following situations:
4385 M-x pr-ps-fast-fire RET
4386 The command prompts the user for a N-UP value and printing will
4387 immediatelly be done using the current active printer.
4389 C-u M-x pr-ps-fast-fire RET
4390 C-u 0 M-x pr-ps-fast-fire RET
4391 The command prompts the user for a N-UP value and also for a current
4392 PostScript printer, then printing will immediatelly be done using the new
4393 current active printer.
4395 C-u 1 M-x pr-ps-fast-fire RET
4396 The command prompts the user for a N-UP value and also for a file name,
4397 and saves the PostScript image in that file instead of sending it to the
4398 printer.
4400 C-u 2 M-x pr-ps-fast-fire RET
4401 The command prompts the user for a N-UP value, then for a current
4402 PostScript printer and, finally, for a file name. Then change the active
4403 printer to that choosen by user and saves the PostScript image in
4404 that file instead of sending it to the printer.
4407 Noninteractively, the argument N-UP should be a positive integer greater than
4408 zero and the argument SELECT is treated as follows:
4410 If it's nil, send the image to the printer.
4412 If it's a list or an integer lesser or equal to zero, the command prompts
4413 the user for a current PostScript printer, then printing will immediatelly
4414 be done using the new current active printer.
4416 If it's an integer equal to 1, the command prompts the user for a file name
4417 and saves the PostScript image in that file instead of sending it to the
4418 printer.
4420 If it's an integer greater or equal to 2, the command prompts the user for a
4421 current PostScript printer and for a file name. Then change the active
4422 printer to that choosen by user and saves the PostScript image in that file
4423 instead of sending it to the printer.
4425 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4426 active printer and printing will immediatelly be done using the new active
4427 printer.
4429 Otherwise, send the image to the printer.
4432 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4433 are both set to t."
4434 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4435 current-prefix-arg))
4436 (let ((pr-auto-region t)
4437 (pr-auto-mode t)
4438 filename)
4439 (cond ((null select))
4440 ((listp select)
4441 (pr-ps-name))
4442 ((and (symbolp select)
4443 (assq select pr-ps-printer-alist))
4444 (pr-menu-set-ps-title select))
4445 ((integerp select)
4446 (and (/= select 1)
4447 (pr-ps-name))
4448 (and (>= select 1) (not pr-spool-p)
4449 (setq filename (pr-ps-outfile-preprint
4450 (if pr-print-using-ghostscript
4451 "Fast GS "
4452 "Fast "))))))
4453 (pr-ps-buffer-ps-print
4454 (if (integerp n-up)
4455 (min (max n-up 1) 100)
4456 (error "n-up must be an integer greater than zero"))
4457 filename)))
4460 ;;;###autoload
4461 (defun pr-txt-fast-fire (&optional select-printer)
4462 "Fast fire function for text printing.
4464 If a region is active, the region will be printed instead of the whole buffer.
4465 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4466 `pr-mode-alist' will be used, that is, the current buffer or region will be
4467 printed using `pr-txt-mode'.
4469 Interactively, when you use a prefix argument (C-u), the command prompts the
4470 user for a new active text printer.
4472 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4474 If it's nil, the printing is sent to the current active text printer.
4476 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4477 active printer and printing will immediatelly be done using the new active
4478 printer.
4480 If it's non-nil, the command prompts the user for a new active text printer.
4482 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4483 are both set to t."
4484 (interactive (list current-prefix-arg))
4485 (cond ((null select-printer))
4486 ((and (symbolp select-printer)
4487 (assq select-printer pr-txt-printer-alist))
4488 (pr-menu-set-txt-title select-printer))
4490 (pr-txt-name)))
4491 (let ((pr-auto-region t)
4492 (pr-auto-mode t))
4493 (pr-txt-buffer)))
4496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4497 ;; Utilities
4500 (defun pr-setup ()
4501 "Return the current `printing' setup.
4503 This is *not* an interactive command.
4504 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4506 M-: (insert (pr-setup)) RET
4508 Or choose the menu option Printing/Show Settings/printing."
4509 (let (ps-prefix-quote)
4510 (mapconcat
4511 #'ps-print-quote
4512 (list
4513 (concat "\n;;; printing.el version " pr-version "\n")
4514 ";; internal vars"
4515 (ps-comment-string "emacs-version " emacs-version)
4516 (ps-comment-string "pr-txt-command " pr-txt-command)
4517 (ps-comment-string "pr-txt-switches "
4518 (pr-switches-string pr-txt-switches "pr-txt-switches"))
4519 (ps-comment-string "pr-txt-printer " pr-txt-printer)
4520 (ps-comment-string "pr-ps-command " pr-ps-command)
4521 (ps-comment-string "pr-ps-switches "
4522 (pr-switches-string pr-ps-switches "pr-ps-switches"))
4523 (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
4524 (ps-comment-string "pr-ps-printer " pr-ps-printer)
4525 (ps-comment-string "pr-cygwin-system " pr-cygwin-system)
4526 (ps-comment-string "ps-windows-system " ps-windows-system)
4527 (ps-comment-string "ps-lp-system " ps-lp-system)
4529 '(14 . pr-path-style)
4530 '(14 . pr-path-alist)
4532 '(21 . pr-txt-name)
4533 '(21 . pr-txt-printer-alist)
4535 '(20 . pr-ps-name)
4536 '(20 . pr-ps-printer-alist)
4538 '(20 . pr-temp-dir)
4539 '(20 . pr-ps-temp-file)
4540 '(20 . pr-file-modes)
4541 '(20 . pr-delete-temp-file)
4542 '(20 . pr-list-directory)
4544 '(17 . pr-gv-command)
4545 '(17 . pr-gs-command)
4546 '(17 . pr-gs-switches)
4547 '(17 . pr-gs-device)
4548 '(17 . pr-gs-resolution)
4550 '(27 . pr-print-using-ghostscript)
4551 '(27 . pr-faces-p)
4552 '(27 . pr-spool-p)
4553 '(27 . pr-file-landscape)
4554 '(27 . pr-file-duplex)
4555 '(27 . pr-file-tumble)
4556 '(27 . pr-auto-region)
4557 '(27 . pr-auto-mode)
4559 '(20 . pr-ps-utility)
4560 '(20 . pr-ps-utility-alist)
4562 '(14 . pr-mode-alist)
4564 '(20 . pr-menu-lock)
4565 '(20 . pr-menu-char-height)
4566 '(20 . pr-menu-char-width)
4568 '(20 . pr-setting-database)
4570 '(22 . pr-visible-entry-list)
4572 '(22 . pr-buffer-verbose)
4573 '(22 . pr-buffer-name)
4574 '(22 . pr-buffer-name-ignore)
4575 ")\n\n;;; printing.el - end of settings\n")
4576 "\n")))
4579 (defun lpr-setup ()
4580 "Return the current `lpr' setup.
4582 This is *not* an interactive command.
4583 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4585 M-: (insert (lpr-setup)) RET
4587 Or choose the menu option Printing/Show Settings/lpr."
4588 (let (ps-prefix-quote)
4589 (mapconcat
4590 #'ps-print-quote
4591 (list
4592 "\n;;; lpr.el settings\n"
4593 (ps-comment-string "emacs-version" emacs-version)
4595 '(25 . printer-name)
4596 '(25 . lpr-switches)
4597 '(25 . lpr-add-switches)
4598 '(25 . lpr-command)
4599 '(25 . lpr-headers-switches)
4600 '(25 . print-region-function)
4601 '(25 . lpr-page-header-program)
4602 '(25 . lpr-page-header-switches)
4603 ")\n\n;;; lpr.el - end of settings\n")
4604 "\n")))
4607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4608 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4611 (defalias 'pr-mh-get-msg-num 'mh-get-msg-num)
4612 (defalias 'pr-mh-show 'mh-show)
4613 (defalias 'pr-mh-start-of-uncleaned-message 'mh-start-of-uncleaned-message)
4614 (defvar mh-show-buffer nil)
4617 (defun pr-article-date ()
4618 "Find the date of an article or mail message in current buffer.
4619 Return only the dayname, if present, weekday, month, and year."
4620 (save-excursion
4621 (goto-char (point-min))
4622 (if (re-search-forward
4623 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4624 (buffer-substring (match-beginning 1) (match-end 1))
4625 (format-time-string "%Y/%m/%d"))))
4628 (defun pr-mh-current-message ()
4629 "Go to mh-inbox current message."
4630 (let ((msg (or (pr-mh-get-msg-num nil) 0)))
4631 (pr-mh-show)
4632 (set-buffer mh-show-buffer)
4633 (goto-char (point-min))
4634 (pr-mh-start-of-uncleaned-message)
4635 (message "Printing message %d" msg)))
4638 (defun pr-mh-print-1 (n-up filename header-list)
4639 "Print mh-inbox current message in PostScript."
4640 (save-excursion
4641 (save-window-excursion
4642 (pr-mh-current-message)
4643 (pr-mode-print n-up filename header-list (point)))))
4646 (defun pr-mh-lpr-1 (header-list)
4647 "Print mh-inbox current message in text printer."
4648 (save-excursion
4649 (save-window-excursion
4650 (pr-mh-current-message)
4651 (pr-mode-lpr header-list (point)))))
4654 (defalias 'pr-mh-print-2 'pr-mode-print)
4657 (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
4660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4661 ;; rmail (hacked from ps-print.el)
4664 (defun pr-rmail-lpr (header-list)
4665 "Print RMAIL current message in text printer."
4666 (pr-lpr-message-from-summary header-list
4667 'rmail-buffer 'rmail-summary-buffer))
4670 (defun pr-rmail-print (n-up filename header-list)
4671 "Print RMAIL current message in PostScript."
4672 (pr-ps-message-from-summary n-up filename header-list
4673 'rmail-buffer 'rmail-summary-buffer))
4676 (defun pr-ps-message-from-summary (n-up filename header-list
4677 summary-buffer summary-default)
4678 "Print current message in PostScript."
4679 (let ((buf (or (and (boundp summary-buffer)
4680 (symbol-value summary-buffer))
4681 (symbol-value summary-default))))
4682 (and (get-buffer buf)
4683 (save-excursion
4684 (set-buffer buf)
4685 (pr-mode-print n-up filename header-list)))))
4688 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
4689 "Print current message in text printer."
4690 (let ((buf (or (and (boundp summary-buffer)
4691 (symbol-value summary-buffer))
4692 (symbol-value summary-default))))
4693 (and (get-buffer buf)
4694 (save-excursion
4695 (set-buffer buf)
4696 (pr-mode-lpr header-list)))))
4699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4700 ;; gnus (hacked from ps-print.el)
4703 (defvar pr-gnus-article "*Article*")
4706 (defun pr-gnus-print (n-up filename header-list)
4707 "Print *Article* current message in PostScript."
4708 (pr-ps-message-from-summary n-up filename header-list
4709 'gnus-article-buffer 'pr-gnus-article))
4712 (defun pr-gnus-lpr (header-list)
4713 "Print *Article* current message in text printer."
4714 (pr-lpr-message-from-summary header-list
4715 'gnus-article-buffer 'pr-gnus-article))
4718 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4719 ;; vm (hacked from ps-print.el)
4722 (defvar pr-vm-summary "")
4725 (defun pr-vm-print (n-up filename header-list)
4726 "Print current vm message in PostScript."
4727 (pr-ps-message-from-summary n-up filename header-list
4728 'vm-mail-buffer 'pr-vm-summary))
4731 (defun pr-vm-lpr (header-list)
4732 "Print current vm message in text printer."
4733 (pr-lpr-message-from-summary header-list
4734 'vm-mail-buffer 'pr-vm-summary))
4737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4738 ;; Mode Functions
4741 (defun pr-ps-mode (n-up filename)
4742 "If current major mode is declared, print it in PostScript."
4743 (let ((args (pr-mode-alist-p)))
4744 (if args
4745 (let ((fun (cdr args)))
4746 (funcall (car fun) n-up filename (cdr fun))
4748 (ding)
4749 (message "`%s' major mode not declared." major-mode)
4750 nil)))
4753 (defmacro pr-local-variable (header-list &rest body)
4754 `(save-excursion
4755 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
4756 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
4757 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
4758 ps-razzle-dazzle)
4759 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
4760 ,@body
4761 (and (nth 3 ,header-list)
4762 (pr-kill-local-variable local-var-list))))))
4765 (defun pr-mode-print (n-up filename header-list &optional from to)
4766 "Print current major mode in PostScript."
4767 (pr-local-variable
4768 header-list
4769 (let ((file (pr-ps-file filename))
4770 (start (cond (from)
4771 ((pr-region-active-p) (region-beginning))
4772 (t nil)
4774 (pr-text2ps (pr-region-active-symbol start) n-up file start
4775 (cond (to)
4776 ((pr-region-active-p) (region-end))
4777 (from (point-max))
4779 (unless (or pr-spool-p filename)
4780 (pr-ps-file-print file)
4781 (pr-delete-file file)))))
4784 (defun pr-mode-lpr (header-list &optional from to)
4785 "Print current major mode in text printer."
4786 (pr-local-variable
4787 header-list
4788 (pr-txt-print (cond (from)
4789 ((pr-region-active-p) (region-beginning))
4790 (t (point-min)))
4791 (cond (to)
4792 ((pr-region-active-p) (region-end))
4793 (t (point-max))))))
4796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4797 ;; Menu Lock
4800 (defconst pr-menu-entry-alist
4801 '((postscript . 3)
4802 (text . 3)
4803 (postscript-options . 9)
4804 (postscript-process . 3)
4805 (printing . 3)
4806 (help . 3)
4808 "Alist that associates menu part with number of items per part.
4810 It's used by `pr-menu-index'.
4812 Each element has the form:
4814 (MENU-PART . NUMBER-OF-ITEMS)
4816 See `pr-visible-entry-alist'.")
4819 (defun pr-menu-index (entry index)
4820 (let ((base-list
4821 (cond ((eq entry 'text)
4822 '(postscript))
4823 ((eq entry 'postscript-options)
4824 '(postscript text))
4825 ((eq entry 'postscript-process)
4826 '(postscript text postscript-options))
4827 ((eq entry 'printing)
4828 '(postscript text postscript-options postscript-process))
4830 nil)
4832 key)
4833 (while base-list
4834 (setq key (car base-list)
4835 base-list (cdr base-list))
4836 (and (pr-visible-p key)
4837 (setq index (+ index
4838 (cdr (assq key pr-menu-entry-alist)))))))
4839 (+ index 2))
4842 (defvar pr-menu-position nil)
4843 (defvar pr-menu-state nil)
4846 (cond
4847 ((featurep 'xemacs)
4848 ;; XEmacs
4849 (defvar current-mouse-event nil) ; to avoid compilation gripes
4850 (defun pr-menu-position (entry index horizontal)
4851 (pr-x-make-event
4852 'button-release
4853 (list 'button 1
4854 'x (- (pr-x-event-x-pixel current-mouse-event) ; X
4855 (* horizontal pr-menu-char-width))
4856 'y (- (pr-x-event-y-pixel current-mouse-event) ; Y
4857 (* (pr-menu-index entry index) pr-menu-char-height)))))
4859 (ps-windows-system
4860 ;; GNU Emacs for Windows 9x/NT
4861 (defun pr-menu-position (entry index horizontal)
4862 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4863 (list
4864 (list (or (car pos) 0) ; X
4865 (- (or (cdr pos) 0) ; Y
4866 (* (pr-menu-index entry index) pr-menu-char-height)))
4867 (selected-frame)))) ; frame
4870 ;; GNU Emacs
4871 (defun pr-menu-position (entry index horizontal)
4872 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4873 (list
4874 (list (- (or (car pos) 0) ; X
4875 (* horizontal pr-menu-char-width))
4876 (- (or (cdr pos) 0) ; Y
4877 (* (pr-menu-index entry index) pr-menu-char-height)))
4878 (selected-frame)))) ; frame
4881 (cond
4882 ((featurep 'xemacs)
4883 ;; XEmacs
4884 (defvar current-menubar nil) ; to avoid compilation gripes
4885 (defun pr-menu-lookup (path)
4886 (car (pr-x-find-menu-item current-menubar (cons "Printing" path))))
4888 ;; XEmacs
4889 (defun pr-menu-lock (entry index horizontal state path)
4890 (when pr-menu-lock
4891 (or (and pr-menu-position (eq state pr-menu-state))
4892 (setq pr-menu-position (pr-menu-position entry index horizontal)
4893 pr-menu-state state))
4894 (let* ((menu (pr-menu-lookup path))
4895 (result (pr-x-get-popup-menu-response menu pr-menu-position)))
4896 (and (pr-x-misc-user-event-p result)
4897 (funcall (pr-x-event-function result)
4898 (pr-x-event-object result))))
4899 (setq pr-menu-position nil))))
4903 ;; GNU Emacs
4904 (defun pr-menu-lookup (path)
4905 (lookup-key global-map
4906 (if path
4907 (vconcat pr-menu-bar
4908 (mapcar 'pr-get-symbol
4909 (if (listp path)
4910 path
4911 (list path))))
4912 pr-menu-bar)))
4914 ;; GNU Emacs
4915 (defun pr-menu-lock (entry index horizontal state path)
4916 (when pr-menu-lock
4917 (or (and pr-menu-position (eq state pr-menu-state))
4918 (setq pr-menu-position (pr-menu-position entry index horizontal)
4919 pr-menu-state state))
4920 (let* ((menu (pr-menu-lookup path))
4921 (result (x-popup-menu pr-menu-position menu)))
4922 (and result
4923 (let ((command (lookup-key menu (vconcat result))))
4924 (if (fboundp command)
4925 (funcall command)
4926 (eval command)))))
4927 (setq pr-menu-position nil)))))
4930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4931 ;; Printer & Utility Selection
4934 (defun pr-update-var (var-sym alist)
4935 (or (assq (symbol-value var-sym) alist)
4936 (set var-sym (car (car alist)))))
4939 (defun pr-update-menus (&optional force)
4940 "Update utility, PostScript and text printer menus.
4942 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
4943 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
4944 otherwise, update PostScript printer menu iff `pr-ps-printer-menu-modified' is
4945 non-nil, update text printer menu iff `pr-txt-printer-menu-modified' is
4946 non-nil, and update PostScript File menus iff `pr-ps-utility-menu-modified' is
4947 non-nil.
4949 If menu binding was not done, calls `pr-menu-bind'."
4950 (interactive "P")
4951 (if pr-menu-print-item ; since v6.8.4
4952 ;; There was no menu binding yet, so do it now!
4953 ;; This is a hack to be compatible with old versions of printing.
4954 ;; So, user does not need to change printing calling in init files.
4955 (pr-menu-bind)
4956 ;; Here menu binding is ok.
4957 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
4958 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
4959 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
4960 (pr-do-update-menus force)))
4963 (defvar pr-ps-printer-menu-modified t
4964 "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
4965 (defvar pr-txt-printer-menu-modified t
4966 "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
4967 (defvar pr-ps-utility-menu-modified t
4968 "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
4971 (defconst pr-even-or-odd-alist
4972 '((nil . "Print All Pages")
4973 (even-page . "Print Even Pages")
4974 (odd-page . "Print Odd Pages")
4975 (even-sheet . "Print Even Sheets")
4976 (odd-sheet . "Print Odd Sheets")))
4979 (defun pr-menu-create (name alist var-sym fun entry index)
4980 (cons name
4981 (mapcar
4982 #'(lambda (elt)
4983 (let ((sym (car elt)))
4984 (vector
4985 (symbol-name sym)
4986 (list fun (list 'quote sym) nil (list 'quote entry) index)
4987 :style 'radio
4988 :selected (list 'eq var-sym (list 'quote sym)))))
4989 alist)))
4992 (cond
4993 ((featurep 'xemacs)
4994 ;; XEmacs
4995 (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
4997 ;; XEmacs
4998 (defvar pr-ps-name-old "PostScript Printers")
4999 (defvar pr-txt-name-old "Text Printers")
5000 (defvar pr-ps-utility-old "PostScript Utility")
5001 (defvar pr-even-or-odd-old "Print All Pages")
5003 ;; XEmacs
5004 (defun pr-do-update-menus (&optional force)
5005 (pr-menu-alist pr-ps-printer-alist
5006 'pr-ps-name
5007 'pr-menu-set-ps-title
5008 '("Printing")
5009 'pr-ps-printer-menu-modified
5010 force
5011 pr-ps-name-old
5012 'postscript 2)
5013 (pr-menu-alist pr-txt-printer-alist
5014 'pr-txt-name
5015 'pr-menu-set-txt-title
5016 '("Printing")
5017 'pr-txt-printer-menu-modified
5018 force
5019 pr-txt-name-old
5020 'text 2)
5021 (let ((save-var pr-ps-utility-menu-modified))
5022 (pr-menu-alist pr-ps-utility-alist
5023 'pr-ps-utility
5024 'pr-menu-set-utility-title
5025 '("Printing" "PostScript Print" "File")
5026 'save-var
5027 force
5028 pr-ps-utility-old
5029 nil 1))
5030 (pr-menu-alist pr-ps-utility-alist
5031 'pr-ps-utility
5032 'pr-menu-set-utility-title
5033 '("Printing" "PostScript Preview" "File")
5034 'pr-ps-utility-menu-modified
5035 force
5036 pr-ps-utility-old
5037 nil 1)
5038 (pr-even-or-odd-pages ps-even-or-odd-pages force))
5040 ;; XEmacs
5041 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
5042 entry index)
5043 (when (and alist (or force (symbol-value modified-sym)))
5044 (pr-xemacs-global-menubar
5045 (pr-x-add-submenu menu-path
5046 (pr-menu-create name alist var-sym
5047 fun entry index)))
5048 (funcall fun (symbol-value var-sym))
5049 (set modified-sym nil)))
5051 ;; XEmacs
5052 (defun pr-relabel-menu-item (newname var-sym)
5053 (pr-xemacs-global-menubar
5054 (pr-x-relabel-menu-item
5055 (list "Printing" (symbol-value var-sym))
5056 newname)
5057 (set var-sym newname)))
5059 ;; XEmacs
5060 (defun pr-menu-set-ps-title (value &optional item entry index)
5061 (pr-relabel-menu-item (format "PostScript Printer: %s" value)
5062 'pr-ps-name-old)
5063 (pr-ps-set-printer value)
5064 (and index
5065 (pr-menu-lock entry index 12 'toggle nil)))
5067 ;; XEmacs
5068 (defun pr-menu-set-txt-title (value &optional item entry index)
5069 (pr-relabel-menu-item (format "Text Printer: %s" value)
5070 'pr-txt-name-old)
5071 (pr-txt-set-printer value)
5072 (and index
5073 (pr-menu-lock entry index 12 'toggle nil)))
5075 ;; XEmacs
5076 (defun pr-menu-set-utility-title (value &optional item entry index)
5077 (pr-xemacs-global-menubar
5078 (let ((newname (format "%s" value)))
5079 (pr-x-relabel-menu-item
5080 (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
5081 newname)
5082 (pr-x-relabel-menu-item
5083 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
5084 newname)
5085 (setq pr-ps-utility-old newname)))
5086 (pr-ps-set-utility value)
5087 (and index
5088 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
5090 ;; XEmacs
5091 (defun pr-even-or-odd-pages (value &optional no-lock)
5092 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
5093 'pr-even-or-odd-old)
5094 (setq ps-even-or-odd-pages value)
5095 (or no-lock
5096 (pr-menu-lock 'postscript-options 8 12 'toggle nil))))
5100 ;; GNU Emacs
5101 (defalias 'pr-update-mode-line 'force-mode-line-update)
5103 ;; GNU Emacs
5104 (defun pr-do-update-menus (&optional force)
5105 (pr-menu-alist pr-ps-printer-alist
5106 'pr-ps-name
5107 'pr-menu-set-ps-title
5108 "PostScript Printers"
5109 'pr-ps-printer-menu-modified
5110 force
5111 "PostScript Printers"
5112 'postscript 2)
5113 (pr-menu-alist pr-txt-printer-alist
5114 'pr-txt-name
5115 'pr-menu-set-txt-title
5116 "Text Printers"
5117 'pr-txt-printer-menu-modified
5118 force
5119 "Text Printers"
5120 'text 2)
5121 (let ((save-var pr-ps-utility-menu-modified))
5122 (pr-menu-alist pr-ps-utility-alist
5123 'pr-ps-utility
5124 'pr-menu-set-utility-title
5125 '("PostScript Print" "File" "PostScript Utility")
5126 'save-var
5127 force
5128 "PostScript Utility"
5129 nil 1))
5130 (pr-menu-alist pr-ps-utility-alist
5131 'pr-ps-utility
5132 'pr-menu-set-utility-title
5133 '("PostScript Preview" "File" "PostScript Utility")
5134 'pr-ps-utility-menu-modified
5135 force
5136 "PostScript Utility"
5137 nil 1)
5138 (pr-even-or-odd-pages ps-even-or-odd-pages force))
5140 ;; GNU Emacs
5141 (defun pr-menu-get-item (name-list)
5142 ;; NAME-LIST is a string or a list of strings.
5143 (or (listp name-list)
5144 (setq name-list (list name-list)))
5145 (and name-list
5146 (let* ((reversed (reverse name-list))
5147 (name (pr-get-symbol (car reversed)))
5148 (path (nreverse (cdr reversed)))
5149 (menu (lookup-key
5150 global-map
5151 (vconcat pr-menu-bar
5152 (mapcar 'pr-get-symbol path)))))
5153 (assq name (nthcdr 2 menu)))))
5155 ;; GNU Emacs
5156 (defvar pr-temp-menu nil)
5158 ;; GNU Emacs
5159 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
5160 entry index)
5161 (when (and alist (or force (symbol-value modified-sym)))
5162 (easy-menu-define pr-temp-menu nil ""
5163 (pr-menu-create name alist var-sym fun entry index))
5164 (let ((item (pr-menu-get-item menu-path)))
5165 (and item
5166 (let* ((binding (nthcdr 3 item))
5167 (key-binding (cdr binding)))
5168 (setcar binding pr-temp-menu)
5169 (and key-binding (listp (car key-binding))
5170 (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
5171 (funcall fun (symbol-value var-sym) item))))
5172 (set modified-sym nil)))
5174 ;; GNU Emacs
5175 (defun pr-menu-set-item-name (item name)
5176 (and item
5177 (setcar (nthcdr 2 item) name))) ; ITEM-NAME
5179 ;; GNU Emacs
5180 (defun pr-menu-set-ps-title (value &optional item entry index)
5181 (pr-menu-set-item-name (or item
5182 (pr-menu-get-item "PostScript Printers"))
5183 (format "PostScript Printer: %s" value))
5184 (pr-ps-set-printer value)
5185 (and index
5186 (pr-menu-lock entry index 12 'toggle nil)))
5188 ;; GNU Emacs
5189 (defun pr-menu-set-txt-title (value &optional item entry index)
5190 (pr-menu-set-item-name (or item
5191 (pr-menu-get-item "Text Printers"))
5192 (format "Text Printer: %s" value))
5193 (pr-txt-set-printer value)
5194 (and index
5195 (pr-menu-lock entry index 12 'toggle nil)))
5197 ;; GNU Emacs
5198 (defun pr-menu-set-utility-title (value &optional item entry index)
5199 (let ((name (symbol-name value)))
5200 (if item
5201 (pr-menu-set-item-name item name)
5202 (pr-menu-set-item-name
5203 (pr-menu-get-item
5204 '("PostScript Print" "File" "PostScript Utility"))
5205 name)
5206 (pr-menu-set-item-name
5207 (pr-menu-get-item
5208 '("PostScript Preview" "File" "PostScript Utility"))
5209 name)))
5210 (pr-ps-set-utility value)
5211 (and index
5212 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
5214 ;; GNU Emacs
5215 (defun pr-even-or-odd-pages (value &optional no-lock)
5216 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
5217 (cdr (assq value pr-even-or-odd-alist)))
5218 (setq ps-even-or-odd-pages value)
5219 (or no-lock
5220 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))))
5223 (defun pr-ps-set-utility (value)
5224 (let ((item (cdr (assq value pr-ps-utility-alist))))
5225 (or item
5226 (error
5227 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
5228 value))
5229 (setq pr-ps-utility value)
5230 (pr-eval-alist (nthcdr 9 item)))
5231 (pr-update-mode-line))
5234 (defun pr-ps-set-printer (value)
5235 (let ((ps (cdr (assq value pr-ps-printer-alist))))
5236 (or ps
5237 (error
5238 "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
5239 value))
5240 (setq pr-ps-name value
5241 pr-ps-command (pr-dosify-file-name (nth 0 ps))
5242 pr-ps-switches (nth 1 ps)
5243 pr-ps-printer-switch (nth 2 ps)
5244 pr-ps-printer (nth 3 ps))
5245 (or (stringp pr-ps-command)
5246 (setq pr-ps-command
5247 (cond (ps-windows-system "print")
5248 (ps-lp-system "lp")
5249 (t "lpr")
5251 (or (stringp pr-ps-printer-switch)
5252 (setq pr-ps-printer-switch
5253 (cond (ps-windows-system "/D:")
5254 (ps-lp-system "-d")
5255 (t "-P")
5257 (pr-eval-alist (nthcdr 4 ps)))
5258 (pr-update-mode-line))
5261 (defun pr-txt-set-printer (value)
5262 (let ((txt (cdr (assq value pr-txt-printer-alist))))
5263 (or txt
5264 (error "Invalid text printer name `%s' for variable `pr-txt-name'"
5265 value))
5266 (setq pr-txt-name value
5267 pr-txt-command (pr-dosify-file-name (nth 0 txt))
5268 pr-txt-switches (nth 1 txt)
5269 pr-txt-printer (nth 2 txt)))
5270 (or (stringp pr-txt-command)
5271 (setq pr-txt-command
5272 (cond (ps-windows-system "print")
5273 (ps-lp-system "lp")
5274 (t "lpr")
5276 (pr-update-mode-line))
5279 (defun pr-eval-alist (alist)
5280 (mapcar #'(lambda (option)
5281 (let ((var-sym (car option))
5282 (value (cdr option)))
5283 (if (eq var-sym 'inherits-from:)
5284 (pr-eval-setting-alist value 'global)
5285 (set var-sym (eval value)))))
5286 alist))
5289 (defun pr-eval-local-alist (alist)
5290 (let (local-list)
5291 (mapcar #'(lambda (option)
5292 (let ((var-sym (car option))
5293 (value (cdr option)))
5294 (setq local-list
5295 (if (eq var-sym 'inherits-from:)
5296 (nconc (pr-eval-setting-alist value) local-list)
5297 (set (make-local-variable var-sym) (eval value))
5298 (cons var-sym local-list)))))
5299 alist)
5300 local-list))
5303 (defun pr-eval-setting-alist (key &optional global old)
5304 (let ((setting (cdr (assq key pr-setting-database))))
5305 (and setting
5306 (let ((inherits (nth 0 setting))
5307 (local (nth 1 setting))
5308 (kill (nth 2 setting))
5309 local-list)
5310 (and local global
5311 (progn
5312 (ding)
5313 (message "There are local buffer settings for `%S'." key)
5314 (setq global nil)))
5315 (and inherits
5316 (if (memq inherits old)
5317 (error "Circular inheritance for `%S'" inherits)
5318 (setq local-list
5319 (pr-eval-setting-alist inherits global
5320 (cons inherits old)))))
5321 (mapcar
5322 (cond ((not local) ; global settings
5323 #'(lambda (option)
5324 (let ((var-sym (car option)))
5325 (or (eq var-sym 'inherits-from:)
5326 (set var-sym (eval (cdr option)))))))
5327 (kill ; local settings with killing
5328 #'(lambda (option)
5329 (let ((var-sym (car option)))
5330 (unless (eq var-sym 'inherits-from:)
5331 (setq local-list (cons var-sym local-list))
5332 (set (make-local-variable var-sym)
5333 (eval (cdr option)))))))
5334 (t ; local settings without killing
5335 #'(lambda (option)
5336 (let ((var-sym (car option)))
5337 (or (eq var-sym 'inherits-from:)
5338 (set (make-local-variable var-sym)
5339 (eval (cdr option))))))))
5340 (nthcdr 3 setting))
5341 local-list))))
5344 (defun pr-kill-local-variable (local-var-list)
5345 (mapcar 'kill-local-variable local-var-list))
5348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5349 ;; Internal Functions (II)
5352 (defun pr-toggle (var-sym mess entry index horizontal state
5353 &optional path no-menu)
5354 (set var-sym (not (symbol-value var-sym)))
5355 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5356 (or no-menu
5357 (pr-menu-lock entry index horizontal state path)))
5360 (defun pr-toggle-file-duplex-menu (&optional no-menu)
5361 (interactive)
5362 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
5363 '("PostScript Print" "File") no-menu))
5366 (defun pr-toggle-file-tumble-menu (&optional no-menu)
5367 (interactive)
5368 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
5369 '("PostScript Print" "File") no-menu))
5372 (defun pr-toggle-file-landscape-menu (&optional no-menu)
5373 (interactive)
5374 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
5375 '("PostScript Print" "File") no-menu))
5378 (defun pr-toggle-ghostscript-menu (&optional no-menu)
5379 (interactive)
5380 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
5381 'postscript-process 2 12 'toggle nil no-menu))
5384 (defun pr-toggle-faces-menu (&optional no-menu)
5385 (interactive)
5386 (pr-toggle 'pr-faces-p "Printing with faces"
5387 'postscript-process 1 12 'toggle nil no-menu))
5390 (defun pr-toggle-spool-menu (&optional no-menu)
5391 (interactive)
5392 (pr-toggle 'pr-spool-p "Spooling printing"
5393 'postscript-process 0 12 'toggle nil no-menu))
5396 (defun pr-toggle-duplex-menu (&optional no-menu)
5397 (interactive)
5398 (pr-toggle 'ps-spool-duplex "Printing duplex"
5399 'postscript-options 5 12 'toggle nil no-menu))
5402 (defun pr-toggle-tumble-menu (&optional no-menu)
5403 (interactive)
5404 (pr-toggle 'ps-spool-tumble "Tumble"
5405 'postscript-options 6 12 'toggle nil no-menu))
5408 (defun pr-toggle-landscape-menu (&optional no-menu)
5409 (interactive)
5410 (pr-toggle 'ps-landscape-mode "Landscape"
5411 'postscript-options 0 12 'toggle nil no-menu))
5414 (defun pr-toggle-upside-down-menu (&optional no-menu)
5415 (interactive)
5416 (pr-toggle 'ps-print-upside-down "Upside-Down"
5417 'postscript-options 7 12 'toggle nil no-menu))
5420 (defun pr-toggle-line-menu (&optional no-menu)
5421 (interactive)
5422 (pr-toggle 'ps-line-number "Line number"
5423 'postscript-options 3 12 'toggle nil no-menu))
5426 (defun pr-toggle-zebra-menu (&optional no-menu)
5427 (interactive)
5428 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
5429 'postscript-options 4 12 'toggle nil no-menu))
5432 (defun pr-toggle-header-menu (&optional no-menu)
5433 (interactive)
5434 (pr-toggle 'ps-print-header "Print header"
5435 'postscript-options 1 12 'toggle nil no-menu))
5438 (defun pr-toggle-header-frame-menu (&optional no-menu)
5439 (interactive)
5440 (pr-toggle 'ps-print-header-frame "Print header frame"
5441 'postscript-options 2 12 'toggle nil no-menu))
5444 (defun pr-toggle-lock-menu (&optional no-menu)
5445 (interactive)
5446 (pr-toggle 'pr-menu-lock "Menu lock"
5447 'printing 2 12 'toggle nil no-menu))
5450 (defun pr-toggle-region-menu (&optional no-menu)
5451 (interactive)
5452 (pr-toggle 'pr-auto-region "Auto region"
5453 'printing 0 12 'toggle nil no-menu))
5456 (defun pr-toggle-mode-menu (&optional no-menu)
5457 (interactive)
5458 (pr-toggle 'pr-auto-mode "Auto mode"
5459 'printing 1 12 'toggle nil no-menu))
5462 (defun pr-prompt (str)
5463 (if (pr-auto-mode-p)
5464 (concat str " mode")
5465 (pr-region-active-string str)))
5468 (defun pr-prompt-region (str)
5469 (concat str (if (pr-auto-mode-p)
5470 " mode"
5471 " region")))
5474 (defun pr-prompt-gs (str)
5475 (if (pr-using-ghostscript-p)
5476 (concat str " GS")
5477 str))
5480 (defun pr-region-active-symbol (&optional region-p)
5481 (if (or region-p (pr-region-active-p))
5482 'region
5483 'buffer))
5486 (defun pr-region-active-string (prefix)
5487 (concat prefix
5488 (if (pr-region-active-p)
5489 " region"
5490 " buffer")))
5493 (defun pr-show-setup (settings buffer-name)
5494 (with-output-to-temp-buffer buffer-name
5495 (princ settings)
5496 (print-help-return-message)))
5499 (defun pr-complete-alist (prompt alist default)
5500 (let ((collection (mapcar #'(lambda (elt)
5501 (setq elt (car elt))
5502 (cons (symbol-name elt) elt))
5503 alist)))
5504 (cdr (assoc (completing-read (concat prompt ": ")
5505 collection nil t
5506 (symbol-name default) nil
5507 (symbol-name default))
5508 collection))))
5511 (defun pr-delete-file (file)
5512 (and pr-delete-temp-file (file-exists-p file)
5513 (delete-file file)))
5516 (defun pr-expand-file-name (filename)
5517 (pr-dosify-file-name (expand-file-name filename)))
5520 (defun pr-ps-outfile-preprint (&optional mess)
5521 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5522 (res (read-file-name prompt default-directory "" nil)))
5523 (while (cond ((not (file-writable-p res))
5524 (ding)
5525 (setq prompt "is unwritable"))
5526 ((file-directory-p res)
5527 (ding)
5528 (setq prompt "is a directory"))
5529 ((file-exists-p res)
5530 (ding)
5531 (setq prompt "exists")
5532 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5533 res))))
5534 (t nil))
5535 (setq res (read-file-name
5536 (format "File %s; PostScript file: " prompt)
5537 (file-name-directory res) nil nil
5538 (file-name-nondirectory res))))
5539 (pr-expand-file-name res)))
5542 (defun pr-ps-infile-preprint (&optional mess)
5543 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5544 (res (read-file-name prompt default-directory "" nil)))
5545 (while (cond ((not (file-exists-p res))
5546 (ding)
5547 (setq prompt "doesn't exist"))
5548 ((not (file-readable-p res))
5549 (ding)
5550 (setq prompt "is unreadable"))
5551 ((file-directory-p res)
5552 (ding)
5553 (setq prompt "is a directory"))
5554 (t nil))
5555 (setq res (read-file-name
5556 (format "File %s; PostScript file: " prompt)
5557 (file-name-directory res) nil nil
5558 (file-name-nondirectory res))))
5559 (pr-expand-file-name res)))
5562 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
5563 ;; check arguments for PostScript file processing.
5564 ;; n-up
5565 (or (symbol-value n-up-sym)
5566 (set n-up-sym (pr-interactive-n-up prompt)))
5567 ;; input file
5568 (and (eq (symbol-value infile-sym) t)
5569 (set infile-sym (pr-ps-infile-preprint prompt)))
5570 (or (symbol-value infile-sym)
5571 (error "%s: input PostScript file name is missing" prompt))
5572 (set infile-sym (pr-dosify-file-name (symbol-value infile-sym)))
5573 ;; output file
5574 (and (eq (symbol-value outfile-sym) t)
5575 (set outfile-sym (and current-prefix-arg
5576 (pr-ps-outfile-preprint prompt))))
5577 (and (symbol-value outfile-sym)
5578 (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym))))
5579 (pr-ps-file (symbol-value outfile-sym)))
5582 (defun pr-ps-utility-process (n-up infile outfile)
5583 ;; activate utility to process a PostScript file.
5584 (let (item)
5585 (and (stringp infile) (file-exists-p infile)
5586 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
5587 (pr-call-process (nth 0 item)
5588 (pr-switches-string (nth 1 item)
5589 "pr-ps-utility-alist entry")
5590 (pr-switches-string (nth 8 item)
5591 "pr-ps-utility-alist entry")
5592 (and (nth 2 item)
5593 (format (nth 2 item) ps-paper-type))
5594 (format (nth 3 item) n-up)
5595 (and pr-file-landscape (nth 4 item))
5596 (and pr-file-duplex (nth 5 item))
5597 (and pr-file-tumble (nth 6 item))
5598 (pr-expand-file-name infile)
5599 (nth 7 item)
5600 (pr-expand-file-name outfile)))))
5603 (defun pr-remove-nil-from-list (lst)
5604 (while (and lst (null (car lst)))
5605 (setq lst (cdr lst)))
5606 (let ((b lst)
5607 (l (cdr lst)))
5608 (while l
5609 (if (car l)
5610 (setq b l
5611 l (cdr l))
5612 (setq l (cdr l))
5613 (setcdr b l))))
5614 lst)
5617 (defun pr-call-process (command &rest args)
5618 (let ((buffer (get-buffer-create "*Printing Command Output*"))
5619 (cmd (pr-command command))
5620 status)
5621 (setq args (pr-remove-nil-from-list args))
5622 ;; *Printing Command Output* == show command & args
5623 (save-excursion
5624 (set-buffer buffer)
5625 (goto-char (point-max))
5626 (insert (format "%s %S\n" cmd args)))
5627 ;; *Printing Command Output* == show any return message from command
5628 (pr-save-file-modes
5629 (setq status
5630 (condition-case data
5631 (apply 'call-process cmd nil buffer nil args)
5632 ((quit error)
5633 (error-message-string data)))))
5634 ;; *Printing Command Output* == show exit status
5635 (save-excursion
5636 (set-buffer buffer)
5637 (goto-char (point-max))
5638 (insert (format "Exit status: %s\n\n" status)))
5639 ;; message if error status
5640 (if (or (stringp status)
5641 (and (integerp status) (/= status 0)))
5642 (message
5643 "Printing error status: %s (see *Printing Command Output* buffer)"
5644 status))))
5647 (defun pr-txt-print (from to)
5648 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command)))
5649 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5650 (printer-name pr-txt-printer))
5651 (lpr-region from to)))
5654 (defun pr-switches-string (switches mess)
5655 ;; If SWITCHES is nil, return nil.
5656 ;; Otherwise, return the list of string in a string.
5657 (and switches
5658 (mapconcat 'identity (pr-switches switches mess) " ")))
5661 (defun pr-switches (switches mess)
5662 (or (listp switches)
5663 (error "%S should have a list of strings" mess))
5664 (ps-flatten-list ; dynamic evaluation
5665 (mapcar 'ps-eval-switch switches)))
5668 (defun pr-ps-preview (kind n-up filename mess)
5669 (pr-set-n-up-and-filename 'n-up 'filename mess)
5670 (let ((file (pr-ps-file filename)))
5671 (pr-text2ps kind n-up file)
5672 (or pr-spool-p (pr-ps-file-preview file))))
5675 (defun pr-ps-using-ghostscript (kind n-up filename mess)
5676 (pr-set-n-up-and-filename 'n-up 'filename mess)
5677 (let ((file (pr-ps-file filename)))
5678 (pr-text2ps kind n-up file)
5679 (unless (or pr-spool-p filename)
5680 (pr-ps-file-using-ghostscript file)
5681 (pr-delete-file file))))
5684 (defun pr-ps-print (kind n-up filename mess)
5685 (pr-set-n-up-and-filename 'n-up 'filename mess)
5686 (let ((file (pr-ps-file filename)))
5687 (pr-text2ps kind n-up file)
5688 (unless (or pr-spool-p filename)
5689 (pr-ps-file-print file)
5690 (pr-delete-file file))))
5693 (defun pr-ps-file (&optional filename)
5694 (pr-dosify-file-name (or filename
5695 (make-temp-file
5696 (convert-standard-filename
5697 (expand-file-name pr-ps-temp-file pr-temp-dir))
5698 nil ".ps"))))
5701 (defun pr-interactive-n-up (mess)
5702 (or (stringp mess) (setq mess "*"))
5703 (save-match-data
5704 (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
5705 (prompt "")
5706 (str (pr-f-read-string (format fmt-prompt prompt mess) "1" nil "1"))
5707 int)
5708 (while (if (string-match "^\\s *[0-9]+$" str)
5709 (setq int (string-to-number str)
5710 prompt (cond ((< int 1) "Integer below 1; ")
5711 ((> int 100) "Integer above 100; ")
5712 (t nil)))
5713 (setq prompt "Invalid integer syntax; "))
5714 (ding)
5715 (setq str
5716 (pr-f-read-string (format fmt-prompt prompt mess) str nil "1")))
5717 int)))
5720 (defun pr-interactive-dir (mess)
5721 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5722 default-directory)))
5723 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
5724 (dir (read-file-name (format fmt-prompt "")
5725 "" dir-name nil dir-name))
5726 prompt)
5727 (while (cond ((not (file-directory-p dir))
5728 (ding)
5729 (setq prompt "It's not a directory! "))
5730 ((not (file-readable-p dir))
5731 (ding)
5732 (setq prompt "Directory is unreadable! "))
5733 (t nil))
5734 (setq dir-name (file-name-directory dir)
5735 dir (read-file-name (format fmt-prompt prompt)
5736 "" dir-name nil dir-name)))
5737 (file-name-as-directory dir)))
5740 (defun pr-interactive-regexp (mess)
5741 (pr-f-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
5744 (defun pr-interactive-dir-args (mess)
5745 (list
5746 ;; get directory argument
5747 (pr-interactive-dir mess)
5748 ;; get file name regexp
5749 (pr-interactive-regexp mess)))
5752 (defun pr-interactive-ps-dir-args (mess)
5753 (list
5754 ;; get n-up argument
5755 (pr-interactive-n-up mess)
5756 ;; get directory argument
5757 (pr-interactive-dir mess)
5758 ;; get file name regexp
5759 (pr-interactive-regexp mess)
5760 ;; get output file name
5761 (and (not pr-spool-p)
5762 (ps-print-preprint current-prefix-arg))))
5765 (defun pr-interactive-n-up-file (mess)
5766 (list
5767 ;; get n-up argument
5768 (pr-interactive-n-up mess)
5769 ;; get output file name
5770 (and (not pr-spool-p)
5771 (ps-print-preprint current-prefix-arg))))
5774 (defun pr-interactive-n-up-inout (mess)
5775 (list
5776 ;; get n-up argument
5777 (pr-interactive-n-up mess)
5778 ;; get input file name
5779 (pr-ps-infile-preprint (concat mess " "))
5780 ;; get output file name
5781 (ps-print-preprint current-prefix-arg)))
5784 (defun pr-set-outfilename (filename-sym)
5785 (and (not pr-spool-p)
5786 (eq (symbol-value filename-sym) t)
5787 (set filename-sym (and current-prefix-arg
5788 (ps-print-preprint current-prefix-arg))))
5789 (and (symbol-value filename-sym)
5790 (set filename-sym (pr-dosify-file-name (symbol-value filename-sym)))))
5793 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5794 ;; n-up
5795 (or (symbol-value n-up-sym)
5796 (set n-up-sym (pr-interactive-n-up mess)))
5797 ;; output file
5798 (pr-set-outfilename filename-sym))
5801 (defun pr-set-dir-args (dir-sym regexp-sym mess)
5802 ;; directory
5803 (or (symbol-value dir-sym)
5804 (set dir-sym (pr-interactive-dir mess)))
5805 ;; file name regexp
5806 (or (symbol-value regexp-sym)
5807 (set regexp-sym (pr-interactive-regexp mess))))
5810 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5811 ;; n-up
5812 (or (symbol-value n-up-sym)
5813 (set n-up-sym (pr-interactive-n-up mess)))
5814 ;; directory & file name regexp
5815 (pr-set-dir-args dir-sym regexp-sym mess)
5816 ;; output file
5817 (pr-set-outfilename filename-sym))
5820 (defun pr-find-buffer-visiting (file)
5821 (if (not (file-directory-p file))
5822 (find-buffer-visiting (if ps-windows-system
5823 (downcase file)
5824 file))
5825 (let ((truename (file-truename file))
5826 (blist (buffer-list))
5827 found)
5828 (while (and (not found) blist)
5829 (save-excursion
5830 (set-buffer (car blist))
5831 (and (eq major-mode 'dired-mode)
5832 (save-excursion
5833 (goto-char (point-min))
5834 (string= (buffer-substring-no-properties
5835 (+ (point-min) 2)
5836 (progn
5837 (end-of-line)
5838 (1- (point))))
5839 truename))
5840 (setq found (car blist))))
5841 (setq blist (cdr blist)))
5842 found)))
5845 (defun pr-file-list (dir file-regexp fun)
5846 (mapcar #'(lambda (file)
5847 (and (or pr-list-directory
5848 (not (file-directory-p file)))
5849 (let ((buffer (pr-find-buffer-visiting file))
5850 pop-up-windows
5851 pop-up-frames)
5852 (and (or buffer
5853 (file-readable-p file))
5854 (save-excursion
5855 (set-buffer (or buffer
5856 (find-file-noselect file)))
5857 (funcall fun)
5858 (or buffer
5859 (kill-buffer (current-buffer))))))))
5860 (directory-files dir t file-regexp)))
5863 (defun pr-delete-file-if-exists (filename)
5864 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5865 (delete-file filename)))
5868 (defun pr-ps-file-list (n-up dir file-regexp filename)
5869 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5870 (let ((pr-spool-p t))
5871 (pr-file-list dir file-regexp
5872 #'(lambda ()
5873 (if (pr-auto-mode-p)
5874 (pr-ps-mode n-up filename)
5875 (pr-text2ps 'buffer n-up filename)))))
5876 (or pr-spool-p
5877 (pr-despool-print filename)))
5880 (defun pr-text2ps (kind n-up filename &optional from to)
5881 (pr-save-file-modes
5882 (let ((ps-n-up-printing n-up)
5883 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5884 'setpagedevice)))
5885 (pr-delete-file-if-exists filename)
5886 (cond (pr-faces-p
5887 (cond (pr-spool-p
5888 ;; pr-faces-p and pr-spool-p
5889 ;; here FILENAME arg is ignored
5890 (cond ((eq kind 'buffer)
5891 (ps-spool-buffer-with-faces))
5892 ((eq kind 'region)
5893 (ps-spool-region-with-faces (or from (point))
5894 (or to (mark))))
5896 ;; pr-faces-p and not pr-spool-p
5897 ((eq kind 'buffer)
5898 (ps-print-buffer-with-faces filename))
5899 ((eq kind 'region)
5900 (ps-print-region-with-faces (or from (point))
5901 (or to (mark)) filename))
5903 (pr-spool-p
5904 ;; not pr-faces-p and pr-spool-p
5905 ;; here FILENAME arg is ignored
5906 (cond ((eq kind 'buffer)
5907 (ps-spool-buffer))
5908 ((eq kind 'region)
5909 (ps-spool-region (or from (point)) (or to (mark))))
5911 ;; not pr-faces-p and not pr-spool-p
5912 ((eq kind 'buffer)
5913 (ps-print-buffer filename))
5914 ((eq kind 'region)
5915 (ps-print-region (or from (point)) (or to (mark)) filename))
5916 ))))
5919 (defun pr-command (command)
5920 "Return absolute file name specification for COMMAND.
5922 If COMMAND is an empty string, return it.
5924 If COMMAND is already an absolute file name specification, return it.
5925 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5926 otherwise, gives an error.
5928 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5929 `unix' are used (see `pr-path-alist' for documentation).
5931 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5932 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5933 (if (string= command "")
5934 command
5935 (pr-dosify-file-name
5936 (or (pr-find-command command)
5937 (pr-path-command (cond (pr-cygwin-system 'cygwin)
5938 (ps-windows-system 'windows)
5939 (t 'unix))
5940 (file-name-nondirectory command)
5941 nil)
5942 (error "Command not found: %s"
5943 (file-name-nondirectory command))))))
5946 (defun pr-path-command (symbol command sym-list)
5947 (let ((lpath (cdr (assq symbol pr-path-alist)))
5948 cmd)
5949 ;; PATH expansion
5950 (and (eq symbol 'PATH) (null lpath)
5951 (setq lpath (parse-colon-path (getenv "PATH"))))
5952 (while (and lpath
5953 (not
5954 (setq cmd
5955 (let ((path (car lpath)))
5956 (cond
5957 ;; symbol expansion
5958 ((symbolp path)
5959 (and (not (memq path sym-list))
5960 (pr-path-command path command
5961 (cons path sym-list))))
5962 ;; normal path
5963 ((stringp path)
5964 (pr-find-command
5965 (expand-file-name
5966 (substitute-in-file-name
5967 (concat (file-name-as-directory path)
5968 command)))))
5969 )))))
5970 (setq lpath (cdr lpath)))
5971 cmd))
5974 (defun pr-find-command (cmd)
5975 (if ps-windows-system
5976 ;; windows system
5977 (let ((ext (cons (file-name-extension cmd t)
5978 (list ".exe" ".bat" ".com")))
5979 found)
5980 (setq cmd (file-name-sans-extension cmd))
5981 (while (and ext
5982 (setq found (concat cmd (car ext)))
5983 (not (and (file-regular-p found)
5984 (file-executable-p found))))
5985 (setq ext (cdr ext)
5986 found nil))
5987 found)
5988 ;; non-windows systems
5989 (and (file-regular-p cmd)
5990 (file-executable-p cmd)
5991 cmd)))
5994 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5995 ;; Printing Interface (inspired on ps-print-interface.el)
5998 (require 'widget)
5999 (require 'wid-edit)
6000 (require 'cus-edit)
6003 (defvar pr-i-window-configuration nil)
6005 (defvar pr-i-buffer nil)
6006 (defvar pr-i-region nil)
6007 (defvar pr-i-mode nil)
6008 (defvar pr-i-despool nil)
6009 (defvar pr-i-ps-as-is t)
6010 (defvar pr-i-n-up 1)
6011 (defvar pr-i-directory "./")
6012 (defvar pr-i-regexp "")
6013 (defvar pr-i-ps-file "")
6014 (defvar pr-i-out-file "")
6015 (defvar pr-i-answer-yes nil)
6016 (defvar pr-i-process 'buffer)
6017 (defvar pr-i-ps-send 'printer)
6020 (defvar pr-interface-map nil
6021 "Keymap for pr-interface.")
6023 (unless pr-interface-map
6024 (setq pr-interface-map (make-sparse-keymap))
6025 (cond ((featurep 'xemacs) ; XEmacs
6026 (pr-f-set-keymap-parents pr-interface-map (list widget-keymap))
6027 (pr-f-set-keymap-name pr-interface-map 'pr-interface-map))
6028 (t ; GNU Emacs
6029 (pr-f-set-keymap-parents pr-interface-map widget-keymap)))
6030 (define-key pr-interface-map "q" 'pr-interface-quit)
6031 (define-key pr-interface-map "?" 'pr-interface-help))
6034 (defmacro pr-interface-save (&rest body)
6035 `(save-excursion
6036 (set-buffer pr-i-buffer)
6037 ,@body))
6040 (defun pr-create-interface ()
6041 "Create the front end for printing package."
6042 (setq pr-i-buffer (buffer-name (current-buffer))
6043 pr-i-region (ps-mark-active-p)
6044 pr-i-mode (pr-mode-alist-p)
6045 pr-i-window-configuration (current-window-configuration))
6047 (put 'pr-i-process 'pr-widget-list nil)
6048 (put 'pr-i-ps-send 'pr-widget-list nil)
6050 (delete-other-windows)
6051 (kill-buffer (get-buffer-create pr-buffer-name))
6052 (switch-to-buffer (get-buffer-create pr-buffer-name))
6054 ;; header
6055 (let ((versions (concat "printing v" pr-version
6056 " ps-print v" ps-print-version)))
6057 (widget-insert (make-string (- 79 (length versions)) ?\s) versions))
6058 (pr-insert-italic "\nCurrent Directory : " 1)
6059 (pr-insert-italic default-directory)
6061 (pr-insert-section-1) ; 1. Print
6062 (pr-insert-section-2) ; 2. PostScript Printer
6063 (pr-insert-section-3) ; 3. Text Printer
6065 ;; separator
6066 (widget-insert "\n\n " (make-string 77 ?-))
6068 (pr-insert-section-4) ; 4. Settings
6069 (pr-insert-section-5) ; 5. Customize
6070 (pr-insert-section-6) ; 6. Show Settings
6071 (pr-insert-section-7) ; 7. Help
6073 (use-local-map pr-interface-map)
6074 (widget-setup)
6075 (goto-char (point-min))
6077 (and pr-i-region ; let region activated
6078 (pr-keep-region-active)))
6081 (defun pr-insert-section-1 ()
6082 ;; 1. Print:
6083 (pr-insert-italic "\nPrint :" 1)
6085 ;; 1a. Buffer:
6086 ;; 1a. Buffer: Buffer List
6087 (pr-insert-radio-button 'pr-i-process 'buffer)
6088 (pr-insert-menu "Buffer List" 'pr-i-buffer
6089 (let ((blist (buffer-list))
6090 case-fold-search choices)
6091 (while blist
6092 (let ((name (buffer-name (car blist)))
6093 (ignore pr-buffer-name-ignore)
6094 found)
6095 (setq blist (cdr blist))
6096 (while (and ignore (not found))
6097 (setq found (string-match (car ignore) name)
6098 ignore (cdr ignore)))
6099 (or found
6100 (setq choices
6101 (cons (list 'quote
6102 (list 'choice-item
6103 :format "%[%t%]"
6104 name))
6105 choices)))))
6106 (nreverse choices))
6107 " Buffer : " nil
6108 '(progn
6109 (pr-interface-save
6110 (setq pr-i-region (ps-mark-active-p)
6111 pr-i-mode (pr-mode-alist-p)))
6112 (pr-update-checkbox 'pr-i-region)
6113 (pr-update-checkbox 'pr-i-mode)))
6114 ;; 1a. Buffer: Region
6115 (put 'pr-i-region 'pr-widget
6116 (pr-insert-checkbox
6117 "\n "
6118 'pr-i-region
6119 #'(lambda (widget &rest ignore)
6120 (let ((region-p (pr-interface-save
6121 (ps-mark-active-p))))
6122 (cond ((null (widget-value widget)) ; widget is nil
6123 (setq pr-i-region nil))
6124 (region-p ; widget is true and there is a region
6125 (setq pr-i-region t)
6126 (widget-value-set widget t)
6127 (widget-setup)) ; MUST be called after widget-value-set
6128 (t ; widget is true and there is no region
6129 (ding)
6130 (message "There is no region active")
6131 (setq pr-i-region nil)
6132 (widget-value-set widget nil)
6133 (widget-setup))))) ; MUST be called after widget-value-set
6134 " Region"))
6135 ;; 1a. Buffer: Mode
6136 (put 'pr-i-mode 'pr-widget
6137 (pr-insert-checkbox
6139 'pr-i-mode
6140 #'(lambda (widget &rest ignore)
6141 (let ((mode-p (pr-interface-save
6142 (pr-mode-alist-p))))
6143 (cond
6144 ((null (widget-value widget)) ; widget is nil
6145 (setq pr-i-mode nil))
6146 (mode-p ; widget is true and there is a `mode'
6147 (setq pr-i-mode t)
6148 (widget-value-set widget t)
6149 (widget-setup)) ; MUST be called after widget-value-set
6150 (t ; widget is true and there is no `mode'
6151 (ding)
6152 (message
6153 "This buffer isn't in a mode that printing treats specially.")
6154 (setq pr-i-mode nil)
6155 (widget-value-set widget nil)
6156 (widget-setup))))) ; MUST be called after widget-value-set
6157 " Mode\n"))
6159 ;; 1b. Directory:
6160 (pr-insert-radio-button 'pr-i-process 'directory)
6161 (widget-create
6162 'directory
6163 :size 58
6164 :format " Directory : %v"
6165 :notify 'pr-interface-directory
6166 :action (lambda (widget &optional event)
6167 (if (pr-interface-directory widget)
6168 (pr-widget-field-action widget event)
6169 (ding)
6170 (message "Please specify a readable directory")))
6171 pr-i-directory)
6172 ;; 1b. Directory: File Regexp
6173 (widget-create 'regexp
6174 :size 58
6175 :format "\n File Regexp : %v\n"
6176 :notify (lambda (widget &rest ignore)
6177 (setq pr-i-regexp (widget-value widget)))
6178 pr-i-regexp)
6179 ;; 1b. Directory: List Directory Entry
6180 (widget-insert " ")
6181 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
6183 ;; 1c. PostScript File:
6184 (pr-insert-radio-button 'pr-i-process 'file)
6185 (widget-create
6186 'file
6187 :size 51
6188 :format " PostScript File : %v"
6189 :notify 'pr-interface-infile
6190 :action (lambda (widget &rest event)
6191 (if (pr-interface-infile widget)
6192 (pr-widget-field-action widget event)
6193 (ding)
6194 (message "Please specify a readable PostScript file")))
6195 pr-i-ps-file)
6196 ;; 1c. PostScript File: PostScript Utility
6197 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
6198 (pr-choice-alist pr-ps-utility-alist)
6199 "\n PostScript Utility : "
6200 " ")
6201 ;; 1c. PostScript File: No Preprocessing
6202 (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
6205 (defun pr-insert-section-2 ()
6206 ;; 2. PostScript Printer:
6207 ;; 2. PostScript Printer: PostScript Printer List
6208 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
6209 (pr-insert-menu "PostScript Printer" 'pr-ps-name
6210 (pr-choice-alist pr-ps-printer-alist))
6211 ;; 2. PostScript Printer: Despool
6212 (put 'pr-i-despool 'pr-widget
6213 (pr-insert-checkbox
6215 'pr-i-despool
6216 #'(lambda (widget &rest ignore)
6217 (if pr-spool-p
6218 (setq pr-i-despool (not pr-i-despool))
6219 (ding)
6220 (message "Can despool only when spooling is actually selected")
6221 (setq pr-i-despool nil))
6222 (widget-value-set widget pr-i-despool)
6223 (widget-setup)) ; MUST be called after widget-value-set
6224 " Despool "))
6225 ;; 2. PostScript Printer: Preview Print Quit
6226 (pr-insert-button 'pr-interface-preview "Preview" " ")
6227 (pr-insert-button 'pr-interface-ps-print "Print" " ")
6228 (pr-insert-button 'pr-interface-quit "Quit")
6229 ;; 2. PostScript Printer: Send to Printer/Temporary File
6230 (pr-insert-radio-button 'pr-i-ps-send 'printer)
6231 (widget-insert " Send to Printer/Temporary File")
6232 ;; 2. PostScript Printer: Send to File
6233 (pr-insert-radio-button 'pr-i-ps-send 'file)
6234 (widget-create
6235 'file
6236 :size 57
6237 :format " Send to File : %v"
6238 :notify 'pr-interface-outfile
6239 :action (lambda (widget &rest event)
6240 (if (and (pr-interface-outfile widget)
6241 (or (not (file-exists-p pr-i-out-file))
6242 (setq pr-i-answer-yes
6243 (y-or-n-p "File exists; overwrite? "))))
6244 (pr-widget-field-action widget event)
6245 (ding)
6246 (message "Please specify a writable PostScript file")))
6247 pr-i-out-file)
6248 ;; 2. PostScript Printer: N-Up
6249 (widget-create
6250 'integer
6251 :size 3
6252 :format "\n N-Up : %v"
6253 :notify (lambda (widget &rest ignore)
6254 (let ((value (if (string= (widget-apply widget :value-get) "")
6256 (widget-value widget))))
6257 (if (and (integerp value)
6258 (<= 1 value) (<= value 100))
6259 (progn
6260 (message " ")
6261 (setq pr-i-n-up value))
6262 (ding)
6263 (message "Please specify an integer between 1 and 100"))))
6264 pr-i-n-up))
6267 (defun pr-insert-section-3 ()
6268 ;; 3. Text Printer:
6269 (pr-insert-italic "\n\nText Printer : " 2 14)
6270 (pr-insert-menu "Text Printer" 'pr-txt-name
6271 (pr-choice-alist pr-txt-printer-alist)
6272 nil " ")
6273 (pr-insert-button 'pr-interface-printify "Printify" " ")
6274 (pr-insert-button 'pr-interface-txt-print "Print" " ")
6275 (pr-insert-button 'pr-interface-quit "Quit"))
6278 (defun pr-insert-section-4 ()
6279 ;; 4. Settings:
6280 ;; 4. Settings: Landscape Auto Region Verbose
6281 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
6282 #'(lambda (&rest ignore)
6283 (setq ps-landscape-mode (not ps-landscape-mode)
6284 pr-file-landscape ps-landscape-mode))
6285 " Landscape ")
6286 (pr-insert-toggle 'pr-auto-region " Auto Region ")
6287 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
6289 ;; 4. Settings: Print Header Auto Mode
6290 (pr-insert-toggle 'ps-print-header " Print Header ")
6291 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
6293 ;; 4. Settings: Print Header Frame Menu Lock
6294 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
6295 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
6297 ;; 4. Settings: Line Number
6298 (pr-insert-toggle 'ps-line-number " Line Number\n ")
6300 ;; 4. Settings: Zebra Stripes Spool Buffer
6301 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
6302 (pr-insert-checkbox " "
6303 'pr-spool-p
6304 #'(lambda (&rest ignore)
6305 (setq pr-spool-p (not pr-spool-p))
6306 (unless pr-spool-p
6307 (setq pr-i-despool nil)
6308 (pr-update-checkbox 'pr-i-despool)))
6309 " Spool Buffer")
6311 ;; 4. Settings: Duplex Print with faces
6312 (pr-insert-checkbox "\n "
6313 'ps-spool-duplex
6314 #'(lambda (&rest ignore)
6315 (setq ps-spool-duplex (not ps-spool-duplex)
6316 pr-file-duplex ps-spool-duplex))
6317 " Duplex ")
6318 (pr-insert-toggle 'pr-faces-p " Print with faces")
6320 ;; 4. Settings: Tumble Print via Ghostscript
6321 (pr-insert-checkbox "\n "
6322 'ps-spool-tumble
6323 #'(lambda (&rest ignore)
6324 (setq ps-spool-tumble (not ps-spool-tumble)
6325 pr-file-tumble ps-spool-tumble))
6326 " Tumble ")
6327 (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
6329 ;; 4. Settings: Upside-Down Page Parity
6330 (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
6331 (pr-insert-italic "\n\nSelect Pages : " 2 14)
6332 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
6333 (mapcar #'(lambda (alist)
6334 (list 'quote
6335 (list 'choice-item
6336 :format "%[%t%]"
6337 :tag (cdr alist)
6338 :value (car alist))))
6339 pr-even-or-odd-alist)))
6342 (defun pr-insert-section-5 ()
6343 ;; 5. Customize:
6344 (pr-insert-italic "\n\nCustomize : " 2 11)
6345 (pr-insert-button 'pr-customize "printing" " ")
6346 (pr-insert-button #'(lambda (&rest ignore) (ps-print-customize))
6347 "ps-print" " ")
6348 (pr-insert-button 'lpr-customize "lpr"))
6351 (defun pr-insert-section-6 ()
6352 ;; 6. Show Settings:
6353 (pr-insert-italic "\nShow Settings : " 1 14)
6354 (pr-insert-button 'pr-show-pr-setup "printing" " ")
6355 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
6356 (pr-insert-button 'pr-show-lpr-setup "lpr"))
6359 (defun pr-insert-section-7 ()
6360 ;; 7. Help:
6361 (pr-insert-italic "\nHelp : " 1 5)
6362 (pr-insert-button 'pr-interface-help "Interface Help" " ")
6363 (pr-insert-button 'pr-help "Menu Help" " ")
6364 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
6365 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
6368 (defun pr-kill-help (&rest ignore)
6369 "Kill all printing help buffer."
6370 (interactive)
6371 (let ((help '("*Printing Interface Help*" "*Printing Help*"
6372 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
6373 (while help
6374 (let ((buffer (get-buffer (car help))))
6375 (setq help (cdr help))
6376 (when buffer
6377 (delete-windows-on buffer)
6378 (kill-buffer buffer)))))
6379 (recenter (- (window-height) 2)))
6382 (defun pr-interface-quit (&rest ignore)
6383 "Kill the printing buffer interface and quit."
6384 (interactive)
6385 (kill-buffer pr-buffer-name)
6386 (set-window-configuration pr-i-window-configuration))
6389 (defun pr-interface-help (&rest ignore)
6390 "printing buffer interface help."
6391 (interactive)
6392 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
6395 (defun pr-interface-txt-print (&rest ignore)
6396 "Print using lpr package."
6397 (interactive)
6398 (condition-case data
6399 (cond
6400 ((eq pr-i-process 'directory)
6401 (pr-i-directory)
6402 (pr-interface-save
6403 (pr-txt-directory pr-i-directory pr-i-regexp)))
6404 ((eq pr-i-process 'buffer)
6405 (pr-interface-save
6406 (cond (pr-i-region
6407 (let ((pr-auto-mode pr-i-mode))
6408 (pr-txt-region)))
6409 (pr-i-mode
6410 (let (pr-auto-region)
6411 (pr-txt-mode)))
6413 (let (pr-auto-mode pr-auto-region)
6414 (pr-txt-buffer)))
6416 ((eq pr-i-process 'file)
6417 (error "Please specify a text file"))
6419 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6421 ;; handlers
6422 ((quit error)
6423 (ding)
6424 (message "%s" (error-message-string data)))))
6427 (defun pr-interface-printify (&rest ignore)
6428 "Printify a buffer."
6429 (interactive)
6430 (condition-case data
6431 (cond
6432 ((eq pr-i-process 'directory)
6433 (pr-i-directory)
6434 (pr-interface-save
6435 (pr-printify-directory pr-i-directory pr-i-regexp)))
6436 ((eq pr-i-process 'buffer)
6437 (pr-interface-save
6438 (if pr-i-region
6439 (pr-printify-region)
6440 (pr-printify-buffer))))
6441 ((eq pr-i-process 'file)
6442 (error "Cannot printify a PostScript file"))
6444 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6446 ;; handlers
6447 ((quit error)
6448 (ding)
6449 (message "%s" (error-message-string data)))))
6452 (defun pr-interface-ps-print (&rest ignore)
6453 "Print using ps-print package."
6454 (interactive)
6455 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6456 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6457 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6458 'pr-ps-buffer-ps-print))
6461 (defun pr-interface-preview (&rest ignore)
6462 "Preview a PostScript file."
6463 (interactive)
6464 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6465 'pr-ps-file-preview 'pr-ps-file-up-preview
6466 'pr-ps-region-preview 'pr-ps-mode-preview
6467 'pr-ps-buffer-preview))
6470 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6471 ps-mode ps-buffer)
6472 (condition-case data
6473 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6474 (pr-i-ps-send))))
6475 (cond
6476 ((and pr-i-despool pr-spool-p)
6477 (pr-interface-save
6478 (funcall ps-despool outfile))
6479 (setq pr-i-despool nil)
6480 (pr-update-checkbox 'pr-i-despool))
6481 ((eq pr-i-process 'directory)
6482 (pr-i-directory)
6483 (pr-interface-save
6484 (funcall ps-directory
6485 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6486 ((eq pr-i-process 'file)
6487 (cond ((or (file-directory-p pr-i-ps-file)
6488 (not (file-readable-p pr-i-ps-file)))
6489 (error "Please specify a readable PostScript file"))
6490 (pr-i-ps-as-is
6491 (pr-interface-save
6492 (funcall ps-file pr-i-ps-file)))
6494 (pr-interface-save
6495 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6497 ((eq pr-i-process 'buffer)
6498 (pr-interface-save
6499 (cond (pr-i-region
6500 (let ((pr-auto-mode pr-i-mode))
6501 (funcall ps-region pr-i-n-up outfile)))
6502 (pr-i-mode
6503 (let (pr-auto-region)
6504 (funcall ps-mode pr-i-n-up outfile)))
6506 (let (pr-auto-mode pr-auto-region)
6507 (funcall ps-buffer pr-i-n-up outfile)))
6510 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6512 ;; handlers
6513 ((quit error)
6514 (ding)
6515 (message "%s" (error-message-string data)))))
6518 (defun pr-i-ps-send ()
6519 (cond ((eq pr-i-ps-send 'printer)
6520 nil)
6521 ((not (eq pr-i-ps-send 'file))
6522 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6523 ((or (file-directory-p pr-i-out-file)
6524 (not (file-writable-p pr-i-out-file)))
6525 (error "Please specify a writable PostScript file"))
6526 ((or (not (file-exists-p pr-i-out-file))
6527 pr-i-answer-yes
6528 (setq pr-i-answer-yes
6529 (y-or-n-p (format "File `%s' exists; overwrite? "
6530 pr-i-out-file))))
6531 pr-i-out-file)
6533 (error "File already exists"))))
6536 (defun pr-i-directory ()
6537 (or (and (file-directory-p pr-i-directory)
6538 (file-readable-p pr-i-directory))
6539 (error "Please specify be a readable directory")))
6542 (defun pr-interface-directory (widget &rest ignore)
6543 (and pr-buffer-verbose
6544 (message "You can use M-TAB or ESC TAB for file completion"))
6545 (let ((dir (widget-value widget)))
6546 (and (file-directory-p dir)
6547 (file-readable-p dir)
6548 (setq pr-i-directory dir))))
6551 (defun pr-interface-infile (widget &rest ignore)
6552 (and pr-buffer-verbose
6553 (message "You can use M-TAB or ESC TAB for file completion"))
6554 (let ((file (widget-value widget)))
6555 (and (not (file-directory-p file))
6556 (file-readable-p file)
6557 (setq pr-i-ps-file file))))
6560 (defun pr-interface-outfile (widget &rest ignore)
6561 (setq pr-i-answer-yes nil)
6562 (and pr-buffer-verbose
6563 (message "You can use M-TAB or ESC TAB for file completion"))
6564 (let ((file (widget-value widget)))
6565 (and (not (file-directory-p file))
6566 (file-writable-p file)
6567 (setq pr-i-out-file file))))
6570 (defun pr-widget-field-action (widget event)
6571 (and (get-buffer "*Completions*") ; clean frame window
6572 (delete-windows-on "*Completions*"))
6573 (message " ") ; clean echo area
6574 (widget-field-action widget event))
6577 (defun pr-insert-italic (str &optional from to)
6578 (let ((len (length str)))
6579 (put-text-property (if from (max from 0) 0)
6580 (if to (max to len) len)
6581 'face 'italic str)
6582 (widget-insert str)))
6585 (defun pr-insert-checkbox (before var-sym fun label)
6586 (widget-insert before)
6587 (prog1
6588 (widget-create 'checkbox
6589 :notify fun
6590 (symbol-value var-sym))
6591 (widget-insert label)))
6594 (defun pr-insert-toggle (var-sym label)
6595 (widget-create 'checkbox
6596 :notify `(lambda (&rest ignore)
6597 (setq ,var-sym (not ,var-sym)))
6598 (symbol-value var-sym))
6599 (widget-insert label))
6602 (defun pr-insert-button (fun label &optional separator)
6603 (widget-create 'push-button
6604 :notify fun
6605 label)
6606 (and separator
6607 (widget-insert separator)))
6610 (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6611 (and before (widget-insert before))
6612 (eval `(widget-create 'menu-choice
6613 :tag ,tag
6614 :format "%v"
6615 :inline t
6616 :value ,var-sym
6617 :notify (lambda (widget &rest ignore)
6618 (setq ,var-sym (widget-value widget))
6619 ,@body)
6620 :void '(choice-item :format "%[%t%]"
6621 :tag "Can not display value!")
6622 ,@choices))
6623 (and after (widget-insert after)))
6626 (defun pr-insert-radio-button (var-sym sym)
6627 (widget-insert "\n")
6628 (let ((wid-list (get var-sym 'pr-widget-list))
6629 (wid (eval `(widget-create
6630 'radio-button
6631 :format " %[%v%]"
6632 :value (eq ,var-sym (quote ,sym))
6633 :notify (lambda (&rest ignore)
6634 (setq ,var-sym (quote ,sym))
6635 (pr-update-radio-button (quote ,var-sym)))))))
6636 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6639 (defun pr-update-radio-button (var-sym)
6640 (let ((wid-list (get var-sym 'pr-widget-list)))
6641 (while wid-list
6642 (let ((wid (car (car wid-list)))
6643 (value (cdr (car wid-list))))
6644 (setq wid-list (cdr wid-list))
6645 (widget-value-set wid (eq (symbol-value var-sym) value))))
6646 (widget-setup)))
6649 (defun pr-update-checkbox (var-sym)
6650 (let ((wid (get var-sym 'pr-widget)))
6651 (when wid
6652 (widget-value-set wid (symbol-value var-sym))
6653 (widget-setup))))
6656 (defun pr-choice-alist (alist)
6657 (let ((max (apply 'max (mapcar #'(lambda (alist)
6658 (length (symbol-name (car alist))))
6659 alist))))
6660 (mapcar #'(lambda (alist)
6661 (let* ((sym (car alist))
6662 (name (symbol-name sym)))
6663 (list
6664 'quote
6665 (list
6666 'choice-item
6667 :format "%[%t%]"
6668 :tag (concat name
6669 (make-string (- max (length name)) ?_))
6670 :value sym))))
6671 alist)))
6674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6677 (provide 'printing)
6680 ;; arch-tag: 9ce9ac3f-0f60-4370-900b-1943215d9d18
6681 ;;; printing.el ends here