* lisp/bookmark.el (bookmark-write-file): Bind `print-circle' to `t'
[emacs.git] / lisp / printing.el
blob02b2fb0139c8fd40f208d6c65d9738065edc9fae
1 ;;; printing.el --- printing utilities
3 ;; Copyright (C) 2000-2001, 2003-2012 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
8 ;; Version: 6.9.3
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 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/>.
33 ;;; Commentary:
35 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;; Introduction
38 ;; ------------
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
44 ;; printer database.
46 ;; There are two user interfaces:
48 ;; * Menu interface:
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
86 ;; Log Messages
87 ;; ------------
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:
93 ;; PROGRAM (ARG...)
94 ;; MESSAGE
95 ;; Exit status: CODE
97 ;; Where
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")
108 ;; Exit status: 0
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
112 ;; would be:
114 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
115 ;; Exit status: Quit
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*,
119 ;; it can help.
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
138 ;; will thank you.
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
144 ;; init file:
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")
153 ;; ))
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 "")
160 ;; ))
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 "" "")
170 ;; ))
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")
180 ;; ))
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")
185 ;; ))
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")
191 ;; ))
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).
207 ;; 2. Type:
208 ;; First line (on first page)
209 ;; ^L
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.
219 ;; Tips
220 ;; ----
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
250 ;; Stack =
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
276 ;; ))
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'.
296 ;; Using `printing'
297 ;; ----------------
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:
306 ;; * On Emacs 20:
307 ;; it replaces the Tools/Print menu by Tools/Printing menu.
308 ;; * On Emacs 21:
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:
318 ;; pr-interface
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
333 ;; pr-ps-mode-print
334 ;; pr-ps-mode-ps-print
335 ;; pr-ps-file-preview
336 ;; pr-ps-file-up-preview
337 ;; pr-ps-file-using-ghostscript
338 ;; pr-ps-file-print
339 ;; pr-ps-file-ps-print
340 ;; pr-ps-file-up-ps-print
341 ;; pr-ps-fast-fire
342 ;; pr-despool-preview
343 ;; pr-despool-using-ghostscript
344 ;; pr-despool-print
345 ;; pr-despool-ps-print
346 ;; pr-printify-directory
347 ;; pr-printify-buffer
348 ;; pr-printify-region
349 ;; pr-txt-directory
350 ;; pr-txt-buffer
351 ;; pr-txt-region
352 ;; pr-txt-mode
353 ;; pr-txt-fast-fire
354 ;; pr-toggle-file-duplex
355 ;; pr-toggle-file-tumble
356 ;; pr-toggle-file-landscape
357 ;; pr-toggle-ghostscript
358 ;; pr-toggle-faces
359 ;; pr-toggle-spool
360 ;; pr-toggle-duplex
361 ;; pr-toggle-tumble
362 ;; pr-toggle-landscape
363 ;; pr-toggle-upside-down
364 ;; pr-toggle-line
365 ;; pr-toggle-zebra
366 ;; pr-toggle-header
367 ;; pr-toggle-lock
368 ;; pr-toggle-region
369 ;; pr-toggle-mode
370 ;; pr-customize
371 ;; lpr-customize
372 ;; pr-help
373 ;; pr-ps-name
374 ;; pr-txt-name
375 ;; pr-ps-utility
376 ;; pr-show-ps-setup
377 ;; pr-show-pr-setup
378 ;; pr-show-lpr-setup
380 ;; The general meanings of above commands are:
382 ;; PREFIX:
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
394 ;; representation.
396 ;; SUFFIX:
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.
406 ;; INFIX/SUFFIX:
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.
422 ;; `pr-toggle-spool'
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)
490 ;; Options
491 ;; -------
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
497 ;; commands.
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
506 ;; file.
508 ;; `pr-ps-printer-alist' Specify an alist for all PostScript printers.
510 ;; `pr-temp-dir' Specify a directory for temporary files during
511 ;; printing.
513 ;; `pr-ps-temp-file' Specify PostScript temporary file name prefix.
515 ;; `pr-file-modes' Specify the file permission bits for newly
516 ;; created files.
518 ;; `pr-gv-command' Specify path and name of the gsview/gv
519 ;; utility.
521 ;; `pr-gs-command' Specify path and name of the ghostscript
522 ;; utility.
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
540 ;; mode.
542 ;; `pr-file-tumble' Non-nil means print PostScript file in tumble
543 ;; mode.
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
551 ;; function.
553 ;; `pr-ps-utility' Specify PostScript utility processing.
555 ;; `pr-ps-utility-alist' Specify an alist for PostScript utility
556 ;; processing.
558 ;; `pr-menu-lock' Non-nil means menu is locked while selecting
559 ;; toggle options.
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
568 ;; entries.
570 ;; `pr-delete-temp-file' Non-nil means delete temporary files.
572 ;; `pr-list-directory' Non-nil means list directory when processing a
573 ;; directory.
575 ;; `pr-buffer-name' Specify the name of the buffer interface for
576 ;; printing package.
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
591 ;; session.
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.
617 ;; e) or invoke:
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.
635 ;; Menu Layout
636 ;; -----------
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:
679 ;; A. Interface:
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
701 ;; 16).
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
714 ;; processing:
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
719 ;; documentation.
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
782 ;; this option.
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'
837 ;; options.
839 ;; 23. Show current settings for `printing', `ps-print' or `lpr'.
841 ;; 24. Quick help for printing menu layout.
844 ;; Option Settings
845 ;; ---------------
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")
857 ;; ))
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")
862 ;; ))
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")
868 ;; ))
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))
880 ;; ))
881 ;; (setq pr-setting-database
882 ;; '((no-duplex
883 ;; nil nil nil
884 ;; (pr-file-duplex . nil)
885 ;; (pr-file-tumble . nil))
886 ;; ))
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")
896 ;; ))
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 "")
903 ;; ))
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 "" "")
914 ;; ))
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))
925 ;; ))
926 ;; (setq pr-setting-database
927 ;; '((no-duplex
928 ;; nil nil nil
929 ;; (pr-file-duplex . nil)
930 ;; (pr-file-tumble . nil))
931 ;; ))
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'.
938 ;; Utilities
939 ;; ---------
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:
968 ;; gswin32, gsview32
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/'
976 ;; Acknowledgments
977 ;; ---------------
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.
988 ;; - doc fix.
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'.
1011 ;; Thanks to:
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 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1021 ;;; Code:
1024 (require 'lpr)
1025 (require 'ps-print)
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 ps-windows-system (getenv "OSTYPE")
1034 (string-match "cygwin" (getenv "OSTYPE"))))
1037 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1038 ;; To avoid compilation gripes
1041 (or (fboundp 'subst-char-in-string) ; hacked from subr.el
1042 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1043 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1044 Unless optional argument INPLACE is non-nil, return a new string."
1045 (let ((i (length string))
1046 (newstr (if inplace string (copy-sequence string))))
1047 (while (> (setq i (1- i)) 0)
1048 (if (eq (aref newstr i) fromchar)
1049 (aset newstr i tochar)))
1050 newstr)))
1053 (or (fboundp 'make-temp-file) ; hacked from subr.el
1054 (defun make-temp-file (prefix &optional dir-flag suffix)
1055 "Create a temporary file.
1056 The returned file name (created by appending some random characters at the end
1057 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1058 is guaranteed to point to a newly created empty file.
1059 You can then use `write-region' to write new data into the file.
1061 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1063 If SUFFIX is non-nil, add that at the end of the file name."
1064 (let ((umask (default-file-modes))
1065 file)
1066 (unwind-protect
1067 (progn
1068 ;; Create temp files with strict access rights. It's easy to
1069 ;; loosen them later, whereas it's impossible to close the
1070 ;; time-window of loose permissions otherwise.
1071 (set-default-file-modes ?\700)
1072 (while (condition-case ()
1073 (progn
1074 (setq file
1075 (make-temp-name
1076 (expand-file-name prefix temporary-file-directory)))
1077 (if suffix
1078 (setq file (concat file suffix)))
1079 (if dir-flag
1080 (make-directory file)
1081 (write-region "" nil file nil 'silent nil 'excl))
1082 nil)
1083 (file-already-exists t))
1084 ;; the file was somehow created by someone else between
1085 ;; `make-temp-name' and `write-region', let's try again.
1086 nil)
1087 file)
1088 ;; Reset the umask.
1089 (set-default-file-modes umask)))))
1092 (eval-when-compile
1093 ;; User Interface --- declared here to avoid compiler warnings
1094 (defvar pr-path-style)
1095 (defvar pr-auto-region)
1096 (defvar pr-menu-char-height)
1097 (defvar pr-menu-char-width)
1098 (defvar pr-menu-lock)
1099 (defvar pr-ps-printer-alist)
1100 (defvar pr-txt-printer-alist)
1101 (defvar pr-ps-utility-alist)
1104 ;; Internal fun alias to avoid compilation gripes
1105 (defalias 'pr-menu-lookup 'ignore)
1106 (defalias 'pr-menu-lock 'ignore)
1107 (defalias 'pr-menu-alist 'ignore)
1108 (defalias 'pr-even-or-odd-pages 'ignore)
1109 (defalias 'pr-menu-get-item 'ignore)
1110 (defalias 'pr-menu-set-item-name 'ignore)
1111 (defalias 'pr-menu-set-utility-title 'ignore)
1112 (defalias 'pr-menu-set-ps-title 'ignore)
1113 (defalias 'pr-menu-set-txt-title 'ignore)
1114 (defalias 'pr-region-active-p 'ignore)
1115 (defalias 'pr-do-update-menus 'ignore)
1116 (defalias 'pr-update-mode-line 'ignore)
1117 (defalias 'pr-read-string 'ignore)
1118 (defalias 'pr-set-keymap-parents 'ignore)
1119 (defalias 'pr-keep-region-active 'ignore))
1122 ;; Internal Vars --- defined here to avoid compiler warnings
1123 (defvar pr-menu-print-item "print"
1124 "Non-nil means that menu binding was not done.
1126 Used by `pr-menu-bind' and `pr-update-menus'.")
1128 (defvar pr-ps-printer-menu-modified t
1129 "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
1131 (defvar pr-txt-printer-menu-modified t
1132 "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
1134 (defvar pr-ps-utility-menu-modified t
1135 "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
1137 (defconst pr-even-or-odd-alist
1138 '((nil . "Print All Pages")
1139 (even-page . "Print Even Pages")
1140 (odd-page . "Print Odd Pages")
1141 (even-sheet . "Print Even Sheets")
1142 (odd-sheet . "Print Odd Sheets")))
1145 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1146 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1147 ;; XEmacs Definitions
1150 (cond
1151 ((featurep 'xemacs) ; XEmacs
1152 ;; XEmacs
1153 (defalias 'pr-set-keymap-parents 'set-keymap-parents)
1154 (defalias 'pr-set-keymap-name 'set-keymap-name)
1156 ;; XEmacs
1157 (defun pr-read-string (prompt initial history default)
1158 (let ((str (read-string prompt initial)))
1159 (if (and str (not (string= str "")))
1161 default)))
1163 ;; XEmacs
1164 (defvar zmacs-region-stays nil)
1166 ;; XEmacs
1167 (defun pr-keep-region-active ()
1168 (setq zmacs-region-stays t))
1170 ;; XEmacs
1171 (defun pr-region-active-p ()
1172 (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p)))
1174 ;; XEmacs
1175 (defun pr-menu-char-height ()
1176 (font-height (face-font 'default)))
1178 ;; XEmacs
1179 (defun pr-menu-char-width ()
1180 (font-width (face-font 'default)))
1182 ;; XEmacs
1183 (defmacro pr-xemacs-global-menubar (&rest body)
1184 `(save-excursion
1185 (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
1186 ;; be sure to access global menubar
1187 (set-buffer temp)
1188 ,@body
1189 (kill-buffer temp))))
1191 ;; XEmacs
1192 (defun pr-global-menubar (pr-menu-spec)
1193 ;; Menu binding
1194 (pr-xemacs-global-menubar
1195 (add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
1196 (setq pr-menu-print-item nil))
1198 ;; XEmacs
1199 (defvar current-mouse-event nil)
1200 (defun pr-menu-position (entry index horizontal)
1201 (make-event
1202 'button-release
1203 (list 'button 1
1204 'x (- (event-x-pixel current-mouse-event) ; X
1205 (* horizontal pr-menu-char-width))
1206 'y (- (event-y-pixel current-mouse-event) ; Y
1207 (* (pr-menu-index entry index) pr-menu-char-height)))))
1209 (defvar pr-menu-position nil)
1210 (defvar pr-menu-state nil)
1212 ;; XEmacs
1213 (defvar current-menubar nil) ; to avoid compilation gripes
1214 (defun pr-menu-lookup (path)
1215 (car (find-menu-item current-menubar (cons "Printing" path))))
1217 ;; XEmacs
1218 (defun pr-menu-lock (entry index horizontal state path)
1219 (when pr-menu-lock
1220 (or (and pr-menu-position (eq state pr-menu-state))
1221 (setq pr-menu-position (pr-menu-position entry index horizontal)
1222 pr-menu-state state))
1223 (let* ((menu (pr-menu-lookup path))
1224 (result (get-popup-menu-response menu pr-menu-position)))
1225 (and (misc-user-event-p result)
1226 (funcall (event-function result)
1227 (event-object result))))
1228 (setq pr-menu-position nil)))
1230 ;; XEmacs
1231 (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
1233 ;; XEmacs
1234 (defvar pr-ps-name-old "PostScript Printers")
1235 (defvar pr-txt-name-old "Text Printers")
1236 (defvar pr-ps-utility-old "PostScript Utility")
1237 (defvar pr-even-or-odd-old "Print All Pages")
1239 ;; XEmacs
1240 (defun pr-do-update-menus (&optional force)
1241 (pr-menu-alist pr-ps-printer-alist
1242 'pr-ps-name
1243 'pr-menu-set-ps-title
1244 '("Printing")
1245 'pr-ps-printer-menu-modified
1246 force
1247 pr-ps-name-old
1248 'postscript 2)
1249 (pr-menu-alist pr-txt-printer-alist
1250 'pr-txt-name
1251 'pr-menu-set-txt-title
1252 '("Printing")
1253 'pr-txt-printer-menu-modified
1254 force
1255 pr-txt-name-old
1256 'text 2)
1257 (let ((save-var pr-ps-utility-menu-modified))
1258 (pr-menu-alist pr-ps-utility-alist
1259 'pr-ps-utility
1260 'pr-menu-set-utility-title
1261 '("Printing" "PostScript Print" "File")
1262 'save-var
1263 force
1264 pr-ps-utility-old
1265 nil 1))
1266 (pr-menu-alist pr-ps-utility-alist
1267 'pr-ps-utility
1268 'pr-menu-set-utility-title
1269 '("Printing" "PostScript Preview" "File")
1270 'pr-ps-utility-menu-modified
1271 force
1272 pr-ps-utility-old
1273 nil 1)
1274 (pr-even-or-odd-pages ps-even-or-odd-pages force))
1276 ;; XEmacs
1277 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1278 entry index)
1279 (when (and alist (or force (symbol-value modified-sym)))
1280 (pr-xemacs-global-menubar
1281 (add-submenu menu-path
1282 (pr-menu-create name alist var-sym
1283 fun entry index)))
1284 (funcall fun (symbol-value var-sym))
1285 (set modified-sym nil)))
1287 ;; XEmacs
1288 (defun pr-relabel-menu-item (newname var-sym)
1289 (pr-xemacs-global-menubar
1290 (relabel-menu-item
1291 (list "Printing" (symbol-value var-sym))
1292 newname)
1293 (set var-sym newname)))
1295 ;; XEmacs
1296 (defun pr-menu-set-ps-title (value &optional item entry index)
1297 (pr-relabel-menu-item (format "PostScript Printer: %s" value)
1298 'pr-ps-name-old)
1299 (pr-ps-set-printer value)
1300 (and index
1301 (pr-menu-lock entry index 12 'toggle nil)))
1303 ;; XEmacs
1304 (defun pr-menu-set-txt-title (value &optional item entry index)
1305 (pr-relabel-menu-item (format "Text Printer: %s" value)
1306 'pr-txt-name-old)
1307 (pr-txt-set-printer value)
1308 (and index
1309 (pr-menu-lock entry index 12 'toggle nil)))
1311 ;; XEmacs
1312 (defun pr-menu-set-utility-title (value &optional item entry index)
1313 (pr-xemacs-global-menubar
1314 (let ((newname (format "%s" value)))
1315 (relabel-menu-item
1316 (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
1317 newname)
1318 (relabel-menu-item
1319 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
1320 newname)
1321 (setq pr-ps-utility-old newname)))
1322 (pr-ps-set-utility value)
1323 (and index
1324 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
1326 ;; XEmacs
1327 (defun pr-even-or-odd-pages (value &optional no-lock)
1328 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
1329 'pr-even-or-odd-old)
1330 (setq ps-even-or-odd-pages value)
1331 (or no-lock
1332 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
1335 (t ; GNU Emacs
1336 ;; Do nothing
1337 )) ; end cond featurep
1341 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1342 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1343 ;; GNU Emacs Definitions
1346 (cond
1347 ((featurep 'xemacs) ; XEmacs
1348 ;; Do nothing
1350 (t ; GNU Emacs
1351 ;; GNU Emacs
1352 (defalias 'pr-set-keymap-parents 'set-keymap-parent)
1353 (defalias 'pr-set-keymap-name 'ignore)
1354 (defalias 'pr-read-string 'read-string)
1356 ;; GNU Emacs
1357 (defvar deactivate-mark)
1359 ;; GNU Emacs
1360 (defun pr-keep-region-active ()
1361 (setq deactivate-mark nil))
1363 ;; GNU Emacs
1364 (defun pr-region-active-p ()
1365 (and pr-auto-region transient-mark-mode mark-active))
1367 ;; GNU Emacs
1368 (defun pr-menu-char-height ()
1369 (frame-char-height))
1371 ;; GNU Emacs
1372 (defun pr-menu-char-width ()
1373 (frame-char-width))
1375 (defvar pr-menu-bar nil
1376 "Specify Printing menu-bar entry.")
1378 ;; GNU Emacs
1379 ;; Menu binding
1380 ;; Replace existing "print" item by "Printing" item.
1381 ;; If you're changing this file, you'll load it a second,
1382 ;; third... time, but "print" item exists only in the first load.
1383 (eval-when-compile
1384 (require 'easymenu)) ; to avoid compilation gripes
1386 (eval-and-compile
1387 (defun pr-global-menubar (pr-menu-spec)
1388 (require 'easymenu)
1389 (let ((menu-file (if (= emacs-major-version 21)
1390 '("menu-bar" "files") ; GNU Emacs 21
1391 '("menu-bar" "file")))) ; GNU Emacs 22 or higher
1392 (cond
1393 (pr-menu-print-item
1394 (easy-menu-add-item global-map menu-file
1395 (easy-menu-create-menu "Print" pr-menu-spec)
1396 "print-buffer")
1397 (dolist (item '("print-buffer" "print-region"
1398 "ps-print-buffer-faces" "ps-print-region-faces"
1399 "ps-print-buffer" "ps-print-region"))
1400 (easy-menu-remove-item global-map menu-file item))
1401 (setq pr-menu-print-item nil
1402 pr-menu-bar (vector 'menu-bar
1403 (pr-get-symbol (nth 1 menu-file))
1404 (pr-get-symbol "Print"))))
1406 (easy-menu-add-item global-map menu-file
1407 (easy-menu-create-menu "Print" pr-menu-spec)))
1408 ))))
1410 (eval-and-compile
1411 (cond
1412 (ps-windows-system
1413 ;; GNU Emacs for Windows 9x/NT
1414 (defun pr-menu-position (entry index horizontal)
1415 (let ((pos (cdr (mouse-pixel-position))))
1416 (list
1417 (list (or (car pos) 0) ; X
1418 (- (or (cdr pos) 0) ; Y
1419 (* (pr-menu-index entry index) pr-menu-char-height)))
1420 (selected-frame)))) ; frame
1423 ;; GNU Emacs
1424 (defun pr-menu-position (entry index horizontal)
1425 (let ((pos (cdr (mouse-pixel-position))))
1426 (list
1427 (list (- (or (car pos) 0) ; X
1428 (* horizontal pr-menu-char-width))
1429 (- (or (cdr pos) 0) ; Y
1430 (* (pr-menu-index entry index) pr-menu-char-height)))
1431 (selected-frame)))) ; frame
1434 (defvar pr-menu-position nil)
1435 (defvar pr-menu-state nil)
1437 ;; GNU Emacs
1438 (defun pr-menu-lookup (path)
1439 (lookup-key global-map
1440 (if path
1441 (vconcat pr-menu-bar
1442 (mapcar 'pr-get-symbol
1443 (if (listp path)
1444 path
1445 (list path))))
1446 pr-menu-bar)))
1448 ;; GNU Emacs
1449 (defun pr-menu-lock (entry index horizontal state path)
1450 (when pr-menu-lock
1451 (or (and pr-menu-position (eq state pr-menu-state))
1452 (setq pr-menu-position (pr-menu-position entry index horizontal)
1453 pr-menu-state state))
1454 (let* ((menu (pr-menu-lookup path))
1455 (result (x-popup-menu pr-menu-position menu)))
1456 (and result
1457 (let ((command (lookup-key menu (vconcat result))))
1458 (if (fboundp command)
1459 (funcall command)
1460 (eval command)))))
1461 (setq pr-menu-position nil)))
1463 ;; GNU Emacs
1464 (defalias 'pr-update-mode-line 'force-mode-line-update)
1466 ;; GNU Emacs
1467 (defun pr-do-update-menus (&optional force)
1468 (pr-menu-alist pr-ps-printer-alist
1469 'pr-ps-name
1470 'pr-menu-set-ps-title
1471 "PostScript Printers"
1472 'pr-ps-printer-menu-modified
1473 force
1474 "PostScript Printers"
1475 'postscript 2)
1476 (pr-menu-alist pr-txt-printer-alist
1477 'pr-txt-name
1478 'pr-menu-set-txt-title
1479 "Text Printers"
1480 'pr-txt-printer-menu-modified
1481 force
1482 "Text Printers"
1483 'text 2)
1484 (let ((save-var pr-ps-utility-menu-modified))
1485 (pr-menu-alist pr-ps-utility-alist
1486 'pr-ps-utility
1487 'pr-menu-set-utility-title
1488 '("PostScript Print" "File" "PostScript Utility")
1489 'save-var
1490 force
1491 "PostScript Utility"
1492 nil 1))
1493 (pr-menu-alist pr-ps-utility-alist
1494 'pr-ps-utility
1495 'pr-menu-set-utility-title
1496 '("PostScript Preview" "File" "PostScript Utility")
1497 'pr-ps-utility-menu-modified
1498 force
1499 "PostScript Utility"
1500 nil 1)
1501 (pr-even-or-odd-pages ps-even-or-odd-pages force))
1503 ;; GNU Emacs
1504 (defun pr-menu-get-item (name-list)
1505 ;; NAME-LIST is a string or a list of strings.
1506 (or (listp name-list)
1507 (setq name-list (list name-list)))
1508 (and name-list
1509 (let* ((reversed (reverse name-list))
1510 (name (pr-get-symbol (car reversed)))
1511 (path (nreverse (cdr reversed)))
1512 (menu (lookup-key
1513 global-map
1514 (vconcat pr-menu-bar
1515 (mapcar 'pr-get-symbol path)))))
1516 (assq name (nthcdr 2 menu)))))
1518 ;; GNU Emacs
1519 (defvar pr-temp-menu nil)
1521 ;; GNU Emacs
1522 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1523 entry index)
1524 (when (and alist (or force (symbol-value modified-sym)))
1525 (easy-menu-define pr-temp-menu nil ""
1526 (pr-menu-create name alist var-sym fun entry index))
1527 (let ((item (pr-menu-get-item menu-path)))
1528 (and item
1529 (let* ((binding (nthcdr 3 item))
1530 (key-binding (cdr binding)))
1531 (setcar binding pr-temp-menu)
1532 (and key-binding (listp (car key-binding))
1533 (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
1534 (funcall fun (symbol-value var-sym) item))))
1535 (set modified-sym nil)))
1537 ;; GNU Emacs
1538 (defun pr-menu-set-item-name (item name)
1539 (and item
1540 (setcar (nthcdr 2 item) name))) ; ITEM-NAME
1542 ;; GNU Emacs
1543 (defun pr-menu-set-ps-title (value &optional item entry index)
1544 (pr-menu-set-item-name (or item
1545 (pr-menu-get-item "PostScript Printers"))
1546 (format "PostScript Printer: %s" value))
1547 (pr-ps-set-printer value)
1548 (and index
1549 (pr-menu-lock entry index 12 'toggle nil)))
1551 ;; GNU Emacs
1552 (defun pr-menu-set-txt-title (value &optional item entry index)
1553 (pr-menu-set-item-name (or item
1554 (pr-menu-get-item "Text Printers"))
1555 (format "Text Printer: %s" value))
1556 (pr-txt-set-printer value)
1557 (and index
1558 (pr-menu-lock entry index 12 'toggle nil)))
1560 ;; GNU Emacs
1561 (defun pr-menu-set-utility-title (value &optional item entry index)
1562 (let ((name (symbol-name value)))
1563 (if item
1564 (pr-menu-set-item-name item name)
1565 (pr-menu-set-item-name
1566 (pr-menu-get-item
1567 '("PostScript Print" "File" "PostScript Utility"))
1568 name)
1569 (pr-menu-set-item-name
1570 (pr-menu-get-item
1571 '("PostScript Preview" "File" "PostScript Utility"))
1572 name)))
1573 (pr-ps-set-utility value)
1574 (and index
1575 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
1577 ;; GNU Emacs
1578 (defun pr-even-or-odd-pages (value &optional no-lock)
1579 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
1580 (cdr (assq value pr-even-or-odd-alist)))
1581 (setq ps-even-or-odd-pages value)
1582 (or no-lock
1583 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
1585 )) ; end cond featurep
1588 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1589 ;; Internal Functions (I)
1592 (defun pr-dosify-file-name (path)
1593 "Replace unix-style directory separator character with dos/windows one."
1594 (interactive "sPath: ")
1595 (if (eq pr-path-style 'windows)
1596 (subst-char-in-string ?/ ?\\ path)
1597 path))
1600 (defun pr-unixify-file-name (path)
1601 "Replace dos/windows-style directory separator character with unix one."
1602 (interactive "sPath: ")
1603 (if (eq pr-path-style 'windows)
1604 (subst-char-in-string ?\\ ?/ path)
1605 path))
1608 (defun pr-standard-file-name (path)
1609 "Ensure the proper directory separator depending on the OS.
1610 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
1611 separator; otherwise, ensure unix-style directory separator."
1612 (if (or pr-cygwin-system ps-windows-system)
1613 (subst-char-in-string ?/ ?\\ path)
1614 (subst-char-in-string ?\\ ?/ path)))
1617 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1618 ;; Customization Functions
1621 (defun pr-alist-custom-set (symbol value)
1622 "Set the value of custom variables for printer & utility selection."
1623 (set symbol value)
1624 (and (featurep 'printing) ; update only after printing is loaded
1625 (pr-update-menus t)))
1628 (defun pr-ps-utility-custom-set (symbol value)
1629 "Update utility menu entry."
1630 (set symbol value)
1631 (and (featurep 'printing) ; update only after printing is loaded
1632 (pr-menu-set-utility-title value)))
1635 (defun pr-ps-name-custom-set (symbol value)
1636 "Update `PostScript Printer:' menu entry."
1637 (set symbol value)
1638 (and (featurep 'printing) ; update only after printing is loaded
1639 (pr-menu-set-ps-title value)))
1642 (defun pr-txt-name-custom-set (symbol value)
1643 "Update `Text Printer:' menu entry."
1644 (set symbol value)
1645 (and (featurep 'printing) ; update only after printing is loaded
1646 (pr-menu-set-txt-title value)))
1649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1650 ;; User Interface
1653 (defgroup printing nil
1654 "Printing Utilities group."
1655 :tag "Printing Utilities"
1656 :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
1657 :prefix "pr-"
1658 :version "22.1"
1659 :group 'wp
1660 :group 'postscript)
1663 (defcustom pr-path-style
1664 (if (and (not pr-cygwin-system)
1665 ps-windows-system)
1666 'windows
1667 'unix)
1668 "Specify which path style to use for external commands.
1670 Valid values are:
1672 windows Windows 9x/NT style (\\)
1674 unix Unix style (/)"
1675 :type '(choice :tag "Path style"
1676 (const :tag "Windows 9x/NT Style (\\)" :value windows)
1677 (const :tag "Unix Style (/)" :value unix))
1678 :group 'printing)
1681 (defcustom pr-path-alist
1682 '((unix PATH)
1683 (cygwin PATH)
1684 (windows PATH))
1685 "Specify an alist for command paths.
1687 It's used to find commands used for printing package, like gv, gs, gsview.exe,
1688 mpage, print.exe, etc. See also `pr-command' function.
1690 Each element has the form:
1692 (ENTRY DIRECTORY...)
1694 Where:
1696 ENTRY It's a symbol, used to identify this entry.
1697 There must exist at least one of the following entries:
1699 unix this entry is used when Emacs is running on GNU or
1700 Unix system.
1702 cygwin this entry is used when Emacs is running on Windows
1703 95/98/NT/2000 with Cygwin.
1705 windows this entry is used when Emacs is running on Windows
1706 95/98/NT/2000.
1708 DIRECTORY It should be a string or a symbol. If it's a symbol, it should
1709 exist an equal entry in `pr-path-alist'. If it's a string,
1710 it's considered a directory specification.
1712 The directory specification may contain:
1713 $var environment variable expansion
1714 ~/ tilde expansion
1715 ./ current directory
1716 ../ previous directory
1718 For example, let's say the home directory is /home/my and the
1719 current directory is /home/my/dir, so:
1721 THE ENTRY IS EXPANDED TO
1722 ~/entry /home/my/entry
1723 ./entry /home/my/dir/entry
1724 ../entry /home/my/entry
1725 $HOME/entry /home/my/entry
1726 $HOME/~/other/../my/entry /home/my/entry
1728 SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
1729 list and there isn't a `PATH' entry in `pr-path-alist' or the
1730 `PATH' entry has a null directory list, the PATH environment
1731 variable is used.
1733 Examples:
1735 * On GNU or Unix system:
1737 '((unix \".\" \"~/bin\" ghostview mpage PATH)
1738 (ghostview \"$HOME/bin/gsview-dir\")
1739 (mpage \"$HOME/bin/mpage-dir\")
1742 * On Windows system:
1744 '((windows \"c:/applications/executables\" PATH ghostview mpage)
1745 (ghostview \"c:/gs/gsview-dir\")
1746 (mpage \"c:/mpage-dir\")
1748 :type '(repeat
1749 (cons :tag ""
1750 (symbol :tag "Identifier ")
1751 (repeat :tag "Directory List"
1752 (choice :menu-tag "Directory"
1753 :tag "Directory"
1754 (string :value "")
1755 (symbol :value symbol)))))
1756 :group 'printing)
1759 (defcustom pr-txt-name 'default
1760 "Specify a printer for printing a text file.
1762 The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
1763 documentation).
1765 This variable should be modified by customization engine. If this variable is
1766 modified by other means (for example, a lisp function), use `pr-update-menus'
1767 function (see it for documentation) to update text printer menu."
1768 :type 'symbol
1769 :set 'pr-txt-name-custom-set
1770 :group 'printing)
1773 (defcustom pr-txt-printer-alist
1774 (list (list 'default lpr-command nil
1775 (cond ((boundp 'printer-name) printer-name)
1776 (ps-windows-system "PRN")
1777 (t nil)
1779 ;; Examples:
1780 ;; * On GNU or Unix system:
1781 ;; '((prt_06a "lpr" nil "prt_06a")
1782 ;; (prt_07c nil nil "prt_07c")
1783 ;; )
1784 ;; * On Windows system:
1785 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
1786 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
1787 ;; (PRN "" nil "PRN")
1788 ;; (standard "redpr.exe" nil "")
1789 ;; )
1790 "Specify an alist of all text printers (text printer database).
1792 The alist element has the form:
1794 (SYMBOL COMMAND SWITCHES NAME)
1796 Where:
1798 SYMBOL It's a symbol to identify a text printer. It's for
1799 `pr-txt-name' variable setting and for menu selection.
1800 Examples:
1801 'prt_06a
1802 'my_printer
1804 COMMAND Name of the program for printing a text file. On MS-DOS and
1805 MS-Windows systems, if the value is an empty string, then Emacs
1806 will write directly to the printer port given by NAME (see text
1807 below), that is, the NAME should be something like \"PRN\" or
1808 \"LPT1:\".
1809 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1810 COMMAND shouldn't be an empty string.
1811 The programs `print' and `nprint' (the standard print programs
1812 on Windows NT and Novell Netware respectively) are handled
1813 specially, using NAME as the destination for output; any other
1814 program is treated like `lpr' except that an explicit filename
1815 is given as the last argument.
1816 If COMMAND is nil, it's used the default printing program:
1817 `print' for Windows system, `lp' for lp system and `lpr' for
1818 all other systems. See also `pr-path-alist'.
1819 Examples:
1820 \"print\"
1821 \"lpr\"
1822 \"lp\"
1824 SWITCHES List of sexp's to pass as extra options for text printer
1825 program. It is recommended to set NAME (see text below)
1826 instead of including an explicit switch on this list.
1827 Example:
1828 . for lpr
1829 '(\"-#3\" \"-l\")
1832 NAME A string that specifies a text printer name.
1833 On Unix-like systems, a string value should be a name
1834 understood by lpr's -P option (or lp's -d option).
1835 On MS-DOS and MS-Windows systems, it is the name of a printer
1836 device or port. Typical non-default settings would be \"LPT1:\"
1837 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1838 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1839 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1840 printer. You can also set it to a name of a file, in which
1841 case the output gets appended to that file. If you want to
1842 discard the printed output, set this to \"NUL\".
1843 Examples:
1844 . for print.exe
1845 \"/D:\\\\\\\\host\\\\share-name\"
1846 \"LPT1:\"
1847 \"PRN\"
1849 . for lpr or lp
1850 \"share-name\"
1852 This variable should be modified by customization engine. If this variable is
1853 modified by other means (for example, a lisp function), use `pr-update-menus'
1854 function (see it for documentation) to update text printer menu.
1856 Examples:
1858 * On GNU or Unix system:
1860 '((prt_06a \"lpr\" nil \"prt_06a\")
1861 (prt_07c nil nil \"prt_07c\")
1864 * On Windows system:
1866 '((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1867 (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
1868 (PRN \"\" nil \"PRN\")
1869 (standard \"redpr.exe\" nil \"\")
1872 Useful links:
1874 * Information about the print command (print.exe)
1875 `http://www.computerhope.com/printhlp.htm'
1877 * RedMon - Redirection Port Monitor (redpr.exe)
1878 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1880 * Redirection Port Monitor (redpr.exe on-line help)
1881 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1883 * UNIX man pages: lpr (or type `man lpr')
1884 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1885 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1887 * UNIX man pages: lp (or type `man lp')
1888 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1889 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1891 :type '(repeat
1892 (list :tag "Text Printer"
1893 (symbol :tag "Printer Symbol Name")
1894 (string :tag "Printer Command")
1895 (repeat :tag "Printer Switches"
1896 (sexp :tag "Switch" :value ""))
1897 (choice :menu-tag "Printer Name"
1898 :tag "Printer Name"
1899 (const :tag "None" nil)
1900 string)))
1901 :set 'pr-alist-custom-set
1902 :group 'printing)
1905 (defcustom pr-ps-name 'default
1906 "Specify a printer for printing a PostScript file.
1908 This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
1909 documentation).
1911 This variable should be modified by customization engine. If this variable is
1912 modified by other means (for example, a lisp function), use `pr-update-menus'
1913 function (see it for documentation) to update PostScript printer menu."
1914 :type 'symbol
1915 :set 'pr-ps-name-custom-set
1916 :group 'printing)
1919 (defcustom pr-ps-printer-alist
1920 (list (list 'default lpr-command nil
1921 (cond (ps-windows-system nil)
1922 (ps-lp-system "-d")
1923 (t "-P"))
1924 (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
1925 ;; Examples:
1926 ;; * On GNU or Unix system:
1927 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
1928 ;; (lps_07c "lpr" nil nil "lps_07c")
1929 ;; (lps_08c nil nil nil "lps_08c")
1930 ;; )
1931 ;; * On Windows system:
1932 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
1933 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
1934 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
1935 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
1936 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
1937 ;; (LPT1 "" nil "" "LPT1:")
1938 ;; (PRN "" nil "" "PRN")
1939 ;; (standard "redpr.exe" nil "" "")
1940 ;; )
1941 "Specify an alist for all PostScript printers (PostScript printer database).
1943 The alist element has the form:
1945 (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
1947 Where:
1949 SYMBOL It's a symbol to identify a PostScript printer. It's for
1950 `pr-ps-name' variable setting and for menu selection.
1951 Examples:
1952 'prt_06a
1953 'my_printer
1955 COMMAND Name of the program for printing a PostScript file. On MS-DOS
1956 and MS-Windows systems, if the value is an empty string then
1957 Emacs will write directly to the printer port given by NAME
1958 (see text below), that is, the NAME should be something like
1959 \"PRN\" or \"LPT1:\".
1960 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1961 COMMAND shouldn't be an empty string.
1962 The programs `print' and `nprint' (the standard print programs
1963 on Windows NT and Novell Netware respectively) are handled
1964 specially, using NAME as the destination for output; any other
1965 program is treated like `lpr' except that an explicit filename
1966 is given as the last argument.
1967 If COMMAND is nil, it's used the default printing program:
1968 `print' for Windows system, `lp' for lp system and `lpr' for
1969 all other systems. See also `pr-path-alist'.
1970 Examples:
1971 \"print\"
1972 \"lpr\"
1973 \"lp\"
1974 \"cp\"
1975 \"gsprint\"
1977 SWITCHES List of sexp's to pass as extra options for PostScript printer
1978 program. It is recommended to set NAME (see text below)
1979 instead of including an explicit switch on this list.
1980 Example:
1981 . for lpr
1982 '(\"-#3\" \"-l\")
1985 . for gsprint.exe
1986 '(\"-all\" \"-twoup\")
1988 PRINTER-SWITCH A string that specifies PostScript printer name switch. If
1989 it's necessary to have a space between PRINTER-SWITCH and NAME,
1990 it should be inserted at the end of PRINTER-SWITCH string.
1991 If PRINTER-SWITCH is nil, it's used the default printer name
1992 switch: `/D:' for Windows system, `-d' for lp system and `-P'
1993 for all other systems.
1994 Examples:
1995 . for lpr
1996 \"-P \"
1998 . for lp
1999 \"-d \"
2001 . for print.exe
2002 \"/D:\"
2004 . for gsprint.exe
2005 \"-printer \"
2007 NAME A string that specifies a PostScript printer name.
2008 On Unix-like systems, a string value should be a name
2009 understood by lpr's -P option (or lp's -d option).
2010 On MS-DOS and MS-Windows systems, it is the name of a printer
2011 device or port. Typical non-default settings would be \"LPT1:\"
2012 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
2013 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
2014 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
2015 printer. You can also set it to a name of a file, in which
2016 case the output gets appended to that file. If you want to
2017 discard the printed output, set this to \"NUL\".
2018 Examples:
2019 . for cp.exe
2020 \"\\\\\\\\host\\\\share-name\"
2022 . for print.exe or gsprint.exe
2023 \"/D:\\\\\\\\host\\\\share-name\"
2024 \"\\\\\\\\host\\\\share-name\"
2025 \"LPT1:\"
2026 \"PRN\"
2028 . for lpr or lp
2029 \"share-name\"
2031 DEFAULT It's a way to set default values when this entry is selected.
2032 It's a cons like:
2034 (VARIABLE . VALUE)
2036 Which associates VARIABLE with VALUE. When this entry is
2037 selected, it's executed the following command:
2039 (set VARIABLE (eval VALUE))
2041 Note that VALUE can be any valid lisp expression. So, don't
2042 forget to quote symbols and constant lists.
2043 If VARIABLE is the special keyword `inherits-from:', VALUE must
2044 be a symbol name setting defined in `pr-setting-database' from
2045 which the current setting inherits the context. Take care with
2046 circular inheritance.
2047 Examples:
2048 '(ps-landscape-mode . nil)
2049 '(ps-spool-duplex . t)
2050 '(pr-gs-device . (my-gs-device t))
2052 This variable should be modified by customization engine. If this variable is
2053 modified by other means (for example, a lisp function), use `pr-update-menus'
2054 function (see it for documentation) to update PostScript printer menu.
2056 Examples:
2058 * On GNU or Unix system:
2060 '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
2061 (lps_07c \"lpr\" nil nil \"lps_07c\")
2062 (lps_08c nil nil nil \"lps_08c\")
2065 * On Windows system:
2067 '((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
2068 (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
2069 (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
2070 (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
2071 (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
2072 (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
2073 (LPT1 \"\" nil \"\" \"LPT1:\")
2074 (PRN \"\" nil \"\" \"PRN\")
2075 (standard \"redpr.exe\" nil \"\" \"\")
2079 gsprint:
2081 You can use gsprint instead of ghostscript to print monochrome PostScript files
2082 in Windows. The gsprint utility documentation says that it is more efficient
2083 than ghostscript to print monochrome PostScript.
2085 To print non-monochrome PostScript file, the efficiency of ghostscript is
2086 similar to gsprint.
2088 Also the gsprint utility comes together with gsview distribution.
2090 As an example of gsprint declaration:
2092 (setq pr-ps-printer-alist
2093 '((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
2094 (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
2095 ;; some other printer declaration
2098 The example above declares that printer A prints all pages (-all) and two pages
2099 per sheet (-twoup). The printer B declaration does the same as the printer A
2100 declaration, the only difference is the printer name selection.
2102 There are other command line options like:
2104 -mono Render in monochrome as 1bit/pixel (only black and white).
2105 -grey Render in greyscale as 8bits/pixel.
2106 -color Render in color as 24bits/pixel.
2108 The default is `-mono'. So, printer A and B in the example above are using
2109 implicitly the `-mono' option. Note that in `-mono' no gray tone or color is
2110 printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
2111 are not printed.
2114 Useful links:
2116 * GSPRINT - Ghostscript print to Windows printer
2117 `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
2119 * Introduction to Ghostscript
2120 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2122 * How to use Ghostscript
2123 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2125 * Information about the print command (print.exe)
2126 `http://www.computerhope.com/printhlp.htm'
2128 * RedMon - Redirection Port Monitor (redpr.exe)
2129 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
2131 * Redirection Port Monitor (redpr.exe on-line help)
2132 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
2134 * UNIX man pages: lpr (or type `man lpr')
2135 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
2136 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
2138 * UNIX man pages: lp (or type `man lp')
2139 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
2140 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
2142 * GNU utilities for w32 (cp.exe)
2143 `http://unxutils.sourceforge.net/'
2145 :type '(repeat
2146 (list
2147 :tag "PostScript Printer"
2148 (symbol :tag "Printer Symbol Name")
2149 (string :tag "Printer Command")
2150 (repeat :tag "Printer Switches"
2151 (sexp :tag "Switch" :value ""))
2152 (choice :menu-tag "Printer Name Switch"
2153 :tag "Printer Name Switch"
2154 (const :tag "None" nil)
2155 string)
2156 (choice :menu-tag "Printer Name"
2157 :tag "Printer Name"
2158 (const :tag "None" nil)
2159 string)
2160 (repeat
2161 :tag "Default Value List"
2162 :inline t
2163 (cons
2164 :tag ""
2165 (choice
2166 :menu-tag "Variable"
2167 :tag "Variable"
2168 (const :tag "Landscape" ps-landscape-mode)
2169 (const :tag "Print Header" ps-print-header)
2170 (const :tag "Print Header Frame" ps-print-header-frame)
2171 (const :tag "Line Number" ps-line-number)
2172 (const :tag "Zebra Stripes" ps-zebra-stripes)
2173 (const :tag "Duplex" ps-spool-duplex)
2174 (const :tag "Tumble" ps-spool-tumble)
2175 (const :tag "Upside-Down" ps-print-upside-down)
2176 (const :tag "PS File Landscape" pr-file-landscape)
2177 (const :tag "PS File Duplex" pr-file-duplex)
2178 (const :tag "PS File Tumble" pr-file-tumble)
2179 (const :tag "Auto Region" pr-auto-region)
2180 (const :tag "Auto Mode" pr-auto-mode)
2181 (const :tag "Ghostscript Device" pr-gs-device)
2182 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2183 (const :tag "inherits-from:" inherits-from:)
2184 (variable :tag "Other"))
2185 (sexp :tag "Value")))
2187 :set 'pr-alist-custom-set
2188 :group 'printing)
2191 (defcustom pr-temp-dir
2192 (pr-dosify-file-name
2193 (if (boundp 'temporary-file-directory)
2194 (symbol-value 'temporary-file-directory)
2195 ;; hacked from `temporary-file-directory' variable in files.el
2196 (file-name-as-directory
2197 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
2198 (cond (ps-windows-system "c:/temp")
2199 (t "/tmp")
2200 )))))
2201 "Specify a directory for temporary files during printing.
2203 See also `pr-ps-temp-file' and `pr-file-modes'."
2204 :type '(directory :tag "Temporary Directory")
2205 :group 'printing)
2208 (defcustom pr-ps-temp-file "prspool-"
2209 "Specify PostScript temporary file name prefix.
2211 See also `pr-temp-dir' and `pr-file-modes'."
2212 :type '(file :tag "PostScript Temporary File Name")
2213 :group 'printing)
2216 ;; It uses 0600 as default instead of (default-file-modes).
2217 ;; So, by default, only the session owner have permission to deal with files
2218 ;; generated by `printing'.
2219 (defcustom pr-file-modes ?\600
2220 "Specify the file permission bits for newly created files.
2222 It should be an integer; only the low 9 bits are used.
2224 See also `pr-temp-dir' and `pr-ps-temp-file'."
2225 :type '(integer :tag "File Permission Bits")
2226 :group 'printing)
2229 (defcustom pr-gv-command
2230 (if ps-windows-system
2231 "gsview32.exe"
2232 "gv")
2233 "Specify path and name of the gsview/gv utility.
2235 See also `pr-path-alist'.
2237 Useful links:
2239 * GNU gv manual
2240 `http://www.gnu.org/software/gv/manual/gv.html'
2242 * GSview Help
2243 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'
2245 * GSview Help - Common Problems
2246 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'
2248 * GSview Readme (compilation & installation)
2249 `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'
2251 * GSview (main site)
2252 `http://www.cs.wisc.edu/~ghost/gsview/index.htm'
2254 * Ghostscript, Ghostview and GSview
2255 `http://www.cs.wisc.edu/~ghost/'
2257 * Ghostview
2258 `http://www.cs.wisc.edu/~ghost/gv/index.htm'
2260 * gv 3.5, June 1997
2261 `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'
2263 * MacGSView (MacOS)
2264 `http://www.cs.wisc.edu/~ghost/macos/index.htm'
2266 :type '(string :tag "Ghostview Utility")
2267 :group 'printing)
2270 (defcustom pr-gs-command
2271 (if ps-windows-system
2272 "gswin32.exe"
2273 "gs")
2274 "Specify path and name of the ghostscript utility.
2276 See also `pr-path-alist'.
2278 Useful links:
2280 * Ghostscript, Ghostview and GSview
2281 `http://www.cs.wisc.edu/~ghost/'
2283 * Introduction to Ghostscript
2284 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2286 * How to use Ghostscript
2287 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2289 * Printer compatibility
2290 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2292 :type '(string :tag "Ghostscript Utility")
2293 :group 'printing)
2296 (defcustom pr-gs-switches
2297 (if ps-windows-system
2298 '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
2299 '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
2300 "Specify ghostscript switches. See the documentation on GS for more info.
2302 It's a list of strings, where each string is one or more ghostscript switches.
2304 A note on the gs switches:
2306 -q quiet
2307 -dNOPAUSE don't wait for user intervention
2308 -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
2309 -c quit it's added at the end to terminate gs
2311 To see ghostscript documentation for more information:
2313 * On GNU or Unix system:
2314 - for full documentation, type: man gs
2315 - for brief documentation, type: gs -h
2317 * On Windows system:
2318 - for full documentation, see in a browser the file
2319 c:/gstools/gs5.50/index.html, that is, the file index.html which is
2320 located in the same directory as gswin32.exe.
2321 - for brief documentation, type: gswin32.exe -h
2323 Useful links:
2325 * Introduction to Ghostscript
2326 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2328 * How to use Ghostscript
2329 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2331 * Printer compatibility
2332 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2334 :type '(repeat (string :tag "Ghostscript Switch"))
2335 :group 'printing)
2338 (defcustom pr-gs-device
2339 (if ps-windows-system
2340 "mswinpr2"
2341 "uniprint")
2342 "Specify the ghostscript device switch value (-sDEVICE=).
2344 A note on the gs switches:
2346 -sDEVICE=djet500 the printer - works with HP DeskJet 540
2348 See `pr-gs-switches' for documentation.
2349 See also `pr-ps-printer-alist'."
2350 :type '(string :tag "Ghostscript Device")
2351 :group 'printing)
2354 (defcustom pr-gs-resolution 300
2355 "Specify ghostscript resolution switch value (-r).
2357 A note on the gs switches:
2359 -r300 resolution 300x300
2361 See `pr-gs-switches' for documentation.
2362 See also `pr-ps-printer-alist'."
2363 :type '(integer :tag "Ghostscript Resolution")
2364 :group 'printing)
2367 (defcustom pr-print-using-ghostscript nil
2368 "Non-nil means print using ghostscript.
2370 This is useful if you don't have a PostScript printer, so you could use the
2371 ghostscript to print a PostScript file.
2373 In GNU or Unix system, if ghostscript is set as a PostScript filter, this
2374 variable should be nil."
2375 :type 'boolean
2376 :group 'printing)
2379 (defcustom pr-faces-p nil
2380 "Non-nil means print with face attributes."
2381 :type 'boolean
2382 :group 'printing)
2385 (defcustom pr-spool-p nil
2386 "Non-nil means spool printing in a buffer."
2387 :type 'boolean
2388 :group 'printing)
2391 (defcustom pr-file-landscape nil
2392 "Non-nil means print PostScript file in landscape orientation."
2393 :type 'boolean
2394 :group 'printing)
2397 (defcustom pr-file-duplex nil
2398 "Non-nil means print PostScript file in duplex mode."
2399 :type 'boolean
2400 :group 'printing)
2403 (defcustom pr-file-tumble nil
2404 "Non-nil means print PostScript file in tumble mode.
2406 If tumble is off, produces a printing suitable for binding on the left or
2407 right.
2408 If tumble is on, produces a printing suitable for binding at the top or
2409 bottom."
2410 :type 'boolean
2411 :group 'printing)
2414 (defcustom pr-auto-region t
2415 "Non-nil means region is automagically detected.
2417 Note that this will only work if you're using transient mark mode.
2419 When this variable is non-nil, the `*-buffer*' commands will behave like
2420 `*-region*' commands, that is, `*-buffer*' commands will print only the region
2421 marked instead of all buffer."
2422 :type 'boolean
2423 :group 'printing)
2426 (defcustom pr-auto-mode t
2427 "Non-nil means major-mode specific printing is preferred over normal printing.
2429 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
2430 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
2431 `*-buffer*' commands will print the current buffer and `*-region*' commands
2432 will print the current region."
2433 :type 'boolean
2434 :group 'printing)
2437 (defcustom pr-mode-alist
2438 '((mh-folder-mode ; mh summary buffer
2439 pr-mh-lpr-1 pr-mh-print-1
2441 (ps-article-author ps-article-subject)
2442 ("/pagenumberstring load" pr-article-date)
2445 (mh-letter-mode ; mh letter buffer
2446 pr-mh-lpr-2 pr-mh-print-2
2448 (ps-article-author ps-article-subject)
2449 ("/pagenumberstring load" pr-article-date)
2452 (rmail-summary-mode ; rmail summary buffer
2453 pr-rmail-lpr pr-rmail-print
2455 (ps-article-subject ps-article-author buffer-name)
2459 (rmail-mode ; rmail buffer
2460 pr-rmail-lpr pr-rmail-print
2462 (ps-article-subject ps-article-author buffer-name)
2466 (gnus-summary-mode ; gnus summary buffer
2467 pr-gnus-lpr pr-gnus-print
2469 (ps-article-subject ps-article-author gnus-newsgroup-name)
2473 (gnus-article-mode ; gnus article buffer
2474 pr-gnus-lpr pr-gnus-print
2476 (ps-article-subject ps-article-author gnus-newsgroup-name)
2480 (Info-mode ; Info buffer
2481 pr-mode-lpr pr-mode-print
2483 (ps-info-node ps-info-file)
2487 (vm-mode ; vm mode
2488 pr-vm-lpr pr-vm-print
2490 (ps-article-subject ps-article-author buffer-name)
2495 "Specify an alist for a major-mode and printing functions.
2497 To customize a major mode printing, just declare the customization in
2498 `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
2499 mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
2500 *Summary* buffer, if you forget to switch to the *Article* buffer before
2501 printing, you'll get a nicely formatted list of article subjects shows up at
2502 the printer. With major mode printing you don't need to switch from gnus
2503 *Summary* buffer first.
2505 The elements have the following form:
2507 (MAJOR-MODE
2508 LPR-PRINT PS-PRINT
2509 HEADER-LINES
2510 LEFT-HEADER
2511 RIGHT-HEADER
2512 KILL-LOCAL-VARIABLE
2513 DEFAULT...)
2515 Where:
2517 MAJOR-MODE It's the major mode symbol.
2519 LPR-PRINT It's a symbol function for text printing. It's invoked with
2520 one argument:
2521 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2523 Usually LPR-PRINT function prepares the environment or buffer
2524 and then call the function `pr-mode-lpr' which it's used to
2525 process the buffer and send it to text printer.
2527 The `pr-mode-lpr' definition is:
2529 (pr-mode-lpr HEADER-LIST &optional FROM TO)
2531 Where HEADER-LIST is like the argument passed to LPR-PRINT.
2532 FROM and TO are the beginning and end markers, respectively,
2533 for a region. If FROM is nil, it's used (point-min); if TO is
2534 nil, it's used (point-max).
2536 PS-PRINT It's a symbol function for PostScript printing. It's invoked
2537 with three arguments: n-up printing, file name and the list:
2538 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2540 Usually PS-PRINT function prepares the environment or buffer
2541 and then call the function `pr-mode-print' which it's used to
2542 process the buffer and send it to PostScript printer.
2544 The `pr-mode-print' definition is:
2546 (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
2548 Where N-UP, FILENAME and HEADER-LIST are like the arguments
2549 passed to PS-PRINT. FROM and TO are the beginning and end
2550 markers, respectively, for a region. If TO is nil, it's used
2551 (point-max).
2553 HEADER-LINES It's the number of header lines; if is nil, it uses
2554 `ps-header-lines' value.
2556 LEFT-HEADER It's the left header part, it's a list of string, variable
2557 symbol or function symbol (with no argument); if is nil, it
2558 uses `ps-left-header' value.
2560 RIGHT-HEADER It's the right header part, it's a list of string, variable
2561 symbol or function symbol (with no argument); if is nil, it
2562 uses `ps-right-header' value.
2564 KILL-LOCAL-VARIABLE
2565 Non-nil means to kill all buffer local variable declared in
2566 DEFAULT (see below).
2568 DEFAULT It's a way to set default values when this entry is selected.
2569 It's a cons like:
2571 (VARIABLE-SYM . VALUE)
2573 Which associates VARIABLE-SYM with VALUE. When this entry is
2574 selected, it's executed the following command:
2576 (set (make-local-variable VARIABLE-SYM) (eval VALUE))
2578 Note that VALUE can be any valid lisp expression. So, don't
2579 forget to quote symbols and constant lists.
2580 If VARIABLE is the special keyword `inherits-from:', VALUE must
2581 be a symbol name setting defined in `pr-setting-database' from
2582 which the current setting inherits the context. Take care with
2583 circular inheritance.
2584 Examples:
2585 '(ps-landscape-mode . nil)
2586 '(ps-spool-duplex . t)
2587 '(pr-gs-device . (my-gs-device t))"
2588 :type '(repeat
2589 (list
2590 :tag ""
2591 (symbol :tag "Major Mode")
2592 (function :tag "Text Printing Function")
2593 (function :tag "PS Printing Function")
2594 (choice :menu-tag "Number of Header Lines"
2595 :tag "Number of Header Lines"
2596 (integer :tag "Number")
2597 (const :tag "Default Number" nil))
2598 (repeat :tag "Left Header List"
2599 (choice :menu-tag "Left Header"
2600 :tag "Left Header"
2601 string symbol))
2602 (repeat :tag "Right Header List"
2603 (choice :menu-tag "Right Header"
2604 :tag "Right Header"
2605 string symbol))
2606 (boolean :tag "Kill Local Variable At End")
2607 (repeat
2608 :tag "Default Value List"
2609 :inline t
2610 (cons
2611 :tag ""
2612 (choice
2613 :menu-tag "Variable"
2614 :tag "Variable"
2615 (const :tag "Landscape" ps-landscape-mode)
2616 (const :tag "Print Header" ps-print-header)
2617 (const :tag "Print Header Frame" ps-print-header-frame)
2618 (const :tag "Line Number" ps-line-number)
2619 (const :tag "Zebra Stripes" ps-zebra-stripes)
2620 (const :tag "Duplex" ps-spool-duplex)
2621 (const :tag "Tumble" ps-spool-tumble)
2622 (const :tag "Upside-Down" ps-print-upside-down)
2623 (const :tag "PS File Landscape" pr-file-landscape)
2624 (const :tag "PS File Duplex" pr-file-duplex)
2625 (const :tag "PS File Tumble" pr-file-tumble)
2626 (const :tag "Auto Region" pr-auto-region)
2627 (const :tag "Auto Mode" pr-auto-mode)
2628 (const :tag "Ghostscript Device" pr-gs-device)
2629 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2630 (const :tag "inherits-from:" inherits-from:)
2631 (variable :tag "Other"))
2632 (sexp :tag "Value")))
2634 :group 'printing)
2637 (defcustom pr-ps-utility 'mpage
2638 "Specify PostScript utility symbol.
2640 This utility symbol should be defined on `pr-ps-utility-alist' (see it for
2641 documentation).
2643 This variable should be modified by customization engine. If this variable is
2644 modified by other means (for example, a lisp function), use `pr-update-menus'
2645 function (see it for documentation) to update PostScript utility menu.
2647 NOTE: Don't forget to download and install the utilities declared on
2648 `pr-ps-utility-alist'."
2649 :type '(symbol :tag "PS File Utility")
2650 :set 'pr-ps-utility-custom-set
2651 :group 'printing)
2654 (defcustom pr-ps-utility-alist
2655 '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2656 (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2657 (inherits-from: . no-duplex))
2659 ;; Examples:
2660 ;; * On GNU or Unix system:
2661 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2662 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2663 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2664 ;; )
2665 ;; * On Windows system:
2666 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2667 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2668 ;; )
2669 "Specify an alist for PostScript utility processing (PS utility database).
2671 The alist element has the form:
2673 (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
2674 SWITCHES DEFAULT...)
2676 Where:
2678 SYMBOL It's a symbol to identify a PostScript utility. It's for
2679 `pr-ps-utility' variable setting and for menu selection.
2680 Examples:
2681 'mpage
2682 'psnup
2684 UTILITY Name of utility for processing a PostScript file.
2685 See also `pr-path-alist'.
2686 Examples:
2687 . for GNU or Unix system:
2688 \"mpage\"
2689 \"psnup -q\"
2691 . for Windows system:
2692 \"c:/psutils/psnup -q\"
2694 MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
2695 program. These options are necessary to process the utility
2696 program and must be placed before any other switches.
2697 Example:
2698 . for psnup:
2699 '(\"-q\")
2701 PAPERSIZE It's a format string to specify paper size switch.
2702 Example:
2703 . for mpage
2704 \"-b%s\"
2706 N-UP It's a format string to specify n-up switch.
2707 Example:
2708 . for psnup
2709 \"-%d\"
2711 LANDSCAPE It's a string to specify landscape switch. If the utility
2712 doesn't have landscape switch, set to nil.
2713 Example:
2714 . for psnup
2715 \"-l\"
2717 DUPLEX It's a string to specify duplex switch. If the utility doesn't
2718 have duplex switch, set to nil.
2719 Example:
2720 . for psnup
2723 TUMBLE It's a string to specify tumble switch. If the utility doesn't
2724 have tumble switch, set to nil.
2725 Example:
2726 . for psnup
2729 OUTPUT It's a string to specify how to generate an output file. Some
2730 utilities accept an output file option, but some others need
2731 output redirection or some other way to specify an output file.
2732 Example:
2733 . for psnup
2734 \" \" ; psnup ... input output
2736 . for mpage
2737 \">\" ; mpage ... input > output
2739 SWITCHES List of sexp's to pass as extra options to the PostScript utility
2740 program.
2741 Example:
2742 . for psnup
2743 '(\"-q\")
2746 DEFAULT It's a way to set default values when this entry is selected.
2747 It's a cons like:
2749 (VARIABLE . VALUE)
2751 Which associates VARIABLE with VALUE. When this entry is
2752 selected, it's executed the following command:
2754 (set VARIABLE (eval VALUE))
2756 Note that VALUE can be any valid lisp expression. So, don't
2757 forget to quote symbols and constant lists.
2758 If VARIABLE is the special keyword `inherits-from:', VALUE must
2759 be a symbol name setting defined in `pr-setting-database' from
2760 which the current setting inherits the context. Take care with
2761 circular inheritance.
2762 Examples:
2763 '(pr-file-landscape . nil)
2764 '(pr-file-duplex . t)
2765 '(pr-gs-device . (my-gs-device t))
2767 This variable should be modified by customization engine. If this variable is
2768 modified by other means (for example, a lisp function), use `pr-update-menus'
2769 function (see it for documentation) to update PostScript utility menu.
2771 NOTE: Don't forget to download and install the utilities declared on
2772 `pr-ps-utility-alist'.
2774 Examples:
2776 * On GNU or Unix system:
2778 '((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
2779 (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
2780 (pr-file-duplex . nil) (pr-file-tumble . nil))
2783 * On Windows system:
2785 '((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
2786 nil (pr-file-duplex . nil) (pr-file-tumble . nil))
2789 Useful links:
2791 * mpage download (GNU or Unix)
2792 `http://www.mesa.nl/pub/mpage/'
2794 * mpage documentation (GNU or Unix - or type `man mpage')
2795 `http://www.cs.umd.edu/faq/guides/manual_unix/node48.html'
2796 `http://www.rt.com/man/mpage.1.html'
2798 * psnup (Windows, GNU or Unix)
2799 `http://www.knackered.org/angus/psutils/'
2800 `http://gershwin.ens.fr/vdaniel/Doc-Locale/Outils-Gnu-Linux/PsUtils/'
2802 * psnup (PsUtils for Windows)
2803 `http://gnuwin32.sourceforge.net/packages/psutils.htm'
2805 * psnup documentation (GNU or Unix - or type `man psnup')
2806 `http://linux.about.com/library/cmd/blcmdl1_psnup.htm'
2807 `http://amath.colorado.edu/computing/software/man/psnup.html'
2809 * GNU Enscript (Windows, GNU or Unix)
2810 `http://people.ssh.com/mtr/genscript/'
2812 * GNU Enscript documentation (Windows, GNU or Unix)
2813 `http://people.ssh.com/mtr/genscript/enscript.man.html'
2814 (on GNU or Unix, type `man enscript')
2816 :type '(repeat
2817 (list :tag "PS File Utility"
2818 (symbol :tag "Utility Symbol")
2819 (string :tag "Utility Name")
2820 (repeat :tag "Must Utility Switches"
2821 (sexp :tag "Switch" :value ""))
2822 (choice :menu-tag "Paper Size"
2823 :tag "Paper Size"
2824 (const :tag "No Paper Size" nil)
2825 (string :tag "Paper Size Format"))
2826 (choice :menu-tag "N-Up"
2827 :tag "N-Up"
2828 (const :tag "No N-Up" nil)
2829 (string :tag "N-Up Format"))
2830 (choice :menu-tag "Landscape"
2831 :tag "Landscape"
2832 (const :tag "No Landscape" nil)
2833 (string :tag "Landscape Switch"))
2834 (choice :menu-tag "Duplex"
2835 :tag "Duplex"
2836 (const :tag "No Duplex" nil)
2837 (string :tag "Duplex Switch"))
2838 (choice :menu-tag "Tumble"
2839 :tag "Tumble"
2840 (const :tag "No Tumble" nil)
2841 (string :tag "Tumble Switch"))
2842 (string :tag "Output Separator")
2843 (repeat :tag "Utility Switches"
2844 (sexp :tag "Switch" :value ""))
2845 (repeat
2846 :tag "Default Value List"
2847 :inline t
2848 (cons
2849 :tag ""
2850 (choice
2851 :menu-tag "Variable"
2852 :tag "Variable"
2853 (const :tag "PS File Landscape" pr-file-landscape)
2854 (const :tag "PS File Duplex" pr-file-duplex)
2855 (const :tag "PS File Tumble" pr-file-tumble)
2856 (const :tag "Ghostscript Device" pr-gs-device)
2857 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2858 (const :tag "inherits-from:" inherits-from:)
2859 (variable :tag "Other"))
2860 (sexp :tag "Value")))
2862 :set 'pr-alist-custom-set
2863 :group 'printing)
2866 (defcustom pr-menu-lock t
2867 "Non-nil means menu is locked while selecting toggle options.
2869 See also `pr-menu-char-height' and `pr-menu-char-width'."
2870 :type 'boolean
2871 :group 'printing)
2874 (defcustom pr-menu-char-height (pr-menu-char-height)
2875 "Specify menu char height in pixels.
2877 This variable is used to guess which vertical position should be locked the
2878 menu, so don't forget to adjust it if menu position is not ok.
2880 See also `pr-menu-lock' and `pr-menu-char-width'."
2881 :type 'integer
2882 :group 'printing)
2885 (defcustom pr-menu-char-width (pr-menu-char-width)
2886 "Specify menu char width in pixels.
2888 This variable is used to guess which horizontal position should be locked the
2889 menu, so don't forget to adjust it if menu position is not ok.
2891 See also `pr-menu-lock' and `pr-menu-char-height'."
2892 :type 'integer
2893 :group 'printing)
2896 (defcustom pr-setting-database
2897 '((no-duplex ; setting symbol name
2898 nil nil nil ; inherits local kill-local
2899 (pr-file-duplex . nil) ; settings
2900 (pr-file-tumble . nil))
2902 "Specify an alist for settings in general.
2904 The elements have the following form:
2906 (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
2908 Where:
2910 SYMBOL It's a symbol to identify the setting group.
2912 INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
2913 setting from which the current setting inherits the context.
2914 If INHERITS is nil, means that there is no inheritance.
2915 This is a simple inheritance mechanism.
2917 Let's see an example to illustrate the inheritance mechanism:
2919 (setq pr-setting-database
2920 '((no-duplex ; setting symbol name
2921 nil ; inherits
2922 nil nil ; local kill-local
2923 (pr-file-duplex . nil) ; settings
2924 (pr-file-tumble . nil)
2926 (no-duplex-and-landscape ; setting symbol name
2927 no-duplex ; inherits
2928 nil nil ; local kill-local
2929 (pr-file-landscape . nil) ; settings
2932 The example above has two setting groups: no-duplex and
2933 no-duplex-and-landscape. When setting no-duplex is activated
2934 through `inherits-from:' (see `pr-ps-utility', `pr-mode-alist'
2935 and `pr-ps-printer-alist'), the variables pr-file-duplex and
2936 pr-file-tumble are both set to nil.
2938 Now when setting no-duplex-and-landscape is activated through
2939 `inherits-from:', the variable pr-file-landscape is set to nil
2940 and also the settings for no-duplex are done, because
2941 no-duplex-and-landscape inherits settings from no-duplex.
2943 Take care with circular inheritance. It's an error if circular
2944 inheritance happens.
2946 LOCAL Non-nil means that all settings for SYMBOL group will be
2947 declared local buffer.
2949 KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
2950 killed at end. It has effect only when LOCAL is non-nil.
2952 SETTING It's a cons like:
2954 (VARIABLE . VALUE)
2956 Which associates VARIABLE with VALUE. When this entry is
2957 selected, it's executed the following command:
2959 * If LOCAL is non-nil:
2960 (set (make-local-variable VARIABLE) (eval VALUE))
2962 * If LOCAL is nil:
2963 (set VARIABLE (eval VALUE))
2965 Note that VALUE can be any valid lisp expression. So, don't
2966 forget to quote symbols and constant lists.
2967 This setting is ignored if VARIABLE is equal to keyword
2968 `inherits-from:'.
2969 Examples:
2970 '(ps-landscape-mode . nil)
2971 '(ps-spool-duplex . t)
2972 '(pr-gs-device . (my-gs-device t))"
2973 :type '(repeat
2974 (list
2975 :tag ""
2976 (symbol :tag "Setting Name")
2977 (choice :menu-tag "Inheritance"
2978 :tag "Inheritance"
2979 (const :tag "No Inheritance" nil)
2980 (symbol :tag "Inherits From"))
2981 (boolean :tag "Local Buffer Setting")
2982 (boolean :tag "Kill Local Variable At End")
2983 (repeat
2984 :tag "Setting List"
2985 :inline t
2986 (cons
2987 :tag ""
2988 (choice
2989 :menu-tag "Variable"
2990 :tag "Variable"
2991 (const :tag "Landscape" ps-landscape-mode)
2992 (const :tag "Print Header" ps-print-header)
2993 (const :tag "Print Header Frame" ps-print-header-frame)
2994 (const :tag "Line Number" ps-line-number)
2995 (const :tag "Zebra Stripes" ps-zebra-stripes)
2996 (const :tag "Duplex" ps-spool-duplex)
2997 (const :tag "Tumble" ps-spool-tumble)
2998 (const :tag "Upside-Down" ps-print-upside-down)
2999 (const :tag "PS File Landscape" pr-file-landscape)
3000 (const :tag "PS File Duplex" pr-file-duplex)
3001 (const :tag "PS File Tumble" pr-file-tumble)
3002 (const :tag "Auto Region" pr-auto-region)
3003 (const :tag "Auto Mode" pr-auto-mode)
3004 (const :tag "Ghostscript Device" pr-gs-device)
3005 (const :tag "Ghostscript Resolution" pr-gs-resolution)
3006 (variable :tag "Other"))
3007 (sexp :tag "Value")))
3009 :group 'printing)
3012 (defcustom pr-visible-entry-list
3013 '(postscript text postscript-options postscript-process printing help)
3014 "Specify a list of Printing menu visible entries.
3016 Valid values with the corresponding menu parts are:
3018 +------------------------------+
3019 | Printing Interface |
3020 +------------------------------+
3021 `postscript' | PostScript Preview >|
3022 | PostScript Print >|
3023 | PostScript Printer: name >|
3024 +------------------------------+
3025 `text' | Printify >|
3026 | Print >|
3027 | Text Printer: name >|
3028 +------------------------------+
3029 `postscript-options' |[ ] Landscape |
3030 |[ ] Print Header |
3031 |[ ] Print Header Frame |
3032 |[ ] Line Number |
3033 |[ ] Zebra Stripes |
3034 |[ ] Duplex |
3035 |[ ] Tumble |
3036 |[ ] Upside-Down |
3037 | Print All Pages >|
3038 +------------------------------+
3039 `postscript-process' |[ ] Spool Buffer |
3040 |[ ] Print with faces |
3041 |[ ] Print via Ghostscript |
3042 +------------------------------+
3043 `printing' |[ ] Auto Region |
3044 |[ ] Auto Mode |
3045 |[ ] Menu Lock |
3046 +------------------------------+
3047 `help' | Customize >|
3048 | Show Settings >|
3049 | Help |
3050 +------------------------------+
3052 Any other value is ignored."
3053 :type '(repeat :tag "Menu Visible Part"
3054 (choice :menu-tag "Menu Part"
3055 :tag "Menu Part"
3056 (const postscript)
3057 (const text)
3058 (const postscript-options)
3059 (const postscript-process)
3060 (const printing)
3061 (const help)))
3062 :group 'printing)
3065 (defcustom pr-delete-temp-file t
3066 "Non-nil means delete temporary files.
3068 Set `pr-delete-temp-file' to nil, if the following message (or a similar)
3069 happens when printing:
3071 Error: could not open \"c:\\temp\\prspool.ps\" for reading."
3072 :type 'boolean
3073 :group 'printing)
3076 (defcustom pr-list-directory nil
3077 "Non-nil means list directory when processing a directory.
3079 That is, any subdirectories (and the superdirectory) of the directory (given as
3080 argument of functions below) are also printed (as dired-mode listings).
3082 It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
3083 `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
3084 and `pr-txt-directory'."
3085 :type 'boolean
3086 :group 'printing)
3089 (defcustom pr-buffer-name "*Printing Interface*"
3090 "Specify the name of the buffer interface for printing package.
3092 It's used by `pr-interface'."
3093 :type 'string
3094 :group 'printing)
3097 (defcustom pr-buffer-name-ignore
3098 (list (regexp-quote pr-buffer-name) ; ignore printing interface buffer
3099 "^ .*$") ; ignore invisible buffers
3100 "Specify a regexp list for buffer names to be ignored in interface buffer.
3102 NOTE: Case is important for matching, that is, `case-fold-search' is always
3103 nil.
3105 It's used by `pr-interface'."
3106 :type '(repeat (regexp :tag "Buffer Name Regexp"))
3107 :group 'printing)
3110 (defcustom pr-buffer-verbose t
3111 "Non-nil means to be verbose when editing a field in interface buffer.
3113 It's used by `pr-interface'."
3114 :type 'boolean
3115 :group 'printing)
3118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3119 ;; Internal Variables
3122 (defvar pr-txt-command nil
3123 "Name of program for printing a text file.
3124 See `pr-txt-printer-alist'.")
3127 (defvar pr-txt-switches nil
3128 "List of sexp's to pass as extra options to the text printer program.
3129 See `pr-txt-printer-alist'.")
3132 (defvar pr-txt-printer nil
3133 "Specify text printer name.
3134 See `pr-txt-printer-alist'.")
3137 (defvar pr-ps-command nil
3138 "Name of program for printing a PostScript file.
3139 See `pr-ps-printer-alist'.")
3142 (defvar pr-ps-switches nil
3143 "List of sexp's to pass as extra options to the PostScript printer program.
3144 See `pr-ps-printer-alist'.")
3147 (defvar pr-ps-printer-switch nil
3148 "Specify PostScript printer name switch.
3149 See `pr-ps-printer-alist'.")
3152 (defvar pr-ps-printer nil
3153 "Specify PostScript printer name.
3154 See `pr-ps-printer-alist'.")
3157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3158 ;; Macros
3161 (defmacro pr-save-file-modes (&rest body)
3162 "Set temporally file modes to `pr-file-modes'."
3163 `(let ((pr--default-file-modes (default-file-modes))) ; save default
3164 (set-default-file-modes pr-file-modes)
3165 ,@body
3166 (set-default-file-modes pr--default-file-modes))) ; restore default
3169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3170 ;; Keys & Menus
3173 (defsubst pr-visible-p (key)
3174 (memq key pr-visible-entry-list))
3177 (defsubst pr-mode-alist-p ()
3178 (cdr (assq major-mode pr-mode-alist)))
3181 (defsubst pr-auto-mode-p ()
3182 (and pr-auto-mode (pr-mode-alist-p)))
3185 (defsubst pr-using-ghostscript-p ()
3186 (and pr-print-using-ghostscript (not pr-spool-p)))
3189 (defalias 'pr-get-symbol
3190 (if (fboundp 'easy-menu-intern) ; hacked from easymenu.el
3191 'easy-menu-intern
3192 (lambda (s) (if (stringp s) (intern s) s))))
3195 (defconst pr-menu-spec
3196 ;; Menu mapping:
3197 ;; unfortunately XEmacs doesn't support :active for submenus,
3198 ;; only for items.
3199 ;; So, it uses :included instead of :active.
3200 ;; Also, XEmacs doesn't support :help tag.
3201 (let ((pr-:active (if (featurep 'xemacs)
3202 :included ; XEmacs
3203 :active)) ; GNU Emacs
3204 (pr-:help (if (featurep 'xemacs)
3205 'ignore ; XEmacs
3206 #'(lambda (text) (list :help text))))) ; GNU Emacs
3208 ["Printing Interface" pr-interface
3209 ,@(funcall
3210 pr-:help "Use buffer interface instead of menu interface")]
3211 "--"
3212 ("PostScript Preview" :included (pr-visible-p 'postscript)
3213 ,@(funcall
3214 pr-:help "Preview PostScript instead of sending to printer")
3215 ("Directory" ,pr-:active (not pr-spool-p)
3216 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
3217 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
3218 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
3219 ["Other..." (pr-ps-directory-preview nil nil nil t)
3220 :keys "\\[pr-ps-buffer-preview]"])
3221 ("Buffer" ,pr-:active (not pr-spool-p)
3222 ["1-up" (pr-ps-buffer-preview 1 t) t]
3223 ["2-up" (pr-ps-buffer-preview 2 t) t]
3224 ["4-up" (pr-ps-buffer-preview 4 t) t]
3225 ["Other..." (pr-ps-buffer-preview nil t)
3226 :keys "\\[pr-ps-buffer-preview]"])
3227 ("Region" ,pr-:active (and (not pr-spool-p) (ps-mark-active-p))
3228 ["1-up" (pr-ps-region-preview 1 t) t]
3229 ["2-up" (pr-ps-region-preview 2 t) t]
3230 ["4-up" (pr-ps-region-preview 4 t) t]
3231 ["Other..." (pr-ps-region-preview nil t)
3232 :keys "\\[pr-ps-region-preview]"])
3233 ("Mode" ,pr-:active (and (not pr-spool-p) (pr-mode-alist-p))
3234 ["1-up" (pr-ps-mode-preview 1 t) t]
3235 ["2-up" (pr-ps-mode-preview 2 t) t]
3236 ["4-up" (pr-ps-mode-preview 4 t) t]
3237 ["Other..." (pr-ps-mode-preview nil t)
3238 :keys "\\[pr-ps-mode-preview]"])
3239 ("File"
3240 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
3241 :keys "\\[pr-ps-file-preview]"
3242 ,@(funcall
3243 pr-:help "Preview PostScript file")]
3244 "--"
3245 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
3246 ,@(funcall
3247 pr-:help "Select PostScript utility")]
3248 "--"
3249 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
3250 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
3251 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
3252 ["Other..." (pr-ps-file-up-preview nil t t)
3253 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
3254 "--"
3255 ["Landscape" pr-toggle-file-landscape-menu
3256 :style toggle :selected pr-file-landscape
3257 ,@(funcall
3258 pr-:help "Toggle landscape for PostScript file")
3259 :active pr-ps-utility-alist]
3260 ["Duplex" pr-toggle-file-duplex-menu
3261 :style toggle :selected pr-file-duplex
3262 ,@(funcall
3263 pr-:help "Toggle duplex for PostScript file")
3264 :active pr-ps-utility-alist]
3265 ["Tumble" pr-toggle-file-tumble-menu
3266 :style toggle :selected pr-file-tumble
3267 ,@(funcall
3268 pr-:help "Toggle tumble for PostScript file")
3269 :active (and pr-file-duplex pr-ps-utility-alist)])
3270 ["Despool..." (call-interactively 'pr-despool-preview)
3271 :active pr-spool-p :keys "\\[pr-despool-preview]"
3272 ,@(funcall
3273 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3274 ("PostScript Print" :included (pr-visible-p 'postscript)
3275 ,@(funcall
3276 pr-:help "Send PostScript to printer or file (C-u)")
3277 ("Directory"
3278 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
3279 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
3280 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
3281 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
3282 :keys "\\[pr-ps-buffer-ps-print]"])
3283 ("Buffer"
3284 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
3285 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
3286 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
3287 ["Other..." (pr-ps-buffer-ps-print nil t)
3288 :keys "\\[pr-ps-buffer-ps-print]"])
3289 ("Region" ,pr-:active (ps-mark-active-p)
3290 ["1-up" (pr-ps-region-ps-print 1 t) t]
3291 ["2-up" (pr-ps-region-ps-print 2 t) t]
3292 ["4-up" (pr-ps-region-ps-print 4 t) t]
3293 ["Other..." (pr-ps-region-ps-print nil t)
3294 :keys "\\[pr-ps-region-ps-print]"])
3295 ("Mode" ,pr-:active (pr-mode-alist-p)
3296 ["1-up" (pr-ps-mode-ps-print 1 t) t]
3297 ["2-up" (pr-ps-mode-ps-print 2 t) t]
3298 ["4-up" (pr-ps-mode-ps-print 4 t) t]
3299 ["Other..." (pr-ps-mode-ps-print nil t)
3300 :keys "\\[pr-ps-mode-ps-print]"])
3301 ("File"
3302 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
3303 :keys "\\[pr-ps-file-ps-print]"
3304 ,@(funcall
3305 pr-:help "Send PostScript file to printer")]
3306 "--"
3307 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
3308 ,@(funcall
3309 pr-:help "Select PostScript utility")]
3310 "--"
3311 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
3312 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
3313 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
3314 ["Other..." (pr-ps-file-up-ps-print nil t t)
3315 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
3316 "--"
3317 ["Landscape" pr-toggle-file-landscape-menu
3318 :style toggle :selected pr-file-landscape
3319 ,@(funcall
3320 pr-:help "Toggle landscape for PostScript file")
3321 :active pr-ps-utility-alist]
3322 ["Duplex" pr-toggle-file-duplex-menu
3323 :style toggle :selected pr-file-duplex
3324 ,@(funcall
3325 pr-:help "Toggle duplex for PostScript file")
3326 :active pr-ps-utility-alist]
3327 ["Tumble" pr-toggle-file-tumble-menu
3328 :style toggle :selected pr-file-tumble
3329 ,@(funcall
3330 pr-:help "Toggle tumble for PostScript file")
3331 :active (and pr-file-duplex pr-ps-utility-alist)])
3332 ["Despool..." (call-interactively 'pr-despool-ps-print)
3333 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
3334 ,@(funcall
3335 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3336 ["PostScript Printers" pr-update-menus
3337 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
3338 ,@(funcall
3339 pr-:help "Select PostScript printer")]
3340 "--"
3341 ("Printify" :included (pr-visible-p 'text)
3342 ,@(funcall
3343 pr-:help
3344 "Replace non-printing chars with printable representations.")
3345 ["Directory" pr-printify-directory t]
3346 ["Buffer" pr-printify-buffer t]
3347 ["Region" pr-printify-region (ps-mark-active-p)])
3348 ("Print" :included (pr-visible-p 'text)
3349 ,@(funcall
3350 pr-:help "Send text to printer")
3351 ["Directory" pr-txt-directory t]
3352 ["Buffer" pr-txt-buffer t]
3353 ["Region" pr-txt-region (ps-mark-active-p)]
3354 ["Mode" pr-txt-mode (pr-mode-alist-p)])
3355 ["Text Printers" pr-update-menus
3356 :active pr-txt-printer-alist :included (pr-visible-p 'text)
3357 ,@(funcall
3358 pr-:help "Select text printer")]
3359 "--"
3360 ["Landscape" pr-toggle-landscape-menu
3361 :style toggle :selected ps-landscape-mode
3362 :included (pr-visible-p 'postscript-options)]
3363 ["Print Header" pr-toggle-header-menu
3364 :style toggle :selected ps-print-header
3365 :included (pr-visible-p 'postscript-options)]
3366 ["Print Header Frame" pr-toggle-header-frame-menu
3367 :style toggle :selected ps-print-header-frame :active ps-print-header
3368 :included (pr-visible-p 'postscript-options)]
3369 ["Line Number" pr-toggle-line-menu
3370 :style toggle :selected ps-line-number
3371 :included (pr-visible-p 'postscript-options)]
3372 ["Zebra Stripes" pr-toggle-zebra-menu
3373 :style toggle :selected ps-zebra-stripes
3374 :included (pr-visible-p 'postscript-options)]
3375 ["Duplex" pr-toggle-duplex-menu
3376 :style toggle :selected ps-spool-duplex
3377 :included (pr-visible-p 'postscript-options)]
3378 ["Tumble" pr-toggle-tumble-menu
3379 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
3380 :included (pr-visible-p 'postscript-options)]
3381 ["Upside-Down" pr-toggle-upside-down-menu
3382 :style toggle :selected ps-print-upside-down
3383 :included (pr-visible-p 'postscript-options)]
3384 ("Print All Pages" :included (pr-visible-p 'postscript-options)
3385 ,@(funcall
3386 pr-:help "Select odd/even pages/sheets to print")
3387 ["All Pages" (pr-even-or-odd-pages nil)
3388 :style radio :selected (eq ps-even-or-odd-pages nil)]
3389 ["Even Pages" (pr-even-or-odd-pages 'even-page)
3390 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
3391 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
3392 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
3393 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
3394 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
3395 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
3396 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
3397 "--"
3398 ["Spool Buffer" pr-toggle-spool-menu
3399 :style toggle :selected pr-spool-p
3400 :included (pr-visible-p 'postscript-process)
3401 ,@(funcall
3402 pr-:help "Toggle PostScript spooling")]
3403 ["Print with faces" pr-toggle-faces-menu
3404 :style toggle :selected pr-faces-p
3405 :included (pr-visible-p 'postscript-process)
3406 ,@(funcall
3407 pr-:help "Toggle PostScript printing with faces")]
3408 ["Print via Ghostscript" pr-toggle-ghostscript-menu
3409 :style toggle :selected pr-print-using-ghostscript
3410 :included (pr-visible-p 'postscript-process)
3411 ,@(funcall
3412 pr-:help "Toggle PostScript generation using ghostscript")]
3413 "--"
3414 ["Auto Region" pr-toggle-region-menu
3415 :style toggle :selected pr-auto-region
3416 :included (pr-visible-p 'printing)]
3417 ["Auto Mode" pr-toggle-mode-menu
3418 :style toggle :selected pr-auto-mode
3419 :included (pr-visible-p 'printing)]
3420 ["Menu Lock" pr-toggle-lock-menu
3421 :style toggle :selected pr-menu-lock
3422 :included (pr-visible-p 'printing)]
3423 "--"
3424 ("Customize" :included (pr-visible-p 'help)
3425 ["printing" pr-customize t]
3426 ["ps-print" ps-print-customize t]
3427 ["lpr" lpr-customize t])
3428 ("Show Settings" :included (pr-visible-p 'help)
3429 ["printing" pr-show-pr-setup t]
3430 ["ps-print" pr-show-ps-setup t]
3431 ["lpr" pr-show-lpr-setup t])
3432 ["Help" pr-help :active t :included (pr-visible-p 'help)]
3436 (defun pr-menu-bind ()
3437 "Install `printing' menu in the menubar.
3438 This replaces the File/Print* menu entries with a File/Print sub-menu.
3439 Calls `pr-update-menus' to adjust menus."
3440 (interactive)
3441 (pr-global-menubar pr-menu-spec)
3442 (pr-update-menus t))
3445 ;; Key binding
3446 (let ((pr-print-key (if (featurep 'xemacs)
3447 'f22 ; XEmacs
3448 'print))) ; GNU Emacs
3449 (global-set-key `[,pr-print-key] 'pr-ps-fast-fire)
3450 ;; Well, M-print and S-print are used because in my keyboard S-print works
3451 ;; and M-print doesn't. But M-print can work in other keyboard.
3452 (global-set-key `[(meta ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3453 (global-set-key `[(shift ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3454 ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
3455 ;; and C-print doesn't. But C-print can work in other keyboard.
3456 (global-set-key `[(control ,pr-print-key)] 'pr-txt-fast-fire)
3457 (global-set-key `[(control meta ,pr-print-key)] 'pr-txt-fast-fire))
3460 ;;; You can also use something like:
3461 ;;;(global-set-key "\C-ci" 'pr-interface)
3462 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
3463 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
3464 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
3465 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
3466 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
3467 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
3470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3471 ;; Help Message
3474 (defconst pr-help-message
3475 (concat "printing.el version " pr-version
3476 " ps-print.el version " ps-print-version
3477 "\n\n
3478 Menu Layout
3479 -----------
3481 The `printing' menu (Tools/Printing or File/Print) has the following layout:
3483 +-----------------------------+
3484 A 0 | Printing Interface |
3485 +-----------------------------+ +-A---------+ +-B------+
3486 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
3487 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
3488 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
3489 +-----------------------------+ |Mode >|-- B |Other...|
3490 II 4 | Printify >|-----\\ |File >|--\\ +--------+
3491 5 | Print >|---\\ | |Despool... | |
3492 6 | Text Printer: name >|-\\ | | +-----------+ |
3493 +-----------------------------+ | | | +---------+ +------------+
3494 III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
3495 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
3496 9 |[ ]Print Header Frame | | | |Region | | name >|- C
3497 10 |[ ]Line Number | | | +---------+ +------------+
3498 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
3499 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
3500 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
3501 14 |[ ]Upside-Down | | |Region | | Other... |
3502 15 | Print All Pages >|--\\ | |Mode | +------------+
3503 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
3504 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
3505 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
3506 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
3507 +-----------------------------+ | |... |
3508 V 19 |[ ]Auto Region | | |(*)name |
3509 20 |[ ]Auto Mode | | |... |
3510 21 |[ ]Menu Lock | | +---------+ +--------------+
3511 +-----------------------------+ \\------------------|(*)All Pages |
3512 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
3513 23 | Show Settings >|-------|printing| |( )Odd Pages |
3514 24 | Help | |ps-print| |( )Even Sheets|
3515 +-----------------------------+ |lpr | |( )Odd Sheets |
3516 +--------+ +--------------+
3518 See `pr-visible-entry-list' for hiding some parts of the menu.
3520 The menu has the following sections:
3522 A. Interface:
3524 0. You can use a buffer interface instead of menus. It looks like the
3525 customization buffer. Basically, it has the same options found in the
3526 menu and some extra options, all this on a buffer.
3528 I. PostScript printing:
3530 1. You can generate a PostScript file (if you type C-u before activating
3531 menu) or PostScript temporary file for a directory, a buffer, a region
3532 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
3533 after file generation, ghostview is activated using the file generated
3534 as argument. This option is disabled if spooling is on (option 16).
3535 Also, if you already have a PostScript file you can preview it.
3536 Instead of previewing each buffer, region or major mode at once, you
3537 can save temporarily the PostScript code generated in a buffer and
3538 preview it later. The option `Despool...' despools the PostScript
3539 spooling buffer in a temporary file and uses ghostview to preview it.
3540 If you type C-u before choosing this option, the PostScript code
3541 generated is saved in a file instead of saving in a temporary file. To
3542 spool the PostScript code generated you need to turn on the option 16.
3543 The option `Despool...' is enabled if spooling is on (option 16).
3545 NOTE 1: It's possible to customize a major mode printing, just declare
3546 the customization in `pr-mode-alist' and invoke some of
3547 `*-mode*' commands or select Mode option in Printing menu. An
3548 example for major mode usage is when you're using gnus (or mh,
3549 or rmail, etc.) and you're in the *Summary* buffer, if you
3550 forget to switch to the *Article* buffer before printing,
3551 you'll get a nicely formatted list of article subjects shows
3552 up at the printer. With major mode printing you don't need to
3553 switch from gnus *Summary* buffer first.
3555 NOTE 2: There are the following options for PostScript file processing:
3556 Ia. Print the file *No Preprocessing*, that is, send it
3557 directly to PostScript printer.
3558 Ib. PostScript utility processing selection.
3559 See `pr-ps-utility-alist' and `pr-setting-database' for
3560 documentation.
3561 Ic. Do n-up processing before printing.
3562 Id. Toggle on/off landscape for PostScript file processing.
3563 Ie. Toggle on/off duplex for PostScript file processing.
3564 If. Toggle on/off tumble for PostScript file processing.
3566 NOTE 3: Don't forget to download and install the utilities declared on
3567 `pr-ps-utility-alist'.
3569 2. Operate the same way as option 1, but it sends directly the PostScript
3570 code (or put in a file, if you've typed C-u) or it uses ghostscript to
3571 print the PostScript file generated. It depends on option 18, if it's
3572 turned on, it uses ghostscript; otherwise, it sends directly to
3573 printer. If spooling is on (option 16), the PostScript code is saved
3574 temporarily in a buffer instead of printing it or saving it in a file.
3575 Also, if you already have a PostScript file you can print it.
3576 Instead of printing each buffer, region or major mode at once, you can
3577 save temporarily the PostScript code generated in a buffer and print it
3578 later. The option `Despool...' despools the PostScript spooling buffer
3579 directly on a printer. If you type C-u before choosing this option,
3580 the PostScript code generated is saved in a file instead of sending it to
3581 the printer. To spool the PostScript code generated you need to turn on
3582 option 16. This option is enabled if spooling is on (option 16).
3583 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
3585 3. You can select a new PostScript printer to send PostScript code
3586 generated. For selection it's used all PostScript printers defined
3587 in `pr-ps-printer-alist' variable (see it for documentation).
3588 See also `pr-setting-database'.
3590 II. Text printing:
3592 4. If you have control characters (character code from \\000 to \\037) in a
3593 buffer and you want to print them in a text printer, select this
3594 option. All control characters in your buffer or region will be
3595 replaced by a printable representation. The printable representations
3596 use ^ (for ASCII control characters) or hex. The characters tab,
3597 linefeed, space, return and formfeed are not affected.
3598 You don't need to select this option if you use any option of section
3599 I, the PostScript engine treats control characters properly.
3601 5. If you want to print a directory, buffer, region or major mode in a
3602 text printer, select this option. See also the NOTE 1 on option 1.
3604 6. You can select a new text printer to send text generated. For
3605 selection it's used all text printers defined in `pr-txt-printer-alist'
3606 variable (see it for documentation).
3607 See also `pr-setting-database'.
3609 III. PostScript page toggle options:
3611 7. If you want a PostScript landscape printing, turn on this option.
3613 8. If you want to have a header in each page in your PostScript code,
3614 turn on this option.
3616 9. If you want to draw a gaudy frame around the header, turn on this
3617 option. This option is enabled if print header is on (option 8).
3619 10. If you want that the line number is printed in your PostScript code,
3620 turn on this option.
3622 11. If you want background zebra stripes in your PostScript code, turn on
3623 this option.
3625 12. If you want a duplex printing and your PostScript printer has this
3626 feature, turn on this option.
3628 13. If you turned on duplex printing, you can choose if you want to have a
3629 printing suitable for binding on the left or right (tumble off), or to
3630 have a printing suitable for binding at top or bottom (tumble on).
3631 This option is enabled if duplex is on (option 12).
3633 14. If you want a PostScript upside-down printing, turn on this option.
3635 15. With this option, you can choose if you want to print all pages, odd
3636 pages, even pages, odd sheets or even sheets.
3637 See also `ps-even-or-odd-pages'.
3639 IV. PostScript processing toggle options:
3641 16. If you want to spool the PostScript code generated, turn on this
3642 option. To spool the PostScript code generated use option 2. You can
3643 despool later by choosing option 1 or 2, sub-option `Despool...'.
3645 17. If you use colors in your buffers and want to see these colors on your
3646 PostScript code generated, turn on this option. If you have a
3647 black/white PostScript printer, these colors are displayed in gray
3648 scale by PostScript printer interpreter.
3650 18. If you don't have a PostScript printer to send PostScript files, turn
3651 on this option. When this option is on, the ghostscript is used to
3652 print PostScript files. In GNU or Unix system, if ghostscript is set
3653 as a PostScript filter, you don't need to turn on this option.
3655 V. Printing customization:
3657 19. If you want that region is automagically detected, turn on this
3658 option. Note that this will only work if you're using transient mark
3659 mode. When this option is on, the `*-buffer*' commands will behave
3660 like `*-region*' commands, that is, `*-buffer*' commands will print
3661 only the region marked instead of all buffer.
3663 20. Turn this option on if you want that when current major-mode is
3664 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3665 behave like `*-mode*' commands.
3667 21. If you want that Printing menu stays open while you are setting
3668 toggle options, turn on this option. The variables
3669 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3670 menu position, so don't forget to adjust these variables if menu
3671 position is not ok.
3673 VI. Customization:
3675 22. Besides all options in section III, IV and V, you can customize much
3676 more PostScript options in `ps-print' option. Or you can customize
3677 some `lpr' options for text printing. Or customize `printing'
3678 options.
3680 23. Show current settings for `printing', `ps-print' or `lpr'.
3682 24. Quick help for printing menu layout.
3684 "Printing help message.")
3687 (defconst pr-interface-help-message
3688 (concat "printing.el version " pr-version
3689 " ps-print.el version " ps-print-version
3690 "\n\n
3691 The printing interface buffer has the same functionality as the printing menu.
3692 The major difference is that the states (like sending PostScript generated to a
3693 file, n-up printing, etc.) are set and saved between printing buffer
3694 activation. Also, the landscape, duplex and tumble values are the same for
3695 PostScript file and directory/buffer/region/mode processing; using menu, there
3696 are different value sets for PostScript file and directory/buffer/region/mode
3697 processing.
3699 The printing interface buffer has the following sections:
3701 1. Print:
3703 Here you can choose to print/preview a buffer, a directory or a PostScript
3704 file:
3706 1a. Buffer:
3708 * Buffer List:
3709 Select a buffer from the current buffer list.
3711 * Region:
3712 If it's on, this means that the selected buffer has an active region,
3713 so you can turn on/off, as you wish.
3714 If it's off when a buffer is selected, this means that the selected
3715 buffer has no active region, so it'll not be possible to turn it on.
3716 If you want to process the region, let this option on.
3717 If you want to process the whole buffer, let this option off.
3719 * Mode:
3720 If it's on, this means that the selected buffer major mode is declared
3721 for major mode processing, so you can turn on/off, as you wish.
3722 If it's off when a buffer is selected, this means that the selected
3723 buffer major mode isn't declared for major mode processing, so it'll
3724 not be possible to turn it on.
3725 If you want the major mode processing, let this option on.
3726 If you don't want the major mode processing, let this option off.
3728 NOTE 1: It's possible to customize a major mode printing, just declare
3729 the customization in `pr-mode-alist' and invoke some of
3730 `*-mode*' commands or select Mode option in Printing menu. An
3731 example for major mode usage is when you're using gnus (or mh,
3732 or rmail, etc.) and you're in the *Summary* buffer, if you
3733 forget to switch to the *Article* buffer before printing,
3734 you'll get a nicely formatted list of article subjects shows
3735 up at the printer. With major mode printing you don't need to
3736 switch from gnus *Summary* buffer first.
3738 1b. Directory:
3740 * Directory:
3741 Specify a valid directory path.
3743 * File Regexp:
3744 Specify a file name regexp. All file names in the directory that
3745 match with regexp will be printed/previewed. An empty file name
3746 regexp means to print/preview all files in the directory.
3748 * List Directory Entry:
3749 If it's turned on, list directory entries besides file entries.
3751 1c. PostScript file:
3753 * PostScript File:
3754 Specify an existent PostScript file to print/preview.
3756 * PostScript Utility:
3757 Select a PostScript utility.
3758 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3760 NOTE 2: Don't forget to download and install the utilities declared on
3761 `pr-ps-utility-alist'.
3763 * No Preprocessing:
3764 If it's turned on, don't use the PostScript utility to preprocess the
3765 PostScript file before printing/previewing.
3767 2. PostScript printer:
3769 * PostScript Printer:
3770 You can select a new PostScript printer to send PostScript code
3771 generated. For selection it's used all PostScript printers defined
3772 in `pr-ps-printer-alist' variable (see it for documentation).
3773 See also `pr-setting-database'.
3775 * Despool:
3776 If spooling is on, you can turn it on/off, as you wish.
3777 If spooling is off, it'll not be possible to turn it on.
3778 If it's turned on, specify to despools the PostScript spooling buffer in
3779 a temporary file or in the selected PostScript file when
3780 printing/previewing.
3782 * Preview:
3783 Preview the PostScript generated.
3785 * Print:
3786 Print the PostScript generated.
3788 * Quit:
3789 Quit from printing interface buffer.
3791 * Send to Printer/Temporary File:
3792 If it's turned on, the PostScript generated is sent directly to
3793 PostScript printer or, for previewing, to a temporary file.
3795 * Send to File:
3796 Specify a file name to send the PostScript generated.
3798 * N-Up:
3799 Specify n-up printing.
3801 3. Text printer:
3803 * Text Printer:
3804 Select a new text printer to send text generated. For selection it's used
3805 all text printers defined in `pr-txt-printer-alist' variable (see it for
3806 documentation). See also `pr-setting-database'.
3808 * Printify:
3809 If you have control characters (character code from \\000 to \\037) in a
3810 buffer and you want to print them in a text printer, select this
3811 option. All control characters in your buffer or region will be
3812 replaced by a printable representation. The printable representations
3813 use ^ (for ASCII control characters) or hex. The characters tab,
3814 linefeed, space, return and formfeed are not affected.
3815 You don't need to select this option if you use any option of section
3816 I, the PostScript engine treats control characters properly.
3818 * Print:
3819 To print a directory, buffer, region or major mode in a
3820 text printer, select this option. See also the NOTE 1 on section 1.
3822 * Quit:
3823 Quit from printing interface buffer.
3825 4. Settings:
3827 There are 3 setting columns:
3829 4a. First column (left column):
3831 * Landscape:
3832 PostScript landscape printing.
3834 * Print Header:
3835 To have a header in each page in your PostScript code.
3837 * Print Header Frame:
3838 To draw a gaudy frame around the header.
3840 * Line Number:
3841 The line number is printed in your PostScript code.
3843 * Zebra Stripes:
3844 Background zebra stripes in your PostScript code.
3846 * Duplex:
3847 Duplex printing (if your PostScript printer has this feature).
3849 * Tumble:
3850 If duplex printing is on, you can choose if you want to have a
3851 printing suitable for binding on the left or right (tumble off), or to
3852 have a printing suitable for binding at top or bottom (tumble on).
3854 * Upside-Down:
3855 PostScript upside-down printing.
3857 4b. Second column (middle column):
3859 * Auto Region:
3860 If you want that region is automagically detected, turn on this
3861 option. Note that this will only work if you're using transient mark
3862 mode. When this option is on, the `*-buffer*' commands will behave
3863 like `*-region*' commands, that is, `*-buffer*' commands will print
3864 only the region marked instead of all buffer.
3866 * Auto Mode:
3867 Turn this option on if you want that when current major-mode is
3868 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3869 behave like `*-mode*' commands.
3871 * Menu Lock:
3872 If you want that Printing menu stays open while you are setting
3873 toggle options, turn on this option. The variables
3874 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3875 menu position, so don't forget to adjust these variables if menu
3876 position is not ok.
3878 * Spool Buffer:
3879 To spool the PostScript code generated. You can despool later by
3880 setting Despool option on PostScript printer section.
3882 * Print with faces:
3883 If you use colors in your buffers and want to see these colors on your
3884 PostScript code generated, turn on this option. If you have a
3885 black/white PostScript printer, these colors are displayed in gray
3886 scale by PostScript printer interpreter.
3888 * Print via Ghostscript:
3889 If you don't have a PostScript printer to send PostScript files, turn
3890 on this option. When this option is on, the ghostscript is used to
3891 print PostScript files. In GNU or Unix system, if ghostscript is set
3892 as a PostScript filter, you don't need to turn on this option.
3894 * Parity Page Menu:
3895 To print all pages, odd pages, even pages, odd sheets or even sheets.
3896 See also `ps-even-or-odd-pages'.
3898 4c. Third column (right column):
3900 * Verbose:
3901 That is, to be verbose when editing a field in interface buffer.
3903 5. Customize:
3905 Besides all options in section 4, you can customize much more PostScript
3906 options in `ps-print' option. Or you can customize some `lpr' options for
3907 text printing. Or customize `printing' options.
3909 6. Show settings:
3911 Show current settings for `printing', `ps-print' or `lpr'.
3913 7. Help:
3915 Quick help for printing interface buffer and printing menu layout. You can
3916 also quit the printing interface buffer or kill all printing help buffer.
3918 "Printing buffer interface help message.")
3921 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3922 ;; Commands
3925 ;;;###autoload
3926 (defun pr-interface (&optional buffer)
3927 "Activate the printing interface buffer.
3929 If BUFFER is nil, the current buffer is used for printing.
3931 For more information, type \\[pr-interface-help]."
3932 (interactive)
3933 (with-current-buffer (or buffer (current-buffer))
3934 (pr-create-interface)))
3937 ;;;###autoload
3938 (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3939 "Preview directory using ghostview.
3941 Interactively, the command prompts for N-UP printing number, a directory, a
3942 file name regexp for matching and, when you use a prefix argument (C-u), the
3943 command prompts the user for a file name, and saves the PostScript image in
3944 that file instead of saving it in a temporary file.
3946 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3947 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3948 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3949 save the image in a temporary file. If FILENAME is a string, save the
3950 PostScript image in a file with that name. If FILENAME is t, prompts for a
3951 file name.
3953 See also documentation for `pr-list-directory'."
3954 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3955 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3956 (pr-prompt "PS preview dir"))
3957 (setq filename (pr-ps-file filename))
3958 (pr-ps-file-list n-up dir file-regexp filename)
3959 (or pr-spool-p
3960 (pr-ps-file-preview filename)))
3963 ;;;###autoload
3964 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3965 "Print directory using PostScript through ghostscript.
3967 Interactively, the command prompts for N-UP printing number, a directory, a
3968 file name regexp for matching and, when you use a prefix argument (C-u), the
3969 command prompts the user for a file name, and saves the PostScript image in
3970 that file instead of saving it in a temporary file.
3972 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3973 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3974 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3975 save the image in a temporary file. If FILENAME is a string, save the
3976 PostScript image in a file with that name. If FILENAME is t, prompts for a
3977 file name.
3979 See also documentation for `pr-list-directory'."
3980 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3981 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3982 (pr-prompt "PS print dir GS"))
3983 (let ((file (pr-ps-file filename)))
3984 (pr-ps-file-list n-up dir file-regexp file)
3985 (pr-ps-file-using-ghostscript file)
3986 (or filename (pr-delete-file file))))
3989 ;;;###autoload
3990 (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
3991 "Print directory using PostScript printer.
3993 Interactively, the command prompts for N-UP printing number, a directory, a
3994 file name regexp for matching and, when you use a prefix argument (C-u), the
3995 command prompts the user for a file name, and saves the PostScript image in
3996 that file instead of saving it in a temporary file.
3998 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3999 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4000 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4001 save the image in a temporary file. If FILENAME is a string, save the
4002 PostScript image in a file with that name. If FILENAME is t, prompts for a
4003 file name.
4005 See also documentation for `pr-list-directory'."
4006 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
4007 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4008 (pr-prompt "PS print dir"))
4009 (let ((file (pr-ps-file filename)))
4010 (pr-ps-file-list n-up dir file-regexp file)
4011 (pr-ps-file-print file)
4012 (or filename (pr-delete-file file))))
4015 ;;;###autoload
4016 (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
4017 "Print directory using PostScript printer or through ghostscript.
4019 It depends on `pr-print-using-ghostscript'.
4021 Interactively, the command prompts for N-UP printing number, a directory, a
4022 file name regexp for matching and, when you use a prefix argument (C-u), the
4023 command prompts the user for a file name, and saves the PostScript image in
4024 that file instead of saving it in a temporary file.
4026 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4027 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4028 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4029 save the image in a temporary file. If FILENAME is a string, save the
4030 PostScript image in a file with that name. If FILENAME is t, prompts for a
4031 file name.
4033 See also documentation for `pr-list-directory'."
4034 (interactive (pr-interactive-ps-dir-args
4035 (pr-prompt (pr-prompt-gs "PS print dir"))))
4036 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4037 (pr-prompt (pr-prompt-gs "PS print dir")))
4038 (if (pr-using-ghostscript-p)
4039 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
4040 (pr-ps-directory-print n-up dir file-regexp filename)))
4043 ;;;###autoload
4044 (defun pr-ps-buffer-preview (n-up &optional filename)
4045 "Preview buffer using ghostview.
4047 Interactively, the command prompts for N-UP printing number and, when you use a
4048 prefix argument (C-u), the command prompts the user for a file name, and saves
4049 the PostScript image in that file instead of saving it in a temporary file.
4051 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4052 argument FILENAME is treated as follows: if it's nil, save the image in a
4053 temporary file. If FILENAME is a string, save the PostScript image in a file
4054 with that name. If FILENAME is t, prompts for a file name."
4055 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
4056 (if (pr-auto-mode-p)
4057 (pr-ps-mode-preview n-up filename)
4058 (pr-ps-preview (pr-region-active-symbol) n-up filename
4059 (pr-region-active-string "PS preview"))))
4062 ;;;###autoload
4063 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
4064 "Print buffer using PostScript through ghostscript.
4066 Interactively, the command prompts for N-UP printing number and, when you use a
4067 prefix argument (C-u), the command prompts the user for a file name, and saves
4068 the PostScript image in that file instead of sending it to the printer.
4070 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4071 argument FILENAME is treated as follows: if it's nil, send the image to the
4072 printer. If FILENAME is a string, save the PostScript image in a file with
4073 that name. If FILENAME is t, prompts for a file name."
4074 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
4075 (if (pr-auto-mode-p)
4076 (pr-ps-mode-using-ghostscript n-up filename)
4077 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4078 (pr-region-active-string "PS print GS"))))
4081 ;;;###autoload
4082 (defun pr-ps-buffer-print (n-up &optional filename)
4083 "Print buffer using PostScript printer.
4085 Interactively, the command prompts for N-UP printing number and, when you use a
4086 prefix argument (C-u), the command prompts the user for a file name, and saves
4087 the PostScript image in that file instead of sending it to the printer.
4089 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4090 argument FILENAME is treated as follows: if it's nil, send the image to the
4091 printer. If FILENAME is a string, save the PostScript image in a file with
4092 that name. If FILENAME is t, prompts for a file name."
4093 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
4094 (if (pr-auto-mode-p)
4095 (pr-ps-mode-print n-up filename)
4096 (pr-ps-print (pr-region-active-symbol) n-up filename
4097 (pr-region-active-string "PS print"))))
4100 ;;;###autoload
4101 (defun pr-ps-buffer-ps-print (n-up &optional filename)
4102 "Print buffer using PostScript printer or through ghostscript.
4104 It depends on `pr-print-using-ghostscript'.
4106 Interactively, the command prompts for N-UP printing number and, when you use a
4107 prefix argument (C-u), the command prompts the user for a file name, and saves
4108 the PostScript image in that file instead of sending it to the printer.
4110 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4111 argument FILENAME is treated as follows: if it's nil, send the image to the
4112 printer. If FILENAME is a string, save the PostScript image in a file with
4113 that name. If FILENAME is t, prompts for a file name."
4114 (interactive (pr-interactive-n-up-file
4115 (pr-prompt (pr-prompt-gs "PS print"))))
4116 (cond ((pr-auto-mode-p)
4117 (pr-ps-mode-ps-print n-up filename))
4118 ((pr-using-ghostscript-p)
4119 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4120 (pr-region-active-string "PS print GS")))
4122 (pr-ps-print (pr-region-active-symbol) n-up filename
4123 (pr-region-active-string "PS print")))))
4126 ;;;###autoload
4127 (defun pr-ps-region-preview (n-up &optional filename)
4128 "Preview region using ghostview.
4130 See also `pr-ps-buffer-preview'."
4131 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
4132 (if (pr-auto-mode-p)
4133 (let ((pr-auto-region t))
4134 (pr-ps-mode-preview n-up filename))
4135 (pr-ps-preview 'region n-up filename "PS preview region")))
4138 ;;;###autoload
4139 (defun pr-ps-region-using-ghostscript (n-up &optional filename)
4140 "Print region using PostScript through ghostscript.
4142 See also `pr-ps-buffer-using-ghostscript'."
4143 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
4144 (if (pr-auto-mode-p)
4145 (let ((pr-auto-region t))
4146 (pr-ps-mode-using-ghostscript n-up filename))
4147 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
4150 ;;;###autoload
4151 (defun pr-ps-region-print (n-up &optional filename)
4152 "Print region using PostScript printer.
4154 See also `pr-ps-buffer-print'."
4155 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
4156 (if (pr-auto-mode-p)
4157 (let ((pr-auto-region t))
4158 (pr-ps-mode-print n-up filename))
4159 (pr-ps-print 'region n-up filename "PS print region")))
4162 ;;;###autoload
4163 (defun pr-ps-region-ps-print (n-up &optional filename)
4164 "Print region using PostScript printer or through ghostscript.
4166 See also `pr-ps-buffer-ps-print'."
4167 (interactive (pr-interactive-n-up-file
4168 (pr-prompt-region (pr-prompt-gs "PS print"))))
4169 (cond ((pr-auto-mode-p)
4170 (let ((pr-auto-region t))
4171 (pr-ps-mode-ps-print n-up filename)))
4172 ((pr-using-ghostscript-p)
4173 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
4175 (pr-ps-print 'region n-up filename "PS print region"))))
4178 ;;;###autoload
4179 (defun pr-ps-mode-preview (n-up &optional filename)
4180 "Preview major mode using ghostview.
4182 See also `pr-ps-buffer-preview'."
4183 (interactive (pr-interactive-n-up-file "PS preview mode"))
4184 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
4185 (let ((file (pr-ps-file filename)))
4186 (and (pr-ps-mode n-up file)
4187 (not pr-spool-p)
4188 (pr-ps-file-preview file))))
4191 ;;;###autoload
4192 (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
4193 "Print major mode using PostScript through ghostscript.
4195 See also `pr-ps-buffer-using-ghostscript'."
4196 (interactive (pr-interactive-n-up-file "PS print GS mode"))
4197 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
4198 (let ((file (pr-ps-file filename)))
4199 (when (and (pr-ps-mode n-up file)
4200 (not pr-spool-p))
4201 (pr-ps-file-using-ghostscript file)
4202 (or filename (pr-delete-file file)))))
4205 ;;;###autoload
4206 (defun pr-ps-mode-print (n-up &optional filename)
4207 "Print major mode using PostScript printer.
4209 See also `pr-ps-buffer-print'."
4210 (interactive (pr-interactive-n-up-file "PS print mode"))
4211 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
4212 (pr-ps-mode n-up filename))
4215 ;;;###autoload
4216 (defun pr-ps-mode-ps-print (n-up &optional filename)
4217 "Print major mode using PostScript or through ghostscript.
4219 See also `pr-ps-buffer-ps-print'."
4220 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
4221 (if (pr-using-ghostscript-p)
4222 (pr-ps-mode-using-ghostscript n-up filename)
4223 (pr-ps-mode-print n-up filename)))
4226 ;;;###autoload
4227 (defun pr-printify-directory (&optional dir file-regexp)
4228 "Replace nonprinting characters in directory with printable representations.
4229 The printable representations use ^ (for ASCII control characters) or hex.
4230 The characters tab, linefeed, space, return and formfeed are not affected.
4232 Interactively, the command prompts for a directory and a file name regexp for
4233 matching.
4235 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4236 prompts for FILE(name)-REGEXP.
4238 See also documentation for `pr-list-directory'."
4239 (interactive (pr-interactive-dir-args "Printify dir"))
4240 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
4241 (pr-file-list dir file-regexp 'pr-printify-buffer))
4244 ;;;###autoload
4245 (defun pr-printify-buffer ()
4246 "Replace nonprinting characters in buffer with printable representations.
4247 The printable representations use ^ (for ASCII control characters) or hex.
4248 The characters tab, linefeed, space, return and formfeed are not affected."
4249 (interactive "*")
4250 (if (pr-region-active-p)
4251 (pr-printify-region)
4252 (printify-region (point-min) (point-max))))
4255 ;;;###autoload
4256 (defun pr-printify-region ()
4257 "Replace nonprinting characters in region with printable representations.
4258 The printable representations use ^ (for ASCII control characters) or hex.
4259 The characters tab, linefeed, space, return and formfeed are not affected."
4260 (interactive "*")
4261 (printify-region (point) (mark)))
4264 ;;;###autoload
4265 (defun pr-txt-directory (&optional dir file-regexp)
4266 "Print directory using text printer.
4268 Interactively, the command prompts for a directory and a file name regexp for
4269 matching.
4271 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4272 prompts for FILE(name)-REGEXP.
4274 See also documentation for `pr-list-directory'."
4275 (interactive (pr-interactive-dir-args "Print dir"))
4276 (pr-set-dir-args 'dir 'file-regexp "Print dir")
4277 (pr-file-list dir file-regexp 'pr-txt-buffer))
4280 ;;;###autoload
4281 (defun pr-txt-buffer ()
4282 "Print buffer using text printer."
4283 (interactive)
4284 (cond ((pr-auto-mode-p)
4285 (pr-txt-mode))
4286 ((pr-region-active-p)
4287 (pr-txt-region))
4289 (pr-txt-print (point-min) (point-max)))))
4292 ;;;###autoload
4293 (defun pr-txt-region ()
4294 "Print region using text printer."
4295 (interactive)
4296 (if (pr-auto-mode-p)
4297 (let ((pr-auto-region t))
4298 (pr-txt-mode))
4299 (pr-txt-print (point) (mark))))
4302 ;;;###autoload
4303 (defun pr-txt-mode ()
4304 "Print major mode using text printer."
4305 (interactive)
4306 (let ((args (pr-mode-alist-p)))
4307 (if args
4308 (funcall (car args) (nthcdr 2 args))
4309 (ding)
4310 (message "`%s' major mode not declared." major-mode))))
4313 ;;;###autoload
4314 (defun pr-despool-preview (&optional filename)
4315 "Preview spooled PostScript.
4317 Interactively, when you use a prefix argument (C-u), the command prompts the
4318 user for a file name, and saves the spooled PostScript image in that file
4319 instead of saving it in a temporary file.
4321 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4322 save the image in a temporary file. If FILENAME is a string, save the
4323 PostScript image in a file with that name."
4324 (interactive (list (ps-print-preprint current-prefix-arg)))
4325 (let ((file (pr-ps-file filename)))
4326 (when (stringp file)
4327 (pr-despool-print file)
4328 (pr-ps-file-preview file))))
4331 ;;;###autoload
4332 (defun pr-despool-using-ghostscript (&optional filename)
4333 "Print spooled PostScript using ghostscript.
4335 Interactively, when you use a prefix argument (C-u), the command prompts the
4336 user for a file name, and saves the spooled PostScript image in that file
4337 instead of sending it to the printer.
4339 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4340 send the image to the printer. If FILENAME is a string, save the PostScript
4341 image in a file with that name."
4342 (interactive (list (ps-print-preprint current-prefix-arg)))
4343 (let ((file (pr-ps-file filename)))
4344 (when (stringp file)
4345 (pr-despool-print file)
4346 (pr-ps-file-using-ghostscript file)
4347 (or filename (pr-delete-file file)))))
4350 ;;;###autoload
4351 (defun pr-despool-print (&optional filename)
4352 "Send the spooled PostScript to the printer.
4354 Interactively, when you use a prefix argument (C-u), the command prompts the
4355 user for a file name, and saves the spooled PostScript image in that file
4356 instead of sending it to the printer.
4358 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4359 send the image to the printer. If FILENAME is a string, save the PostScript
4360 image in a file with that name."
4361 (interactive (list (ps-print-preprint current-prefix-arg)))
4362 (pr-save-file-modes
4363 (let ((ps-lpr-command (pr-command pr-ps-command))
4364 (ps-lpr-switches pr-ps-switches)
4365 (ps-printer-name-option pr-ps-printer-switch)
4366 (ps-printer-name pr-ps-printer))
4367 (ps-despool filename))))
4370 ;;;###autoload
4371 (defun pr-despool-ps-print (&optional filename)
4372 "Send the spooled PostScript to the printer or use ghostscript to print it.
4374 Interactively, when you use a prefix argument (C-u), the command prompts the
4375 user for a file name, and saves the spooled PostScript image in that file
4376 instead of sending it to the printer.
4378 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4379 send the image to the printer. If FILENAME is a string, save the PostScript
4380 image in a file with that name."
4381 (interactive (list (ps-print-preprint current-prefix-arg)))
4382 (if pr-print-using-ghostscript
4383 (pr-despool-using-ghostscript filename)
4384 (pr-despool-print filename)))
4387 ;;;###autoload
4388 (defun pr-ps-file-preview (filename)
4389 "Preview PostScript file FILENAME."
4390 (interactive (list (pr-ps-infile-preprint "Preview ")))
4391 (and (stringp filename) (file-exists-p filename)
4392 (pr-call-process pr-gv-command filename)))
4395 ;;;###autoload
4396 (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
4397 "Preview PostScript file FILENAME."
4398 (interactive (pr-interactive-n-up-inout "PS preview"))
4399 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4400 "PS preview ")))
4401 (pr-ps-utility-process n-up ifilename outfile)
4402 (pr-ps-file-preview outfile)))
4405 ;;;###autoload
4406 (defun pr-ps-file-using-ghostscript (filename)
4407 "Print PostScript file FILENAME using ghostscript."
4408 (interactive (list (pr-ps-infile-preprint "Print preview ")))
4409 (and (stringp filename) (file-exists-p filename)
4410 (let* ((file (pr-expand-file-name filename))
4411 (tempfile (pr-dosify-file-name (make-temp-file file))))
4412 ;; gs use
4413 (pr-call-process pr-gs-command
4414 (format "-sDEVICE=%s" pr-gs-device)
4415 (format "-r%d" pr-gs-resolution)
4416 (pr-switches-string pr-gs-switches "pr-gs-switches")
4417 (format "-sOutputFile=\"%s\"" tempfile)
4418 file
4419 "-c quit")
4420 ;; printing
4421 (pr-ps-file-print tempfile)
4422 ;; deleting
4423 (pr-delete-file tempfile))))
4426 ;;;###autoload
4427 (defun pr-ps-file-print (filename)
4428 "Print PostScript file FILENAME."
4429 (interactive (list (pr-ps-infile-preprint "Print ")))
4430 (and (stringp filename) (file-exists-p filename)
4431 ;; printing
4432 (let ((file (pr-expand-file-name filename)))
4433 (if (string= pr-ps-command "")
4434 ;; default action
4435 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
4436 (with-current-buffer ps-spool-buffer
4437 (erase-buffer)
4438 (insert-file-contents-literally file))
4439 (pr-despool-print))
4440 ;; use `pr-ps-command' to print
4441 (apply 'pr-call-process
4442 pr-ps-command
4443 (pr-switches-string pr-ps-switches "pr-ps-switches")
4444 (if (string-match "cp" pr-ps-command)
4445 ;; for "cp" (cmd in out)
4446 (list file
4447 (concat pr-ps-printer-switch pr-ps-printer))
4448 ;; else, for others (cmd out in)
4449 (list (concat pr-ps-printer-switch pr-ps-printer)
4450 file)))))))
4453 ;;;###autoload
4454 (defun pr-ps-file-ps-print (filename)
4455 "Send PostScript file FILENAME to printer or use ghostscript to print it."
4456 (interactive (list (pr-ps-infile-preprint
4457 (if pr-print-using-ghostscript
4458 "Print preview "
4459 "Print "))))
4460 (if pr-print-using-ghostscript
4461 (pr-ps-file-using-ghostscript filename)
4462 (pr-ps-file-print filename)))
4465 ;;;###autoload
4466 (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
4467 "Process a PostScript file IFILENAME and send it to printer.
4469 Interactively, the command prompts for N-UP printing number, for an input
4470 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
4471 command prompts the user for an output PostScript file name OFILENAME, and
4472 saves the PostScript image in that file instead of sending it to the printer.
4474 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4475 argument IFILENAME is treated as follows: if it's t, prompts for an input
4476 PostScript file name; otherwise, it *must* be a string that it's an input
4477 PostScript file name. The argument OFILENAME is treated as follows: if it's
4478 nil, send the image to the printer. If OFILENAME is a string, save the
4479 PostScript image in a file with that name. If OFILENAME is t, prompts for a
4480 file name."
4481 (interactive (pr-interactive-n-up-inout
4482 (if pr-print-using-ghostscript
4483 "PS print GS"
4484 "PS print")))
4485 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4486 (if pr-print-using-ghostscript
4487 "PS print GS "
4488 "PS print "))))
4489 (pr-ps-utility-process n-up ifilename outfile)
4490 (unless ofilename
4491 (pr-ps-file-ps-print outfile)
4492 (pr-delete-file outfile))))
4495 ;;;###autoload
4496 (defun pr-toggle-file-duplex ()
4497 "Toggle duplex for PostScript file."
4498 (interactive)
4499 (pr-toggle-file-duplex-menu t))
4502 ;;;###autoload
4503 (defun pr-toggle-file-tumble ()
4504 "Toggle tumble for PostScript file.
4506 If tumble is off, produces a printing suitable for binding on the left or
4507 right.
4508 If tumble is on, produces a printing suitable for binding at the top or
4509 bottom."
4510 (interactive)
4511 (pr-toggle-file-tumble-menu t))
4514 ;;;###autoload
4515 (defun pr-toggle-file-landscape ()
4516 "Toggle landscape for PostScript file."
4517 (interactive)
4518 (pr-toggle-file-landscape-menu t))
4521 ;;;###autoload
4522 (defun pr-toggle-ghostscript ()
4523 "Toggle printing using ghostscript."
4524 (interactive)
4525 (pr-toggle-ghostscript-menu t))
4528 ;;;###autoload
4529 (defun pr-toggle-faces ()
4530 "Toggle printing with faces."
4531 (interactive)
4532 (pr-toggle-faces-menu t))
4535 ;;;###autoload
4536 (defun pr-toggle-spool ()
4537 "Toggle spooling."
4538 (interactive)
4539 (pr-toggle-spool-menu t))
4542 ;;;###autoload
4543 (defun pr-toggle-duplex ()
4544 "Toggle duplex."
4545 (interactive)
4546 (pr-toggle-duplex-menu t))
4549 ;;;###autoload
4550 (defun pr-toggle-tumble ()
4551 "Toggle tumble.
4553 If tumble is off, produces a printing suitable for binding on the left or
4554 right.
4555 If tumble is on, produces a printing suitable for binding at the top or
4556 bottom."
4557 (interactive)
4558 (pr-toggle-tumble-menu t))
4561 ;;;###autoload
4562 (defun pr-toggle-landscape ()
4563 "Toggle landscape."
4564 (interactive)
4565 (pr-toggle-landscape-menu t))
4568 ;;;###autoload
4569 (defun pr-toggle-upside-down ()
4570 "Toggle upside-down."
4571 (interactive)
4572 (pr-toggle-upside-down-menu t))
4575 ;;;###autoload
4576 (defun pr-toggle-line ()
4577 "Toggle line number."
4578 (interactive)
4579 (pr-toggle-line-menu t))
4582 ;;;###autoload
4583 (defun pr-toggle-zebra ()
4584 "Toggle zebra stripes."
4585 (interactive)
4586 (pr-toggle-zebra-menu t))
4589 ;;;###autoload
4590 (defun pr-toggle-header ()
4591 "Toggle printing header."
4592 (interactive)
4593 (pr-toggle-header-menu t))
4596 ;;;###autoload
4597 (defun pr-toggle-header-frame ()
4598 "Toggle printing header frame."
4599 (interactive)
4600 (pr-toggle-header-frame-menu t))
4603 ;;;###autoload
4604 (defun pr-toggle-lock ()
4605 "Toggle menu lock."
4606 (interactive)
4607 (pr-toggle-lock-menu t))
4610 ;;;###autoload
4611 (defun pr-toggle-region ()
4612 "Toggle whether the region is automagically detected."
4613 (interactive)
4614 (pr-toggle-region-menu t))
4617 ;;;###autoload
4618 (defun pr-toggle-mode ()
4619 "Toggle auto mode."
4620 (interactive)
4621 (pr-toggle-mode-menu t))
4624 ;;;###autoload
4625 (defun pr-customize (&rest ignore)
4626 "Customization of the `printing' group."
4627 (interactive)
4628 (customize-group 'printing))
4631 ;;;###autoload
4632 (defun lpr-customize (&rest ignore)
4633 "Customization of the `lpr' group."
4634 (interactive)
4635 (customize-group 'lpr))
4638 ;;;###autoload
4639 (defun pr-help (&rest ignore)
4640 "Help for the printing package."
4641 (interactive)
4642 (pr-show-setup pr-help-message "*Printing Help*"))
4645 ;;;###autoload
4646 (defun pr-ps-name ()
4647 "Interactively select a PostScript printer."
4648 (interactive)
4649 (pr-menu-set-ps-title
4650 (pr-complete-alist "PostScript printer"
4651 pr-ps-printer-alist pr-ps-name)))
4654 ;;;###autoload
4655 (defun pr-txt-name ()
4656 "Interactively select a text printer."
4657 (interactive)
4658 (pr-menu-set-txt-title
4659 (pr-complete-alist "Text printer"
4660 pr-txt-printer-alist pr-txt-name)))
4663 ;;;###autoload
4664 (defun pr-ps-utility ()
4665 "Interactively select a PostScript utility."
4666 (interactive)
4667 (pr-menu-set-utility-title
4668 (pr-complete-alist "PostScript utility"
4669 pr-ps-utility-alist pr-ps-utility)))
4672 ;;;###autoload
4673 (defun pr-show-ps-setup (&rest ignore)
4674 "Show current ps-print settings."
4675 (interactive)
4676 (pr-show-setup (ps-setup) "*PS Setup*"))
4679 ;;;###autoload
4680 (defun pr-show-pr-setup (&rest ignore)
4681 "Show current printing settings."
4682 (interactive)
4683 (pr-show-setup (pr-setup) "*PR Setup*"))
4686 ;;;###autoload
4687 (defun pr-show-lpr-setup (&rest ignore)
4688 "Show current lpr settings."
4689 (interactive)
4690 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4694 ;; Fast Commands
4697 ;;;###autoload
4698 (defun pr-ps-fast-fire (n-up &optional select)
4699 "Fast fire function for PostScript printing.
4701 If a region is active, the region will be printed instead of the whole buffer.
4702 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4703 `pr-mode-alist' will be used, that is, the current buffer or region will be
4704 printed using `pr-ps-mode-ps-print'.
4707 Interactively, you have the following situations:
4709 M-x pr-ps-fast-fire RET
4710 The command prompts the user for a N-UP value and printing will
4711 immediately be done using the current active printer.
4713 C-u M-x pr-ps-fast-fire RET
4714 C-u 0 M-x pr-ps-fast-fire RET
4715 The command prompts the user for a N-UP value and also for a current
4716 PostScript printer, then printing will immediately be done using the new
4717 current active printer.
4719 C-u 1 M-x pr-ps-fast-fire RET
4720 The command prompts the user for a N-UP value and also for a file name,
4721 and saves the PostScript image in that file instead of sending it to the
4722 printer.
4724 C-u 2 M-x pr-ps-fast-fire RET
4725 The command prompts the user for a N-UP value, then for a current
4726 PostScript printer and, finally, for a file name. Then change the active
4727 printer to that chosen by user and saves the PostScript image in
4728 that file instead of sending it to the printer.
4731 Noninteractively, the argument N-UP should be a positive integer greater than
4732 zero and the argument SELECT is treated as follows:
4734 If it's nil, send the image to the printer.
4736 If it's a list or an integer lesser or equal to zero, the command prompts
4737 the user for a current PostScript printer, then printing will immediately
4738 be done using the new current active printer.
4740 If it's an integer equal to 1, the command prompts the user for a file name
4741 and saves the PostScript image in that file instead of sending it to the
4742 printer.
4744 If it's an integer greater or equal to 2, the command prompts the user for a
4745 current PostScript printer and for a file name. Then change the active
4746 printer to that chosen by user and saves the PostScript image in that file
4747 instead of sending it to the printer.
4749 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4750 active printer and printing will immediately be done using the new active
4751 printer.
4753 Otherwise, send the image to the printer.
4756 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4757 are both set to t."
4758 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4759 current-prefix-arg))
4760 (let ((pr-auto-region t)
4761 (pr-auto-mode t)
4762 filename)
4763 (cond ((null select))
4764 ((listp select)
4765 (pr-ps-name))
4766 ((and (symbolp select)
4767 (assq select pr-ps-printer-alist))
4768 (pr-menu-set-ps-title select))
4769 ((integerp select)
4770 (and (/= select 1)
4771 (pr-ps-name))
4772 (and (>= select 1) (not pr-spool-p)
4773 (setq filename (pr-ps-outfile-preprint
4774 (if pr-print-using-ghostscript
4775 "Fast GS "
4776 "Fast "))))))
4777 (pr-ps-buffer-ps-print
4778 (if (integerp n-up)
4779 (min (max n-up 1) 100)
4780 (error "n-up must be an integer greater than zero"))
4781 filename)))
4784 ;;;###autoload
4785 (defun pr-txt-fast-fire (&optional select-printer)
4786 "Fast fire function for text printing.
4788 If a region is active, the region will be printed instead of the whole buffer.
4789 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4790 `pr-mode-alist' will be used, that is, the current buffer or region will be
4791 printed using `pr-txt-mode'.
4793 Interactively, when you use a prefix argument (C-u), the command prompts the
4794 user for a new active text printer.
4796 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4798 If it's nil, the printing is sent to the current active text printer.
4800 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4801 active printer and printing will immediately be done using the new active
4802 printer.
4804 If it's non-nil, the command prompts the user for a new active text printer.
4806 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4807 are both set to t."
4808 (interactive (list current-prefix-arg))
4809 (cond ((null select-printer))
4810 ((and (symbolp select-printer)
4811 (assq select-printer pr-txt-printer-alist))
4812 (pr-menu-set-txt-title select-printer))
4814 (pr-txt-name)))
4815 (let ((pr-auto-region t)
4816 (pr-auto-mode t))
4817 (pr-txt-buffer)))
4820 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4821 ;; Utilities
4824 (defun pr-setup ()
4825 "Return the current `printing' setup.
4827 This is *not* an interactive command.
4828 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4830 M-: (insert (pr-setup)) RET
4832 Or choose the menu option Printing/Show Settings/printing."
4833 (let (ps-prefix-quote)
4834 (mapconcat
4835 #'ps-print-quote
4836 (list
4837 (concat "\n;;; printing.el version " pr-version "\n")
4838 ";; internal vars"
4839 (ps-comment-string "emacs-version " emacs-version)
4840 (ps-comment-string "pr-txt-command " pr-txt-command)
4841 (ps-comment-string "pr-txt-switches "
4842 (pr-switches-string pr-txt-switches "pr-txt-switches"))
4843 (ps-comment-string "pr-txt-printer " pr-txt-printer)
4844 (ps-comment-string "pr-ps-command " pr-ps-command)
4845 (ps-comment-string "pr-ps-switches "
4846 (pr-switches-string pr-ps-switches "pr-ps-switches"))
4847 (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
4848 (ps-comment-string "pr-ps-printer " pr-ps-printer)
4849 (ps-comment-string "pr-cygwin-system " pr-cygwin-system)
4850 (ps-comment-string "ps-windows-system " ps-windows-system)
4851 (ps-comment-string "ps-lp-system " ps-lp-system)
4853 '(14 . pr-path-style)
4854 '(14 . pr-path-alist)
4856 '(21 . pr-txt-name)
4857 '(21 . pr-txt-printer-alist)
4859 '(20 . pr-ps-name)
4860 '(20 . pr-ps-printer-alist)
4862 '(20 . pr-temp-dir)
4863 '(20 . pr-ps-temp-file)
4864 '(20 . pr-file-modes)
4865 '(20 . pr-delete-temp-file)
4866 '(20 . pr-list-directory)
4868 '(17 . pr-gv-command)
4869 '(17 . pr-gs-command)
4870 '(17 . pr-gs-switches)
4871 '(17 . pr-gs-device)
4872 '(17 . pr-gs-resolution)
4874 '(27 . pr-print-using-ghostscript)
4875 '(27 . pr-faces-p)
4876 '(27 . pr-spool-p)
4877 '(27 . pr-file-landscape)
4878 '(27 . pr-file-duplex)
4879 '(27 . pr-file-tumble)
4880 '(27 . pr-auto-region)
4881 '(27 . pr-auto-mode)
4883 '(20 . pr-ps-utility)
4884 '(20 . pr-ps-utility-alist)
4886 '(14 . pr-mode-alist)
4888 '(20 . pr-menu-lock)
4889 '(20 . pr-menu-char-height)
4890 '(20 . pr-menu-char-width)
4892 '(20 . pr-setting-database)
4894 '(22 . pr-visible-entry-list)
4896 '(22 . pr-buffer-verbose)
4897 '(22 . pr-buffer-name)
4898 '(22 . pr-buffer-name-ignore)
4899 ")\n\n;;; printing.el - end of settings\n")
4900 "\n")))
4903 (defun lpr-setup ()
4904 "Return the current `lpr' setup.
4906 This is *not* an interactive command.
4907 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4909 M-: (insert (lpr-setup)) RET
4911 Or choose the menu option Printing/Show Settings/lpr."
4912 (let (ps-prefix-quote)
4913 (mapconcat
4914 #'ps-print-quote
4915 (list
4916 "\n;;; lpr.el settings\n"
4917 (ps-comment-string "emacs-version" emacs-version)
4919 '(25 . printer-name)
4920 '(25 . lpr-switches)
4921 '(25 . lpr-add-switches)
4922 '(25 . lpr-command)
4923 '(25 . lpr-headers-switches)
4924 '(25 . print-region-function)
4925 '(25 . lpr-page-header-program)
4926 '(25 . lpr-page-header-switches)
4927 ")\n\n;;; lpr.el - end of settings\n")
4928 "\n")))
4931 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4932 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4934 (declare-function mh-get-msg-num "mh-utils" (error-if-no-message))
4935 (declare-function mh-show "mh-show" (&optional message redisplay-flag))
4936 (declare-function mh-start-of-uncleaned-message "mh-show" ())
4937 (defvar mh-show-buffer)
4940 (defun pr-article-date ()
4941 "Find the date of an article or mail message in current buffer.
4942 Return only the dayname, if present, weekday, month, and year."
4943 (save-excursion
4944 (goto-char (point-min))
4945 (if (re-search-forward
4946 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4947 (buffer-substring (match-beginning 1) (match-end 1))
4948 (format-time-string "%Y/%m/%d"))))
4951 (defun pr-mh-current-message ()
4952 "Go to mh-inbox current message."
4953 (let ((msg (or (mh-get-msg-num nil) 0)))
4954 (mh-show)
4955 (set-buffer mh-show-buffer)
4956 (goto-char (point-min))
4957 (mh-start-of-uncleaned-message)
4958 (message "Printing message %d" msg)))
4961 (defun pr-mh-print-1 (n-up filename header-list)
4962 "Print mh-inbox current message in PostScript."
4963 (save-excursion
4964 (save-window-excursion
4965 (pr-mh-current-message)
4966 (pr-mode-print n-up filename header-list (point)))))
4969 (defun pr-mh-lpr-1 (header-list)
4970 "Print mh-inbox current message in text printer."
4971 (save-excursion
4972 (save-window-excursion
4973 (pr-mh-current-message)
4974 (pr-mode-lpr header-list (point)))))
4977 (defalias 'pr-mh-print-2 'pr-mode-print)
4980 (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
4983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4984 ;; rmail (hacked from ps-print.el)
4987 (defun pr-rmail-lpr (header-list)
4988 "Print RMAIL current message in text printer."
4989 (pr-lpr-message-from-summary header-list
4990 'rmail-buffer 'rmail-summary-buffer))
4993 (defun pr-rmail-print (n-up filename header-list)
4994 "Print RMAIL current message in PostScript."
4995 (pr-ps-message-from-summary n-up filename header-list
4996 'rmail-buffer 'rmail-summary-buffer))
4999 (defun pr-ps-message-from-summary (n-up filename header-list
5000 summary-buffer summary-default)
5001 "Print current message in PostScript."
5002 (let ((buf (or (and (boundp summary-buffer)
5003 (symbol-value summary-buffer))
5004 (symbol-value summary-default))))
5005 (and (get-buffer buf)
5006 (with-current-buffer buf
5007 (pr-mode-print n-up filename header-list)))))
5010 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
5011 "Print current message in text printer."
5012 (let ((buf (or (and (boundp summary-buffer)
5013 (symbol-value summary-buffer))
5014 (symbol-value summary-default))))
5015 (and (get-buffer buf)
5016 (with-current-buffer buf
5017 (pr-mode-lpr header-list)))))
5020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5021 ;; gnus (hacked from ps-print.el)
5024 (defvar pr-gnus-article "*Article*")
5027 (defun pr-gnus-print (n-up filename header-list)
5028 "Print *Article* current message in PostScript."
5029 (pr-ps-message-from-summary n-up filename header-list
5030 'gnus-article-buffer 'pr-gnus-article))
5033 (defun pr-gnus-lpr (header-list)
5034 "Print *Article* current message in text printer."
5035 (pr-lpr-message-from-summary header-list
5036 'gnus-article-buffer 'pr-gnus-article))
5039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5040 ;; vm (hacked from ps-print.el)
5043 (defvar pr-vm-summary "")
5046 (defun pr-vm-print (n-up filename header-list)
5047 "Print current vm message in PostScript."
5048 (pr-ps-message-from-summary n-up filename header-list
5049 'vm-mail-buffer 'pr-vm-summary))
5052 (defun pr-vm-lpr (header-list)
5053 "Print current vm message in text printer."
5054 (pr-lpr-message-from-summary header-list
5055 'vm-mail-buffer 'pr-vm-summary))
5058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5059 ;; Mode Functions
5062 (defun pr-ps-mode (n-up filename)
5063 "If current major mode is declared, print it in PostScript."
5064 (let ((args (pr-mode-alist-p)))
5065 (if args
5066 (let ((fun (cdr args)))
5067 (funcall (car fun) n-up filename (cdr fun))
5069 (ding)
5070 (message "`%s' major mode not declared." major-mode)
5071 nil)))
5074 (defmacro pr-local-variable (header-list &rest body)
5075 `(save-excursion
5076 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
5077 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
5078 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
5079 ps-razzle-dazzle)
5080 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
5081 ,@body
5082 (and (nth 3 ,header-list)
5083 (pr-kill-local-variable local-var-list))))))
5086 (defun pr-mode-print (n-up filename header-list &optional from to)
5087 "Print current major mode in PostScript."
5088 (pr-local-variable
5089 header-list
5090 (let ((file (pr-ps-file filename))
5091 (start (cond (from)
5092 ((pr-region-active-p) (region-beginning))
5093 (t nil)
5095 (pr-text2ps (pr-region-active-symbol start) n-up file start
5096 (cond (to)
5097 ((pr-region-active-p) (region-end))
5098 (from (point-max))
5100 (unless (or pr-spool-p filename)
5101 (pr-ps-file-print file)
5102 (pr-delete-file file)))))
5105 (defun pr-mode-lpr (header-list &optional from to)
5106 "Print current major mode in text printer."
5107 (pr-local-variable
5108 header-list
5109 (pr-txt-print (cond (from)
5110 ((pr-region-active-p) (region-beginning))
5111 (t (point-min)))
5112 (cond (to)
5113 ((pr-region-active-p) (region-end))
5114 (t (point-max))))))
5117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5118 ;; Menu Lock
5121 (defconst pr-menu-entry-alist
5122 '((postscript . 3)
5123 (text . 3)
5124 (postscript-options . 9)
5125 (postscript-process . 3)
5126 (printing . 3)
5127 (help . 3)
5129 "Alist that associates menu part with number of items per part.
5131 It's used by `pr-menu-index'.
5133 Each element has the form:
5135 (MENU-PART . NUMBER-OF-ITEMS)
5137 See `pr-visible-entry-alist'.")
5140 (defun pr-menu-index (entry index)
5141 (let ((base-list
5142 (cond ((eq entry 'text)
5143 '(postscript))
5144 ((eq entry 'postscript-options)
5145 '(postscript text))
5146 ((eq entry 'postscript-process)
5147 '(postscript text postscript-options))
5148 ((eq entry 'printing)
5149 '(postscript text postscript-options postscript-process))
5151 nil)
5153 key)
5154 (while base-list
5155 (setq key (car base-list)
5156 base-list (cdr base-list))
5157 (and (pr-visible-p key)
5158 (setq index (+ index
5159 (cdr (assq key pr-menu-entry-alist)))))))
5160 (+ index 2))
5163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5164 ;; Printer & Utility Selection
5167 (defun pr-update-var (var-sym alist)
5168 (or (assq (symbol-value var-sym) alist)
5169 (set var-sym (car (car alist)))))
5172 (defun pr-update-menus (&optional force)
5173 "Update utility, PostScript and text printer menus.
5175 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
5176 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
5177 otherwise, update PostScript printer menu if `pr-ps-printer-menu-modified' is
5178 non-nil, update text printer menu if `pr-txt-printer-menu-modified' is
5179 non-nil, and update PostScript File menus if `pr-ps-utility-menu-modified' is
5180 non-nil.
5182 If menu binding was not done, calls `pr-menu-bind'."
5183 (interactive "P")
5184 (if pr-menu-print-item ; since v6.8.4
5185 ;; There was no menu binding yet, so do it now!
5186 ;; This is a hack to be compatible with old versions of printing.
5187 ;; So, user does not need to change printing calling in init files.
5188 (pr-menu-bind)
5189 ;; Here menu binding is ok.
5190 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
5191 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
5192 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
5193 (pr-do-update-menus force)))
5196 (defun pr-menu-create (name alist var-sym fun entry index)
5197 (cons name
5198 (mapcar
5199 #'(lambda (elt)
5200 (let ((sym (car elt)))
5201 (vector
5202 (symbol-name sym)
5203 (list fun (list 'quote sym) nil (list 'quote entry) index)
5204 :style 'radio
5205 :selected (list 'eq var-sym (list 'quote sym)))))
5206 alist)))
5209 (defun pr-ps-set-utility (value)
5210 (let ((item (cdr (assq value pr-ps-utility-alist))))
5211 (or item
5212 (error
5213 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
5214 value))
5215 (setq pr-ps-utility value)
5216 (pr-eval-alist (nthcdr 9 item)))
5217 (pr-update-mode-line))
5220 (defun pr-ps-set-printer (value)
5221 (let ((ps (cdr (assq value pr-ps-printer-alist))))
5222 (or ps
5223 (error
5224 "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
5225 value))
5226 (setq pr-ps-name value
5227 pr-ps-command (pr-dosify-file-name (nth 0 ps))
5228 pr-ps-switches (nth 1 ps)
5229 pr-ps-printer-switch (nth 2 ps)
5230 pr-ps-printer (nth 3 ps))
5231 (or (stringp pr-ps-command)
5232 (setq pr-ps-command
5233 (cond (ps-windows-system "print")
5234 (ps-lp-system "lp")
5235 (t "lpr")
5237 (or (stringp pr-ps-printer-switch)
5238 (setq pr-ps-printer-switch
5239 (cond (ps-windows-system "/D:")
5240 (ps-lp-system "-d")
5241 (t "-P")
5243 (pr-eval-alist (nthcdr 4 ps)))
5244 (pr-update-mode-line))
5247 (defun pr-txt-set-printer (value)
5248 (let ((txt (cdr (assq value pr-txt-printer-alist))))
5249 (or txt
5250 (error "Invalid text printer name `%s' for variable `pr-txt-name'"
5251 value))
5252 (setq pr-txt-name value
5253 pr-txt-command (pr-dosify-file-name (nth 0 txt))
5254 pr-txt-switches (nth 1 txt)
5255 pr-txt-printer (nth 2 txt)))
5256 (or (stringp pr-txt-command)
5257 (setq pr-txt-command
5258 (cond (ps-windows-system "print")
5259 (ps-lp-system "lp")
5260 (t "lpr")
5262 (pr-update-mode-line))
5265 (defun pr-eval-alist (alist)
5266 (mapcar #'(lambda (option)
5267 (let ((var-sym (car option))
5268 (value (cdr option)))
5269 (if (eq var-sym 'inherits-from:)
5270 (pr-eval-setting-alist value 'global)
5271 (set var-sym (eval value)))))
5272 alist))
5275 (defun pr-eval-local-alist (alist)
5276 (let (local-list)
5277 (mapc #'(lambda (option)
5278 (let ((var-sym (car option))
5279 (value (cdr option)))
5280 (setq local-list
5281 (if (eq var-sym 'inherits-from:)
5282 (nconc (pr-eval-setting-alist value) local-list)
5283 (set (make-local-variable var-sym) (eval value))
5284 (cons var-sym local-list)))))
5285 alist)
5286 local-list))
5289 (defun pr-eval-setting-alist (key &optional global old)
5290 (let ((setting (cdr (assq key pr-setting-database))))
5291 (and setting
5292 (let ((inherits (nth 0 setting))
5293 (local (nth 1 setting))
5294 (kill (nth 2 setting))
5295 local-list)
5296 (and local global
5297 (progn
5298 (ding)
5299 (message "There are local buffer settings for `%S'." key)
5300 (setq global nil)))
5301 (and inherits
5302 (if (memq inherits old)
5303 (error "Circular inheritance for `%S'" inherits)
5304 (setq local-list
5305 (pr-eval-setting-alist inherits global
5306 (cons inherits old)))))
5307 (mapc
5308 (cond ((not local) ; global settings
5309 #'(lambda (option)
5310 (let ((var-sym (car option)))
5311 (or (eq var-sym 'inherits-from:)
5312 (set var-sym (eval (cdr option)))))))
5313 (kill ; local settings with killing
5314 #'(lambda (option)
5315 (let ((var-sym (car option)))
5316 (unless (eq var-sym 'inherits-from:)
5317 (setq local-list (cons var-sym local-list))
5318 (set (make-local-variable var-sym)
5319 (eval (cdr option)))))))
5320 (t ; local settings without killing
5321 #'(lambda (option)
5322 (let ((var-sym (car option)))
5323 (or (eq var-sym 'inherits-from:)
5324 (set (make-local-variable var-sym)
5325 (eval (cdr option))))))))
5326 (nthcdr 3 setting))
5327 local-list))))
5330 (defun pr-kill-local-variable (local-var-list)
5331 (mapcar 'kill-local-variable local-var-list))
5334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5335 ;; Internal Functions (II)
5338 (defun pr-toggle (var-sym mess entry index horizontal state
5339 &optional path no-menu)
5340 (set var-sym (not (symbol-value var-sym)))
5341 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5342 (or no-menu
5343 (pr-menu-lock entry index horizontal state path)))
5346 (defun pr-toggle-file-duplex-menu (&optional no-menu)
5347 "Toggle whether to print PostScript files in duplex mode."
5348 (interactive)
5349 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
5350 '("PostScript Print" "File") no-menu))
5353 (defun pr-toggle-file-tumble-menu (&optional no-menu)
5354 "Toggle whether to print PostScript files in tumble mode."
5355 (interactive)
5356 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
5357 '("PostScript Print" "File") no-menu))
5360 (defun pr-toggle-file-landscape-menu (&optional no-menu)
5361 "Toggle whether to print PostScript files in landscape orientation."
5362 (interactive)
5363 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
5364 '("PostScript Print" "File") no-menu))
5367 (defun pr-toggle-ghostscript-menu (&optional no-menu)
5368 "Toggle whether to print using ghostscript."
5369 (interactive)
5370 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
5371 'postscript-process 2 12 'toggle nil no-menu))
5374 (defun pr-toggle-faces-menu (&optional no-menu)
5375 "Toggle whether to print with face attributes."
5376 (interactive)
5377 (pr-toggle 'pr-faces-p "Printing with faces"
5378 'postscript-process 1 12 'toggle nil no-menu))
5381 (defun pr-toggle-spool-menu (&optional no-menu)
5382 "Toggle whether to spool printing in a buffer."
5383 (interactive)
5384 (pr-toggle 'pr-spool-p "Spooling printing"
5385 'postscript-process 0 12 'toggle nil no-menu))
5388 (defun pr-toggle-duplex-menu (&optional no-menu)
5389 "Toggle whether to generate PostScript for a two-sided printer."
5390 (interactive)
5391 (pr-toggle 'ps-spool-duplex "Printing duplex"
5392 'postscript-options 5 12 'toggle nil no-menu))
5395 (defun pr-toggle-tumble-menu (&optional no-menu)
5396 "Toggle how pages on opposite sides of a sheet are oriented."
5397 (interactive)
5398 (pr-toggle 'ps-spool-tumble "Tumble"
5399 'postscript-options 6 12 'toggle nil no-menu))
5402 (defun pr-toggle-landscape-menu (&optional no-menu)
5403 "Toggle whether to print in landscape mode."
5404 (interactive)
5405 (pr-toggle 'ps-landscape-mode "Landscape"
5406 'postscript-options 0 12 'toggle nil no-menu))
5409 (defun pr-toggle-upside-down-menu (&optional no-menu)
5410 "Toggle whether to print upside-down (that is, rotated by 180 degrees)."
5411 (interactive)
5412 (pr-toggle 'ps-print-upside-down "Upside-Down"
5413 'postscript-options 7 12 'toggle nil no-menu))
5416 (defun pr-toggle-line-menu (&optional no-menu)
5417 "Toggle whether to means print line numbers."
5418 (interactive)
5419 (pr-toggle 'ps-line-number "Line number"
5420 'postscript-options 3 12 'toggle nil no-menu))
5423 (defun pr-toggle-zebra-menu (&optional no-menu)
5424 "Toggle whether to print zebra stripes."
5425 (interactive)
5426 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
5427 'postscript-options 4 12 'toggle nil no-menu))
5430 (defun pr-toggle-header-menu (&optional no-menu)
5431 "Toggle whether to print a header at the top of each page."
5432 (interactive)
5433 (pr-toggle 'ps-print-header "Print header"
5434 'postscript-options 1 12 'toggle nil no-menu))
5437 (defun pr-toggle-header-frame-menu (&optional no-menu)
5438 "Toggle whether to draw a gaudy frame around the header."
5439 (interactive)
5440 (pr-toggle 'ps-print-header-frame "Print header frame"
5441 'postscript-options 2 12 'toggle nil no-menu))
5444 (defun pr-toggle-lock-menu (&optional no-menu)
5445 "Toggle whether the menu is locked while selecting toggle options."
5446 (interactive)
5447 (pr-toggle 'pr-menu-lock "Menu lock"
5448 'printing 2 12 'toggle nil no-menu))
5451 (defun pr-toggle-region-menu (&optional no-menu)
5452 "Toggle whether the region is automagically detected."
5453 (interactive)
5454 (pr-toggle 'pr-auto-region "Auto region"
5455 'printing 0 12 'toggle nil no-menu))
5458 (defun pr-toggle-mode-menu (&optional no-menu)
5459 "Toggle whether major-mode specific printing is preferred over normal printing."
5460 (interactive)
5461 (pr-toggle 'pr-auto-mode "Auto mode"
5462 'printing 1 12 'toggle nil no-menu))
5465 (defun pr-prompt (str)
5466 (if (pr-auto-mode-p)
5467 (concat str " mode")
5468 (pr-region-active-string str)))
5471 (defun pr-prompt-region (str)
5472 (concat str (if (pr-auto-mode-p)
5473 " mode"
5474 " region")))
5477 (defun pr-prompt-gs (str)
5478 (if (pr-using-ghostscript-p)
5479 (concat str " GS")
5480 str))
5483 (defun pr-region-active-symbol (&optional region-p)
5484 (if (or region-p (pr-region-active-p))
5485 'region
5486 'buffer))
5489 (defun pr-region-active-string (prefix)
5490 (concat prefix
5491 (if (pr-region-active-p)
5492 " region"
5493 " buffer")))
5496 (defun pr-show-setup (settings buffer-name)
5497 (with-output-to-temp-buffer buffer-name
5498 (princ settings)
5499 (help-print-return-message)))
5502 (defun pr-complete-alist (prompt alist default)
5503 (let ((collection (mapcar #'(lambda (elt)
5504 (setq elt (car elt))
5505 (cons (symbol-name elt) elt))
5506 alist)))
5507 (cdr (assoc (completing-read (concat prompt ": ")
5508 collection nil t
5509 (symbol-name default) nil
5510 (symbol-name default))
5511 collection))))
5514 (defun pr-delete-file (file)
5515 (and pr-delete-temp-file (file-exists-p file)
5516 (delete-file file)))
5519 (defun pr-expand-file-name (filename)
5520 (pr-dosify-file-name (expand-file-name filename)))
5523 (defun pr-ps-outfile-preprint (&optional mess)
5524 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5525 (res (read-file-name prompt default-directory "" nil)))
5526 (while (cond ((not (file-writable-p res))
5527 (ding)
5528 (setq prompt "is unwritable"))
5529 ((file-directory-p res)
5530 (ding)
5531 (setq prompt "is a directory"))
5532 ((file-exists-p res)
5533 (ding)
5534 (setq prompt "exists")
5535 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5536 res))))
5537 (t nil))
5538 (setq res (read-file-name
5539 (format "File %s; PostScript file: " prompt)
5540 (file-name-directory res) nil nil
5541 (file-name-nondirectory res))))
5542 (pr-expand-file-name res)))
5545 (defun pr-ps-infile-preprint (&optional mess)
5546 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5547 (res (read-file-name prompt default-directory "" nil)))
5548 (while (cond ((not (file-exists-p res))
5549 (ding)
5550 (setq prompt "doesn't exist"))
5551 ((not (file-readable-p res))
5552 (ding)
5553 (setq prompt "is unreadable"))
5554 ((file-directory-p res)
5555 (ding)
5556 (setq prompt "is a directory"))
5557 (t nil))
5558 (setq res (read-file-name
5559 (format "File %s; PostScript file: " prompt)
5560 (file-name-directory res) nil nil
5561 (file-name-nondirectory res))))
5562 (pr-expand-file-name res)))
5565 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
5566 ;; check arguments for PostScript file processing.
5567 ;; n-up
5568 (or (symbol-value n-up-sym)
5569 (set n-up-sym (pr-interactive-n-up prompt)))
5570 ;; input file
5571 (and (eq (symbol-value infile-sym) t)
5572 (set infile-sym (pr-ps-infile-preprint prompt)))
5573 (or (symbol-value infile-sym)
5574 (error "%s: input PostScript file name is missing" prompt))
5575 (set infile-sym (pr-dosify-file-name (symbol-value infile-sym)))
5576 ;; output file
5577 (and (eq (symbol-value outfile-sym) t)
5578 (set outfile-sym (and current-prefix-arg
5579 (pr-ps-outfile-preprint prompt))))
5580 (and (symbol-value outfile-sym)
5581 (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym))))
5582 (pr-ps-file (symbol-value outfile-sym)))
5585 (defun pr-ps-utility-process (n-up infile outfile)
5586 ;; activate utility to process a PostScript file.
5587 (let (item)
5588 (and (stringp infile) (file-exists-p infile)
5589 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
5590 (pr-call-process (nth 0 item)
5591 (pr-switches-string (nth 1 item)
5592 "pr-ps-utility-alist entry")
5593 (pr-switches-string (nth 8 item)
5594 "pr-ps-utility-alist entry")
5595 (and (nth 2 item)
5596 (format (nth 2 item) ps-paper-type))
5597 (format (nth 3 item) n-up)
5598 (and pr-file-landscape (nth 4 item))
5599 (and pr-file-duplex (nth 5 item))
5600 (and pr-file-tumble (nth 6 item))
5601 (pr-expand-file-name infile)
5602 (nth 7 item)
5603 (pr-expand-file-name outfile)))))
5606 (defun pr-remove-nil-from-list (lst)
5607 (while (and lst (null (car lst)))
5608 (setq lst (cdr lst)))
5609 (let ((b lst)
5610 (l (cdr lst)))
5611 (while l
5612 (if (car l)
5613 (setq b l
5614 l (cdr l))
5615 (setq l (cdr l))
5616 (setcdr b l))))
5617 lst)
5620 (defun pr-call-process (command &rest args)
5621 (let ((buffer (get-buffer-create "*Printing Command Output*"))
5622 (cmd (pr-command command))
5623 status)
5624 (setq args (pr-remove-nil-from-list args))
5625 ;; *Printing Command Output* == show command & args
5626 (with-current-buffer buffer
5627 (goto-char (point-max))
5628 (insert (format "%s %S\n" cmd args)))
5629 ;; *Printing Command Output* == show any return message from command
5630 (pr-save-file-modes
5631 (setq status
5632 (condition-case data
5633 (apply 'call-process cmd nil buffer nil args)
5634 ((quit error)
5635 (error-message-string data)))))
5636 ;; *Printing Command Output* == show exit status
5637 (with-current-buffer buffer
5638 (goto-char (point-max))
5639 (insert (format "Exit status: %s\n\n" status)))
5640 ;; message if error status
5641 (if (or (stringp status)
5642 (and (integerp status) (/= status 0)))
5643 (message
5644 "Printing error status: %s (see *Printing Command Output* buffer)"
5645 status))))
5648 (defun pr-txt-print (from to)
5649 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command)))
5650 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5651 (printer-name pr-txt-printer))
5652 (lpr-region from to)))
5655 (defun pr-switches-string (switches mess)
5656 ;; If SWITCHES is nil, return nil.
5657 ;; Otherwise, return the list of string in a string.
5658 (and switches
5659 (mapconcat 'identity (pr-switches switches mess) " ")))
5662 (defun pr-switches (switches mess)
5663 (or (listp switches)
5664 (error "%S should have a list of strings" mess))
5665 (ps-flatten-list ; dynamic evaluation
5666 (mapcar 'ps-eval-switch switches)))
5669 (defun pr-ps-preview (kind n-up filename mess)
5670 (pr-set-n-up-and-filename 'n-up 'filename mess)
5671 (let ((file (pr-ps-file filename)))
5672 (pr-text2ps kind n-up file)
5673 (or pr-spool-p (pr-ps-file-preview file))))
5676 (defun pr-ps-using-ghostscript (kind n-up filename mess)
5677 (pr-set-n-up-and-filename 'n-up 'filename mess)
5678 (let ((file (pr-ps-file filename)))
5679 (pr-text2ps kind n-up file)
5680 (unless (or pr-spool-p filename)
5681 (pr-ps-file-using-ghostscript file)
5682 (pr-delete-file file))))
5685 (defun pr-ps-print (kind n-up filename mess)
5686 (pr-set-n-up-and-filename 'n-up 'filename mess)
5687 (let ((file (pr-ps-file filename)))
5688 (pr-text2ps kind n-up file)
5689 (unless (or pr-spool-p filename)
5690 (pr-ps-file-print file)
5691 (pr-delete-file file))))
5694 (defun pr-ps-file (&optional filename)
5695 (pr-dosify-file-name (or filename
5696 (make-temp-file
5697 (convert-standard-filename
5698 (expand-file-name pr-ps-temp-file pr-temp-dir))
5699 nil ".ps"))))
5702 (defun pr-interactive-n-up (mess)
5703 (or (stringp mess) (setq mess "*"))
5704 (save-match-data
5705 (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
5706 (prompt "")
5707 (str (pr-read-string (format fmt-prompt prompt mess) "1" nil "1"))
5708 int)
5709 (while (if (string-match "^\\s *[0-9]+$" str)
5710 (setq int (string-to-number str)
5711 prompt (cond ((< int 1) "Integer below 1; ")
5712 ((> int 100) "Integer above 100; ")
5713 (t nil)))
5714 (setq prompt "Invalid integer syntax; "))
5715 (ding)
5716 (setq str
5717 (pr-read-string (format fmt-prompt prompt mess) str nil "1")))
5718 int)))
5721 (defun pr-interactive-dir (mess)
5722 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5723 default-directory)))
5724 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
5725 (dir (read-directory-name (format fmt-prompt "")
5726 "" dir-name nil dir-name))
5727 prompt)
5728 (while (cond ((not (file-directory-p dir))
5729 (ding)
5730 (setq prompt "It's not a directory! "))
5731 ((not (file-readable-p dir))
5732 (ding)
5733 (setq prompt "Directory is unreadable! "))
5734 (t nil))
5735 (setq dir-name (file-name-directory dir)
5736 dir (read-directory-name (format fmt-prompt prompt)
5737 "" dir-name nil dir-name)))
5738 (file-name-as-directory dir)))
5741 (defun pr-interactive-regexp (mess)
5742 (pr-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
5745 (defun pr-interactive-dir-args (mess)
5746 (list
5747 ;; get directory argument
5748 (pr-interactive-dir mess)
5749 ;; get file name regexp
5750 (pr-interactive-regexp mess)))
5753 (defun pr-interactive-ps-dir-args (mess)
5754 (list
5755 ;; get n-up argument
5756 (pr-interactive-n-up mess)
5757 ;; get directory argument
5758 (pr-interactive-dir mess)
5759 ;; get file name regexp
5760 (pr-interactive-regexp mess)
5761 ;; get output file name
5762 (and (not pr-spool-p)
5763 (ps-print-preprint current-prefix-arg))))
5766 (defun pr-interactive-n-up-file (mess)
5767 (list
5768 ;; get n-up argument
5769 (pr-interactive-n-up mess)
5770 ;; get output file name
5771 (and (not pr-spool-p)
5772 (ps-print-preprint current-prefix-arg))))
5775 (defun pr-interactive-n-up-inout (mess)
5776 (list
5777 ;; get n-up argument
5778 (pr-interactive-n-up mess)
5779 ;; get input file name
5780 (pr-ps-infile-preprint (concat mess " "))
5781 ;; get output file name
5782 (ps-print-preprint current-prefix-arg)))
5785 (defun pr-set-outfilename (filename-sym)
5786 (and (not pr-spool-p)
5787 (eq (symbol-value filename-sym) t)
5788 (set filename-sym (and current-prefix-arg
5789 (ps-print-preprint current-prefix-arg))))
5790 (and (symbol-value filename-sym)
5791 (set filename-sym (pr-dosify-file-name (symbol-value filename-sym)))))
5794 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5795 ;; n-up
5796 (or (symbol-value n-up-sym)
5797 (set n-up-sym (pr-interactive-n-up mess)))
5798 ;; output file
5799 (pr-set-outfilename filename-sym))
5802 (defun pr-set-dir-args (dir-sym regexp-sym mess)
5803 ;; directory
5804 (or (symbol-value dir-sym)
5805 (set dir-sym (pr-interactive-dir mess)))
5806 ;; file name regexp
5807 (or (symbol-value regexp-sym)
5808 (set regexp-sym (pr-interactive-regexp mess))))
5811 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5812 ;; n-up
5813 (or (symbol-value n-up-sym)
5814 (set n-up-sym (pr-interactive-n-up mess)))
5815 ;; directory & file name regexp
5816 (pr-set-dir-args dir-sym regexp-sym mess)
5817 ;; output file
5818 (pr-set-outfilename filename-sym))
5821 (defun pr-find-buffer-visiting (file)
5822 (if (not (file-directory-p file))
5823 (find-buffer-visiting (if ps-windows-system
5824 (downcase file)
5825 file))
5826 (let ((truename (file-truename file))
5827 (blist (buffer-list))
5828 found)
5829 (while (and (not found) blist)
5830 (with-current-buffer (car blist)
5831 (and (eq major-mode 'dired-mode)
5832 (save-excursion
5833 (goto-char (point-min))
5834 (string= (buffer-substring-no-properties
5835 (+ (point-min) 2)
5836 (progn
5837 (end-of-line)
5838 (1- (point))))
5839 truename))
5840 (setq found (car blist))))
5841 (setq blist (cdr blist)))
5842 found)))
5845 (defun pr-file-list (dir file-regexp fun)
5846 (mapcar #'(lambda (file)
5847 (and (or pr-list-directory
5848 (not (file-directory-p file)))
5849 (let ((buffer (pr-find-buffer-visiting file))
5850 pop-up-windows
5851 pop-up-frames)
5852 (and (or buffer
5853 (file-readable-p file))
5854 (with-current-buffer (or buffer
5855 (find-file-noselect file))
5856 (funcall fun)
5857 (or buffer
5858 (kill-buffer (current-buffer))))))))
5859 (directory-files dir t file-regexp)))
5862 (defun pr-delete-file-if-exists (filename)
5863 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5864 (delete-file filename)))
5867 (defun pr-ps-file-list (n-up dir file-regexp filename)
5868 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5869 (let ((pr-spool-p t))
5870 (pr-file-list dir file-regexp
5871 #'(lambda ()
5872 (if (pr-auto-mode-p)
5873 (pr-ps-mode n-up filename)
5874 (pr-text2ps 'buffer n-up filename)))))
5875 (or pr-spool-p
5876 (pr-despool-print filename)))
5879 (defun pr-text2ps (kind n-up filename &optional from to)
5880 (pr-save-file-modes
5881 (let ((ps-n-up-printing n-up)
5882 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5883 'setpagedevice)))
5884 (pr-delete-file-if-exists filename)
5885 (cond (pr-faces-p
5886 (cond (pr-spool-p
5887 ;; pr-faces-p and pr-spool-p
5888 ;; here FILENAME arg is ignored
5889 (cond ((eq kind 'buffer)
5890 (ps-spool-buffer-with-faces))
5891 ((eq kind 'region)
5892 (ps-spool-region-with-faces (or from (point))
5893 (or to (mark))))
5895 ;; pr-faces-p and not pr-spool-p
5896 ((eq kind 'buffer)
5897 (ps-print-buffer-with-faces filename))
5898 ((eq kind 'region)
5899 (ps-print-region-with-faces (or from (point))
5900 (or to (mark)) filename))
5902 (pr-spool-p
5903 ;; not pr-faces-p and pr-spool-p
5904 ;; here FILENAME arg is ignored
5905 (cond ((eq kind 'buffer)
5906 (ps-spool-buffer))
5907 ((eq kind 'region)
5908 (ps-spool-region (or from (point)) (or to (mark))))
5910 ;; not pr-faces-p and not pr-spool-p
5911 ((eq kind 'buffer)
5912 (ps-print-buffer filename))
5913 ((eq kind 'region)
5914 (ps-print-region (or from (point)) (or to (mark)) filename))
5915 ))))
5918 (defun pr-command (command)
5919 "Return absolute file name specification for COMMAND.
5921 If COMMAND is an empty string, return it.
5923 If COMMAND is already an absolute file name specification, return it.
5924 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5925 otherwise, gives an error.
5927 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5928 `unix' are used (see `pr-path-alist' for documentation).
5930 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5931 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5932 (if (string= command "")
5933 command
5934 (pr-dosify-file-name
5935 (or (pr-find-command command)
5936 (pr-path-command (cond (pr-cygwin-system 'cygwin)
5937 (ps-windows-system 'windows)
5938 (t 'unix))
5939 (file-name-nondirectory command)
5940 nil)
5941 (error "Command not found: %s"
5942 (file-name-nondirectory command))))))
5945 (defun pr-path-command (symbol command sym-list)
5946 (let ((lpath (cdr (assq symbol pr-path-alist)))
5947 cmd)
5948 ;; PATH expansion
5949 (and (eq symbol 'PATH) (null lpath)
5950 (setq lpath (parse-colon-path (getenv "PATH"))))
5951 (while (and lpath
5952 (not
5953 (setq cmd
5954 (let ((path (car lpath)))
5955 (cond
5956 ;; symbol expansion
5957 ((symbolp path)
5958 (and (not (memq path sym-list))
5959 (pr-path-command path command
5960 (cons path sym-list))))
5961 ;; normal path
5962 ((stringp path)
5963 (pr-find-command
5964 (expand-file-name
5965 (substitute-in-file-name
5966 (concat (file-name-as-directory path)
5967 command)))))
5968 )))))
5969 (setq lpath (cdr lpath)))
5970 cmd))
5973 (defun pr-find-command (cmd)
5974 (if ps-windows-system
5975 ;; windows system
5976 (let ((ext (cons (file-name-extension cmd t)
5977 (list ".exe" ".bat" ".com")))
5978 found)
5979 (setq cmd (file-name-sans-extension cmd))
5980 (while (and ext
5981 (setq found (concat cmd (car ext)))
5982 (not (and (file-regular-p found)
5983 (file-executable-p found))))
5984 (setq ext (cdr ext)
5985 found nil))
5986 found)
5987 ;; non-windows systems
5988 (and (file-regular-p cmd)
5989 (file-executable-p cmd)
5990 cmd)))
5993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5994 ;; Printing Interface (inspired by ps-print-interface.el)
5997 (eval-when-compile
5998 (require 'cus-edit)
5999 (require 'wid-edit)
6000 (require 'widget))
6003 (defvar pr-i-window-configuration nil)
6005 (defvar pr-i-buffer nil)
6006 (defvar pr-i-region nil)
6007 (defvar pr-i-mode nil)
6008 (defvar pr-i-despool nil)
6009 (defvar pr-i-ps-as-is t)
6010 (defvar pr-i-n-up 1)
6011 (defvar pr-i-directory "./")
6012 (defvar pr-i-regexp "")
6013 (defvar pr-i-ps-file "")
6014 (defvar pr-i-out-file "")
6015 (defvar pr-i-answer-yes nil)
6016 (defvar pr-i-process 'buffer)
6017 (defvar pr-i-ps-send 'printer)
6020 (defvar pr-interface-map nil
6021 "Keymap for pr-interface.")
6023 (unless pr-interface-map
6024 (let ((map (make-sparse-keymap)))
6025 (cond ((featurep 'xemacs) ; XEmacs
6026 (pr-set-keymap-parents map (list widget-keymap))
6027 (pr-set-keymap-name map 'pr-interface-map))
6028 (t ; GNU Emacs
6029 (pr-set-keymap-parents map widget-keymap)))
6030 (define-key map "q" 'pr-interface-quit)
6031 (define-key map "?" 'pr-interface-help)
6032 (setq pr-interface-map map)))
6035 (defmacro pr-interface-save (&rest body)
6036 `(with-current-buffer pr-i-buffer
6037 ,@body))
6040 (defun pr-create-interface ()
6041 "Create the front end for printing package."
6042 (setq pr-i-buffer (buffer-name (current-buffer))
6043 pr-i-region (ps-mark-active-p)
6044 pr-i-mode (pr-mode-alist-p)
6045 pr-i-window-configuration (current-window-configuration))
6047 (put 'pr-i-process 'pr-widget-list nil)
6048 (put 'pr-i-ps-send 'pr-widget-list nil)
6050 (delete-other-windows)
6051 (kill-buffer (get-buffer-create pr-buffer-name))
6052 (switch-to-buffer (get-buffer-create pr-buffer-name))
6054 ;; header
6055 (let ((versions (concat "printing v" pr-version
6056 " ps-print v" ps-print-version)))
6057 ;; to keep compatibility with Emacs 20 & 21:
6058 ;; DO NOT REPLACE `?\ ' BY `?\s'
6059 (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
6060 (pr-insert-italic "\nCurrent Directory : " 1)
6061 (pr-insert-italic default-directory)
6063 (pr-insert-section-1) ; 1. Print
6064 (pr-insert-section-2) ; 2. PostScript Printer
6065 (pr-insert-section-3) ; 3. Text Printer
6067 ;; separator
6068 (widget-insert "\n\n " (make-string 77 ?-))
6070 (pr-insert-section-4) ; 4. Settings
6071 (pr-insert-section-5) ; 5. Customize
6072 (pr-insert-section-6) ; 6. Show Settings
6073 (pr-insert-section-7) ; 7. Help
6075 (use-local-map pr-interface-map)
6076 (widget-setup)
6077 (goto-char (point-min))
6079 (and pr-i-region ; let region activated
6080 (pr-keep-region-active)))
6083 (defun pr-insert-section-1 ()
6084 ;; 1. Print:
6085 (pr-insert-italic "\nPrint :" 1)
6087 ;; 1a. Buffer:
6088 ;; 1a. Buffer: Buffer List
6089 (pr-insert-radio-button 'pr-i-process 'buffer)
6090 (pr-insert-menu "Buffer List" 'pr-i-buffer
6091 (let ((blist (buffer-list))
6092 case-fold-search choices)
6093 (while blist
6094 (let ((name (buffer-name (car blist)))
6095 (ignore pr-buffer-name-ignore)
6096 found)
6097 (setq blist (cdr blist))
6098 (while (and ignore (not found))
6099 (setq found (string-match (car ignore) name)
6100 ignore (cdr ignore)))
6101 (or found
6102 (setq choices
6103 (cons (list 'quote
6104 (list 'choice-item
6105 :format "%[%t%]"
6106 name))
6107 choices)))))
6108 (nreverse choices))
6109 " Buffer : " nil
6110 '(progn
6111 (pr-interface-save
6112 (setq pr-i-region (ps-mark-active-p)
6113 pr-i-mode (pr-mode-alist-p)))
6114 (pr-update-checkbox 'pr-i-region)
6115 (pr-update-checkbox 'pr-i-mode)))
6116 ;; 1a. Buffer: Region
6117 (put 'pr-i-region 'pr-widget
6118 (pr-insert-checkbox
6119 "\n "
6120 'pr-i-region
6121 #'(lambda (widget &rest ignore)
6122 (let ((region-p (pr-interface-save
6123 (ps-mark-active-p))))
6124 (cond ((null (widget-value widget)) ; widget is nil
6125 (setq pr-i-region nil))
6126 (region-p ; widget is true and there is a region
6127 (setq pr-i-region t)
6128 (widget-value-set widget t)
6129 (widget-setup)) ; MUST be called after widget-value-set
6130 (t ; widget is true and there is no region
6131 (ding)
6132 (message "There is no region active")
6133 (setq pr-i-region nil)
6134 (widget-value-set widget nil)
6135 (widget-setup))))) ; MUST be called after widget-value-set
6136 " Region"))
6137 ;; 1a. Buffer: Mode
6138 (put 'pr-i-mode 'pr-widget
6139 (pr-insert-checkbox
6141 'pr-i-mode
6142 #'(lambda (widget &rest ignore)
6143 (let ((mode-p (pr-interface-save
6144 (pr-mode-alist-p))))
6145 (cond
6146 ((null (widget-value widget)) ; widget is nil
6147 (setq pr-i-mode nil))
6148 (mode-p ; widget is true and there is a `mode'
6149 (setq pr-i-mode t)
6150 (widget-value-set widget t)
6151 (widget-setup)) ; MUST be called after widget-value-set
6152 (t ; widget is true and there is no `mode'
6153 (ding)
6154 (message
6155 "This buffer isn't in a mode that printing treats specially.")
6156 (setq pr-i-mode nil)
6157 (widget-value-set widget nil)
6158 (widget-setup))))) ; MUST be called after widget-value-set
6159 " Mode\n"))
6161 ;; 1b. Directory:
6162 (pr-insert-radio-button 'pr-i-process 'directory)
6163 (widget-create
6164 'directory
6165 :size 58
6166 :format " Directory : %v"
6167 :notify 'pr-interface-directory
6168 :action (lambda (widget &optional event)
6169 (if (pr-interface-directory widget)
6170 (pr-widget-field-action widget event)
6171 (ding)
6172 (message "Please specify a readable directory")))
6173 pr-i-directory)
6174 ;; 1b. Directory: File Regexp
6175 (widget-create 'regexp
6176 :size 58
6177 :format "\n File Regexp : %v\n"
6178 :notify (lambda (widget &rest ignore)
6179 (setq pr-i-regexp (widget-value widget)))
6180 pr-i-regexp)
6181 ;; 1b. Directory: List Directory Entry
6182 (widget-insert " ")
6183 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
6185 ;; 1c. PostScript File:
6186 (pr-insert-radio-button 'pr-i-process 'file)
6187 (widget-create
6188 'file
6189 :size 51
6190 :format " PostScript File : %v"
6191 :notify 'pr-interface-infile
6192 :action (lambda (widget &rest event)
6193 (if (pr-interface-infile widget)
6194 (pr-widget-field-action widget event)
6195 (ding)
6196 (message "Please specify a readable PostScript file")))
6197 pr-i-ps-file)
6198 ;; 1c. PostScript File: PostScript Utility
6199 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
6200 (pr-choice-alist pr-ps-utility-alist)
6201 "\n PostScript Utility : "
6202 " ")
6203 ;; 1c. PostScript File: No Preprocessing
6204 (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
6207 (defun pr-insert-section-2 ()
6208 ;; 2. PostScript Printer:
6209 ;; 2. PostScript Printer: PostScript Printer List
6210 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
6211 (pr-insert-menu "PostScript Printer" 'pr-ps-name
6212 (pr-choice-alist pr-ps-printer-alist))
6213 ;; 2. PostScript Printer: Despool
6214 (put 'pr-i-despool 'pr-widget
6215 (pr-insert-checkbox
6217 'pr-i-despool
6218 #'(lambda (widget &rest ignore)
6219 (if pr-spool-p
6220 (setq pr-i-despool (not pr-i-despool))
6221 (ding)
6222 (message "Can despool only when spooling is actually selected")
6223 (setq pr-i-despool nil))
6224 (widget-value-set widget pr-i-despool)
6225 (widget-setup)) ; MUST be called after widget-value-set
6226 " Despool "))
6227 ;; 2. PostScript Printer: Preview Print Quit
6228 (pr-insert-button 'pr-interface-preview "Preview" " ")
6229 (pr-insert-button 'pr-interface-ps-print "Print" " ")
6230 (pr-insert-button 'pr-interface-quit "Quit")
6231 ;; 2. PostScript Printer: Send to Printer/Temporary File
6232 (pr-insert-radio-button 'pr-i-ps-send 'printer)
6233 (widget-insert " Send to Printer/Temporary File")
6234 ;; 2. PostScript Printer: Send to File
6235 (pr-insert-radio-button 'pr-i-ps-send 'file)
6236 (widget-create
6237 'file
6238 :size 57
6239 :format " Send to File : %v"
6240 :notify 'pr-interface-outfile
6241 :action (lambda (widget &rest event)
6242 (if (and (pr-interface-outfile widget)
6243 (or (not (file-exists-p pr-i-out-file))
6244 (setq pr-i-answer-yes
6245 (y-or-n-p "File exists; overwrite? "))))
6246 (pr-widget-field-action widget event)
6247 (ding)
6248 (message "Please specify a writable PostScript file")))
6249 pr-i-out-file)
6250 ;; 2. PostScript Printer: N-Up
6251 (widget-create
6252 'integer
6253 :size 3
6254 :format "\n N-Up : %v"
6255 :notify (lambda (widget &rest ignore)
6256 (let ((value (if (string= (widget-apply widget :value-get) "")
6258 (widget-value widget))))
6259 (if (and (integerp value)
6260 (<= 1 value) (<= value 100))
6261 (progn
6262 (message " ")
6263 (setq pr-i-n-up value))
6264 (ding)
6265 (message "Please specify an integer between 1 and 100"))))
6266 pr-i-n-up))
6269 (defun pr-insert-section-3 ()
6270 ;; 3. Text Printer:
6271 (pr-insert-italic "\n\nText Printer : " 2 14)
6272 (pr-insert-menu "Text Printer" 'pr-txt-name
6273 (pr-choice-alist pr-txt-printer-alist)
6274 nil " ")
6275 (pr-insert-button 'pr-interface-printify "Printify" " ")
6276 (pr-insert-button 'pr-interface-txt-print "Print" " ")
6277 (pr-insert-button 'pr-interface-quit "Quit"))
6280 (defun pr-insert-section-4 ()
6281 ;; 4. Settings:
6282 ;; 4. Settings: Landscape Auto Region Verbose
6283 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
6284 #'(lambda (&rest ignore)
6285 (setq ps-landscape-mode (not ps-landscape-mode)
6286 pr-file-landscape ps-landscape-mode))
6287 " Landscape ")
6288 (pr-insert-toggle 'pr-auto-region " Auto Region ")
6289 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
6291 ;; 4. Settings: Print Header Auto Mode
6292 (pr-insert-toggle 'ps-print-header " Print Header ")
6293 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
6295 ;; 4. Settings: Print Header Frame Menu Lock
6296 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
6297 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
6299 ;; 4. Settings: Line Number
6300 (pr-insert-toggle 'ps-line-number " Line Number\n ")
6302 ;; 4. Settings: Zebra Stripes Spool Buffer
6303 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
6304 (pr-insert-checkbox " "
6305 'pr-spool-p
6306 #'(lambda (&rest ignore)
6307 (setq pr-spool-p (not pr-spool-p))
6308 (unless pr-spool-p
6309 (setq pr-i-despool nil)
6310 (pr-update-checkbox 'pr-i-despool)))
6311 " Spool Buffer")
6313 ;; 4. Settings: Duplex Print with faces
6314 (pr-insert-checkbox "\n "
6315 'ps-spool-duplex
6316 #'(lambda (&rest ignore)
6317 (setq ps-spool-duplex (not ps-spool-duplex)
6318 pr-file-duplex ps-spool-duplex))
6319 " Duplex ")
6320 (pr-insert-toggle 'pr-faces-p " Print with faces")
6322 ;; 4. Settings: Tumble Print via Ghostscript
6323 (pr-insert-checkbox "\n "
6324 'ps-spool-tumble
6325 #'(lambda (&rest ignore)
6326 (setq ps-spool-tumble (not ps-spool-tumble)
6327 pr-file-tumble ps-spool-tumble))
6328 " Tumble ")
6329 (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
6331 ;; 4. Settings: Upside-Down Page Parity
6332 (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
6333 (pr-insert-italic "\n\nSelect Pages : " 2 14)
6334 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
6335 (mapcar #'(lambda (alist)
6336 (list 'quote
6337 (list 'choice-item
6338 :format "%[%t%]"
6339 :tag (cdr alist)
6340 :value (car alist))))
6341 pr-even-or-odd-alist)))
6344 (defun pr-insert-section-5 ()
6345 ;; 5. Customize:
6346 (pr-insert-italic "\n\nCustomize : " 2 11)
6347 (pr-insert-button 'pr-customize "printing" " ")
6348 (pr-insert-button #'(lambda (&rest ignore) (ps-print-customize))
6349 "ps-print" " ")
6350 (pr-insert-button 'lpr-customize "lpr"))
6353 (defun pr-insert-section-6 ()
6354 ;; 6. Show Settings:
6355 (pr-insert-italic "\nShow Settings : " 1 14)
6356 (pr-insert-button 'pr-show-pr-setup "printing" " ")
6357 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
6358 (pr-insert-button 'pr-show-lpr-setup "lpr"))
6361 (defun pr-insert-section-7 ()
6362 ;; 7. Help:
6363 (pr-insert-italic "\nHelp : " 1 5)
6364 (pr-insert-button 'pr-interface-help "Interface Help" " ")
6365 (pr-insert-button 'pr-help "Menu Help" " ")
6366 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
6367 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
6370 (defun pr-kill-help (&rest ignore)
6371 "Kill all printing help buffer."
6372 (interactive)
6373 (let ((help '("*Printing Interface Help*" "*Printing Help*"
6374 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
6375 (while help
6376 (let ((buffer (get-buffer (car help))))
6377 (setq help (cdr help))
6378 (when buffer
6379 (delete-windows-on buffer)
6380 (kill-buffer buffer)))))
6381 (recenter (- (window-height) 2)))
6384 (defun pr-interface-quit (&rest ignore)
6385 "Kill the printing buffer interface and quit."
6386 (interactive)
6387 (kill-buffer pr-buffer-name)
6388 (set-window-configuration pr-i-window-configuration))
6391 (defun pr-interface-help (&rest ignore)
6392 "printing buffer interface help."
6393 (interactive)
6394 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
6397 (defun pr-interface-txt-print (&rest ignore)
6398 "Print using lpr package."
6399 (interactive)
6400 (condition-case data
6401 (cond
6402 ((eq pr-i-process 'directory)
6403 (pr-i-directory)
6404 (pr-interface-save
6405 (pr-txt-directory pr-i-directory pr-i-regexp)))
6406 ((eq pr-i-process 'buffer)
6407 (pr-interface-save
6408 (cond (pr-i-region
6409 (let ((pr-auto-mode pr-i-mode))
6410 (pr-txt-region)))
6411 (pr-i-mode
6412 (let (pr-auto-region)
6413 (pr-txt-mode)))
6415 (let (pr-auto-mode pr-auto-region)
6416 (pr-txt-buffer)))
6418 ((eq pr-i-process 'file)
6419 (error "Please specify a text file"))
6421 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6423 ;; handlers
6424 ((quit error)
6425 (ding)
6426 (message "%s" (error-message-string data)))))
6429 (defun pr-interface-printify (&rest ignore)
6430 "Printify a buffer."
6431 (interactive)
6432 (condition-case data
6433 (cond
6434 ((eq pr-i-process 'directory)
6435 (pr-i-directory)
6436 (pr-interface-save
6437 (pr-printify-directory pr-i-directory pr-i-regexp)))
6438 ((eq pr-i-process 'buffer)
6439 (pr-interface-save
6440 (if pr-i-region
6441 (pr-printify-region)
6442 (pr-printify-buffer))))
6443 ((eq pr-i-process 'file)
6444 (error "Cannot printify a PostScript file"))
6446 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6448 ;; handlers
6449 ((quit error)
6450 (ding)
6451 (message "%s" (error-message-string data)))))
6454 (defun pr-interface-ps-print (&rest ignore)
6455 "Print using ps-print package."
6456 (interactive)
6457 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6458 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6459 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6460 'pr-ps-buffer-ps-print))
6463 (defun pr-interface-preview (&rest ignore)
6464 "Preview a PostScript file."
6465 (interactive)
6466 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6467 'pr-ps-file-preview 'pr-ps-file-up-preview
6468 'pr-ps-region-preview 'pr-ps-mode-preview
6469 'pr-ps-buffer-preview))
6472 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6473 ps-mode ps-buffer)
6474 (condition-case data
6475 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6476 (pr-i-ps-send))))
6477 (cond
6478 ((and pr-i-despool pr-spool-p)
6479 (pr-interface-save
6480 (funcall ps-despool outfile))
6481 (setq pr-i-despool nil)
6482 (pr-update-checkbox 'pr-i-despool))
6483 ((eq pr-i-process 'directory)
6484 (pr-i-directory)
6485 (pr-interface-save
6486 (funcall ps-directory
6487 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6488 ((eq pr-i-process 'file)
6489 (cond ((or (file-directory-p pr-i-ps-file)
6490 (not (file-readable-p pr-i-ps-file)))
6491 (error "Please specify a readable PostScript file"))
6492 (pr-i-ps-as-is
6493 (pr-interface-save
6494 (funcall ps-file pr-i-ps-file)))
6496 (pr-interface-save
6497 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6499 ((eq pr-i-process 'buffer)
6500 (pr-interface-save
6501 (cond (pr-i-region
6502 (let ((pr-auto-mode pr-i-mode))
6503 (funcall ps-region pr-i-n-up outfile)))
6504 (pr-i-mode
6505 (let (pr-auto-region)
6506 (funcall ps-mode pr-i-n-up outfile)))
6508 (let (pr-auto-mode pr-auto-region)
6509 (funcall ps-buffer pr-i-n-up outfile)))
6512 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6514 ;; handlers
6515 ((quit error)
6516 (ding)
6517 (message "%s" (error-message-string data)))))
6520 (defun pr-i-ps-send ()
6521 (cond ((eq pr-i-ps-send 'printer)
6522 nil)
6523 ((not (eq pr-i-ps-send 'file))
6524 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6525 ((or (file-directory-p pr-i-out-file)
6526 (not (file-writable-p pr-i-out-file)))
6527 (error "Please specify a writable PostScript file"))
6528 ((or (not (file-exists-p pr-i-out-file))
6529 pr-i-answer-yes
6530 (setq pr-i-answer-yes
6531 (y-or-n-p (format "File `%s' exists; overwrite? "
6532 pr-i-out-file))))
6533 pr-i-out-file)
6535 (error "File already exists"))))
6538 (defun pr-i-directory ()
6539 (or (and (file-directory-p pr-i-directory)
6540 (file-readable-p pr-i-directory))
6541 (error "Please specify be a readable directory")))
6544 (defun pr-interface-directory (widget &rest ignore)
6545 (and pr-buffer-verbose
6546 (message "You can use M-TAB or ESC TAB for file completion"))
6547 (let ((dir (widget-value widget)))
6548 (and (file-directory-p dir)
6549 (file-readable-p dir)
6550 (setq pr-i-directory dir))))
6553 (defun pr-interface-infile (widget &rest ignore)
6554 (and pr-buffer-verbose
6555 (message "You can use M-TAB or ESC TAB for file completion"))
6556 (let ((file (widget-value widget)))
6557 (and (not (file-directory-p file))
6558 (file-readable-p file)
6559 (setq pr-i-ps-file file))))
6562 (defun pr-interface-outfile (widget &rest ignore)
6563 (setq pr-i-answer-yes nil)
6564 (and pr-buffer-verbose
6565 (message "You can use M-TAB or ESC TAB for file completion"))
6566 (let ((file (widget-value widget)))
6567 (and (not (file-directory-p file))
6568 (file-writable-p file)
6569 (setq pr-i-out-file file))))
6572 (defun pr-widget-field-action (widget event)
6573 (and (get-buffer "*Completions*") ; clean frame window
6574 (delete-windows-on "*Completions*"))
6575 (message " ") ; clean echo area
6576 (widget-field-action widget event))
6579 (defun pr-insert-italic (str &optional from to)
6580 (let ((len (length str)))
6581 (put-text-property (if from (max from 0) 0)
6582 (if to (max to len) len)
6583 'face 'italic str)
6584 (widget-insert str)))
6587 (defun pr-insert-checkbox (before var-sym fun label)
6588 (widget-insert before)
6589 (prog1
6590 (widget-create 'checkbox
6591 :notify fun
6592 (symbol-value var-sym))
6593 (widget-insert label)))
6596 (defun pr-insert-toggle (var-sym label)
6597 (widget-create 'checkbox
6598 :notify `(lambda (&rest ignore)
6599 (setq ,var-sym (not ,var-sym)))
6600 (symbol-value var-sym))
6601 (widget-insert label))
6604 (defun pr-insert-button (fun label &optional separator)
6605 (widget-create 'push-button
6606 :notify fun
6607 label)
6608 (and separator
6609 (widget-insert separator)))
6612 (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6613 (and before (widget-insert before))
6614 (eval `(widget-create 'menu-choice
6615 :tag ,tag
6616 :format "%v"
6617 :inline t
6618 :value ,var-sym
6619 :notify (lambda (widget &rest ignore)
6620 (setq ,var-sym (widget-value widget))
6621 ,@body)
6622 :void '(choice-item :format "%[%t%]"
6623 :tag "Can not display value!")
6624 ,@choices))
6625 (and after (widget-insert after)))
6628 (defun pr-insert-radio-button (var-sym sym)
6629 (widget-insert "\n")
6630 (let ((wid-list (get var-sym 'pr-widget-list))
6631 (wid (eval `(widget-create
6632 'radio-button
6633 :format " %[%v%]"
6634 :value (eq ,var-sym (quote ,sym))
6635 :notify (lambda (&rest ignore)
6636 (setq ,var-sym (quote ,sym))
6637 (pr-update-radio-button (quote ,var-sym)))))))
6638 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6641 (defun pr-update-radio-button (var-sym)
6642 (let ((wid-list (get var-sym 'pr-widget-list)))
6643 (while wid-list
6644 (let ((wid (car (car wid-list)))
6645 (value (cdr (car wid-list))))
6646 (setq wid-list (cdr wid-list))
6647 (widget-value-set wid (eq (symbol-value var-sym) value))))
6648 (widget-setup)))
6651 (defun pr-update-checkbox (var-sym)
6652 (let ((wid (get var-sym 'pr-widget)))
6653 (when wid
6654 (widget-value-set wid (symbol-value var-sym))
6655 (widget-setup))))
6658 (defun pr-choice-alist (alist)
6659 (let ((max (apply 'max (mapcar #'(lambda (alist)
6660 (length (symbol-name (car alist))))
6661 alist))))
6662 (mapcar #'(lambda (alist)
6663 (let* ((sym (car alist))
6664 (name (symbol-name sym)))
6665 (list
6666 'quote
6667 (list
6668 'choice-item
6669 :format "%[%t%]"
6670 :tag (concat name
6671 (make-string (- max (length name)) ?_))
6672 :value sym))))
6673 alist)))
6676 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6679 (provide 'printing)
6682 ;;; printing.el ends here