Update .gitattributes for DOS EOL files
[emacs.git] / lisp / printing.el
blob86d569a6ac61a4cf2fd8f3450c8c7a1b290c7e96
1 ;;; printing.el --- printing utilities
3 ;; Copyright (C) 2000-2001, 2003-2015 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 bug-gnu-emacs@gnu.org and Vinicius Jose Latorre <viniciusjl@ig.com.br>
18 ;; This file is part of GNU Emacs.
20 ;; GNU Emacs is free software: you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation, either version 3 of the License, or
23 ;; (at your option) any later version.
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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 lpr-windows-system (getenv "OSTYPE")
1034 (string-match "cygwin" (getenv "OSTYPE"))))
1037 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1038 ;; To avoid compilation gripes
1041 ;; Emacs has this since at least 21.1.
1042 (when (featurep 'xemacs)
1043 (or (fboundp 'subst-char-in-string) ; hacked from subr.el
1044 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1045 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1046 Unless optional argument INPLACE is non-nil, return a new string."
1047 (let ((i (length string))
1048 (newstr (if inplace string (copy-sequence string))))
1049 (while (> (setq i (1- i)) 0)
1050 (if (eq (aref newstr i) fromchar)
1051 (aset newstr i tochar)))
1052 newstr))))
1055 ;; Emacs has this since at least 21.1, but the SUFFIX argument
1056 ;; (which this file uses) only since 22.1. So the fboundp test
1057 ;; wasn't even correct/adequate. Whatever, no-one is using
1058 ;; this file on older Emacs version, so it's irrelevant.
1059 (when (featurep 'xemacs)
1060 (or (fboundp 'make-temp-file) ; hacked from subr.el
1061 (defun make-temp-file (prefix &optional dir-flag suffix)
1062 "Create a temporary file.
1063 The returned file name (created by appending some random characters at the end
1064 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1065 is guaranteed to point to a newly created empty file.
1066 You can then use `write-region' to write new data into the file.
1068 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1070 If SUFFIX is non-nil, add that at the end of the file name."
1071 (let ((umask (default-file-modes))
1072 file)
1073 (unwind-protect
1074 (progn
1075 ;; Create temp files with strict access rights. It's easy to
1076 ;; loosen them later, whereas it's impossible to close the
1077 ;; time-window of loose permissions otherwise.
1078 (set-default-file-modes ?\700)
1079 (while (condition-case ()
1080 (progn
1081 (setq file
1082 (make-temp-name
1083 (expand-file-name prefix temporary-file-directory)))
1084 (if suffix
1085 (setq file (concat file suffix)))
1086 (if dir-flag
1087 (make-directory file)
1088 (write-region "" nil file nil 'silent nil 'excl))
1089 nil)
1090 (file-already-exists t))
1091 ;; the file was somehow created by someone else between
1092 ;; `make-temp-name' and `write-region', let's try again.
1093 nil)
1094 file)
1095 ;; Reset the umask.
1096 (set-default-file-modes umask))))))
1099 (eval-when-compile
1100 ;; User Interface --- declared here to avoid compiler warnings
1101 (defvar pr-path-style)
1102 (defvar pr-auto-region)
1103 (defvar pr-menu-char-height)
1104 (defvar pr-menu-char-width)
1105 (defvar pr-menu-lock)
1106 (defvar pr-ps-printer-alist)
1107 (defvar pr-txt-printer-alist)
1108 (defvar pr-ps-utility-alist)
1111 ;; Internal fun alias to avoid compilation gripes
1112 (defalias 'pr-menu-lookup 'ignore)
1113 (defalias 'pr-menu-lock 'ignore)
1114 (defalias 'pr-menu-alist 'ignore)
1115 (defalias 'pr-even-or-odd-pages 'ignore)
1116 (defalias 'pr-menu-get-item 'ignore)
1117 (defalias 'pr-menu-set-item-name 'ignore)
1118 (defalias 'pr-menu-set-utility-title 'ignore)
1119 (defalias 'pr-menu-set-ps-title 'ignore)
1120 (defalias 'pr-menu-set-txt-title 'ignore)
1121 (defalias 'pr-region-active-p 'ignore)
1122 (defalias 'pr-do-update-menus 'ignore)
1123 (defalias 'pr-update-mode-line 'ignore)
1124 (defalias 'pr-read-string 'ignore)
1125 (defalias 'pr-set-keymap-parents 'ignore)
1126 (defalias 'pr-keep-region-active 'ignore))
1129 ;; Internal Vars --- defined here to avoid compiler warnings
1130 (defvar pr-menu-print-item "print"
1131 "Non-nil means that menu binding was not done.
1133 Used by `pr-menu-bind' and `pr-update-menus'.")
1135 (defvar pr-ps-printer-menu-modified t
1136 "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
1138 (defvar pr-txt-printer-menu-modified t
1139 "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
1141 (defvar pr-ps-utility-menu-modified t
1142 "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
1144 (defconst pr-even-or-odd-alist
1145 '((nil . "Print All Pages")
1146 (even-page . "Print Even Pages")
1147 (odd-page . "Print Odd Pages")
1148 (even-sheet . "Print Even Sheets")
1149 (odd-sheet . "Print Odd Sheets")))
1152 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1153 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1154 ;; XEmacs Definitions
1157 (cond
1158 ((featurep 'xemacs) ; XEmacs
1159 ;; XEmacs
1160 (defalias 'pr-set-keymap-parents 'set-keymap-parents)
1161 (defalias 'pr-set-keymap-name 'set-keymap-name)
1163 ;; XEmacs
1164 (defun pr-read-string (prompt initial history default)
1165 (let ((str (read-string prompt initial)))
1166 (if (and str (not (string= str "")))
1168 default)))
1170 ;; XEmacs
1171 (defvar zmacs-region-stays nil)
1173 ;; XEmacs
1174 (defun pr-keep-region-active ()
1175 (setq zmacs-region-stays t))
1177 ;; XEmacs
1178 (defun pr-region-active-p ()
1179 (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p)))
1181 ;; XEmacs
1182 (defun pr-menu-char-height ()
1183 (font-height (face-font 'default)))
1185 ;; XEmacs
1186 (defun pr-menu-char-width ()
1187 (font-width (face-font 'default)))
1189 ;; XEmacs
1190 (defmacro pr-xemacs-global-menubar (&rest body)
1191 `(save-excursion
1192 (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
1193 ;; be sure to access global menubar
1194 (set-buffer temp)
1195 ,@body
1196 (kill-buffer temp))))
1198 ;; XEmacs
1199 (defun pr-global-menubar (pr-menu-spec)
1200 ;; Menu binding
1201 (pr-xemacs-global-menubar
1202 (add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
1203 (setq pr-menu-print-item nil))
1205 ;; XEmacs
1206 (defvar current-mouse-event nil)
1207 (defun pr-menu-position (entry index horizontal)
1208 (make-event
1209 'button-release
1210 (list 'button 1
1211 'x (- (event-x-pixel current-mouse-event) ; X
1212 (* horizontal pr-menu-char-width))
1213 'y (- (event-y-pixel current-mouse-event) ; Y
1214 (* (pr-menu-index entry index) pr-menu-char-height)))))
1216 (defvar pr-menu-position nil)
1217 (defvar pr-menu-state nil)
1219 ;; XEmacs
1220 (defvar current-menubar nil) ; to avoid compilation gripes
1221 (defun pr-menu-lookup (path)
1222 (car (find-menu-item current-menubar (cons "Printing" path))))
1224 ;; XEmacs
1225 (defun pr-menu-lock (entry index horizontal state path)
1226 (when pr-menu-lock
1227 (or (and pr-menu-position (eq state pr-menu-state))
1228 (setq pr-menu-position (pr-menu-position entry index horizontal)
1229 pr-menu-state state))
1230 (let* ((menu (pr-menu-lookup path))
1231 (result (get-popup-menu-response menu pr-menu-position)))
1232 (and (misc-user-event-p result)
1233 (funcall (event-function result)
1234 (event-object result))))
1235 (setq pr-menu-position nil)))
1237 ;; XEmacs
1238 (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
1240 ;; XEmacs
1241 (defvar pr-ps-name-old "PostScript Printers")
1242 (defvar pr-txt-name-old "Text Printers")
1243 (defvar pr-ps-utility-old "PostScript Utility")
1244 (defvar pr-even-or-odd-old "Print All Pages")
1246 ;; XEmacs
1247 (defun pr-do-update-menus (&optional force)
1248 (pr-menu-alist pr-ps-printer-alist
1249 'pr-ps-name
1250 'pr-menu-set-ps-title
1251 '("Printing")
1252 'pr-ps-printer-menu-modified
1253 force
1254 pr-ps-name-old
1255 'postscript 2)
1256 (pr-menu-alist pr-txt-printer-alist
1257 'pr-txt-name
1258 'pr-menu-set-txt-title
1259 '("Printing")
1260 'pr-txt-printer-menu-modified
1261 force
1262 pr-txt-name-old
1263 'text 2)
1264 (let ((save-var pr-ps-utility-menu-modified))
1265 (pr-menu-alist pr-ps-utility-alist
1266 'pr-ps-utility
1267 'pr-menu-set-utility-title
1268 '("Printing" "PostScript Print" "File")
1269 'save-var
1270 force
1271 pr-ps-utility-old
1272 nil 1))
1273 (pr-menu-alist pr-ps-utility-alist
1274 'pr-ps-utility
1275 'pr-menu-set-utility-title
1276 '("Printing" "PostScript Preview" "File")
1277 'pr-ps-utility-menu-modified
1278 force
1279 pr-ps-utility-old
1280 nil 1)
1281 (pr-even-or-odd-pages ps-even-or-odd-pages force))
1283 ;; XEmacs
1284 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1285 entry index)
1286 (when (and alist (or force (symbol-value modified-sym)))
1287 (pr-xemacs-global-menubar
1288 (add-submenu menu-path
1289 (pr-menu-create name alist var-sym
1290 fun entry index)))
1291 (funcall fun (symbol-value var-sym))
1292 (set modified-sym nil)))
1294 ;; XEmacs
1295 (defun pr-relabel-menu-item (newname var-sym)
1296 (pr-xemacs-global-menubar
1297 (relabel-menu-item
1298 (list "Printing" (symbol-value var-sym))
1299 newname)
1300 (set var-sym newname)))
1302 ;; XEmacs
1303 (defun pr-menu-set-ps-title (value &optional item entry index)
1304 (pr-relabel-menu-item (format "PostScript Printer: %s" value)
1305 'pr-ps-name-old)
1306 (pr-ps-set-printer value)
1307 (and index
1308 (pr-menu-lock entry index 12 'toggle nil)))
1310 ;; XEmacs
1311 (defun pr-menu-set-txt-title (value &optional item entry index)
1312 (pr-relabel-menu-item (format "Text Printer: %s" value)
1313 'pr-txt-name-old)
1314 (pr-txt-set-printer value)
1315 (and index
1316 (pr-menu-lock entry index 12 'toggle nil)))
1318 ;; XEmacs
1319 (defun pr-menu-set-utility-title (value &optional item entry index)
1320 (pr-xemacs-global-menubar
1321 (let ((newname (format "%s" value)))
1322 (relabel-menu-item
1323 (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
1324 newname)
1325 (relabel-menu-item
1326 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
1327 newname)
1328 (setq pr-ps-utility-old newname)))
1329 (pr-ps-set-utility value)
1330 (and index
1331 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
1333 ;; XEmacs
1334 (defun pr-even-or-odd-pages (value &optional no-lock)
1335 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
1336 'pr-even-or-odd-old)
1337 (setq ps-even-or-odd-pages value)
1338 (or no-lock
1339 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
1342 (t ; GNU Emacs
1343 ;; Do nothing
1344 )) ; end cond featurep
1348 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1349 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1350 ;; GNU Emacs Definitions
1352 (eval-and-compile
1353 (unless (featurep 'xemacs)
1354 (defvar pr-menu-bar nil
1355 "Specify Printing menu-bar entry.")))
1357 (cond
1358 ((featurep 'xemacs) ; XEmacs
1359 ;; Do nothing
1361 (t ; GNU Emacs
1362 ;; GNU Emacs
1363 (defalias 'pr-set-keymap-parents 'set-keymap-parent)
1364 (defalias 'pr-set-keymap-name 'ignore)
1365 (defalias 'pr-read-string 'read-string)
1367 ;; GNU Emacs
1368 (defvar deactivate-mark)
1370 ;; GNU Emacs
1371 (defun pr-keep-region-active ()
1372 (setq deactivate-mark nil))
1374 ;; GNU Emacs
1375 (defun pr-region-active-p ()
1376 (and pr-auto-region transient-mark-mode mark-active))
1378 ;; GNU Emacs
1379 (defun pr-menu-char-height ()
1380 (frame-char-height))
1382 ;; GNU Emacs
1383 (defun pr-menu-char-width ()
1384 (frame-char-width))
1386 ;; GNU Emacs
1387 ;; Menu binding
1388 ;; Replace existing "print" item by "Printing" item.
1389 ;; If you're changing this file, you'll load it a second,
1390 ;; third... time, but "print" item exists only in the first load.
1391 (eval-when-compile
1392 (require 'easymenu)) ; to avoid compilation gripes
1394 (declare-function easy-menu-add-item "easymenu"
1395 (map path item &optional before))
1396 (declare-function easy-menu-remove-item "easymenu" (map path name))
1398 (eval-and-compile
1399 (defun pr-global-menubar (pr-menu-spec)
1400 (require 'easymenu)
1401 (let ((menu-file (if (= emacs-major-version 21)
1402 '("menu-bar" "files") ; GNU Emacs 21
1403 '("menu-bar" "file")))) ; GNU Emacs 22 or higher
1404 (cond
1405 (pr-menu-print-item
1406 (easy-menu-add-item global-map menu-file
1407 (easy-menu-create-menu "Print" pr-menu-spec)
1408 "print-buffer")
1409 (dolist (item '("print-buffer" "print-region"
1410 "ps-print-buffer-faces" "ps-print-region-faces"
1411 "ps-print-buffer" "ps-print-region"))
1412 (easy-menu-remove-item global-map menu-file item))
1413 (setq pr-menu-print-item nil
1414 pr-menu-bar (vector 'menu-bar
1415 (pr-get-symbol (nth 1 menu-file))
1416 (pr-get-symbol "Print"))))
1418 (easy-menu-add-item global-map menu-file
1419 (easy-menu-create-menu "Print" pr-menu-spec)))
1420 ))))
1422 (eval-and-compile
1423 (cond
1424 (lpr-windows-system
1425 ;; GNU Emacs for Windows 9x/NT
1426 (defun pr-menu-position (entry index horizontal)
1427 (let ((pos (cdr (mouse-pixel-position))))
1428 (list
1429 (list (or (car pos) 0) ; X
1430 (- (or (cdr pos) 0) ; Y
1431 (* (pr-menu-index entry index) pr-menu-char-height)))
1432 (selected-frame)))) ; frame
1435 ;; GNU Emacs
1436 (defun pr-menu-position (entry index horizontal)
1437 (let ((pos (cdr (mouse-pixel-position))))
1438 (list
1439 (list (- (or (car pos) 0) ; X
1440 (* horizontal pr-menu-char-width))
1441 (- (or (cdr pos) 0) ; Y
1442 (* (pr-menu-index entry index) pr-menu-char-height)))
1443 (selected-frame)))) ; frame
1446 (defvar pr-menu-position nil)
1447 (defvar pr-menu-state nil)
1449 ;; GNU Emacs
1450 (defun pr-menu-lookup (path)
1451 (lookup-key global-map
1452 (if path
1453 (vconcat pr-menu-bar
1454 (mapcar 'pr-get-symbol
1455 (if (listp path)
1456 path
1457 (list path))))
1458 pr-menu-bar)))
1460 ;; GNU Emacs
1461 (defun pr-menu-lock (entry index horizontal state path)
1462 (when pr-menu-lock
1463 (or (and pr-menu-position (eq state pr-menu-state))
1464 (setq pr-menu-position (pr-menu-position entry index horizontal)
1465 pr-menu-state state))
1466 (let* ((menu (pr-menu-lookup path))
1467 (result (x-popup-menu pr-menu-position menu)))
1468 (and result
1469 (let ((command (lookup-key menu (vconcat result))))
1470 (if (fboundp command)
1471 (funcall command)
1472 (eval command)))))
1473 (setq pr-menu-position nil)))
1475 ;; GNU Emacs
1476 (defalias 'pr-update-mode-line 'force-mode-line-update)
1478 ;; GNU Emacs
1479 (defun pr-do-update-menus (&optional force)
1480 (pr-menu-alist pr-ps-printer-alist
1481 'pr-ps-name
1482 'pr-menu-set-ps-title
1483 "PostScript Printers"
1484 'pr-ps-printer-menu-modified
1485 force
1486 "PostScript Printers"
1487 'postscript 2)
1488 (pr-menu-alist pr-txt-printer-alist
1489 'pr-txt-name
1490 'pr-menu-set-txt-title
1491 "Text Printers"
1492 'pr-txt-printer-menu-modified
1493 force
1494 "Text Printers"
1495 'text 2)
1496 (let ((save-var pr-ps-utility-menu-modified))
1497 (pr-menu-alist pr-ps-utility-alist
1498 'pr-ps-utility
1499 'pr-menu-set-utility-title
1500 '("PostScript Print" "File" "PostScript Utility")
1501 'save-var
1502 force
1503 "PostScript Utility"
1504 nil 1))
1505 (pr-menu-alist pr-ps-utility-alist
1506 'pr-ps-utility
1507 'pr-menu-set-utility-title
1508 '("PostScript Preview" "File" "PostScript Utility")
1509 'pr-ps-utility-menu-modified
1510 force
1511 "PostScript Utility"
1512 nil 1)
1513 (pr-even-or-odd-pages ps-even-or-odd-pages force))
1515 ;; GNU Emacs
1516 (defun pr-menu-get-item (name-list)
1517 ;; NAME-LIST is a string or a list of strings.
1518 (or (listp name-list)
1519 (setq name-list (list name-list)))
1520 (and name-list
1521 (let* ((reversed (reverse name-list))
1522 (name (pr-get-symbol (car reversed)))
1523 (path (nreverse (cdr reversed)))
1524 (menu (lookup-key
1525 global-map
1526 (vconcat pr-menu-bar
1527 (mapcar 'pr-get-symbol path)))))
1528 (assq name (nthcdr 2 menu)))))
1530 ;; GNU Emacs
1531 (defvar pr-temp-menu nil)
1533 ;; GNU Emacs
1534 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1535 entry index)
1536 (when (and alist (or force (symbol-value modified-sym)))
1537 (easy-menu-define pr-temp-menu nil ""
1538 (pr-menu-create name alist var-sym fun entry index))
1539 (let ((item (pr-menu-get-item menu-path)))
1540 (and item
1541 (let* ((binding (nthcdr 3 item))
1542 (key-binding (cdr binding)))
1543 (setcar binding pr-temp-menu)
1544 (and key-binding (listp (car key-binding))
1545 (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
1546 (funcall fun (symbol-value var-sym) item))))
1547 (set modified-sym nil)))
1549 ;; GNU Emacs
1550 (defun pr-menu-set-item-name (item name)
1551 (and item
1552 (setcar (nthcdr 2 item) name))) ; ITEM-NAME
1554 ;; GNU Emacs
1555 (defun pr-menu-set-ps-title (value &optional item entry index)
1556 (pr-menu-set-item-name (or item
1557 (pr-menu-get-item "PostScript Printers"))
1558 (format "PostScript Printer: %s" value))
1559 (pr-ps-set-printer value)
1560 (and index
1561 (pr-menu-lock entry index 12 'toggle nil)))
1563 ;; GNU Emacs
1564 (defun pr-menu-set-txt-title (value &optional item entry index)
1565 (pr-menu-set-item-name (or item
1566 (pr-menu-get-item "Text Printers"))
1567 (format "Text Printer: %s" value))
1568 (pr-txt-set-printer value)
1569 (and index
1570 (pr-menu-lock entry index 12 'toggle nil)))
1572 ;; GNU Emacs
1573 (defun pr-menu-set-utility-title (value &optional item entry index)
1574 (let ((name (symbol-name value)))
1575 (if item
1576 (pr-menu-set-item-name item name)
1577 (pr-menu-set-item-name
1578 (pr-menu-get-item
1579 '("PostScript Print" "File" "PostScript Utility"))
1580 name)
1581 (pr-menu-set-item-name
1582 (pr-menu-get-item
1583 '("PostScript Preview" "File" "PostScript Utility"))
1584 name)))
1585 (pr-ps-set-utility value)
1586 (and index
1587 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
1589 ;; GNU Emacs
1590 (defun pr-even-or-odd-pages (value &optional no-lock)
1591 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
1592 (cdr (assq value pr-even-or-odd-alist)))
1593 (setq ps-even-or-odd-pages value)
1594 (or no-lock
1595 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
1597 )) ; end cond featurep
1600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1601 ;; Internal Functions (I)
1604 (defun pr-dosify-file-name (path)
1605 "Replace unix-style directory separator character with dos/windows one."
1606 (interactive "sPath: ")
1607 (if (eq pr-path-style 'windows)
1608 (subst-char-in-string ?/ ?\\ path)
1609 path))
1612 (defun pr-unixify-file-name (path)
1613 "Replace dos/windows-style directory separator character with unix one."
1614 (interactive "sPath: ")
1615 (if (eq pr-path-style 'windows)
1616 (subst-char-in-string ?\\ ?/ path)
1617 path))
1620 (defun pr-standard-file-name (path)
1621 "Ensure the proper directory separator depending on the OS.
1622 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
1623 separator; otherwise, ensure unix-style directory separator."
1624 (if (or pr-cygwin-system lpr-windows-system)
1625 (subst-char-in-string ?/ ?\\ path)
1626 (subst-char-in-string ?\\ ?/ path)))
1629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1630 ;; Customization Functions
1633 (defun pr-alist-custom-set (symbol value)
1634 "Set the value of custom variables for printer & utility selection."
1635 (set symbol value)
1636 (and (featurep 'printing) ; update only after printing is loaded
1637 (pr-update-menus t)))
1640 (defun pr-ps-utility-custom-set (symbol value)
1641 "Update utility menu entry."
1642 (set symbol value)
1643 (and (featurep 'printing) ; update only after printing is loaded
1644 (pr-menu-set-utility-title value)))
1647 (defun pr-ps-name-custom-set (symbol value)
1648 "Update `PostScript Printer:' menu entry."
1649 (set symbol value)
1650 (and (featurep 'printing) ; update only after printing is loaded
1651 (pr-menu-set-ps-title value)))
1654 (defun pr-txt-name-custom-set (symbol value)
1655 "Update `Text Printer:' menu entry."
1656 (set symbol value)
1657 (and (featurep 'printing) ; update only after printing is loaded
1658 (pr-menu-set-txt-title value)))
1661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1662 ;; User Interface
1665 (defgroup printing nil
1666 "Printing Utilities group."
1667 :tag "Printing Utilities"
1668 :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
1669 :prefix "pr-"
1670 :version "22.1"
1671 :group 'wp
1672 :group 'postscript)
1675 (defcustom pr-path-style
1676 (if (and (not pr-cygwin-system)
1677 lpr-windows-system)
1678 'windows
1679 'unix)
1680 "Specify which path style to use for external commands.
1682 Valid values are:
1684 windows Windows 9x/NT style (\\)
1686 unix Unix style (/)"
1687 :type '(choice :tag "Path style"
1688 (const :tag "Windows 9x/NT Style (\\)" :value windows)
1689 (const :tag "Unix Style (/)" :value unix))
1690 :group 'printing)
1693 (defcustom pr-path-alist
1694 '((unix PATH)
1695 (cygwin PATH)
1696 (windows PATH))
1697 "Specify an alist for command paths.
1699 It's used to find commands used for printing package, like gv, gs, gsview.exe,
1700 mpage, print.exe, etc. See also `pr-command' function.
1702 Each element has the form:
1704 (ENTRY DIRECTORY...)
1706 Where:
1708 ENTRY It's a symbol, used to identify this entry.
1709 There must exist at least one of the following entries:
1711 unix this entry is used when Emacs is running on GNU or
1712 Unix system.
1714 cygwin this entry is used when Emacs is running on Windows
1715 95/98/NT/2000 with Cygwin.
1717 windows this entry is used when Emacs is running on Windows
1718 95/98/NT/2000.
1720 DIRECTORY It should be a string or a symbol. If it's a symbol, it should
1721 exist an equal entry in `pr-path-alist'. If it's a string,
1722 it's considered a directory specification.
1724 The directory specification may contain:
1725 $var environment variable expansion
1726 ~/ tilde expansion
1727 ./ current directory
1728 ../ previous directory
1730 For example, let's say the home directory is /home/my and the
1731 current directory is /home/my/dir, so:
1733 THE ENTRY IS EXPANDED TO
1734 ~/entry /home/my/entry
1735 ./entry /home/my/dir/entry
1736 ../entry /home/my/entry
1737 $HOME/entry /home/my/entry
1738 $HOME/~/other/../my/entry /home/my/entry
1740 SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
1741 list and there isn't a `PATH' entry in `pr-path-alist' or the
1742 `PATH' entry has a null directory list, the PATH environment
1743 variable is used.
1745 Examples:
1747 * On GNU or Unix system:
1749 '((unix \".\" \"~/bin\" ghostview mpage PATH)
1750 (ghostview \"$HOME/bin/gsview-dir\")
1751 (mpage \"$HOME/bin/mpage-dir\")
1754 * On Windows system:
1756 '((windows \"c:/applications/executables\" PATH ghostview mpage)
1757 (ghostview \"c:/gs/gsview-dir\")
1758 (mpage \"c:/mpage-dir\")
1760 :type '(repeat
1761 (cons :tag ""
1762 (symbol :tag "Identifier ")
1763 (repeat :tag "Directory List"
1764 (choice :menu-tag "Directory"
1765 :tag "Directory"
1766 (string :value "")
1767 (symbol :value symbol)))))
1768 :group 'printing)
1771 (defcustom pr-txt-name 'default
1772 "Specify a printer for printing a text file.
1774 The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
1775 documentation).
1777 This variable should be modified by customization engine. If this variable is
1778 modified by other means (for example, a lisp function), use `pr-update-menus'
1779 function (see it for documentation) to update text printer menu."
1780 :type 'symbol
1781 :set 'pr-txt-name-custom-set
1782 :group 'printing)
1785 (defcustom pr-txt-printer-alist
1786 (list (list 'default lpr-command nil
1787 (cond ((boundp 'printer-name) printer-name)
1788 (lpr-windows-system "PRN")
1789 (t nil)
1791 ;; Examples:
1792 ;; * On GNU or Unix system:
1793 ;; '((prt_06a "lpr" nil "prt_06a")
1794 ;; (prt_07c nil nil "prt_07c")
1795 ;; )
1796 ;; * On Windows system:
1797 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
1798 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
1799 ;; (PRN "" nil "PRN")
1800 ;; (standard "redpr.exe" nil "")
1801 ;; )
1802 "Specify an alist of all text printers (text printer database).
1804 The alist element has the form:
1806 (SYMBOL COMMAND SWITCHES NAME)
1808 Where:
1810 SYMBOL It's a symbol to identify a text printer. It's for
1811 setting option `pr-txt-name' and for menu selection.
1812 Examples:
1813 'prt_06a
1814 'my_printer
1816 COMMAND Name of the program for printing a text file. On MS-DOS and
1817 MS-Windows systems, if the value is an empty string, then Emacs
1818 will write directly to the printer port given by NAME (see text
1819 below), that is, the NAME should be something like \"PRN\" or
1820 \"LPT1:\".
1821 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1822 COMMAND shouldn't be an empty string.
1823 The programs `print' and `nprint' (the standard print programs
1824 on Windows NT and Novell Netware respectively) are handled
1825 specially, using NAME as the destination for output; any other
1826 program is treated like `lpr' except that an explicit filename
1827 is given as the last argument.
1828 If COMMAND is nil, it's used the default printing program:
1829 `print' for Windows system, `lp' for lp system and `lpr' for
1830 all other systems. See also `pr-path-alist'.
1831 Examples:
1832 \"print\"
1833 \"lpr\"
1834 \"lp\"
1836 SWITCHES List of sexp's to pass as extra options for text printer
1837 program. It is recommended to set NAME (see text below)
1838 instead of including an explicit switch on this list.
1839 Example:
1840 . for lpr
1841 '(\"-#3\" \"-l\")
1844 NAME A string that specifies a text printer name.
1845 On Unix-like systems, a string value should be a name
1846 understood by lpr's -P option (or lp's -d option).
1847 On MS-DOS and MS-Windows systems, it is the name of a printer
1848 device or port. Typical non-default settings would be \"LPT1:\"
1849 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1850 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1851 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1852 printer. You can also set it to a name of a file, in which
1853 case the output gets appended to that file. If you want to
1854 discard the printed output, set this to \"NUL\".
1855 Examples:
1856 . for print.exe
1857 \"/D:\\\\\\\\host\\\\share-name\"
1858 \"LPT1:\"
1859 \"PRN\"
1861 . for lpr or lp
1862 \"share-name\"
1864 This variable should be modified by customization engine. If this variable is
1865 modified by other means (for example, a lisp function), use `pr-update-menus'
1866 function (see it for documentation) to update text printer menu.
1868 Examples:
1870 * On GNU or Unix system:
1872 '((prt_06a \"lpr\" nil \"prt_06a\")
1873 (prt_07c nil nil \"prt_07c\")
1876 * On Windows system:
1878 '((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1879 (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
1880 (PRN \"\" nil \"PRN\")
1881 (standard \"redpr.exe\" nil \"\")
1884 Useful links:
1886 * Information about the print command (print.exe)
1887 `http://www.computerhope.com/printhlp.htm'
1889 * RedMon - Redirection Port Monitor (redpr.exe)
1890 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1892 * Redirection Port Monitor (redpr.exe on-line help)
1893 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1895 * UNIX man pages: lpr (or type `man lpr')
1896 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1897 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1899 * UNIX man pages: lp (or type `man lp')
1900 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1901 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1903 :type '(repeat
1904 (list :tag "Text Printer"
1905 (symbol :tag "Printer Symbol Name")
1906 (string :tag "Printer Command")
1907 (repeat :tag "Printer Switches"
1908 (sexp :tag "Switch" :value ""))
1909 (choice :menu-tag "Printer Name"
1910 :tag "Printer Name"
1911 (const :tag "None" nil)
1912 string)))
1913 :set 'pr-alist-custom-set
1914 :group 'printing)
1917 (defcustom pr-ps-name 'default
1918 "Specify a printer for printing a PostScript file.
1920 This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
1921 documentation).
1923 This variable should be modified by customization engine. If this variable is
1924 modified by other means (for example, a lisp function), use `pr-update-menus'
1925 function (see it for documentation) to update PostScript printer menu."
1926 :type 'symbol
1927 :set 'pr-ps-name-custom-set
1928 :group 'printing)
1931 (defcustom pr-ps-printer-alist
1932 (list (list 'default lpr-command nil
1933 (cond (lpr-windows-system nil)
1934 (lpr-lp-system "-d")
1935 (t "-P"))
1936 (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
1937 ;; Examples:
1938 ;; * On GNU or Unix system:
1939 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
1940 ;; (lps_07c "lpr" nil nil "lps_07c")
1941 ;; (lps_08c nil nil nil "lps_08c")
1942 ;; )
1943 ;; * On Windows system:
1944 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
1945 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
1946 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
1947 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
1948 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
1949 ;; (LPT1 "" nil "" "LPT1:")
1950 ;; (PRN "" nil "" "PRN")
1951 ;; (standard "redpr.exe" nil "" "")
1952 ;; )
1953 "Specify an alist for all PostScript printers (PostScript printer database).
1955 The alist element has the form:
1957 (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
1959 Where:
1961 SYMBOL It's a symbol to identify a PostScript printer. It's for
1962 setting option `pr-ps-name' and for menu selection.
1963 Examples:
1964 'prt_06a
1965 'my_printer
1967 COMMAND Name of the program for printing a PostScript file. On MS-DOS
1968 and MS-Windows systems, if the value is an empty string then
1969 Emacs will write directly to the printer port given by NAME
1970 (see text below), that is, the NAME should be something like
1971 \"PRN\" or \"LPT1:\".
1972 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1973 COMMAND shouldn't be an empty string.
1974 The programs `print' and `nprint' (the standard print programs
1975 on Windows NT and Novell Netware respectively) are handled
1976 specially, using NAME as the destination for output; any other
1977 program is treated like `lpr' except that an explicit filename
1978 is given as the last argument.
1979 If COMMAND is nil, it's used the default printing program:
1980 `print' for Windows system, `lp' for lp system and `lpr' for
1981 all other systems. See also `pr-path-alist'.
1982 Examples:
1983 \"print\"
1984 \"lpr\"
1985 \"lp\"
1986 \"cp\"
1987 \"gsprint\"
1989 SWITCHES List of sexp's to pass as extra options for PostScript printer
1990 program. It is recommended to set NAME (see text below)
1991 instead of including an explicit switch on this list.
1992 Example:
1993 . for lpr
1994 '(\"-#3\" \"-l\")
1997 . for gsprint.exe
1998 '(\"-all\" \"-twoup\")
2000 PRINTER-SWITCH A string that specifies PostScript printer name switch. If
2001 it's necessary to have a space between PRINTER-SWITCH and NAME,
2002 it should be inserted at the end of PRINTER-SWITCH string.
2003 If PRINTER-SWITCH is nil, it's used the default printer name
2004 switch: `/D:' for Windows system, `-d' for lp system and `-P'
2005 for all other systems.
2006 Examples:
2007 . for lpr
2008 \"-P \"
2010 . for lp
2011 \"-d \"
2013 . for print.exe
2014 \"/D:\"
2016 . for gsprint.exe
2017 \"-printer \"
2019 NAME A string that specifies a PostScript printer name.
2020 On Unix-like systems, a string value should be a name
2021 understood by lpr's -P option (or lp's -d option).
2022 On MS-DOS and MS-Windows systems, it is the name of a printer
2023 device or port. Typical non-default settings would be \"LPT1:\"
2024 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
2025 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
2026 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
2027 printer. You can also set it to a name of a file, in which
2028 case the output gets appended to that file. If you want to
2029 discard the printed output, set this to \"NUL\".
2030 Examples:
2031 . for cp.exe
2032 \"\\\\\\\\host\\\\share-name\"
2034 . for print.exe or gsprint.exe
2035 \"/D:\\\\\\\\host\\\\share-name\"
2036 \"\\\\\\\\host\\\\share-name\"
2037 \"LPT1:\"
2038 \"PRN\"
2040 . for lpr or lp
2041 \"share-name\"
2043 DEFAULT It's a way to set default values when this entry is selected.
2044 It's a cons like:
2046 (VARIABLE . VALUE)
2048 Which associates VARIABLE with VALUE. When this entry is
2049 selected, it's executed the following command:
2051 (set VARIABLE (eval VALUE))
2053 Note that VALUE can be any valid lisp expression. So, don't
2054 forget to quote symbols and constant lists.
2055 If VARIABLE is the special keyword `inherits-from:', VALUE must
2056 be a symbol name setting defined in `pr-setting-database' from
2057 which the current setting inherits the context. Take care with
2058 circular inheritance.
2059 Examples:
2060 '(ps-landscape-mode . nil)
2061 '(ps-spool-duplex . t)
2062 '(pr-gs-device . (my-gs-device t))
2064 This variable should be modified by customization engine. If this variable is
2065 modified by other means (for example, a lisp function), use `pr-update-menus'
2066 function (see it for documentation) to update PostScript printer menu.
2068 Examples:
2070 * On GNU or Unix system:
2072 '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
2073 (lps_07c \"lpr\" nil nil \"lps_07c\")
2074 (lps_08c nil nil nil \"lps_08c\")
2077 * On Windows system:
2079 '((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
2080 (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
2081 (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
2082 (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
2083 (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
2084 (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
2085 (LPT1 \"\" nil \"\" \"LPT1:\")
2086 (PRN \"\" nil \"\" \"PRN\")
2087 (standard \"redpr.exe\" nil \"\" \"\")
2091 gsprint:
2093 You can use gsprint instead of ghostscript to print monochrome PostScript files
2094 in Windows. The gsprint utility documentation says that it is more efficient
2095 than ghostscript to print monochrome PostScript.
2097 To print non-monochrome PostScript file, the efficiency of ghostscript is
2098 similar to gsprint.
2100 Also the gsprint utility comes together with gsview distribution.
2102 As an example of gsprint declaration:
2104 (setq pr-ps-printer-alist
2105 '((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
2106 (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
2107 ;; some other printer declaration
2110 The example above declares that printer A prints all pages (-all) and two pages
2111 per sheet (-twoup). The printer B declaration does the same as the printer A
2112 declaration, the only difference is the printer name selection.
2114 There are other command line options like:
2116 -mono Render in monochrome as 1bit/pixel (only black and white).
2117 -grey Render in greyscale as 8bits/pixel.
2118 -color Render in color as 24bits/pixel.
2120 The default is `-mono'. So, printer A and B in the example above are using
2121 implicitly the `-mono' option. Note that in `-mono' no gray tone or color is
2122 printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
2123 are not printed.
2126 Useful links:
2128 * GSPRINT - Ghostscript print to Windows printer
2129 `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
2131 * Introduction to Ghostscript
2132 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2134 * How to use Ghostscript
2135 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2137 * Information about the print command (print.exe)
2138 `http://www.computerhope.com/printhlp.htm'
2140 * RedMon - Redirection Port Monitor (redpr.exe)
2141 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
2143 * Redirection Port Monitor (redpr.exe on-line help)
2144 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
2146 * UNIX man pages: lpr (or type `man lpr')
2147 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
2148 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
2150 * UNIX man pages: lp (or type `man lp')
2151 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
2152 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
2154 * GNU utilities for w32 (cp.exe)
2155 `http://unxutils.sourceforge.net/'
2157 :type '(repeat
2158 (list
2159 :tag "PostScript Printer"
2160 (symbol :tag "Printer Symbol Name")
2161 (string :tag "Printer Command")
2162 (repeat :tag "Printer Switches"
2163 (sexp :tag "Switch" :value ""))
2164 (choice :menu-tag "Printer Name Switch"
2165 :tag "Printer Name Switch"
2166 (const :tag "None" nil)
2167 string)
2168 (choice :menu-tag "Printer Name"
2169 :tag "Printer Name"
2170 (const :tag "None" nil)
2171 string)
2172 (repeat
2173 :tag "Default Value List"
2174 :inline t
2175 (cons
2176 :tag ""
2177 (choice
2178 :menu-tag "Variable"
2179 :tag "Variable"
2180 (const :tag "Landscape" ps-landscape-mode)
2181 (const :tag "Print Header" ps-print-header)
2182 (const :tag "Print Header Frame" ps-print-header-frame)
2183 (const :tag "Line Number" ps-line-number)
2184 (const :tag "Zebra Stripes" ps-zebra-stripes)
2185 (const :tag "Duplex" ps-spool-duplex)
2186 (const :tag "Tumble" ps-spool-tumble)
2187 (const :tag "Upside-Down" ps-print-upside-down)
2188 (const :tag "PS File Landscape" pr-file-landscape)
2189 (const :tag "PS File Duplex" pr-file-duplex)
2190 (const :tag "PS File Tumble" pr-file-tumble)
2191 (const :tag "Auto Region" pr-auto-region)
2192 (const :tag "Auto Mode" pr-auto-mode)
2193 (const :tag "Ghostscript Device" pr-gs-device)
2194 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2195 (const :tag "inherits-from:" inherits-from:)
2196 (variable :tag "Other"))
2197 (sexp :tag "Value")))
2199 :set 'pr-alist-custom-set
2200 :group 'printing)
2203 (defcustom pr-temp-dir
2204 (pr-dosify-file-name
2205 (if (boundp 'temporary-file-directory)
2206 (symbol-value 'temporary-file-directory)
2207 ;; hacked from `temporary-file-directory' variable in files.el
2208 (file-name-as-directory
2209 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
2210 (cond (lpr-windows-system "c:/temp")
2211 (t "/tmp")
2212 )))))
2213 "Specify a directory for temporary files during printing.
2215 See also `pr-ps-temp-file' and `pr-file-modes'."
2216 :type '(directory :tag "Temporary Directory")
2217 :group 'printing)
2220 (defcustom pr-ps-temp-file "prspool-"
2221 "Specify PostScript temporary file name prefix.
2223 See also `pr-temp-dir' and `pr-file-modes'."
2224 :type '(file :tag "PostScript Temporary File Name")
2225 :group 'printing)
2228 ;; It uses 0600 as default instead of (default-file-modes).
2229 ;; So, by default, only the session owner have permission to deal with files
2230 ;; generated by `printing'.
2231 (defcustom pr-file-modes ?\600
2232 "Specify the file permission bits for newly created files.
2234 It should be an integer; only the low 9 bits are used.
2236 See also `pr-temp-dir' and `pr-ps-temp-file'."
2237 :type '(integer :tag "File Permission Bits")
2238 :group 'printing)
2241 (defcustom pr-gv-command
2242 (if lpr-windows-system
2243 "gsview32.exe"
2244 "gv")
2245 "Specify path and name of the gsview/gv utility.
2247 See also `pr-path-alist'.
2249 Useful links:
2251 * GNU gv manual
2252 `http://www.gnu.org/software/gv/manual/gv.html'
2254 * GSview Help
2255 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'
2257 * GSview Help - Common Problems
2258 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'
2260 * GSview Readme (compilation & installation)
2261 `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'
2263 * GSview (main site)
2264 `http://www.cs.wisc.edu/~ghost/gsview/index.htm'
2266 * Ghostscript, Ghostview and GSview
2267 `http://www.cs.wisc.edu/~ghost/'
2269 * Ghostview
2270 `http://www.cs.wisc.edu/~ghost/gv/index.htm'
2272 * gv 3.5, June 1997
2273 `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'
2275 * MacGSView (MacOS)
2276 `http://www.cs.wisc.edu/~ghost/macos/index.htm'
2278 :type '(string :tag "Ghostview Utility")
2279 :group 'printing)
2282 (defcustom pr-gs-command
2283 (if lpr-windows-system
2284 "gswin32.exe"
2285 "gs")
2286 "Specify path and name of the ghostscript utility.
2288 See also `pr-path-alist'.
2290 Useful links:
2292 * Ghostscript, Ghostview and GSview
2293 `http://www.cs.wisc.edu/~ghost/'
2295 * Introduction to Ghostscript
2296 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2298 * How to use Ghostscript
2299 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2301 * Printer compatibility
2302 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2304 :type '(string :tag "Ghostscript Utility")
2305 :group 'printing)
2308 (defcustom pr-gs-switches
2309 (if lpr-windows-system
2310 '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
2311 '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
2312 "Specify ghostscript switches. See the documentation on GS for more info.
2314 It's a list of strings, where each string is one or more ghostscript switches.
2316 A note on the gs switches:
2318 -q quiet
2319 -dNOPAUSE don't wait for user intervention
2320 -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
2321 -c quit it's added at the end to terminate gs
2323 To see ghostscript documentation for more information:
2325 * On GNU or Unix system:
2326 - for full documentation, type: man gs
2327 - for brief documentation, type: gs -h
2329 * On Windows system:
2330 - for full documentation, see in a browser the file
2331 c:/gstools/gs5.50/index.html, that is, the file index.html which is
2332 located in the same directory as gswin32.exe.
2333 - for brief documentation, type: gswin32.exe -h
2335 Useful links:
2337 * Introduction to Ghostscript
2338 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2340 * How to use Ghostscript
2341 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2343 * Printer compatibility
2344 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2346 :type '(repeat (string :tag "Ghostscript Switch"))
2347 :group 'printing)
2350 (defcustom pr-gs-device
2351 (if lpr-windows-system
2352 "mswinpr2"
2353 "uniprint")
2354 "Specify the ghostscript device switch value (-sDEVICE=).
2356 A note on the gs switches:
2358 -sDEVICE=djet500 the printer - works with HP DeskJet 540
2360 See `pr-gs-switches' for documentation.
2361 See also `pr-ps-printer-alist'."
2362 :type '(string :tag "Ghostscript Device")
2363 :group 'printing)
2366 (defcustom pr-gs-resolution 300
2367 "Specify ghostscript resolution switch value (-r).
2369 A note on the gs switches:
2371 -r300 resolution 300x300
2373 See `pr-gs-switches' for documentation.
2374 See also `pr-ps-printer-alist'."
2375 :type '(integer :tag "Ghostscript Resolution")
2376 :group 'printing)
2379 (defcustom pr-print-using-ghostscript nil
2380 "Non-nil means print using ghostscript.
2382 This is useful if you don't have a PostScript printer, so you could use the
2383 ghostscript to print a PostScript file.
2385 In GNU or Unix system, if ghostscript is set as a PostScript filter, this
2386 variable should be nil."
2387 :type 'boolean
2388 :group 'printing)
2391 (defcustom pr-faces-p nil
2392 "Non-nil means print with face attributes."
2393 :type 'boolean
2394 :group 'printing)
2397 (defcustom pr-spool-p nil
2398 "Non-nil means spool printing in a buffer."
2399 :type 'boolean
2400 :group 'printing)
2403 (defcustom pr-file-landscape nil
2404 "Non-nil means print PostScript file in landscape orientation."
2405 :type 'boolean
2406 :group 'printing)
2409 (defcustom pr-file-duplex nil
2410 "Non-nil means print PostScript file in duplex mode."
2411 :type 'boolean
2412 :group 'printing)
2415 (defcustom pr-file-tumble nil
2416 "Non-nil means print PostScript file in tumble mode.
2418 If tumble is off, produces a printing suitable for binding on the left or
2419 right.
2420 If tumble is on, produces a printing suitable for binding at the top or
2421 bottom."
2422 :type 'boolean
2423 :group 'printing)
2426 (defcustom pr-auto-region t
2427 "Non-nil means region is automagically detected.
2429 Note that this will only work if you're using transient mark mode.
2431 When this variable is non-nil, the `*-buffer*' commands will behave like
2432 `*-region*' commands, that is, `*-buffer*' commands will print only the region
2433 marked instead of all buffer."
2434 :type 'boolean
2435 :group 'printing)
2438 (defcustom pr-auto-mode t
2439 "Non-nil means major-mode specific printing is preferred over normal printing.
2441 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
2442 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
2443 `*-buffer*' commands will print the current buffer and `*-region*' commands
2444 will print the current region."
2445 :type 'boolean
2446 :group 'printing)
2449 (defcustom pr-mode-alist
2450 '((mh-folder-mode ; mh summary buffer
2451 pr-mh-lpr-1 pr-mh-print-1
2453 (ps-article-author ps-article-subject)
2454 ("/pagenumberstring load" pr-article-date)
2457 (mh-letter-mode ; mh letter buffer
2458 pr-mh-lpr-2 pr-mh-print-2
2460 (ps-article-author ps-article-subject)
2461 ("/pagenumberstring load" pr-article-date)
2464 (rmail-summary-mode ; rmail summary buffer
2465 pr-rmail-lpr pr-rmail-print
2467 (ps-article-subject ps-article-author buffer-name)
2471 (rmail-mode ; rmail buffer
2472 pr-rmail-lpr pr-rmail-print
2474 (ps-article-subject ps-article-author buffer-name)
2478 (gnus-summary-mode ; gnus summary buffer
2479 pr-gnus-lpr pr-gnus-print
2481 (ps-article-subject ps-article-author gnus-newsgroup-name)
2485 (gnus-article-mode ; gnus article buffer
2486 pr-gnus-lpr pr-gnus-print
2488 (ps-article-subject ps-article-author gnus-newsgroup-name)
2492 (Info-mode ; Info buffer
2493 pr-mode-lpr pr-mode-print
2495 (ps-info-node ps-info-file)
2499 (vm-mode ; vm mode
2500 pr-vm-lpr pr-vm-print
2502 (ps-article-subject ps-article-author buffer-name)
2507 "Specify an alist for a major-mode and printing functions.
2509 To customize a major mode printing, just declare the customization in
2510 `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
2511 mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
2512 *Summary* buffer, if you forget to switch to the *Article* buffer before
2513 printing, you'll get a nicely formatted list of article subjects shows up at
2514 the printer. With major mode printing you don't need to switch from gnus
2515 *Summary* buffer first.
2517 The elements have the following form:
2519 (MAJOR-MODE
2520 LPR-PRINT PS-PRINT
2521 HEADER-LINES
2522 LEFT-HEADER
2523 RIGHT-HEADER
2524 KILL-LOCAL-VARIABLE
2525 DEFAULT...)
2527 Where:
2529 MAJOR-MODE It's the major mode symbol.
2531 LPR-PRINT It's a symbol function for text printing. It's invoked with
2532 one argument:
2533 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2535 Usually LPR-PRINT function prepares the environment or buffer
2536 and then call the function `pr-mode-lpr' which it's used to
2537 process the buffer and send it to text printer.
2539 The `pr-mode-lpr' definition is:
2541 (pr-mode-lpr HEADER-LIST &optional FROM TO)
2543 Where HEADER-LIST is like the argument passed to LPR-PRINT.
2544 FROM and TO are the beginning and end markers, respectively,
2545 for a region. If FROM is nil, it's used (point-min); if TO is
2546 nil, it's used (point-max).
2548 PS-PRINT It's a symbol function for PostScript printing. It's invoked
2549 with three arguments: n-up printing, file name and the list:
2550 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2552 Usually PS-PRINT function prepares the environment or buffer
2553 and then call the function `pr-mode-print' which it's used to
2554 process the buffer and send it to PostScript printer.
2556 The `pr-mode-print' definition is:
2558 (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
2560 Where N-UP, FILENAME and HEADER-LIST are like the arguments
2561 passed to PS-PRINT. FROM and TO are the beginning and end
2562 markers, respectively, for a region. If TO is nil, it's used
2563 (point-max).
2565 HEADER-LINES It's the number of header lines; if is nil, it uses
2566 `ps-header-lines' value.
2568 LEFT-HEADER It's the left header part, it's a list of string, variable
2569 symbol or function symbol (with no argument); if is nil, it
2570 uses `ps-left-header' value.
2572 RIGHT-HEADER It's the right header part, it's a list of string, variable
2573 symbol or function symbol (with no argument); if is nil, it
2574 uses `ps-right-header' value.
2576 KILL-LOCAL-VARIABLE
2577 Non-nil means to kill all buffer local variable declared in
2578 DEFAULT (see below).
2580 DEFAULT It's a way to set default values when this entry is selected.
2581 It's a cons like:
2583 (VARIABLE-SYM . VALUE)
2585 Which associates VARIABLE-SYM with VALUE. When this entry is
2586 selected, it's executed the following command:
2588 (set (make-local-variable VARIABLE-SYM) (eval VALUE))
2590 Note that VALUE can be any valid lisp expression. So, don't
2591 forget to quote symbols and constant lists.
2592 If VARIABLE is the special keyword `inherits-from:', VALUE must
2593 be a symbol name setting defined in `pr-setting-database' from
2594 which the current setting inherits the context. Take care with
2595 circular inheritance.
2596 Examples:
2597 '(ps-landscape-mode . nil)
2598 '(ps-spool-duplex . t)
2599 '(pr-gs-device . (my-gs-device t))"
2600 :type '(repeat
2601 (list
2602 :tag ""
2603 (symbol :tag "Major Mode")
2604 (function :tag "Text Printing Function")
2605 (function :tag "PS Printing Function")
2606 (choice :menu-tag "Number of Header Lines"
2607 :tag "Number of Header Lines"
2608 (integer :tag "Number")
2609 (const :tag "Default Number" nil))
2610 (repeat :tag "Left Header List"
2611 (choice :menu-tag "Left Header"
2612 :tag "Left Header"
2613 string symbol))
2614 (repeat :tag "Right Header List"
2615 (choice :menu-tag "Right Header"
2616 :tag "Right Header"
2617 string symbol))
2618 (boolean :tag "Kill Local Variable At End")
2619 (repeat
2620 :tag "Default Value List"
2621 :inline t
2622 (cons
2623 :tag ""
2624 (choice
2625 :menu-tag "Variable"
2626 :tag "Variable"
2627 (const :tag "Landscape" ps-landscape-mode)
2628 (const :tag "Print Header" ps-print-header)
2629 (const :tag "Print Header Frame" ps-print-header-frame)
2630 (const :tag "Line Number" ps-line-number)
2631 (const :tag "Zebra Stripes" ps-zebra-stripes)
2632 (const :tag "Duplex" ps-spool-duplex)
2633 (const :tag "Tumble" ps-spool-tumble)
2634 (const :tag "Upside-Down" ps-print-upside-down)
2635 (const :tag "PS File Landscape" pr-file-landscape)
2636 (const :tag "PS File Duplex" pr-file-duplex)
2637 (const :tag "PS File Tumble" pr-file-tumble)
2638 (const :tag "Auto Region" pr-auto-region)
2639 (const :tag "Auto Mode" pr-auto-mode)
2640 (const :tag "Ghostscript Device" pr-gs-device)
2641 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2642 (const :tag "inherits-from:" inherits-from:)
2643 (variable :tag "Other"))
2644 (sexp :tag "Value")))
2646 :group 'printing)
2649 (defcustom pr-ps-utility 'mpage
2650 "Specify PostScript utility symbol.
2652 This utility symbol should be defined on `pr-ps-utility-alist' (see it for
2653 documentation).
2655 This variable should be modified by customization engine. If this variable is
2656 modified by other means (for example, a lisp function), use `pr-update-menus'
2657 function (see it for documentation) to update PostScript utility menu.
2659 NOTE: Don't forget to download and install the utilities declared on
2660 `pr-ps-utility-alist'."
2661 :type '(symbol :tag "PS File Utility")
2662 :set 'pr-ps-utility-custom-set
2663 :group 'printing)
2666 (defcustom pr-ps-utility-alist
2667 '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2668 (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2669 (inherits-from: . no-duplex))
2671 ;; Examples:
2672 ;; * On GNU or Unix system:
2673 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2674 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2675 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2676 ;; )
2677 ;; * On Windows system:
2678 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2679 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2680 ;; )
2681 "Specify an alist for PostScript utility processing (PS utility database).
2683 The alist element has the form:
2685 (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
2686 SWITCHES DEFAULT...)
2688 Where:
2690 SYMBOL It's a symbol to identify a PostScript utility. It's for
2691 `pr-ps-utility' variable setting and for menu selection.
2692 Examples:
2693 'mpage
2694 'psnup
2696 UTILITY Name of utility for processing a PostScript file.
2697 See also `pr-path-alist'.
2698 Examples:
2699 . for GNU or Unix system:
2700 \"mpage\"
2701 \"psnup -q\"
2703 . for Windows system:
2704 \"c:/psutils/psnup -q\"
2706 MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
2707 program. These options are necessary to process the utility
2708 program and must be placed before any other switches.
2709 Example:
2710 . for psnup:
2711 '(\"-q\")
2713 PAPERSIZE It's a format string to specify paper size switch.
2714 Example:
2715 . for mpage
2716 \"-b%s\"
2718 N-UP It's a format string to specify n-up switch.
2719 Example:
2720 . for psnup
2721 \"-%d\"
2723 LANDSCAPE It's a string to specify landscape switch. If the utility
2724 doesn't have landscape switch, set to nil.
2725 Example:
2726 . for psnup
2727 \"-l\"
2729 DUPLEX It's a string to specify duplex switch. If the utility doesn't
2730 have duplex switch, set to nil.
2731 Example:
2732 . for psnup
2735 TUMBLE It's a string to specify tumble switch. If the utility doesn't
2736 have tumble switch, set to nil.
2737 Example:
2738 . for psnup
2741 OUTPUT It's a string to specify how to generate an output file. Some
2742 utilities accept an output file option, but some others need
2743 output redirection or some other way to specify an output file.
2744 Example:
2745 . for psnup
2746 \" \" ; psnup ... input output
2748 . for mpage
2749 \">\" ; mpage ... input > output
2751 SWITCHES List of sexp's to pass as extra options to the PostScript utility
2752 program.
2753 Example:
2754 . for psnup
2755 '(\"-q\")
2758 DEFAULT It's a way to set default values when this entry is selected.
2759 It's a cons like:
2761 (VARIABLE . VALUE)
2763 Which associates VARIABLE with VALUE. When this entry is
2764 selected, it's executed the following command:
2766 (set VARIABLE (eval VALUE))
2768 Note that VALUE can be any valid lisp expression. So, don't
2769 forget to quote symbols and constant lists.
2770 If VARIABLE is the special keyword `inherits-from:', VALUE must
2771 be a symbol name setting defined in `pr-setting-database' from
2772 which the current setting inherits the context. Take care with
2773 circular inheritance.
2774 Examples:
2775 '(pr-file-landscape . nil)
2776 '(pr-file-duplex . t)
2777 '(pr-gs-device . (my-gs-device t))
2779 This variable should be modified by customization engine. If this variable is
2780 modified by other means (for example, a lisp function), use `pr-update-menus'
2781 function (see it for documentation) to update PostScript utility menu.
2783 NOTE: Don't forget to download and install the utilities declared on
2784 `pr-ps-utility-alist'.
2786 Examples:
2788 * On GNU or Unix system:
2790 '((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
2791 (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
2792 (pr-file-duplex . nil) (pr-file-tumble . nil))
2795 * On Windows system:
2797 '((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
2798 nil (pr-file-duplex . nil) (pr-file-tumble . nil))
2801 Useful links:
2803 * mpage download (GNU or Unix)
2804 `http://www.mesa.nl/pub/mpage/'
2806 * mpage documentation (GNU or Unix - or type `man mpage')
2807 `http://www.cs.umd.edu/faq/guides/manual_unix/node48.html'
2808 `http://www.rt.com/man/mpage.1.html'
2810 * psnup (Windows, GNU or Unix)
2811 `http://www.knackered.org/angus/psutils/'
2812 `http://gershwin.ens.fr/vdaniel/Doc-Locale/Outils-Gnu-Linux/PsUtils/'
2814 * psnup (PsUtils for Windows)
2815 `http://gnuwin32.sourceforge.net/packages/psutils.htm'
2817 * psnup documentation (GNU or Unix - or type `man psnup')
2818 `http://linux.about.com/library/cmd/blcmdl1_psnup.htm'
2819 `http://amath.colorado.edu/computing/software/man/psnup.html'
2821 * GNU Enscript (Windows, GNU or Unix)
2822 `http://people.ssh.com/mtr/genscript/'
2824 * GNU Enscript documentation (Windows, GNU or Unix)
2825 `http://people.ssh.com/mtr/genscript/enscript.man.html'
2826 (on GNU or Unix, type `man enscript')
2828 :type '(repeat
2829 (list :tag "PS File Utility"
2830 (symbol :tag "Utility Symbol")
2831 (string :tag "Utility Name")
2832 (repeat :tag "Must Utility Switches"
2833 (sexp :tag "Switch" :value ""))
2834 (choice :menu-tag "Paper Size"
2835 :tag "Paper Size"
2836 (const :tag "No Paper Size" nil)
2837 (string :tag "Paper Size Format"))
2838 (choice :menu-tag "N-Up"
2839 :tag "N-Up"
2840 (const :tag "No N-Up" nil)
2841 (string :tag "N-Up Format"))
2842 (choice :menu-tag "Landscape"
2843 :tag "Landscape"
2844 (const :tag "No Landscape" nil)
2845 (string :tag "Landscape Switch"))
2846 (choice :menu-tag "Duplex"
2847 :tag "Duplex"
2848 (const :tag "No Duplex" nil)
2849 (string :tag "Duplex Switch"))
2850 (choice :menu-tag "Tumble"
2851 :tag "Tumble"
2852 (const :tag "No Tumble" nil)
2853 (string :tag "Tumble Switch"))
2854 (string :tag "Output Separator")
2855 (repeat :tag "Utility Switches"
2856 (sexp :tag "Switch" :value ""))
2857 (repeat
2858 :tag "Default Value List"
2859 :inline t
2860 (cons
2861 :tag ""
2862 (choice
2863 :menu-tag "Variable"
2864 :tag "Variable"
2865 (const :tag "PS File Landscape" pr-file-landscape)
2866 (const :tag "PS File Duplex" pr-file-duplex)
2867 (const :tag "PS File Tumble" pr-file-tumble)
2868 (const :tag "Ghostscript Device" pr-gs-device)
2869 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2870 (const :tag "inherits-from:" inherits-from:)
2871 (variable :tag "Other"))
2872 (sexp :tag "Value")))
2874 :set 'pr-alist-custom-set
2875 :group 'printing)
2878 (defcustom pr-menu-lock t
2879 "Non-nil means menu is locked while selecting toggle options.
2881 See also `pr-menu-char-height' and `pr-menu-char-width'."
2882 :type 'boolean
2883 :group 'printing)
2886 (defcustom pr-menu-char-height (pr-menu-char-height)
2887 "Specify menu char height in pixels.
2889 This variable is used to guess which vertical position should be locked the
2890 menu, so don't forget to adjust it if menu position is not ok.
2892 See also `pr-menu-lock' and `pr-menu-char-width'."
2893 :type 'integer
2894 :group 'printing)
2897 (defcustom pr-menu-char-width (pr-menu-char-width)
2898 "Specify menu char width in pixels.
2900 This variable is used to guess which horizontal position should be locked the
2901 menu, so don't forget to adjust it if menu position is not ok.
2903 See also `pr-menu-lock' and `pr-menu-char-height'."
2904 :type 'integer
2905 :group 'printing)
2908 (defcustom pr-setting-database
2909 '((no-duplex ; setting symbol name
2910 nil nil nil ; inherits local kill-local
2911 (pr-file-duplex . nil) ; settings
2912 (pr-file-tumble . nil))
2914 "Specify an alist for settings in general.
2916 The elements have the following form:
2918 (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
2920 Where:
2922 SYMBOL It's a symbol to identify the setting group.
2924 INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
2925 setting from which the current setting inherits the context.
2926 If INHERITS is nil, means that there is no inheritance.
2927 This is a simple inheritance mechanism.
2929 Let's see an example to illustrate the inheritance mechanism:
2931 (setq pr-setting-database
2932 '((no-duplex ; setting symbol name
2933 nil ; inherits
2934 nil nil ; local kill-local
2935 (pr-file-duplex . nil) ; settings
2936 (pr-file-tumble . nil)
2938 (no-duplex-and-landscape ; setting symbol name
2939 no-duplex ; inherits
2940 nil nil ; local kill-local
2941 (pr-file-landscape . nil) ; settings
2944 The example above has two setting groups: no-duplex and
2945 no-duplex-and-landscape. When setting no-duplex is activated
2946 through `inherits-from:' (see option `pr-ps-utility',
2947 `pr-mode-alist' and `pr-ps-printer-alist'), the variables
2948 pr-file-duplex and pr-file-tumble are both set to nil.
2950 Now when setting no-duplex-and-landscape is activated through
2951 `inherits-from:', the variable pr-file-landscape is set to nil
2952 and also the settings for no-duplex are done, because
2953 no-duplex-and-landscape inherits settings from no-duplex.
2955 Take care with circular inheritance. It's an error if circular
2956 inheritance happens.
2958 LOCAL Non-nil means that all settings for SYMBOL group will be
2959 declared local buffer.
2961 KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
2962 killed at end. It has effect only when LOCAL is non-nil.
2964 SETTING It's a cons like:
2966 (VARIABLE . VALUE)
2968 Which associates VARIABLE with VALUE. When this entry is
2969 selected, it's executed the following command:
2971 * If LOCAL is non-nil:
2972 (set (make-local-variable VARIABLE) (eval VALUE))
2974 * If LOCAL is nil:
2975 (set VARIABLE (eval VALUE))
2977 Note that VALUE can be any valid lisp expression. So, don't
2978 forget to quote symbols and constant lists.
2979 This setting is ignored if VARIABLE is equal to keyword
2980 `inherits-from:'.
2981 Examples:
2982 '(ps-landscape-mode . nil)
2983 '(ps-spool-duplex . t)
2984 '(pr-gs-device . (my-gs-device t))"
2985 :type '(repeat
2986 (list
2987 :tag ""
2988 (symbol :tag "Setting Name")
2989 (choice :menu-tag "Inheritance"
2990 :tag "Inheritance"
2991 (const :tag "No Inheritance" nil)
2992 (symbol :tag "Inherits From"))
2993 (boolean :tag "Local Buffer Setting")
2994 (boolean :tag "Kill Local Variable At End")
2995 (repeat
2996 :tag "Setting List"
2997 :inline t
2998 (cons
2999 :tag ""
3000 (choice
3001 :menu-tag "Variable"
3002 :tag "Variable"
3003 (const :tag "Landscape" ps-landscape-mode)
3004 (const :tag "Print Header" ps-print-header)
3005 (const :tag "Print Header Frame" ps-print-header-frame)
3006 (const :tag "Line Number" ps-line-number)
3007 (const :tag "Zebra Stripes" ps-zebra-stripes)
3008 (const :tag "Duplex" ps-spool-duplex)
3009 (const :tag "Tumble" ps-spool-tumble)
3010 (const :tag "Upside-Down" ps-print-upside-down)
3011 (const :tag "PS File Landscape" pr-file-landscape)
3012 (const :tag "PS File Duplex" pr-file-duplex)
3013 (const :tag "PS File Tumble" pr-file-tumble)
3014 (const :tag "Auto Region" pr-auto-region)
3015 (const :tag "Auto Mode" pr-auto-mode)
3016 (const :tag "Ghostscript Device" pr-gs-device)
3017 (const :tag "Ghostscript Resolution" pr-gs-resolution)
3018 (variable :tag "Other"))
3019 (sexp :tag "Value")))
3021 :group 'printing)
3024 (defcustom pr-visible-entry-list
3025 '(postscript text postscript-options postscript-process printing help)
3026 "Specify a list of Printing menu visible entries.
3028 Valid values with the corresponding menu parts are:
3030 +------------------------------+
3031 | Printing Interface |
3032 +------------------------------+
3033 `postscript' | PostScript Preview >|
3034 | PostScript Print >|
3035 | PostScript Printer: name >|
3036 +------------------------------+
3037 `text' | Printify >|
3038 | Print >|
3039 | Text Printer: name >|
3040 +------------------------------+
3041 `postscript-options' |[ ] Landscape |
3042 |[ ] Print Header |
3043 |[ ] Print Header Frame |
3044 |[ ] Line Number |
3045 |[ ] Zebra Stripes |
3046 |[ ] Duplex |
3047 |[ ] Tumble |
3048 |[ ] Upside-Down |
3049 | Print All Pages >|
3050 +------------------------------+
3051 `postscript-process' |[ ] Spool Buffer |
3052 |[ ] Print with faces |
3053 |[ ] Print via Ghostscript |
3054 +------------------------------+
3055 `printing' |[ ] Auto Region |
3056 |[ ] Auto Mode |
3057 |[ ] Menu Lock |
3058 +------------------------------+
3059 `help' | Customize >|
3060 | Show Settings >|
3061 | Help |
3062 +------------------------------+
3064 Any other value is ignored."
3065 :type '(repeat :tag "Menu Visible Part"
3066 (choice :menu-tag "Menu Part"
3067 :tag "Menu Part"
3068 (const postscript)
3069 (const text)
3070 (const postscript-options)
3071 (const postscript-process)
3072 (const printing)
3073 (const help)))
3074 :group 'printing)
3077 (defcustom pr-delete-temp-file t
3078 "Non-nil means delete temporary files.
3080 Set `pr-delete-temp-file' to nil, if the following message (or a similar)
3081 happens when printing:
3083 Error: could not open \"c:\\temp\\prspool.ps\" for reading."
3084 :type 'boolean
3085 :group 'printing)
3088 (defcustom pr-list-directory nil
3089 "Non-nil means list directory when processing a directory.
3091 That is, any subdirectories (and the superdirectory) of the directory (given as
3092 argument of functions below) are also printed (as dired-mode listings).
3094 It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
3095 `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
3096 and `pr-txt-directory'."
3097 :type 'boolean
3098 :group 'printing)
3101 (defcustom pr-buffer-name "*Printing Interface*"
3102 "Specify the name of the buffer interface for printing package.
3104 It's used by `pr-interface'."
3105 :type 'string
3106 :group 'printing)
3109 (defcustom pr-buffer-name-ignore
3110 (list (regexp-quote pr-buffer-name) ; ignore printing interface buffer
3111 "^ .*$") ; ignore invisible buffers
3112 "Specify a regexp list for buffer names to be ignored in interface buffer.
3114 NOTE: Case is important for matching, that is, `case-fold-search' is always
3115 nil.
3117 It's used by `pr-interface'."
3118 :type '(repeat (regexp :tag "Buffer Name Regexp"))
3119 :group 'printing)
3122 (defcustom pr-buffer-verbose t
3123 "Non-nil means to be verbose when editing a field in interface buffer.
3125 It's used by `pr-interface'."
3126 :type 'boolean
3127 :group 'printing)
3130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3131 ;; Internal Variables
3134 (defvar pr-txt-command nil
3135 "Name of program for printing a text file.
3136 See `pr-txt-printer-alist'.")
3139 (defvar pr-txt-switches nil
3140 "List of sexp's to pass as extra options to the text printer program.
3141 See `pr-txt-printer-alist'.")
3144 (defvar pr-txt-printer nil
3145 "Specify text printer name.
3146 See `pr-txt-printer-alist'.")
3149 (defvar pr-ps-command nil
3150 "Name of program for printing a PostScript file.
3151 See `pr-ps-printer-alist'.")
3154 (defvar pr-ps-switches nil
3155 "List of sexp's to pass as extra options to the PostScript printer program.
3156 See `pr-ps-printer-alist'.")
3159 (defvar pr-ps-printer-switch nil
3160 "Specify PostScript printer name switch.
3161 See `pr-ps-printer-alist'.")
3164 (defvar pr-ps-printer nil
3165 "Specify PostScript printer name.
3166 See `pr-ps-printer-alist'.")
3169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3170 ;; Macros
3173 (defmacro pr-save-file-modes (&rest body)
3174 "Execute BODY with file permissions temporarily set to `pr-file-modes'."
3175 (declare (obsolete with-file-modes "25.1"))
3176 `(with-file-modes pr-file-modes ,@body))
3178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3179 ;; Keys & Menus
3182 (defsubst pr-visible-p (key)
3183 (memq key pr-visible-entry-list))
3186 (defsubst pr-mode-alist-p ()
3187 (cdr (assq major-mode pr-mode-alist)))
3190 (defsubst pr-auto-mode-p ()
3191 (and pr-auto-mode (pr-mode-alist-p)))
3194 (defsubst pr-using-ghostscript-p ()
3195 (and pr-print-using-ghostscript (not pr-spool-p)))
3198 (defalias 'pr-get-symbol
3199 (if (featurep 'emacs) 'easy-menu-intern ; since 22.1
3200 (if (fboundp 'easy-menu-intern) ; hacked from easymenu.el
3201 'easy-menu-intern
3202 (lambda (s) (if (stringp s) (intern s) s)))))
3205 (defconst pr-menu-spec
3206 ;; Menu mapping:
3207 ;; unfortunately XEmacs doesn't support :active for submenus,
3208 ;; only for items.
3209 ;; So, it uses :included instead of :active.
3210 ;; Also, XEmacs doesn't support :help tag.
3211 (let ((pr-:active (if (featurep 'xemacs)
3212 :included ; XEmacs
3213 :active)) ; GNU Emacs
3214 (pr-:help (if (featurep 'xemacs)
3215 'ignore ; XEmacs
3216 #'(lambda (text) (list :help text))))) ; GNU Emacs
3218 ["Printing Interface" pr-interface
3219 ,@(funcall
3220 pr-:help "Use buffer interface instead of menu interface")]
3221 "--"
3222 ("PostScript Preview" :included (pr-visible-p 'postscript)
3223 ,@(funcall
3224 pr-:help "Preview PostScript instead of sending to printer")
3225 ("Directory" ,pr-:active (not pr-spool-p)
3226 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
3227 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
3228 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
3229 ["Other..." (pr-ps-directory-preview nil nil nil t)
3230 :keys "\\[pr-ps-buffer-preview]"])
3231 ("Buffer" ,pr-:active (not pr-spool-p)
3232 ["1-up" (pr-ps-buffer-preview 1 t) t]
3233 ["2-up" (pr-ps-buffer-preview 2 t) t]
3234 ["4-up" (pr-ps-buffer-preview 4 t) t]
3235 ["Other..." (pr-ps-buffer-preview nil t)
3236 :keys "\\[pr-ps-buffer-preview]"])
3237 ("Region" ,pr-:active (and (not pr-spool-p) (ps-mark-active-p))
3238 ["1-up" (pr-ps-region-preview 1 t) t]
3239 ["2-up" (pr-ps-region-preview 2 t) t]
3240 ["4-up" (pr-ps-region-preview 4 t) t]
3241 ["Other..." (pr-ps-region-preview nil t)
3242 :keys "\\[pr-ps-region-preview]"])
3243 ("Mode" ,pr-:active (and (not pr-spool-p) (pr-mode-alist-p))
3244 ["1-up" (pr-ps-mode-preview 1 t) t]
3245 ["2-up" (pr-ps-mode-preview 2 t) t]
3246 ["4-up" (pr-ps-mode-preview 4 t) t]
3247 ["Other..." (pr-ps-mode-preview nil t)
3248 :keys "\\[pr-ps-mode-preview]"])
3249 ("File"
3250 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
3251 :keys "\\[pr-ps-file-preview]"
3252 ,@(funcall
3253 pr-:help "Preview PostScript file")]
3254 "--"
3255 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
3256 ,@(funcall
3257 pr-:help "Select PostScript utility")]
3258 "--"
3259 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
3260 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
3261 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
3262 ["Other..." (pr-ps-file-up-preview nil t t)
3263 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
3264 "--"
3265 ["Landscape" pr-toggle-file-landscape-menu
3266 :style toggle :selected pr-file-landscape
3267 ,@(funcall
3268 pr-:help "Toggle landscape for PostScript file")
3269 :active pr-ps-utility-alist]
3270 ["Duplex" pr-toggle-file-duplex-menu
3271 :style toggle :selected pr-file-duplex
3272 ,@(funcall
3273 pr-:help "Toggle duplex for PostScript file")
3274 :active pr-ps-utility-alist]
3275 ["Tumble" pr-toggle-file-tumble-menu
3276 :style toggle :selected pr-file-tumble
3277 ,@(funcall
3278 pr-:help "Toggle tumble for PostScript file")
3279 :active (and pr-file-duplex pr-ps-utility-alist)])
3280 ["Despool..." (call-interactively 'pr-despool-preview)
3281 :active pr-spool-p :keys "\\[pr-despool-preview]"
3282 ,@(funcall
3283 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3284 ("PostScript Print" :included (pr-visible-p 'postscript)
3285 ,@(funcall
3286 pr-:help "Send PostScript to printer or file (C-u)")
3287 ("Directory"
3288 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
3289 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
3290 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
3291 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
3292 :keys "\\[pr-ps-buffer-ps-print]"])
3293 ("Buffer"
3294 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
3295 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
3296 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
3297 ["Other..." (pr-ps-buffer-ps-print nil t)
3298 :keys "\\[pr-ps-buffer-ps-print]"])
3299 ("Region" ,pr-:active (ps-mark-active-p)
3300 ["1-up" (pr-ps-region-ps-print 1 t) t]
3301 ["2-up" (pr-ps-region-ps-print 2 t) t]
3302 ["4-up" (pr-ps-region-ps-print 4 t) t]
3303 ["Other..." (pr-ps-region-ps-print nil t)
3304 :keys "\\[pr-ps-region-ps-print]"])
3305 ("Mode" ,pr-:active (pr-mode-alist-p)
3306 ["1-up" (pr-ps-mode-ps-print 1 t) t]
3307 ["2-up" (pr-ps-mode-ps-print 2 t) t]
3308 ["4-up" (pr-ps-mode-ps-print 4 t) t]
3309 ["Other..." (pr-ps-mode-ps-print nil t)
3310 :keys "\\[pr-ps-mode-ps-print]"])
3311 ("File"
3312 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
3313 :keys "\\[pr-ps-file-ps-print]"
3314 ,@(funcall
3315 pr-:help "Send PostScript file to printer")]
3316 "--"
3317 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
3318 ,@(funcall
3319 pr-:help "Select PostScript utility")]
3320 "--"
3321 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
3322 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
3323 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
3324 ["Other..." (pr-ps-file-up-ps-print nil t t)
3325 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
3326 "--"
3327 ["Landscape" pr-toggle-file-landscape-menu
3328 :style toggle :selected pr-file-landscape
3329 ,@(funcall
3330 pr-:help "Toggle landscape for PostScript file")
3331 :active pr-ps-utility-alist]
3332 ["Duplex" pr-toggle-file-duplex-menu
3333 :style toggle :selected pr-file-duplex
3334 ,@(funcall
3335 pr-:help "Toggle duplex for PostScript file")
3336 :active pr-ps-utility-alist]
3337 ["Tumble" pr-toggle-file-tumble-menu
3338 :style toggle :selected pr-file-tumble
3339 ,@(funcall
3340 pr-:help "Toggle tumble for PostScript file")
3341 :active (and pr-file-duplex pr-ps-utility-alist)])
3342 ["Despool..." (call-interactively 'pr-despool-ps-print)
3343 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
3344 ,@(funcall
3345 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3346 ["PostScript Printers" pr-update-menus
3347 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
3348 ,@(funcall
3349 pr-:help "Select PostScript printer")]
3350 "--"
3351 ("Printify" :included (pr-visible-p 'text)
3352 ,@(funcall
3353 pr-:help
3354 "Replace non-printing chars with printable representations.")
3355 ["Directory" pr-printify-directory t]
3356 ["Buffer" pr-printify-buffer t]
3357 ["Region" pr-printify-region (ps-mark-active-p)])
3358 ("Print" :included (pr-visible-p 'text)
3359 ,@(funcall
3360 pr-:help "Send text to printer")
3361 ["Directory" pr-txt-directory t]
3362 ["Buffer" pr-txt-buffer t]
3363 ["Region" pr-txt-region (ps-mark-active-p)]
3364 ["Mode" pr-txt-mode (pr-mode-alist-p)])
3365 ["Text Printers" pr-update-menus
3366 :active pr-txt-printer-alist :included (pr-visible-p 'text)
3367 ,@(funcall
3368 pr-:help "Select text printer")]
3369 "--"
3370 ["Landscape" pr-toggle-landscape-menu
3371 :style toggle :selected ps-landscape-mode
3372 :included (pr-visible-p 'postscript-options)]
3373 ["Print Header" pr-toggle-header-menu
3374 :style toggle :selected ps-print-header
3375 :included (pr-visible-p 'postscript-options)]
3376 ["Print Header Frame" pr-toggle-header-frame-menu
3377 :style toggle :selected ps-print-header-frame :active ps-print-header
3378 :included (pr-visible-p 'postscript-options)]
3379 ["Line Number" pr-toggle-line-menu
3380 :style toggle :selected ps-line-number
3381 :included (pr-visible-p 'postscript-options)]
3382 ["Zebra Stripes" pr-toggle-zebra-menu
3383 :style toggle :selected ps-zebra-stripes
3384 :included (pr-visible-p 'postscript-options)]
3385 ["Duplex" pr-toggle-duplex-menu
3386 :style toggle :selected ps-spool-duplex
3387 :included (pr-visible-p 'postscript-options)]
3388 ["Tumble" pr-toggle-tumble-menu
3389 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
3390 :included (pr-visible-p 'postscript-options)]
3391 ["Upside-Down" pr-toggle-upside-down-menu
3392 :style toggle :selected ps-print-upside-down
3393 :included (pr-visible-p 'postscript-options)]
3394 ("Print All Pages" :included (pr-visible-p 'postscript-options)
3395 ,@(funcall
3396 pr-:help "Select odd/even pages/sheets to print")
3397 ["All Pages" (pr-even-or-odd-pages nil)
3398 :style radio :selected (eq ps-even-or-odd-pages nil)]
3399 ["Even Pages" (pr-even-or-odd-pages 'even-page)
3400 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
3401 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
3402 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
3403 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
3404 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
3405 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
3406 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
3407 "--"
3408 ["Spool Buffer" pr-toggle-spool-menu
3409 :style toggle :selected pr-spool-p
3410 :included (pr-visible-p 'postscript-process)
3411 ,@(funcall
3412 pr-:help "Toggle PostScript spooling")]
3413 ["Print with faces" pr-toggle-faces-menu
3414 :style toggle :selected pr-faces-p
3415 :included (pr-visible-p 'postscript-process)
3416 ,@(funcall
3417 pr-:help "Toggle PostScript printing with faces")]
3418 ["Print via Ghostscript" pr-toggle-ghostscript-menu
3419 :style toggle :selected pr-print-using-ghostscript
3420 :included (pr-visible-p 'postscript-process)
3421 ,@(funcall
3422 pr-:help "Toggle PostScript generation using ghostscript")]
3423 "--"
3424 ["Auto Region" pr-toggle-region-menu
3425 :style toggle :selected pr-auto-region
3426 :included (pr-visible-p 'printing)]
3427 ["Auto Mode" pr-toggle-mode-menu
3428 :style toggle :selected pr-auto-mode
3429 :included (pr-visible-p 'printing)]
3430 ["Menu Lock" pr-toggle-lock-menu
3431 :style toggle :selected pr-menu-lock
3432 :included (pr-visible-p 'printing)]
3433 "--"
3434 ("Customize" :included (pr-visible-p 'help)
3435 ["printing" pr-customize t]
3436 ["ps-print" ps-print-customize t]
3437 ["lpr" lpr-customize t])
3438 ("Show Settings" :included (pr-visible-p 'help)
3439 ["printing" pr-show-pr-setup t]
3440 ["ps-print" pr-show-ps-setup t]
3441 ["lpr" pr-show-lpr-setup t])
3442 ["Help" pr-help :active t :included (pr-visible-p 'help)]
3446 (defun pr-menu-bind ()
3447 "Install `printing' menu in the menubar.
3448 This replaces the File/Print* menu entries with a File/Print sub-menu.
3449 Calls `pr-update-menus' to adjust menus."
3450 (interactive)
3451 (pr-global-menubar pr-menu-spec)
3452 (pr-update-menus t))
3455 ;; Key binding
3456 (let ((pr-print-key (if (featurep 'xemacs)
3457 'f22 ; XEmacs
3458 'print))) ; GNU Emacs
3459 (global-set-key `[,pr-print-key] 'pr-ps-fast-fire)
3460 ;; Well, M-print and S-print are used because in my keyboard S-print works
3461 ;; and M-print doesn't. But M-print can work in other keyboard.
3462 (global-set-key `[(meta ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3463 (global-set-key `[(shift ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3464 ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
3465 ;; and C-print doesn't. But C-print can work in other keyboard.
3466 (global-set-key `[(control ,pr-print-key)] 'pr-txt-fast-fire)
3467 (global-set-key `[(control meta ,pr-print-key)] 'pr-txt-fast-fire))
3470 ;;; You can also use something like:
3471 ;;;(global-set-key "\C-ci" 'pr-interface)
3472 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
3473 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
3474 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
3475 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
3476 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
3477 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
3480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3481 ;; Help Message
3484 (defconst pr-help-message
3485 (concat "printing.el version " pr-version
3486 " ps-print.el version " ps-print-version
3487 "\n\n
3488 Menu Layout
3489 -----------
3491 The `printing' menu (Tools/Printing or File/Print) has the following layout:
3493 +-----------------------------+
3494 A 0 | Printing Interface |
3495 +-----------------------------+ +-A---------+ +-B------+
3496 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
3497 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
3498 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
3499 +-----------------------------+ |Mode >|-- B |Other...|
3500 II 4 | Printify >|-----\\ |File >|--\\ +--------+
3501 5 | Print >|---\\ | |Despool... | |
3502 6 | Text Printer: name >|-\\ | | +-----------+ |
3503 +-----------------------------+ | | | +---------+ +------------+
3504 III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
3505 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
3506 9 |[ ]Print Header Frame | | | |Region | | name >|- C
3507 10 |[ ]Line Number | | | +---------+ +------------+
3508 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
3509 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
3510 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
3511 14 |[ ]Upside-Down | | |Region | | Other... |
3512 15 | Print All Pages >|--\\ | |Mode | +------------+
3513 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
3514 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
3515 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
3516 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
3517 +-----------------------------+ | |... |
3518 V 19 |[ ]Auto Region | | |(*)name |
3519 20 |[ ]Auto Mode | | |... |
3520 21 |[ ]Menu Lock | | +---------+ +--------------+
3521 +-----------------------------+ \\------------------|(*)All Pages |
3522 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
3523 23 | Show Settings >|-------|printing| |( )Odd Pages |
3524 24 | Help | |ps-print| |( )Even Sheets|
3525 +-----------------------------+ |lpr | |( )Odd Sheets |
3526 +--------+ +--------------+
3528 See `pr-visible-entry-list' for hiding some parts of the menu.
3530 The menu has the following sections:
3532 A. Interface:
3534 0. You can use a buffer interface instead of menus. It looks like the
3535 customization buffer. Basically, it has the same options found in the
3536 menu and some extra options, all this on a buffer.
3538 I. PostScript printing:
3540 1. You can generate a PostScript file (if you type C-u before activating
3541 menu) or PostScript temporary file for a directory, a buffer, a region
3542 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
3543 after file generation, ghostview is activated using the file generated
3544 as argument. This option is disabled if spooling is on (option 16).
3545 Also, if you already have a PostScript file you can preview it.
3546 Instead of previewing each buffer, region or major mode at once, you
3547 can save temporarily the PostScript code generated in a buffer and
3548 preview it later. The option `Despool...' despools the PostScript
3549 spooling buffer in a temporary file and uses ghostview to preview it.
3550 If you type C-u before choosing this option, the PostScript code
3551 generated is saved in a file instead of saving in a temporary file. To
3552 spool the PostScript code generated you need to turn on the option 16.
3553 The option `Despool...' is enabled if spooling is on (option 16).
3555 NOTE 1: It's possible to customize a major mode printing, just declare
3556 the customization in `pr-mode-alist' and invoke some of
3557 `*-mode*' commands or select Mode option in Printing menu. An
3558 example for major mode usage is when you're using gnus (or mh,
3559 or rmail, etc.) and you're in the *Summary* buffer, if you
3560 forget to switch to the *Article* buffer before printing,
3561 you'll get a nicely formatted list of article subjects shows
3562 up at the printer. With major mode printing you don't need to
3563 switch from gnus *Summary* buffer first.
3565 NOTE 2: There are the following options for PostScript file processing:
3566 Ia. Print the file *No Preprocessing*, that is, send it
3567 directly to PostScript printer.
3568 Ib. PostScript utility processing selection.
3569 See `pr-ps-utility-alist' and `pr-setting-database' for
3570 documentation.
3571 Ic. Do n-up processing before printing.
3572 Id. Toggle on/off landscape for PostScript file processing.
3573 Ie. Toggle on/off duplex for PostScript file processing.
3574 If. Toggle on/off tumble for PostScript file processing.
3576 NOTE 3: Don't forget to download and install the utilities declared on
3577 `pr-ps-utility-alist'.
3579 2. Operate the same way as option 1, but it sends directly the PostScript
3580 code (or put in a file, if you've typed C-u) or it uses ghostscript to
3581 print the PostScript file generated. It depends on option 18, if it's
3582 turned on, it uses ghostscript; otherwise, it sends directly to
3583 printer. If spooling is on (option 16), the PostScript code is saved
3584 temporarily in a buffer instead of printing it or saving it in a file.
3585 Also, if you already have a PostScript file you can print it.
3586 Instead of printing each buffer, region or major mode at once, you can
3587 save temporarily the PostScript code generated in a buffer and print it
3588 later. The option `Despool...' despools the PostScript spooling buffer
3589 directly on a printer. If you type C-u before choosing this option,
3590 the PostScript code generated is saved in a file instead of sending it to
3591 the printer. To spool the PostScript code generated you need to turn on
3592 option 16. This option is enabled if spooling is on (option 16).
3593 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
3595 3. You can select a new PostScript printer to send PostScript code
3596 generated. For selection it's used all PostScript printers defined
3597 in `pr-ps-printer-alist' variable (see it for documentation).
3598 See also `pr-setting-database'.
3600 II. Text printing:
3602 4. If you have control characters (character code from \\000 to \\037) in a
3603 buffer and you want to print them in a text printer, select this
3604 option. All control characters in your buffer or region will be
3605 replaced by a printable representation. The printable representations
3606 use ^ (for ASCII control characters) or hex. The characters tab,
3607 linefeed, space, return and formfeed are not affected.
3608 You don't need to select this option if you use any option of section
3609 I, the PostScript engine treats control characters properly.
3611 5. If you want to print a directory, buffer, region or major mode in a
3612 text printer, select this option. See also the NOTE 1 on option 1.
3614 6. You can select a new text printer to send text generated. For
3615 selection it's used all text printers defined in `pr-txt-printer-alist'
3616 variable (see it for documentation).
3617 See also `pr-setting-database'.
3619 III. PostScript page toggle options:
3621 7. If you want a PostScript landscape printing, turn on this option.
3623 8. If you want to have a header in each page in your PostScript code,
3624 turn on this option.
3626 9. If you want to draw a gaudy frame around the header, turn on this
3627 option. This option is enabled if print header is on (option 8).
3629 10. If you want that the line number is printed in your PostScript code,
3630 turn on this option.
3632 11. If you want background zebra stripes in your PostScript code, turn on
3633 this option.
3635 12. If you want a duplex printing and your PostScript printer has this
3636 feature, turn on this option.
3638 13. If you turned on duplex printing, you can choose if you want to have a
3639 printing suitable for binding on the left or right (tumble off), or to
3640 have a printing suitable for binding at top or bottom (tumble on).
3641 This option is enabled if duplex is on (option 12).
3643 14. If you want a PostScript upside-down printing, turn on this option.
3645 15. With this option, you can choose if you want to print all pages, odd
3646 pages, even pages, odd sheets or even sheets.
3647 See also `ps-even-or-odd-pages'.
3649 IV. PostScript processing toggle options:
3651 16. If you want to spool the PostScript code generated, turn on this
3652 option. To spool the PostScript code generated use option 2. You can
3653 despool later by choosing option 1 or 2, sub-option `Despool...'.
3655 17. If you use colors in your buffers and want to see these colors on your
3656 PostScript code generated, turn on this option. If you have a
3657 black/white PostScript printer, these colors are displayed in gray
3658 scale by PostScript printer interpreter.
3660 18. If you don't have a PostScript printer to send PostScript files, turn
3661 on this option. When this option is on, the ghostscript is used to
3662 print PostScript files. In GNU or Unix system, if ghostscript is set
3663 as a PostScript filter, you don't need to turn on this option.
3665 V. Printing customization:
3667 19. If you want that region is automagically detected, turn on this
3668 option. Note that this will only work if you're using transient mark
3669 mode. When this option is on, the `*-buffer*' commands will behave
3670 like `*-region*' commands, that is, `*-buffer*' commands will print
3671 only the region marked instead of all buffer.
3673 20. Turn this option on if you want that when current major-mode is
3674 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3675 behave like `*-mode*' commands.
3677 21. If you want that Printing menu stays open while you are setting
3678 toggle options, turn on this option. The variables
3679 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3680 menu position, so don't forget to adjust these variables if menu
3681 position is not ok.
3683 VI. Customization:
3685 22. Besides all options in section III, IV and V, you can customize much
3686 more PostScript options in `ps-print' option. Or you can customize
3687 some `lpr' options for text printing. Or customize `printing'
3688 options.
3690 23. Show current settings for `printing', `ps-print' or `lpr'.
3692 24. Quick help for printing menu layout.
3694 "Printing help message.")
3697 (defconst pr-interface-help-message
3698 (concat "printing.el version " pr-version
3699 " ps-print.el version " ps-print-version
3700 "\n\n
3701 The printing interface buffer has the same functionality as the printing menu.
3702 The major difference is that the states (like sending PostScript generated to a
3703 file, n-up printing, etc.) are set and saved between printing buffer
3704 activation. Also, the landscape, duplex and tumble values are the same for
3705 PostScript file and directory/buffer/region/mode processing; using menu, there
3706 are different value sets for PostScript file and directory/buffer/region/mode
3707 processing.
3709 The printing interface buffer has the following sections:
3711 1. Print:
3713 Here you can choose to print/preview a buffer, a directory or a PostScript
3714 file:
3716 1a. Buffer:
3718 * Buffer List:
3719 Select a buffer from the current buffer list.
3721 * Region:
3722 If it's on, this means that the selected buffer has an active region,
3723 so you can turn on/off, as you wish.
3724 If it's off when a buffer is selected, this means that the selected
3725 buffer has no active region, so it'll not be possible to turn it on.
3726 If you want to process the region, let this option on.
3727 If you want to process the whole buffer, let this option off.
3729 * Mode:
3730 If it's on, this means that the selected buffer major mode is declared
3731 for major mode processing, so you can turn on/off, as you wish.
3732 If it's off when a buffer is selected, this means that the selected
3733 buffer major mode isn't declared for major mode processing, so it'll
3734 not be possible to turn it on.
3735 If you want the major mode processing, let this option on.
3736 If you don't want the major mode processing, let this option off.
3738 NOTE 1: It's possible to customize a major mode printing, just declare
3739 the customization in `pr-mode-alist' and invoke some of
3740 `*-mode*' commands or select Mode option in Printing menu. An
3741 example for major mode usage is when you're using gnus (or mh,
3742 or rmail, etc.) and you're in the *Summary* buffer, if you
3743 forget to switch to the *Article* buffer before printing,
3744 you'll get a nicely formatted list of article subjects shows
3745 up at the printer. With major mode printing you don't need to
3746 switch from gnus *Summary* buffer first.
3748 1b. Directory:
3750 * Directory:
3751 Specify a valid directory path.
3753 * File Regexp:
3754 Specify a file name regexp. All file names in the directory that
3755 match with regexp will be printed/previewed. An empty file name
3756 regexp means to print/preview all files in the directory.
3758 * List Directory Entry:
3759 If it's turned on, list directory entries besides file entries.
3761 1c. PostScript file:
3763 * PostScript File:
3764 Specify an existent PostScript file to print/preview.
3766 * PostScript Utility:
3767 Select a PostScript utility.
3768 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3770 NOTE 2: Don't forget to download and install the utilities declared on
3771 `pr-ps-utility-alist'.
3773 * No Preprocessing:
3774 If it's turned on, don't use the PostScript utility to preprocess the
3775 PostScript file before printing/previewing.
3777 2. PostScript printer:
3779 * PostScript Printer:
3780 You can select a new PostScript printer to send PostScript code
3781 generated. For selection it's used all PostScript printers defined
3782 in `pr-ps-printer-alist' variable (see it for documentation).
3783 See also `pr-setting-database'.
3785 * Despool:
3786 If spooling is on, you can turn it on/off, as you wish.
3787 If spooling is off, it'll not be possible to turn it on.
3788 If it's turned on, specify to despools the PostScript spooling buffer in
3789 a temporary file or in the selected PostScript file when
3790 printing/previewing.
3792 * Preview:
3793 Preview the PostScript generated.
3795 * Print:
3796 Print the PostScript generated.
3798 * Quit:
3799 Quit from printing interface buffer.
3801 * Send to Printer/Temporary File:
3802 If it's turned on, the PostScript generated is sent directly to
3803 PostScript printer or, for previewing, to a temporary file.
3805 * Send to File:
3806 Specify a file name to send the PostScript generated.
3808 * N-Up:
3809 Specify n-up printing.
3811 3. Text printer:
3813 * Text Printer:
3814 Select a new text printer to send text generated. For selection it's used
3815 all text printers defined in `pr-txt-printer-alist' variable (see it for
3816 documentation). See also `pr-setting-database'.
3818 * Printify:
3819 If you have control characters (character code from \\000 to \\037) in a
3820 buffer and you want to print them in a text printer, select this
3821 option. All control characters in your buffer or region will be
3822 replaced by a printable representation. The printable representations
3823 use ^ (for ASCII control characters) or hex. The characters tab,
3824 linefeed, space, return and formfeed are not affected.
3825 You don't need to select this option if you use any option of section
3826 I, the PostScript engine treats control characters properly.
3828 * Print:
3829 To print a directory, buffer, region or major mode in a
3830 text printer, select this option. See also the NOTE 1 on section 1.
3832 * Quit:
3833 Quit from printing interface buffer.
3835 4. Settings:
3837 There are 3 setting columns:
3839 4a. First column (left column):
3841 * Landscape:
3842 PostScript landscape printing.
3844 * Print Header:
3845 To have a header in each page in your PostScript code.
3847 * Print Header Frame:
3848 To draw a gaudy frame around the header.
3850 * Line Number:
3851 The line number is printed in your PostScript code.
3853 * Zebra Stripes:
3854 Background zebra stripes in your PostScript code.
3856 * Duplex:
3857 Duplex printing (if your PostScript printer has this feature).
3859 * Tumble:
3860 If duplex printing is on, you can choose if you want to have a
3861 printing suitable for binding on the left or right (tumble off), or to
3862 have a printing suitable for binding at top or bottom (tumble on).
3864 * Upside-Down:
3865 PostScript upside-down printing.
3867 4b. Second column (middle column):
3869 * Auto Region:
3870 If you want that region is automagically detected, turn on this
3871 option. Note that this will only work if you're using transient mark
3872 mode. When this option is on, the `*-buffer*' commands will behave
3873 like `*-region*' commands, that is, `*-buffer*' commands will print
3874 only the region marked instead of all buffer.
3876 * Auto Mode:
3877 Turn this option on if you want that when current major-mode is
3878 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3879 behave like `*-mode*' commands.
3881 * Menu Lock:
3882 If you want that Printing menu stays open while you are setting
3883 toggle options, turn on this option. The variables
3884 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3885 menu position, so don't forget to adjust these variables if menu
3886 position is not ok.
3888 * Spool Buffer:
3889 To spool the PostScript code generated. You can despool later by
3890 setting Despool option on PostScript printer section.
3892 * Print with faces:
3893 If you use colors in your buffers and want to see these colors on your
3894 PostScript code generated, turn on this option. If you have a
3895 black/white PostScript printer, these colors are displayed in gray
3896 scale by PostScript printer interpreter.
3898 * Print via Ghostscript:
3899 If you don't have a PostScript printer to send PostScript files, turn
3900 on this option. When this option is on, the ghostscript is used to
3901 print PostScript files. In GNU or Unix system, if ghostscript is set
3902 as a PostScript filter, you don't need to turn on this option.
3904 * Parity Page Menu:
3905 To print all pages, odd pages, even pages, odd sheets or even sheets.
3906 See also `ps-even-or-odd-pages'.
3908 4c. Third column (right column):
3910 * Verbose:
3911 That is, to be verbose when editing a field in interface buffer.
3913 5. Customize:
3915 Besides all options in section 4, you can customize much more PostScript
3916 options in `ps-print' option. Or you can customize some `lpr' options for
3917 text printing. Or customize `printing' options.
3919 6. Show settings:
3921 Show current settings for `printing', `ps-print' or `lpr'.
3923 7. Help:
3925 Quick help for printing interface buffer and printing menu layout. You can
3926 also quit the printing interface buffer or kill all printing help buffer.
3928 "Printing buffer interface help message.")
3931 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3932 ;; Commands
3935 ;;;###autoload
3936 (defun pr-interface (&optional buffer)
3937 "Activate the printing interface buffer.
3939 If BUFFER is nil, the current buffer is used for printing.
3941 For more information, type \\[pr-interface-help]."
3942 (interactive)
3943 (with-current-buffer (or buffer (current-buffer))
3944 (pr-create-interface)))
3947 ;;;###autoload
3948 (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3949 "Preview directory using ghostview.
3951 Interactively, the command prompts for N-UP printing number, a directory, a
3952 file name regexp for matching and, when you use a prefix argument (C-u), the
3953 command prompts the user for a file name, and saves the PostScript image in
3954 that file instead of saving it in a temporary file.
3956 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3957 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3958 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3959 save the image in a temporary file. If FILENAME is a string, save the
3960 PostScript image in a file with that name. If FILENAME is t, prompts for a
3961 file name.
3963 See also documentation for `pr-list-directory'."
3964 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3965 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3966 (pr-prompt "PS preview dir"))
3967 (setq filename (pr-ps-file filename))
3968 (pr-ps-file-list n-up dir file-regexp filename)
3969 (or pr-spool-p
3970 (pr-ps-file-preview filename)))
3973 ;;;###autoload
3974 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3975 "Print directory using PostScript through ghostscript.
3977 Interactively, the command prompts for N-UP printing number, a directory, a
3978 file name regexp for matching and, when you use a prefix argument (C-u), the
3979 command prompts the user for a file name, and saves the PostScript image in
3980 that file instead of saving it in a temporary file.
3982 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3983 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3984 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3985 save the image in a temporary file. If FILENAME is a string, save the
3986 PostScript image in a file with that name. If FILENAME is t, prompts for a
3987 file name.
3989 See also documentation for `pr-list-directory'."
3990 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3991 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3992 (pr-prompt "PS print dir GS"))
3993 (let ((file (pr-ps-file filename)))
3994 (pr-ps-file-list n-up dir file-regexp file)
3995 (pr-ps-file-using-ghostscript file)
3996 (or filename (pr-delete-file file))))
3999 ;;;###autoload
4000 (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
4001 "Print directory using PostScript printer.
4003 Interactively, the command prompts for N-UP printing number, a directory, a
4004 file name regexp for matching and, when you use a prefix argument (C-u), the
4005 command prompts the user for a file name, and saves the PostScript image in
4006 that file instead of saving it in a temporary file.
4008 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4009 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4010 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4011 save the image in a temporary file. If FILENAME is a string, save the
4012 PostScript image in a file with that name. If FILENAME is t, prompts for a
4013 file name.
4015 See also documentation for `pr-list-directory'."
4016 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
4017 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4018 (pr-prompt "PS print dir"))
4019 (let ((file (pr-ps-file filename)))
4020 (pr-ps-file-list n-up dir file-regexp file)
4021 (pr-ps-file-print file)
4022 (or filename (pr-delete-file file))))
4025 ;;;###autoload
4026 (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
4027 "Print directory using PostScript printer or through ghostscript.
4029 It depends on `pr-print-using-ghostscript'.
4031 Interactively, the command prompts for N-UP printing number, a directory, a
4032 file name regexp for matching and, when you use a prefix argument (C-u), the
4033 command prompts the user for a file name, and saves the PostScript image in
4034 that file instead of saving it in a temporary file.
4036 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4037 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4038 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4039 save the image in a temporary file. If FILENAME is a string, save the
4040 PostScript image in a file with that name. If FILENAME is t, prompts for a
4041 file name.
4043 See also documentation for `pr-list-directory'."
4044 (interactive (pr-interactive-ps-dir-args
4045 (pr-prompt (pr-prompt-gs "PS print dir"))))
4046 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4047 (pr-prompt (pr-prompt-gs "PS print dir")))
4048 (if (pr-using-ghostscript-p)
4049 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
4050 (pr-ps-directory-print n-up dir file-regexp filename)))
4053 ;;;###autoload
4054 (defun pr-ps-buffer-preview (n-up &optional filename)
4055 "Preview buffer using ghostview.
4057 Interactively, the command prompts for N-UP printing number and, when you use a
4058 prefix argument (C-u), the command prompts the user for a file name, and saves
4059 the PostScript image in that file instead of saving it in a temporary file.
4061 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4062 argument FILENAME is treated as follows: if it's nil, save the image in a
4063 temporary file. If FILENAME is a string, save the PostScript image in a file
4064 with that name. If FILENAME is t, prompts for a file name."
4065 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
4066 (if (pr-auto-mode-p)
4067 (pr-ps-mode-preview n-up filename)
4068 (pr-ps-preview (pr-region-active-symbol) n-up filename
4069 (pr-region-active-string "PS preview"))))
4072 ;;;###autoload
4073 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
4074 "Print buffer using PostScript through ghostscript.
4076 Interactively, the command prompts for N-UP printing number and, when you use a
4077 prefix argument (C-u), the command prompts the user for a file name, and saves
4078 the PostScript image in that file instead of sending it to the printer.
4080 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4081 argument FILENAME is treated as follows: if it's nil, send the image to the
4082 printer. If FILENAME is a string, save the PostScript image in a file with
4083 that name. If FILENAME is t, prompts for a file name."
4084 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
4085 (if (pr-auto-mode-p)
4086 (pr-ps-mode-using-ghostscript n-up filename)
4087 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4088 (pr-region-active-string "PS print GS"))))
4091 ;;;###autoload
4092 (defun pr-ps-buffer-print (n-up &optional filename)
4093 "Print buffer using PostScript printer.
4095 Interactively, the command prompts for N-UP printing number and, when you use a
4096 prefix argument (C-u), the command prompts the user for a file name, and saves
4097 the PostScript image in that file instead of sending it to the printer.
4099 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4100 argument FILENAME is treated as follows: if it's nil, send the image to the
4101 printer. If FILENAME is a string, save the PostScript image in a file with
4102 that name. If FILENAME is t, prompts for a file name."
4103 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
4104 (if (pr-auto-mode-p)
4105 (pr-ps-mode-print n-up filename)
4106 (pr-ps-print (pr-region-active-symbol) n-up filename
4107 (pr-region-active-string "PS print"))))
4110 ;;;###autoload
4111 (defun pr-ps-buffer-ps-print (n-up &optional filename)
4112 "Print buffer using PostScript printer or through ghostscript.
4114 It depends on `pr-print-using-ghostscript'.
4116 Interactively, the command prompts for N-UP printing number and, when you use a
4117 prefix argument (C-u), the command prompts the user for a file name, and saves
4118 the PostScript image in that file instead of sending it to the printer.
4120 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4121 argument FILENAME is treated as follows: if it's nil, send the image to the
4122 printer. If FILENAME is a string, save the PostScript image in a file with
4123 that name. If FILENAME is t, prompts for a file name."
4124 (interactive (pr-interactive-n-up-file
4125 (pr-prompt (pr-prompt-gs "PS print"))))
4126 (cond ((pr-auto-mode-p)
4127 (pr-ps-mode-ps-print n-up filename))
4128 ((pr-using-ghostscript-p)
4129 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4130 (pr-region-active-string "PS print GS")))
4132 (pr-ps-print (pr-region-active-symbol) n-up filename
4133 (pr-region-active-string "PS print")))))
4136 ;;;###autoload
4137 (defun pr-ps-region-preview (n-up &optional filename)
4138 "Preview region using ghostview.
4140 See also `pr-ps-buffer-preview'."
4141 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
4142 (if (pr-auto-mode-p)
4143 (let ((pr-auto-region t))
4144 (pr-ps-mode-preview n-up filename))
4145 (pr-ps-preview 'region n-up filename "PS preview region")))
4148 ;;;###autoload
4149 (defun pr-ps-region-using-ghostscript (n-up &optional filename)
4150 "Print region using PostScript through ghostscript.
4152 See also `pr-ps-buffer-using-ghostscript'."
4153 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
4154 (if (pr-auto-mode-p)
4155 (let ((pr-auto-region t))
4156 (pr-ps-mode-using-ghostscript n-up filename))
4157 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
4160 ;;;###autoload
4161 (defun pr-ps-region-print (n-up &optional filename)
4162 "Print region using PostScript printer.
4164 See also `pr-ps-buffer-print'."
4165 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
4166 (if (pr-auto-mode-p)
4167 (let ((pr-auto-region t))
4168 (pr-ps-mode-print n-up filename))
4169 (pr-ps-print 'region n-up filename "PS print region")))
4172 ;;;###autoload
4173 (defun pr-ps-region-ps-print (n-up &optional filename)
4174 "Print region using PostScript printer or through ghostscript.
4176 See also `pr-ps-buffer-ps-print'."
4177 (interactive (pr-interactive-n-up-file
4178 (pr-prompt-region (pr-prompt-gs "PS print"))))
4179 (cond ((pr-auto-mode-p)
4180 (let ((pr-auto-region t))
4181 (pr-ps-mode-ps-print n-up filename)))
4182 ((pr-using-ghostscript-p)
4183 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
4185 (pr-ps-print 'region n-up filename "PS print region"))))
4188 ;;;###autoload
4189 (defun pr-ps-mode-preview (n-up &optional filename)
4190 "Preview major mode using ghostview.
4192 See also `pr-ps-buffer-preview'."
4193 (interactive (pr-interactive-n-up-file "PS preview mode"))
4194 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
4195 (let ((file (pr-ps-file filename)))
4196 (and (pr-ps-mode n-up file)
4197 (not pr-spool-p)
4198 (pr-ps-file-preview file))))
4201 ;;;###autoload
4202 (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
4203 "Print major mode using PostScript through ghostscript.
4205 See also `pr-ps-buffer-using-ghostscript'."
4206 (interactive (pr-interactive-n-up-file "PS print GS mode"))
4207 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
4208 (let ((file (pr-ps-file filename)))
4209 (when (and (pr-ps-mode n-up file)
4210 (not pr-spool-p))
4211 (pr-ps-file-using-ghostscript file)
4212 (or filename (pr-delete-file file)))))
4215 ;;;###autoload
4216 (defun pr-ps-mode-print (n-up &optional filename)
4217 "Print major mode using PostScript printer.
4219 See also `pr-ps-buffer-print'."
4220 (interactive (pr-interactive-n-up-file "PS print mode"))
4221 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
4222 (pr-ps-mode n-up filename))
4225 ;;;###autoload
4226 (defun pr-ps-mode-ps-print (n-up &optional filename)
4227 "Print major mode using PostScript or through ghostscript.
4229 See also `pr-ps-buffer-ps-print'."
4230 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
4231 (if (pr-using-ghostscript-p)
4232 (pr-ps-mode-using-ghostscript n-up filename)
4233 (pr-ps-mode-print n-up filename)))
4236 ;;;###autoload
4237 (defun pr-printify-directory (&optional dir file-regexp)
4238 "Replace nonprinting characters in directory with printable representations.
4239 The printable representations use ^ (for ASCII control characters) or hex.
4240 The characters tab, linefeed, space, return and formfeed are not affected.
4242 Interactively, the command prompts for a directory and a file name regexp for
4243 matching.
4245 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4246 prompts for FILE(name)-REGEXP.
4248 See also documentation for `pr-list-directory'."
4249 (interactive (pr-interactive-dir-args "Printify dir"))
4250 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
4251 (pr-file-list dir file-regexp 'pr-printify-buffer))
4254 ;;;###autoload
4255 (defun pr-printify-buffer ()
4256 "Replace nonprinting characters in buffer with printable representations.
4257 The printable representations use ^ (for ASCII control characters) or hex.
4258 The characters tab, linefeed, space, return and formfeed are not affected."
4259 (interactive "*")
4260 (if (pr-region-active-p)
4261 (pr-printify-region)
4262 (printify-region (point-min) (point-max))))
4265 ;;;###autoload
4266 (defun pr-printify-region ()
4267 "Replace nonprinting characters in region with printable representations.
4268 The printable representations use ^ (for ASCII control characters) or hex.
4269 The characters tab, linefeed, space, return and formfeed are not affected."
4270 (interactive "*")
4271 (printify-region (point) (mark)))
4274 ;;;###autoload
4275 (defun pr-txt-directory (&optional dir file-regexp)
4276 "Print directory using text printer.
4278 Interactively, the command prompts for a directory and a file name regexp for
4279 matching.
4281 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4282 prompts for FILE(name)-REGEXP.
4284 See also documentation for `pr-list-directory'."
4285 (interactive (pr-interactive-dir-args "Print dir"))
4286 (pr-set-dir-args 'dir 'file-regexp "Print dir")
4287 (pr-file-list dir file-regexp 'pr-txt-buffer))
4290 ;;;###autoload
4291 (defun pr-txt-buffer ()
4292 "Print buffer using text printer."
4293 (interactive)
4294 (cond ((pr-auto-mode-p)
4295 (pr-txt-mode))
4296 ((pr-region-active-p)
4297 (pr-txt-region))
4299 (pr-txt-print (point-min) (point-max)))))
4302 ;;;###autoload
4303 (defun pr-txt-region ()
4304 "Print region using text printer."
4305 (interactive)
4306 (if (pr-auto-mode-p)
4307 (let ((pr-auto-region t))
4308 (pr-txt-mode))
4309 (pr-txt-print (point) (mark))))
4312 ;;;###autoload
4313 (defun pr-txt-mode ()
4314 "Print major mode using text printer."
4315 (interactive)
4316 (let ((args (pr-mode-alist-p)))
4317 (if args
4318 (funcall (car args) (nthcdr 2 args))
4319 (ding)
4320 (message "`%s' major mode not declared." major-mode))))
4323 ;;;###autoload
4324 (defun pr-despool-preview (&optional filename)
4325 "Preview spooled PostScript.
4327 Interactively, when you use a prefix argument (C-u), the command prompts the
4328 user for a file name, and saves the spooled PostScript image in that file
4329 instead of saving it in a temporary file.
4331 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4332 save the image in a temporary file. If FILENAME is a string, save the
4333 PostScript image in a file with that name."
4334 (interactive (list (ps-print-preprint current-prefix-arg)))
4335 (let ((file (pr-ps-file filename)))
4336 (when (stringp file)
4337 (pr-despool-print file)
4338 (pr-ps-file-preview file))))
4341 ;;;###autoload
4342 (defun pr-despool-using-ghostscript (&optional filename)
4343 "Print spooled PostScript using ghostscript.
4345 Interactively, when you use a prefix argument (C-u), the command prompts the
4346 user for a file name, and saves the spooled PostScript image in that file
4347 instead of sending it to the printer.
4349 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4350 send the image to the printer. If FILENAME is a string, save the PostScript
4351 image in a file with that name."
4352 (interactive (list (ps-print-preprint current-prefix-arg)))
4353 (let ((file (pr-ps-file filename)))
4354 (when (stringp file)
4355 (pr-despool-print file)
4356 (pr-ps-file-using-ghostscript file)
4357 (or filename (pr-delete-file file)))))
4360 ;;;###autoload
4361 (defun pr-despool-print (&optional filename)
4362 "Send the spooled PostScript to the printer.
4364 Interactively, when you use a prefix argument (C-u), the command prompts the
4365 user for a file name, and saves the spooled PostScript image in that file
4366 instead of sending it to the printer.
4368 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4369 send the image to the printer. If FILENAME is a string, save the PostScript
4370 image in a file with that name."
4371 (interactive (list (ps-print-preprint current-prefix-arg)))
4372 (with-file-modes pr-file-modes
4373 (let ((ps-lpr-command (pr-command pr-ps-command))
4374 (ps-lpr-switches pr-ps-switches)
4375 (ps-printer-name-option pr-ps-printer-switch)
4376 (ps-printer-name pr-ps-printer))
4377 (ps-despool filename))))
4380 ;;;###autoload
4381 (defun pr-despool-ps-print (&optional filename)
4382 "Send the spooled PostScript to the printer or use ghostscript to print it.
4384 Interactively, when you use a prefix argument (C-u), the command prompts the
4385 user for a file name, and saves the spooled PostScript image in that file
4386 instead of sending it to the printer.
4388 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4389 send the image to the printer. If FILENAME is a string, save the PostScript
4390 image in a file with that name."
4391 (interactive (list (ps-print-preprint current-prefix-arg)))
4392 (if pr-print-using-ghostscript
4393 (pr-despool-using-ghostscript filename)
4394 (pr-despool-print filename)))
4397 ;;;###autoload
4398 (defun pr-ps-file-preview (filename)
4399 "Preview PostScript file FILENAME."
4400 (interactive (list (pr-ps-infile-preprint "Preview ")))
4401 (and (stringp filename) (file-exists-p filename)
4402 (pr-call-process pr-gv-command filename)))
4405 ;;;###autoload
4406 (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
4407 "Preview PostScript file FILENAME."
4408 (interactive (pr-interactive-n-up-inout "PS preview"))
4409 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4410 "PS preview ")))
4411 (pr-ps-utility-process n-up ifilename outfile)
4412 (pr-ps-file-preview outfile)))
4415 ;;;###autoload
4416 (defun pr-ps-file-using-ghostscript (filename)
4417 "Print PostScript file FILENAME using ghostscript."
4418 (interactive (list (pr-ps-infile-preprint "Print preview ")))
4419 (and (stringp filename) (file-exists-p filename)
4420 (let* ((file (pr-expand-file-name filename))
4421 (tempfile (pr-dosify-file-name (make-temp-file file))))
4422 ;; gs use
4423 (pr-call-process pr-gs-command
4424 (format "-sDEVICE=%s" pr-gs-device)
4425 (format "-r%d" pr-gs-resolution)
4426 (pr-switches-string pr-gs-switches "pr-gs-switches")
4427 (format "-sOutputFile=\"%s\"" tempfile)
4428 file
4429 "-c quit")
4430 ;; printing
4431 (pr-ps-file-print tempfile)
4432 ;; deleting
4433 (pr-delete-file tempfile))))
4436 ;;;###autoload
4437 (defun pr-ps-file-print (filename)
4438 "Print PostScript file FILENAME."
4439 (interactive (list (pr-ps-infile-preprint "Print ")))
4440 (and (stringp filename) (file-exists-p filename)
4441 ;; printing
4442 (let ((file (pr-expand-file-name filename)))
4443 (if (string= pr-ps-command "")
4444 ;; default action
4445 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
4446 (with-current-buffer ps-spool-buffer
4447 (erase-buffer)
4448 (insert-file-contents-literally file))
4449 (pr-despool-print))
4450 ;; use `pr-ps-command' to print
4451 (apply 'pr-call-process
4452 pr-ps-command
4453 (pr-switches-string pr-ps-switches "pr-ps-switches")
4454 (if (string-match "cp" pr-ps-command)
4455 ;; for "cp" (cmd in out)
4456 (list file
4457 (concat pr-ps-printer-switch pr-ps-printer))
4458 ;; else, for others (cmd out in)
4459 (list (concat pr-ps-printer-switch pr-ps-printer)
4460 file)))))))
4463 ;;;###autoload
4464 (defun pr-ps-file-ps-print (filename)
4465 "Send PostScript file FILENAME to printer or use ghostscript to print it."
4466 (interactive (list (pr-ps-infile-preprint
4467 (if pr-print-using-ghostscript
4468 "Print preview "
4469 "Print "))))
4470 (if pr-print-using-ghostscript
4471 (pr-ps-file-using-ghostscript filename)
4472 (pr-ps-file-print filename)))
4475 ;;;###autoload
4476 (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
4477 "Process a PostScript file IFILENAME and send it to printer.
4479 Interactively, the command prompts for N-UP printing number, for an input
4480 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
4481 command prompts the user for an output PostScript file name OFILENAME, and
4482 saves the PostScript image in that file instead of sending it to the printer.
4484 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4485 argument IFILENAME is treated as follows: if it's t, prompts for an input
4486 PostScript file name; otherwise, it *must* be a string that it's an input
4487 PostScript file name. The argument OFILENAME is treated as follows: if it's
4488 nil, send the image to the printer. If OFILENAME is a string, save the
4489 PostScript image in a file with that name. If OFILENAME is t, prompts for a
4490 file name."
4491 (interactive (pr-interactive-n-up-inout
4492 (if pr-print-using-ghostscript
4493 "PS print GS"
4494 "PS print")))
4495 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4496 (if pr-print-using-ghostscript
4497 "PS print GS "
4498 "PS print "))))
4499 (pr-ps-utility-process n-up ifilename outfile)
4500 (unless ofilename
4501 (pr-ps-file-ps-print outfile)
4502 (pr-delete-file outfile))))
4505 ;;;###autoload
4506 (defun pr-toggle-file-duplex ()
4507 "Toggle duplex for PostScript file."
4508 (interactive)
4509 (pr-toggle-file-duplex-menu t))
4512 ;;;###autoload
4513 (defun pr-toggle-file-tumble ()
4514 "Toggle tumble for PostScript file.
4516 If tumble is off, produces a printing suitable for binding on the left or
4517 right.
4518 If tumble is on, produces a printing suitable for binding at the top or
4519 bottom."
4520 (interactive)
4521 (pr-toggle-file-tumble-menu t))
4524 ;;;###autoload
4525 (defun pr-toggle-file-landscape ()
4526 "Toggle landscape for PostScript file."
4527 (interactive)
4528 (pr-toggle-file-landscape-menu t))
4531 ;;;###autoload
4532 (defun pr-toggle-ghostscript ()
4533 "Toggle printing using ghostscript."
4534 (interactive)
4535 (pr-toggle-ghostscript-menu t))
4538 ;;;###autoload
4539 (defun pr-toggle-faces ()
4540 "Toggle printing with faces."
4541 (interactive)
4542 (pr-toggle-faces-menu t))
4545 ;;;###autoload
4546 (defun pr-toggle-spool ()
4547 "Toggle spooling."
4548 (interactive)
4549 (pr-toggle-spool-menu t))
4552 ;;;###autoload
4553 (defun pr-toggle-duplex ()
4554 "Toggle duplex."
4555 (interactive)
4556 (pr-toggle-duplex-menu t))
4559 ;;;###autoload
4560 (defun pr-toggle-tumble ()
4561 "Toggle tumble.
4563 If tumble is off, produces a printing suitable for binding on the left or
4564 right.
4565 If tumble is on, produces a printing suitable for binding at the top or
4566 bottom."
4567 (interactive)
4568 (pr-toggle-tumble-menu t))
4571 ;;;###autoload
4572 (defun pr-toggle-landscape ()
4573 "Toggle landscape."
4574 (interactive)
4575 (pr-toggle-landscape-menu t))
4578 ;;;###autoload
4579 (defun pr-toggle-upside-down ()
4580 "Toggle upside-down."
4581 (interactive)
4582 (pr-toggle-upside-down-menu t))
4585 ;;;###autoload
4586 (defun pr-toggle-line ()
4587 "Toggle line number."
4588 (interactive)
4589 (pr-toggle-line-menu t))
4592 ;;;###autoload
4593 (defun pr-toggle-zebra ()
4594 "Toggle zebra stripes."
4595 (interactive)
4596 (pr-toggle-zebra-menu t))
4599 ;;;###autoload
4600 (defun pr-toggle-header ()
4601 "Toggle printing header."
4602 (interactive)
4603 (pr-toggle-header-menu t))
4606 ;;;###autoload
4607 (defun pr-toggle-header-frame ()
4608 "Toggle printing header frame."
4609 (interactive)
4610 (pr-toggle-header-frame-menu t))
4613 ;;;###autoload
4614 (defun pr-toggle-lock ()
4615 "Toggle menu lock."
4616 (interactive)
4617 (pr-toggle-lock-menu t))
4620 ;;;###autoload
4621 (defun pr-toggle-region ()
4622 "Toggle whether the region is automagically detected."
4623 (interactive)
4624 (pr-toggle-region-menu t))
4627 ;;;###autoload
4628 (defun pr-toggle-mode ()
4629 "Toggle auto mode."
4630 (interactive)
4631 (pr-toggle-mode-menu t))
4634 ;;;###autoload
4635 (defun pr-customize (&rest _ignore)
4636 "Customization of the `printing' group."
4637 (interactive)
4638 (customize-group 'printing))
4641 ;;;###autoload
4642 (defun lpr-customize (&rest _ignore)
4643 "Customization of the `lpr' group."
4644 (interactive)
4645 (customize-group 'lpr))
4648 ;;;###autoload
4649 (defun pr-help (&rest _ignore)
4650 "Help for the printing package."
4651 (interactive)
4652 (pr-show-setup pr-help-message "*Printing Help*"))
4655 ;;;###autoload
4656 (defun pr-ps-name ()
4657 "Interactively select a PostScript printer."
4658 (interactive)
4659 (pr-menu-set-ps-title
4660 (pr-complete-alist "PostScript printer"
4661 pr-ps-printer-alist pr-ps-name)))
4664 ;;;###autoload
4665 (defun pr-txt-name ()
4666 "Interactively select a text printer."
4667 (interactive)
4668 (pr-menu-set-txt-title
4669 (pr-complete-alist "Text printer"
4670 pr-txt-printer-alist pr-txt-name)))
4673 ;;;###autoload
4674 (defun pr-ps-utility ()
4675 "Interactively select a PostScript utility."
4676 (interactive)
4677 (pr-menu-set-utility-title
4678 (pr-complete-alist "PostScript utility"
4679 pr-ps-utility-alist pr-ps-utility)))
4682 ;;;###autoload
4683 (defun pr-show-ps-setup (&rest _ignore)
4684 "Show current ps-print settings."
4685 (interactive)
4686 (pr-show-setup (ps-setup) "*PS Setup*"))
4689 ;;;###autoload
4690 (defun pr-show-pr-setup (&rest _ignore)
4691 "Show current printing settings."
4692 (interactive)
4693 (pr-show-setup (pr-setup) "*PR Setup*"))
4696 ;;;###autoload
4697 (defun pr-show-lpr-setup (&rest _ignore)
4698 "Show current lpr settings."
4699 (interactive)
4700 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4703 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4704 ;; Fast Commands
4707 ;;;###autoload
4708 (defun pr-ps-fast-fire (n-up &optional select)
4709 "Fast fire function for PostScript printing.
4711 If a region is active, the region will be printed instead of the whole buffer.
4712 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4713 `pr-mode-alist' will be used, that is, the current buffer or region will be
4714 printed using `pr-ps-mode-ps-print'.
4717 Interactively, you have the following situations:
4719 M-x pr-ps-fast-fire RET
4720 The command prompts the user for a N-UP value and printing will
4721 immediately be done using the current active printer.
4723 C-u M-x pr-ps-fast-fire RET
4724 C-u 0 M-x pr-ps-fast-fire RET
4725 The command prompts the user for a N-UP value and also for a current
4726 PostScript printer, then printing will immediately be done using the new
4727 current active printer.
4729 C-u 1 M-x pr-ps-fast-fire RET
4730 The command prompts the user for a N-UP value and also for a file name,
4731 and saves the PostScript image in that file instead of sending it to the
4732 printer.
4734 C-u 2 M-x pr-ps-fast-fire RET
4735 The command prompts the user for a N-UP value, then for a current
4736 PostScript printer and, finally, for a file name. Then change the active
4737 printer to that chosen by user and saves the PostScript image in
4738 that file instead of sending it to the printer.
4741 Noninteractively, the argument N-UP should be a positive integer greater than
4742 zero and the argument SELECT is treated as follows:
4744 If it's nil, send the image to the printer.
4746 If it's a list or an integer lesser or equal to zero, the command prompts
4747 the user for a current PostScript printer, then printing will immediately
4748 be done using the new current active printer.
4750 If it's an integer equal to 1, the command prompts the user for a file name
4751 and saves the PostScript image in that file instead of sending it to the
4752 printer.
4754 If it's an integer greater or equal to 2, the command prompts the user for a
4755 current PostScript printer and for a file name. Then change the active
4756 printer to that chosen by user and saves the PostScript image in that file
4757 instead of sending it to the printer.
4759 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4760 active printer and printing will immediately be done using the new active
4761 printer.
4763 Otherwise, send the image to the printer.
4766 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4767 are both set to t."
4768 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4769 current-prefix-arg))
4770 (let ((pr-auto-region t)
4771 (pr-auto-mode t)
4772 filename)
4773 (cond ((null select))
4774 ((listp select)
4775 (pr-ps-name))
4776 ((and (symbolp select)
4777 (assq select pr-ps-printer-alist))
4778 (pr-menu-set-ps-title select))
4779 ((integerp select)
4780 (and (/= select 1)
4781 (pr-ps-name))
4782 (and (>= select 1) (not pr-spool-p)
4783 (setq filename (pr-ps-outfile-preprint
4784 (if pr-print-using-ghostscript
4785 "Fast GS "
4786 "Fast "))))))
4787 (pr-ps-buffer-ps-print
4788 (if (integerp n-up)
4789 (min (max n-up 1) 100)
4790 (error "n-up must be an integer greater than zero"))
4791 filename)))
4794 ;;;###autoload
4795 (defun pr-txt-fast-fire (&optional select-printer)
4796 "Fast fire function for text printing.
4798 If a region is active, the region will be printed instead of the whole buffer.
4799 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4800 `pr-mode-alist' will be used, that is, the current buffer or region will be
4801 printed using `pr-txt-mode'.
4803 Interactively, when you use a prefix argument (C-u), the command prompts the
4804 user for a new active text printer.
4806 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4808 If it's nil, the printing is sent to the current active text printer.
4810 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4811 active printer and printing will immediately be done using the new active
4812 printer.
4814 If it's non-nil, the command prompts the user for a new active text printer.
4816 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4817 are both set to t."
4818 (interactive (list current-prefix-arg))
4819 (cond ((null select-printer))
4820 ((and (symbolp select-printer)
4821 (assq select-printer pr-txt-printer-alist))
4822 (pr-menu-set-txt-title select-printer))
4824 (pr-txt-name)))
4825 (let ((pr-auto-region t)
4826 (pr-auto-mode t))
4827 (pr-txt-buffer)))
4830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4831 ;; Utilities
4834 (defun pr-setup ()
4835 "Return the current `printing' setup.
4837 This is *not* an interactive command.
4838 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4840 M-: (insert (pr-setup)) RET
4842 Or choose the menu option Printing/Show Settings/printing."
4843 (let (ps-prefix-quote)
4844 (mapconcat
4845 #'ps-print-quote
4846 (list
4847 (concat "\n;;; printing.el version " pr-version "\n")
4848 ";; internal vars"
4849 (ps-comment-string "emacs-version " emacs-version)
4850 (ps-comment-string "pr-txt-command " pr-txt-command)
4851 (ps-comment-string "pr-txt-switches "
4852 (pr-switches-string pr-txt-switches "pr-txt-switches"))
4853 (ps-comment-string "pr-txt-printer " pr-txt-printer)
4854 (ps-comment-string "pr-ps-command " pr-ps-command)
4855 (ps-comment-string "pr-ps-switches "
4856 (pr-switches-string pr-ps-switches "pr-ps-switches"))
4857 (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
4858 (ps-comment-string "pr-ps-printer " pr-ps-printer)
4859 (ps-comment-string "pr-cygwin-system " pr-cygwin-system)
4860 (ps-comment-string "lpr-windows-system " lpr-windows-system)
4861 (ps-comment-string "lpr-lp-system " lpr-lp-system)
4863 '(14 . pr-path-style)
4864 '(14 . pr-path-alist)
4866 '(21 . pr-txt-name)
4867 '(21 . pr-txt-printer-alist)
4869 '(20 . pr-ps-name)
4870 '(20 . pr-ps-printer-alist)
4872 '(20 . pr-temp-dir)
4873 '(20 . pr-ps-temp-file)
4874 '(20 . pr-file-modes)
4875 '(20 . pr-delete-temp-file)
4876 '(20 . pr-list-directory)
4878 '(17 . pr-gv-command)
4879 '(17 . pr-gs-command)
4880 '(17 . pr-gs-switches)
4881 '(17 . pr-gs-device)
4882 '(17 . pr-gs-resolution)
4884 '(27 . pr-print-using-ghostscript)
4885 '(27 . pr-faces-p)
4886 '(27 . pr-spool-p)
4887 '(27 . pr-file-landscape)
4888 '(27 . pr-file-duplex)
4889 '(27 . pr-file-tumble)
4890 '(27 . pr-auto-region)
4891 '(27 . pr-auto-mode)
4893 '(20 . pr-ps-utility)
4894 '(20 . pr-ps-utility-alist)
4896 '(14 . pr-mode-alist)
4898 '(20 . pr-menu-lock)
4899 '(20 . pr-menu-char-height)
4900 '(20 . pr-menu-char-width)
4902 '(20 . pr-setting-database)
4904 '(22 . pr-visible-entry-list)
4906 '(22 . pr-buffer-verbose)
4907 '(22 . pr-buffer-name)
4908 '(22 . pr-buffer-name-ignore)
4909 ")\n\n;;; printing.el - end of settings\n")
4910 "\n")))
4913 (defun lpr-setup ()
4914 "Return the current `lpr' setup.
4916 This is *not* an interactive command.
4917 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4919 M-: (insert (lpr-setup)) RET
4921 Or choose the menu option Printing/Show Settings/lpr."
4922 (let (ps-prefix-quote)
4923 (mapconcat
4924 #'ps-print-quote
4925 (list
4926 "\n;;; lpr.el settings\n"
4927 (ps-comment-string "emacs-version" emacs-version)
4929 '(25 . printer-name)
4930 '(25 . lpr-switches)
4931 '(25 . lpr-add-switches)
4932 '(25 . lpr-command)
4933 '(25 . lpr-headers-switches)
4934 '(25 . print-region-function)
4935 '(25 . lpr-page-header-program)
4936 '(25 . lpr-page-header-switches)
4937 ")\n\n;;; lpr.el - end of settings\n")
4938 "\n")))
4941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4942 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4944 (declare-function mh-get-msg-num "mh-utils" (error-if-no-message))
4945 (declare-function mh-show "mh-show" (&optional message redisplay-flag))
4946 (declare-function mh-start-of-uncleaned-message "mh-show" ())
4947 (defvar mh-show-buffer)
4950 (defun pr-article-date ()
4951 "Find the date of an article or mail message in current buffer.
4952 Return only the dayname, if present, weekday, month, and year."
4953 (save-excursion
4954 (goto-char (point-min))
4955 (if (re-search-forward
4956 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4957 (buffer-substring (match-beginning 1) (match-end 1))
4958 (format-time-string "%Y/%m/%d"))))
4961 (defun pr-mh-current-message ()
4962 "Go to mh-inbox current message."
4963 (let ((msg (or (mh-get-msg-num nil) 0)))
4964 (mh-show)
4965 (set-buffer mh-show-buffer)
4966 (goto-char (point-min))
4967 (mh-start-of-uncleaned-message)
4968 (message "Printing message %d" msg)))
4971 (defun pr-mh-print-1 (n-up filename header-list)
4972 "Print mh-inbox current message in PostScript."
4973 (save-excursion
4974 (save-window-excursion
4975 (pr-mh-current-message)
4976 (pr-mode-print n-up filename header-list (point)))))
4979 (defun pr-mh-lpr-1 (header-list)
4980 "Print mh-inbox current message in text printer."
4981 (save-excursion
4982 (save-window-excursion
4983 (pr-mh-current-message)
4984 (pr-mode-lpr header-list (point)))))
4987 (defalias 'pr-mh-print-2 'pr-mode-print)
4990 (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
4993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4994 ;; rmail (hacked from ps-print.el)
4997 (defun pr-rmail-lpr (header-list)
4998 "Print RMAIL current message in text printer."
4999 (pr-lpr-message-from-summary header-list
5000 'rmail-buffer 'rmail-summary-buffer))
5003 (defun pr-rmail-print (n-up filename header-list)
5004 "Print RMAIL current message in PostScript."
5005 (pr-ps-message-from-summary n-up filename header-list
5006 'rmail-buffer 'rmail-summary-buffer))
5009 (defun pr-ps-message-from-summary (n-up filename header-list
5010 summary-buffer summary-default)
5011 "Print current message in PostScript."
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-print n-up filename header-list)))))
5020 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
5021 "Print current message in text printer."
5022 (let ((buf (or (and (boundp summary-buffer)
5023 (symbol-value summary-buffer))
5024 (symbol-value summary-default))))
5025 (and (get-buffer buf)
5026 (with-current-buffer buf
5027 (pr-mode-lpr header-list)))))
5030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5031 ;; gnus (hacked from ps-print.el)
5034 (defvar pr-gnus-article "*Article*")
5037 (defun pr-gnus-print (n-up filename header-list)
5038 "Print *Article* current message in PostScript."
5039 (pr-ps-message-from-summary n-up filename header-list
5040 'gnus-article-buffer 'pr-gnus-article))
5043 (defun pr-gnus-lpr (header-list)
5044 "Print *Article* current message in text printer."
5045 (pr-lpr-message-from-summary header-list
5046 'gnus-article-buffer 'pr-gnus-article))
5049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5050 ;; vm (hacked from ps-print.el)
5053 (defvar pr-vm-summary "")
5056 (defun pr-vm-print (n-up filename header-list)
5057 "Print current vm message in PostScript."
5058 (pr-ps-message-from-summary n-up filename header-list
5059 'vm-mail-buffer 'pr-vm-summary))
5062 (defun pr-vm-lpr (header-list)
5063 "Print current vm message in text printer."
5064 (pr-lpr-message-from-summary header-list
5065 'vm-mail-buffer 'pr-vm-summary))
5068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5069 ;; Mode Functions
5072 (defun pr-ps-mode (n-up filename)
5073 "If current major mode is declared, print it in PostScript."
5074 (let ((args (pr-mode-alist-p)))
5075 (if args
5076 (let ((fun (cdr args)))
5077 (funcall (car fun) n-up filename (cdr fun))
5079 (ding)
5080 (message "`%s' major mode not declared." major-mode)
5081 nil)))
5084 (defmacro pr-local-variable (header-list &rest body)
5085 `(save-excursion
5086 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
5087 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
5088 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
5089 ps-razzle-dazzle)
5090 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
5091 ,@body
5092 (and (nth 3 ,header-list)
5093 (pr-kill-local-variable local-var-list))))))
5096 (defun pr-mode-print (n-up filename header-list &optional from to)
5097 "Print current major mode in PostScript."
5098 (pr-local-variable
5099 header-list
5100 (let ((file (pr-ps-file filename))
5101 (start (cond (from)
5102 ((pr-region-active-p) (region-beginning))
5103 (t nil)
5105 (pr-text2ps (pr-region-active-symbol start) n-up file start
5106 (cond (to)
5107 ((pr-region-active-p) (region-end))
5108 (from (point-max))
5110 (unless (or pr-spool-p filename)
5111 (pr-ps-file-print file)
5112 (pr-delete-file file)))))
5115 (defun pr-mode-lpr (header-list &optional from to)
5116 "Print current major mode in text printer."
5117 (pr-local-variable
5118 header-list
5119 (pr-txt-print (cond (from)
5120 ((pr-region-active-p) (region-beginning))
5121 (t (point-min)))
5122 (cond (to)
5123 ((pr-region-active-p) (region-end))
5124 (t (point-max))))))
5127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5128 ;; Menu Lock
5131 (defconst pr-menu-entry-alist
5132 '((postscript . 3)
5133 (text . 3)
5134 (postscript-options . 9)
5135 (postscript-process . 3)
5136 (printing . 3)
5137 (help . 3)
5139 "Alist that associates menu part with number of items per part.
5141 It's used by `pr-menu-index'.
5143 Each element has the form:
5145 (MENU-PART . NUMBER-OF-ITEMS)
5147 See `pr-visible-entry-alist'.")
5150 (defun pr-menu-index (entry index)
5151 (let ((base-list
5152 (cond ((eq entry 'text)
5153 '(postscript))
5154 ((eq entry 'postscript-options)
5155 '(postscript text))
5156 ((eq entry 'postscript-process)
5157 '(postscript text postscript-options))
5158 ((eq entry 'printing)
5159 '(postscript text postscript-options postscript-process))
5161 nil)
5163 key)
5164 (while base-list
5165 (setq key (car base-list)
5166 base-list (cdr base-list))
5167 (and (pr-visible-p key)
5168 (setq index (+ index
5169 (cdr (assq key pr-menu-entry-alist)))))))
5170 (+ index 2))
5173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5174 ;; Printer & Utility Selection
5177 (defun pr-update-var (var-sym alist)
5178 (or (assq (symbol-value var-sym) alist)
5179 (set var-sym (car (car alist)))))
5182 (defun pr-update-menus (&optional force)
5183 "Update utility, PostScript and text printer menus.
5185 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
5186 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
5187 otherwise, update PostScript printer menu if `pr-ps-printer-menu-modified' is
5188 non-nil, update text printer menu if `pr-txt-printer-menu-modified' is
5189 non-nil, and update PostScript File menus if `pr-ps-utility-menu-modified' is
5190 non-nil.
5192 If menu binding was not done, calls `pr-menu-bind'."
5193 (interactive "P")
5194 (if pr-menu-print-item ; since v6.8.4
5195 ;; There was no menu binding yet, so do it now!
5196 ;; This is a hack to be compatible with old versions of printing.
5197 ;; So, user does not need to change printing calling in init files.
5198 (pr-menu-bind)
5199 ;; Here menu binding is ok.
5200 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
5201 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
5202 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
5203 (pr-do-update-menus force)))
5206 (defun pr-menu-create (name alist var-sym fun entry index)
5207 (cons name
5208 (mapcar
5209 #'(lambda (elt)
5210 (let ((sym (car elt)))
5211 (vector
5212 (symbol-name sym)
5213 (list fun (list 'quote sym) nil (list 'quote entry) index)
5214 :style 'radio
5215 :selected (list 'eq var-sym (list 'quote sym)))))
5216 alist)))
5219 (defun pr-ps-set-utility (value)
5220 (let ((item (cdr (assq value pr-ps-utility-alist))))
5221 (or item
5222 (error
5223 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
5224 value))
5225 (setq pr-ps-utility value)
5226 (pr-eval-alist (nthcdr 9 item)))
5227 (pr-update-mode-line))
5230 (defun pr-ps-set-printer (value)
5231 (let ((ps (cdr (assq value pr-ps-printer-alist))))
5232 (or ps
5233 (error
5234 "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
5235 value))
5236 (setq pr-ps-name value
5237 pr-ps-command (pr-dosify-file-name (nth 0 ps))
5238 pr-ps-switches (nth 1 ps)
5239 pr-ps-printer-switch (nth 2 ps)
5240 pr-ps-printer (nth 3 ps))
5241 (or (stringp pr-ps-command)
5242 (setq pr-ps-command
5243 (cond (lpr-windows-system "print")
5244 (lpr-lp-system "lp")
5245 (t "lpr")
5247 (or (stringp pr-ps-printer-switch)
5248 (setq pr-ps-printer-switch
5249 (cond (lpr-windows-system "/D:")
5250 (lpr-lp-system "-d")
5251 (t "-P")
5253 (pr-eval-alist (nthcdr 4 ps)))
5254 (pr-update-mode-line))
5257 (defun pr-txt-set-printer (value)
5258 (let ((txt (cdr (assq value pr-txt-printer-alist))))
5259 (or txt
5260 (error "Invalid text printer name `%s' for variable `pr-txt-name'"
5261 value))
5262 (setq pr-txt-name value
5263 pr-txt-command (pr-dosify-file-name (nth 0 txt))
5264 pr-txt-switches (nth 1 txt)
5265 pr-txt-printer (nth 2 txt)))
5266 (or (stringp pr-txt-command)
5267 (setq pr-txt-command
5268 (cond (lpr-windows-system "print")
5269 (lpr-lp-system "lp")
5270 (t "lpr")
5272 (pr-update-mode-line))
5275 (defun pr-eval-alist (alist)
5276 (mapcar #'(lambda (option)
5277 (let ((var-sym (car option))
5278 (value (cdr option)))
5279 (if (eq var-sym 'inherits-from:)
5280 (pr-eval-setting-alist value 'global)
5281 (set var-sym (eval value)))))
5282 alist))
5285 (defun pr-eval-local-alist (alist)
5286 (let (local-list)
5287 (mapc #'(lambda (option)
5288 (let ((var-sym (car option))
5289 (value (cdr option)))
5290 (setq local-list
5291 (if (eq var-sym 'inherits-from:)
5292 (nconc (pr-eval-setting-alist value) local-list)
5293 (set (make-local-variable var-sym) (eval value))
5294 (cons var-sym local-list)))))
5295 alist)
5296 local-list))
5299 (defun pr-eval-setting-alist (key &optional global old)
5300 (let ((setting (cdr (assq key pr-setting-database))))
5301 (and setting
5302 (let ((inherits (nth 0 setting))
5303 (local (nth 1 setting))
5304 (kill (nth 2 setting))
5305 local-list)
5306 (and local global
5307 (progn
5308 (ding)
5309 (message "There are local buffer settings for `%S'." key)
5310 (setq global nil)))
5311 (and inherits
5312 (if (memq inherits old)
5313 (error "Circular inheritance for `%S'" inherits)
5314 (setq local-list
5315 (pr-eval-setting-alist inherits global
5316 (cons inherits old)))))
5317 (mapc
5318 (cond ((not local) ; global settings
5319 #'(lambda (option)
5320 (let ((var-sym (car option)))
5321 (or (eq var-sym 'inherits-from:)
5322 (set var-sym (eval (cdr option)))))))
5323 (kill ; local settings with killing
5324 #'(lambda (option)
5325 (let ((var-sym (car option)))
5326 (unless (eq var-sym 'inherits-from:)
5327 (setq local-list (cons var-sym local-list))
5328 (set (make-local-variable var-sym)
5329 (eval (cdr option)))))))
5330 (t ; local settings without killing
5331 #'(lambda (option)
5332 (let ((var-sym (car option)))
5333 (or (eq var-sym 'inherits-from:)
5334 (set (make-local-variable var-sym)
5335 (eval (cdr option))))))))
5336 (nthcdr 3 setting))
5337 local-list))))
5340 (defun pr-kill-local-variable (local-var-list)
5341 (mapcar 'kill-local-variable local-var-list))
5344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5345 ;; Internal Functions (II)
5348 (defun pr-toggle (var-sym mess entry index horizontal state
5349 &optional path no-menu)
5350 (set var-sym (not (symbol-value var-sym)))
5351 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5352 (or no-menu
5353 (pr-menu-lock entry index horizontal state path)))
5356 (defun pr-toggle-file-duplex-menu (&optional no-menu)
5357 "Toggle whether to print PostScript files in duplex mode."
5358 (interactive)
5359 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
5360 '("PostScript Print" "File") no-menu))
5363 (defun pr-toggle-file-tumble-menu (&optional no-menu)
5364 "Toggle whether to print PostScript files in tumble mode."
5365 (interactive)
5366 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
5367 '("PostScript Print" "File") no-menu))
5370 (defun pr-toggle-file-landscape-menu (&optional no-menu)
5371 "Toggle whether to print PostScript files in landscape orientation."
5372 (interactive)
5373 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
5374 '("PostScript Print" "File") no-menu))
5377 (defun pr-toggle-ghostscript-menu (&optional no-menu)
5378 "Toggle whether to print using ghostscript."
5379 (interactive)
5380 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
5381 'postscript-process 2 12 'toggle nil no-menu))
5384 (defun pr-toggle-faces-menu (&optional no-menu)
5385 "Toggle whether to print with face attributes."
5386 (interactive)
5387 (pr-toggle 'pr-faces-p "Printing with faces"
5388 'postscript-process 1 12 'toggle nil no-menu))
5391 (defun pr-toggle-spool-menu (&optional no-menu)
5392 "Toggle whether to spool printing in a buffer."
5393 (interactive)
5394 (pr-toggle 'pr-spool-p "Spooling printing"
5395 'postscript-process 0 12 'toggle nil no-menu))
5398 (defun pr-toggle-duplex-menu (&optional no-menu)
5399 "Toggle whether to generate PostScript for a two-sided printer."
5400 (interactive)
5401 (pr-toggle 'ps-spool-duplex "Printing duplex"
5402 'postscript-options 5 12 'toggle nil no-menu))
5405 (defun pr-toggle-tumble-menu (&optional no-menu)
5406 "Toggle how pages on opposite sides of a sheet are oriented."
5407 (interactive)
5408 (pr-toggle 'ps-spool-tumble "Tumble"
5409 'postscript-options 6 12 'toggle nil no-menu))
5412 (defun pr-toggle-landscape-menu (&optional no-menu)
5413 "Toggle whether to print in landscape mode."
5414 (interactive)
5415 (pr-toggle 'ps-landscape-mode "Landscape"
5416 'postscript-options 0 12 'toggle nil no-menu))
5419 (defun pr-toggle-upside-down-menu (&optional no-menu)
5420 "Toggle whether to print upside-down (that is, rotated by 180 degrees)."
5421 (interactive)
5422 (pr-toggle 'ps-print-upside-down "Upside-Down"
5423 'postscript-options 7 12 'toggle nil no-menu))
5426 (defun pr-toggle-line-menu (&optional no-menu)
5427 "Toggle whether to means print line numbers."
5428 (interactive)
5429 (pr-toggle 'ps-line-number "Line number"
5430 'postscript-options 3 12 'toggle nil no-menu))
5433 (defun pr-toggle-zebra-menu (&optional no-menu)
5434 "Toggle whether to print zebra stripes."
5435 (interactive)
5436 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
5437 'postscript-options 4 12 'toggle nil no-menu))
5440 (defun pr-toggle-header-menu (&optional no-menu)
5441 "Toggle whether to print a header at the top of each page."
5442 (interactive)
5443 (pr-toggle 'ps-print-header "Print header"
5444 'postscript-options 1 12 'toggle nil no-menu))
5447 (defun pr-toggle-header-frame-menu (&optional no-menu)
5448 "Toggle whether to draw a gaudy frame around the header."
5449 (interactive)
5450 (pr-toggle 'ps-print-header-frame "Print header frame"
5451 'postscript-options 2 12 'toggle nil no-menu))
5454 (defun pr-toggle-lock-menu (&optional no-menu)
5455 "Toggle whether the menu is locked while selecting toggle options."
5456 (interactive)
5457 (pr-toggle 'pr-menu-lock "Menu lock"
5458 'printing 2 12 'toggle nil no-menu))
5461 (defun pr-toggle-region-menu (&optional no-menu)
5462 "Toggle whether the region is automagically detected."
5463 (interactive)
5464 (pr-toggle 'pr-auto-region "Auto region"
5465 'printing 0 12 'toggle nil no-menu))
5468 (defun pr-toggle-mode-menu (&optional no-menu)
5469 "Toggle whether major-mode specific printing is preferred over normal printing."
5470 (interactive)
5471 (pr-toggle 'pr-auto-mode "Auto mode"
5472 'printing 1 12 'toggle nil no-menu))
5475 (defun pr-prompt (str)
5476 (if (pr-auto-mode-p)
5477 (concat str " mode")
5478 (pr-region-active-string str)))
5481 (defun pr-prompt-region (str)
5482 (concat str (if (pr-auto-mode-p)
5483 " mode"
5484 " region")))
5487 (defun pr-prompt-gs (str)
5488 (if (pr-using-ghostscript-p)
5489 (concat str " GS")
5490 str))
5493 (defun pr-region-active-symbol (&optional region-p)
5494 (if (or region-p (pr-region-active-p))
5495 'region
5496 'buffer))
5499 (defun pr-region-active-string (prefix)
5500 (concat prefix
5501 (if (pr-region-active-p)
5502 " region"
5503 " buffer")))
5506 (defun pr-show-setup (settings buffer-name)
5507 (with-output-to-temp-buffer buffer-name
5508 (princ settings)
5509 (help-print-return-message)))
5512 (defun pr-complete-alist (prompt alist default)
5513 (let ((collection (mapcar #'(lambda (elt)
5514 (setq elt (car elt))
5515 (cons (symbol-name elt) elt))
5516 alist)))
5517 (cdr (assoc (completing-read (concat prompt ": ")
5518 collection nil t
5519 (symbol-name default) nil
5520 (symbol-name default))
5521 collection))))
5524 (defun pr-delete-file (file)
5525 (and pr-delete-temp-file (file-exists-p file)
5526 (delete-file file)))
5529 (defun pr-expand-file-name (filename)
5530 (pr-dosify-file-name (expand-file-name filename)))
5533 (defun pr-ps-outfile-preprint (&optional mess)
5534 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5535 (res (read-file-name prompt default-directory "" nil)))
5536 (while (cond ((not (file-writable-p res))
5537 (ding)
5538 (setq prompt "is unwritable"))
5539 ((file-directory-p res)
5540 (ding)
5541 (setq prompt "is a directory"))
5542 ((file-exists-p res)
5543 (ding)
5544 (setq prompt "exists")
5545 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5546 res))))
5547 (t nil))
5548 (setq res (read-file-name
5549 (format "File %s; PostScript file: " prompt)
5550 (file-name-directory res) nil nil
5551 (file-name-nondirectory res))))
5552 (pr-expand-file-name res)))
5555 (defun pr-ps-infile-preprint (&optional mess)
5556 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5557 (res (read-file-name prompt default-directory "" nil)))
5558 (while (cond ((not (file-exists-p res))
5559 (ding)
5560 (setq prompt "doesn't exist"))
5561 ((not (file-readable-p res))
5562 (ding)
5563 (setq prompt "is unreadable"))
5564 ((file-directory-p res)
5565 (ding)
5566 (setq prompt "is a directory"))
5567 (t nil))
5568 (setq res (read-file-name
5569 (format "File %s; PostScript file: " prompt)
5570 (file-name-directory res) nil nil
5571 (file-name-nondirectory res))))
5572 (pr-expand-file-name res)))
5575 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
5576 ;; check arguments for PostScript file processing.
5577 ;; n-up
5578 (or (symbol-value n-up-sym)
5579 (set n-up-sym (pr-interactive-n-up prompt)))
5580 ;; input file
5581 (and (eq (symbol-value infile-sym) t)
5582 (set infile-sym (pr-ps-infile-preprint prompt)))
5583 (or (symbol-value infile-sym)
5584 (error "%s: input PostScript file name is missing" prompt))
5585 (set infile-sym (pr-dosify-file-name (symbol-value infile-sym)))
5586 ;; output file
5587 (and (eq (symbol-value outfile-sym) t)
5588 (set outfile-sym (and current-prefix-arg
5589 (pr-ps-outfile-preprint prompt))))
5590 (and (symbol-value outfile-sym)
5591 (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym))))
5592 (pr-ps-file (symbol-value outfile-sym)))
5595 (defun pr-ps-utility-process (n-up infile outfile)
5596 ;; activate utility to process a PostScript file.
5597 (let (item)
5598 (and (stringp infile) (file-exists-p infile)
5599 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
5600 (pr-call-process (nth 0 item)
5601 (pr-switches-string (nth 1 item)
5602 "pr-ps-utility-alist entry")
5603 (pr-switches-string (nth 8 item)
5604 "pr-ps-utility-alist entry")
5605 (and (nth 2 item)
5606 (format (nth 2 item) ps-paper-type))
5607 (format (nth 3 item) n-up)
5608 (and pr-file-landscape (nth 4 item))
5609 (and pr-file-duplex (nth 5 item))
5610 (and pr-file-tumble (nth 6 item))
5611 (pr-expand-file-name infile)
5612 (nth 7 item)
5613 (pr-expand-file-name outfile)))))
5616 (defun pr-remove-nil-from-list (lst)
5617 (while (and lst (null (car lst)))
5618 (setq lst (cdr lst)))
5619 (let ((b lst)
5620 (l (cdr lst)))
5621 (while l
5622 (if (car l)
5623 (setq b l
5624 l (cdr l))
5625 (setq l (cdr l))
5626 (setcdr b l))))
5627 lst)
5630 (defun pr-call-process (command &rest args)
5631 (let ((buffer (get-buffer-create "*Printing Command Output*"))
5632 (cmd (pr-command command))
5633 status)
5634 (setq args (pr-remove-nil-from-list args))
5635 ;; *Printing Command Output* == show command & args
5636 (with-current-buffer buffer
5637 (goto-char (point-max))
5638 (insert (format "%s %S\n" cmd args)))
5639 ;; *Printing Command Output* == show any return message from command
5640 (with-file-modes pr-file-modes
5641 (setq status
5642 (condition-case data
5643 (apply 'call-process cmd nil buffer nil args)
5644 ((quit error)
5645 (error-message-string data)))))
5646 ;; *Printing Command Output* == show exit status
5647 (with-current-buffer buffer
5648 (goto-char (point-max))
5649 (insert (format "Exit status: %s\n\n" status)))
5650 ;; message if error status
5651 (if (or (stringp status)
5652 (and (integerp status) (/= status 0)))
5653 (message
5654 "Printing error status: %s (see *Printing Command Output* buffer)"
5655 status))))
5658 (defun pr-txt-print (from to)
5659 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command)))
5660 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5661 (printer-name pr-txt-printer))
5662 (lpr-region from to)))
5665 (defun pr-switches-string (switches mess)
5666 ;; If SWITCHES is nil, return nil.
5667 ;; Otherwise, return the list of string in a string.
5668 (and switches
5669 (mapconcat 'identity (pr-switches switches mess) " ")))
5672 (defun pr-switches (switches mess)
5673 (or (listp switches)
5674 (error "%S should have a list of strings" mess))
5675 (lpr-flatten-list ; dynamic evaluation
5676 (mapcar 'ps-eval-switch switches)))
5679 (defun pr-ps-preview (kind n-up filename mess)
5680 (pr-set-n-up-and-filename 'n-up 'filename mess)
5681 (let ((file (pr-ps-file filename)))
5682 (pr-text2ps kind n-up file)
5683 (or pr-spool-p (pr-ps-file-preview file))))
5686 (defun pr-ps-using-ghostscript (kind n-up filename mess)
5687 (pr-set-n-up-and-filename 'n-up 'filename mess)
5688 (let ((file (pr-ps-file filename)))
5689 (pr-text2ps kind n-up file)
5690 (unless (or pr-spool-p filename)
5691 (pr-ps-file-using-ghostscript file)
5692 (pr-delete-file file))))
5695 (defun pr-ps-print (kind n-up filename mess)
5696 (pr-set-n-up-and-filename 'n-up 'filename mess)
5697 (let ((file (pr-ps-file filename)))
5698 (pr-text2ps kind n-up file)
5699 (unless (or pr-spool-p filename)
5700 (pr-ps-file-print file)
5701 (pr-delete-file file))))
5704 (defun pr-ps-file (&optional filename)
5705 (pr-dosify-file-name (or filename
5706 (make-temp-file
5707 (convert-standard-filename
5708 (expand-file-name pr-ps-temp-file pr-temp-dir))
5709 nil ".ps"))))
5712 (defun pr-interactive-n-up (mess)
5713 (or (stringp mess) (setq mess "*"))
5714 (save-match-data
5715 (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
5716 (prompt "")
5717 (str (pr-read-string (format fmt-prompt prompt mess) "1" nil "1"))
5718 int)
5719 (while (if (string-match "^\\s *[0-9]+$" str)
5720 (setq int (string-to-number str)
5721 prompt (cond ((< int 1) "Integer below 1; ")
5722 ((> int 100) "Integer above 100; ")
5723 (t nil)))
5724 (setq prompt "Invalid integer syntax; "))
5725 (ding)
5726 (setq str
5727 (pr-read-string (format fmt-prompt prompt mess) str nil "1")))
5728 int)))
5731 (defun pr-interactive-dir (mess)
5732 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5733 default-directory)))
5734 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
5735 (dir (read-directory-name (format fmt-prompt "")
5736 "" dir-name nil dir-name))
5737 prompt)
5738 (while (cond ((not (file-directory-p dir))
5739 (ding)
5740 (setq prompt "It's not a directory! "))
5741 ((not (file-readable-p dir))
5742 (ding)
5743 (setq prompt "Directory is unreadable! "))
5744 (t nil))
5745 (setq dir-name (file-name-directory dir)
5746 dir (read-directory-name (format fmt-prompt prompt)
5747 "" dir-name nil dir-name)))
5748 (file-name-as-directory dir)))
5751 (defun pr-interactive-regexp (mess)
5752 (pr-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
5755 (defun pr-interactive-dir-args (mess)
5756 (list
5757 ;; get directory argument
5758 (pr-interactive-dir mess)
5759 ;; get file name regexp
5760 (pr-interactive-regexp mess)))
5763 (defun pr-interactive-ps-dir-args (mess)
5764 (list
5765 ;; get n-up argument
5766 (pr-interactive-n-up mess)
5767 ;; get directory argument
5768 (pr-interactive-dir mess)
5769 ;; get file name regexp
5770 (pr-interactive-regexp mess)
5771 ;; get output file name
5772 (and (not pr-spool-p)
5773 (ps-print-preprint current-prefix-arg))))
5776 (defun pr-interactive-n-up-file (mess)
5777 (list
5778 ;; get n-up argument
5779 (pr-interactive-n-up mess)
5780 ;; get output file name
5781 (and (not pr-spool-p)
5782 (ps-print-preprint current-prefix-arg))))
5785 (defun pr-interactive-n-up-inout (mess)
5786 (list
5787 ;; get n-up argument
5788 (pr-interactive-n-up mess)
5789 ;; get input file name
5790 (pr-ps-infile-preprint (concat mess " "))
5791 ;; get output file name
5792 (ps-print-preprint current-prefix-arg)))
5795 (defun pr-set-outfilename (filename-sym)
5796 (and (not pr-spool-p)
5797 (eq (symbol-value filename-sym) t)
5798 (set filename-sym (and current-prefix-arg
5799 (ps-print-preprint current-prefix-arg))))
5800 (and (symbol-value filename-sym)
5801 (set filename-sym (pr-dosify-file-name (symbol-value filename-sym)))))
5804 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5805 ;; n-up
5806 (or (symbol-value n-up-sym)
5807 (set n-up-sym (pr-interactive-n-up mess)))
5808 ;; output file
5809 (pr-set-outfilename filename-sym))
5812 (defun pr-set-dir-args (dir-sym regexp-sym mess)
5813 ;; directory
5814 (or (symbol-value dir-sym)
5815 (set dir-sym (pr-interactive-dir mess)))
5816 ;; file name regexp
5817 (or (symbol-value regexp-sym)
5818 (set regexp-sym (pr-interactive-regexp mess))))
5821 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5822 ;; n-up
5823 (or (symbol-value n-up-sym)
5824 (set n-up-sym (pr-interactive-n-up mess)))
5825 ;; directory & file name regexp
5826 (pr-set-dir-args dir-sym regexp-sym mess)
5827 ;; output file
5828 (pr-set-outfilename filename-sym))
5831 (defun pr-find-buffer-visiting (file)
5832 (if (not (file-directory-p file))
5833 (find-buffer-visiting (if lpr-windows-system
5834 (downcase file)
5835 file))
5836 (let ((truename (file-truename file))
5837 (blist (buffer-list))
5838 found)
5839 (while (and (not found) blist)
5840 (with-current-buffer (car blist)
5841 (and (eq major-mode 'dired-mode)
5842 (save-excursion
5843 (goto-char (point-min))
5844 (string= (buffer-substring-no-properties
5845 (+ (point-min) 2)
5846 (progn
5847 (end-of-line)
5848 (1- (point))))
5849 truename))
5850 (setq found (car blist))))
5851 (setq blist (cdr blist)))
5852 found)))
5855 (defun pr-file-list (dir file-regexp fun)
5856 (mapcar #'(lambda (file)
5857 (and (or pr-list-directory
5858 (not (file-directory-p file)))
5859 (let ((buffer (pr-find-buffer-visiting file))
5860 pop-up-windows
5861 pop-up-frames)
5862 (and (or buffer
5863 (file-readable-p file))
5864 (with-current-buffer (or buffer
5865 (find-file-noselect file))
5866 (funcall fun)
5867 (or buffer
5868 (kill-buffer (current-buffer))))))))
5869 (directory-files dir t file-regexp)))
5872 (defun pr-delete-file-if-exists (filename)
5873 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5874 (delete-file filename)))
5877 (defun pr-ps-file-list (n-up dir file-regexp filename)
5878 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5879 (let ((pr-spool-p t))
5880 (pr-file-list dir file-regexp
5881 #'(lambda ()
5882 (if (pr-auto-mode-p)
5883 (pr-ps-mode n-up filename)
5884 (pr-text2ps 'buffer n-up filename)))))
5885 (or pr-spool-p
5886 (pr-despool-print filename)))
5889 (defun pr-text2ps (kind n-up filename &optional from to)
5890 (with-file-modes pr-file-modes
5891 (let ((ps-n-up-printing n-up)
5892 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5893 'setpagedevice)))
5894 (pr-delete-file-if-exists filename)
5895 (cond (pr-faces-p
5896 (cond (pr-spool-p
5897 ;; pr-faces-p and pr-spool-p
5898 ;; here FILENAME arg is ignored
5899 (cond ((eq kind 'buffer)
5900 (ps-spool-buffer-with-faces))
5901 ((eq kind 'region)
5902 (ps-spool-region-with-faces (or from (point))
5903 (or to (mark))))
5905 ;; pr-faces-p and not pr-spool-p
5906 ((eq kind 'buffer)
5907 (ps-print-buffer-with-faces filename))
5908 ((eq kind 'region)
5909 (ps-print-region-with-faces (or from (point))
5910 (or to (mark)) filename))
5912 (pr-spool-p
5913 ;; not pr-faces-p and pr-spool-p
5914 ;; here FILENAME arg is ignored
5915 (cond ((eq kind 'buffer)
5916 (ps-spool-buffer))
5917 ((eq kind 'region)
5918 (ps-spool-region (or from (point)) (or to (mark))))
5920 ;; not pr-faces-p and not pr-spool-p
5921 ((eq kind 'buffer)
5922 (ps-print-buffer filename))
5923 ((eq kind 'region)
5924 (ps-print-region (or from (point)) (or to (mark)) filename))
5925 ))))
5928 (defun pr-command (command)
5929 "Return absolute file name specification for COMMAND.
5931 If COMMAND is an empty string, return it.
5933 If COMMAND is already an absolute file name specification, return it.
5934 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5935 otherwise, gives an error.
5937 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5938 `unix' are used (see `pr-path-alist' for documentation).
5940 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5941 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5942 (if (string= command "")
5943 command
5944 (pr-dosify-file-name
5945 (or (pr-find-command command)
5946 (pr-path-command (cond (pr-cygwin-system 'cygwin)
5947 (lpr-windows-system 'windows)
5948 (t 'unix))
5949 (file-name-nondirectory command)
5950 nil)
5951 (error "Command not found: %s"
5952 (file-name-nondirectory command))))))
5955 (defun pr-path-command (symbol command sym-list)
5956 (let ((lpath (cdr (assq symbol pr-path-alist)))
5957 cmd)
5958 ;; PATH expansion
5959 (and (eq symbol 'PATH) (null lpath)
5960 (setq lpath (parse-colon-path (getenv "PATH"))))
5961 (while (and lpath
5962 (not
5963 (setq cmd
5964 (let ((path (car lpath)))
5965 (cond
5966 ;; symbol expansion
5967 ((symbolp path)
5968 (and (not (memq path sym-list))
5969 (pr-path-command path command
5970 (cons path sym-list))))
5971 ;; normal path
5972 ((stringp path)
5973 (pr-find-command
5974 (expand-file-name
5975 (substitute-in-file-name
5976 (concat (file-name-as-directory path)
5977 command)))))
5978 )))))
5979 (setq lpath (cdr lpath)))
5980 cmd))
5983 (defun pr-find-command (cmd)
5984 (if lpr-windows-system
5985 ;; windows system
5986 (let ((ext (cons (file-name-extension cmd t)
5987 (list ".exe" ".bat" ".com")))
5988 found)
5989 (setq cmd (file-name-sans-extension cmd))
5990 (while (and ext
5991 (setq found (concat cmd (car ext)))
5992 (not (and (file-regular-p found)
5993 (file-executable-p found))))
5994 (setq ext (cdr ext)
5995 found nil))
5996 found)
5997 ;; non-windows systems
5998 (and (file-regular-p cmd)
5999 (file-executable-p cmd)
6000 cmd)))
6003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6004 ;; Printing Interface (inspired by ps-print-interface.el)
6007 (eval-when-compile
6008 (require 'cus-edit)
6009 (require 'wid-edit)
6010 (require 'widget))
6013 (defvar pr-i-window-configuration nil)
6015 (defvar pr-i-buffer nil)
6016 (defvar pr-i-region nil)
6017 (defvar pr-i-mode nil)
6018 (defvar pr-i-despool nil)
6019 (defvar pr-i-ps-as-is t)
6020 (defvar pr-i-n-up 1)
6021 (defvar pr-i-directory "./")
6022 (defvar pr-i-regexp "")
6023 (defvar pr-i-ps-file "")
6024 (defvar pr-i-out-file "")
6025 (defvar pr-i-answer-yes nil)
6026 (defvar pr-i-process 'buffer)
6027 (defvar pr-i-ps-send 'printer)
6030 (defvar pr-interface-map nil
6031 "Keymap for pr-interface.")
6033 (unless pr-interface-map
6034 (let ((map (make-sparse-keymap)))
6035 (cond ((featurep 'xemacs) ; XEmacs
6036 (pr-set-keymap-parents map (list widget-keymap))
6037 (pr-set-keymap-name map 'pr-interface-map))
6038 (t ; GNU Emacs
6039 (pr-set-keymap-parents map widget-keymap)))
6040 (define-key map "q" 'pr-interface-quit)
6041 (define-key map "?" 'pr-interface-help)
6042 (setq pr-interface-map map)))
6045 (defmacro pr-interface-save (&rest body)
6046 `(with-current-buffer pr-i-buffer
6047 ,@body))
6050 (defun pr-create-interface ()
6051 "Create the front end for printing package."
6052 (setq pr-i-buffer (buffer-name (current-buffer))
6053 pr-i-region (ps-mark-active-p)
6054 pr-i-mode (pr-mode-alist-p)
6055 pr-i-window-configuration (current-window-configuration))
6057 (put 'pr-i-process 'pr-widget-list nil)
6058 (put 'pr-i-ps-send 'pr-widget-list nil)
6060 (delete-other-windows)
6061 (kill-buffer (get-buffer-create pr-buffer-name))
6062 (switch-to-buffer (get-buffer-create pr-buffer-name))
6064 ;; header
6065 (let ((versions (concat "printing v" pr-version
6066 " ps-print v" ps-print-version)))
6067 ;; to keep compatibility with Emacs 20 & 21:
6068 ;; DO NOT REPLACE `?\ ' BY `?\s'
6069 (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
6070 (pr-insert-italic "\nCurrent Directory : " 1)
6071 (pr-insert-italic default-directory)
6073 (pr-insert-section-1) ; 1. Print
6074 (pr-insert-section-2) ; 2. PostScript Printer
6075 (pr-insert-section-3) ; 3. Text Printer
6077 ;; separator
6078 (widget-insert "\n\n " (make-string 77 ?-))
6080 (pr-insert-section-4) ; 4. Settings
6081 (pr-insert-section-5) ; 5. Customize
6082 (pr-insert-section-6) ; 6. Show Settings
6083 (pr-insert-section-7) ; 7. Help
6085 (use-local-map pr-interface-map)
6086 (widget-setup)
6087 (goto-char (point-min))
6089 (and pr-i-region ; let region activated
6090 (pr-keep-region-active)))
6092 (declare-function widget-field-action "wid-edit" (widget &optional _event))
6093 (declare-function widget-value-set "wid-edit" (widget value))
6095 (defun pr-insert-section-1 ()
6096 ;; 1. Print:
6097 (pr-insert-italic "\nPrint :" 1)
6099 ;; 1a. Buffer:
6100 ;; 1a. Buffer: Buffer List
6101 (pr-insert-radio-button 'pr-i-process 'buffer)
6102 (pr-insert-menu "Buffer List" 'pr-i-buffer
6103 (let ((blist (buffer-list))
6104 case-fold-search choices)
6105 (while blist
6106 (let ((name (buffer-name (car blist)))
6107 (ignore pr-buffer-name-ignore)
6108 found)
6109 (setq blist (cdr blist))
6110 (while (and ignore (not found))
6111 (setq found (string-match (car ignore) name)
6112 ignore (cdr ignore)))
6113 (or found
6114 (setq choices
6115 (cons (list 'quote
6116 (list 'choice-item
6117 :format "%[%t%]"
6118 name))
6119 choices)))))
6120 (nreverse choices))
6121 " Buffer : " nil
6122 '(progn
6123 (pr-interface-save
6124 (setq pr-i-region (ps-mark-active-p)
6125 pr-i-mode (pr-mode-alist-p)))
6126 (pr-update-checkbox 'pr-i-region)
6127 (pr-update-checkbox 'pr-i-mode)))
6128 ;; 1a. Buffer: Region
6129 (put 'pr-i-region 'pr-widget
6130 (pr-insert-checkbox
6131 "\n "
6132 'pr-i-region
6133 #'(lambda (widget &rest _ignore)
6134 (let ((region-p (pr-interface-save
6135 (ps-mark-active-p))))
6136 (cond ((null (widget-value widget)) ; widget is nil
6137 (setq pr-i-region nil))
6138 (region-p ; widget is true and there is a region
6139 (setq pr-i-region t)
6140 (widget-value-set widget t)
6141 (widget-setup)) ; MUST be called after widget-value-set
6142 (t ; widget is true and there is no region
6143 (ding)
6144 (message "There is no region active")
6145 (setq pr-i-region nil)
6146 (widget-value-set widget nil)
6147 (widget-setup))))) ; MUST be called after widget-value-set
6148 " Region"))
6149 ;; 1a. Buffer: Mode
6150 (put 'pr-i-mode 'pr-widget
6151 (pr-insert-checkbox
6153 'pr-i-mode
6154 #'(lambda (widget &rest _ignore)
6155 (let ((mode-p (pr-interface-save
6156 (pr-mode-alist-p))))
6157 (cond
6158 ((null (widget-value widget)) ; widget is nil
6159 (setq pr-i-mode nil))
6160 (mode-p ; widget is true and there is a `mode'
6161 (setq pr-i-mode t)
6162 (widget-value-set widget t)
6163 (widget-setup)) ; MUST be called after widget-value-set
6164 (t ; widget is true and there is no `mode'
6165 (ding)
6166 (message
6167 "This buffer isn't in a mode that printing treats specially.")
6168 (setq pr-i-mode nil)
6169 (widget-value-set widget nil)
6170 (widget-setup))))) ; MUST be called after widget-value-set
6171 " Mode\n"))
6173 ;; 1b. Directory:
6174 (pr-insert-radio-button 'pr-i-process 'directory)
6175 (widget-create
6176 'directory
6177 :size 58
6178 :format " Directory : %v"
6179 :notify 'pr-interface-directory
6180 :action (lambda (widget &optional event)
6181 (if (pr-interface-directory widget)
6182 (pr-widget-field-action widget event)
6183 (ding)
6184 (message "Please specify a readable directory")))
6185 pr-i-directory)
6186 ;; 1b. Directory: File Regexp
6187 (widget-create 'regexp
6188 :size 58
6189 :format "\n File Regexp : %v\n"
6190 :notify (lambda (widget &rest _ignore)
6191 (setq pr-i-regexp (widget-value widget)))
6192 pr-i-regexp)
6193 ;; 1b. Directory: List Directory Entry
6194 (widget-insert " ")
6195 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
6197 ;; 1c. PostScript File:
6198 (pr-insert-radio-button 'pr-i-process 'file)
6199 (widget-create
6200 'file
6201 :size 51
6202 :format " PostScript File : %v"
6203 :notify 'pr-interface-infile
6204 :action (lambda (widget &rest event)
6205 (if (pr-interface-infile widget)
6206 (pr-widget-field-action widget event)
6207 (ding)
6208 (message "Please specify a readable PostScript file")))
6209 pr-i-ps-file)
6210 ;; 1c. PostScript File: PostScript Utility
6211 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
6212 (pr-choice-alist pr-ps-utility-alist)
6213 "\n PostScript Utility : "
6214 " ")
6215 ;; 1c. PostScript File: No Preprocessing
6216 (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
6219 (defun pr-insert-section-2 ()
6220 ;; 2. PostScript Printer:
6221 ;; 2. PostScript Printer: PostScript Printer List
6222 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
6223 (pr-insert-menu "PostScript Printer" 'pr-ps-name
6224 (pr-choice-alist pr-ps-printer-alist))
6225 ;; 2. PostScript Printer: Despool
6226 (put 'pr-i-despool 'pr-widget
6227 (pr-insert-checkbox
6229 'pr-i-despool
6230 #'(lambda (widget &rest _ignore)
6231 (if pr-spool-p
6232 (setq pr-i-despool (not pr-i-despool))
6233 (ding)
6234 (message "Can despool only when spooling is actually selected")
6235 (setq pr-i-despool nil))
6236 (widget-value-set widget pr-i-despool)
6237 (widget-setup)) ; MUST be called after widget-value-set
6238 " Despool "))
6239 ;; 2. PostScript Printer: Preview Print Quit
6240 (pr-insert-button 'pr-interface-preview "Preview" " ")
6241 (pr-insert-button 'pr-interface-ps-print "Print" " ")
6242 (pr-insert-button 'pr-interface-quit "Quit")
6243 ;; 2. PostScript Printer: Send to Printer/Temporary File
6244 (pr-insert-radio-button 'pr-i-ps-send 'printer)
6245 (widget-insert " Send to Printer/Temporary File")
6246 ;; 2. PostScript Printer: Send to File
6247 (pr-insert-radio-button 'pr-i-ps-send 'file)
6248 (widget-create
6249 'file
6250 :size 57
6251 :format " Send to File : %v"
6252 :notify 'pr-interface-outfile
6253 :action (lambda (widget &rest event)
6254 (if (and (pr-interface-outfile widget)
6255 (or (not (file-exists-p pr-i-out-file))
6256 (setq pr-i-answer-yes
6257 (y-or-n-p "File exists; overwrite? "))))
6258 (pr-widget-field-action widget event)
6259 (ding)
6260 (message "Please specify a writable PostScript file")))
6261 pr-i-out-file)
6262 ;; 2. PostScript Printer: N-Up
6263 (widget-create
6264 'integer
6265 :size 3
6266 :format "\n N-Up : %v"
6267 :notify (lambda (widget &rest _ignore)
6268 (let ((value (if (string= (widget-apply widget :value-get) "")
6270 (widget-value widget))))
6271 (if (and (integerp value)
6272 (<= 1 value) (<= value 100))
6273 (progn
6274 (message " ")
6275 (setq pr-i-n-up value))
6276 (ding)
6277 (message "Please specify an integer between 1 and 100"))))
6278 pr-i-n-up))
6281 (defun pr-insert-section-3 ()
6282 ;; 3. Text Printer:
6283 (pr-insert-italic "\n\nText Printer : " 2 14)
6284 (pr-insert-menu "Text Printer" 'pr-txt-name
6285 (pr-choice-alist pr-txt-printer-alist)
6286 nil " ")
6287 (pr-insert-button 'pr-interface-printify "Printify" " ")
6288 (pr-insert-button 'pr-interface-txt-print "Print" " ")
6289 (pr-insert-button 'pr-interface-quit "Quit"))
6292 (defun pr-insert-section-4 ()
6293 ;; 4. Settings:
6294 ;; 4. Settings: Landscape Auto Region Verbose
6295 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
6296 #'(lambda (&rest _ignore)
6297 (setq ps-landscape-mode (not ps-landscape-mode)
6298 pr-file-landscape ps-landscape-mode))
6299 " Landscape ")
6300 (pr-insert-toggle 'pr-auto-region " Auto Region ")
6301 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
6303 ;; 4. Settings: Print Header Auto Mode
6304 (pr-insert-toggle 'ps-print-header " Print Header ")
6305 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
6307 ;; 4. Settings: Print Header Frame Menu Lock
6308 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
6309 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
6311 ;; 4. Settings: Line Number
6312 (pr-insert-toggle 'ps-line-number " Line Number\n ")
6314 ;; 4. Settings: Zebra Stripes Spool Buffer
6315 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
6316 (pr-insert-checkbox " "
6317 'pr-spool-p
6318 #'(lambda (&rest _ignore)
6319 (setq pr-spool-p (not pr-spool-p))
6320 (unless pr-spool-p
6321 (setq pr-i-despool nil)
6322 (pr-update-checkbox 'pr-i-despool)))
6323 " Spool Buffer")
6325 ;; 4. Settings: Duplex Print with faces
6326 (pr-insert-checkbox "\n "
6327 'ps-spool-duplex
6328 #'(lambda (&rest _ignore)
6329 (setq ps-spool-duplex (not ps-spool-duplex)
6330 pr-file-duplex ps-spool-duplex))
6331 " Duplex ")
6332 (pr-insert-toggle 'pr-faces-p " Print with faces")
6334 ;; 4. Settings: Tumble Print via Ghostscript
6335 (pr-insert-checkbox "\n "
6336 'ps-spool-tumble
6337 #'(lambda (&rest _ignore)
6338 (setq ps-spool-tumble (not ps-spool-tumble)
6339 pr-file-tumble ps-spool-tumble))
6340 " Tumble ")
6341 (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
6343 ;; 4. Settings: Upside-Down Page Parity
6344 (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
6345 (pr-insert-italic "\n\nSelect Pages : " 2 14)
6346 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
6347 (mapcar #'(lambda (alist)
6348 (list 'quote
6349 (list 'choice-item
6350 :format "%[%t%]"
6351 :tag (cdr alist)
6352 :value (car alist))))
6353 pr-even-or-odd-alist)))
6356 (defun pr-insert-section-5 ()
6357 ;; 5. Customize:
6358 (pr-insert-italic "\n\nCustomize : " 2 11)
6359 (pr-insert-button 'pr-customize "printing" " ")
6360 (pr-insert-button #'(lambda (&rest _ignore) (ps-print-customize))
6361 "ps-print" " ")
6362 (pr-insert-button 'lpr-customize "lpr"))
6365 (defun pr-insert-section-6 ()
6366 ;; 6. Show Settings:
6367 (pr-insert-italic "\nShow Settings : " 1 14)
6368 (pr-insert-button 'pr-show-pr-setup "printing" " ")
6369 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
6370 (pr-insert-button 'pr-show-lpr-setup "lpr"))
6373 (defun pr-insert-section-7 ()
6374 ;; 7. Help:
6375 (pr-insert-italic "\nHelp : " 1 5)
6376 (pr-insert-button 'pr-interface-help "Interface Help" " ")
6377 (pr-insert-button 'pr-help "Menu Help" " ")
6378 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
6379 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
6382 (defun pr-kill-help (&rest _ignore)
6383 "Kill all printing help buffer."
6384 (interactive)
6385 (let ((help '("*Printing Interface Help*" "*Printing Help*"
6386 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
6387 (while help
6388 (let ((buffer (get-buffer (car help))))
6389 (setq help (cdr help))
6390 (when buffer
6391 (delete-windows-on buffer)
6392 (kill-buffer buffer)))))
6393 (recenter (- (window-height) 2)))
6396 (defun pr-interface-quit (&rest _ignore)
6397 "Kill the printing buffer interface and quit."
6398 (interactive)
6399 (kill-buffer pr-buffer-name)
6400 (set-window-configuration pr-i-window-configuration))
6403 (defun pr-interface-help (&rest _ignore)
6404 "printing buffer interface help."
6405 (interactive)
6406 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
6409 (defun pr-interface-txt-print (&rest _ignore)
6410 "Print using lpr package."
6411 (interactive)
6412 (condition-case data
6413 (cond
6414 ((eq pr-i-process 'directory)
6415 (pr-i-directory)
6416 (pr-interface-save
6417 (pr-txt-directory pr-i-directory pr-i-regexp)))
6418 ((eq pr-i-process 'buffer)
6419 (pr-interface-save
6420 (cond (pr-i-region
6421 (let ((pr-auto-mode pr-i-mode))
6422 (pr-txt-region)))
6423 (pr-i-mode
6424 (let (pr-auto-region)
6425 (pr-txt-mode)))
6427 (let (pr-auto-mode pr-auto-region)
6428 (pr-txt-buffer)))
6430 ((eq pr-i-process 'file)
6431 (error "Please specify a text file"))
6433 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6435 ;; handlers
6436 ((quit error)
6437 (ding)
6438 (message "%s" (error-message-string data)))))
6441 (defun pr-interface-printify (&rest _ignore)
6442 "Printify a buffer."
6443 (interactive)
6444 (condition-case data
6445 (cond
6446 ((eq pr-i-process 'directory)
6447 (pr-i-directory)
6448 (pr-interface-save
6449 (pr-printify-directory pr-i-directory pr-i-regexp)))
6450 ((eq pr-i-process 'buffer)
6451 (pr-interface-save
6452 (if pr-i-region
6453 (pr-printify-region)
6454 (pr-printify-buffer))))
6455 ((eq pr-i-process 'file)
6456 (error "Cannot printify a PostScript file"))
6458 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6460 ;; handlers
6461 ((quit error)
6462 (ding)
6463 (message "%s" (error-message-string data)))))
6466 (defun pr-interface-ps-print (&rest _ignore)
6467 "Print using ps-print package."
6468 (interactive)
6469 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6470 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6471 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6472 'pr-ps-buffer-ps-print))
6475 (defun pr-interface-preview (&rest _ignore)
6476 "Preview a PostScript file."
6477 (interactive)
6478 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6479 'pr-ps-file-preview 'pr-ps-file-up-preview
6480 'pr-ps-region-preview 'pr-ps-mode-preview
6481 'pr-ps-buffer-preview))
6484 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6485 ps-mode ps-buffer)
6486 (condition-case data
6487 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6488 (pr-i-ps-send))))
6489 (cond
6490 ((and pr-i-despool pr-spool-p)
6491 (pr-interface-save
6492 (funcall ps-despool outfile))
6493 (setq pr-i-despool nil)
6494 (pr-update-checkbox 'pr-i-despool))
6495 ((eq pr-i-process 'directory)
6496 (pr-i-directory)
6497 (pr-interface-save
6498 (funcall ps-directory
6499 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6500 ((eq pr-i-process 'file)
6501 (cond ((or (file-directory-p pr-i-ps-file)
6502 (not (file-readable-p pr-i-ps-file)))
6503 (error "Please specify a readable PostScript file"))
6504 (pr-i-ps-as-is
6505 (pr-interface-save
6506 (funcall ps-file pr-i-ps-file)))
6508 (pr-interface-save
6509 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6511 ((eq pr-i-process 'buffer)
6512 (pr-interface-save
6513 (cond (pr-i-region
6514 (let ((pr-auto-mode pr-i-mode))
6515 (funcall ps-region pr-i-n-up outfile)))
6516 (pr-i-mode
6517 (let (pr-auto-region)
6518 (funcall ps-mode pr-i-n-up outfile)))
6520 (let (pr-auto-mode pr-auto-region)
6521 (funcall ps-buffer pr-i-n-up outfile)))
6524 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6526 ;; handlers
6527 ((quit error)
6528 (ding)
6529 (message "%s" (error-message-string data)))))
6532 (defun pr-i-ps-send ()
6533 (cond ((eq pr-i-ps-send 'printer)
6534 nil)
6535 ((not (eq pr-i-ps-send 'file))
6536 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6537 ((or (file-directory-p pr-i-out-file)
6538 (not (file-writable-p pr-i-out-file)))
6539 (error "Please specify a writable PostScript file"))
6540 ((or (not (file-exists-p pr-i-out-file))
6541 pr-i-answer-yes
6542 (setq pr-i-answer-yes
6543 (y-or-n-p (format "File `%s' exists; overwrite? "
6544 pr-i-out-file))))
6545 pr-i-out-file)
6547 (error "File already exists"))))
6550 (defun pr-i-directory ()
6551 (or (file-accessible-directory-p pr-i-directory)
6552 (error "Please specify be a readable directory")))
6555 (defun pr-interface-directory (widget &rest _ignore)
6556 (and pr-buffer-verbose
6557 (message "You can use M-TAB or ESC TAB for file completion"))
6558 (let ((dir (widget-value widget)))
6559 (and (file-accessible-directory-p dir)
6560 (setq pr-i-directory dir))))
6563 (defun pr-interface-infile (widget &rest _ignore)
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-readable-p file)
6569 (setq pr-i-ps-file file))))
6572 (defun pr-interface-outfile (widget &rest _ignore)
6573 (setq pr-i-answer-yes nil)
6574 (and pr-buffer-verbose
6575 (message "You can use M-TAB or ESC TAB for file completion"))
6576 (let ((file (widget-value widget)))
6577 (and (not (file-directory-p file))
6578 (file-writable-p file)
6579 (setq pr-i-out-file file))))
6582 (defun pr-widget-field-action (widget event)
6583 (and (get-buffer "*Completions*") ; clean frame window
6584 (delete-windows-on "*Completions*"))
6585 (message " ") ; clean echo area
6586 (widget-field-action widget event))
6589 (defun pr-insert-italic (str &optional from to)
6590 (let ((len (length str)))
6591 (put-text-property (if from (max from 0) 0)
6592 (if to (max to len) len)
6593 'face 'italic str)
6594 (widget-insert str)))
6597 (defun pr-insert-checkbox (before var-sym fun label)
6598 (widget-insert before)
6599 (prog1
6600 (widget-create 'checkbox
6601 :notify fun
6602 (symbol-value var-sym))
6603 (widget-insert label)))
6606 (defun pr-insert-toggle (var-sym label)
6607 (widget-create 'checkbox
6608 :notify `(lambda (&rest _ignore)
6609 (setq ,var-sym (not ,var-sym)))
6610 (symbol-value var-sym))
6611 (widget-insert label))
6614 (defun pr-insert-button (fun label &optional separator)
6615 (widget-create 'push-button
6616 :notify fun
6617 label)
6618 (and separator
6619 (widget-insert separator)))
6622 (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6623 (and before (widget-insert before))
6624 (eval `(widget-create 'menu-choice
6625 :tag ,tag
6626 :format "%v"
6627 :inline t
6628 :value ,var-sym
6629 :notify (lambda (widget &rest _ignore)
6630 (setq ,var-sym (widget-value widget))
6631 ,@body)
6632 :void '(choice-item :format "%[%t%]"
6633 :tag "Can not display value!")
6634 ,@choices))
6635 (and after (widget-insert after)))
6638 (defun pr-insert-radio-button (var-sym sym)
6639 (widget-insert "\n")
6640 (let ((wid-list (get var-sym 'pr-widget-list))
6641 (wid (eval `(widget-create
6642 'radio-button
6643 :format " %[%v%]"
6644 :value (eq ,var-sym (quote ,sym))
6645 :notify (lambda (&rest _ignore)
6646 (setq ,var-sym (quote ,sym))
6647 (pr-update-radio-button (quote ,var-sym)))))))
6648 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6651 (defun pr-update-radio-button (var-sym)
6652 (let ((wid-list (get var-sym 'pr-widget-list)))
6653 (while wid-list
6654 (let ((wid (car (car wid-list)))
6655 (value (cdr (car wid-list))))
6656 (setq wid-list (cdr wid-list))
6657 (widget-value-set wid (eq (symbol-value var-sym) value))))
6658 (widget-setup)))
6661 (defun pr-update-checkbox (var-sym)
6662 (let ((wid (get var-sym 'pr-widget)))
6663 (when wid
6664 (widget-value-set wid (symbol-value var-sym))
6665 (widget-setup))))
6668 (defun pr-choice-alist (alist)
6669 (let ((max (apply 'max (mapcar #'(lambda (alist)
6670 (length (symbol-name (car alist))))
6671 alist))))
6672 (mapcar #'(lambda (alist)
6673 (let* ((sym (car alist))
6674 (name (symbol-name sym)))
6675 (list
6676 'quote
6677 (list
6678 'choice-item
6679 :format "%[%t%]"
6680 :tag (concat name
6681 (make-string (- max (length name)) ?_))
6682 :value sym))))
6683 alist)))
6686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6689 (provide 'printing)
6692 ;;; printing.el ends here