1 ;;; printing.el --- printing utilities
3 ;; Copyright (C) 2000-2001, 2003-2014 Free Software Foundation, Inc.
5 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
6 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7 ;; Keywords: wp, print, PostScript
9 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
11 (defconst pr-version
"6.9.3"
12 "printing.el, v 6.9.3 <2007/12/09 vinicius>
14 Please send all bug fixes and enhancements to
15 bug-gnu-emacs@gnu.org and Vinicius Jose Latorre <viniciusjl@ig.com.br>
18 ;; This file is part of GNU Emacs.
20 ;; GNU Emacs is free software: you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation, either version 3 of the License, or
23 ;; (at your option) any later version.
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
35 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;; With `printing' you can preview or print a PostScript file. You can also
41 ;; print a text file using PostScript, and preview or print buffers that use
42 ;; certain special modes like mh-folder-mode, rmail-summary-mode,
43 ;; gnus-summary-mode, etc. This package also includes a PostScript/text
46 ;; There are two user interfaces:
49 ;; The `printing' menu replaces the usual print options in the menu bar.
50 ;; This is the default user interface.
52 ;; * Buffer interface:
53 ;; You can use a buffer interface instead of menus. It looks like a
54 ;; customization buffer. Basically, it has the same options found in the
55 ;; menu and some extra options, all this on a buffer.
57 ;; `printing' is prepared to run on GNU, Unix and NT systems.
58 ;; On GNU or Unix system, `printing' depends on gs and gv utilities.
59 ;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe).
60 ;; To obtain ghostscript, ghostview and GSview see the URL
61 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'.
63 ;; `printing' depends on ps-print package to generate PostScript files, to
64 ;; spool and to despool PostScript buffer. So, `printing' provides an
65 ;; interface to ps-print package and it also provides some extra stuff.
67 ;; To download the latest ps-print package see
68 ;; `http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'.
69 ;; Please, see README file for ps-print installation instructions.
71 ;; `printing' was inspired by:
73 ;; print-nt.el Frederic Corne <frederic.corne@erli.fr>
74 ;; Special printing functions for Windows NT
76 ;; mh-e-init.el Tom Vogels <tov@ece.cmu.edu>
77 ;; PS-print for mail messages
79 ;; win32-ps-print.el Matthew O. Persico <mpersico@erols.com>
80 ;; PostScript printing with ghostscript
82 ;; ps-print-interface.el Volker Franz <volker.franz@tuebingen.mpg.de>
83 ;; Graphical front end for ps-print and previewing
89 ;; The buffer *Printing Command Output* is where the `printing' log messages
90 ;; are inserted. All program called by `printing' has a log entry in the
91 ;; buffer *Printing Command Output*. A log entry has the following form:
98 ;; PROGRAM is the program activated by `printing',
99 ;; ARG is an argument passed to PROGRAM (it can have more than one argument),
100 ;; MESSAGE is an error message returned by PROGRAM (it can have no message, if
101 ;; PROGRAM is successful),
102 ;; and CODE is a numeric exit status or a signal description string.
104 ;; For example, after previewing a PostScript file, *Printing Command Output*
105 ;; will have the following entry:
107 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
110 ;; In the example above, the previewing was successful. If during previewing,
111 ;; you quit gv execution (by typing C-g during Emacs session), the log entry
114 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
117 ;; So, if something goes wrong, a good place to take a look is the buffer
118 ;; *Printing Command Output*. Don't forget to see also the buffer *Messages*,
122 ;; Novices (First Users)
123 ;; ---------------------
125 ;; First of all, see printing documentation only to get an idea of what
126 ;; `printing' is capable.
128 ;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
129 ;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'. These variables
130 ;; are the main variables for printing processing.
132 ;; Now, please, see these variables documentation deeper. You can do this by
133 ;; typing C-h v pr-ps-name RET (for example) if you already loaded printing
134 ;; package, or by browsing printing.el source file.
136 ;; If the documentation isn't clear or if you find a way to improve the
137 ;; documentation, please, send an email to maintainer. All printing users
140 ;; One way to set variables is by calling `pr-customize', customize all
141 ;; variables and save the customization by future sessions (see Options
142 ;; section). Other way is by adding code to your init file; see below
143 ;; for a first setting template that it should be inserted on your
146 ;; * Example of setting for Windows system:
148 ;; (require 'printing) ; load printing package
149 ;; (setq pr-path-alist
150 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
151 ;; (ghostview "c:/gs/gsview-dir")
152 ;; (mpage "c:/mpage-dir")
154 ;; (setq pr-txt-name 'prt_06a)
155 ;; (setq pr-txt-printer-alist
156 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
157 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
158 ;; (PRN "" nil "PRN")
159 ;; (standard "redpr.exe" nil "")
161 ;; (setq pr-ps-name 'lps_06b)
162 ;; (setq pr-ps-printer-alist
163 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
164 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
165 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
166 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
167 ;; (LPT1 "" nil "" "LPT1:")
168 ;; (PRN "" nil "" "PRN")
169 ;; (standard "redpr.exe" nil "" "")
171 ;; (pr-update-menus t) ; update now printer and utility menus
173 ;; * Example of setting for GNU or Unix system:
175 ;; (require 'printing) ; load printing package
176 ;; (setq pr-path-alist
177 ;; '((unix "." "~/bin" ghostview mpage PATH)
178 ;; (ghostview "$HOME/bin/gsview-dir")
179 ;; (mpage "$HOME/bin/mpage-dir")
181 ;; (setq pr-txt-name 'prt_06a)
182 ;; (setq pr-txt-printer-alist
183 ;; '((prt_06a "lpr" nil "prt_06a")
184 ;; (prt_07c nil nil "prt_07c")
186 ;; (setq pr-ps-name 'lps_06b)
187 ;; (setq pr-ps-printer-alist
188 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
189 ;; (lps_07c "lpr" nil nil "lps_07c")
190 ;; (lps_08c nil nil nil "lps_08c")
192 ;; (pr-update-menus t) ; update now printer and utility menus
195 ;; NOTE 1: Don't forget to download and install ghostscript utilities (see
196 ;; Utilities section).
198 ;; NOTE 2: The `printer-name' and `ps-printer-name' variables don't need to be
199 ;; set, as they are implicit set by `pr-ps-printer-alist' and
200 ;; `pr-txt-printer-alist'.
202 ;; NOTE 3: The duplex feature will only work on PostScript printers that
203 ;; support this feature.
204 ;; You can check if your PostScript printer supports duplex feature
205 ;; by checking the printer manual. Or you can try these steps:
206 ;; 1. Open a buffer (or use the *scratch* buffer).
208 ;; First line (on first page)
210 ;; Second line (on second page)
211 ;; 3. Print this buffer with duplex turned on.
212 ;; If it's printed 2 (two) sheets of paper, then your PostScript
213 ;; printer doesn't have duplex feature; otherwise, it's ok, your
214 ;; printer does have duplex feature.
216 ;; NOTE 4: See Tips section.
222 ;; 1. If you have a local printer, that is, a printer which is connected
223 ;; directly to your computer, don't forget to connect the printer to your
224 ;; computer before printing.
226 ;; 2. If you try to print a file and it seems that the file was printed, but
227 ;; there is no paper in the printer, then try to set `pr-delete-temp-file'
228 ;; to nil. Probably `printing' is deleting the temporary file before your
229 ;; local system can get it to send to the printer.
231 ;; 3. Don't try to print a dynamic buffer, that is, a buffer which is
232 ;; modifying while `printing' tries to print. Eventually you got an error
233 ;; message. Instead, save the dynamic buffer to a file or copy it in
234 ;; another buffer and, then, print the file or the new static buffer.
235 ;; An example of dynamic buffer is the *Messages* buffer.
237 ;; 4. When running Emacs on Windows (with or without cygwin), check if your
238 ;; printer is a text printer or not by typing in a DOS window:
240 ;; print /D:\\host\printer somefile.txt
242 ;; Where, `host' is the machine where the printer is directly connected,
243 ;; `printer' is the printer name and `somefile.txt' is a text file.
245 ;; If the printer `\\host\printer' doesn't print the content of
246 ;; `somefile.txt' or, instead, it returns the following message:
248 ;; PostScript Error Handler
249 ;; Offending Command = CCC
252 ;; Where `CCC' is whatever is at the beginning of the text to be printed.
254 ;; Therefore, the printer `\\host\printer' is not a text printer, but a
255 ;; PostScript printer. So, please, don't include this printer in
256 ;; `pr-txt-printer-alist' (which see).
258 ;; 5. You can use gsprint instead of ghostscript to print monochrome PostScript
259 ;; files in Windows. The gsprint utility documentation says that it is more
260 ;; efficient than ghostscript to print monochrome PostScript.
262 ;; To print non-monochrome PostScript file, the efficiency of ghostscript
263 ;; is similar to gsprint.
265 ;; Also the gsprint utility comes together with gsview distribution.
267 ;; For more information about gsprint see
268 ;; `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
270 ;; As an example of gsprint declaration:
272 ;; (setq pr-ps-printer-alist
273 ;; '((A "gsprint" ("-all" "-twoup") "-printer " "my-b/w-printer-name")
274 ;; (B "gsprint" ("-all" "-twoup") nil "-printer my-b/w-printer-name")
275 ;; ;; some other printer declaration
278 ;; The example above declares that printer A prints all pages (-all) and two
279 ;; pages per sheet (-twoup). The printer B declaration does the same as the
280 ;; printer A declaration, the only difference is the printer name selection.
282 ;; There are other command line options like:
284 ;; -mono Render in monochrome as 1bit/pixel (only black and white).
285 ;; -grey Render in greyscale as 8bits/pixel.
286 ;; -color Render in color as 24bits/pixel.
288 ;; The default is `-mono'. So, printer A and B in the example above are
289 ;; using implicitly the `-mono' option. Note that in `-mono' no gray tone
290 ;; or color is printed, this includes the zebra stripes, that is, in `-mono'
291 ;; the zebra stripes are not printed.
293 ;; See also documentation for `pr-ps-printer-alist'.
299 ;; To use `printing' insert in your init file:
301 ;; (require 'printing)
302 ;; ;; ...some user settings...
303 ;; (pr-update-menus t)
305 ;; During `pr-update-menus' evaluation:
307 ;; it replaces the Tools/Print menu by Tools/Printing menu.
309 ;; it replaces the File/Print* menu entries by File/Print menu.
310 ;; Please, see section Menu Layout below for menu explanation.
312 ;; To use `printing' utilities you can use the Printing menu options, type M-x
313 ;; followed by one of the commands below, or type a key associated with the
314 ;; command you want (if there is a key binding).
316 ;; `printing' has the following commands:
319 ;; pr-ps-directory-preview
320 ;; pr-ps-directory-using-ghostscript
321 ;; pr-ps-directory-print
322 ;; pr-ps-directory-ps-print
323 ;; pr-ps-buffer-preview
324 ;; pr-ps-buffer-using-ghostscript
325 ;; pr-ps-buffer-print
326 ;; pr-ps-buffer-ps-print
327 ;; pr-ps-region-preview
328 ;; pr-ps-region-using-ghostscript
329 ;; pr-ps-region-print
330 ;; pr-ps-region-ps-print
331 ;; pr-ps-mode-preview
332 ;; pr-ps-mode-using-ghostscript
334 ;; pr-ps-mode-ps-print
335 ;; pr-ps-file-preview
336 ;; pr-ps-file-up-preview
337 ;; pr-ps-file-using-ghostscript
339 ;; pr-ps-file-ps-print
340 ;; pr-ps-file-up-ps-print
342 ;; pr-despool-preview
343 ;; pr-despool-using-ghostscript
345 ;; pr-despool-ps-print
346 ;; pr-printify-directory
347 ;; pr-printify-buffer
348 ;; pr-printify-region
354 ;; pr-toggle-file-duplex
355 ;; pr-toggle-file-tumble
356 ;; pr-toggle-file-landscape
357 ;; pr-toggle-ghostscript
362 ;; pr-toggle-landscape
363 ;; pr-toggle-upside-down
380 ;; The general meanings of above commands are:
383 ;; `pr-interface' buffer interface for printing package.
384 ;; `pr-help' help for printing package.
385 ;; `pr-ps-name' interactively select a PostScript printer.
386 ;; `pr-txt-name' interactively select a text printer.
387 ;; `pr-ps-utility' interactively select a PostScript utility.
388 ;; `pr-show-*-setup' show current settings.
389 ;; `pr-ps-*' deal with PostScript code generation.
390 ;; `pr-txt-*' deal with text generation.
391 ;; `pr-toggle-*' toggle on/off some boolean variable.
392 ;; `pr-despool-*' despool the PostScript spooling buffer.
393 ;; `pr-printify-*' replace nonprintable ASCII by printable ASCII
397 ;; `*-customize' customization.
398 ;; `*-preview' preview a PostScript file.
399 ;; `*-using-ghostscript' use ghostscript to print.
400 ;; `*-fast-fire' fast fire command (see it for documentation).
401 ;; `*-print' send PostScript directly to printer.
402 ;; `*-ps-print' send PostScript directly to printer or use
403 ;; ghostscript to print. It depends on
404 ;; `pr-print-using-ghostscript' option.
407 ;; `*-directory*' process a directory.
408 ;; `*-buffer*' process a buffer.
409 ;; `*-region*' process a region.
410 ;; `*-mode*' process a major mode (see explanation below).
411 ;; `*-file-*' process a PostScript file.
412 ;; `*-file-up-*' process a PostScript file using a filter utility.
414 ;; Here are some examples:
416 ;; `pr-ps-buffer-using-ghostscript'
417 ;; Use ghostscript to print a buffer.
419 ;; `pr-ps-file-print'
420 ;; Print a PostScript file.
423 ;; Toggle spooling buffer.
425 ;; So you can preview through ghostview, use ghostscript to print (if you don't
426 ;; have a PostScript printer) or send directly to printer a PostScript code
427 ;; generated by `ps-print' package.
429 ;; Besides operating one buffer or region each time, you also can postpone
430 ;; previewing or printing by saving the PostScript code generated in a
431 ;; temporary Emacs buffer. This way you can save banner pages between
432 ;; successive printing. You can toggle on/off spooling by invoking
433 ;; `pr-toggle-spool' interactively or through menu bar.
435 ;; If you type, for example:
437 ;; C-u M-x pr-ps-buffer-print RET
439 ;; The `pr-ps-buffer-print' command prompts you for a n-up printing number and
440 ;; a file name, and save the PostScript code generated to the file name instead
441 ;; of sending to printer.
443 ;; This behavior is similar with the commands that deal with PostScript code
444 ;; generation, that is, with `pr-ps-*' and `pr-despool-*' commands. If
445 ;; spooling is on, only `pr-despool-*' commands prompt for a file name and save
446 ;; the PostScript code spooled in this file.
448 ;; Besides the behavior described above, the `*-directory*' commands also
449 ;; prompt for a directory and a file name regexp. So, it's possible to process
450 ;; all or certain files on a directory at once (see also documentation for
451 ;; `pr-list-directory').
453 ;; `printing' has also a special way to handle some major mode through
454 ;; `*-mode*' commands. So it's possible to customize a major mode printing,
455 ;; it's only needed to declare the customization in `pr-mode-alist' (see
456 ;; section Options) and invoke some of `*-mode*' commands. An example for
457 ;; major mode usage is when you're using gnus (or mh, or rmail, etc.) and
458 ;; you're in the *Summary* buffer, if you forget to switch to the *Article*
459 ;; buffer before printing, you'll get a nicely formatted list of article
460 ;; subjects shows up at the printer. With major mode printing you don't need
461 ;; to switch from gnus *Summary* buffer first.
463 ;; Current global keyboard mapping for GNU Emacs is:
465 ;; (global-set-key [print] 'pr-ps-fast-fire)
466 ;; (global-set-key [M-print] 'pr-ps-mode-using-ghostscript)
467 ;; (global-set-key [S-print] 'pr-ps-mode-using-ghostscript)
468 ;; (global-set-key [C-print] 'pr-txt-fast-fire)
469 ;; (global-set-key [C-M-print] 'pr-txt-fast-fire)
471 ;; And for XEmacs is:
473 ;; (global-set-key 'f22 'pr-ps-fast-fire)
474 ;; (global-set-key '(meta f22) 'pr-ps-mode-using-ghostscript)
475 ;; (global-set-key '(shift f22) 'pr-ps-mode-using-ghostscript)
476 ;; (global-set-key '(control f22) 'pr-txt-fast-fire)
477 ;; (global-set-key '(control meta f22) 'pr-txt-fast-fire)
479 ;; As a suggestion of global keyboard mapping for some `printing' commands:
481 ;; (global-set-key "\C-ci" 'pr-interface)
482 ;; (global-set-key "\C-cbp" 'pr-ps-buffer-print)
483 ;; (global-set-key "\C-cbx" 'pr-ps-buffer-preview)
484 ;; (global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
485 ;; (global-set-key "\C-crp" 'pr-ps-region-print)
486 ;; (global-set-key "\C-crx" 'pr-ps-region-preview)
487 ;; (global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
493 ;; Below it's shown a brief description of `printing' options, please, see the
494 ;; options declaration in the code for a long documentation.
496 ;; `pr-path-style' Specify which path style to use for external
499 ;; `pr-path-alist' Specify an alist for command paths.
501 ;; `pr-txt-name' Specify a printer for printing a text file.
503 ;; `pr-txt-printer-alist' Specify an alist of all text printers.
505 ;; `pr-ps-name' Specify a printer for printing a PostScript
508 ;; `pr-ps-printer-alist' Specify an alist for all PostScript printers.
510 ;; `pr-temp-dir' Specify a directory for temporary files during
513 ;; `pr-ps-temp-file' Specify PostScript temporary file name prefix.
515 ;; `pr-file-modes' Specify the file permission bits for newly
518 ;; `pr-gv-command' Specify path and name of the gsview/gv
521 ;; `pr-gs-command' Specify path and name of the ghostscript
524 ;; `pr-gs-switches' Specify ghostscript switches.
526 ;; `pr-gs-device' Specify ghostscript device switch value.
528 ;; `pr-gs-resolution' Specify ghostscript resolution switch value.
530 ;; `pr-print-using-ghostscript' Non-nil means print using ghostscript.
532 ;; `pr-faces-p' Non-nil means print with face attributes.
534 ;; `pr-spool-p' Non-nil means spool printing in a buffer.
536 ;; `pr-file-landscape' Non-nil means print PostScript file in
537 ;; landscape orientation.
539 ;; `pr-file-duplex' Non-nil means print PostScript file in duplex
542 ;; `pr-file-tumble' Non-nil means print PostScript file in tumble
545 ;; `pr-auto-region' Non-nil means region is automagically detected.
547 ;; `pr-auto-mode' Non-nil means major-mode specific printing is
548 ;; preferred over normal printing.
550 ;; `pr-mode-alist' Specify an alist for a major-mode and printing
553 ;; `pr-ps-utility' Specify PostScript utility processing.
555 ;; `pr-ps-utility-alist' Specify an alist for PostScript utility
558 ;; `pr-menu-lock' Non-nil means menu is locked while selecting
561 ;; `pr-menu-char-height' Specify menu char height in pixels.
563 ;; `pr-menu-char-width' Specify menu char width in pixels.
565 ;; `pr-setting-database' Specify an alist for settings in general.
567 ;; `pr-visible-entry-list' Specify a list of Printing menu visible
570 ;; `pr-delete-temp-file' Non-nil means delete temporary files.
572 ;; `pr-list-directory' Non-nil means list directory when processing a
575 ;; `pr-buffer-name' Specify the name of the buffer interface for
578 ;; `pr-buffer-name-ignore' Specify a regexp list for buffer names to be
579 ;; ignored in interface buffer.
581 ;; `pr-buffer-verbose' Non-nil means to be verbose when editing a
582 ;; field in interface buffer.
584 ;; To set the above options you may:
586 ;; a) insert the code in your ~/.emacs, like:
588 ;; (setq pr-faces-p t)
590 ;; This way always keep your default settings when you enter a new Emacs
593 ;; b) or use `set-variable' in your Emacs session, like:
595 ;; M-x set-variable RET pr-faces-p RET t RET
597 ;; This way keep your settings only during the current Emacs session.
599 ;; c) or use customization, for example:
600 ;; click on menu-bar *Help* option,
601 ;; then click on *Customize*,
602 ;; then click on *Browse Customization Groups*,
603 ;; expand *PostScript* group,
604 ;; expand *Printing* group
605 ;; and then customize `printing' options.
606 ;; Through this way, you may choose if the settings are kept or not when
607 ;; you leave out the current Emacs session.
609 ;; d) or see the option value:
611 ;; C-h v pr-faces-p RET
613 ;; and click the *customize* hypertext button.
614 ;; Through this way, you may choose if the settings are kept or not when
615 ;; you leave out the current Emacs session.
619 ;; M-x pr-customize RET
621 ;; and then customize `printing' options.
622 ;; Through this way, you may choose if the settings are kept or not when
623 ;; you leave out the current Emacs session.
625 ;; f) or use menu bar, for example:
626 ;; click on menu-bar *File* option,
627 ;; then click on *Printing*,
628 ;; then click on *Customize*,
629 ;; then click on *printing*
630 ;; and then customize `printing' options.
631 ;; Through this way, you may choose if the settings are kept or not when
632 ;; you leave out the current Emacs session.
638 ;; The `printing' menu (Tools/Printing or File/Print) has the following layout:
640 ;; +-----------------------------+
641 ;; A 0 | Printing Interface |
642 ;; +-----------------------------+ +-A---------+ +-B------+
643 ;; I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
644 ;; 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
645 ;; 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
646 ;; +-----------------------------+ |Mode >|-- B |Other...|
647 ;; II 4 | Printify >|-----\ |File >|--\ +--------+
648 ;; 5 | Print >|---\ | |Despool... | |
649 ;; 6 | Text Printer: name >|-\ | | +-----------+ |
650 ;; +-----------------------------+ | | | +---------+ +------------+
651 ;; III 7 |[ ]Landscape | | | \-|Directory| | No Prep... | Ia
652 ;; 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
653 ;; 9 |[ ]Print Header Frame | | | |Region | | name >|- C
654 ;; 10 |[ ]Line Number | | | +---------+ +------------+
655 ;; 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
656 ;; 12 |[ ]Duplex | | \---|Directory| | 2-up... |
657 ;; 13 |[ ]Tumble | \--\ |Buffer | | 4-up... |
658 ;; 14 |[ ]Upside-Down | | |Region | | Other... |
659 ;; 15 | Print All Pages >|--\ | |Mode | +------------+
660 ;; +-----------------------------+ | | +---------+ |[ ]Landscape| Id
661 ;; IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
662 ;; 17 |[ ]Print with faces | | \--|( )name A| |[ ]Tumble | If
663 ;; 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
664 ;; +-----------------------------+ | |... |
665 ;; V 19 |[ ]Auto Region | | |(*)name |
666 ;; 20 |[ ]Auto Mode | | |... |
667 ;; 21 |[ ]Menu Lock | | +---------+ +--------------+
668 ;; +-----------------------------+ \------------------|(*)All Pages |
669 ;; VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
670 ;; 23 | Show Settings >|-------|printing| |( )Odd Pages |
671 ;; 24 | Help | |ps-print| |( )Even Sheets|
672 ;; +-----------------------------+ |lpr | |( )Odd Sheets |
673 ;; +--------+ +--------------+
675 ;; See `pr-visible-entry-list' for hiding some parts of the menu.
677 ;; The menu has the following sections:
681 ;; 0. You can use a buffer interface instead of menus. It looks like the
682 ;; customization buffer. Basically, it has the same options found in the
683 ;; menu and some extra options, all this on a buffer.
685 ;; I. PostScript printing:
687 ;; 1. You can generate a PostScript file (if you type C-u before activating
688 ;; menu) or PostScript temporary file for a directory, a buffer, a region
689 ;; or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
690 ;; after file generation, ghostview is activated using the file generated
691 ;; as argument. This option is disabled if spooling is on (option 16).
692 ;; Also, if you already have a PostScript file you can preview it.
693 ;; Instead of previewing each buffer, region or major mode at once, you
694 ;; can save temporarily the PostScript code generated in a buffer and
695 ;; preview it later. The option `Despool...' despools the PostScript
696 ;; spooling buffer in a temporary file and uses ghostview to preview it.
697 ;; If you type C-u before choosing this option, the PostScript code
698 ;; generated is saved in a file instead of saving in a temporary file.
699 ;; To spool the PostScript code generated you need to turn on the option
700 ;; 16. The option `Despool...' is enabled if spooling is on (option
703 ;; NOTE 1: It's possible to customize a major mode printing, just declare
704 ;; the customization in `pr-mode-alist' and invoke some of
705 ;; `*-mode*' commands or select Mode option in Printing menu. An
706 ;; example for major mode usage is when you're using gnus (or mh,
707 ;; or rmail, etc.) and you're in the *Summary* buffer, if you
708 ;; forget to switch to the *Article* buffer before printing,
709 ;; you'll get a nicely formatted list of article subjects shows
710 ;; up at the printer. With major mode printing you don't need to
711 ;; switch from gnus *Summary* buffer first.
713 ;; NOTE 2: There are the following options for PostScript file
715 ;; Ia. Print the file *No Preprocessing*, that is, send it
716 ;; directly to PostScript printer.
717 ;; Ib. PostScript utility processing selection.
718 ;; See `pr-ps-utility-alist' and `pr-setting-database' for
720 ;; Ic. Do n-up processing before printing.
721 ;; Id. Toggle on/off landscape for PostScript file processing.
722 ;; Ie. Toggle on/off duplex for PostScript file processing.
723 ;; If. Toggle on/off tumble for PostScript file processing.
725 ;; NOTE 3: Don't forget to download and install the utilities declared on
726 ;; `pr-ps-utility-alist'.
728 ;; 2. Operate the same way as option 1, but it sends directly the PostScript
729 ;; code (or put in a file, if you've typed C-u) or it uses ghostscript to
730 ;; print the PostScript file generated. It depends on option 18, if it's
731 ;; turned on, it uses ghostscript; otherwise, it sends directly to
732 ;; printer. If spooling is on (option 16), the PostScript code is saved
733 ;; temporarily in a buffer instead of printing it or saving it in a file.
734 ;; Also, if you already have a PostScript file you can print it. Instead
735 ;; of printing each buffer, region or major mode at once, you can save
736 ;; temporarily the PostScript code generated in a buffer and print it
737 ;; later. The option `Despool...' despools the PostScript spooling
738 ;; buffer directly on a printer. If you type C-u before choosing this
739 ;; option, the PostScript code generated is saved in a file instead of
740 ;; sending to printer. To spool the PostScript code generated you need
741 ;; to turn on the option 16. This option is enabled if spooling is on
742 ;; (option 16). See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
744 ;; 3. You can select a new PostScript printer to send PostScript code
745 ;; generated. For selection it's used all PostScript printers defined
746 ;; in `pr-ps-printer-alist' variable (see it for documentation).
747 ;; See also `pr-setting-database'.
749 ;; II. Text printing:
751 ;; 4. If you have control characters (character code from \000 to \037) in a
752 ;; buffer and you want to print them in a text printer, select this
753 ;; option. All control characters in your buffer or region will be
754 ;; replaced by a printable representation. The printable representations
755 ;; use ^ (for ASCII control characters) or hex. The characters tab,
756 ;; linefeed, space, return and formfeed are not affected. You don't need
757 ;; to select this option if you use any option of section I, the
758 ;; PostScript engine treats control characters properly.
760 ;; 5. If you want to print a directory, buffer, region or major mode in a
761 ;; text printer, select this option. See also the NOTE 1 on option 1.
763 ;; 6. You can select a new text printer to send text generated. For
764 ;; selection it's used all text printers defined in
765 ;; `pr-txt-printer-alist' variable (see it for documentation).
766 ;; See also `pr-setting-database'.
768 ;; III. PostScript page toggle options:
770 ;; 7. If you want a PostScript landscape printing, turn on this option.
772 ;; 8. If you want to have a header in each page in your PostScript code,
773 ;; turn on this option.
775 ;; 9. If you want to draw a gaudy frame around the header, turn on this
776 ;; option. This option is enabled if print header is on (option 8).
778 ;; 10. If you want that the line number is printed in your PostScript code,
779 ;; turn on this option.
781 ;; 11. If you want background zebra stripes in your PostScript code, turn on
784 ;; 12. If you want a duplex printing and your PostScript printer has this
785 ;; feature, turn on this option.
787 ;; 13. If you turned on duplex printing, you can choose if you want to have
788 ;; a printing suitable for binding on the left or right (tumble off), or
789 ;; to have a printing suitable for binding at top or bottom (tumble on).
790 ;; This option is enabled if duplex is on (option 12).
792 ;; 14. If you want a PostScript upside-down printing, turn on this option.
794 ;; 15. With this option, you can choose if you want to print all pages, odd
795 ;; pages, even pages, odd sheets or even sheets.
796 ;; See also `ps-even-or-odd-pages'.
798 ;; IV. PostScript processing toggle options:
800 ;; 16. If you want to spool the PostScript code generated, turn on this
801 ;; option. To spool the PostScript code generated use option 2. You
802 ;; can despool later by choosing option 1 or 2, sub-option `Despool...'.
804 ;; 17. If you use colors in your buffers and want to see these colors on
805 ;; your PostScript code generated, turn on this option. If you have a
806 ;; black/white PostScript printer, these colors are displayed in gray
807 ;; scale by PostScript printer interpreter.
809 ;; 18. If you don't have a PostScript printer to send PostScript files, turn
810 ;; on this option. When this option is on, the ghostscript is used to
811 ;; print PostScript files. In GNU or Unix system, if ghostscript is set
812 ;; as a PostScript filter, you don't need to turn on this option.
814 ;; V. Printing customization:
816 ;; 19. If you want that region is automagically detected, turn on this
817 ;; option. Note that this will only work if you're using transient mark
818 ;; mode. When this option is on, the `*-buffer*' commands will behave
819 ;; like `*-region*' commands, that is, `*-buffer*' commands will print
820 ;; only the region marked instead of all buffer.
822 ;; 20. Turn this option on if you want that when current major-mode is
823 ;; declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
824 ;; behave like `*-mode*' commands.
826 ;; 21. If you want that Printing menu stays open while you are setting
827 ;; toggle options, turn on this option. The variables
828 ;; `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
829 ;; menu position, so don't forget to adjust these variables if menu
830 ;; position is not ok.
832 ;; VI. Customization:
834 ;; 22. Besides all options in section III, IV and V, you can customize much
835 ;; more PostScript options in `ps-print' option. Or you can customize
836 ;; some `lpr' options for text printing. Or customize `printing'
839 ;; 23. Show current settings for `printing', `ps-print' or `lpr'.
841 ;; 24. Quick help for printing menu layout.
847 ;; Below it's shown only the main options that affect all `printing' package.
848 ;; Check all the settings below *BEFORE* running `printing' commands.
850 ;; * Example of setting for GNU or Unix system:
852 ;; (require 'printing)
853 ;; (setq pr-path-alist
854 ;; '((unix "." "~/bin" ghostview mpage PATH)
855 ;; (ghostview "$HOME/bin/gsview-dir")
856 ;; (mpage "$HOME/bin/mpage-dir")
858 ;; (setq pr-txt-name 'prt_06a)
859 ;; (setq pr-txt-printer-alist
860 ;; '((prt_06a "lpr" nil "prt_06a")
861 ;; (prt_07c nil nil "prt_07c")
863 ;; (setq pr-ps-name 'lps_06b)
864 ;; (setq pr-ps-printer-alist
865 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
866 ;; (lps_07c "lpr" nil nil "lps_07c")
867 ;; (lps_08c nil nil nil "lps_08c")
869 ;; (setq pr-temp-dir "/tmp/")
870 ;; (setq pr-gv-command "gv")
871 ;; (setq pr-gs-command "gs")
872 ;; (setq pr-gs-switches '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
873 ;; (setq pr-gs-device "uniprint")
874 ;; (setq pr-gs-resolution 300)
875 ;; (setq pr-ps-utility 'mpage)
876 ;; (setq pr-ps-utility-alist
877 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
878 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
879 ;; (inherits-from: . no-duplex))
881 ;; (setq pr-setting-database
884 ;; (pr-file-duplex . nil)
885 ;; (pr-file-tumble . nil))
887 ;; (pr-update-menus t) ; update now printer and utility menus
889 ;; * Example of setting for Windows system:
891 ;; (require 'printing)
892 ;; (setq pr-path-alist
893 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
894 ;; (ghostview "c:/gs/gsview-dir")
895 ;; (mpage "c:/mpage-dir")
897 ;; (setq pr-txt-name 'prt_06a)
898 ;; (setq pr-txt-printer-alist
899 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
900 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
901 ;; (PRN "" nil "PRN")
902 ;; (standard "redpr.exe" nil "")
904 ;; (setq pr-ps-name 'lps_06b)
905 ;; (setq pr-ps-printer-alist
906 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
907 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
908 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
909 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
910 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
911 ;; (LPT1 "" nil "" "LPT1:")
912 ;; (PRN "" nil "" "PRN")
913 ;; (standard "redpr.exe" nil "" "")
915 ;; (setq pr-temp-dir "C:/WINDOWS/TEMP/")
916 ;; (setq pr-gv-command "c:/gs/gsview/gsview32.exe")
917 ;; (setq pr-gs-command "c:/gs/gswin32.exe")
918 ;; (setq pr-gs-switches '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts"))
919 ;; (setq pr-gs-device "mswinpr2")
920 ;; (setq pr-gs-resolution 300)
921 ;; (setq pr-ps-utility 'psnup)
922 ;; (setq pr-ps-utility-alist
923 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " "
924 ;; nil (inherits-from: . no-duplex))
926 ;; (setq pr-setting-database
929 ;; (pr-file-duplex . nil)
930 ;; (pr-file-tumble . nil))
932 ;; (pr-update-menus t) ; update now printer and utility menus
934 ;; NOTE: Don't forget to download and install the utilities declared on
935 ;; `pr-ps-utility-alist'.
941 ;; `printing' package has the following utilities:
943 ;; `pr-setup' Return the current `printing' setup.
945 ;; `lpr-setup' Return the current `lpr' setup.
947 ;; `pr-update-menus' Update utility, PostScript and text printer menus.
949 ;; `pr-menu-bind' Install `printing' menu in the menubar.
952 ;; Below are some URL where you can find good utilities.
954 ;; * For `printing' package:
956 ;; printing `http://www.emacswiki.org/cgi-bin/emacs/download/printing.el'
957 ;; ps-print `http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'
959 ;; * For GNU or Unix system:
961 ;; gs, gv `http://www.gnu.org/software/ghostscript/ghostscript.html'
962 ;; enscript `http://people.ssh.fi/mtr/genscript/'
963 ;; psnup `http://www.knackered.org/angus/psutils/'
964 ;; mpage `http://www.mesa.nl/pub/mpage/'
966 ;; * For Windows system:
969 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'
970 ;; gsprint `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
971 ;; enscript `http://people.ssh.fi/mtr/genscript/'
972 ;; psnup `http://gnuwin32.sourceforge.net/packages/psutils.htm'
973 ;; redmon `http://www.cs.wisc.edu/~ghost/redmon/'
979 ;; Thanks to Stefan Monnier <monnier@iro.umontreal.ca> for GNU Emacs and XEmacs
980 ;; printing menu (in `pr-menu-spec') merging suggestion.
982 ;; Thanks to Lennart Borgman <lennart.borgman.073@student.lu.se> for gsprint
983 ;; suggestion (see tip 5 in section Tips).
985 ;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions:
986 ;; - directory processing.
987 ;; - `pr-path-alist' variable.
989 ;; - a lot of tests on Windows.
991 ;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests.
993 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging
994 ;; and for suggestions:
995 ;; - even/odd pages printing.
996 ;; - ghostscript parameters for `pr-ps-printer-alist'.
997 ;; - default printer name.
998 ;; - completion functions.
999 ;; - automagic region detection.
1000 ;; - menu entry hiding.
1001 ;; - fast fire PostScript printing command.
1002 ;; - `pr-path-style' variable.
1004 ;; Thanks to Kim F. Storm <storm@filanet.dk> for beta-test and for suggestions:
1005 ;; - PostScript Print and PostScript Print Preview merge.
1006 ;; - Tools/Printing menu.
1007 ;; - replace *-using-preview by *-using-ghostscript.
1008 ;; - printer selection.
1009 ;; - extra parameters for `pr-ps-printer-alist'.
1012 ;; Frederic Corne <frederic.corne@erli.fr> print-nt.el
1013 ;; Tom Vogels <tov@ece.cmu.edu> mh-e-init.el
1014 ;; Matthew O. Persico <mpersico@erols.com> win32-ps-print.el
1015 ;; Volker Franz <volker.franz@tuebingen.mpg.de> ps-print-interface.el
1016 ;; And to all people who contributed with them.
1019 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1028 (and (string< ps-print-version
"6.6.4")
1029 (error "`printing' requires `ps-print' package version 6.6.4 or later"))
1032 (defconst pr-cygwin-system
1033 (and lpr-windows-system
(getenv "OSTYPE")
1034 (string-match "cygwin" (getenv "OSTYPE"))))
1037 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1038 ;; To avoid compilation gripes
1041 ;; Emacs has this since at least 21.1.
1042 (when (featurep 'xemacs
)
1043 (or (fboundp 'subst-char-in-string
) ; hacked from subr.el
1044 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
1045 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1046 Unless optional argument INPLACE is non-nil, return a new string."
1047 (let ((i (length string
))
1048 (newstr (if inplace string
(copy-sequence string
))))
1049 (while (> (setq i
(1- i
)) 0)
1050 (if (eq (aref newstr i
) fromchar
)
1051 (aset newstr i tochar
)))
1055 ;; Emacs has this since at least 21.1, but the SUFFIX argument
1056 ;; (which this file uses) only since 22.1. So the fboundp test
1057 ;; wasn't even correct/adequate. Whatever, no-one is using
1058 ;; this file on older Emacs version, so it's irrelevant.
1059 (when (featurep 'xemacs
)
1060 (or (fboundp 'make-temp-file
) ; hacked from subr.el
1061 (defun make-temp-file (prefix &optional dir-flag suffix
)
1062 "Create a temporary file.
1063 The returned file name (created by appending some random characters at the end
1064 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1065 is guaranteed to point to a newly created empty file.
1066 You can then use `write-region' to write new data into the file.
1068 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1070 If SUFFIX is non-nil, add that at the end of the file name."
1071 (let ((umask (default-file-modes))
1075 ;; Create temp files with strict access rights. It's easy to
1076 ;; loosen them later, whereas it's impossible to close the
1077 ;; time-window of loose permissions otherwise.
1078 (set-default-file-modes ?
\700)
1079 (while (condition-case ()
1083 (expand-file-name prefix temporary-file-directory
)))
1085 (setq file
(concat file suffix
)))
1087 (make-directory file
)
1088 (write-region "" nil file nil
'silent nil
'excl
))
1090 (file-already-exists t
))
1091 ;; the file was somehow created by someone else between
1092 ;; `make-temp-name' and `write-region', let's try again.
1096 (set-default-file-modes umask
))))))
1100 ;; User Interface --- declared here to avoid compiler warnings
1101 (defvar pr-path-style
)
1102 (defvar pr-auto-region
)
1103 (defvar pr-menu-char-height
)
1104 (defvar pr-menu-char-width
)
1105 (defvar pr-menu-lock
)
1106 (defvar pr-ps-printer-alist
)
1107 (defvar pr-txt-printer-alist
)
1108 (defvar pr-ps-utility-alist
)
1111 ;; Internal fun alias to avoid compilation gripes
1112 (defalias 'pr-menu-lookup
'ignore
)
1113 (defalias 'pr-menu-lock
'ignore
)
1114 (defalias 'pr-menu-alist
'ignore
)
1115 (defalias 'pr-even-or-odd-pages
'ignore
)
1116 (defalias 'pr-menu-get-item
'ignore
)
1117 (defalias 'pr-menu-set-item-name
'ignore
)
1118 (defalias 'pr-menu-set-utility-title
'ignore
)
1119 (defalias 'pr-menu-set-ps-title
'ignore
)
1120 (defalias 'pr-menu-set-txt-title
'ignore
)
1121 (defalias 'pr-region-active-p
'ignore
)
1122 (defalias 'pr-do-update-menus
'ignore
)
1123 (defalias 'pr-update-mode-line
'ignore
)
1124 (defalias 'pr-read-string
'ignore
)
1125 (defalias 'pr-set-keymap-parents
'ignore
)
1126 (defalias 'pr-keep-region-active
'ignore
))
1129 ;; Internal Vars --- defined here to avoid compiler warnings
1130 (defvar pr-menu-print-item
"print"
1131 "Non-nil means that menu binding was not done.
1133 Used by `pr-menu-bind' and `pr-update-menus'.")
1135 (defvar pr-ps-printer-menu-modified t
1136 "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
1138 (defvar pr-txt-printer-menu-modified t
1139 "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
1141 (defvar pr-ps-utility-menu-modified t
1142 "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
1144 (defconst pr-even-or-odd-alist
1145 '((nil .
"Print All Pages")
1146 (even-page .
"Print Even Pages")
1147 (odd-page .
"Print Odd Pages")
1148 (even-sheet .
"Print Even Sheets")
1149 (odd-sheet .
"Print Odd Sheets")))
1152 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1153 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1154 ;; XEmacs Definitions
1158 ((featurep 'xemacs
) ; XEmacs
1160 (defalias 'pr-set-keymap-parents
'set-keymap-parents
)
1161 (defalias 'pr-set-keymap-name
'set-keymap-name
)
1164 (defun pr-read-string (prompt initial history default
)
1165 (let ((str (read-string prompt initial
)))
1166 (if (and str
(not (string= str
"")))
1171 (defvar zmacs-region-stays nil
)
1174 (defun pr-keep-region-active ()
1175 (setq zmacs-region-stays t
))
1178 (defun pr-region-active-p ()
1179 (and pr-auto-region
(not zmacs-region-stays
) (ps-mark-active-p)))
1182 (defun pr-menu-char-height ()
1183 (font-height (face-font 'default
)))
1186 (defun pr-menu-char-width ()
1187 (font-width (face-font 'default
)))
1190 (defmacro pr-xemacs-global-menubar
(&rest body
)
1192 (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
1193 ;; be sure to access global menubar
1196 (kill-buffer temp
))))
1199 (defun pr-global-menubar (pr-menu-spec)
1201 (pr-xemacs-global-menubar
1202 (add-submenu nil
(cons "Printing" pr-menu-spec
) "Apps"))
1203 (setq pr-menu-print-item nil
))
1206 (defvar current-mouse-event nil
)
1207 (defun pr-menu-position (entry index horizontal
)
1211 'x
(- (event-x-pixel current-mouse-event
) ; X
1212 (* horizontal pr-menu-char-width
))
1213 'y
(- (event-y-pixel current-mouse-event
) ; Y
1214 (* (pr-menu-index entry index
) pr-menu-char-height
)))))
1216 (defvar pr-menu-position nil
)
1217 (defvar pr-menu-state nil
)
1220 (defvar current-menubar nil
) ; to avoid compilation gripes
1221 (defun pr-menu-lookup (path)
1222 (car (find-menu-item current-menubar
(cons "Printing" path
))))
1225 (defun pr-menu-lock (entry index horizontal state path
)
1227 (or (and pr-menu-position
(eq state pr-menu-state
))
1228 (setq pr-menu-position
(pr-menu-position entry index horizontal
)
1229 pr-menu-state state
))
1230 (let* ((menu (pr-menu-lookup path
))
1231 (result (get-popup-menu-response menu pr-menu-position
)))
1232 (and (misc-user-event-p result
)
1233 (funcall (event-function result
)
1234 (event-object result
))))
1235 (setq pr-menu-position nil
)))
1238 (defalias 'pr-update-mode-line
'set-menubar-dirty-flag
)
1241 (defvar pr-ps-name-old
"PostScript Printers")
1242 (defvar pr-txt-name-old
"Text Printers")
1243 (defvar pr-ps-utility-old
"PostScript Utility")
1244 (defvar pr-even-or-odd-old
"Print All Pages")
1247 (defun pr-do-update-menus (&optional force
)
1248 (pr-menu-alist pr-ps-printer-alist
1250 'pr-menu-set-ps-title
1252 'pr-ps-printer-menu-modified
1256 (pr-menu-alist pr-txt-printer-alist
1258 'pr-menu-set-txt-title
1260 'pr-txt-printer-menu-modified
1264 (let ((save-var pr-ps-utility-menu-modified
))
1265 (pr-menu-alist pr-ps-utility-alist
1267 'pr-menu-set-utility-title
1268 '("Printing" "PostScript Print" "File")
1273 (pr-menu-alist pr-ps-utility-alist
1275 'pr-menu-set-utility-title
1276 '("Printing" "PostScript Preview" "File")
1277 'pr-ps-utility-menu-modified
1281 (pr-even-or-odd-pages ps-even-or-odd-pages force
))
1284 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1286 (when (and alist
(or force
(symbol-value modified-sym
)))
1287 (pr-xemacs-global-menubar
1288 (add-submenu menu-path
1289 (pr-menu-create name alist var-sym
1291 (funcall fun
(symbol-value var-sym
))
1292 (set modified-sym nil
)))
1295 (defun pr-relabel-menu-item (newname var-sym
)
1296 (pr-xemacs-global-menubar
1298 (list "Printing" (symbol-value var-sym
))
1300 (set var-sym newname
)))
1303 (defun pr-menu-set-ps-title (value &optional item entry index
)
1304 (pr-relabel-menu-item (format "PostScript Printer: %s" value
)
1306 (pr-ps-set-printer value
)
1308 (pr-menu-lock entry index
12 'toggle nil
)))
1311 (defun pr-menu-set-txt-title (value &optional item entry index
)
1312 (pr-relabel-menu-item (format "Text Printer: %s" value
)
1314 (pr-txt-set-printer value
)
1316 (pr-menu-lock entry index
12 'toggle nil
)))
1319 (defun pr-menu-set-utility-title (value &optional item entry index
)
1320 (pr-xemacs-global-menubar
1321 (let ((newname (format "%s" value
)))
1323 (list "Printing" "PostScript Print" "File" pr-ps-utility-old
)
1326 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old
)
1328 (setq pr-ps-utility-old newname
)))
1329 (pr-ps-set-utility value
)
1331 (pr-menu-lock entry index
5 nil
'("PostScript Print" "File"))))
1334 (defun pr-even-or-odd-pages (value &optional no-lock
)
1335 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist
))
1336 'pr-even-or-odd-old
)
1337 (setq ps-even-or-odd-pages value
)
1339 (pr-menu-lock 'postscript-options
8 12 'toggle nil
)))
1344 )) ; end cond featurep
1348 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1349 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1350 ;; GNU Emacs Definitions
1353 (unless (featurep 'xemacs
)
1354 (defvar pr-menu-bar nil
1355 "Specify Printing menu-bar entry.")))
1358 ((featurep 'xemacs
) ; XEmacs
1363 (defalias 'pr-set-keymap-parents
'set-keymap-parent
)
1364 (defalias 'pr-set-keymap-name
'ignore
)
1365 (defalias 'pr-read-string
'read-string
)
1368 (defvar deactivate-mark
)
1371 (defun pr-keep-region-active ()
1372 (setq deactivate-mark nil
))
1375 (defun pr-region-active-p ()
1376 (and pr-auto-region transient-mark-mode mark-active
))
1379 (defun pr-menu-char-height ()
1380 (frame-char-height))
1383 (defun pr-menu-char-width ()
1388 ;; Replace existing "print" item by "Printing" item.
1389 ;; If you're changing this file, you'll load it a second,
1390 ;; third... time, but "print" item exists only in the first load.
1392 (require 'easymenu
)) ; to avoid compilation gripes
1394 (declare-function easy-menu-add-item
"easymenu"
1395 (map path item
&optional before
))
1396 (declare-function easy-menu-remove-item
"easymenu" (map path name
))
1399 (defun pr-global-menubar (pr-menu-spec)
1401 (let ((menu-file (if (= emacs-major-version
21)
1402 '("menu-bar" "files") ; GNU Emacs 21
1403 '("menu-bar" "file")))) ; GNU Emacs 22 or higher
1406 (easy-menu-add-item global-map menu-file
1407 (easy-menu-create-menu "Print" pr-menu-spec
)
1409 (dolist (item '("print-buffer" "print-region"
1410 "ps-print-buffer-faces" "ps-print-region-faces"
1411 "ps-print-buffer" "ps-print-region"))
1412 (easy-menu-remove-item global-map menu-file item
))
1413 (setq pr-menu-print-item nil
1414 pr-menu-bar
(vector 'menu-bar
1415 (pr-get-symbol (nth 1 menu-file
))
1416 (pr-get-symbol "Print"))))
1418 (easy-menu-add-item global-map menu-file
1419 (easy-menu-create-menu "Print" pr-menu-spec
)))
1425 ;; GNU Emacs for Windows 9x/NT
1426 (defun pr-menu-position (entry index horizontal
)
1427 (let ((pos (cdr (mouse-pixel-position))))
1429 (list (or (car pos
) 0) ; X
1430 (- (or (cdr pos
) 0) ; Y
1431 (* (pr-menu-index entry index
) pr-menu-char-height
)))
1432 (selected-frame)))) ; frame
1436 (defun pr-menu-position (entry index horizontal
)
1437 (let ((pos (cdr (mouse-pixel-position))))
1439 (list (- (or (car pos
) 0) ; X
1440 (* horizontal pr-menu-char-width
))
1441 (- (or (cdr pos
) 0) ; Y
1442 (* (pr-menu-index entry index
) pr-menu-char-height
)))
1443 (selected-frame)))) ; frame
1446 (defvar pr-menu-position nil
)
1447 (defvar pr-menu-state nil
)
1450 (defun pr-menu-lookup (path)
1451 (lookup-key global-map
1453 (vconcat pr-menu-bar
1454 (mapcar 'pr-get-symbol
1461 (defun pr-menu-lock (entry index horizontal state path
)
1463 (or (and pr-menu-position
(eq state pr-menu-state
))
1464 (setq pr-menu-position
(pr-menu-position entry index horizontal
)
1465 pr-menu-state state
))
1466 (let* ((menu (pr-menu-lookup path
))
1467 (result (x-popup-menu pr-menu-position menu
)))
1469 (let ((command (lookup-key menu
(vconcat result
))))
1470 (if (fboundp command
)
1473 (setq pr-menu-position nil
)))
1476 (defalias 'pr-update-mode-line
'force-mode-line-update
)
1479 (defun pr-do-update-menus (&optional force
)
1480 (pr-menu-alist pr-ps-printer-alist
1482 'pr-menu-set-ps-title
1483 "PostScript Printers"
1484 'pr-ps-printer-menu-modified
1486 "PostScript Printers"
1488 (pr-menu-alist pr-txt-printer-alist
1490 'pr-menu-set-txt-title
1492 'pr-txt-printer-menu-modified
1496 (let ((save-var pr-ps-utility-menu-modified
))
1497 (pr-menu-alist pr-ps-utility-alist
1499 'pr-menu-set-utility-title
1500 '("PostScript Print" "File" "PostScript Utility")
1503 "PostScript Utility"
1505 (pr-menu-alist pr-ps-utility-alist
1507 'pr-menu-set-utility-title
1508 '("PostScript Preview" "File" "PostScript Utility")
1509 'pr-ps-utility-menu-modified
1511 "PostScript Utility"
1513 (pr-even-or-odd-pages ps-even-or-odd-pages force
))
1516 (defun pr-menu-get-item (name-list)
1517 ;; NAME-LIST is a string or a list of strings.
1518 (or (listp name-list
)
1519 (setq name-list
(list name-list
)))
1521 (let* ((reversed (reverse name-list
))
1522 (name (pr-get-symbol (car reversed
)))
1523 (path (nreverse (cdr reversed
)))
1526 (vconcat pr-menu-bar
1527 (mapcar 'pr-get-symbol path
)))))
1528 (assq name
(nthcdr 2 menu
)))))
1531 (defvar pr-temp-menu nil
)
1534 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1536 (when (and alist
(or force
(symbol-value modified-sym
)))
1537 (easy-menu-define pr-temp-menu nil
""
1538 (pr-menu-create name alist var-sym fun entry index
))
1539 (let ((item (pr-menu-get-item menu-path
)))
1541 (let* ((binding (nthcdr 3 item
))
1542 (key-binding (cdr binding
)))
1543 (setcar binding pr-temp-menu
)
1544 (and key-binding
(listp (car key-binding
))
1545 (setcdr binding
(cdr key-binding
))) ; skip KEY-BINDING
1546 (funcall fun
(symbol-value var-sym
) item
))))
1547 (set modified-sym nil
)))
1550 (defun pr-menu-set-item-name (item name
)
1552 (setcar (nthcdr 2 item
) name
))) ; ITEM-NAME
1555 (defun pr-menu-set-ps-title (value &optional item entry index
)
1556 (pr-menu-set-item-name (or item
1557 (pr-menu-get-item "PostScript Printers"))
1558 (format "PostScript Printer: %s" value
))
1559 (pr-ps-set-printer value
)
1561 (pr-menu-lock entry index
12 'toggle nil
)))
1564 (defun pr-menu-set-txt-title (value &optional item entry index
)
1565 (pr-menu-set-item-name (or item
1566 (pr-menu-get-item "Text Printers"))
1567 (format "Text Printer: %s" value
))
1568 (pr-txt-set-printer value
)
1570 (pr-menu-lock entry index
12 'toggle nil
)))
1573 (defun pr-menu-set-utility-title (value &optional item entry index
)
1574 (let ((name (symbol-name value
)))
1576 (pr-menu-set-item-name item name
)
1577 (pr-menu-set-item-name
1579 '("PostScript Print" "File" "PostScript Utility"))
1581 (pr-menu-set-item-name
1583 '("PostScript Preview" "File" "PostScript Utility"))
1585 (pr-ps-set-utility value
)
1587 (pr-menu-lock entry index
5 nil
'("PostScript Print" "File"))))
1590 (defun pr-even-or-odd-pages (value &optional no-lock
)
1591 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
1592 (cdr (assq value pr-even-or-odd-alist
)))
1593 (setq ps-even-or-odd-pages value
)
1595 (pr-menu-lock 'postscript-options
8 12 'toggle nil
)))
1597 )) ; end cond featurep
1600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1601 ;; Internal Functions (I)
1604 (defun pr-dosify-file-name (path)
1605 "Replace unix-style directory separator character with dos/windows one."
1606 (interactive "sPath: ")
1607 (if (eq pr-path-style
'windows
)
1608 (subst-char-in-string ?
/ ?
\\ path
)
1612 (defun pr-unixify-file-name (path)
1613 "Replace dos/windows-style directory separator character with unix one."
1614 (interactive "sPath: ")
1615 (if (eq pr-path-style
'windows
)
1616 (subst-char-in-string ?
\\ ?
/ path
)
1620 (defun pr-standard-file-name (path)
1621 "Ensure the proper directory separator depending on the OS.
1622 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
1623 separator; otherwise, ensure unix-style directory separator."
1624 (if (or pr-cygwin-system lpr-windows-system
)
1625 (subst-char-in-string ?
/ ?
\\ path
)
1626 (subst-char-in-string ?
\\ ?
/ path
)))
1629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1630 ;; Customization Functions
1633 (defun pr-alist-custom-set (symbol value
)
1634 "Set the value of custom variables for printer & utility selection."
1636 (and (featurep 'printing
) ; update only after printing is loaded
1637 (pr-update-menus t
)))
1640 (defun pr-ps-utility-custom-set (symbol value
)
1641 "Update utility menu entry."
1643 (and (featurep 'printing
) ; update only after printing is loaded
1644 (pr-menu-set-utility-title value
)))
1647 (defun pr-ps-name-custom-set (symbol value
)
1648 "Update `PostScript Printer:' menu entry."
1650 (and (featurep 'printing
) ; update only after printing is loaded
1651 (pr-menu-set-ps-title value
)))
1654 (defun pr-txt-name-custom-set (symbol value
)
1655 "Update `Text Printer:' menu entry."
1657 (and (featurep 'printing
) ; update only after printing is loaded
1658 (pr-menu-set-txt-title value
)))
1661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1665 (defgroup printing nil
1666 "Printing Utilities group."
1667 :tag
"Printing Utilities"
1668 :link
'(emacs-library-link :tag
"Source Lisp File" "printing.el")
1675 (defcustom pr-path-style
1676 (if (and (not pr-cygwin-system
)
1680 "Specify which path style to use for external commands.
1684 windows Windows 9x/NT style (\\)
1686 unix Unix style (/)"
1687 :type
'(choice :tag
"Path style"
1688 (const :tag
"Windows 9x/NT Style (\\)" :value windows
)
1689 (const :tag
"Unix Style (/)" :value unix
))
1693 (defcustom pr-path-alist
1697 "Specify an alist for command paths.
1699 It's used to find commands used for printing package, like gv, gs, gsview.exe,
1700 mpage, print.exe, etc. See also `pr-command' function.
1702 Each element has the form:
1704 (ENTRY DIRECTORY...)
1708 ENTRY It's a symbol, used to identify this entry.
1709 There must exist at least one of the following entries:
1711 unix this entry is used when Emacs is running on GNU or
1714 cygwin this entry is used when Emacs is running on Windows
1715 95/98/NT/2000 with Cygwin.
1717 windows this entry is used when Emacs is running on Windows
1720 DIRECTORY It should be a string or a symbol. If it's a symbol, it should
1721 exist an equal entry in `pr-path-alist'. If it's a string,
1722 it's considered a directory specification.
1724 The directory specification may contain:
1725 $var environment variable expansion
1727 ./ current directory
1728 ../ previous directory
1730 For example, let's say the home directory is /home/my and the
1731 current directory is /home/my/dir, so:
1733 THE ENTRY IS EXPANDED TO
1734 ~/entry /home/my/entry
1735 ./entry /home/my/dir/entry
1736 ../entry /home/my/entry
1737 $HOME/entry /home/my/entry
1738 $HOME/~/other/../my/entry /home/my/entry
1740 SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
1741 list and there isn't a `PATH' entry in `pr-path-alist' or the
1742 `PATH' entry has a null directory list, the PATH environment
1747 * On GNU or Unix system:
1749 '((unix \".\" \"~/bin\" ghostview mpage PATH)
1750 (ghostview \"$HOME/bin/gsview-dir\")
1751 (mpage \"$HOME/bin/mpage-dir\")
1754 * On Windows system:
1756 '((windows \"c:/applications/executables\" PATH ghostview mpage)
1757 (ghostview \"c:/gs/gsview-dir\")
1758 (mpage \"c:/mpage-dir\")
1762 (symbol :tag
"Identifier ")
1763 (repeat :tag
"Directory List"
1764 (choice :menu-tag
"Directory"
1767 (symbol :value symbol
)))))
1771 (defcustom pr-txt-name
'default
1772 "Specify a printer for printing a text file.
1774 The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
1777 This variable should be modified by customization engine. If this variable is
1778 modified by other means (for example, a lisp function), use `pr-update-menus'
1779 function (see it for documentation) to update text printer menu."
1781 :set
'pr-txt-name-custom-set
1785 (defcustom pr-txt-printer-alist
1786 (list (list 'default lpr-command nil
1787 (cond ((boundp 'printer-name
) printer-name
)
1788 (lpr-windows-system "PRN")
1792 ;; * On GNU or Unix system:
1793 ;; '((prt_06a "lpr" nil "prt_06a")
1794 ;; (prt_07c nil nil "prt_07c")
1796 ;; * On Windows system:
1797 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
1798 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
1799 ;; (PRN "" nil "PRN")
1800 ;; (standard "redpr.exe" nil "")
1802 "Specify an alist of all text printers (text printer database).
1804 The alist element has the form:
1806 (SYMBOL COMMAND SWITCHES NAME)
1810 SYMBOL It's a symbol to identify a text printer. It's for
1811 setting option `pr-txt-name' and for menu selection.
1816 COMMAND Name of the program for printing a text file. On MS-DOS and
1817 MS-Windows systems, if the value is an empty string, then Emacs
1818 will write directly to the printer port given by NAME (see text
1819 below), that is, the NAME should be something like \"PRN\" or
1821 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1822 COMMAND shouldn't be an empty string.
1823 The programs `print' and `nprint' (the standard print programs
1824 on Windows NT and Novell Netware respectively) are handled
1825 specially, using NAME as the destination for output; any other
1826 program is treated like `lpr' except that an explicit filename
1827 is given as the last argument.
1828 If COMMAND is nil, it's used the default printing program:
1829 `print' for Windows system, `lp' for lp system and `lpr' for
1830 all other systems. See also `pr-path-alist'.
1836 SWITCHES List of sexp's to pass as extra options for text printer
1837 program. It is recommended to set NAME (see text below)
1838 instead of including an explicit switch on this list.
1844 NAME A string that specifies a text printer name.
1845 On Unix-like systems, a string value should be a name
1846 understood by lpr's -P option (or lp's -d option).
1847 On MS-DOS and MS-Windows systems, it is the name of a printer
1848 device or port. Typical non-default settings would be \"LPT1:\"
1849 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1850 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1851 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1852 printer. You can also set it to a name of a file, in which
1853 case the output gets appended to that file. If you want to
1854 discard the printed output, set this to \"NUL\".
1857 \"/D:\\\\\\\\host\\\\share-name\"
1864 This variable should be modified by customization engine. If this variable is
1865 modified by other means (for example, a lisp function), use `pr-update-menus'
1866 function (see it for documentation) to update text printer menu.
1870 * On GNU or Unix system:
1872 '((prt_06a \"lpr\" nil \"prt_06a\")
1873 (prt_07c nil nil \"prt_07c\")
1876 * On Windows system:
1878 '((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1879 (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
1880 (PRN \"\" nil \"PRN\")
1881 (standard \"redpr.exe\" nil \"\")
1886 * Information about the print command (print.exe)
1887 `http://www.computerhope.com/printhlp.htm'
1889 * RedMon - Redirection Port Monitor (redpr.exe)
1890 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1892 * Redirection Port Monitor (redpr.exe on-line help)
1893 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1895 * UNIX man pages: lpr (or type `man lpr')
1896 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1897 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1899 * UNIX man pages: lp (or type `man lp')
1900 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1901 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1904 (list :tag
"Text Printer"
1905 (symbol :tag
"Printer Symbol Name")
1906 (string :tag
"Printer Command")
1907 (repeat :tag
"Printer Switches"
1908 (sexp :tag
"Switch" :value
""))
1909 (choice :menu-tag
"Printer Name"
1911 (const :tag
"None" nil
)
1913 :set
'pr-alist-custom-set
1917 (defcustom pr-ps-name
'default
1918 "Specify a printer for printing a PostScript file.
1920 This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
1923 This variable should be modified by customization engine. If this variable is
1924 modified by other means (for example, a lisp function), use `pr-update-menus'
1925 function (see it for documentation) to update PostScript printer menu."
1927 :set
'pr-ps-name-custom-set
1931 (defcustom pr-ps-printer-alist
1932 (list (list 'default lpr-command nil
1933 (cond (lpr-windows-system nil
)
1934 (lpr-lp-system "-d")
1936 (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name
)))
1938 ;; * On GNU or Unix system:
1939 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
1940 ;; (lps_07c "lpr" nil nil "lps_07c")
1941 ;; (lps_08c nil nil nil "lps_08c")
1943 ;; * On Windows system:
1944 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
1945 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
1946 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
1947 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
1948 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
1949 ;; (LPT1 "" nil "" "LPT1:")
1950 ;; (PRN "" nil "" "PRN")
1951 ;; (standard "redpr.exe" nil "" "")
1953 "Specify an alist for all PostScript printers (PostScript printer database).
1955 The alist element has the form:
1957 (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
1961 SYMBOL It's a symbol to identify a PostScript printer. It's for
1962 setting option `pr-ps-name' and for menu selection.
1967 COMMAND Name of the program for printing a PostScript file. On MS-DOS
1968 and MS-Windows systems, if the value is an empty string then
1969 Emacs will write directly to the printer port given by NAME
1970 (see text below), that is, the NAME should be something like
1971 \"PRN\" or \"LPT1:\".
1972 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1973 COMMAND shouldn't be an empty string.
1974 The programs `print' and `nprint' (the standard print programs
1975 on Windows NT and Novell Netware respectively) are handled
1976 specially, using NAME as the destination for output; any other
1977 program is treated like `lpr' except that an explicit filename
1978 is given as the last argument.
1979 If COMMAND is nil, it's used the default printing program:
1980 `print' for Windows system, `lp' for lp system and `lpr' for
1981 all other systems. See also `pr-path-alist'.
1989 SWITCHES List of sexp's to pass as extra options for PostScript printer
1990 program. It is recommended to set NAME (see text below)
1991 instead of including an explicit switch on this list.
1998 '(\"-all\" \"-twoup\")
2000 PRINTER-SWITCH A string that specifies PostScript printer name switch. If
2001 it's necessary to have a space between PRINTER-SWITCH and NAME,
2002 it should be inserted at the end of PRINTER-SWITCH string.
2003 If PRINTER-SWITCH is nil, it's used the default printer name
2004 switch: `/D:' for Windows system, `-d' for lp system and `-P'
2005 for all other systems.
2019 NAME A string that specifies a PostScript printer name.
2020 On Unix-like systems, a string value should be a name
2021 understood by lpr's -P option (or lp's -d option).
2022 On MS-DOS and MS-Windows systems, it is the name of a printer
2023 device or port. Typical non-default settings would be \"LPT1:\"
2024 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
2025 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
2026 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
2027 printer. You can also set it to a name of a file, in which
2028 case the output gets appended to that file. If you want to
2029 discard the printed output, set this to \"NUL\".
2032 \"\\\\\\\\host\\\\share-name\"
2034 . for print.exe or gsprint.exe
2035 \"/D:\\\\\\\\host\\\\share-name\"
2036 \"\\\\\\\\host\\\\share-name\"
2043 DEFAULT It's a way to set default values when this entry is selected.
2048 Which associates VARIABLE with VALUE. When this entry is
2049 selected, it's executed the following command:
2051 (set VARIABLE (eval VALUE))
2053 Note that VALUE can be any valid lisp expression. So, don't
2054 forget to quote symbols and constant lists.
2055 If VARIABLE is the special keyword `inherits-from:', VALUE must
2056 be a symbol name setting defined in `pr-setting-database' from
2057 which the current setting inherits the context. Take care with
2058 circular inheritance.
2060 '(ps-landscape-mode . nil)
2061 '(ps-spool-duplex . t)
2062 '(pr-gs-device . (my-gs-device t))
2064 This variable should be modified by customization engine. If this variable is
2065 modified by other means (for example, a lisp function), use `pr-update-menus'
2066 function (see it for documentation) to update PostScript printer menu.
2070 * On GNU or Unix system:
2072 '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
2073 (lps_07c \"lpr\" nil nil \"lps_07c\")
2074 (lps_08c nil nil nil \"lps_08c\")
2077 * On Windows system:
2079 '((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
2080 (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
2081 (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
2082 (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
2083 (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
2084 (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
2085 (LPT1 \"\" nil \"\" \"LPT1:\")
2086 (PRN \"\" nil \"\" \"PRN\")
2087 (standard \"redpr.exe\" nil \"\" \"\")
2093 You can use gsprint instead of ghostscript to print monochrome PostScript files
2094 in Windows. The gsprint utility documentation says that it is more efficient
2095 than ghostscript to print monochrome PostScript.
2097 To print non-monochrome PostScript file, the efficiency of ghostscript is
2100 Also the gsprint utility comes together with gsview distribution.
2102 As an example of gsprint declaration:
2104 (setq pr-ps-printer-alist
2105 '((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
2106 (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
2107 ;; some other printer declaration
2110 The example above declares that printer A prints all pages (-all) and two pages
2111 per sheet (-twoup). The printer B declaration does the same as the printer A
2112 declaration, the only difference is the printer name selection.
2114 There are other command line options like:
2116 -mono Render in monochrome as 1bit/pixel (only black and white).
2117 -grey Render in greyscale as 8bits/pixel.
2118 -color Render in color as 24bits/pixel.
2120 The default is `-mono'. So, printer A and B in the example above are using
2121 implicitly the `-mono' option. Note that in `-mono' no gray tone or color is
2122 printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
2128 * GSPRINT - Ghostscript print to Windows printer
2129 `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
2131 * Introduction to Ghostscript
2132 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2134 * How to use Ghostscript
2135 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2137 * Information about the print command (print.exe)
2138 `http://www.computerhope.com/printhlp.htm'
2140 * RedMon - Redirection Port Monitor (redpr.exe)
2141 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
2143 * Redirection Port Monitor (redpr.exe on-line help)
2144 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
2146 * UNIX man pages: lpr (or type `man lpr')
2147 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
2148 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
2150 * UNIX man pages: lp (or type `man lp')
2151 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
2152 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
2154 * GNU utilities for w32 (cp.exe)
2155 `http://unxutils.sourceforge.net/'
2159 :tag
"PostScript Printer"
2160 (symbol :tag
"Printer Symbol Name")
2161 (string :tag
"Printer Command")
2162 (repeat :tag
"Printer Switches"
2163 (sexp :tag
"Switch" :value
""))
2164 (choice :menu-tag
"Printer Name Switch"
2165 :tag
"Printer Name Switch"
2166 (const :tag
"None" nil
)
2168 (choice :menu-tag
"Printer Name"
2170 (const :tag
"None" nil
)
2173 :tag
"Default Value List"
2178 :menu-tag
"Variable"
2180 (const :tag
"Landscape" ps-landscape-mode
)
2181 (const :tag
"Print Header" ps-print-header
)
2182 (const :tag
"Print Header Frame" ps-print-header-frame
)
2183 (const :tag
"Line Number" ps-line-number
)
2184 (const :tag
"Zebra Stripes" ps-zebra-stripes
)
2185 (const :tag
"Duplex" ps-spool-duplex
)
2186 (const :tag
"Tumble" ps-spool-tumble
)
2187 (const :tag
"Upside-Down" ps-print-upside-down
)
2188 (const :tag
"PS File Landscape" pr-file-landscape
)
2189 (const :tag
"PS File Duplex" pr-file-duplex
)
2190 (const :tag
"PS File Tumble" pr-file-tumble
)
2191 (const :tag
"Auto Region" pr-auto-region
)
2192 (const :tag
"Auto Mode" pr-auto-mode
)
2193 (const :tag
"Ghostscript Device" pr-gs-device
)
2194 (const :tag
"Ghostscript Resolution" pr-gs-resolution
)
2195 (const :tag
"inherits-from:" inherits-from
:)
2196 (variable :tag
"Other"))
2197 (sexp :tag
"Value")))
2199 :set
'pr-alist-custom-set
2203 (defcustom pr-temp-dir
2204 (pr-dosify-file-name
2205 (if (boundp 'temporary-file-directory
)
2206 (symbol-value 'temporary-file-directory
)
2207 ;; hacked from `temporary-file-directory' variable in files.el
2208 (file-name-as-directory
2209 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
2210 (cond (lpr-windows-system "c:/temp")
2213 "Specify a directory for temporary files during printing.
2215 See also `pr-ps-temp-file' and `pr-file-modes'."
2216 :type
'(directory :tag
"Temporary Directory")
2220 (defcustom pr-ps-temp-file
"prspool-"
2221 "Specify PostScript temporary file name prefix.
2223 See also `pr-temp-dir' and `pr-file-modes'."
2224 :type
'(file :tag
"PostScript Temporary File Name")
2228 ;; It uses 0600 as default instead of (default-file-modes).
2229 ;; So, by default, only the session owner have permission to deal with files
2230 ;; generated by `printing'.
2231 (defcustom pr-file-modes ?
\600
2232 "Specify the file permission bits for newly created files.
2234 It should be an integer; only the low 9 bits are used.
2236 See also `pr-temp-dir' and `pr-ps-temp-file'."
2237 :type
'(integer :tag
"File Permission Bits")
2241 (defcustom pr-gv-command
2242 (if lpr-windows-system
2245 "Specify path and name of the gsview/gv utility.
2247 See also `pr-path-alist'.
2252 `http://www.gnu.org/software/gv/manual/gv.html'
2255 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'
2257 * GSview Help - Common Problems
2258 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'
2260 * GSview Readme (compilation & installation)
2261 `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'
2263 * GSview (main site)
2264 `http://www.cs.wisc.edu/~ghost/gsview/index.htm'
2266 * Ghostscript, Ghostview and GSview
2267 `http://www.cs.wisc.edu/~ghost/'
2270 `http://www.cs.wisc.edu/~ghost/gv/index.htm'
2273 `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'
2276 `http://www.cs.wisc.edu/~ghost/macos/index.htm'
2278 :type
'(string :tag
"Ghostview Utility")
2282 (defcustom pr-gs-command
2283 (if lpr-windows-system
2286 "Specify path and name of the ghostscript utility.
2288 See also `pr-path-alist'.
2292 * Ghostscript, Ghostview and GSview
2293 `http://www.cs.wisc.edu/~ghost/'
2295 * Introduction to Ghostscript
2296 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2298 * How to use Ghostscript
2299 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2301 * Printer compatibility
2302 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2304 :type
'(string :tag
"Ghostscript Utility")
2308 (defcustom pr-gs-switches
2309 (if lpr-windows-system
2310 '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
2311 '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
2312 "Specify ghostscript switches. See the documentation on GS for more info.
2314 It's a list of strings, where each string is one or more ghostscript switches.
2316 A note on the gs switches:
2319 -dNOPAUSE don't wait for user intervention
2320 -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
2321 -c quit it's added at the end to terminate gs
2323 To see ghostscript documentation for more information:
2325 * On GNU or Unix system:
2326 - for full documentation, type: man gs
2327 - for brief documentation, type: gs -h
2329 * On Windows system:
2330 - for full documentation, see in a browser the file
2331 c:/gstools/gs5.50/index.html, that is, the file index.html which is
2332 located in the same directory as gswin32.exe.
2333 - for brief documentation, type: gswin32.exe -h
2337 * Introduction to Ghostscript
2338 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2340 * How to use Ghostscript
2341 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2343 * Printer compatibility
2344 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2346 :type
'(repeat (string :tag
"Ghostscript Switch"))
2350 (defcustom pr-gs-device
2351 (if lpr-windows-system
2354 "Specify the ghostscript device switch value (-sDEVICE=).
2356 A note on the gs switches:
2358 -sDEVICE=djet500 the printer - works with HP DeskJet 540
2360 See `pr-gs-switches' for documentation.
2361 See also `pr-ps-printer-alist'."
2362 :type
'(string :tag
"Ghostscript Device")
2366 (defcustom pr-gs-resolution
300
2367 "Specify ghostscript resolution switch value (-r).
2369 A note on the gs switches:
2371 -r300 resolution 300x300
2373 See `pr-gs-switches' for documentation.
2374 See also `pr-ps-printer-alist'."
2375 :type
'(integer :tag
"Ghostscript Resolution")
2379 (defcustom pr-print-using-ghostscript nil
2380 "Non-nil means print using ghostscript.
2382 This is useful if you don't have a PostScript printer, so you could use the
2383 ghostscript to print a PostScript file.
2385 In GNU or Unix system, if ghostscript is set as a PostScript filter, this
2386 variable should be nil."
2391 (defcustom pr-faces-p nil
2392 "Non-nil means print with face attributes."
2397 (defcustom pr-spool-p nil
2398 "Non-nil means spool printing in a buffer."
2403 (defcustom pr-file-landscape nil
2404 "Non-nil means print PostScript file in landscape orientation."
2409 (defcustom pr-file-duplex nil
2410 "Non-nil means print PostScript file in duplex mode."
2415 (defcustom pr-file-tumble nil
2416 "Non-nil means print PostScript file in tumble mode.
2418 If tumble is off, produces a printing suitable for binding on the left or
2420 If tumble is on, produces a printing suitable for binding at the top or
2426 (defcustom pr-auto-region t
2427 "Non-nil means region is automagically detected.
2429 Note that this will only work if you're using transient mark mode.
2431 When this variable is non-nil, the `*-buffer*' commands will behave like
2432 `*-region*' commands, that is, `*-buffer*' commands will print only the region
2433 marked instead of all buffer."
2438 (defcustom pr-auto-mode t
2439 "Non-nil means major-mode specific printing is preferred over normal printing.
2441 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
2442 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
2443 `*-buffer*' commands will print the current buffer and `*-region*' commands
2444 will print the current region."
2449 (defcustom pr-mode-alist
2450 '((mh-folder-mode ; mh summary buffer
2451 pr-mh-lpr-1 pr-mh-print-1
2453 (ps-article-author ps-article-subject
)
2454 ("/pagenumberstring load" pr-article-date
)
2457 (mh-letter-mode ; mh letter buffer
2458 pr-mh-lpr-2 pr-mh-print-2
2460 (ps-article-author ps-article-subject
)
2461 ("/pagenumberstring load" pr-article-date
)
2464 (rmail-summary-mode ; rmail summary buffer
2465 pr-rmail-lpr pr-rmail-print
2467 (ps-article-subject ps-article-author buffer-name
)
2471 (rmail-mode ; rmail buffer
2472 pr-rmail-lpr pr-rmail-print
2474 (ps-article-subject ps-article-author buffer-name
)
2478 (gnus-summary-mode ; gnus summary buffer
2479 pr-gnus-lpr pr-gnus-print
2481 (ps-article-subject ps-article-author gnus-newsgroup-name
)
2485 (gnus-article-mode ; gnus article buffer
2486 pr-gnus-lpr pr-gnus-print
2488 (ps-article-subject ps-article-author gnus-newsgroup-name
)
2492 (Info-mode ; Info buffer
2493 pr-mode-lpr pr-mode-print
2495 (ps-info-node ps-info-file
)
2500 pr-vm-lpr pr-vm-print
2502 (ps-article-subject ps-article-author buffer-name
)
2507 "Specify an alist for a major-mode and printing functions.
2509 To customize a major mode printing, just declare the customization in
2510 `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
2511 mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
2512 *Summary* buffer, if you forget to switch to the *Article* buffer before
2513 printing, you'll get a nicely formatted list of article subjects shows up at
2514 the printer. With major mode printing you don't need to switch from gnus
2515 *Summary* buffer first.
2517 The elements have the following form:
2529 MAJOR-MODE It's the major mode symbol.
2531 LPR-PRINT It's a symbol function for text printing. It's invoked with
2533 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2535 Usually LPR-PRINT function prepares the environment or buffer
2536 and then call the function `pr-mode-lpr' which it's used to
2537 process the buffer and send it to text printer.
2539 The `pr-mode-lpr' definition is:
2541 (pr-mode-lpr HEADER-LIST &optional FROM TO)
2543 Where HEADER-LIST is like the argument passed to LPR-PRINT.
2544 FROM and TO are the beginning and end markers, respectively,
2545 for a region. If FROM is nil, it's used (point-min); if TO is
2546 nil, it's used (point-max).
2548 PS-PRINT It's a symbol function for PostScript printing. It's invoked
2549 with three arguments: n-up printing, file name and the list:
2550 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2552 Usually PS-PRINT function prepares the environment or buffer
2553 and then call the function `pr-mode-print' which it's used to
2554 process the buffer and send it to PostScript printer.
2556 The `pr-mode-print' definition is:
2558 (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
2560 Where N-UP, FILENAME and HEADER-LIST are like the arguments
2561 passed to PS-PRINT. FROM and TO are the beginning and end
2562 markers, respectively, for a region. If TO is nil, it's used
2565 HEADER-LINES It's the number of header lines; if is nil, it uses
2566 `ps-header-lines' value.
2568 LEFT-HEADER It's the left header part, it's a list of string, variable
2569 symbol or function symbol (with no argument); if is nil, it
2570 uses `ps-left-header' value.
2572 RIGHT-HEADER It's the right header part, it's a list of string, variable
2573 symbol or function symbol (with no argument); if is nil, it
2574 uses `ps-right-header' value.
2577 Non-nil means to kill all buffer local variable declared in
2578 DEFAULT (see below).
2580 DEFAULT It's a way to set default values when this entry is selected.
2583 (VARIABLE-SYM . VALUE)
2585 Which associates VARIABLE-SYM with VALUE. When this entry is
2586 selected, it's executed the following command:
2588 (set (make-local-variable VARIABLE-SYM) (eval VALUE))
2590 Note that VALUE can be any valid lisp expression. So, don't
2591 forget to quote symbols and constant lists.
2592 If VARIABLE is the special keyword `inherits-from:', VALUE must
2593 be a symbol name setting defined in `pr-setting-database' from
2594 which the current setting inherits the context. Take care with
2595 circular inheritance.
2597 '(ps-landscape-mode . nil)
2598 '(ps-spool-duplex . t)
2599 '(pr-gs-device . (my-gs-device t))"
2603 (symbol :tag
"Major Mode")
2604 (function :tag
"Text Printing Function")
2605 (function :tag
"PS Printing Function")
2606 (choice :menu-tag
"Number of Header Lines"
2607 :tag
"Number of Header Lines"
2608 (integer :tag
"Number")
2609 (const :tag
"Default Number" nil
))
2610 (repeat :tag
"Left Header List"
2611 (choice :menu-tag
"Left Header"
2614 (repeat :tag
"Right Header List"
2615 (choice :menu-tag
"Right Header"
2618 (boolean :tag
"Kill Local Variable At End")
2620 :tag
"Default Value List"
2625 :menu-tag
"Variable"
2627 (const :tag
"Landscape" ps-landscape-mode
)
2628 (const :tag
"Print Header" ps-print-header
)
2629 (const :tag
"Print Header Frame" ps-print-header-frame
)
2630 (const :tag
"Line Number" ps-line-number
)
2631 (const :tag
"Zebra Stripes" ps-zebra-stripes
)
2632 (const :tag
"Duplex" ps-spool-duplex
)
2633 (const :tag
"Tumble" ps-spool-tumble
)
2634 (const :tag
"Upside-Down" ps-print-upside-down
)
2635 (const :tag
"PS File Landscape" pr-file-landscape
)
2636 (const :tag
"PS File Duplex" pr-file-duplex
)
2637 (const :tag
"PS File Tumble" pr-file-tumble
)
2638 (const :tag
"Auto Region" pr-auto-region
)
2639 (const :tag
"Auto Mode" pr-auto-mode
)
2640 (const :tag
"Ghostscript Device" pr-gs-device
)
2641 (const :tag
"Ghostscript Resolution" pr-gs-resolution
)
2642 (const :tag
"inherits-from:" inherits-from
:)
2643 (variable :tag
"Other"))
2644 (sexp :tag
"Value")))
2649 (defcustom pr-ps-utility
'mpage
2650 "Specify PostScript utility symbol.
2652 This utility symbol should be defined on `pr-ps-utility-alist' (see it for
2655 This variable should be modified by customization engine. If this variable is
2656 modified by other means (for example, a lisp function), use `pr-update-menus'
2657 function (see it for documentation) to update PostScript utility menu.
2659 NOTE: Don't forget to download and install the utilities declared on
2660 `pr-ps-utility-alist'."
2661 :type
'(symbol :tag
"PS File Utility")
2662 :set
'pr-ps-utility-custom-set
2666 (defcustom pr-ps-utility-alist
2667 '((mpage "mpage" nil
"-b%s" "-%d" "-l" "-t" "-T" ">" nil
)
2668 (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil
" " nil
2669 (inherits-from: . no-duplex
))
2672 ;; * On GNU or Unix system:
2673 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2674 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2675 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2677 ;; * On Windows system:
2678 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2679 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2681 "Specify an alist for PostScript utility processing (PS utility database).
2683 The alist element has the form:
2685 (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
2686 SWITCHES DEFAULT...)
2690 SYMBOL It's a symbol to identify a PostScript utility. It's for
2691 `pr-ps-utility' variable setting and for menu selection.
2696 UTILITY Name of utility for processing a PostScript file.
2697 See also `pr-path-alist'.
2699 . for GNU or Unix system:
2703 . for Windows system:
2704 \"c:/psutils/psnup -q\"
2706 MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
2707 program. These options are necessary to process the utility
2708 program and must be placed before any other switches.
2713 PAPERSIZE It's a format string to specify paper size switch.
2718 N-UP It's a format string to specify n-up switch.
2723 LANDSCAPE It's a string to specify landscape switch. If the utility
2724 doesn't have landscape switch, set to nil.
2729 DUPLEX It's a string to specify duplex switch. If the utility doesn't
2730 have duplex switch, set to nil.
2735 TUMBLE It's a string to specify tumble switch. If the utility doesn't
2736 have tumble switch, set to nil.
2741 OUTPUT It's a string to specify how to generate an output file. Some
2742 utilities accept an output file option, but some others need
2743 output redirection or some other way to specify an output file.
2746 \" \" ; psnup ... input output
2749 \">\" ; mpage ... input > output
2751 SWITCHES List of sexp's to pass as extra options to the PostScript utility
2758 DEFAULT It's a way to set default values when this entry is selected.
2763 Which associates VARIABLE with VALUE. When this entry is
2764 selected, it's executed the following command:
2766 (set VARIABLE (eval VALUE))
2768 Note that VALUE can be any valid lisp expression. So, don't
2769 forget to quote symbols and constant lists.
2770 If VARIABLE is the special keyword `inherits-from:', VALUE must
2771 be a symbol name setting defined in `pr-setting-database' from
2772 which the current setting inherits the context. Take care with
2773 circular inheritance.
2775 '(pr-file-landscape . nil)
2776 '(pr-file-duplex . t)
2777 '(pr-gs-device . (my-gs-device t))
2779 This variable should be modified by customization engine. If this variable is
2780 modified by other means (for example, a lisp function), use `pr-update-menus'
2781 function (see it for documentation) to update PostScript utility menu.
2783 NOTE: Don't forget to download and install the utilities declared on
2784 `pr-ps-utility-alist'.
2788 * On GNU or Unix system:
2790 '((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
2791 (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
2792 (pr-file-duplex . nil) (pr-file-tumble . nil))
2795 * On Windows system:
2797 '((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
2798 nil (pr-file-duplex . nil) (pr-file-tumble . nil))
2803 * mpage download (GNU or Unix)
2804 `http://www.mesa.nl/pub/mpage/'
2806 * mpage documentation (GNU or Unix - or type `man mpage')
2807 `http://www.cs.umd.edu/faq/guides/manual_unix/node48.html'
2808 `http://www.rt.com/man/mpage.1.html'
2810 * psnup (Windows, GNU or Unix)
2811 `http://www.knackered.org/angus/psutils/'
2812 `http://gershwin.ens.fr/vdaniel/Doc-Locale/Outils-Gnu-Linux/PsUtils/'
2814 * psnup (PsUtils for Windows)
2815 `http://gnuwin32.sourceforge.net/packages/psutils.htm'
2817 * psnup documentation (GNU or Unix - or type `man psnup')
2818 `http://linux.about.com/library/cmd/blcmdl1_psnup.htm'
2819 `http://amath.colorado.edu/computing/software/man/psnup.html'
2821 * GNU Enscript (Windows, GNU or Unix)
2822 `http://people.ssh.com/mtr/genscript/'
2824 * GNU Enscript documentation (Windows, GNU or Unix)
2825 `http://people.ssh.com/mtr/genscript/enscript.man.html'
2826 (on GNU or Unix, type `man enscript')
2829 (list :tag
"PS File Utility"
2830 (symbol :tag
"Utility Symbol")
2831 (string :tag
"Utility Name")
2832 (repeat :tag
"Must Utility Switches"
2833 (sexp :tag
"Switch" :value
""))
2834 (choice :menu-tag
"Paper Size"
2836 (const :tag
"No Paper Size" nil
)
2837 (string :tag
"Paper Size Format"))
2838 (choice :menu-tag
"N-Up"
2840 (const :tag
"No N-Up" nil
)
2841 (string :tag
"N-Up Format"))
2842 (choice :menu-tag
"Landscape"
2844 (const :tag
"No Landscape" nil
)
2845 (string :tag
"Landscape Switch"))
2846 (choice :menu-tag
"Duplex"
2848 (const :tag
"No Duplex" nil
)
2849 (string :tag
"Duplex Switch"))
2850 (choice :menu-tag
"Tumble"
2852 (const :tag
"No Tumble" nil
)
2853 (string :tag
"Tumble Switch"))
2854 (string :tag
"Output Separator")
2855 (repeat :tag
"Utility Switches"
2856 (sexp :tag
"Switch" :value
""))
2858 :tag
"Default Value List"
2863 :menu-tag
"Variable"
2865 (const :tag
"PS File Landscape" pr-file-landscape
)
2866 (const :tag
"PS File Duplex" pr-file-duplex
)
2867 (const :tag
"PS File Tumble" pr-file-tumble
)
2868 (const :tag
"Ghostscript Device" pr-gs-device
)
2869 (const :tag
"Ghostscript Resolution" pr-gs-resolution
)
2870 (const :tag
"inherits-from:" inherits-from
:)
2871 (variable :tag
"Other"))
2872 (sexp :tag
"Value")))
2874 :set
'pr-alist-custom-set
2878 (defcustom pr-menu-lock t
2879 "Non-nil means menu is locked while selecting toggle options.
2881 See also `pr-menu-char-height' and `pr-menu-char-width'."
2886 (defcustom pr-menu-char-height
(pr-menu-char-height)
2887 "Specify menu char height in pixels.
2889 This variable is used to guess which vertical position should be locked the
2890 menu, so don't forget to adjust it if menu position is not ok.
2892 See also `pr-menu-lock' and `pr-menu-char-width'."
2897 (defcustom pr-menu-char-width
(pr-menu-char-width)
2898 "Specify menu char width in pixels.
2900 This variable is used to guess which horizontal position should be locked the
2901 menu, so don't forget to adjust it if menu position is not ok.
2903 See also `pr-menu-lock' and `pr-menu-char-height'."
2908 (defcustom pr-setting-database
2909 '((no-duplex ; setting symbol name
2910 nil nil nil
; inherits local kill-local
2911 (pr-file-duplex . nil
) ; settings
2912 (pr-file-tumble . nil
))
2914 "Specify an alist for settings in general.
2916 The elements have the following form:
2918 (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
2922 SYMBOL It's a symbol to identify the setting group.
2924 INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
2925 setting from which the current setting inherits the context.
2926 If INHERITS is nil, means that there is no inheritance.
2927 This is a simple inheritance mechanism.
2929 Let's see an example to illustrate the inheritance mechanism:
2931 (setq pr-setting-database
2932 '((no-duplex ; setting symbol name
2934 nil nil ; local kill-local
2935 (pr-file-duplex . nil) ; settings
2936 (pr-file-tumble . nil)
2938 (no-duplex-and-landscape ; setting symbol name
2939 no-duplex ; inherits
2940 nil nil ; local kill-local
2941 (pr-file-landscape . nil) ; settings
2944 The example above has two setting groups: no-duplex and
2945 no-duplex-and-landscape. When setting no-duplex is activated
2946 through `inherits-from:' (see option `pr-ps-utility',
2947 `pr-mode-alist' and `pr-ps-printer-alist'), the variables
2948 pr-file-duplex and pr-file-tumble are both set to nil.
2950 Now when setting no-duplex-and-landscape is activated through
2951 `inherits-from:', the variable pr-file-landscape is set to nil
2952 and also the settings for no-duplex are done, because
2953 no-duplex-and-landscape inherits settings from no-duplex.
2955 Take care with circular inheritance. It's an error if circular
2956 inheritance happens.
2958 LOCAL Non-nil means that all settings for SYMBOL group will be
2959 declared local buffer.
2961 KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
2962 killed at end. It has effect only when LOCAL is non-nil.
2964 SETTING It's a cons like:
2968 Which associates VARIABLE with VALUE. When this entry is
2969 selected, it's executed the following command:
2971 * If LOCAL is non-nil:
2972 (set (make-local-variable VARIABLE) (eval VALUE))
2975 (set VARIABLE (eval VALUE))
2977 Note that VALUE can be any valid lisp expression. So, don't
2978 forget to quote symbols and constant lists.
2979 This setting is ignored if VARIABLE is equal to keyword
2982 '(ps-landscape-mode . nil)
2983 '(ps-spool-duplex . t)
2984 '(pr-gs-device . (my-gs-device t))"
2988 (symbol :tag
"Setting Name")
2989 (choice :menu-tag
"Inheritance"
2991 (const :tag
"No Inheritance" nil
)
2992 (symbol :tag
"Inherits From"))
2993 (boolean :tag
"Local Buffer Setting")
2994 (boolean :tag
"Kill Local Variable At End")
3001 :menu-tag
"Variable"
3003 (const :tag
"Landscape" ps-landscape-mode
)
3004 (const :tag
"Print Header" ps-print-header
)
3005 (const :tag
"Print Header Frame" ps-print-header-frame
)
3006 (const :tag
"Line Number" ps-line-number
)
3007 (const :tag
"Zebra Stripes" ps-zebra-stripes
)
3008 (const :tag
"Duplex" ps-spool-duplex
)
3009 (const :tag
"Tumble" ps-spool-tumble
)
3010 (const :tag
"Upside-Down" ps-print-upside-down
)
3011 (const :tag
"PS File Landscape" pr-file-landscape
)
3012 (const :tag
"PS File Duplex" pr-file-duplex
)
3013 (const :tag
"PS File Tumble" pr-file-tumble
)
3014 (const :tag
"Auto Region" pr-auto-region
)
3015 (const :tag
"Auto Mode" pr-auto-mode
)
3016 (const :tag
"Ghostscript Device" pr-gs-device
)
3017 (const :tag
"Ghostscript Resolution" pr-gs-resolution
)
3018 (variable :tag
"Other"))
3019 (sexp :tag
"Value")))
3024 (defcustom pr-visible-entry-list
3025 '(postscript text postscript-options postscript-process printing help
)
3026 "Specify a list of Printing menu visible entries.
3028 Valid values with the corresponding menu parts are:
3030 +------------------------------+
3031 | Printing Interface |
3032 +------------------------------+
3033 `postscript' | PostScript Preview >|
3034 | PostScript Print >|
3035 | PostScript Printer: name >|
3036 +------------------------------+
3037 `text' | Printify >|
3039 | Text Printer: name >|
3040 +------------------------------+
3041 `postscript-options' |[ ] Landscape |
3043 |[ ] Print Header Frame |
3045 |[ ] Zebra Stripes |
3049 | Print All Pages >|
3050 +------------------------------+
3051 `postscript-process' |[ ] Spool Buffer |
3052 |[ ] Print with faces |
3053 |[ ] Print via Ghostscript |
3054 +------------------------------+
3055 `printing' |[ ] Auto Region |
3058 +------------------------------+
3059 `help' | Customize >|
3062 +------------------------------+
3064 Any other value is ignored."
3065 :type
'(repeat :tag
"Menu Visible Part"
3066 (choice :menu-tag
"Menu Part"
3070 (const postscript-options
)
3071 (const postscript-process
)
3077 (defcustom pr-delete-temp-file t
3078 "Non-nil means delete temporary files.
3080 Set `pr-delete-temp-file' to nil, if the following message (or a similar)
3081 happens when printing:
3083 Error: could not open \"c:\\temp\\prspool.ps\" for reading."
3088 (defcustom pr-list-directory nil
3089 "Non-nil means list directory when processing a directory.
3091 That is, any subdirectories (and the superdirectory) of the directory (given as
3092 argument of functions below) are also printed (as dired-mode listings).
3094 It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
3095 `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
3096 and `pr-txt-directory'."
3101 (defcustom pr-buffer-name
"*Printing Interface*"
3102 "Specify the name of the buffer interface for printing package.
3104 It's used by `pr-interface'."
3109 (defcustom pr-buffer-name-ignore
3110 (list (regexp-quote pr-buffer-name
) ; ignore printing interface buffer
3111 "^ .*$") ; ignore invisible buffers
3112 "Specify a regexp list for buffer names to be ignored in interface buffer.
3114 NOTE: Case is important for matching, that is, `case-fold-search' is always
3117 It's used by `pr-interface'."
3118 :type
'(repeat (regexp :tag
"Buffer Name Regexp"))
3122 (defcustom pr-buffer-verbose t
3123 "Non-nil means to be verbose when editing a field in interface buffer.
3125 It's used by `pr-interface'."
3130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3131 ;; Internal Variables
3134 (defvar pr-txt-command nil
3135 "Name of program for printing a text file.
3136 See `pr-txt-printer-alist'.")
3139 (defvar pr-txt-switches nil
3140 "List of sexp's to pass as extra options to the text printer program.
3141 See `pr-txt-printer-alist'.")
3144 (defvar pr-txt-printer nil
3145 "Specify text printer name.
3146 See `pr-txt-printer-alist'.")
3149 (defvar pr-ps-command nil
3150 "Name of program for printing a PostScript file.
3151 See `pr-ps-printer-alist'.")
3154 (defvar pr-ps-switches nil
3155 "List of sexp's to pass as extra options to the PostScript printer program.
3156 See `pr-ps-printer-alist'.")
3159 (defvar pr-ps-printer-switch nil
3160 "Specify PostScript printer name switch.
3161 See `pr-ps-printer-alist'.")
3164 (defvar pr-ps-printer nil
3165 "Specify PostScript printer name.
3166 See `pr-ps-printer-alist'.")
3169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3173 (defmacro pr-save-file-modes
(&rest body
)
3174 "Set temporally file modes to `pr-file-modes'."
3175 `(let ((pr--default-file-modes (default-file-modes))) ; save default
3176 (set-default-file-modes pr-file-modes
)
3178 (set-default-file-modes pr--default-file-modes
))) ; restore default
3181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3185 (defsubst pr-visible-p
(key)
3186 (memq key pr-visible-entry-list
))
3189 (defsubst pr-mode-alist-p
()
3190 (cdr (assq major-mode pr-mode-alist
)))
3193 (defsubst pr-auto-mode-p
()
3194 (and pr-auto-mode
(pr-mode-alist-p)))
3197 (defsubst pr-using-ghostscript-p
()
3198 (and pr-print-using-ghostscript
(not pr-spool-p
)))
3201 (defalias 'pr-get-symbol
3202 (if (featurep 'emacs
) 'easy-menu-intern
; since 22.1
3203 (if (fboundp 'easy-menu-intern
) ; hacked from easymenu.el
3205 (lambda (s) (if (stringp s
) (intern s
) s
)))))
3208 (defconst pr-menu-spec
3210 ;; unfortunately XEmacs doesn't support :active for submenus,
3212 ;; So, it uses :included instead of :active.
3213 ;; Also, XEmacs doesn't support :help tag.
3214 (let ((pr-:active
(if (featurep 'xemacs
)
3216 :active
)) ; GNU Emacs
3217 (pr-:help
(if (featurep 'xemacs
)
3219 #'(lambda (text) (list :help text
))))) ; GNU Emacs
3221 ["Printing Interface" pr-interface
3223 pr-
:help
"Use buffer interface instead of menu interface")]
3225 ("PostScript Preview" :included
(pr-visible-p 'postscript
)
3227 pr-
:help
"Preview PostScript instead of sending to printer")
3228 ("Directory" ,pr-
:active
(not pr-spool-p
)
3229 ["1-up" (pr-ps-directory-preview 1 nil nil t
) t
]
3230 ["2-up" (pr-ps-directory-preview 2 nil nil t
) t
]
3231 ["4-up" (pr-ps-directory-preview 4 nil nil t
) t
]
3232 ["Other..." (pr-ps-directory-preview nil nil nil t
)
3233 :keys
"\\[pr-ps-buffer-preview]"])
3234 ("Buffer" ,pr-
:active
(not pr-spool-p
)
3235 ["1-up" (pr-ps-buffer-preview 1 t
) t
]
3236 ["2-up" (pr-ps-buffer-preview 2 t
) t
]
3237 ["4-up" (pr-ps-buffer-preview 4 t
) t
]
3238 ["Other..." (pr-ps-buffer-preview nil t
)
3239 :keys
"\\[pr-ps-buffer-preview]"])
3240 ("Region" ,pr-
:active
(and (not pr-spool-p
) (ps-mark-active-p))
3241 ["1-up" (pr-ps-region-preview 1 t
) t
]
3242 ["2-up" (pr-ps-region-preview 2 t
) t
]
3243 ["4-up" (pr-ps-region-preview 4 t
) t
]
3244 ["Other..." (pr-ps-region-preview nil t
)
3245 :keys
"\\[pr-ps-region-preview]"])
3246 ("Mode" ,pr-
:active
(and (not pr-spool-p
) (pr-mode-alist-p))
3247 ["1-up" (pr-ps-mode-preview 1 t
) t
]
3248 ["2-up" (pr-ps-mode-preview 2 t
) t
]
3249 ["4-up" (pr-ps-mode-preview 4 t
) t
]
3250 ["Other..." (pr-ps-mode-preview nil t
)
3251 :keys
"\\[pr-ps-mode-preview]"])
3253 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview
)
3254 :keys
"\\[pr-ps-file-preview]"
3256 pr-
:help
"Preview PostScript file")]
3258 ["PostScript Utility" pr-update-menus
:active pr-ps-utility-alist
3260 pr-
:help
"Select PostScript utility")]
3262 ["1-up..." (pr-ps-file-up-preview 1 t t
) pr-ps-utility-alist
]
3263 ["2-up..." (pr-ps-file-up-preview 2 t t
) pr-ps-utility-alist
]
3264 ["4-up..." (pr-ps-file-up-preview 4 t t
) pr-ps-utility-alist
]
3265 ["Other..." (pr-ps-file-up-preview nil t t
)
3266 :keys
"\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist
]
3268 ["Landscape" pr-toggle-file-landscape-menu
3269 :style toggle
:selected pr-file-landscape
3271 pr-
:help
"Toggle landscape for PostScript file")
3272 :active pr-ps-utility-alist
]
3273 ["Duplex" pr-toggle-file-duplex-menu
3274 :style toggle
:selected pr-file-duplex
3276 pr-
:help
"Toggle duplex for PostScript file")
3277 :active pr-ps-utility-alist
]
3278 ["Tumble" pr-toggle-file-tumble-menu
3279 :style toggle
:selected pr-file-tumble
3281 pr-
:help
"Toggle tumble for PostScript file")
3282 :active
(and pr-file-duplex pr-ps-utility-alist
)])
3283 ["Despool..." (call-interactively 'pr-despool-preview
)
3284 :active pr-spool-p
:keys
"\\[pr-despool-preview]"
3286 pr-
:help
"Despool PostScript buffer to printer or file (C-u)")])
3287 ("PostScript Print" :included
(pr-visible-p 'postscript
)
3289 pr-
:help
"Send PostScript to printer or file (C-u)")
3291 ["1-up" (pr-ps-directory-ps-print 1 nil nil t
) t
]
3292 ["2-up" (pr-ps-directory-ps-print 2 nil nil t
) t
]
3293 ["4-up" (pr-ps-directory-ps-print 4 nil nil t
) t
]
3294 ["Other..." (pr-ps-directory-ps-print nil nil nil t
)
3295 :keys
"\\[pr-ps-buffer-ps-print]"])
3297 ["1-up" (pr-ps-buffer-ps-print 1 t
) t
]
3298 ["2-up" (pr-ps-buffer-ps-print 2 t
) t
]
3299 ["4-up" (pr-ps-buffer-ps-print 4 t
) t
]
3300 ["Other..." (pr-ps-buffer-ps-print nil t
)
3301 :keys
"\\[pr-ps-buffer-ps-print]"])
3302 ("Region" ,pr-
:active
(ps-mark-active-p)
3303 ["1-up" (pr-ps-region-ps-print 1 t
) t
]
3304 ["2-up" (pr-ps-region-ps-print 2 t
) t
]
3305 ["4-up" (pr-ps-region-ps-print 4 t
) t
]
3306 ["Other..." (pr-ps-region-ps-print nil t
)
3307 :keys
"\\[pr-ps-region-ps-print]"])
3308 ("Mode" ,pr-
:active
(pr-mode-alist-p)
3309 ["1-up" (pr-ps-mode-ps-print 1 t
) t
]
3310 ["2-up" (pr-ps-mode-ps-print 2 t
) t
]
3311 ["4-up" (pr-ps-mode-ps-print 4 t
) t
]
3312 ["Other..." (pr-ps-mode-ps-print nil t
)
3313 :keys
"\\[pr-ps-mode-ps-print]"])
3315 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print
)
3316 :keys
"\\[pr-ps-file-ps-print]"
3318 pr-
:help
"Send PostScript file to printer")]
3320 ["PostScript Utility" pr-update-menus
:active pr-ps-utility-alist
3322 pr-
:help
"Select PostScript utility")]
3324 ["1-up..." (pr-ps-file-up-ps-print 1 t t
) pr-ps-utility-alist
]
3325 ["2-up..." (pr-ps-file-up-ps-print 2 t t
) pr-ps-utility-alist
]
3326 ["4-up..." (pr-ps-file-up-ps-print 4 t t
) pr-ps-utility-alist
]
3327 ["Other..." (pr-ps-file-up-ps-print nil t t
)
3328 :keys
"\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist
]
3330 ["Landscape" pr-toggle-file-landscape-menu
3331 :style toggle
:selected pr-file-landscape
3333 pr-
:help
"Toggle landscape for PostScript file")
3334 :active pr-ps-utility-alist
]
3335 ["Duplex" pr-toggle-file-duplex-menu
3336 :style toggle
:selected pr-file-duplex
3338 pr-
:help
"Toggle duplex for PostScript file")
3339 :active pr-ps-utility-alist
]
3340 ["Tumble" pr-toggle-file-tumble-menu
3341 :style toggle
:selected pr-file-tumble
3343 pr-
:help
"Toggle tumble for PostScript file")
3344 :active
(and pr-file-duplex pr-ps-utility-alist
)])
3345 ["Despool..." (call-interactively 'pr-despool-ps-print
)
3346 :active pr-spool-p
:keys
"\\[pr-despool-ps-print]"
3348 pr-
:help
"Despool PostScript buffer to printer or file (C-u)")])
3349 ["PostScript Printers" pr-update-menus
3350 :active pr-ps-printer-alist
:included
(pr-visible-p 'postscript
)
3352 pr-
:help
"Select PostScript printer")]
3354 ("Printify" :included
(pr-visible-p 'text
)
3357 "Replace non-printing chars with printable representations.")
3358 ["Directory" pr-printify-directory t
]
3359 ["Buffer" pr-printify-buffer t
]
3360 ["Region" pr-printify-region
(ps-mark-active-p)])
3361 ("Print" :included
(pr-visible-p 'text
)
3363 pr-
:help
"Send text to printer")
3364 ["Directory" pr-txt-directory t
]
3365 ["Buffer" pr-txt-buffer t
]
3366 ["Region" pr-txt-region
(ps-mark-active-p)]
3367 ["Mode" pr-txt-mode
(pr-mode-alist-p)])
3368 ["Text Printers" pr-update-menus
3369 :active pr-txt-printer-alist
:included
(pr-visible-p 'text
)
3371 pr-
:help
"Select text printer")]
3373 ["Landscape" pr-toggle-landscape-menu
3374 :style toggle
:selected ps-landscape-mode
3375 :included
(pr-visible-p 'postscript-options
)]
3376 ["Print Header" pr-toggle-header-menu
3377 :style toggle
:selected ps-print-header
3378 :included
(pr-visible-p 'postscript-options
)]
3379 ["Print Header Frame" pr-toggle-header-frame-menu
3380 :style toggle
:selected ps-print-header-frame
:active ps-print-header
3381 :included
(pr-visible-p 'postscript-options
)]
3382 ["Line Number" pr-toggle-line-menu
3383 :style toggle
:selected ps-line-number
3384 :included
(pr-visible-p 'postscript-options
)]
3385 ["Zebra Stripes" pr-toggle-zebra-menu
3386 :style toggle
:selected ps-zebra-stripes
3387 :included
(pr-visible-p 'postscript-options
)]
3388 ["Duplex" pr-toggle-duplex-menu
3389 :style toggle
:selected ps-spool-duplex
3390 :included
(pr-visible-p 'postscript-options
)]
3391 ["Tumble" pr-toggle-tumble-menu
3392 :style toggle
:selected ps-spool-tumble
:active ps-spool-duplex
3393 :included
(pr-visible-p 'postscript-options
)]
3394 ["Upside-Down" pr-toggle-upside-down-menu
3395 :style toggle
:selected ps-print-upside-down
3396 :included
(pr-visible-p 'postscript-options
)]
3397 ("Print All Pages" :included
(pr-visible-p 'postscript-options
)
3399 pr-
:help
"Select odd/even pages/sheets to print")
3400 ["All Pages" (pr-even-or-odd-pages nil
)
3401 :style radio
:selected
(eq ps-even-or-odd-pages nil
)]
3402 ["Even Pages" (pr-even-or-odd-pages 'even-page
)
3403 :style radio
:selected
(eq ps-even-or-odd-pages
'even-page
)]
3404 ["Odd Pages" (pr-even-or-odd-pages 'odd-page
)
3405 :style radio
:selected
(eq ps-even-or-odd-pages
'odd-page
)]
3406 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet
)
3407 :style radio
:selected
(eq ps-even-or-odd-pages
'even-sheet
)]
3408 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet
)
3409 :style radio
:selected
(eq ps-even-or-odd-pages
'odd-sheet
)])
3411 ["Spool Buffer" pr-toggle-spool-menu
3412 :style toggle
:selected pr-spool-p
3413 :included
(pr-visible-p 'postscript-process
)
3415 pr-
:help
"Toggle PostScript spooling")]
3416 ["Print with faces" pr-toggle-faces-menu
3417 :style toggle
:selected pr-faces-p
3418 :included
(pr-visible-p 'postscript-process
)
3420 pr-
:help
"Toggle PostScript printing with faces")]
3421 ["Print via Ghostscript" pr-toggle-ghostscript-menu
3422 :style toggle
:selected pr-print-using-ghostscript
3423 :included
(pr-visible-p 'postscript-process
)
3425 pr-
:help
"Toggle PostScript generation using ghostscript")]
3427 ["Auto Region" pr-toggle-region-menu
3428 :style toggle
:selected pr-auto-region
3429 :included
(pr-visible-p 'printing
)]
3430 ["Auto Mode" pr-toggle-mode-menu
3431 :style toggle
:selected pr-auto-mode
3432 :included
(pr-visible-p 'printing
)]
3433 ["Menu Lock" pr-toggle-lock-menu
3434 :style toggle
:selected pr-menu-lock
3435 :included
(pr-visible-p 'printing
)]
3437 ("Customize" :included
(pr-visible-p 'help
)
3438 ["printing" pr-customize t
]
3439 ["ps-print" ps-print-customize t
]
3440 ["lpr" lpr-customize t
])
3441 ("Show Settings" :included
(pr-visible-p 'help
)
3442 ["printing" pr-show-pr-setup t
]
3443 ["ps-print" pr-show-ps-setup t
]
3444 ["lpr" pr-show-lpr-setup t
])
3445 ["Help" pr-help
:active t
:included
(pr-visible-p 'help
)]
3449 (defun pr-menu-bind ()
3450 "Install `printing' menu in the menubar.
3451 This replaces the File/Print* menu entries with a File/Print sub-menu.
3452 Calls `pr-update-menus' to adjust menus."
3454 (pr-global-menubar pr-menu-spec
)
3455 (pr-update-menus t
))
3459 (let ((pr-print-key (if (featurep 'xemacs
)
3461 'print
))) ; GNU Emacs
3462 (global-set-key `[,pr-print-key
] 'pr-ps-fast-fire
)
3463 ;; Well, M-print and S-print are used because in my keyboard S-print works
3464 ;; and M-print doesn't. But M-print can work in other keyboard.
3465 (global-set-key `[(meta ,pr-print-key
)] 'pr-ps-mode-using-ghostscript
)
3466 (global-set-key `[(shift ,pr-print-key
)] 'pr-ps-mode-using-ghostscript
)
3467 ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
3468 ;; and C-print doesn't. But C-print can work in other keyboard.
3469 (global-set-key `[(control ,pr-print-key
)] 'pr-txt-fast-fire
)
3470 (global-set-key `[(control meta
,pr-print-key
)] 'pr-txt-fast-fire
))
3473 ;;; You can also use something like:
3474 ;;;(global-set-key "\C-ci" 'pr-interface)
3475 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
3476 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
3477 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
3478 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
3479 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
3480 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
3483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3487 (defconst pr-help-message
3488 (concat "printing.el version " pr-version
3489 " ps-print.el version " ps-print-version
3494 The `printing' menu (Tools/Printing or File/Print) has the following layout:
3496 +-----------------------------+
3497 A 0 | Printing Interface |
3498 +-----------------------------+ +-A---------+ +-B------+
3499 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
3500 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
3501 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
3502 +-----------------------------+ |Mode >|-- B |Other...|
3503 II 4 | Printify >|-----\\ |File >|--\\ +--------+
3504 5 | Print >|---\\ | |Despool... | |
3505 6 | Text Printer: name >|-\\ | | +-----------+ |
3506 +-----------------------------+ | | | +---------+ +------------+
3507 III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
3508 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
3509 9 |[ ]Print Header Frame | | | |Region | | name >|- C
3510 10 |[ ]Line Number | | | +---------+ +------------+
3511 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
3512 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
3513 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
3514 14 |[ ]Upside-Down | | |Region | | Other... |
3515 15 | Print All Pages >|--\\ | |Mode | +------------+
3516 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
3517 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
3518 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
3519 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
3520 +-----------------------------+ | |... |
3521 V 19 |[ ]Auto Region | | |(*)name |
3522 20 |[ ]Auto Mode | | |... |
3523 21 |[ ]Menu Lock | | +---------+ +--------------+
3524 +-----------------------------+ \\------------------|(*)All Pages |
3525 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
3526 23 | Show Settings >|-------|printing| |( )Odd Pages |
3527 24 | Help | |ps-print| |( )Even Sheets|
3528 +-----------------------------+ |lpr | |( )Odd Sheets |
3529 +--------+ +--------------+
3531 See `pr-visible-entry-list' for hiding some parts of the menu.
3533 The menu has the following sections:
3537 0. You can use a buffer interface instead of menus. It looks like the
3538 customization buffer. Basically, it has the same options found in the
3539 menu and some extra options, all this on a buffer.
3541 I. PostScript printing:
3543 1. You can generate a PostScript file (if you type C-u before activating
3544 menu) or PostScript temporary file for a directory, a buffer, a region
3545 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
3546 after file generation, ghostview is activated using the file generated
3547 as argument. This option is disabled if spooling is on (option 16).
3548 Also, if you already have a PostScript file you can preview it.
3549 Instead of previewing each buffer, region or major mode at once, you
3550 can save temporarily the PostScript code generated in a buffer and
3551 preview it later. The option `Despool...' despools the PostScript
3552 spooling buffer in a temporary file and uses ghostview to preview it.
3553 If you type C-u before choosing this option, the PostScript code
3554 generated is saved in a file instead of saving in a temporary file. To
3555 spool the PostScript code generated you need to turn on the option 16.
3556 The option `Despool...' is enabled if spooling is on (option 16).
3558 NOTE 1: It's possible to customize a major mode printing, just declare
3559 the customization in `pr-mode-alist' and invoke some of
3560 `*-mode*' commands or select Mode option in Printing menu. An
3561 example for major mode usage is when you're using gnus (or mh,
3562 or rmail, etc.) and you're in the *Summary* buffer, if you
3563 forget to switch to the *Article* buffer before printing,
3564 you'll get a nicely formatted list of article subjects shows
3565 up at the printer. With major mode printing you don't need to
3566 switch from gnus *Summary* buffer first.
3568 NOTE 2: There are the following options for PostScript file processing:
3569 Ia. Print the file *No Preprocessing*, that is, send it
3570 directly to PostScript printer.
3571 Ib. PostScript utility processing selection.
3572 See `pr-ps-utility-alist' and `pr-setting-database' for
3574 Ic. Do n-up processing before printing.
3575 Id. Toggle on/off landscape for PostScript file processing.
3576 Ie. Toggle on/off duplex for PostScript file processing.
3577 If. Toggle on/off tumble for PostScript file processing.
3579 NOTE 3: Don't forget to download and install the utilities declared on
3580 `pr-ps-utility-alist'.
3582 2. Operate the same way as option 1, but it sends directly the PostScript
3583 code (or put in a file, if you've typed C-u) or it uses ghostscript to
3584 print the PostScript file generated. It depends on option 18, if it's
3585 turned on, it uses ghostscript; otherwise, it sends directly to
3586 printer. If spooling is on (option 16), the PostScript code is saved
3587 temporarily in a buffer instead of printing it or saving it in a file.
3588 Also, if you already have a PostScript file you can print it.
3589 Instead of printing each buffer, region or major mode at once, you can
3590 save temporarily the PostScript code generated in a buffer and print it
3591 later. The option `Despool...' despools the PostScript spooling buffer
3592 directly on a printer. If you type C-u before choosing this option,
3593 the PostScript code generated is saved in a file instead of sending it to
3594 the printer. To spool the PostScript code generated you need to turn on
3595 option 16. This option is enabled if spooling is on (option 16).
3596 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
3598 3. You can select a new PostScript printer to send PostScript code
3599 generated. For selection it's used all PostScript printers defined
3600 in `pr-ps-printer-alist' variable (see it for documentation).
3601 See also `pr-setting-database'.
3605 4. If you have control characters (character code from \\000 to \\037) in a
3606 buffer and you want to print them in a text printer, select this
3607 option. All control characters in your buffer or region will be
3608 replaced by a printable representation. The printable representations
3609 use ^ (for ASCII control characters) or hex. The characters tab,
3610 linefeed, space, return and formfeed are not affected.
3611 You don't need to select this option if you use any option of section
3612 I, the PostScript engine treats control characters properly.
3614 5. If you want to print a directory, buffer, region or major mode in a
3615 text printer, select this option. See also the NOTE 1 on option 1.
3617 6. You can select a new text printer to send text generated. For
3618 selection it's used all text printers defined in `pr-txt-printer-alist'
3619 variable (see it for documentation).
3620 See also `pr-setting-database'.
3622 III. PostScript page toggle options:
3624 7. If you want a PostScript landscape printing, turn on this option.
3626 8. If you want to have a header in each page in your PostScript code,
3627 turn on this option.
3629 9. If you want to draw a gaudy frame around the header, turn on this
3630 option. This option is enabled if print header is on (option 8).
3632 10. If you want that the line number is printed in your PostScript code,
3633 turn on this option.
3635 11. If you want background zebra stripes in your PostScript code, turn on
3638 12. If you want a duplex printing and your PostScript printer has this
3639 feature, turn on this option.
3641 13. If you turned on duplex printing, you can choose if you want to have a
3642 printing suitable for binding on the left or right (tumble off), or to
3643 have a printing suitable for binding at top or bottom (tumble on).
3644 This option is enabled if duplex is on (option 12).
3646 14. If you want a PostScript upside-down printing, turn on this option.
3648 15. With this option, you can choose if you want to print all pages, odd
3649 pages, even pages, odd sheets or even sheets.
3650 See also `ps-even-or-odd-pages'.
3652 IV. PostScript processing toggle options:
3654 16. If you want to spool the PostScript code generated, turn on this
3655 option. To spool the PostScript code generated use option 2. You can
3656 despool later by choosing option 1 or 2, sub-option `Despool...'.
3658 17. If you use colors in your buffers and want to see these colors on your
3659 PostScript code generated, turn on this option. If you have a
3660 black/white PostScript printer, these colors are displayed in gray
3661 scale by PostScript printer interpreter.
3663 18. If you don't have a PostScript printer to send PostScript files, turn
3664 on this option. When this option is on, the ghostscript is used to
3665 print PostScript files. In GNU or Unix system, if ghostscript is set
3666 as a PostScript filter, you don't need to turn on this option.
3668 V. Printing customization:
3670 19. If you want that region is automagically detected, turn on this
3671 option. Note that this will only work if you're using transient mark
3672 mode. When this option is on, the `*-buffer*' commands will behave
3673 like `*-region*' commands, that is, `*-buffer*' commands will print
3674 only the region marked instead of all buffer.
3676 20. Turn this option on if you want that when current major-mode is
3677 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3678 behave like `*-mode*' commands.
3680 21. If you want that Printing menu stays open while you are setting
3681 toggle options, turn on this option. The variables
3682 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3683 menu position, so don't forget to adjust these variables if menu
3688 22. Besides all options in section III, IV and V, you can customize much
3689 more PostScript options in `ps-print' option. Or you can customize
3690 some `lpr' options for text printing. Or customize `printing'
3693 23. Show current settings for `printing', `ps-print' or `lpr'.
3695 24. Quick help for printing menu layout.
3697 "Printing help message.")
3700 (defconst pr-interface-help-message
3701 (concat "printing.el version " pr-version
3702 " ps-print.el version " ps-print-version
3704 The printing interface buffer has the same functionality as the printing menu.
3705 The major difference is that the states (like sending PostScript generated to a
3706 file, n-up printing, etc.) are set and saved between printing buffer
3707 activation. Also, the landscape, duplex and tumble values are the same for
3708 PostScript file and directory/buffer/region/mode processing; using menu, there
3709 are different value sets for PostScript file and directory/buffer/region/mode
3712 The printing interface buffer has the following sections:
3716 Here you can choose to print/preview a buffer, a directory or a PostScript
3722 Select a buffer from the current buffer list.
3725 If it's on, this means that the selected buffer has an active region,
3726 so you can turn on/off, as you wish.
3727 If it's off when a buffer is selected, this means that the selected
3728 buffer has no active region, so it'll not be possible to turn it on.
3729 If you want to process the region, let this option on.
3730 If you want to process the whole buffer, let this option off.
3733 If it's on, this means that the selected buffer major mode is declared
3734 for major mode processing, so you can turn on/off, as you wish.
3735 If it's off when a buffer is selected, this means that the selected
3736 buffer major mode isn't declared for major mode processing, so it'll
3737 not be possible to turn it on.
3738 If you want the major mode processing, let this option on.
3739 If you don't want the major mode processing, let this option off.
3741 NOTE 1: It's possible to customize a major mode printing, just declare
3742 the customization in `pr-mode-alist' and invoke some of
3743 `*-mode*' commands or select Mode option in Printing menu. An
3744 example for major mode usage is when you're using gnus (or mh,
3745 or rmail, etc.) and you're in the *Summary* buffer, if you
3746 forget to switch to the *Article* buffer before printing,
3747 you'll get a nicely formatted list of article subjects shows
3748 up at the printer. With major mode printing you don't need to
3749 switch from gnus *Summary* buffer first.
3754 Specify a valid directory path.
3757 Specify a file name regexp. All file names in the directory that
3758 match with regexp will be printed/previewed. An empty file name
3759 regexp means to print/preview all files in the directory.
3761 * List Directory Entry:
3762 If it's turned on, list directory entries besides file entries.
3764 1c. PostScript file:
3767 Specify an existent PostScript file to print/preview.
3769 * PostScript Utility:
3770 Select a PostScript utility.
3771 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3773 NOTE 2: Don't forget to download and install the utilities declared on
3774 `pr-ps-utility-alist'.
3777 If it's turned on, don't use the PostScript utility to preprocess the
3778 PostScript file before printing/previewing.
3780 2. PostScript printer:
3782 * PostScript Printer:
3783 You can select a new PostScript printer to send PostScript code
3784 generated. For selection it's used all PostScript printers defined
3785 in `pr-ps-printer-alist' variable (see it for documentation).
3786 See also `pr-setting-database'.
3789 If spooling is on, you can turn it on/off, as you wish.
3790 If spooling is off, it'll not be possible to turn it on.
3791 If it's turned on, specify to despools the PostScript spooling buffer in
3792 a temporary file or in the selected PostScript file when
3793 printing/previewing.
3796 Preview the PostScript generated.
3799 Print the PostScript generated.
3802 Quit from printing interface buffer.
3804 * Send to Printer/Temporary File:
3805 If it's turned on, the PostScript generated is sent directly to
3806 PostScript printer or, for previewing, to a temporary file.
3809 Specify a file name to send the PostScript generated.
3812 Specify n-up printing.
3817 Select a new text printer to send text generated. For selection it's used
3818 all text printers defined in `pr-txt-printer-alist' variable (see it for
3819 documentation). See also `pr-setting-database'.
3822 If you have control characters (character code from \\000 to \\037) in a
3823 buffer and you want to print them in a text printer, select this
3824 option. All control characters in your buffer or region will be
3825 replaced by a printable representation. The printable representations
3826 use ^ (for ASCII control characters) or hex. The characters tab,
3827 linefeed, space, return and formfeed are not affected.
3828 You don't need to select this option if you use any option of section
3829 I, the PostScript engine treats control characters properly.
3832 To print a directory, buffer, region or major mode in a
3833 text printer, select this option. See also the NOTE 1 on section 1.
3836 Quit from printing interface buffer.
3840 There are 3 setting columns:
3842 4a. First column (left column):
3845 PostScript landscape printing.
3848 To have a header in each page in your PostScript code.
3850 * Print Header Frame:
3851 To draw a gaudy frame around the header.
3854 The line number is printed in your PostScript code.
3857 Background zebra stripes in your PostScript code.
3860 Duplex printing (if your PostScript printer has this feature).
3863 If duplex printing is on, you can choose if you want to have a
3864 printing suitable for binding on the left or right (tumble off), or to
3865 have a printing suitable for binding at top or bottom (tumble on).
3868 PostScript upside-down printing.
3870 4b. Second column (middle column):
3873 If you want that region is automagically detected, turn on this
3874 option. Note that this will only work if you're using transient mark
3875 mode. When this option is on, the `*-buffer*' commands will behave
3876 like `*-region*' commands, that is, `*-buffer*' commands will print
3877 only the region marked instead of all buffer.
3880 Turn this option on if you want that when current major-mode is
3881 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3882 behave like `*-mode*' commands.
3885 If you want that Printing menu stays open while you are setting
3886 toggle options, turn on this option. The variables
3887 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3888 menu position, so don't forget to adjust these variables if menu
3892 To spool the PostScript code generated. You can despool later by
3893 setting Despool option on PostScript printer section.
3896 If you use colors in your buffers and want to see these colors on your
3897 PostScript code generated, turn on this option. If you have a
3898 black/white PostScript printer, these colors are displayed in gray
3899 scale by PostScript printer interpreter.
3901 * Print via Ghostscript:
3902 If you don't have a PostScript printer to send PostScript files, turn
3903 on this option. When this option is on, the ghostscript is used to
3904 print PostScript files. In GNU or Unix system, if ghostscript is set
3905 as a PostScript filter, you don't need to turn on this option.
3908 To print all pages, odd pages, even pages, odd sheets or even sheets.
3909 See also `ps-even-or-odd-pages'.
3911 4c. Third column (right column):
3914 That is, to be verbose when editing a field in interface buffer.
3918 Besides all options in section 4, you can customize much more PostScript
3919 options in `ps-print' option. Or you can customize some `lpr' options for
3920 text printing. Or customize `printing' options.
3924 Show current settings for `printing', `ps-print' or `lpr'.
3928 Quick help for printing interface buffer and printing menu layout. You can
3929 also quit the printing interface buffer or kill all printing help buffer.
3931 "Printing buffer interface help message.")
3934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3939 (defun pr-interface (&optional buffer
)
3940 "Activate the printing interface buffer.
3942 If BUFFER is nil, the current buffer is used for printing.
3944 For more information, type \\[pr-interface-help]."
3946 (with-current-buffer (or buffer
(current-buffer))
3947 (pr-create-interface)))
3951 (defun pr-ps-directory-preview (n-up dir file-regexp
&optional filename
)
3952 "Preview directory using ghostview.
3954 Interactively, the command prompts for N-UP printing number, a directory, a
3955 file name regexp for matching and, when you use a prefix argument (C-u), the
3956 command prompts the user for a file name, and saves the PostScript image in
3957 that file instead of saving it in a temporary file.
3959 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3960 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3961 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3962 save the image in a temporary file. If FILENAME is a string, save the
3963 PostScript image in a file with that name. If FILENAME is t, prompts for a
3966 See also documentation for `pr-list-directory'."
3967 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3968 (pr-set-ps-dir-args 'n-up
'dir
'file-regexp
'filename
3969 (pr-prompt "PS preview dir"))
3970 (setq filename
(pr-ps-file filename
))
3971 (pr-ps-file-list n-up dir file-regexp filename
)
3973 (pr-ps-file-preview filename
)))
3977 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp
&optional filename
)
3978 "Print directory using PostScript through ghostscript.
3980 Interactively, the command prompts for N-UP printing number, a directory, a
3981 file name regexp for matching and, when you use a prefix argument (C-u), the
3982 command prompts the user for a file name, and saves the PostScript image in
3983 that file instead of saving it in a temporary file.
3985 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3986 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3987 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3988 save the image in a temporary file. If FILENAME is a string, save the
3989 PostScript image in a file with that name. If FILENAME is t, prompts for a
3992 See also documentation for `pr-list-directory'."
3993 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3994 (pr-set-ps-dir-args 'n-up
'dir
'file-regexp
'filename
3995 (pr-prompt "PS print dir GS"))
3996 (let ((file (pr-ps-file filename
)))
3997 (pr-ps-file-list n-up dir file-regexp file
)
3998 (pr-ps-file-using-ghostscript file
)
3999 (or filename
(pr-delete-file file
))))
4003 (defun pr-ps-directory-print (n-up dir file-regexp
&optional filename
)
4004 "Print directory using PostScript printer.
4006 Interactively, the command prompts for N-UP printing number, a directory, a
4007 file name regexp for matching and, when you use a prefix argument (C-u), the
4008 command prompts the user for a file name, and saves the PostScript image in
4009 that file instead of saving it in a temporary file.
4011 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4012 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4013 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4014 save the image in a temporary file. If FILENAME is a string, save the
4015 PostScript image in a file with that name. If FILENAME is t, prompts for a
4018 See also documentation for `pr-list-directory'."
4019 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
4020 (pr-set-ps-dir-args 'n-up
'dir
'file-regexp
'filename
4021 (pr-prompt "PS print dir"))
4022 (let ((file (pr-ps-file filename
)))
4023 (pr-ps-file-list n-up dir file-regexp file
)
4024 (pr-ps-file-print file
)
4025 (or filename
(pr-delete-file file
))))
4029 (defun pr-ps-directory-ps-print (n-up dir file-regexp
&optional filename
)
4030 "Print directory using PostScript printer or through ghostscript.
4032 It depends on `pr-print-using-ghostscript'.
4034 Interactively, the command prompts for N-UP printing number, a directory, a
4035 file name regexp for matching and, when you use a prefix argument (C-u), the
4036 command prompts the user for a file name, and saves the PostScript image in
4037 that file instead of saving it in a temporary file.
4039 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4040 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4041 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4042 save the image in a temporary file. If FILENAME is a string, save the
4043 PostScript image in a file with that name. If FILENAME is t, prompts for a
4046 See also documentation for `pr-list-directory'."
4047 (interactive (pr-interactive-ps-dir-args
4048 (pr-prompt (pr-prompt-gs "PS print dir"))))
4049 (pr-set-ps-dir-args 'n-up
'dir
'file-regexp
'filename
4050 (pr-prompt (pr-prompt-gs "PS print dir")))
4051 (if (pr-using-ghostscript-p)
4052 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename
)
4053 (pr-ps-directory-print n-up dir file-regexp filename
)))
4057 (defun pr-ps-buffer-preview (n-up &optional filename
)
4058 "Preview buffer using ghostview.
4060 Interactively, the command prompts for N-UP printing number and, when you use a
4061 prefix argument (C-u), the command prompts the user for a file name, and saves
4062 the PostScript image in that file instead of saving it in a temporary file.
4064 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4065 argument FILENAME is treated as follows: if it's nil, save the image in a
4066 temporary file. If FILENAME is a string, save the PostScript image in a file
4067 with that name. If FILENAME is t, prompts for a file name."
4068 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
4069 (if (pr-auto-mode-p)
4070 (pr-ps-mode-preview n-up filename
)
4071 (pr-ps-preview (pr-region-active-symbol) n-up filename
4072 (pr-region-active-string "PS preview"))))
4076 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename
)
4077 "Print buffer using PostScript through ghostscript.
4079 Interactively, the command prompts for N-UP printing number and, when you use a
4080 prefix argument (C-u), the command prompts the user for a file name, and saves
4081 the PostScript image in that file instead of sending it to the printer.
4083 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4084 argument FILENAME is treated as follows: if it's nil, send the image to the
4085 printer. If FILENAME is a string, save the PostScript image in a file with
4086 that name. If FILENAME is t, prompts for a file name."
4087 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
4088 (if (pr-auto-mode-p)
4089 (pr-ps-mode-using-ghostscript n-up filename
)
4090 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4091 (pr-region-active-string "PS print GS"))))
4095 (defun pr-ps-buffer-print (n-up &optional filename
)
4096 "Print buffer using PostScript printer.
4098 Interactively, the command prompts for N-UP printing number and, when you use a
4099 prefix argument (C-u), the command prompts the user for a file name, and saves
4100 the PostScript image in that file instead of sending it to the printer.
4102 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4103 argument FILENAME is treated as follows: if it's nil, send the image to the
4104 printer. If FILENAME is a string, save the PostScript image in a file with
4105 that name. If FILENAME is t, prompts for a file name."
4106 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
4107 (if (pr-auto-mode-p)
4108 (pr-ps-mode-print n-up filename
)
4109 (pr-ps-print (pr-region-active-symbol) n-up filename
4110 (pr-region-active-string "PS print"))))
4114 (defun pr-ps-buffer-ps-print (n-up &optional filename
)
4115 "Print buffer using PostScript printer or through ghostscript.
4117 It depends on `pr-print-using-ghostscript'.
4119 Interactively, the command prompts for N-UP printing number and, when you use a
4120 prefix argument (C-u), the command prompts the user for a file name, and saves
4121 the PostScript image in that file instead of sending it to the printer.
4123 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4124 argument FILENAME is treated as follows: if it's nil, send the image to the
4125 printer. If FILENAME is a string, save the PostScript image in a file with
4126 that name. If FILENAME is t, prompts for a file name."
4127 (interactive (pr-interactive-n-up-file
4128 (pr-prompt (pr-prompt-gs "PS print"))))
4129 (cond ((pr-auto-mode-p)
4130 (pr-ps-mode-ps-print n-up filename
))
4131 ((pr-using-ghostscript-p)
4132 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4133 (pr-region-active-string "PS print GS")))
4135 (pr-ps-print (pr-region-active-symbol) n-up filename
4136 (pr-region-active-string "PS print")))))
4140 (defun pr-ps-region-preview (n-up &optional filename
)
4141 "Preview region using ghostview.
4143 See also `pr-ps-buffer-preview'."
4144 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
4145 (if (pr-auto-mode-p)
4146 (let ((pr-auto-region t
))
4147 (pr-ps-mode-preview n-up filename
))
4148 (pr-ps-preview 'region n-up filename
"PS preview region")))
4152 (defun pr-ps-region-using-ghostscript (n-up &optional filename
)
4153 "Print region using PostScript through ghostscript.
4155 See also `pr-ps-buffer-using-ghostscript'."
4156 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
4157 (if (pr-auto-mode-p)
4158 (let ((pr-auto-region t
))
4159 (pr-ps-mode-using-ghostscript n-up filename
))
4160 (pr-ps-using-ghostscript 'region n-up filename
"PS print GS region")))
4164 (defun pr-ps-region-print (n-up &optional filename
)
4165 "Print region using PostScript printer.
4167 See also `pr-ps-buffer-print'."
4168 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
4169 (if (pr-auto-mode-p)
4170 (let ((pr-auto-region t
))
4171 (pr-ps-mode-print n-up filename
))
4172 (pr-ps-print 'region n-up filename
"PS print region")))
4176 (defun pr-ps-region-ps-print (n-up &optional filename
)
4177 "Print region using PostScript printer or through ghostscript.
4179 See also `pr-ps-buffer-ps-print'."
4180 (interactive (pr-interactive-n-up-file
4181 (pr-prompt-region (pr-prompt-gs "PS print"))))
4182 (cond ((pr-auto-mode-p)
4183 (let ((pr-auto-region t
))
4184 (pr-ps-mode-ps-print n-up filename
)))
4185 ((pr-using-ghostscript-p)
4186 (pr-ps-using-ghostscript 'region n-up filename
"PS print GS region"))
4188 (pr-ps-print 'region n-up filename
"PS print region"))))
4192 (defun pr-ps-mode-preview (n-up &optional filename
)
4193 "Preview major mode using ghostview.
4195 See also `pr-ps-buffer-preview'."
4196 (interactive (pr-interactive-n-up-file "PS preview mode"))
4197 (pr-set-n-up-and-filename 'n-up
'filename
"PS preview mode")
4198 (let ((file (pr-ps-file filename
)))
4199 (and (pr-ps-mode n-up file
)
4201 (pr-ps-file-preview file
))))
4205 (defun pr-ps-mode-using-ghostscript (n-up &optional filename
)
4206 "Print major mode using PostScript through ghostscript.
4208 See also `pr-ps-buffer-using-ghostscript'."
4209 (interactive (pr-interactive-n-up-file "PS print GS mode"))
4210 (pr-set-n-up-and-filename 'n-up
'filename
"PS print GS mode")
4211 (let ((file (pr-ps-file filename
)))
4212 (when (and (pr-ps-mode n-up file
)
4214 (pr-ps-file-using-ghostscript file
)
4215 (or filename
(pr-delete-file file
)))))
4219 (defun pr-ps-mode-print (n-up &optional filename
)
4220 "Print major mode using PostScript printer.
4222 See also `pr-ps-buffer-print'."
4223 (interactive (pr-interactive-n-up-file "PS print mode"))
4224 (pr-set-n-up-and-filename 'n-up
'filename
"PS print mode")
4225 (pr-ps-mode n-up filename
))
4229 (defun pr-ps-mode-ps-print (n-up &optional filename
)
4230 "Print major mode using PostScript or through ghostscript.
4232 See also `pr-ps-buffer-ps-print'."
4233 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
4234 (if (pr-using-ghostscript-p)
4235 (pr-ps-mode-using-ghostscript n-up filename
)
4236 (pr-ps-mode-print n-up filename
)))
4240 (defun pr-printify-directory (&optional dir file-regexp
)
4241 "Replace nonprinting characters in directory with printable representations.
4242 The printable representations use ^ (for ASCII control characters) or hex.
4243 The characters tab, linefeed, space, return and formfeed are not affected.
4245 Interactively, the command prompts for a directory and a file name regexp for
4248 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4249 prompts for FILE(name)-REGEXP.
4251 See also documentation for `pr-list-directory'."
4252 (interactive (pr-interactive-dir-args "Printify dir"))
4253 (pr-set-dir-args 'dir
'file-regexp
"Printify dir")
4254 (pr-file-list dir file-regexp
'pr-printify-buffer
))
4258 (defun pr-printify-buffer ()
4259 "Replace nonprinting characters in buffer with printable representations.
4260 The printable representations use ^ (for ASCII control characters) or hex.
4261 The characters tab, linefeed, space, return and formfeed are not affected."
4263 (if (pr-region-active-p)
4264 (pr-printify-region)
4265 (printify-region (point-min) (point-max))))
4269 (defun pr-printify-region ()
4270 "Replace nonprinting characters in region with printable representations.
4271 The printable representations use ^ (for ASCII control characters) or hex.
4272 The characters tab, linefeed, space, return and formfeed are not affected."
4274 (printify-region (point) (mark)))
4278 (defun pr-txt-directory (&optional dir file-regexp
)
4279 "Print directory using text printer.
4281 Interactively, the command prompts for a directory and a file name regexp for
4284 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4285 prompts for FILE(name)-REGEXP.
4287 See also documentation for `pr-list-directory'."
4288 (interactive (pr-interactive-dir-args "Print dir"))
4289 (pr-set-dir-args 'dir
'file-regexp
"Print dir")
4290 (pr-file-list dir file-regexp
'pr-txt-buffer
))
4294 (defun pr-txt-buffer ()
4295 "Print buffer using text printer."
4297 (cond ((pr-auto-mode-p)
4299 ((pr-region-active-p)
4302 (pr-txt-print (point-min) (point-max)))))
4306 (defun pr-txt-region ()
4307 "Print region using text printer."
4309 (if (pr-auto-mode-p)
4310 (let ((pr-auto-region t
))
4312 (pr-txt-print (point) (mark))))
4316 (defun pr-txt-mode ()
4317 "Print major mode using text printer."
4319 (let ((args (pr-mode-alist-p)))
4321 (funcall (car args
) (nthcdr 2 args
))
4323 (message "`%s' major mode not declared." major-mode
))))
4327 (defun pr-despool-preview (&optional filename
)
4328 "Preview spooled PostScript.
4330 Interactively, when you use a prefix argument (C-u), the command prompts the
4331 user for a file name, and saves the spooled PostScript image in that file
4332 instead of saving it in a temporary file.
4334 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4335 save the image in a temporary file. If FILENAME is a string, save the
4336 PostScript image in a file with that name."
4337 (interactive (list (ps-print-preprint current-prefix-arg
)))
4338 (let ((file (pr-ps-file filename
)))
4339 (when (stringp file
)
4340 (pr-despool-print file
)
4341 (pr-ps-file-preview file
))))
4345 (defun pr-despool-using-ghostscript (&optional filename
)
4346 "Print spooled PostScript using ghostscript.
4348 Interactively, when you use a prefix argument (C-u), the command prompts the
4349 user for a file name, and saves the spooled PostScript image in that file
4350 instead of sending it to the printer.
4352 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4353 send the image to the printer. If FILENAME is a string, save the PostScript
4354 image in a file with that name."
4355 (interactive (list (ps-print-preprint current-prefix-arg
)))
4356 (let ((file (pr-ps-file filename
)))
4357 (when (stringp file
)
4358 (pr-despool-print file
)
4359 (pr-ps-file-using-ghostscript file
)
4360 (or filename
(pr-delete-file file
)))))
4364 (defun pr-despool-print (&optional filename
)
4365 "Send the spooled PostScript to the printer.
4367 Interactively, when you use a prefix argument (C-u), the command prompts the
4368 user for a file name, and saves the spooled PostScript image in that file
4369 instead of sending it to the printer.
4371 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4372 send the image to the printer. If FILENAME is a string, save the PostScript
4373 image in a file with that name."
4374 (interactive (list (ps-print-preprint current-prefix-arg
)))
4376 (let ((ps-lpr-command (pr-command pr-ps-command
))
4377 (ps-lpr-switches pr-ps-switches
)
4378 (ps-printer-name-option pr-ps-printer-switch
)
4379 (ps-printer-name pr-ps-printer
))
4380 (ps-despool filename
))))
4384 (defun pr-despool-ps-print (&optional filename
)
4385 "Send the spooled PostScript to the printer or use ghostscript to print it.
4387 Interactively, when you use a prefix argument (C-u), the command prompts the
4388 user for a file name, and saves the spooled PostScript image in that file
4389 instead of sending it to the printer.
4391 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4392 send the image to the printer. If FILENAME is a string, save the PostScript
4393 image in a file with that name."
4394 (interactive (list (ps-print-preprint current-prefix-arg
)))
4395 (if pr-print-using-ghostscript
4396 (pr-despool-using-ghostscript filename
)
4397 (pr-despool-print filename
)))
4401 (defun pr-ps-file-preview (filename)
4402 "Preview PostScript file FILENAME."
4403 (interactive (list (pr-ps-infile-preprint "Preview ")))
4404 (and (stringp filename
) (file-exists-p filename
)
4405 (pr-call-process pr-gv-command filename
)))
4409 (defun pr-ps-file-up-preview (n-up ifilename
&optional ofilename
)
4410 "Preview PostScript file FILENAME."
4411 (interactive (pr-interactive-n-up-inout "PS preview"))
4412 (let ((outfile (pr-ps-utility-args 'n-up
'ifilename
'ofilename
4414 (pr-ps-utility-process n-up ifilename outfile
)
4415 (pr-ps-file-preview outfile
)))
4419 (defun pr-ps-file-using-ghostscript (filename)
4420 "Print PostScript file FILENAME using ghostscript."
4421 (interactive (list (pr-ps-infile-preprint "Print preview ")))
4422 (and (stringp filename
) (file-exists-p filename
)
4423 (let* ((file (pr-expand-file-name filename
))
4424 (tempfile (pr-dosify-file-name (make-temp-file file
))))
4426 (pr-call-process pr-gs-command
4427 (format "-sDEVICE=%s" pr-gs-device
)
4428 (format "-r%d" pr-gs-resolution
)
4429 (pr-switches-string pr-gs-switches
"pr-gs-switches")
4430 (format "-sOutputFile=\"%s\"" tempfile
)
4434 (pr-ps-file-print tempfile
)
4436 (pr-delete-file tempfile
))))
4440 (defun pr-ps-file-print (filename)
4441 "Print PostScript file FILENAME."
4442 (interactive (list (pr-ps-infile-preprint "Print ")))
4443 (and (stringp filename
) (file-exists-p filename
)
4445 (let ((file (pr-expand-file-name filename
)))
4446 (if (string= pr-ps-command
"")
4448 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name
)))
4449 (with-current-buffer ps-spool-buffer
4451 (insert-file-contents-literally file
))
4453 ;; use `pr-ps-command' to print
4454 (apply 'pr-call-process
4456 (pr-switches-string pr-ps-switches
"pr-ps-switches")
4457 (if (string-match "cp" pr-ps-command
)
4458 ;; for "cp" (cmd in out)
4460 (concat pr-ps-printer-switch pr-ps-printer
))
4461 ;; else, for others (cmd out in)
4462 (list (concat pr-ps-printer-switch pr-ps-printer
)
4467 (defun pr-ps-file-ps-print (filename)
4468 "Send PostScript file FILENAME to printer or use ghostscript to print it."
4469 (interactive (list (pr-ps-infile-preprint
4470 (if pr-print-using-ghostscript
4473 (if pr-print-using-ghostscript
4474 (pr-ps-file-using-ghostscript filename
)
4475 (pr-ps-file-print filename
)))
4479 (defun pr-ps-file-up-ps-print (n-up ifilename
&optional ofilename
)
4480 "Process a PostScript file IFILENAME and send it to printer.
4482 Interactively, the command prompts for N-UP printing number, for an input
4483 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
4484 command prompts the user for an output PostScript file name OFILENAME, and
4485 saves the PostScript image in that file instead of sending it to the printer.
4487 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4488 argument IFILENAME is treated as follows: if it's t, prompts for an input
4489 PostScript file name; otherwise, it *must* be a string that it's an input
4490 PostScript file name. The argument OFILENAME is treated as follows: if it's
4491 nil, send the image to the printer. If OFILENAME is a string, save the
4492 PostScript image in a file with that name. If OFILENAME is t, prompts for a
4494 (interactive (pr-interactive-n-up-inout
4495 (if pr-print-using-ghostscript
4498 (let ((outfile (pr-ps-utility-args 'n-up
'ifilename
'ofilename
4499 (if pr-print-using-ghostscript
4502 (pr-ps-utility-process n-up ifilename outfile
)
4504 (pr-ps-file-ps-print outfile
)
4505 (pr-delete-file outfile
))))
4509 (defun pr-toggle-file-duplex ()
4510 "Toggle duplex for PostScript file."
4512 (pr-toggle-file-duplex-menu t
))
4516 (defun pr-toggle-file-tumble ()
4517 "Toggle tumble for PostScript file.
4519 If tumble is off, produces a printing suitable for binding on the left or
4521 If tumble is on, produces a printing suitable for binding at the top or
4524 (pr-toggle-file-tumble-menu t
))
4528 (defun pr-toggle-file-landscape ()
4529 "Toggle landscape for PostScript file."
4531 (pr-toggle-file-landscape-menu t
))
4535 (defun pr-toggle-ghostscript ()
4536 "Toggle printing using ghostscript."
4538 (pr-toggle-ghostscript-menu t
))
4542 (defun pr-toggle-faces ()
4543 "Toggle printing with faces."
4545 (pr-toggle-faces-menu t
))
4549 (defun pr-toggle-spool ()
4552 (pr-toggle-spool-menu t
))
4556 (defun pr-toggle-duplex ()
4559 (pr-toggle-duplex-menu t
))
4563 (defun pr-toggle-tumble ()
4566 If tumble is off, produces a printing suitable for binding on the left or
4568 If tumble is on, produces a printing suitable for binding at the top or
4571 (pr-toggle-tumble-menu t
))
4575 (defun pr-toggle-landscape ()
4578 (pr-toggle-landscape-menu t
))
4582 (defun pr-toggle-upside-down ()
4583 "Toggle upside-down."
4585 (pr-toggle-upside-down-menu t
))
4589 (defun pr-toggle-line ()
4590 "Toggle line number."
4592 (pr-toggle-line-menu t
))
4596 (defun pr-toggle-zebra ()
4597 "Toggle zebra stripes."
4599 (pr-toggle-zebra-menu t
))
4603 (defun pr-toggle-header ()
4604 "Toggle printing header."
4606 (pr-toggle-header-menu t
))
4610 (defun pr-toggle-header-frame ()
4611 "Toggle printing header frame."
4613 (pr-toggle-header-frame-menu t
))
4617 (defun pr-toggle-lock ()
4620 (pr-toggle-lock-menu t
))
4624 (defun pr-toggle-region ()
4625 "Toggle whether the region is automagically detected."
4627 (pr-toggle-region-menu t
))
4631 (defun pr-toggle-mode ()
4634 (pr-toggle-mode-menu t
))
4638 (defun pr-customize (&rest _ignore
)
4639 "Customization of the `printing' group."
4641 (customize-group 'printing
))
4645 (defun lpr-customize (&rest _ignore
)
4646 "Customization of the `lpr' group."
4648 (customize-group 'lpr
))
4652 (defun pr-help (&rest _ignore
)
4653 "Help for the printing package."
4655 (pr-show-setup pr-help-message
"*Printing Help*"))
4659 (defun pr-ps-name ()
4660 "Interactively select a PostScript printer."
4662 (pr-menu-set-ps-title
4663 (pr-complete-alist "PostScript printer"
4664 pr-ps-printer-alist pr-ps-name
)))
4668 (defun pr-txt-name ()
4669 "Interactively select a text printer."
4671 (pr-menu-set-txt-title
4672 (pr-complete-alist "Text printer"
4673 pr-txt-printer-alist pr-txt-name
)))
4677 (defun pr-ps-utility ()
4678 "Interactively select a PostScript utility."
4680 (pr-menu-set-utility-title
4681 (pr-complete-alist "PostScript utility"
4682 pr-ps-utility-alist pr-ps-utility
)))
4686 (defun pr-show-ps-setup (&rest _ignore
)
4687 "Show current ps-print settings."
4689 (pr-show-setup (ps-setup) "*PS Setup*"))
4693 (defun pr-show-pr-setup (&rest _ignore
)
4694 "Show current printing settings."
4696 (pr-show-setup (pr-setup) "*PR Setup*"))
4700 (defun pr-show-lpr-setup (&rest _ignore
)
4701 "Show current lpr settings."
4703 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4706 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4711 (defun pr-ps-fast-fire (n-up &optional select
)
4712 "Fast fire function for PostScript printing.
4714 If a region is active, the region will be printed instead of the whole buffer.
4715 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4716 `pr-mode-alist' will be used, that is, the current buffer or region will be
4717 printed using `pr-ps-mode-ps-print'.
4720 Interactively, you have the following situations:
4722 M-x pr-ps-fast-fire RET
4723 The command prompts the user for a N-UP value and printing will
4724 immediately be done using the current active printer.
4726 C-u M-x pr-ps-fast-fire RET
4727 C-u 0 M-x pr-ps-fast-fire RET
4728 The command prompts the user for a N-UP value and also for a current
4729 PostScript printer, then printing will immediately be done using the new
4730 current active printer.
4732 C-u 1 M-x pr-ps-fast-fire RET
4733 The command prompts the user for a N-UP value and also for a file name,
4734 and saves the PostScript image in that file instead of sending it to the
4737 C-u 2 M-x pr-ps-fast-fire RET
4738 The command prompts the user for a N-UP value, then for a current
4739 PostScript printer and, finally, for a file name. Then change the active
4740 printer to that chosen by user and saves the PostScript image in
4741 that file instead of sending it to the printer.
4744 Noninteractively, the argument N-UP should be a positive integer greater than
4745 zero and the argument SELECT is treated as follows:
4747 If it's nil, send the image to the printer.
4749 If it's a list or an integer lesser or equal to zero, the command prompts
4750 the user for a current PostScript printer, then printing will immediately
4751 be done using the new current active printer.
4753 If it's an integer equal to 1, the command prompts the user for a file name
4754 and saves the PostScript image in that file instead of sending it to the
4757 If it's an integer greater or equal to 2, the command prompts the user for a
4758 current PostScript printer and for a file name. Then change the active
4759 printer to that chosen by user and saves the PostScript image in that file
4760 instead of sending it to the printer.
4762 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4763 active printer and printing will immediately be done using the new active
4766 Otherwise, send the image to the printer.
4769 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4771 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4772 current-prefix-arg
))
4773 (let ((pr-auto-region t
)
4776 (cond ((null select
))
4779 ((and (symbolp select
)
4780 (assq select pr-ps-printer-alist
))
4781 (pr-menu-set-ps-title select
))
4785 (and (>= select
1) (not pr-spool-p
)
4786 (setq filename
(pr-ps-outfile-preprint
4787 (if pr-print-using-ghostscript
4790 (pr-ps-buffer-ps-print
4792 (min (max n-up
1) 100)
4793 (error "n-up must be an integer greater than zero"))
4798 (defun pr-txt-fast-fire (&optional select-printer
)
4799 "Fast fire function for text printing.
4801 If a region is active, the region will be printed instead of the whole buffer.
4802 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4803 `pr-mode-alist' will be used, that is, the current buffer or region will be
4804 printed using `pr-txt-mode'.
4806 Interactively, when you use a prefix argument (C-u), the command prompts the
4807 user for a new active text printer.
4809 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4811 If it's nil, the printing is sent to the current active text printer.
4813 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4814 active printer and printing will immediately be done using the new active
4817 If it's non-nil, the command prompts the user for a new active text printer.
4819 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4821 (interactive (list current-prefix-arg
))
4822 (cond ((null select-printer
))
4823 ((and (symbolp select-printer
)
4824 (assq select-printer pr-txt-printer-alist
))
4825 (pr-menu-set-txt-title select-printer
))
4828 (let ((pr-auto-region t
)
4833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4838 "Return the current `printing' setup.
4840 This is *not* an interactive command.
4841 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4843 M-: (insert (pr-setup)) RET
4845 Or choose the menu option Printing/Show Settings/printing."
4846 (let (ps-prefix-quote)
4850 (concat "\n;;; printing.el version " pr-version
"\n")
4852 (ps-comment-string "emacs-version " emacs-version
)
4853 (ps-comment-string "pr-txt-command " pr-txt-command
)
4854 (ps-comment-string "pr-txt-switches "
4855 (pr-switches-string pr-txt-switches
"pr-txt-switches"))
4856 (ps-comment-string "pr-txt-printer " pr-txt-printer
)
4857 (ps-comment-string "pr-ps-command " pr-ps-command
)
4858 (ps-comment-string "pr-ps-switches "
4859 (pr-switches-string pr-ps-switches
"pr-ps-switches"))
4860 (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch
)
4861 (ps-comment-string "pr-ps-printer " pr-ps-printer
)
4862 (ps-comment-string "pr-cygwin-system " pr-cygwin-system
)
4863 (ps-comment-string "lpr-windows-system " lpr-windows-system
)
4864 (ps-comment-string "lpr-lp-system " lpr-lp-system
)
4866 '(14 . pr-path-style
)
4867 '(14 . pr-path-alist
)
4870 '(21 . pr-txt-printer-alist
)
4873 '(20 . pr-ps-printer-alist
)
4876 '(20 . pr-ps-temp-file
)
4877 '(20 . pr-file-modes
)
4878 '(20 . pr-delete-temp-file
)
4879 '(20 . pr-list-directory
)
4881 '(17 . pr-gv-command
)
4882 '(17 . pr-gs-command
)
4883 '(17 . pr-gs-switches
)
4884 '(17 . pr-gs-device
)
4885 '(17 . pr-gs-resolution
)
4887 '(27 . pr-print-using-ghostscript
)
4890 '(27 . pr-file-landscape
)
4891 '(27 . pr-file-duplex
)
4892 '(27 . pr-file-tumble
)
4893 '(27 . pr-auto-region
)
4894 '(27 . pr-auto-mode
)
4896 '(20 . pr-ps-utility
)
4897 '(20 . pr-ps-utility-alist
)
4899 '(14 . pr-mode-alist
)
4901 '(20 . pr-menu-lock
)
4902 '(20 . pr-menu-char-height
)
4903 '(20 . pr-menu-char-width
)
4905 '(20 . pr-setting-database
)
4907 '(22 . pr-visible-entry-list
)
4909 '(22 . pr-buffer-verbose
)
4910 '(22 . pr-buffer-name
)
4911 '(22 . pr-buffer-name-ignore
)
4912 ")\n\n;;; printing.el - end of settings\n")
4917 "Return the current `lpr' setup.
4919 This is *not* an interactive command.
4920 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4922 M-: (insert (lpr-setup)) RET
4924 Or choose the menu option Printing/Show Settings/lpr."
4925 (let (ps-prefix-quote)
4929 "\n;;; lpr.el settings\n"
4930 (ps-comment-string "emacs-version" emacs-version
)
4932 '(25 . printer-name
)
4933 '(25 . lpr-switches
)
4934 '(25 . lpr-add-switches
)
4936 '(25 . lpr-headers-switches
)
4937 '(25 . print-region-function
)
4938 '(25 . lpr-page-header-program
)
4939 '(25 . lpr-page-header-switches
)
4940 ")\n\n;;; lpr.el - end of settings\n")
4944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4945 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4947 (declare-function mh-get-msg-num
"mh-utils" (error-if-no-message))
4948 (declare-function mh-show
"mh-show" (&optional message redisplay-flag
))
4949 (declare-function mh-start-of-uncleaned-message
"mh-show" ())
4950 (defvar mh-show-buffer
)
4953 (defun pr-article-date ()
4954 "Find the date of an article or mail message in current buffer.
4955 Return only the dayname, if present, weekday, month, and year."
4957 (goto-char (point-min))
4958 (if (re-search-forward
4959 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t
)
4960 (buffer-substring (match-beginning 1) (match-end 1))
4961 (format-time-string "%Y/%m/%d"))))
4964 (defun pr-mh-current-message ()
4965 "Go to mh-inbox current message."
4966 (let ((msg (or (mh-get-msg-num nil
) 0)))
4968 (set-buffer mh-show-buffer
)
4969 (goto-char (point-min))
4970 (mh-start-of-uncleaned-message)
4971 (message "Printing message %d" msg
)))
4974 (defun pr-mh-print-1 (n-up filename header-list
)
4975 "Print mh-inbox current message in PostScript."
4977 (save-window-excursion
4978 (pr-mh-current-message)
4979 (pr-mode-print n-up filename header-list
(point)))))
4982 (defun pr-mh-lpr-1 (header-list)
4983 "Print mh-inbox current message in text printer."
4985 (save-window-excursion
4986 (pr-mh-current-message)
4987 (pr-mode-lpr header-list
(point)))))
4990 (defalias 'pr-mh-print-2
'pr-mode-print
)
4993 (defalias 'pr-mh-lpr-2
'pr-mode-lpr
)
4996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4997 ;; rmail (hacked from ps-print.el)
5000 (defun pr-rmail-lpr (header-list)
5001 "Print RMAIL current message in text printer."
5002 (pr-lpr-message-from-summary header-list
5003 'rmail-buffer
'rmail-summary-buffer
))
5006 (defun pr-rmail-print (n-up filename header-list
)
5007 "Print RMAIL current message in PostScript."
5008 (pr-ps-message-from-summary n-up filename header-list
5009 'rmail-buffer
'rmail-summary-buffer
))
5012 (defun pr-ps-message-from-summary (n-up filename header-list
5013 summary-buffer summary-default
)
5014 "Print current message in PostScript."
5015 (let ((buf (or (and (boundp summary-buffer
)
5016 (symbol-value summary-buffer
))
5017 (symbol-value summary-default
))))
5018 (and (get-buffer buf
)
5019 (with-current-buffer buf
5020 (pr-mode-print n-up filename header-list
)))))
5023 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default
)
5024 "Print current message in text printer."
5025 (let ((buf (or (and (boundp summary-buffer
)
5026 (symbol-value summary-buffer
))
5027 (symbol-value summary-default
))))
5028 (and (get-buffer buf
)
5029 (with-current-buffer buf
5030 (pr-mode-lpr header-list
)))))
5033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5034 ;; gnus (hacked from ps-print.el)
5037 (defvar pr-gnus-article
"*Article*")
5040 (defun pr-gnus-print (n-up filename header-list
)
5041 "Print *Article* current message in PostScript."
5042 (pr-ps-message-from-summary n-up filename header-list
5043 'gnus-article-buffer
'pr-gnus-article
))
5046 (defun pr-gnus-lpr (header-list)
5047 "Print *Article* current message in text printer."
5048 (pr-lpr-message-from-summary header-list
5049 'gnus-article-buffer
'pr-gnus-article
))
5052 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5053 ;; vm (hacked from ps-print.el)
5056 (defvar pr-vm-summary
"")
5059 (defun pr-vm-print (n-up filename header-list
)
5060 "Print current vm message in PostScript."
5061 (pr-ps-message-from-summary n-up filename header-list
5062 'vm-mail-buffer
'pr-vm-summary
))
5065 (defun pr-vm-lpr (header-list)
5066 "Print current vm message in text printer."
5067 (pr-lpr-message-from-summary header-list
5068 'vm-mail-buffer
'pr-vm-summary
))
5071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5075 (defun pr-ps-mode (n-up filename
)
5076 "If current major mode is declared, print it in PostScript."
5077 (let ((args (pr-mode-alist-p)))
5079 (let ((fun (cdr args
)))
5080 (funcall (car fun
) n-up filename
(cdr fun
))
5083 (message "`%s' major mode not declared." major-mode
)
5087 (defmacro pr-local-variable
(header-list &rest body
)
5089 (let ((ps-header-lines (or (nth 0 ,header-list
) ps-header-lines
))
5090 (ps-left-header (or (nth 1 ,header-list
) ps-left-header
))
5091 (ps-right-header (or (nth 2 ,header-list
) ps-right-header
))
5093 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list
))))
5095 (and (nth 3 ,header-list
)
5096 (pr-kill-local-variable local-var-list
))))))
5099 (defun pr-mode-print (n-up filename header-list
&optional from to
)
5100 "Print current major mode in PostScript."
5103 (let ((file (pr-ps-file filename
))
5105 ((pr-region-active-p) (region-beginning))
5108 (pr-text2ps (pr-region-active-symbol start
) n-up file start
5110 ((pr-region-active-p) (region-end))
5113 (unless (or pr-spool-p filename
)
5114 (pr-ps-file-print file
)
5115 (pr-delete-file file
)))))
5118 (defun pr-mode-lpr (header-list &optional from to
)
5119 "Print current major mode in text printer."
5122 (pr-txt-print (cond (from)
5123 ((pr-region-active-p) (region-beginning))
5126 ((pr-region-active-p) (region-end))
5130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5134 (defconst pr-menu-entry-alist
5137 (postscript-options .
9)
5138 (postscript-process .
3)
5142 "Alist that associates menu part with number of items per part.
5144 It's used by `pr-menu-index'.
5146 Each element has the form:
5148 (MENU-PART . NUMBER-OF-ITEMS)
5150 See `pr-visible-entry-alist'.")
5153 (defun pr-menu-index (entry index
)
5155 (cond ((eq entry
'text
)
5157 ((eq entry
'postscript-options
)
5159 ((eq entry
'postscript-process
)
5160 '(postscript text postscript-options
))
5161 ((eq entry
'printing
)
5162 '(postscript text postscript-options postscript-process
))
5168 (setq key
(car base-list
)
5169 base-list
(cdr base-list
))
5170 (and (pr-visible-p key
)
5171 (setq index
(+ index
5172 (cdr (assq key pr-menu-entry-alist
)))))))
5176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5177 ;; Printer & Utility Selection
5180 (defun pr-update-var (var-sym alist
)
5181 (or (assq (symbol-value var-sym
) alist
)
5182 (set var-sym
(car (car alist
)))))
5185 (defun pr-update-menus (&optional force
)
5186 "Update utility, PostScript and text printer menus.
5188 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
5189 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
5190 otherwise, update PostScript printer menu if `pr-ps-printer-menu-modified' is
5191 non-nil, update text printer menu if `pr-txt-printer-menu-modified' is
5192 non-nil, and update PostScript File menus if `pr-ps-utility-menu-modified' is
5195 If menu binding was not done, calls `pr-menu-bind'."
5197 (if pr-menu-print-item
; since v6.8.4
5198 ;; There was no menu binding yet, so do it now!
5199 ;; This is a hack to be compatible with old versions of printing.
5200 ;; So, user does not need to change printing calling in init files.
5202 ;; Here menu binding is ok.
5203 (pr-update-var 'pr-ps-name pr-ps-printer-alist
)
5204 (pr-update-var 'pr-txt-name pr-txt-printer-alist
)
5205 (pr-update-var 'pr-ps-utility pr-ps-utility-alist
)
5206 (pr-do-update-menus force
)))
5209 (defun pr-menu-create (name alist var-sym fun entry index
)
5213 (let ((sym (car elt
)))
5216 (list fun
(list 'quote sym
) nil
(list 'quote entry
) index
)
5218 :selected
(list 'eq var-sym
(list 'quote sym
)))))
5222 (defun pr-ps-set-utility (value)
5223 (let ((item (cdr (assq value pr-ps-utility-alist
))))
5226 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
5228 (setq pr-ps-utility value
)
5229 (pr-eval-alist (nthcdr 9 item
)))
5230 (pr-update-mode-line))
5233 (defun pr-ps-set-printer (value)
5234 (let ((ps (cdr (assq value pr-ps-printer-alist
))))
5237 "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
5239 (setq pr-ps-name value
5240 pr-ps-command
(pr-dosify-file-name (nth 0 ps
))
5241 pr-ps-switches
(nth 1 ps
)
5242 pr-ps-printer-switch
(nth 2 ps
)
5243 pr-ps-printer
(nth 3 ps
))
5244 (or (stringp pr-ps-command
)
5246 (cond (lpr-windows-system "print")
5247 (lpr-lp-system "lp")
5250 (or (stringp pr-ps-printer-switch
)
5251 (setq pr-ps-printer-switch
5252 (cond (lpr-windows-system "/D:")
5253 (lpr-lp-system "-d")
5256 (pr-eval-alist (nthcdr 4 ps
)))
5257 (pr-update-mode-line))
5260 (defun pr-txt-set-printer (value)
5261 (let ((txt (cdr (assq value pr-txt-printer-alist
))))
5263 (error "Invalid text printer name `%s' for variable `pr-txt-name'"
5265 (setq pr-txt-name value
5266 pr-txt-command
(pr-dosify-file-name (nth 0 txt
))
5267 pr-txt-switches
(nth 1 txt
)
5268 pr-txt-printer
(nth 2 txt
)))
5269 (or (stringp pr-txt-command
)
5270 (setq pr-txt-command
5271 (cond (lpr-windows-system "print")
5272 (lpr-lp-system "lp")
5275 (pr-update-mode-line))
5278 (defun pr-eval-alist (alist)
5279 (mapcar #'(lambda (option)
5280 (let ((var-sym (car option
))
5281 (value (cdr option
)))
5282 (if (eq var-sym
'inherits-from
:)
5283 (pr-eval-setting-alist value
'global
)
5284 (set var-sym
(eval value
)))))
5288 (defun pr-eval-local-alist (alist)
5290 (mapc #'(lambda (option)
5291 (let ((var-sym (car option
))
5292 (value (cdr option
)))
5294 (if (eq var-sym
'inherits-from
:)
5295 (nconc (pr-eval-setting-alist value
) local-list
)
5296 (set (make-local-variable var-sym
) (eval value
))
5297 (cons var-sym local-list
)))))
5302 (defun pr-eval-setting-alist (key &optional global old
)
5303 (let ((setting (cdr (assq key pr-setting-database
))))
5305 (let ((inherits (nth 0 setting
))
5306 (local (nth 1 setting
))
5307 (kill (nth 2 setting
))
5312 (message "There are local buffer settings for `%S'." key
)
5315 (if (memq inherits old
)
5316 (error "Circular inheritance for `%S'" inherits
)
5318 (pr-eval-setting-alist inherits global
5319 (cons inherits old
)))))
5321 (cond ((not local
) ; global settings
5323 (let ((var-sym (car option
)))
5324 (or (eq var-sym
'inherits-from
:)
5325 (set var-sym
(eval (cdr option
)))))))
5326 (kill ; local settings with killing
5328 (let ((var-sym (car option
)))
5329 (unless (eq var-sym
'inherits-from
:)
5330 (setq local-list
(cons var-sym local-list
))
5331 (set (make-local-variable var-sym
)
5332 (eval (cdr option
)))))))
5333 (t ; local settings without killing
5335 (let ((var-sym (car option
)))
5336 (or (eq var-sym
'inherits-from
:)
5337 (set (make-local-variable var-sym
)
5338 (eval (cdr option
))))))))
5343 (defun pr-kill-local-variable (local-var-list)
5344 (mapcar 'kill-local-variable local-var-list
))
5347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5348 ;; Internal Functions (II)
5351 (defun pr-toggle (var-sym mess entry index horizontal state
5352 &optional path no-menu
)
5353 (set var-sym
(not (symbol-value var-sym
)))
5354 (message "%s is %s" mess
(if (symbol-value var-sym
) "on" "off"))
5356 (pr-menu-lock entry index horizontal state path
)))
5359 (defun pr-toggle-file-duplex-menu (&optional no-menu
)
5360 "Toggle whether to print PostScript files in duplex mode."
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 "Toggle whether to print PostScript files in tumble mode."
5369 (pr-toggle 'pr-file-tumble
"PS file tumble" nil
8 5 nil
5370 '("PostScript Print" "File") no-menu
))
5373 (defun pr-toggle-file-landscape-menu (&optional no-menu
)
5374 "Toggle whether to print PostScript files in landscape orientation."
5376 (pr-toggle 'pr-file-landscape
"PS file landscape" nil
6 5 nil
5377 '("PostScript Print" "File") no-menu
))
5380 (defun pr-toggle-ghostscript-menu (&optional no-menu
)
5381 "Toggle whether to print using ghostscript."
5383 (pr-toggle 'pr-print-using-ghostscript
"Printing using ghostscript"
5384 'postscript-process
2 12 'toggle nil no-menu
))
5387 (defun pr-toggle-faces-menu (&optional no-menu
)
5388 "Toggle whether to print with face attributes."
5390 (pr-toggle 'pr-faces-p
"Printing with faces"
5391 'postscript-process
1 12 'toggle nil no-menu
))
5394 (defun pr-toggle-spool-menu (&optional no-menu
)
5395 "Toggle whether to spool printing in a buffer."
5397 (pr-toggle 'pr-spool-p
"Spooling printing"
5398 'postscript-process
0 12 'toggle nil no-menu
))
5401 (defun pr-toggle-duplex-menu (&optional no-menu
)
5402 "Toggle whether to generate PostScript for a two-sided printer."
5404 (pr-toggle 'ps-spool-duplex
"Printing duplex"
5405 'postscript-options
5 12 'toggle nil no-menu
))
5408 (defun pr-toggle-tumble-menu (&optional no-menu
)
5409 "Toggle how pages on opposite sides of a sheet are oriented."
5411 (pr-toggle 'ps-spool-tumble
"Tumble"
5412 'postscript-options
6 12 'toggle nil no-menu
))
5415 (defun pr-toggle-landscape-menu (&optional no-menu
)
5416 "Toggle whether to print in landscape mode."
5418 (pr-toggle 'ps-landscape-mode
"Landscape"
5419 'postscript-options
0 12 'toggle nil no-menu
))
5422 (defun pr-toggle-upside-down-menu (&optional no-menu
)
5423 "Toggle whether to print upside-down (that is, rotated by 180 degrees)."
5425 (pr-toggle 'ps-print-upside-down
"Upside-Down"
5426 'postscript-options
7 12 'toggle nil no-menu
))
5429 (defun pr-toggle-line-menu (&optional no-menu
)
5430 "Toggle whether to means print line numbers."
5432 (pr-toggle 'ps-line-number
"Line number"
5433 'postscript-options
3 12 'toggle nil no-menu
))
5436 (defun pr-toggle-zebra-menu (&optional no-menu
)
5437 "Toggle whether to print zebra stripes."
5439 (pr-toggle 'ps-zebra-stripes
"Zebra stripe"
5440 'postscript-options
4 12 'toggle nil no-menu
))
5443 (defun pr-toggle-header-menu (&optional no-menu
)
5444 "Toggle whether to print a header at the top of each page."
5446 (pr-toggle 'ps-print-header
"Print header"
5447 'postscript-options
1 12 'toggle nil no-menu
))
5450 (defun pr-toggle-header-frame-menu (&optional no-menu
)
5451 "Toggle whether to draw a gaudy frame around the header."
5453 (pr-toggle 'ps-print-header-frame
"Print header frame"
5454 'postscript-options
2 12 'toggle nil no-menu
))
5457 (defun pr-toggle-lock-menu (&optional no-menu
)
5458 "Toggle whether the menu is locked while selecting toggle options."
5460 (pr-toggle 'pr-menu-lock
"Menu lock"
5461 'printing
2 12 'toggle nil no-menu
))
5464 (defun pr-toggle-region-menu (&optional no-menu
)
5465 "Toggle whether the region is automagically detected."
5467 (pr-toggle 'pr-auto-region
"Auto region"
5468 'printing
0 12 'toggle nil no-menu
))
5471 (defun pr-toggle-mode-menu (&optional no-menu
)
5472 "Toggle whether major-mode specific printing is preferred over normal printing."
5474 (pr-toggle 'pr-auto-mode
"Auto mode"
5475 'printing
1 12 'toggle nil no-menu
))
5478 (defun pr-prompt (str)
5479 (if (pr-auto-mode-p)
5480 (concat str
" mode")
5481 (pr-region-active-string str
)))
5484 (defun pr-prompt-region (str)
5485 (concat str
(if (pr-auto-mode-p)
5490 (defun pr-prompt-gs (str)
5491 (if (pr-using-ghostscript-p)
5496 (defun pr-region-active-symbol (&optional region-p
)
5497 (if (or region-p
(pr-region-active-p))
5502 (defun pr-region-active-string (prefix)
5504 (if (pr-region-active-p)
5509 (defun pr-show-setup (settings buffer-name
)
5510 (with-output-to-temp-buffer buffer-name
5512 (help-print-return-message)))
5515 (defun pr-complete-alist (prompt alist default
)
5516 (let ((collection (mapcar #'(lambda (elt)
5517 (setq elt
(car elt
))
5518 (cons (symbol-name elt
) elt
))
5520 (cdr (assoc (completing-read (concat prompt
": ")
5522 (symbol-name default
) nil
5523 (symbol-name default
))
5527 (defun pr-delete-file (file)
5528 (and pr-delete-temp-file
(file-exists-p file
)
5529 (delete-file file
)))
5532 (defun pr-expand-file-name (filename)
5533 (pr-dosify-file-name (expand-file-name filename
)))
5536 (defun pr-ps-outfile-preprint (&optional mess
)
5537 (let* ((prompt (format "%soutput PostScript file name: " (or mess
"")))
5538 (res (read-file-name prompt default-directory
"" nil
)))
5539 (while (cond ((not (file-writable-p res
))
5541 (setq prompt
"is unwritable"))
5542 ((file-directory-p res
)
5544 (setq prompt
"is a directory"))
5545 ((file-exists-p res
)
5547 (setq prompt
"exists")
5548 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5551 (setq res
(read-file-name
5552 (format "File %s; PostScript file: " prompt
)
5553 (file-name-directory res
) nil nil
5554 (file-name-nondirectory res
))))
5555 (pr-expand-file-name res
)))
5558 (defun pr-ps-infile-preprint (&optional mess
)
5559 (let* ((prompt (format "%sinput PostScript file name: " (or mess
"")))
5560 (res (read-file-name prompt default-directory
"" nil
)))
5561 (while (cond ((not (file-exists-p res
))
5563 (setq prompt
"doesn't exist"))
5564 ((not (file-readable-p res
))
5566 (setq prompt
"is unreadable"))
5567 ((file-directory-p res
)
5569 (setq prompt
"is a directory"))
5571 (setq res
(read-file-name
5572 (format "File %s; PostScript file: " prompt
)
5573 (file-name-directory res
) nil nil
5574 (file-name-nondirectory res
))))
5575 (pr-expand-file-name res
)))
5578 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt
)
5579 ;; check arguments for PostScript file processing.
5581 (or (symbol-value n-up-sym
)
5582 (set n-up-sym
(pr-interactive-n-up prompt
)))
5584 (and (eq (symbol-value infile-sym
) t
)
5585 (set infile-sym
(pr-ps-infile-preprint prompt
)))
5586 (or (symbol-value infile-sym
)
5587 (error "%s: input PostScript file name is missing" prompt
))
5588 (set infile-sym
(pr-dosify-file-name (symbol-value infile-sym
)))
5590 (and (eq (symbol-value outfile-sym
) t
)
5591 (set outfile-sym
(and current-prefix-arg
5592 (pr-ps-outfile-preprint prompt
))))
5593 (and (symbol-value outfile-sym
)
5594 (set outfile-sym
(pr-dosify-file-name (symbol-value outfile-sym
))))
5595 (pr-ps-file (symbol-value outfile-sym
)))
5598 (defun pr-ps-utility-process (n-up infile outfile
)
5599 ;; activate utility to process a PostScript file.
5601 (and (stringp infile
) (file-exists-p infile
)
5602 (setq item
(cdr (assq pr-ps-utility pr-ps-utility-alist
)))
5603 (pr-call-process (nth 0 item
)
5604 (pr-switches-string (nth 1 item
)
5605 "pr-ps-utility-alist entry")
5606 (pr-switches-string (nth 8 item
)
5607 "pr-ps-utility-alist entry")
5609 (format (nth 2 item
) ps-paper-type
))
5610 (format (nth 3 item
) n-up
)
5611 (and pr-file-landscape
(nth 4 item
))
5612 (and pr-file-duplex
(nth 5 item
))
5613 (and pr-file-tumble
(nth 6 item
))
5614 (pr-expand-file-name infile
)
5616 (pr-expand-file-name outfile
)))))
5619 (defun pr-remove-nil-from-list (lst)
5620 (while (and lst
(null (car lst
)))
5621 (setq lst
(cdr lst
)))
5633 (defun pr-call-process (command &rest args
)
5634 (let ((buffer (get-buffer-create "*Printing Command Output*"))
5635 (cmd (pr-command command
))
5637 (setq args
(pr-remove-nil-from-list args
))
5638 ;; *Printing Command Output* == show command & args
5639 (with-current-buffer buffer
5640 (goto-char (point-max))
5641 (insert (format "%s %S\n" cmd args
)))
5642 ;; *Printing Command Output* == show any return message from command
5645 (condition-case data
5646 (apply 'call-process cmd nil buffer nil args
)
5648 (error-message-string data
)))))
5649 ;; *Printing Command Output* == show exit status
5650 (with-current-buffer buffer
5651 (goto-char (point-max))
5652 (insert (format "Exit status: %s\n\n" status
)))
5653 ;; message if error status
5654 (if (or (stringp status
)
5655 (and (integerp status
) (/= status
0)))
5657 "Printing error status: %s (see *Printing Command Output* buffer)"
5661 (defun pr-txt-print (from to
)
5662 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command
)))
5663 (lpr-switches (pr-switches pr-txt-switches
"pr-txt-switches"))
5664 (printer-name pr-txt-printer
))
5665 (lpr-region from to
)))
5668 (defun pr-switches-string (switches mess
)
5669 ;; If SWITCHES is nil, return nil.
5670 ;; Otherwise, return the list of string in a string.
5672 (mapconcat 'identity
(pr-switches switches mess
) " ")))
5675 (defun pr-switches (switches mess
)
5676 (or (listp switches
)
5677 (error "%S should have a list of strings" mess
))
5678 (lpr-flatten-list ; dynamic evaluation
5679 (mapcar 'ps-eval-switch switches
)))
5682 (defun pr-ps-preview (kind n-up filename mess
)
5683 (pr-set-n-up-and-filename 'n-up
'filename mess
)
5684 (let ((file (pr-ps-file filename
)))
5685 (pr-text2ps kind n-up file
)
5686 (or pr-spool-p
(pr-ps-file-preview file
))))
5689 (defun pr-ps-using-ghostscript (kind n-up filename mess
)
5690 (pr-set-n-up-and-filename 'n-up
'filename mess
)
5691 (let ((file (pr-ps-file filename
)))
5692 (pr-text2ps kind n-up file
)
5693 (unless (or pr-spool-p filename
)
5694 (pr-ps-file-using-ghostscript file
)
5695 (pr-delete-file file
))))
5698 (defun pr-ps-print (kind n-up filename mess
)
5699 (pr-set-n-up-and-filename 'n-up
'filename mess
)
5700 (let ((file (pr-ps-file filename
)))
5701 (pr-text2ps kind n-up file
)
5702 (unless (or pr-spool-p filename
)
5703 (pr-ps-file-print file
)
5704 (pr-delete-file file
))))
5707 (defun pr-ps-file (&optional filename
)
5708 (pr-dosify-file-name (or filename
5710 (convert-standard-filename
5711 (expand-file-name pr-ps-temp-file pr-temp-dir
))
5715 (defun pr-interactive-n-up (mess)
5716 (or (stringp mess
) (setq mess
"*"))
5718 (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
5720 (str (pr-read-string (format fmt-prompt prompt mess
) "1" nil
"1"))
5722 (while (if (string-match "^\\s *[0-9]+$" str
)
5723 (setq int
(string-to-number str
)
5724 prompt
(cond ((< int
1) "Integer below 1; ")
5725 ((> int
100) "Integer above 100; ")
5727 (setq prompt
"Invalid integer syntax; "))
5730 (pr-read-string (format fmt-prompt prompt mess
) str nil
"1")))
5734 (defun pr-interactive-dir (mess)
5735 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5736 default-directory
)))
5737 (fmt-prompt (concat "%s[" mess
"] Directory to print: "))
5738 (dir (read-directory-name (format fmt-prompt
"")
5739 "" dir-name nil dir-name
))
5741 (while (cond ((not (file-directory-p dir
))
5743 (setq prompt
"It's not a directory! "))
5744 ((not (file-readable-p dir
))
5746 (setq prompt
"Directory is unreadable! "))
5748 (setq dir-name
(file-name-directory dir
)
5749 dir
(read-directory-name (format fmt-prompt prompt
)
5750 "" dir-name nil dir-name
)))
5751 (file-name-as-directory dir
)))
5754 (defun pr-interactive-regexp (mess)
5755 (pr-read-string (format "[%s] File regexp to print: " mess
) "" nil
""))
5758 (defun pr-interactive-dir-args (mess)
5760 ;; get directory argument
5761 (pr-interactive-dir mess
)
5762 ;; get file name regexp
5763 (pr-interactive-regexp mess
)))
5766 (defun pr-interactive-ps-dir-args (mess)
5768 ;; get n-up argument
5769 (pr-interactive-n-up mess
)
5770 ;; get directory argument
5771 (pr-interactive-dir mess
)
5772 ;; get file name regexp
5773 (pr-interactive-regexp mess
)
5774 ;; get output file name
5775 (and (not pr-spool-p
)
5776 (ps-print-preprint current-prefix-arg
))))
5779 (defun pr-interactive-n-up-file (mess)
5781 ;; get n-up argument
5782 (pr-interactive-n-up mess
)
5783 ;; get output file name
5784 (and (not pr-spool-p
)
5785 (ps-print-preprint current-prefix-arg
))))
5788 (defun pr-interactive-n-up-inout (mess)
5790 ;; get n-up argument
5791 (pr-interactive-n-up mess
)
5792 ;; get input file name
5793 (pr-ps-infile-preprint (concat mess
" "))
5794 ;; get output file name
5795 (ps-print-preprint current-prefix-arg
)))
5798 (defun pr-set-outfilename (filename-sym)
5799 (and (not pr-spool-p
)
5800 (eq (symbol-value filename-sym
) t
)
5801 (set filename-sym
(and current-prefix-arg
5802 (ps-print-preprint current-prefix-arg
))))
5803 (and (symbol-value filename-sym
)
5804 (set filename-sym
(pr-dosify-file-name (symbol-value filename-sym
)))))
5807 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess
)
5809 (or (symbol-value n-up-sym
)
5810 (set n-up-sym
(pr-interactive-n-up mess
)))
5812 (pr-set-outfilename filename-sym
))
5815 (defun pr-set-dir-args (dir-sym regexp-sym mess
)
5817 (or (symbol-value dir-sym
)
5818 (set dir-sym
(pr-interactive-dir mess
)))
5820 (or (symbol-value regexp-sym
)
5821 (set regexp-sym
(pr-interactive-regexp mess
))))
5824 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess
)
5826 (or (symbol-value n-up-sym
)
5827 (set n-up-sym
(pr-interactive-n-up mess
)))
5828 ;; directory & file name regexp
5829 (pr-set-dir-args dir-sym regexp-sym mess
)
5831 (pr-set-outfilename filename-sym
))
5834 (defun pr-find-buffer-visiting (file)
5835 (if (not (file-directory-p file
))
5836 (find-buffer-visiting (if lpr-windows-system
5839 (let ((truename (file-truename file
))
5840 (blist (buffer-list))
5842 (while (and (not found
) blist
)
5843 (with-current-buffer (car blist
)
5844 (and (eq major-mode
'dired-mode
)
5846 (goto-char (point-min))
5847 (string= (buffer-substring-no-properties
5853 (setq found
(car blist
))))
5854 (setq blist
(cdr blist
)))
5858 (defun pr-file-list (dir file-regexp fun
)
5859 (mapcar #'(lambda (file)
5860 (and (or pr-list-directory
5861 (not (file-directory-p file
)))
5862 (let ((buffer (pr-find-buffer-visiting file
))
5866 (file-readable-p file
))
5867 (with-current-buffer (or buffer
5868 (find-file-noselect file
))
5871 (kill-buffer (current-buffer))))))))
5872 (directory-files dir t file-regexp
)))
5875 (defun pr-delete-file-if-exists (filename)
5876 (and (not pr-spool-p
) (stringp filename
) (file-exists-p filename
)
5877 (delete-file filename
)))
5880 (defun pr-ps-file-list (n-up dir file-regexp filename
)
5881 (pr-delete-file-if-exists (setq filename
(pr-expand-file-name filename
)))
5882 (let ((pr-spool-p t
))
5883 (pr-file-list dir file-regexp
5885 (if (pr-auto-mode-p)
5886 (pr-ps-mode n-up filename
)
5887 (pr-text2ps 'buffer n-up filename
)))))
5889 (pr-despool-print filename
)))
5892 (defun pr-text2ps (kind n-up filename
&optional from to
)
5894 (let ((ps-n-up-printing n-up
)
5895 (ps-spool-config (and (eq ps-spool-config
'setpagedevice
)
5897 (pr-delete-file-if-exists filename
)
5900 ;; pr-faces-p and pr-spool-p
5901 ;; here FILENAME arg is ignored
5902 (cond ((eq kind
'buffer
)
5903 (ps-spool-buffer-with-faces))
5905 (ps-spool-region-with-faces (or from
(point))
5908 ;; pr-faces-p and not pr-spool-p
5910 (ps-print-buffer-with-faces filename
))
5912 (ps-print-region-with-faces (or from
(point))
5913 (or to
(mark)) filename
))
5916 ;; not pr-faces-p and pr-spool-p
5917 ;; here FILENAME arg is ignored
5918 (cond ((eq kind
'buffer
)
5921 (ps-spool-region (or from
(point)) (or to
(mark))))
5923 ;; not pr-faces-p and not pr-spool-p
5925 (ps-print-buffer filename
))
5927 (ps-print-region (or from
(point)) (or to
(mark)) filename
))
5931 (defun pr-command (command)
5932 "Return absolute file name specification for COMMAND.
5934 If COMMAND is an empty string, return it.
5936 If COMMAND is already an absolute file name specification, return it.
5937 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5938 otherwise, gives an error.
5940 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5941 `unix' are used (see `pr-path-alist' for documentation).
5943 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5944 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5945 (if (string= command
"")
5947 (pr-dosify-file-name
5948 (or (pr-find-command command
)
5949 (pr-path-command (cond (pr-cygwin-system 'cygwin
)
5950 (lpr-windows-system 'windows
)
5952 (file-name-nondirectory command
)
5954 (error "Command not found: %s"
5955 (file-name-nondirectory command
))))))
5958 (defun pr-path-command (symbol command sym-list
)
5959 (let ((lpath (cdr (assq symbol pr-path-alist
)))
5962 (and (eq symbol
'PATH
) (null lpath
)
5963 (setq lpath
(parse-colon-path (getenv "PATH"))))
5967 (let ((path (car lpath
)))
5971 (and (not (memq path sym-list
))
5972 (pr-path-command path command
5973 (cons path sym-list
))))
5978 (substitute-in-file-name
5979 (concat (file-name-as-directory path
)
5982 (setq lpath
(cdr lpath
)))
5986 (defun pr-find-command (cmd)
5987 (if lpr-windows-system
5989 (let ((ext (cons (file-name-extension cmd t
)
5990 (list ".exe" ".bat" ".com")))
5992 (setq cmd
(file-name-sans-extension cmd
))
5994 (setq found
(concat cmd
(car ext
)))
5995 (not (and (file-regular-p found
)
5996 (file-executable-p found
))))
6000 ;; non-windows systems
6001 (and (file-regular-p cmd
)
6002 (file-executable-p cmd
)
6006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6007 ;; Printing Interface (inspired by ps-print-interface.el)
6016 (defvar pr-i-window-configuration nil
)
6018 (defvar pr-i-buffer nil
)
6019 (defvar pr-i-region nil
)
6020 (defvar pr-i-mode nil
)
6021 (defvar pr-i-despool nil
)
6022 (defvar pr-i-ps-as-is t
)
6023 (defvar pr-i-n-up
1)
6024 (defvar pr-i-directory
"./")
6025 (defvar pr-i-regexp
"")
6026 (defvar pr-i-ps-file
"")
6027 (defvar pr-i-out-file
"")
6028 (defvar pr-i-answer-yes nil
)
6029 (defvar pr-i-process
'buffer
)
6030 (defvar pr-i-ps-send
'printer
)
6033 (defvar pr-interface-map nil
6034 "Keymap for pr-interface.")
6036 (unless pr-interface-map
6037 (let ((map (make-sparse-keymap)))
6038 (cond ((featurep 'xemacs
) ; XEmacs
6039 (pr-set-keymap-parents map
(list widget-keymap
))
6040 (pr-set-keymap-name map
'pr-interface-map
))
6042 (pr-set-keymap-parents map widget-keymap
)))
6043 (define-key map
"q" 'pr-interface-quit
)
6044 (define-key map
"?" 'pr-interface-help
)
6045 (setq pr-interface-map map
)))
6048 (defmacro pr-interface-save
(&rest body
)
6049 `(with-current-buffer pr-i-buffer
6053 (defun pr-create-interface ()
6054 "Create the front end for printing package."
6055 (setq pr-i-buffer
(buffer-name (current-buffer))
6056 pr-i-region
(ps-mark-active-p)
6057 pr-i-mode
(pr-mode-alist-p)
6058 pr-i-window-configuration
(current-window-configuration))
6060 (put 'pr-i-process
'pr-widget-list nil
)
6061 (put 'pr-i-ps-send
'pr-widget-list nil
)
6063 (delete-other-windows)
6064 (kill-buffer (get-buffer-create pr-buffer-name
))
6065 (switch-to-buffer (get-buffer-create pr-buffer-name
))
6068 (let ((versions (concat "printing v" pr-version
6069 " ps-print v" ps-print-version
)))
6070 ;; to keep compatibility with Emacs 20 & 21:
6071 ;; DO NOT REPLACE `?\ ' BY `?\s'
6072 (widget-insert (make-string (- 79 (length versions
)) ?\
) versions
))
6073 (pr-insert-italic "\nCurrent Directory : " 1)
6074 (pr-insert-italic default-directory
)
6076 (pr-insert-section-1) ; 1. Print
6077 (pr-insert-section-2) ; 2. PostScript Printer
6078 (pr-insert-section-3) ; 3. Text Printer
6081 (widget-insert "\n\n " (make-string 77 ?-
))
6083 (pr-insert-section-4) ; 4. Settings
6084 (pr-insert-section-5) ; 5. Customize
6085 (pr-insert-section-6) ; 6. Show Settings
6086 (pr-insert-section-7) ; 7. Help
6088 (use-local-map pr-interface-map
)
6090 (goto-char (point-min))
6092 (and pr-i-region
; let region activated
6093 (pr-keep-region-active)))
6095 (declare-function widget-field-action
"wid-edit" (widget &optional _event
))
6096 (declare-function widget-value-set
"wid-edit" (widget value
))
6098 (defun pr-insert-section-1 ()
6100 (pr-insert-italic "\nPrint :" 1)
6103 ;; 1a. Buffer: Buffer List
6104 (pr-insert-radio-button 'pr-i-process
'buffer
)
6105 (pr-insert-menu "Buffer List" 'pr-i-buffer
6106 (let ((blist (buffer-list))
6107 case-fold-search choices
)
6109 (let ((name (buffer-name (car blist
)))
6110 (ignore pr-buffer-name-ignore
)
6112 (setq blist
(cdr blist
))
6113 (while (and ignore
(not found
))
6114 (setq found
(string-match (car ignore
) name
)
6115 ignore
(cdr ignore
)))
6127 (setq pr-i-region
(ps-mark-active-p)
6128 pr-i-mode
(pr-mode-alist-p)))
6129 (pr-update-checkbox 'pr-i-region
)
6130 (pr-update-checkbox 'pr-i-mode
)))
6131 ;; 1a. Buffer: Region
6132 (put 'pr-i-region
'pr-widget
6136 #'(lambda (widget &rest _ignore
)
6137 (let ((region-p (pr-interface-save
6138 (ps-mark-active-p))))
6139 (cond ((null (widget-value widget
)) ; widget is nil
6140 (setq pr-i-region nil
))
6141 (region-p ; widget is true and there is a region
6142 (setq pr-i-region t
)
6143 (widget-value-set widget t
)
6144 (widget-setup)) ; MUST be called after widget-value-set
6145 (t ; widget is true and there is no region
6147 (message "There is no region active")
6148 (setq pr-i-region nil
)
6149 (widget-value-set widget nil
)
6150 (widget-setup))))) ; MUST be called after widget-value-set
6153 (put 'pr-i-mode
'pr-widget
6157 #'(lambda (widget &rest _ignore
)
6158 (let ((mode-p (pr-interface-save
6159 (pr-mode-alist-p))))
6161 ((null (widget-value widget
)) ; widget is nil
6162 (setq pr-i-mode nil
))
6163 (mode-p ; widget is true and there is a `mode'
6165 (widget-value-set widget t
)
6166 (widget-setup)) ; MUST be called after widget-value-set
6167 (t ; widget is true and there is no `mode'
6170 "This buffer isn't in a mode that printing treats specially.")
6171 (setq pr-i-mode nil
)
6172 (widget-value-set widget nil
)
6173 (widget-setup))))) ; MUST be called after widget-value-set
6177 (pr-insert-radio-button 'pr-i-process
'directory
)
6181 :format
" Directory : %v"
6182 :notify
'pr-interface-directory
6183 :action
(lambda (widget &optional event
)
6184 (if (pr-interface-directory widget
)
6185 (pr-widget-field-action widget event
)
6187 (message "Please specify a readable directory")))
6189 ;; 1b. Directory: File Regexp
6190 (widget-create 'regexp
6192 :format
"\n File Regexp : %v\n"
6193 :notify
(lambda (widget &rest _ignore
)
6194 (setq pr-i-regexp
(widget-value widget
)))
6196 ;; 1b. Directory: List Directory Entry
6198 (pr-insert-toggle 'pr-list-directory
" List Directory Entry\n")
6200 ;; 1c. PostScript File:
6201 (pr-insert-radio-button 'pr-i-process
'file
)
6205 :format
" PostScript File : %v"
6206 :notify
'pr-interface-infile
6207 :action
(lambda (widget &rest event
)
6208 (if (pr-interface-infile widget
)
6209 (pr-widget-field-action widget event
)
6211 (message "Please specify a readable PostScript file")))
6213 ;; 1c. PostScript File: PostScript Utility
6214 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
6215 (pr-choice-alist pr-ps-utility-alist
)
6216 "\n PostScript Utility : "
6218 ;; 1c. PostScript File: No Preprocessing
6219 (pr-insert-toggle 'pr-i-ps-as-is
" No Preprocessing"))
6222 (defun pr-insert-section-2 ()
6223 ;; 2. PostScript Printer:
6224 ;; 2. PostScript Printer: PostScript Printer List
6225 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
6226 (pr-insert-menu "PostScript Printer" 'pr-ps-name
6227 (pr-choice-alist pr-ps-printer-alist
))
6228 ;; 2. PostScript Printer: Despool
6229 (put 'pr-i-despool
'pr-widget
6233 #'(lambda (widget &rest _ignore
)
6235 (setq pr-i-despool
(not pr-i-despool
))
6237 (message "Can despool only when spooling is actually selected")
6238 (setq pr-i-despool nil
))
6239 (widget-value-set widget pr-i-despool
)
6240 (widget-setup)) ; MUST be called after widget-value-set
6242 ;; 2. PostScript Printer: Preview Print Quit
6243 (pr-insert-button 'pr-interface-preview
"Preview" " ")
6244 (pr-insert-button 'pr-interface-ps-print
"Print" " ")
6245 (pr-insert-button 'pr-interface-quit
"Quit")
6246 ;; 2. PostScript Printer: Send to Printer/Temporary File
6247 (pr-insert-radio-button 'pr-i-ps-send
'printer
)
6248 (widget-insert " Send to Printer/Temporary File")
6249 ;; 2. PostScript Printer: Send to File
6250 (pr-insert-radio-button 'pr-i-ps-send
'file
)
6254 :format
" Send to File : %v"
6255 :notify
'pr-interface-outfile
6256 :action
(lambda (widget &rest event
)
6257 (if (and (pr-interface-outfile widget
)
6258 (or (not (file-exists-p pr-i-out-file
))
6259 (setq pr-i-answer-yes
6260 (y-or-n-p "File exists; overwrite? "))))
6261 (pr-widget-field-action widget event
)
6263 (message "Please specify a writable PostScript file")))
6265 ;; 2. PostScript Printer: N-Up
6269 :format
"\n N-Up : %v"
6270 :notify
(lambda (widget &rest _ignore
)
6271 (let ((value (if (string= (widget-apply widget
:value-get
) "")
6273 (widget-value widget
))))
6274 (if (and (integerp value
)
6275 (<= 1 value
) (<= value
100))
6278 (setq pr-i-n-up value
))
6280 (message "Please specify an integer between 1 and 100"))))
6284 (defun pr-insert-section-3 ()
6286 (pr-insert-italic "\n\nText Printer : " 2 14)
6287 (pr-insert-menu "Text Printer" 'pr-txt-name
6288 (pr-choice-alist pr-txt-printer-alist
)
6290 (pr-insert-button 'pr-interface-printify
"Printify" " ")
6291 (pr-insert-button 'pr-interface-txt-print
"Print" " ")
6292 (pr-insert-button 'pr-interface-quit
"Quit"))
6295 (defun pr-insert-section-4 ()
6297 ;; 4. Settings: Landscape Auto Region Verbose
6298 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
6299 #'(lambda (&rest _ignore
)
6300 (setq ps-landscape-mode
(not ps-landscape-mode
)
6301 pr-file-landscape ps-landscape-mode
))
6303 (pr-insert-toggle 'pr-auto-region
" Auto Region ")
6304 (pr-insert-toggle 'pr-buffer-verbose
" Verbose\n ")
6306 ;; 4. Settings: Print Header Auto Mode
6307 (pr-insert-toggle 'ps-print-header
" Print Header ")
6308 (pr-insert-toggle 'pr-auto-mode
" Auto Mode\n ")
6310 ;; 4. Settings: Print Header Frame Menu Lock
6311 (pr-insert-toggle 'ps-print-header-frame
" Print Header Frame ")
6312 (pr-insert-toggle 'pr-menu-lock
" Menu Lock\n ")
6314 ;; 4. Settings: Line Number
6315 (pr-insert-toggle 'ps-line-number
" Line Number\n ")
6317 ;; 4. Settings: Zebra Stripes Spool Buffer
6318 (pr-insert-toggle 'ps-zebra-stripes
" Zebra Stripes")
6319 (pr-insert-checkbox " "
6321 #'(lambda (&rest _ignore
)
6322 (setq pr-spool-p
(not pr-spool-p
))
6324 (setq pr-i-despool nil
)
6325 (pr-update-checkbox 'pr-i-despool
)))
6328 ;; 4. Settings: Duplex Print with faces
6329 (pr-insert-checkbox "\n "
6331 #'(lambda (&rest _ignore
)
6332 (setq ps-spool-duplex
(not ps-spool-duplex
)
6333 pr-file-duplex ps-spool-duplex
))
6335 (pr-insert-toggle 'pr-faces-p
" Print with faces")
6337 ;; 4. Settings: Tumble Print via Ghostscript
6338 (pr-insert-checkbox "\n "
6340 #'(lambda (&rest _ignore
)
6341 (setq ps-spool-tumble
(not ps-spool-tumble
)
6342 pr-file-tumble ps-spool-tumble
))
6344 (pr-insert-toggle 'pr-print-using-ghostscript
" Print via Ghostscript\n ")
6346 ;; 4. Settings: Upside-Down Page Parity
6347 (pr-insert-toggle 'ps-print-upside-down
" Upside-Down")
6348 (pr-insert-italic "\n\nSelect Pages : " 2 14)
6349 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
6350 (mapcar #'(lambda (alist)
6355 :value
(car alist
))))
6356 pr-even-or-odd-alist
)))
6359 (defun pr-insert-section-5 ()
6361 (pr-insert-italic "\n\nCustomize : " 2 11)
6362 (pr-insert-button 'pr-customize
"printing" " ")
6363 (pr-insert-button #'(lambda (&rest _ignore
) (ps-print-customize))
6365 (pr-insert-button 'lpr-customize
"lpr"))
6368 (defun pr-insert-section-6 ()
6369 ;; 6. Show Settings:
6370 (pr-insert-italic "\nShow Settings : " 1 14)
6371 (pr-insert-button 'pr-show-pr-setup
"printing" " ")
6372 (pr-insert-button 'pr-show-ps-setup
"ps-print" " ")
6373 (pr-insert-button 'pr-show-lpr-setup
"lpr"))
6376 (defun pr-insert-section-7 ()
6378 (pr-insert-italic "\nHelp : " 1 5)
6379 (pr-insert-button 'pr-interface-help
"Interface Help" " ")
6380 (pr-insert-button 'pr-help
"Menu Help" " ")
6381 (pr-insert-button 'pr-interface-quit
"Quit" "\n ")
6382 (pr-insert-button 'pr-kill-help
"Kill All Printing Help Buffer"))
6385 (defun pr-kill-help (&rest _ignore
)
6386 "Kill all printing help buffer."
6388 (let ((help '("*Printing Interface Help*" "*Printing Help*"
6389 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
6391 (let ((buffer (get-buffer (car help
))))
6392 (setq help
(cdr help
))
6394 (delete-windows-on buffer
)
6395 (kill-buffer buffer
)))))
6396 (recenter (- (window-height) 2)))
6399 (defun pr-interface-quit (&rest _ignore
)
6400 "Kill the printing buffer interface and quit."
6402 (kill-buffer pr-buffer-name
)
6403 (set-window-configuration pr-i-window-configuration
))
6406 (defun pr-interface-help (&rest _ignore
)
6407 "printing buffer interface help."
6409 (pr-show-setup pr-interface-help-message
"*Printing Interface Help*"))
6412 (defun pr-interface-txt-print (&rest _ignore
)
6413 "Print using lpr package."
6415 (condition-case data
6417 ((eq pr-i-process
'directory
)
6420 (pr-txt-directory pr-i-directory pr-i-regexp
)))
6421 ((eq pr-i-process
'buffer
)
6424 (let ((pr-auto-mode pr-i-mode
))
6427 (let (pr-auto-region)
6430 (let (pr-auto-mode pr-auto-region
)
6433 ((eq pr-i-process
'file
)
6434 (error "Please specify a text file"))
6436 (error "Internal error: `pr-i-process' = %S" pr-i-process
))
6441 (message "%s" (error-message-string data
)))))
6444 (defun pr-interface-printify (&rest _ignore
)
6445 "Printify a buffer."
6447 (condition-case data
6449 ((eq pr-i-process
'directory
)
6452 (pr-printify-directory pr-i-directory pr-i-regexp
)))
6453 ((eq pr-i-process
'buffer
)
6456 (pr-printify-region)
6457 (pr-printify-buffer))))
6458 ((eq pr-i-process
'file
)
6459 (error "Cannot printify a PostScript file"))
6461 (error "Internal error: `pr-i-process' = %S" pr-i-process
))
6466 (message "%s" (error-message-string data
)))))
6469 (defun pr-interface-ps-print (&rest _ignore
)
6470 "Print using ps-print package."
6472 (pr-interface-ps 'pr-despool-ps-print
'pr-ps-directory-ps-print
6473 'pr-ps-file-ps-print
'pr-ps-file-up-ps-print
6474 'pr-ps-region-ps-print
'pr-ps-mode-ps-print
6475 'pr-ps-buffer-ps-print
))
6478 (defun pr-interface-preview (&rest _ignore
)
6479 "Preview a PostScript file."
6481 (pr-interface-ps 'pr-despool-preview
'pr-ps-directory-preview
6482 'pr-ps-file-preview
'pr-ps-file-up-preview
6483 'pr-ps-region-preview
'pr-ps-mode-preview
6484 'pr-ps-buffer-preview
))
6487 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6489 (condition-case data
6490 (let ((outfile (or (and (eq pr-i-process
'file
) pr-i-ps-as-is
)
6493 ((and pr-i-despool pr-spool-p
)
6495 (funcall ps-despool outfile
))
6496 (setq pr-i-despool nil
)
6497 (pr-update-checkbox 'pr-i-despool
))
6498 ((eq pr-i-process
'directory
)
6501 (funcall ps-directory
6502 pr-i-n-up pr-i-directory pr-i-regexp outfile
)))
6503 ((eq pr-i-process
'file
)
6504 (cond ((or (file-directory-p pr-i-ps-file
)
6505 (not (file-readable-p pr-i-ps-file
)))
6506 (error "Please specify a readable PostScript file"))
6509 (funcall ps-file pr-i-ps-file
)))
6512 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile
)))
6514 ((eq pr-i-process
'buffer
)
6517 (let ((pr-auto-mode pr-i-mode
))
6518 (funcall ps-region pr-i-n-up outfile
)))
6520 (let (pr-auto-region)
6521 (funcall ps-mode pr-i-n-up outfile
)))
6523 (let (pr-auto-mode pr-auto-region
)
6524 (funcall ps-buffer pr-i-n-up outfile
)))
6527 (error "Internal error: `pr-i-process' = %S" pr-i-process
))
6532 (message "%s" (error-message-string data
)))))
6535 (defun pr-i-ps-send ()
6536 (cond ((eq pr-i-ps-send
'printer
)
6538 ((not (eq pr-i-ps-send
'file
))
6539 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send
))
6540 ((or (file-directory-p pr-i-out-file
)
6541 (not (file-writable-p pr-i-out-file
)))
6542 (error "Please specify a writable PostScript file"))
6543 ((or (not (file-exists-p pr-i-out-file
))
6545 (setq pr-i-answer-yes
6546 (y-or-n-p (format "File `%s' exists; overwrite? "
6550 (error "File already exists"))))
6553 (defun pr-i-directory ()
6554 (or (file-accessible-directory-p pr-i-directory
)
6555 (error "Please specify be a readable directory")))
6558 (defun pr-interface-directory (widget &rest _ignore
)
6559 (and pr-buffer-verbose
6560 (message "You can use M-TAB or ESC TAB for file completion"))
6561 (let ((dir (widget-value widget
)))
6562 (and (file-accessible-directory-p dir
)
6563 (setq pr-i-directory dir
))))
6566 (defun pr-interface-infile (widget &rest _ignore
)
6567 (and pr-buffer-verbose
6568 (message "You can use M-TAB or ESC TAB for file completion"))
6569 (let ((file (widget-value widget
)))
6570 (and (not (file-directory-p file
))
6571 (file-readable-p file
)
6572 (setq pr-i-ps-file file
))))
6575 (defun pr-interface-outfile (widget &rest _ignore
)
6576 (setq pr-i-answer-yes nil
)
6577 (and pr-buffer-verbose
6578 (message "You can use M-TAB or ESC TAB for file completion"))
6579 (let ((file (widget-value widget
)))
6580 (and (not (file-directory-p file
))
6581 (file-writable-p file
)
6582 (setq pr-i-out-file file
))))
6585 (defun pr-widget-field-action (widget event
)
6586 (and (get-buffer "*Completions*") ; clean frame window
6587 (delete-windows-on "*Completions*"))
6588 (message " ") ; clean echo area
6589 (widget-field-action widget event
))
6592 (defun pr-insert-italic (str &optional from to
)
6593 (let ((len (length str
)))
6594 (put-text-property (if from
(max from
0) 0)
6595 (if to
(max to len
) len
)
6597 (widget-insert str
)))
6600 (defun pr-insert-checkbox (before var-sym fun label
)
6601 (widget-insert before
)
6603 (widget-create 'checkbox
6605 (symbol-value var-sym
))
6606 (widget-insert label
)))
6609 (defun pr-insert-toggle (var-sym label
)
6610 (widget-create 'checkbox
6611 :notify
`(lambda (&rest _ignore
)
6612 (setq ,var-sym
(not ,var-sym
)))
6613 (symbol-value var-sym
))
6614 (widget-insert label
))
6617 (defun pr-insert-button (fun label
&optional separator
)
6618 (widget-create 'push-button
6622 (widget-insert separator
)))
6625 (defun pr-insert-menu (tag var-sym choices
&optional before after
&rest body
)
6626 (and before
(widget-insert before
))
6627 (eval `(widget-create 'menu-choice
6632 :notify
(lambda (widget &rest _ignore
)
6633 (setq ,var-sym
(widget-value widget
))
6635 :void
'(choice-item :format
"%[%t%]"
6636 :tag
"Can not display value!")
6638 (and after
(widget-insert after
)))
6641 (defun pr-insert-radio-button (var-sym sym
)
6642 (widget-insert "\n")
6643 (let ((wid-list (get var-sym
'pr-widget-list
))
6644 (wid (eval `(widget-create
6647 :value
(eq ,var-sym
(quote ,sym
))
6648 :notify
(lambda (&rest _ignore
)
6649 (setq ,var-sym
(quote ,sym
))
6650 (pr-update-radio-button (quote ,var-sym
)))))))
6651 (put var-sym
'pr-widget-list
(cons (cons wid sym
) wid-list
))))
6654 (defun pr-update-radio-button (var-sym)
6655 (let ((wid-list (get var-sym
'pr-widget-list
)))
6657 (let ((wid (car (car wid-list
)))
6658 (value (cdr (car wid-list
))))
6659 (setq wid-list
(cdr wid-list
))
6660 (widget-value-set wid
(eq (symbol-value var-sym
) value
))))
6664 (defun pr-update-checkbox (var-sym)
6665 (let ((wid (get var-sym
'pr-widget
)))
6667 (widget-value-set wid
(symbol-value var-sym
))
6671 (defun pr-choice-alist (alist)
6672 (let ((max (apply 'max
(mapcar #'(lambda (alist)
6673 (length (symbol-name (car alist
))))
6675 (mapcar #'(lambda (alist)
6676 (let* ((sym (car alist
))
6677 (name (symbol-name sym
)))
6684 (make-string (- max
(length name
)) ?_
))
6689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6695 ;;; printing.el ends here