Fix sectrioning errors in files.texi.
[emacs.git] / lisp / printing.el
blob0f58956408308fb8d2fe959bc77cb51cf4d19589
1 ;;; printing.el --- printing utilities
3 ;; Copyright (C) 2000, 2001, 2003, 2004, 2005,
4 ;; 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8 ;; Keywords: wp, print, PostScript
9 ;; Version: 6.9.1
10 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
12 (defconst pr-version "6.9.1"
13 "printing.el, v 6.9.1 <2007/08/02 vinicius>
15 Please send all bug fixes and enhancements to
16 Vinicius Jose Latorre <viniciusjl@ig.com.br>
19 ;; This file is part of GNU Emacs.
21 ;; GNU Emacs is free software; you can redistribute it and/or modify it under
22 ;; the terms of the GNU General Public License as published by the Free
23 ;; Software Foundation; either version 3, or (at your option) any later
24 ;; version.
26 ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY
27 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
28 ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
29 ;; details.
31 ;; You should have received a copy of the GNU General Public License along with
32 ;; GNU Emacs; see the file COPYING. If not, write to the Free Software
33 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
35 ;;; Commentary:
37 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; Introduction
40 ;; ------------
42 ;; With `printing' you can preview or print a PostScript file. You can also
43 ;; print a text file using PostScript, and preview or print buffers that use
44 ;; certain special modes like mh-folder-mode, rmail-summary-mode,
45 ;; gnus-summary-mode, etc. This package also includes a PostScript/text
46 ;; printer database.
48 ;; There are two user interfaces:
50 ;; * Menu interface:
51 ;; The `printing' menu replaces the usual print options in the menu bar.
52 ;; This is the default user interface.
54 ;; * Buffer interface:
55 ;; You can use a buffer interface instead of menus. It looks like a
56 ;; customization buffer. Basically, it has the same options found in the
57 ;; menu and some extra options, all this on a buffer.
59 ;; `printing' is prepared to run on GNU, Unix and NT systems.
60 ;; On GNU or Unix system, `printing' depends on gs and gv utilities.
61 ;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe).
62 ;; To obtain ghostscript, ghostview and GSview see the URL
63 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'.
65 ;; `printing' depends on ps-print package to generate PostScript files, to
66 ;; spool and to despool PostScript buffer. So, `printing' provides an
67 ;; interface to ps-print package and it also provides some extra stuff.
69 ;; To download the latest ps-print package see
70 ;; `http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'.
71 ;; Please, see README file for ps-print installation instructions.
73 ;; `printing' was inspired on:
75 ;; print-nt.el Frederic Corne <frederic.corne@erli.fr>
76 ;; Special printing functions for Windows NT
78 ;; mh-e-init.el Tom Vogels <tov@ece.cmu.edu>
79 ;; PS-print for mail messages
81 ;; win32-ps-print.el Matthew O. Persico <mpersico@erols.com>
82 ;; PostScript printing with ghostscript
84 ;; ps-print-interface.el Volker Franz <volker.franz@tuebingen.mpg.de>
85 ;; Graphical front end for ps-print and previewing
88 ;; Log Messages
89 ;; ------------
91 ;; The buffer *Printing Command Output* is where the `printing' log messages
92 ;; are inserted. All program called by `printing' has a log entry in the
93 ;; buffer *Printing Command Output*. A log entry has the following form:
95 ;; PROGRAM (ARG...)
96 ;; MESSAGE
97 ;; Exit status: CODE
99 ;; Where
100 ;; PROGRAM is the program activated by `printing',
101 ;; ARG is an argument passed to PROGRAM (it can have more than one argument),
102 ;; MESSAGE is an error message returned by PROGRAM (it can have no message, if
103 ;; PROGRAM is successful),
104 ;; and CODE is a numeric exit status or a signal description string.
106 ;; For example, after previewing a PostScript file, *Printing Command Output*
107 ;; will have the following entry:
109 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
110 ;; Exit status: 0
112 ;; In the example above, the previewing was successful. If during previewing,
113 ;; you quit gv execution (by typing C-g during Emacs session), the log entry
114 ;; would be:
116 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
117 ;; Exit status: Quit
119 ;; So, if something goes wrong, a good place to take a look is the buffer
120 ;; *Printing Command Output*. Don't forget to see also the buffer *Messages*,
121 ;; it can help.
124 ;; Novices (First Users)
125 ;; ---------------------
127 ;; First of all, see printing documentation only to get an idea of what
128 ;; `printing' is capable.
130 ;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
131 ;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'. These variables
132 ;; are the main variables for printing processing.
134 ;; Now, please, see these variables documentation deeper. You can do this by
135 ;; typing C-h v pr-ps-name RET (for example) if you already loaded printing
136 ;; package, or by browsing printing.el source file.
138 ;; If the documentation isn't clear or if you find a way to improve the
139 ;; documentation, please, send an email to maintainer. All printing users
140 ;; will thank you.
142 ;; One way to set variables is by calling `pr-customize', customize all
143 ;; variables and save the customization by future sessions (see Options
144 ;; section). Other way is by coding your settings on Emacs init file (that is,
145 ;; ~/.emacs file), see below for a first setting template that it should be
146 ;; inserted on your ~/.emacs file (or c:/_emacs, if you're using Windows 9x/NT
147 ;; or MS-DOS):
149 ;; * Example of setting for Windows system:
151 ;; (require 'printing) ; load printing package
152 ;; (setq pr-path-alist
153 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
154 ;; (ghostview "c:/gs/gsview-dir")
155 ;; (mpage "c:/mpage-dir")
156 ;; ))
157 ;; (setq pr-txt-name 'prt_06a)
158 ;; (setq pr-txt-printer-alist
159 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
160 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
161 ;; (PRN "" nil "PRN")
162 ;; (standard "redpr.exe" nil "")
163 ;; ))
164 ;; (setq pr-ps-name 'lps_06b)
165 ;; (setq pr-ps-printer-alist
166 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
167 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
168 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
169 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
170 ;; (LPT1 "" nil "" "LPT1:")
171 ;; (PRN "" nil "" "PRN")
172 ;; (standard "redpr.exe" nil "" "")
173 ;; ))
174 ;; (pr-update-menus t) ; update now printer and utility menus
176 ;; * Example of setting for GNU or Unix system:
178 ;; (require 'printing) ; load printing package
179 ;; (setq pr-path-alist
180 ;; '((unix "." "~/bin" ghostview mpage PATH)
181 ;; (ghostview "$HOME/bin/gsview-dir")
182 ;; (mpage "$HOME/bin/mpage-dir")
183 ;; ))
184 ;; (setq pr-txt-name 'prt_06a)
185 ;; (setq pr-txt-printer-alist
186 ;; '((prt_06a "lpr" nil "prt_06a")
187 ;; (prt_07c nil nil "prt_07c")
188 ;; ))
189 ;; (setq pr-ps-name 'lps_06b)
190 ;; (setq pr-ps-printer-alist
191 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
192 ;; (lps_07c "lpr" nil nil "lps_07c")
193 ;; (lps_08c nil nil nil "lps_08c")
194 ;; ))
195 ;; (pr-update-menus t) ; update now printer and utility menus
198 ;; NOTE 1: Don't forget to download and install ghostscript utilities (see
199 ;; Utilities section).
201 ;; NOTE 2: The `printer-name' and `ps-printer-name' variables don't need to be
202 ;; set, as they are implicit set by `pr-ps-printer-alist' and
203 ;; `pr-txt-printer-alist'.
205 ;; NOTE 3: The duplex feature will only work on PostScript printers that
206 ;; support this feature.
207 ;; You can check if your PostScript printer supports duplex feature
208 ;; by checking the printer manual. Or you can try these steps:
209 ;; 1. Open a buffer (or use the *scratch* buffer).
210 ;; 2. Type:
211 ;; First line (on first page)
212 ;; ^L
213 ;; Second line (on second page)
214 ;; 3. Print this buffer with duplex turned on.
215 ;; If it's printed 2 (two) sheets of paper, then your PostScript
216 ;; printer doesn't have duplex feature; otherwise, it's ok, your
217 ;; printer does have duplex feature.
219 ;; NOTE 4: See Tips section.
222 ;; Tips
223 ;; ----
225 ;; 1. If you have a local printer, that is, a printer which is connected
226 ;; directly to your computer, don't forget to connect the printer to your
227 ;; computer before printing.
229 ;; 2. If you try to print a file and it seems that the file was printed, but
230 ;; there is no paper in the printer, then try to set `pr-delete-temp-file'
231 ;; to nil. Probably `printing' is deleting the temporary file before your
232 ;; local system can get it to send to the printer.
234 ;; 3. Don't try to print a dynamic buffer, that is, a buffer which is
235 ;; modifying while `printing' tries to print. Eventually you got an error
236 ;; message. Instead, save the dynamic buffer to a file or copy it in
237 ;; another buffer and, then, print the file or the new static buffer.
238 ;; An example of dynamic buffer is the *Messages* buffer.
240 ;; 4. When running Emacs on Windows (with or without cygwin), check if your
241 ;; printer is a text printer or not by typing in a DOS window:
243 ;; print /D:\\host\printer somefile.txt
245 ;; Where, `host' is the machine where the printer is directly connected,
246 ;; `printer' is the printer name and `somefile.txt' is a text file.
248 ;; If the printer `\\host\printer' doesn't print the content of
249 ;; `somefile.txt' or, instead, it returns the following message:
251 ;; PostScript Error Handler
252 ;; Offending Command = CCC
253 ;; Stack =
255 ;; Where `CCC' is whatever is at the beginning of the text to be printed.
257 ;; Therefore, the printer `\\host\printer' is not a text printer, but a
258 ;; PostScript printer. So, please, don't include this printer in
259 ;; `pr-txt-printer-alist' (which see).
261 ;; 5. You can use gsprint instead of ghostscript to print monochrome PostScript
262 ;; files in Windows. The gsprint utility documentation says that it is more
263 ;; efficient than ghostscript to print monochrome PostScript.
265 ;; To print non-monochrome PostScript file, the efficiency of ghostscript
266 ;; is similar to gsprint.
268 ;; Also the gsprint utility comes together with gsview distribution.
270 ;; For more information about gsprint see
271 ;; `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
273 ;; As an example of gsprint declaration:
275 ;; (setq pr-ps-printer-alist
276 ;; '((A "gsprint" ("-all" "-twoup") "-printer " "my-b/w-printer-name")
277 ;; (B "gsprint" ("-all" "-twoup") nil "-printer my-b/w-printer-name")
278 ;; ;; some other printer declaration
279 ;; ))
281 ;; The example above declares that printer A prints all pages (-all) and two
282 ;; pages per sheet (-twoup). The printer B declaration does the same as the
283 ;; printer A declaration, the only difference is the printer name selection.
285 ;; There are other command line options like:
287 ;; -mono Render in monochrome as 1bit/pixel (only black and white).
288 ;; -grey Render in greyscale as 8bits/pixel.
289 ;; -color Render in color as 24bits/pixel.
291 ;; The default is `-mono'. So, printer A and B in the example above are
292 ;; using implicitly the `-mono' option. Note that in `-mono' no gray tone
293 ;; or color is printed, this includes the zebra stripes, that is, in `-mono'
294 ;; the zebra stripes are not printed.
296 ;; See also documentation for `pr-ps-printer-alist'.
299 ;; Using `printing'
300 ;; ----------------
302 ;; To use `printing' insert in your ~/.emacs file (or c:/_emacs, if you're
303 ;; using Windows 9x/NT or MS-DOS):
305 ;; (require 'printing)
306 ;; ;; ...some user settings...
307 ;; (pr-update-menus t)
309 ;; During `pr-update-menus' evaluation:
310 ;; * On Emacs 20:
311 ;; it replaces the Tools/Print menu by Tools/Printing menu.
312 ;; * On Emacs 21:
313 ;; it replaces the File/Print* menu entries by File/Print menu.
314 ;; Please, see section Menu Layout below for menu explanation.
316 ;; To use `printing' utilities you can use the Printing menu options, type M-x
317 ;; followed by one of the commands below, or type a key associated with the
318 ;; command you want (if there is a key binding).
320 ;; `printing' has the following commands:
322 ;; pr-interface
323 ;; pr-ps-directory-preview
324 ;; pr-ps-directory-using-ghostscript
325 ;; pr-ps-directory-print
326 ;; pr-ps-directory-ps-print
327 ;; pr-ps-buffer-preview
328 ;; pr-ps-buffer-using-ghostscript
329 ;; pr-ps-buffer-print
330 ;; pr-ps-buffer-ps-print
331 ;; pr-ps-region-preview
332 ;; pr-ps-region-using-ghostscript
333 ;; pr-ps-region-print
334 ;; pr-ps-region-ps-print
335 ;; pr-ps-mode-preview
336 ;; pr-ps-mode-using-ghostscript
337 ;; pr-ps-mode-print
338 ;; pr-ps-mode-ps-print
339 ;; pr-ps-file-preview
340 ;; pr-ps-file-up-preview
341 ;; pr-ps-file-using-ghostscript
342 ;; pr-ps-file-print
343 ;; pr-ps-file-ps-print
344 ;; pr-ps-file-up-ps-print
345 ;; pr-ps-fast-fire
346 ;; pr-despool-preview
347 ;; pr-despool-using-ghostscript
348 ;; pr-despool-print
349 ;; pr-despool-ps-print
350 ;; pr-printify-directory
351 ;; pr-printify-buffer
352 ;; pr-printify-region
353 ;; pr-txt-directory
354 ;; pr-txt-buffer
355 ;; pr-txt-region
356 ;; pr-txt-mode
357 ;; pr-txt-fast-fire
358 ;; pr-toggle-file-duplex
359 ;; pr-toggle-file-tumble
360 ;; pr-toggle-file-landscape
361 ;; pr-toggle-ghostscript
362 ;; pr-toggle-faces
363 ;; pr-toggle-spool
364 ;; pr-toggle-duplex
365 ;; pr-toggle-tumble
366 ;; pr-toggle-landscape
367 ;; pr-toggle-upside-down
368 ;; pr-toggle-line
369 ;; pr-toggle-zebra
370 ;; pr-toggle-header
371 ;; pr-toggle-lock
372 ;; pr-toggle-region
373 ;; pr-toggle-mode
374 ;; pr-customize
375 ;; lpr-customize
376 ;; pr-help
377 ;; pr-ps-name
378 ;; pr-txt-name
379 ;; pr-ps-utility
380 ;; pr-show-ps-setup
381 ;; pr-show-pr-setup
382 ;; pr-show-lpr-setup
384 ;; The general meanings of above commands are:
386 ;; PREFIX:
387 ;; `pr-interface' buffer interface for printing package.
388 ;; `pr-help' help for printing package.
389 ;; `pr-ps-name' interactively select a PostScript printer.
390 ;; `pr-txt-name' interactively select a text printer.
391 ;; `pr-ps-utility' interactively select a PostScript utility.
392 ;; `pr-show-*-setup' show current settings.
393 ;; `pr-ps-*' deal with PostScript code generation.
394 ;; `pr-txt-*' deal with text generation.
395 ;; `pr-toggle-*' toggle on/off some boolean variable.
396 ;; `pr-despool-*' despool the PostScript spooling buffer.
397 ;; `pr-printify-*' replace nonprintable ASCII by printable ASCII
398 ;; representation.
400 ;; SUFFIX:
401 ;; `*-customize' customization.
402 ;; `*-preview' preview a PostScript file.
403 ;; `*-using-ghostscript' use ghostscript to print.
404 ;; `*-fast-fire' fast fire command (see it for documentation).
405 ;; `*-print' send PostScript directly to printer.
406 ;; `*-ps-print' send PostScript directly to printer or use
407 ;; ghostscript to print. It depends on
408 ;; `pr-print-using-ghostscript' option.
410 ;; INFIX/SUFFIX:
411 ;; `*-directory*' process a directory.
412 ;; `*-buffer*' process a buffer.
413 ;; `*-region*' process a region.
414 ;; `*-mode*' process a major mode (see explanation below).
415 ;; `*-file-*' process a PostScript file.
416 ;; `*-file-up-*' process a PostScript file using a filter utility.
418 ;; Here are some examples:
420 ;; `pr-ps-buffer-using-ghostscript'
421 ;; Use ghostscript to print a buffer.
423 ;; `pr-ps-file-print'
424 ;; Print a PostScript file.
426 ;; `pr-toggle-spool'
427 ;; Toggle spooling buffer.
429 ;; So you can preview through ghostview, use ghostscript to print (if you don't
430 ;; have a PostScript printer) or send directly to printer a PostScript code
431 ;; generated by `ps-print' package.
433 ;; Besides operating one buffer or region each time, you also can postpone
434 ;; previewing or printing by saving the PostScript code generated in a
435 ;; temporary Emacs buffer. This way you can save banner pages between
436 ;; successive printing. You can toggle on/off spooling by invoking
437 ;; `pr-toggle-spool' interactively or through menu bar.
439 ;; If you type, for example:
441 ;; C-u M-x pr-ps-buffer-print RET
443 ;; The `pr-ps-buffer-print' command prompts you for a n-up printing number and
444 ;; a file name, and save the PostScript code generated to the file name instead
445 ;; of sending to printer.
447 ;; This behavior is similar with the commands that deal with PostScript code
448 ;; generation, that is, with `pr-ps-*' and `pr-despool-*' commands. If
449 ;; spooling is on, only `pr-despool-*' commands prompt for a file name and save
450 ;; the PostScript code spooled in this file.
452 ;; Besides the behavior described above, the `*-directory*' commands also
453 ;; prompt for a directory and a file name regexp. So, it's possible to process
454 ;; all or certain files on a directory at once (see also documentation for
455 ;; `pr-list-directory').
457 ;; `printing' has also a special way to handle some major mode through
458 ;; `*-mode*' commands. So it's possible to customize a major mode printing,
459 ;; it's only needed to declare the customization in `pr-mode-alist' (see
460 ;; section Options) and invoke some of `*-mode*' commands. An example for
461 ;; major mode usage is when you're using gnus (or mh, or rmail, etc.) and
462 ;; you're in the *Summary* buffer, if you forget to switch to the *Article*
463 ;; buffer before printing, you'll get a nicely formatted list of article
464 ;; subjects shows up at the printer. With major mode printing you don't need
465 ;; to switch from gnus *Summary* buffer first.
467 ;; Current global keyboard mapping for GNU Emacs is:
469 ;; (global-set-key [print] 'pr-ps-fast-fire)
470 ;; (global-set-key [M-print] 'pr-ps-mode-using-ghostscript)
471 ;; (global-set-key [S-print] 'pr-ps-mode-using-ghostscript)
472 ;; (global-set-key [C-print] 'pr-txt-fast-fire)
473 ;; (global-set-key [C-M-print] 'pr-txt-fast-fire)
475 ;; And for XEmacs is:
477 ;; (global-set-key 'f22 'pr-ps-fast-fire)
478 ;; (global-set-key '(meta f22) 'pr-ps-mode-using-ghostscript)
479 ;; (global-set-key '(shift f22) 'pr-ps-mode-using-ghostscript)
480 ;; (global-set-key '(control f22) 'pr-txt-fast-fire)
481 ;; (global-set-key '(control meta f22) 'pr-txt-fast-fire)
483 ;; As a suggestion of global keyboard mapping for some `printing' commands:
485 ;; (global-set-key "\C-ci" 'pr-interface)
486 ;; (global-set-key "\C-cbp" 'pr-ps-buffer-print)
487 ;; (global-set-key "\C-cbx" 'pr-ps-buffer-preview)
488 ;; (global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
489 ;; (global-set-key "\C-crp" 'pr-ps-region-print)
490 ;; (global-set-key "\C-crx" 'pr-ps-region-preview)
491 ;; (global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
494 ;; Options
495 ;; -------
497 ;; Below it's shown a brief description of `printing' options, please, see the
498 ;; options declaration in the code for a long documentation.
500 ;; `pr-path-style' Specify which path style to use for external
501 ;; commands.
503 ;; `pr-path-alist' Specify an alist for command paths.
505 ;; `pr-txt-name' Specify a printer for printing a text file.
507 ;; `pr-txt-printer-alist' Specify an alist of all text printers.
509 ;; `pr-ps-name' Specify a printer for printing a PostScript
510 ;; file.
512 ;; `pr-ps-printer-alist' Specify an alist for all PostScript printers.
514 ;; `pr-temp-dir' Specify a directory for temporary files during
515 ;; printing.
517 ;; `pr-ps-temp-file' Specify PostScript temporary file name prefix.
519 ;; `pr-file-modes' Specify the file permission bits for newly
520 ;; created files.
522 ;; `pr-gv-command' Specify path and name of the gsview/gv
523 ;; utility.
525 ;; `pr-gs-command' Specify path and name of the ghostscript
526 ;; utility.
528 ;; `pr-gs-switches' Specify ghostscript switches.
530 ;; `pr-gs-device' Specify ghostscript device switch value.
532 ;; `pr-gs-resolution' Specify ghostscript resolution switch value.
534 ;; `pr-print-using-ghostscript' Non-nil means print using ghostscript.
536 ;; `pr-faces-p' Non-nil means print with face attributes.
538 ;; `pr-spool-p' Non-nil means spool printing in a buffer.
540 ;; `pr-file-landscape' Non-nil means print PostScript file in
541 ;; landscape orientation.
543 ;; `pr-file-duplex' Non-nil means print PostScript file in duplex
544 ;; mode.
546 ;; `pr-file-tumble' Non-nil means print PostScript file in tumble
547 ;; mode.
549 ;; `pr-auto-region' Non-nil means region is automagically detected.
551 ;; `pr-auto-mode' Non-nil means major-mode specific printing is
552 ;; prefered over normal printing.
554 ;; `pr-mode-alist' Specify an alist for a major-mode and printing
555 ;; function.
557 ;; `pr-ps-utility' Specify PostScript utility processing.
559 ;; `pr-ps-utility-alist' Specify an alist for PostScript utility
560 ;; processing.
562 ;; `pr-menu-lock' Non-nil means menu is locked while selecting
563 ;; toggle options.
565 ;; `pr-menu-char-height' Specify menu char height in pixels.
567 ;; `pr-menu-char-width' Specify menu char width in pixels.
569 ;; `pr-setting-database' Specify an alist for settings in general.
571 ;; `pr-visible-entry-list' Specify a list of Printing menu visible
572 ;; entries.
574 ;; `pr-delete-temp-file' Non-nil means delete temporary files.
576 ;; `pr-list-directory' Non-nil means list directory when processing a
577 ;; directory.
579 ;; `pr-buffer-name' Specify the name of the buffer interface for
580 ;; printing package.
582 ;; `pr-buffer-name-ignore' Specify a regexp list for buffer names to be
583 ;; ignored in interface buffer.
585 ;; `pr-buffer-verbose' Non-nil means to be verbose when editing a
586 ;; field in interface buffer.
588 ;; To set the above options you may:
590 ;; a) insert the code in your ~/.emacs, like:
592 ;; (setq pr-faces-p t)
594 ;; This way always keep your default settings when you enter a new Emacs
595 ;; session.
597 ;; b) or use `set-variable' in your Emacs session, like:
599 ;; M-x set-variable RET pr-faces-p RET t RET
601 ;; This way keep your settings only during the current Emacs session.
603 ;; c) or use customization, for example:
604 ;; click on menu-bar *Help* option,
605 ;; then click on *Customize*,
606 ;; then click on *Browse Customization Groups*,
607 ;; expand *PostScript* group,
608 ;; expand *Printing* group
609 ;; and then customize `printing' options.
610 ;; Through this way, you may choose if the settings are kept or not when
611 ;; you leave out the current Emacs session.
613 ;; d) or see the option value:
615 ;; C-h v pr-faces-p RET
617 ;; and click the *customize* hypertext button.
618 ;; Through this way, you may choose if the settings are kept or not when
619 ;; you leave out the current Emacs session.
621 ;; e) or invoke:
623 ;; M-x pr-customize RET
625 ;; and then customize `printing' options.
626 ;; Through this way, you may choose if the settings are kept or not when
627 ;; you leave out the current Emacs session.
629 ;; f) or use menu bar, for example:
630 ;; click on menu-bar *File* option,
631 ;; then click on *Printing*,
632 ;; then click on *Customize*,
633 ;; then click on *printing*
634 ;; and then customize `printing' options.
635 ;; Through this way, you may choose if the settings are kept or not when
636 ;; you leave out the current Emacs session.
639 ;; Menu Layout
640 ;; -----------
642 ;; The `printing' menu (Tools/Printing or File/Print) has the following layout:
644 ;; +-----------------------------+
645 ;; A 0 | Printing Interface |
646 ;; +-----------------------------+ +-A---------+ +-B------+
647 ;; I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
648 ;; 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
649 ;; 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
650 ;; +-----------------------------+ |Mode >|-- B |Other...|
651 ;; II 4 | Printify >|-----\ |File >|--\ +--------+
652 ;; 5 | Print >|---\ | |Despool... | |
653 ;; 6 | Text Printer: name >|-\ | | +-----------+ |
654 ;; +-----------------------------+ | | | +---------+ +------------+
655 ;; III 7 |[ ]Landscape | | | \-|Directory| | No Prep... | Ia
656 ;; 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
657 ;; 9 |[ ]Print Header Frame | | | |Region | | name >|- C
658 ;; 10 |[ ]Line Number | | | +---------+ +------------+
659 ;; 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
660 ;; 12 |[ ]Duplex | | \---|Directory| | 2-up... |
661 ;; 13 |[ ]Tumble | \--\ |Buffer | | 4-up... |
662 ;; 14 |[ ]Upside-Down | | |Region | | Other... |
663 ;; 15 | Print All Pages >|--\ | |Mode | +------------+
664 ;; +-----------------------------+ | | +---------+ |[ ]Landscape| Id
665 ;; IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
666 ;; 17 |[ ]Print with faces | | \--|( )name A| |[ ]Tumble | If
667 ;; 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
668 ;; +-----------------------------+ | |... |
669 ;; V 19 |[ ]Auto Region | | |(*)name |
670 ;; 20 |[ ]Auto Mode | | |... |
671 ;; 21 |[ ]Menu Lock | | +---------+ +--------------+
672 ;; +-----------------------------+ \------------------|(*)All Pages |
673 ;; VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
674 ;; 23 | Show Settings >|-------|printing| |( )Odd Pages |
675 ;; 24 | Help | |ps-print| |( )Even Sheets|
676 ;; +-----------------------------+ |lpr | |( )Odd Sheets |
677 ;; +--------+ +--------------+
679 ;; See `pr-visible-entry-list' for hiding some parts of the menu.
681 ;; The menu has the following sections:
683 ;; A. Interface:
685 ;; 0. You can use a buffer interface instead of menus. It looks like the
686 ;; customization buffer. Basically, it has the same options found in the
687 ;; menu and some extra options, all this on a buffer.
689 ;; I. PostScript printing:
691 ;; 1. You can generate a PostScript file (if you type C-u before activating
692 ;; menu) or PostScript temporary file for a directory, a buffer, a region
693 ;; or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
694 ;; after file generation, ghostview is activated using the file generated
695 ;; as argument. This option is disabled if spooling is on (option 16).
696 ;; Also, if you already have a PostScript file you can preview it.
697 ;; Instead of previewing each buffer, region or major mode at once, you
698 ;; can save temporarily the PostScript code generated in a buffer and
699 ;; preview it later. The option `Despool...' despools the PostScript
700 ;; spooling buffer in a temporary file and uses ghostview to preview it.
701 ;; If you type C-u before choosing this option, the PostScript code
702 ;; generated is saved in a file instead of saving in a temporary file.
703 ;; To spool the PostScript code generated you need to turn on the option
704 ;; 16. The option `Despool...' is enabled if spooling is on (option
705 ;; 16).
707 ;; NOTE 1: It's possible to customize a major mode printing, just declare
708 ;; the customization in `pr-mode-alist' and invoke some of
709 ;; `*-mode*' commands or select Mode option in Printing menu. An
710 ;; example for major mode usage is when you're using gnus (or mh,
711 ;; or rmail, etc.) and you're in the *Summary* buffer, if you
712 ;; forget to switch to the *Article* buffer before printing,
713 ;; you'll get a nicely formatted list of article subjects shows
714 ;; up at the printer. With major mode printing you don't need to
715 ;; switch from gnus *Summary* buffer first.
717 ;; NOTE 2: There are the following options for PostScript file
718 ;; processing:
719 ;; Ia. Print the file *No Preprocessing*, that is, send it
720 ;; directly to PostScript printer.
721 ;; Ib. PostScript utility processing selection.
722 ;; See `pr-ps-utility-alist' and `pr-setting-database' for
723 ;; documentation.
724 ;; Ic. Do n-up processing before printing.
725 ;; Id. Toggle on/off landscape for PostScript file processing.
726 ;; Ie. Toggle on/off duplex for PostScript file processing.
727 ;; If. Toggle on/off tumble for PostScript file processing.
729 ;; NOTE 3: Don't forget to download and install the utilities declared on
730 ;; `pr-ps-utility-alist'.
732 ;; 2. Operate the same way as option 1, but it sends directly the PostScript
733 ;; code (or put in a file, if you've typed C-u) or it uses ghostscript to
734 ;; print the PostScript file generated. It depends on option 18, if it's
735 ;; turned on, it uses ghostscript; otherwise, it sends directly to
736 ;; printer. If spooling is on (option 16), the PostScript code is saved
737 ;; temporarily in a buffer instead of printing it or saving it in a file.
738 ;; Also, if you already have a PostScript file you can print it. Instead
739 ;; of printing each buffer, region or major mode at once, you can save
740 ;; temporarily the PostScript code generated in a buffer and print it
741 ;; later. The option `Despool...' despools the PostScript spooling
742 ;; buffer directly on a printer. If you type C-u before choosing this
743 ;; option, the PostScript code generated is saved in a file instead of
744 ;; sending to printer. To spool the PostScript code generated you need
745 ;; to turn on the option 16. This option is enabled if spooling is on
746 ;; (option 16). See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
748 ;; 3. You can select a new PostScript printer to send PostScript code
749 ;; generated. For selection it's used all PostScript printers defined
750 ;; in `pr-ps-printer-alist' variable (see it for documentation).
751 ;; See also `pr-setting-database'.
753 ;; II. Text printing:
755 ;; 4. If you have control characters (character code from \000 to \037) in a
756 ;; buffer and you want to print them in a text printer, select this
757 ;; option. All control characters in your buffer or region will be
758 ;; replaced by a printable representation. The printable representations
759 ;; use ^ (for ASCII control characters) or hex. The characters tab,
760 ;; linefeed, space, return and formfeed are not affected. You don't need
761 ;; to select this option if you use any option of section I, the
762 ;; PostScript engine treats control characters properly.
764 ;; 5. If you want to print a directory, buffer, region or major mode in a
765 ;; text printer, select this option. See also the NOTE 1 on option 1.
767 ;; 6. You can select a new text printer to send text generated. For
768 ;; selection it's used all text printers defined in
769 ;; `pr-txt-printer-alist' variable (see it for documentation).
770 ;; See also `pr-setting-database'.
772 ;; III. PostScript page toggle options:
774 ;; 7. If you want a PostScript landscape printing, turn on this option.
776 ;; 8. If you want to have a header in each page in your PostScript code,
777 ;; turn on this option.
779 ;; 9. If you want to draw a gaudy frame around the header, turn on this
780 ;; option. This option is enabled if print header is on (option 8).
782 ;; 10. If you want that the line number is printed in your PostScript code,
783 ;; turn on this option.
785 ;; 11. If you want background zebra stripes in your PostScript code, turn on
786 ;; this option.
788 ;; 12. If you want a duplex printing and your PostScript printer has this
789 ;; feature, turn on this option.
791 ;; 13. If you turned on duplex printing, you can choose if you want to have
792 ;; a printing suitable for binding on the left or right (tumble off), or
793 ;; to have a printing suitable for binding at top or bottom (tumble on).
794 ;; This option is enabled if duplex is on (option 12).
796 ;; 14. If you want a PostScript upside-down printing, turn on this option.
798 ;; 15. With this option, you can choose if you want to print all pages, odd
799 ;; pages, even pages, odd sheets or even sheets.
800 ;; See also `ps-even-or-odd-pages'.
802 ;; IV. PostScript processing toggle options:
804 ;; 16. If you want to spool the PostScript code generated, turn on this
805 ;; option. To spool the PostScript code generated use option 2. You
806 ;; can despool later by choosing option 1 or 2, sub-option `Despool...'.
808 ;; 17. If you use colors in your buffers and want to see these colors on
809 ;; your PostScript code generated, turn on this option. If you have a
810 ;; black/white PostScript printer, these colors are displayed in gray
811 ;; scale by PostScript printer interpreter.
813 ;; 18. If you don't have a PostScript printer to send PostScript files, turn
814 ;; on this option. When this option is on, the ghostscript is used to
815 ;; print PostScript files. In GNU or Unix system, if ghostscript is set
816 ;; as a PostScript filter, you don't need to turn on this option.
818 ;; V. Printing customization:
820 ;; 19. If you want that region is automagically detected, turn on this
821 ;; option. Note that this will only work if you're using transient mark
822 ;; mode. When this option is on, the `*-buffer*' commands will behave
823 ;; like `*-region*' commands, that is, `*-buffer*' commands will print
824 ;; only the region marked instead of all buffer.
826 ;; 20. Turn this option on if you want that when current major-mode is
827 ;; declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
828 ;; behave like `*-mode*' commands.
830 ;; 21. If you want that Printing menu stays open while you are setting
831 ;; toggle options, turn on this option. The variables
832 ;; `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
833 ;; menu position, so don't forget to adjust these variables if menu
834 ;; position is not ok.
836 ;; VI. Customization:
838 ;; 22. Besides all options in section III, IV and V, you can customize much
839 ;; more PostScript options in `ps-print' option. Or you can customize
840 ;; some `lpr' options for text printing. Or customize `printing'
841 ;; options.
843 ;; 23. Show current settings for `printing', `ps-print' or `lpr'.
845 ;; 24. Quick help for printing menu layout.
848 ;; Option Settings
849 ;; ---------------
851 ;; Below it's shown only the main options that affect all `printing' package.
852 ;; Check all the settings below *BEFORE* running `printing' commands.
854 ;; * Example of setting for GNU or Unix system:
856 ;; (require 'printing)
857 ;; (setq pr-path-alist
858 ;; '((unix "." "~/bin" ghostview mpage PATH)
859 ;; (ghostview "$HOME/bin/gsview-dir")
860 ;; (mpage "$HOME/bin/mpage-dir")
861 ;; ))
862 ;; (setq pr-txt-name 'prt_06a)
863 ;; (setq pr-txt-printer-alist
864 ;; '((prt_06a "lpr" nil "prt_06a")
865 ;; (prt_07c nil nil "prt_07c")
866 ;; ))
867 ;; (setq pr-ps-name 'lps_06b)
868 ;; (setq pr-ps-printer-alist
869 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
870 ;; (lps_07c "lpr" nil nil "lps_07c")
871 ;; (lps_08c nil nil nil "lps_08c")
872 ;; ))
873 ;; (setq pr-temp-dir "/tmp/")
874 ;; (setq pr-gv-command "gv")
875 ;; (setq pr-gs-command "gs")
876 ;; (setq pr-gs-switches '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
877 ;; (setq pr-gs-device "uniprint")
878 ;; (setq pr-gs-resolution 300)
879 ;; (setq pr-ps-utility 'mpage)
880 ;; (setq pr-ps-utility-alist
881 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
882 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
883 ;; (inherits-from: . no-duplex))
884 ;; ))
885 ;; (setq pr-setting-database
886 ;; '((no-duplex
887 ;; nil nil nil
888 ;; (pr-file-duplex . nil)
889 ;; (pr-file-tumble . nil))
890 ;; ))
891 ;; (pr-update-menus t) ; update now printer and utility menus
893 ;; * Example of setting for Windows system:
895 ;; (require 'printing)
896 ;; (setq pr-path-alist
897 ;; '((windows "c:/applications/executables" PATH ghostview mpage)
898 ;; (ghostview "c:/gs/gsview-dir")
899 ;; (mpage "c:/mpage-dir")
900 ;; ))
901 ;; (setq pr-txt-name 'prt_06a)
902 ;; (setq pr-txt-printer-alist
903 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
904 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
905 ;; (PRN "" nil "PRN")
906 ;; (standard "redpr.exe" nil "")
907 ;; ))
908 ;; (setq pr-ps-name 'lps_06b)
909 ;; (setq pr-ps-printer-alist
910 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
911 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
912 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
913 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
914 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
915 ;; (LPT1 "" nil "" "LPT1:")
916 ;; (PRN "" nil "" "PRN")
917 ;; (standard "redpr.exe" nil "" "")
918 ;; ))
919 ;; (setq pr-temp-dir "C:/WINDOWS/TEMP/")
920 ;; (setq pr-gv-command "c:/gs/gsview/gsview32.exe")
921 ;; (setq pr-gs-command "c:/gs/gswin32.exe")
922 ;; (setq pr-gs-switches '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts"))
923 ;; (setq pr-gs-device "mswinpr2")
924 ;; (setq pr-gs-resolution 300)
925 ;; (setq pr-ps-utility 'psnup)
926 ;; (setq pr-ps-utility-alist
927 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " "
928 ;; nil (inherits-from: . no-duplex))
929 ;; ))
930 ;; (setq pr-setting-database
931 ;; '((no-duplex
932 ;; nil nil nil
933 ;; (pr-file-duplex . nil)
934 ;; (pr-file-tumble . nil))
935 ;; ))
936 ;; (pr-update-menus t) ; update now printer and utility menus
938 ;; NOTE: Don't forget to download and install the utilities declared on
939 ;; `pr-ps-utility-alist'.
942 ;; Utilities
943 ;; ---------
945 ;; `printing' package has the following utilities:
947 ;; `pr-setup' Return the current `printing' setup.
949 ;; `lpr-setup' Return the current `lpr' setup.
951 ;; `pr-update-menus' Update utility, PostScript and text printer menus.
953 ;; `pr-menu-bind' Install `printing' menu in the menubar.
956 ;; Below are some URL where you can find good utilities.
958 ;; * For `printing' package:
960 ;; printing `http://www.emacswiki.org/cgi-bin/emacs/download/printing.el'
961 ;; ps-print `http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'
963 ;; * For GNU or Unix system:
965 ;; gs, gv `http://www.gnu.org/software/ghostscript/ghostscript.html'
966 ;; enscript `http://people.ssh.fi/mtr/genscript/'
967 ;; psnup `http://www.knackered.org/angus/psutils/'
968 ;; mpage `http://www.mesa.nl/pub/mpage/'
970 ;; * For Windows system:
972 ;; gswin32, gsview32
973 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'
974 ;; gsprint `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
975 ;; enscript `http://people.ssh.fi/mtr/genscript/'
976 ;; psnup `http://gnuwin32.sourceforge.net/packages/psutils.htm'
977 ;; redmon `http://www.cs.wisc.edu/~ghost/redmon/'
980 ;; Acknowledgments
981 ;; ---------------
983 ;; Thanks to Stefan Monnier <monnier@iro.umontreal.ca> for GNU Emacs and XEmacs
984 ;; printing menu (in `pr-menu-spec') merging suggestion.
986 ;; Thanks to Lennart Borgman <lennart.borgman.073@student.lu.se> for gsprint
987 ;; suggestion (see tip 5 in section Tips).
989 ;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions:
990 ;; - directory processing.
991 ;; - `pr-path-alist' variable.
992 ;; - doc fix.
993 ;; - a lot of tests on Windows.
995 ;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests.
997 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging
998 ;; and for suggestions:
999 ;; - even/odd pages printing.
1000 ;; - ghostscript parameters for `pr-ps-printer-alist'.
1001 ;; - default printer name.
1002 ;; - completion functions.
1003 ;; - automagic region detection.
1004 ;; - menu entry hiding.
1005 ;; - fast fire PostScript printing command.
1006 ;; - `pr-path-style' variable.
1008 ;; Thanks to Kim F. Storm <storm@filanet.dk> for beta-test and for suggestions:
1009 ;; - PostScript Print and PostScript Print Preview merge.
1010 ;; - Tools/Printing menu.
1011 ;; - replace *-using-preview by *-using-ghostscript.
1012 ;; - printer selection.
1013 ;; - extra parameters for `pr-ps-printer-alist'.
1015 ;; Thanks to:
1016 ;; Frederic Corne <frederic.corne@erli.fr> print-nt.el
1017 ;; Tom Vogels <tov@ece.cmu.edu> mh-e-init.el
1018 ;; Matthew O. Persico <mpersico@erols.com> win32-ps-print.el
1019 ;; Volker Franz <volker.franz@tuebingen.mpg.de> ps-print-interface.el
1020 ;; And to all people who contributed with them.
1023 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1025 ;;; Code:
1028 (require 'lpr)
1029 (require 'ps-print)
1032 (and (string< ps-print-version "6.6.4")
1033 (error "`printing' requires `ps-print' package version 6.6.4 or later"))
1036 (defconst pr-cygwin-system
1037 (and ps-windows-system (getenv "OSTYPE")
1038 (string-match "cygwin" (getenv "OSTYPE"))))
1041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1042 ;; To avoid compilation gripes
1045 (or (fboundp 'subst-char-in-string) ; hacked from subr.el
1046 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1047 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1048 Unless optional argument INPLACE is non-nil, return a new string."
1049 (let ((i (length string))
1050 (newstr (if inplace string (copy-sequence string))))
1051 (while (> (setq i (1- i)) 0)
1052 (if (eq (aref newstr i) fromchar)
1053 (aset newstr i tochar)))
1054 newstr)))
1057 (or (fboundp 'make-temp-file) ; hacked from subr.el
1058 (defun make-temp-file (prefix &optional dir-flag suffix)
1059 "Create a temporary file.
1060 The returned file name (created by appending some random characters at the end
1061 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1062 is guaranteed to point to a newly created empty file.
1063 You can then use `write-region' to write new data into the file.
1065 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1067 If SUFFIX is non-nil, add that at the end of the file name."
1068 (let ((umask (default-file-modes))
1069 file)
1070 (unwind-protect
1071 (progn
1072 ;; Create temp files with strict access rights. It's easy to
1073 ;; loosen them later, whereas it's impossible to close the
1074 ;; time-window of loose permissions otherwise.
1075 (set-default-file-modes ?\700)
1076 (while (condition-case ()
1077 (progn
1078 (setq file
1079 (make-temp-name
1080 (expand-file-name prefix temporary-file-directory)))
1081 (if suffix
1082 (setq file (concat file suffix)))
1083 (if dir-flag
1084 (make-directory file)
1085 (write-region "" nil file nil 'silent nil 'excl))
1086 nil)
1087 (file-already-exists t))
1088 ;; the file was somehow created by someone else between
1089 ;; `make-temp-name' and `write-region', let's try again.
1090 nil)
1091 file)
1092 ;; Reset the umask.
1093 (set-default-file-modes umask)))))
1097 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1098 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1099 ;; XEmacs Definitions
1102 (cond
1103 ((featurep 'xemacs) ; XEmacs
1104 ;; XEmacs
1105 (defalias 'pr-f-set-keymap-parents 'set-keymap-parents)
1106 (defalias 'pr-f-set-keymap-name 'set-keymap-name)
1108 ;; XEmacs
1109 (defun pr-f-read-string (prompt initial history default)
1110 (let ((str (read-string prompt initial)))
1111 (if (and str (not (string= str "")))
1113 default)))
1115 ;; XEmacs
1116 (defvar zmacs-region-stays nil)
1118 ;; XEmacs
1119 (defun pr-keep-region-active ()
1120 (setq zmacs-region-stays t))
1122 ;; XEmacs
1123 (defun pr-region-active-p ()
1124 (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p)))
1126 ;; XEmacs
1127 (defun pr-menu-char-height ()
1128 (font-height (face-font 'default)))
1130 ;; XEmacs
1131 (defun pr-menu-char-width ()
1132 (font-width (face-font 'default)))
1134 ;; XEmacs
1135 (defmacro pr-xemacs-global-menubar (&rest body)
1136 `(save-excursion
1137 (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
1138 ;; be sure to access global menubar
1139 (set-buffer temp)
1140 ,@body
1141 (kill-buffer temp))))
1143 ;; XEmacs
1144 (defun pr-global-menubar (pr-menu-spec)
1145 ;; Menu binding
1146 (pr-xemacs-global-menubar
1147 (add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
1148 (setq pr-menu-print-item nil))
1150 ;; XEmacs
1151 (defvar current-mouse-event nil)
1152 (defun pr-menu-position (entry index horizontal)
1153 (make-event
1154 'button-release
1155 (list 'button 1
1156 'x (- (event-x-pixel current-mouse-event) ; X
1157 (* horizontal pr-menu-char-width))
1158 'y (- (event-y-pixel current-mouse-event) ; Y
1159 (* (pr-menu-index entry index) pr-menu-char-height)))))
1161 (defvar pr-menu-position nil)
1162 (defvar pr-menu-state nil)
1164 ;; XEmacs
1165 (defvar current-menubar nil) ; to avoid compilation gripes
1166 (defun pr-menu-lookup (path)
1167 (car (find-menu-item current-menubar (cons "Printing" path))))
1169 ;; XEmacs
1170 (defun pr-menu-lock (entry index horizontal state path)
1171 (when pr-menu-lock
1172 (or (and pr-menu-position (eq state pr-menu-state))
1173 (setq pr-menu-position (pr-menu-position entry index horizontal)
1174 pr-menu-state state))
1175 (let* ((menu (pr-menu-lookup path))
1176 (result (get-popup-menu-response menu pr-menu-position)))
1177 (and (misc-user-event-p result)
1178 (funcall (event-function result)
1179 (event-object result))))
1180 (setq pr-menu-position nil)))
1182 ;; XEmacs
1183 (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
1185 ;; XEmacs
1186 (defvar pr-ps-name-old "PostScript Printers")
1187 (defvar pr-txt-name-old "Text Printers")
1188 (defvar pr-ps-utility-old "PostScript Utility")
1189 (defvar pr-even-or-odd-old "Print All Pages")
1191 ;; XEmacs
1192 (defun pr-do-update-menus (&optional force)
1193 (pr-menu-alist pr-ps-printer-alist
1194 'pr-ps-name
1195 'pr-menu-set-ps-title
1196 '("Printing")
1197 'pr-ps-printer-menu-modified
1198 force
1199 pr-ps-name-old
1200 'postscript 2)
1201 (pr-menu-alist pr-txt-printer-alist
1202 'pr-txt-name
1203 'pr-menu-set-txt-title
1204 '("Printing")
1205 'pr-txt-printer-menu-modified
1206 force
1207 pr-txt-name-old
1208 'text 2)
1209 (let ((save-var pr-ps-utility-menu-modified))
1210 (pr-menu-alist pr-ps-utility-alist
1211 'pr-ps-utility
1212 'pr-menu-set-utility-title
1213 '("Printing" "PostScript Print" "File")
1214 'save-var
1215 force
1216 pr-ps-utility-old
1217 nil 1))
1218 (pr-menu-alist pr-ps-utility-alist
1219 'pr-ps-utility
1220 'pr-menu-set-utility-title
1221 '("Printing" "PostScript Preview" "File")
1222 'pr-ps-utility-menu-modified
1223 force
1224 pr-ps-utility-old
1225 nil 1)
1226 (pr-even-or-odd-pages ps-even-or-odd-pages force))
1228 ;; XEmacs
1229 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1230 entry index)
1231 (when (and alist (or force (symbol-value modified-sym)))
1232 (pr-xemacs-global-menubar
1233 (add-submenu menu-path
1234 (pr-menu-create name alist var-sym
1235 fun entry index)))
1236 (funcall fun (symbol-value var-sym))
1237 (set modified-sym nil)))
1239 ;; XEmacs
1240 (defun pr-relabel-menu-item (newname var-sym)
1241 (pr-xemacs-global-menubar
1242 (relabel-menu-item
1243 (list "Printing" (symbol-value var-sym))
1244 newname)
1245 (set var-sym newname)))
1247 ;; XEmacs
1248 (defun pr-menu-set-ps-title (value &optional item entry index)
1249 (pr-relabel-menu-item (format "PostScript Printer: %s" value)
1250 'pr-ps-name-old)
1251 (pr-ps-set-printer value)
1252 (and index
1253 (pr-menu-lock entry index 12 'toggle nil)))
1255 ;; XEmacs
1256 (defun pr-menu-set-txt-title (value &optional item entry index)
1257 (pr-relabel-menu-item (format "Text Printer: %s" value)
1258 'pr-txt-name-old)
1259 (pr-txt-set-printer value)
1260 (and index
1261 (pr-menu-lock entry index 12 'toggle nil)))
1263 ;; XEmacs
1264 (defun pr-menu-set-utility-title (value &optional item entry index)
1265 (pr-xemacs-global-menubar
1266 (let ((newname (format "%s" value)))
1267 (relabel-menu-item
1268 (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
1269 newname)
1270 (relabel-menu-item
1271 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
1272 newname)
1273 (setq pr-ps-utility-old newname)))
1274 (pr-ps-set-utility value)
1275 (and index
1276 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
1278 ;; XEmacs
1279 (defun pr-even-or-odd-pages (value &optional no-lock)
1280 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
1281 'pr-even-or-odd-old)
1282 (setq ps-even-or-odd-pages value)
1283 (or no-lock
1284 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
1287 (t ; GNU Emacs
1288 ;; Do nothing
1289 )) ; end cond featurep
1293 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1294 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1295 ;; GNU Emacs Definitions
1298 (cond
1299 ((featurep 'xemacs) ; XEmacs
1300 ;; Do nothing
1302 (t ; GNU Emacs
1303 ;; GNU Emacs
1304 (defalias 'pr-f-set-keymap-parents 'set-keymap-parent)
1305 (defalias 'pr-f-set-keymap-name 'ignore)
1306 (defalias 'pr-f-read-string 'read-string)
1308 ;; GNU Emacs
1309 (defvar deactivate-mark)
1311 ;; GNU Emacs
1312 (defun pr-keep-region-active ()
1313 (setq deactivate-mark nil))
1315 ;; GNU Emacs
1316 (defun pr-region-active-p ()
1317 (and pr-auto-region transient-mark-mode mark-active))
1319 ;; GNU Emacs
1320 (defun pr-menu-char-height ()
1321 (frame-char-height))
1323 ;; GNU Emacs
1324 (defun pr-menu-char-width ()
1325 (frame-char-width))
1327 ;; GNU Emacs
1328 ;; Menu binding
1329 ;; Replace existing "print" item by "Printing" item.
1330 ;; If you're changing this file, you'll load it a second,
1331 ;; third... time, but "print" item exists only in the first load.
1332 (eval-and-compile
1333 (cond
1334 ;; GNU Emacs 20
1335 ((< emacs-major-version 21)
1336 (defun pr-global-menubar (pr-menu-spec)
1337 (require 'easymenu)
1338 (easy-menu-change '("tools") "Printing" pr-menu-spec pr-menu-print-item)
1339 (when pr-menu-print-item
1340 (easy-menu-remove-item nil '("tools") pr-menu-print-item)
1341 (setq pr-menu-print-item nil
1342 pr-menu-bar (vector 'menu-bar 'tools
1343 (pr-get-symbol "Printing")))))
1345 ;; GNU Emacs 21 & 22
1347 (defun pr-global-menubar (pr-menu-spec)
1348 (require 'easymenu)
1349 (let ((menu-file (if (= emacs-major-version 21)
1350 '("menu-bar" "files") ; GNU Emacs 21
1351 '("menu-bar" "file")))) ; GNU Emacs 22 or higher
1352 (cond
1353 (pr-menu-print-item
1354 (easy-menu-add-item global-map menu-file
1355 (easy-menu-create-menu "Print" pr-menu-spec)
1356 "print-buffer")
1357 (dolist (item '("print-buffer" "print-region"
1358 "ps-print-buffer-faces" "ps-print-region-faces"
1359 "ps-print-buffer" "ps-print-region"))
1360 (easy-menu-remove-item global-map menu-file item))
1361 (setq pr-menu-print-item nil
1362 pr-menu-bar (vector 'menu-bar
1363 (pr-get-symbol (nth 1 menu-file))
1364 (pr-get-symbol "Print"))))
1366 (easy-menu-add-item global-map menu-file
1367 (easy-menu-create-menu "Print" pr-menu-spec)))
1371 (eval-and-compile
1372 (cond
1373 (ps-windows-system
1374 ;; GNU Emacs for Windows 9x/NT
1375 (defun pr-menu-position (entry index horizontal)
1376 (let ((pos (cdr (mouse-pixel-position))))
1377 (list
1378 (list (or (car pos) 0) ; X
1379 (- (or (cdr pos) 0) ; Y
1380 (* (pr-menu-index entry index) pr-menu-char-height)))
1381 (selected-frame)))) ; frame
1384 ;; GNU Emacs
1385 (defun pr-menu-position (entry index horizontal)
1386 (let ((pos (cdr (mouse-pixel-position))))
1387 (list
1388 (list (- (or (car pos) 0) ; X
1389 (* horizontal pr-menu-char-width))
1390 (- (or (cdr pos) 0) ; Y
1391 (* (pr-menu-index entry index) pr-menu-char-height)))
1392 (selected-frame)))) ; frame
1395 (defvar pr-menu-position nil)
1396 (defvar pr-menu-state nil)
1398 ;; GNU Emacs
1399 (defun pr-menu-lookup (path)
1400 (lookup-key global-map
1401 (if path
1402 (vconcat pr-menu-bar
1403 (mapcar 'pr-get-symbol
1404 (if (listp path)
1405 path
1406 (list path))))
1407 pr-menu-bar)))
1409 ;; GNU Emacs
1410 (defun pr-menu-lock (entry index horizontal state path)
1411 (when pr-menu-lock
1412 (or (and pr-menu-position (eq state pr-menu-state))
1413 (setq pr-menu-position (pr-menu-position entry index horizontal)
1414 pr-menu-state state))
1415 (let* ((menu (pr-menu-lookup path))
1416 (result (x-popup-menu pr-menu-position menu)))
1417 (and result
1418 (let ((command (lookup-key menu (vconcat result))))
1419 (if (fboundp command)
1420 (funcall command)
1421 (eval command)))))
1422 (setq pr-menu-position nil)))
1424 ;; GNU Emacs
1425 (defalias 'pr-update-mode-line 'force-mode-line-update)
1427 ;; GNU Emacs
1428 (defun pr-do-update-menus (&optional force)
1429 (pr-menu-alist pr-ps-printer-alist
1430 'pr-ps-name
1431 'pr-menu-set-ps-title
1432 "PostScript Printers"
1433 'pr-ps-printer-menu-modified
1434 force
1435 "PostScript Printers"
1436 'postscript 2)
1437 (pr-menu-alist pr-txt-printer-alist
1438 'pr-txt-name
1439 'pr-menu-set-txt-title
1440 "Text Printers"
1441 'pr-txt-printer-menu-modified
1442 force
1443 "Text Printers"
1444 'text 2)
1445 (let ((save-var pr-ps-utility-menu-modified))
1446 (pr-menu-alist pr-ps-utility-alist
1447 'pr-ps-utility
1448 'pr-menu-set-utility-title
1449 '("PostScript Print" "File" "PostScript Utility")
1450 'save-var
1451 force
1452 "PostScript Utility"
1453 nil 1))
1454 (pr-menu-alist pr-ps-utility-alist
1455 'pr-ps-utility
1456 'pr-menu-set-utility-title
1457 '("PostScript Preview" "File" "PostScript Utility")
1458 'pr-ps-utility-menu-modified
1459 force
1460 "PostScript Utility"
1461 nil 1)
1462 (pr-even-or-odd-pages ps-even-or-odd-pages force))
1464 ;; GNU Emacs
1465 (defun pr-menu-get-item (name-list)
1466 ;; NAME-LIST is a string or a list of strings.
1467 (or (listp name-list)
1468 (setq name-list (list name-list)))
1469 (and name-list
1470 (let* ((reversed (reverse name-list))
1471 (name (pr-get-symbol (car reversed)))
1472 (path (nreverse (cdr reversed)))
1473 (menu (lookup-key
1474 global-map
1475 (vconcat pr-menu-bar
1476 (mapcar 'pr-get-symbol path)))))
1477 (assq name (nthcdr 2 menu)))))
1479 ;; GNU Emacs
1480 (defvar pr-temp-menu nil)
1482 ;; GNU Emacs
1483 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
1484 entry index)
1485 (when (and alist (or force (symbol-value modified-sym)))
1486 (easy-menu-define pr-temp-menu nil ""
1487 (pr-menu-create name alist var-sym fun entry index))
1488 (let ((item (pr-menu-get-item menu-path)))
1489 (and item
1490 (let* ((binding (nthcdr 3 item))
1491 (key-binding (cdr binding)))
1492 (setcar binding pr-temp-menu)
1493 (and key-binding (listp (car key-binding))
1494 (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
1495 (funcall fun (symbol-value var-sym) item))))
1496 (set modified-sym nil)))
1498 ;; GNU Emacs
1499 (defun pr-menu-set-item-name (item name)
1500 (and item
1501 (setcar (nthcdr 2 item) name))) ; ITEM-NAME
1503 ;; GNU Emacs
1504 (defun pr-menu-set-ps-title (value &optional item entry index)
1505 (pr-menu-set-item-name (or item
1506 (pr-menu-get-item "PostScript Printers"))
1507 (format "PostScript Printer: %s" value))
1508 (pr-ps-set-printer value)
1509 (and index
1510 (pr-menu-lock entry index 12 'toggle nil)))
1512 ;; GNU Emacs
1513 (defun pr-menu-set-txt-title (value &optional item entry index)
1514 (pr-menu-set-item-name (or item
1515 (pr-menu-get-item "Text Printers"))
1516 (format "Text Printer: %s" value))
1517 (pr-txt-set-printer value)
1518 (and index
1519 (pr-menu-lock entry index 12 'toggle nil)))
1521 ;; GNU Emacs
1522 (defun pr-menu-set-utility-title (value &optional item entry index)
1523 (let ((name (symbol-name value)))
1524 (if item
1525 (pr-menu-set-item-name item name)
1526 (pr-menu-set-item-name
1527 (pr-menu-get-item
1528 '("PostScript Print" "File" "PostScript Utility"))
1529 name)
1530 (pr-menu-set-item-name
1531 (pr-menu-get-item
1532 '("PostScript Preview" "File" "PostScript Utility"))
1533 name)))
1534 (pr-ps-set-utility value)
1535 (and index
1536 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
1538 ;; GNU Emacs
1539 (defun pr-even-or-odd-pages (value &optional no-lock)
1540 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
1541 (cdr (assq value pr-even-or-odd-alist)))
1542 (setq ps-even-or-odd-pages value)
1543 (or no-lock
1544 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
1546 )) ; end cond featurep
1549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1550 ;; Customization Functions
1553 (defun pr-alist-custom-set (symbol value)
1554 "Set the value of custom variables for printer & utility selection."
1555 (set symbol value)
1556 (and (featurep 'printing) ; update only after printing is loaded
1557 (pr-update-menus t)))
1560 (defun pr-ps-utility-custom-set (symbol value)
1561 "Update utility menu entry."
1562 (set symbol value)
1563 (and (featurep 'printing) ; update only after printing is loaded
1564 (pr-menu-set-utility-title value)))
1567 (defun pr-ps-name-custom-set (symbol value)
1568 "Update `PostScript Printer:' menu entry."
1569 (set symbol value)
1570 (and (featurep 'printing) ; update only after printing is loaded
1571 (pr-menu-set-ps-title value)))
1574 (defun pr-txt-name-custom-set (symbol value)
1575 "Update `Text Printer:' menu entry."
1576 (set symbol value)
1577 (and (featurep 'printing) ; update only after printing is loaded
1578 (pr-menu-set-txt-title value)))
1581 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1582 ;; User Interface (I)
1585 (defgroup printing nil
1586 "Printing Utilities group."
1587 :tag "Printing Utilities"
1588 :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
1589 :prefix "pr-"
1590 :version "20"
1591 :group 'wp
1592 :group 'postscript)
1595 (defcustom pr-path-style
1596 (if (and (not pr-cygwin-system)
1597 ps-windows-system)
1598 'windows
1599 'unix)
1600 "*Specify which path style to use for external commands.
1602 Valid values are:
1604 windows Windows 9x/NT style (\\)
1606 unix Unix style (/)"
1607 :type '(choice :tag "Path style"
1608 (const :tag "Windows 9x/NT Style (\\)" :value windows)
1609 (const :tag "Unix Style (/)" :value unix))
1610 :version "20"
1611 :group 'printing)
1614 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1615 ;; Internal Functions (I)
1618 (defun pr-dosify-file-name (path)
1619 "Replace unix-style directory separator character with dos/windows one."
1620 (interactive "sPath: ")
1621 (if (eq pr-path-style 'windows)
1622 (subst-char-in-string ?/ ?\\ path)
1623 path))
1626 (defun pr-unixify-file-name (path)
1627 "Replace dos/windows-style directory separator character with unix one."
1628 (interactive "sPath: ")
1629 (if (eq pr-path-style 'windows)
1630 (subst-char-in-string ?\\ ?/ path)
1631 path))
1634 (defun pr-standard-file-name (path)
1635 "Ensure the proper directory separator depending on the OS.
1636 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
1637 separator; otherwise, ensure unix-style directory separator."
1638 (if (or pr-cygwin-system ps-windows-system)
1639 (subst-char-in-string ?/ ?\\ path)
1640 (subst-char-in-string ?\\ ?/ path)))
1643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1644 ;; User Interface (II)
1647 (defcustom pr-path-alist
1648 '((unix PATH)
1649 (cygwin PATH)
1650 (windows PATH))
1651 "*Specify an alist for command paths.
1653 It's used to find commands used for printing package, like gv, gs, gsview.exe,
1654 mpage, print.exe, etc. See also `pr-command' function.
1656 Each element has the form:
1658 (ENTRY DIRECTORY...)
1660 Where:
1662 ENTRY It's a symbol, used to identify this entry.
1663 There must exist at least one of the following entries:
1665 unix this entry is used when Emacs is running on GNU or
1666 Unix system.
1668 cygwin this entry is used when Emacs is running on Windows
1669 95/98/NT/2000 with Cygwin.
1671 windows this entry is used when Emacs is running on Windows
1672 95/98/NT/2000.
1674 DIRECTORY It should be a string or a symbol. If it's a symbol, it should
1675 exist an equal entry in `pr-path-alist'. If it's a string,
1676 it's considered a directory specification.
1678 The directory specification may contain:
1679 $var environment variable expansion
1680 ~/ tilde expansion
1681 ./ current directory
1682 ../ previous directory
1684 For example, let's say the home directory is /home/my and the
1685 current directory is /home/my/dir, so:
1687 THE ENTRY IS EXPANDED TO
1688 ~/entry /home/my/entry
1689 ./entry /home/my/dir/entry
1690 ../entry /home/my/entry
1691 $HOME/entry /home/my/entry
1692 $HOME/~/other/../my/entry /home/my/entry
1694 SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
1695 list and there isn't a `PATH' entry in `pr-path-alist' or the
1696 `PATH' entry has a null directory list, the PATH environment
1697 variable is used.
1699 Examples:
1701 * On GNU or Unix system:
1703 '((unix \".\" \"~/bin\" ghostview mpage PATH)
1704 (ghostview \"$HOME/bin/gsview-dir\")
1705 (mpage \"$HOME/bin/mpage-dir\")
1708 * On Windows system:
1710 '((windows \"c:/applications/executables\" PATH ghostview mpage)
1711 (ghostview \"c:/gs/gsview-dir\")
1712 (mpage \"c:/mpage-dir\")
1714 :type '(repeat
1715 (cons :tag ""
1716 (symbol :tag "Identifier ")
1717 (repeat :tag "Directory List"
1718 (choice :menu-tag "Directory"
1719 :tag "Directory"
1720 (string :value "")
1721 (symbol :value symbol)))))
1722 :version "20"
1723 :group 'printing)
1726 (defcustom pr-txt-name 'default
1727 "*Specify a printer for printing a text file.
1729 The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
1730 documentation).
1732 This variable should be modified by customization engine. If this variable is
1733 modified by other means (for example, a lisp function), use `pr-update-menus'
1734 function (see it for documentation) to update text printer menu."
1735 :type 'symbol
1736 :set 'pr-txt-name-custom-set
1737 :version "20"
1738 :group 'printing)
1741 (defcustom pr-txt-printer-alist
1742 (list (list 'default lpr-command nil
1743 (cond ((boundp 'printer-name) printer-name)
1744 (ps-windows-system "PRN")
1745 (t nil)
1747 ;; Examples:
1748 ;; * On GNU or Unix system:
1749 ;; '((prt_06a "lpr" nil "prt_06a")
1750 ;; (prt_07c nil nil "prt_07c")
1751 ;; )
1752 ;; * On Windows system:
1753 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
1754 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
1755 ;; (PRN "" nil "PRN")
1756 ;; (standard "redpr.exe" nil "")
1757 ;; )
1758 "*Specify an alist of all text printers (text printer database).
1760 The alist element has the form:
1762 (SYMBOL COMMAND SWITCHES NAME)
1764 Where:
1766 SYMBOL It's a symbol to identify a text printer. It's for
1767 `pr-txt-name' variable setting and for menu selection.
1768 Examples:
1769 'prt_06a
1770 'my_printer
1772 COMMAND Name of the program for printing a text file. On MS-DOS and
1773 MS-Windows systems, if the value is an empty string, then Emacs
1774 will write directly to the printer port given by NAME (see text
1775 below), that is, the NAME should be something like \"PRN\" or
1776 \"LPT1:\".
1777 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1778 COMMAND shouldn't be an empty string.
1779 The programs `print' and `nprint' (the standard print programs
1780 on Windows NT and Novell Netware respectively) are handled
1781 specially, using NAME as the destination for output; any other
1782 program is treated like `lpr' except that an explicit filename
1783 is given as the last argument.
1784 If COMMAND is nil, it's used the default printing program:
1785 `print' for Windows system, `lp' for lp system and `lpr' for
1786 all other systems. See also `pr-path-alist'.
1787 Examples:
1788 \"print\"
1789 \"lpr\"
1790 \"lp\"
1792 SWITCHES List of sexp's to pass as extra options for text printer
1793 program. It is recommended to set NAME (see text below)
1794 instead of including an explicit switch on this list.
1795 Example:
1796 . for lpr
1797 '(\"-#3\" \"-l\")
1800 NAME A string that specifies a text printer name.
1801 On Unix-like systems, a string value should be a name
1802 understood by lpr's -P option (or lp's -d option).
1803 On MS-DOS and MS-Windows systems, it is the name of a printer
1804 device or port. Typical non-default settings would be \"LPT1:\"
1805 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1806 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1807 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1808 printer. You can also set it to a name of a file, in which
1809 case the output gets appended to that file. If you want to
1810 discard the printed output, set this to \"NUL\".
1811 Examples:
1812 . for print.exe
1813 \"/D:\\\\\\\\host\\\\share-name\"
1814 \"LPT1:\"
1815 \"PRN\"
1817 . for lpr or lp
1818 \"share-name\"
1820 This variable should be modified by customization engine. If this variable is
1821 modified by other means (for example, a lisp function), use `pr-update-menus'
1822 function (see it for documentation) to update text printer menu.
1824 Examples:
1826 * On GNU or Unix system:
1828 '((prt_06a \"lpr\" nil \"prt_06a\")
1829 (prt_07c nil nil \"prt_07c\")
1832 * On Windows system:
1834 '((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1835 (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
1836 (PRN \"\" nil \"PRN\")
1837 (standard \"redpr.exe\" nil \"\")
1840 Useful links:
1842 * Information about the print command (print.exe)
1843 `http://www.computerhope.com/printhlp.htm'
1845 * RedMon - Redirection Port Monitor (redpr.exe)
1846 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1848 * Redirection Port Monitor (redpr.exe on-line help)
1849 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1851 * UNIX man pages: lpr (or type `man lpr')
1852 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1853 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1855 * UNIX man pages: lp (or type `man lp')
1856 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1857 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1859 :type '(repeat
1860 (list :tag "Text Printer"
1861 (symbol :tag "Printer Symbol Name")
1862 (string :tag "Printer Command")
1863 (repeat :tag "Printer Switches"
1864 (sexp :tag "Switch" :value ""))
1865 (choice :menu-tag "Printer Name"
1866 :tag "Printer Name"
1867 (const :tag "None" nil)
1868 string)))
1869 :set 'pr-alist-custom-set
1870 :version "20"
1871 :group 'printing)
1874 (defcustom pr-ps-name 'default
1875 "*Specify a printer for printing a PostScript file.
1877 This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
1878 documentation).
1880 This variable should be modified by customization engine. If this variable is
1881 modified by other means (for example, a lisp function), use `pr-update-menus'
1882 function (see it for documentation) to update PostScript printer menu."
1883 :type 'symbol
1884 :set 'pr-ps-name-custom-set
1885 :version "20"
1886 :group 'printing)
1889 (defcustom pr-ps-printer-alist
1890 (list (list 'default lpr-command nil
1891 (cond (ps-windows-system nil)
1892 (ps-lp-system "-d")
1893 (t "-P"))
1894 (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
1895 ;; Examples:
1896 ;; * On GNU or Unix system:
1897 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
1898 ;; (lps_07c "lpr" nil nil "lps_07c")
1899 ;; (lps_08c nil nil nil "lps_08c")
1900 ;; )
1901 ;; * On Windows system:
1902 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
1903 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
1904 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
1905 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
1906 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
1907 ;; (LPT1 "" nil "" "LPT1:")
1908 ;; (PRN "" nil "" "PRN")
1909 ;; (standard "redpr.exe" nil "" "")
1910 ;; )
1911 "*Specify an alist for all PostScript printers (PostScript printer database).
1913 The alist element has the form:
1915 (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
1917 Where:
1919 SYMBOL It's a symbol to identify a PostScript printer. It's for
1920 `pr-ps-name' variable setting and for menu selection.
1921 Examples:
1922 'prt_06a
1923 'my_printer
1925 COMMAND Name of the program for printing a PostScript file. On MS-DOS
1926 and MS-Windows systems, if the value is an empty string then
1927 Emacs will write directly to the printer port given by NAME
1928 (see text below), that is, the NAME should be something like
1929 \"PRN\" or \"LPT1:\".
1930 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1931 COMMAND shouldn't be an empty string.
1932 The programs `print' and `nprint' (the standard print programs
1933 on Windows NT and Novell Netware respectively) are handled
1934 specially, using NAME as the destination for output; any other
1935 program is treated like `lpr' except that an explicit filename
1936 is given as the last argument.
1937 If COMMAND is nil, it's used the default printing program:
1938 `print' for Windows system, `lp' for lp system and `lpr' for
1939 all other systems. See also `pr-path-alist'.
1940 Examples:
1941 \"print\"
1942 \"lpr\"
1943 \"lp\"
1944 \"cp\"
1945 \"gsprint\"
1947 SWITCHES List of sexp's to pass as extra options for PostScript printer
1948 program. It is recommended to set NAME (see text below)
1949 instead of including an explicit switch on this list.
1950 Example:
1951 . for lpr
1952 '(\"-#3\" \"-l\")
1955 . for gsprint.exe
1956 '(\"-all\" \"-twoup\")
1958 PRINTER-SWITCH A string that specifies PostScript printer name switch. If
1959 it's necessary to have a space between PRINTER-SWITCH and NAME,
1960 it should be inserted at the end of PRINTER-SWITCH string.
1961 If PRINTER-SWITCH is nil, it's used the default printer name
1962 switch: `/D:' for Windows system, `-d' for lp system and `-P'
1963 for all other systems.
1964 Examples:
1965 . for lpr
1966 \"-P \"
1968 . for lp
1969 \"-d \"
1971 . for print.exe
1972 \"/D:\"
1974 . for gsprint.exe
1975 \"-printer \"
1977 NAME A string that specifies a PostScript printer name.
1978 On Unix-like systems, a string value should be a name
1979 understood by lpr's -P option (or lp's -d option).
1980 On MS-DOS and MS-Windows systems, it is the name of a printer
1981 device or port. Typical non-default settings would be \"LPT1:\"
1982 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1983 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1984 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1985 printer. You can also set it to a name of a file, in which
1986 case the output gets appended to that file. If you want to
1987 discard the printed output, set this to \"NUL\".
1988 Examples:
1989 . for cp.exe
1990 \"\\\\\\\\host\\\\share-name\"
1992 . for print.exe or gsprint.exe
1993 \"/D:\\\\\\\\host\\\\share-name\"
1994 \"\\\\\\\\host\\\\share-name\"
1995 \"LPT1:\"
1996 \"PRN\"
1998 . for lpr or lp
1999 \"share-name\"
2001 DEFAULT It's a way to set default values when this entry is selected.
2002 It's a cons like:
2004 (VARIABLE . VALUE)
2006 Which associates VARIABLE with VALUE. When this entry is
2007 selected, it's executed the following command:
2009 (set VARIABLE (eval VALUE))
2011 Note that VALUE can be any valid lisp expression. So, don't
2012 forget to quote symbols and constant lists.
2013 If VARIABLE is the special keyword `inherits-from:', VALUE must
2014 be a symbol name setting defined in `pr-setting-database' from
2015 which the current setting inherits the context. Take care with
2016 circular inheritance.
2017 Examples:
2018 '(ps-landscape-mode . nil)
2019 '(ps-spool-duplex . t)
2020 '(pr-gs-device . (my-gs-device t))
2022 This variable should be modified by customization engine. If this variable is
2023 modified by other means (for example, a lisp function), use `pr-update-menus'
2024 function (see it for documentation) to update PostScript printer menu.
2026 Examples:
2028 * On GNU or Unix system:
2030 '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
2031 (lps_07c \"lpr\" nil nil \"lps_07c\")
2032 (lps_08c nil nil nil \"lps_08c\")
2035 * On Windows system:
2037 '((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
2038 (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
2039 (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
2040 (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
2041 (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
2042 (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
2043 (LPT1 \"\" nil \"\" \"LPT1:\")
2044 (PRN \"\" nil \"\" \"PRN\")
2045 (standard \"redpr.exe\" nil \"\" \"\")
2049 gsprint:
2051 You can use gsprint instead of ghostscript to print monochrome PostScript files
2052 in Windows. The gsprint utility documentation says that it is more efficient
2053 than ghostscript to print monochrome PostScript.
2055 To print non-monochrome PostScript file, the efficiency of ghostscript is
2056 similar to gsprint.
2058 Also the gsprint utility comes together with gsview distribution.
2060 As an example of gsprint declaration:
2062 (setq pr-ps-printer-alist
2063 '((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
2064 (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
2065 ;; some other printer declaration
2068 The example above declares that printer A prints all pages (-all) and two pages
2069 per sheet (-twoup). The printer B declaration does the same as the printer A
2070 declaration, the only difference is the printer name selection.
2072 There are other command line options like:
2074 -mono Render in monochrome as 1bit/pixel (only black and white).
2075 -grey Render in greyscale as 8bits/pixel.
2076 -color Render in color as 24bits/pixel.
2078 The default is `-mono'. So, printer A and B in the example above are using
2079 implicitly the `-mono' option. Note that in `-mono' no gray tone or color is
2080 printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
2081 are not printed.
2084 Useful links:
2086 * GSPRINT - Ghostscript print to Windows printer
2087 `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
2089 * Introduction to Ghostscript
2090 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2092 * How to use Ghostscript
2093 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2095 * Information about the print command (print.exe)
2096 `http://www.computerhope.com/printhlp.htm'
2098 * RedMon - Redirection Port Monitor (redpr.exe)
2099 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
2101 * Redirection Port Monitor (redpr.exe on-line help)
2102 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
2104 * UNIX man pages: lpr (or type `man lpr')
2105 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
2106 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
2108 * UNIX man pages: lp (or type `man lp')
2109 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
2110 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
2112 * GNU utilities for Win32 (cp.exe)
2113 `http://unxutils.sourceforge.net/'
2115 :type '(repeat
2116 (list
2117 :tag "PostScript Printer"
2118 (symbol :tag "Printer Symbol Name")
2119 (string :tag "Printer Command")
2120 (repeat :tag "Printer Switches"
2121 (sexp :tag "Switch" :value ""))
2122 (choice :menu-tag "Printer Name Switch"
2123 :tag "Printer Name Switch"
2124 (const :tag "None" nil)
2125 string)
2126 (choice :menu-tag "Printer Name"
2127 :tag "Printer Name"
2128 (const :tag "None" nil)
2129 string)
2130 (repeat
2131 :tag "Default Value List"
2132 :inline t
2133 (cons
2134 :tag ""
2135 (choice
2136 :menu-tag "Variable"
2137 :tag "Variable"
2138 (const :tag "Landscape" ps-landscape-mode)
2139 (const :tag "Print Header" ps-print-header)
2140 (const :tag "Print Header Frame" ps-print-header-frame)
2141 (const :tag "Line Number" ps-line-number)
2142 (const :tag "Zebra Stripes" ps-zebra-stripes)
2143 (const :tag "Duplex" ps-spool-duplex)
2144 (const :tag "Tumble" ps-spool-tumble)
2145 (const :tag "Upside-Down" ps-print-upside-down)
2146 (const :tag "PS File Landscape" pr-file-landscape)
2147 (const :tag "PS File Duplex" pr-file-duplex)
2148 (const :tag "PS File Tumble" pr-file-tumble)
2149 (const :tag "Auto Region" pr-auto-region)
2150 (const :tag "Auto Mode" pr-auto-mode)
2151 (const :tag "Ghostscript Device" pr-gs-device)
2152 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2153 (const :tag "inherits-from:" inherits-from:)
2154 (variable :tag "Other"))
2155 (sexp :tag "Value")))
2157 :set 'pr-alist-custom-set
2158 :version "20"
2159 :group 'printing)
2162 (defcustom pr-temp-dir
2163 (pr-dosify-file-name
2164 (if (boundp 'temporary-file-directory)
2165 (symbol-value 'temporary-file-directory)
2166 ;; hacked from `temporary-file-directory' variable in files.el
2167 (file-name-as-directory
2168 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
2169 (cond (ps-windows-system "c:/temp")
2170 ((memq system-type '(vax-vms axp-vms)) "SYS$SCRATCH:")
2171 (t "/tmp")
2172 )))))
2173 "*Specify a directory for temporary files during printing.
2175 See also `pr-ps-temp-file' and `pr-file-modes'."
2176 :type '(directory :tag "Temporary Directory")
2177 :version "20"
2178 :group 'printing)
2181 (defcustom pr-ps-temp-file "prspool-"
2182 "*Specify PostScript temporary file name prefix.
2184 See also `pr-temp-dir' and `pr-file-modes'."
2185 :type '(file :tag "PostScript Temporary File Name")
2186 :version "21"
2187 :group 'printing)
2190 ;; It uses 0600 as default instead of (default-file-modes).
2191 ;; So, by default, only the session owner have permission to deal with files
2192 ;; generated by `printing'.
2193 (defcustom pr-file-modes ?\600
2194 "*Specify the file permission bits for newly created files.
2196 It should be an integer; only the low 9 bits are used.
2198 See also `pr-temp-dir' and `pr-ps-temp-file'."
2199 :type '(integer :tag "File Permission Bits")
2200 :version "21.3"
2201 :group 'printing)
2204 (defcustom pr-gv-command
2205 (if ps-windows-system
2206 "gsview32.exe"
2207 "gv")
2208 "*Specify path and name of the gsview/gv utility.
2210 See also `pr-path-alist'.
2212 Useful links:
2214 * GNU gv manual
2215 `http://www.gnu.org/software/gv/manual/gv.html'
2217 * GSview Help
2218 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'
2220 * GSview Help - Common Problems
2221 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'
2223 * GSview Readme (compilation & installation)
2224 `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'
2226 * GSview (main site)
2227 `http://www.cs.wisc.edu/~ghost/gsview/index.htm'
2229 * Ghostscript, Ghostview and GSview
2230 `http://www.cs.wisc.edu/~ghost/'
2232 * Ghostview
2233 `http://www.cs.wisc.edu/~ghost/gv/index.htm'
2235 * gv 3.5, June 1997
2236 `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'
2238 * MacGSView (MacOS)
2239 `http://www.cs.wisc.edu/~ghost/macos/index.htm'
2241 :type '(string :tag "Ghostview Utility")
2242 :version "20"
2243 :group 'printing)
2246 (defcustom pr-gs-command
2247 (if ps-windows-system
2248 "gswin32.exe"
2249 "gs")
2250 "*Specify path and name of the ghostscript utility.
2252 See also `pr-path-alist'.
2254 Useful links:
2256 * Ghostscript, Ghostview and GSview
2257 `http://www.cs.wisc.edu/~ghost/'
2259 * Introduction to Ghostscript
2260 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2262 * How to use Ghostscript
2263 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2265 * Printer compatibility
2266 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2268 :type '(string :tag "Ghostscript Utility")
2269 :version "20"
2270 :group 'printing)
2273 (defcustom pr-gs-switches
2274 (if ps-windows-system
2275 '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
2276 '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
2277 "*Specify ghostscript switches. See the documentation on GS for more info.
2279 It's a list of strings, where each string is one or more ghostscript switches.
2281 A note on the gs switches:
2283 -q quiet
2284 -dNOPAUSE don't wait for user intervention
2285 -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
2286 -c quit it's added at the end to terminate gs
2288 To see ghostscript documentation for more information:
2290 * On GNU or Unix system:
2291 - for full documentation, type: man gs
2292 - for brief documentation, type: gs -h
2294 * On Windows system:
2295 - for full documentation, see in a browser the file
2296 c:/gstools/gs5.50/index.html, that is, the file index.html which is
2297 located in the same directory as gswin32.exe.
2298 - for brief documentation, type: gswin32.exe -h
2300 Useful links:
2302 * Introduction to Ghostscript
2303 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
2305 * How to use Ghostscript
2306 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
2308 * Printer compatibility
2309 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
2311 :type '(repeat (string :tag "Ghostscript Switch"))
2312 :version "20"
2313 :group 'printing)
2316 (defcustom pr-gs-device
2317 (if ps-windows-system
2318 "mswinpr2"
2319 "uniprint")
2320 "*Specify the ghostscript device switch value (-sDEVICE=).
2322 A note on the gs switches:
2324 -sDEVICE=djet500 the printer - works with HP DeskJet 540
2326 See `pr-gs-switches' for documentation.
2327 See also `pr-ps-printer-alist'."
2328 :type '(string :tag "Ghostscript Device")
2329 :version "20"
2330 :group 'printing)
2333 (defcustom pr-gs-resolution 300
2334 "*Specify ghostscript resolution switch value (-r).
2336 A note on the gs switches:
2338 -r300 resolution 300x300
2340 See `pr-gs-switches' for documentation.
2341 See also `pr-ps-printer-alist'."
2342 :type '(integer :tag "Ghostscript Resolution")
2343 :version "20"
2344 :group 'printing)
2347 (defcustom pr-print-using-ghostscript nil
2348 "*Non-nil means print using ghostscript.
2350 This is useful if you don't have a PostScript printer, so you could use the
2351 ghostscript to print a PostScript file.
2353 In GNU or Unix system, if ghostscript is set as a PostScript filter, this
2354 variable should be nil."
2355 :type 'boolean
2356 :version "20"
2357 :group 'printing)
2360 (defcustom pr-faces-p nil
2361 "*Non-nil means print with face attributes."
2362 :type 'boolean
2363 :version "20"
2364 :group 'printing)
2367 (defcustom pr-spool-p nil
2368 "*Non-nil means spool printing in a buffer."
2369 :type 'boolean
2370 :version "20"
2371 :group 'printing)
2374 (defcustom pr-file-landscape nil
2375 "*Non-nil means print PostScript file in landscape orientation."
2376 :type 'boolean
2377 :version "20"
2378 :group 'printing)
2381 (defcustom pr-file-duplex nil
2382 "*Non-nil means print PostScript file in duplex mode."
2383 :type 'boolean
2384 :version "20"
2385 :group 'printing)
2388 (defcustom pr-file-tumble nil
2389 "*Non-nil means print PostScript file in tumble mode.
2391 If tumble is off, produces a printing suitable for binding on the left or
2392 right.
2393 If tumble is on, produces a printing suitable for binding at the top or
2394 bottom."
2395 :type 'boolean
2396 :version "20"
2397 :group 'printing)
2400 (defcustom pr-auto-region t
2401 "*Non-nil means region is automagically detected.
2403 Note that this will only work if you're using transient mark mode.
2405 When this variable is non-nil, the `*-buffer*' commands will behave like
2406 `*-region*' commands, that is, `*-buffer*' commands will print only the region
2407 marked instead of all buffer."
2408 :type 'boolean
2409 :version "20"
2410 :group 'printing)
2413 (defcustom pr-auto-mode t
2414 "*Non-nil means major-mode specific printing is prefered over normal printing.
2416 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
2417 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
2418 `*-buffer*' commands will print the current buffer and `*-region*' commands
2419 will print the current region."
2420 :type 'boolean
2421 :version "20"
2422 :group 'printing)
2425 (defcustom pr-mode-alist
2426 '((mh-folder-mode ; mh summary buffer
2427 pr-mh-lpr-1 pr-mh-print-1
2429 (ps-article-author ps-article-subject)
2430 ("/pagenumberstring load" pr-article-date)
2433 (mh-letter-mode ; mh letter buffer
2434 pr-mh-lpr-2 pr-mh-print-2
2436 (ps-article-author ps-article-subject)
2437 ("/pagenumberstring load" pr-article-date)
2440 (rmail-summary-mode ; rmail summary buffer
2441 pr-rmail-lpr pr-rmail-print
2443 (ps-article-subject ps-article-author buffer-name)
2447 (rmail-mode ; rmail buffer
2448 pr-rmail-lpr pr-rmail-print
2450 (ps-article-subject ps-article-author buffer-name)
2454 (gnus-summary-mode ; gnus summary buffer
2455 pr-gnus-lpr pr-gnus-print
2457 (ps-article-subject ps-article-author gnus-newsgroup-name)
2461 (gnus-article-mode ; gnus article buffer
2462 pr-gnus-lpr pr-gnus-print
2464 (ps-article-subject ps-article-author gnus-newsgroup-name)
2468 (Info-mode ; Info buffer
2469 pr-mode-lpr pr-mode-print
2471 (ps-info-node ps-info-file)
2475 (vm-mode ; vm mode
2476 pr-vm-lpr pr-vm-print
2478 (ps-article-subject ps-article-author buffer-name)
2483 "*Specify an alist for a major-mode and printing functions.
2485 To customize a major mode printing, just declare the customization in
2486 `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
2487 mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
2488 *Summary* buffer, if you forget to switch to the *Article* buffer before
2489 printing, you'll get a nicely formatted list of article subjects shows up at
2490 the printer. With major mode printing you don't need to switch from gnus
2491 *Summary* buffer first.
2493 The elements have the following form:
2495 (MAJOR-MODE
2496 LPR-PRINT PS-PRINT
2497 HEADER-LINES
2498 LEFT-HEADER
2499 RIGHT-HEADER
2500 KILL-LOCAL-VARIABLE
2501 DEFAULT...)
2503 Where:
2505 MAJOR-MODE It's the major mode symbol.
2507 LPR-PRINT It's a symbol function for text printing. It's invoked with
2508 one argument:
2509 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2511 Usually LPR-PRINT function prepares the environment or buffer
2512 and then call the function `pr-mode-lpr' which it's used to
2513 process the buffer and send it to text printer.
2515 The `pr-mode-lpr' definition is:
2517 (pr-mode-lpr HEADER-LIST &optional FROM TO)
2519 Where HEADER-LIST is like the argument passed to LPR-PRINT.
2520 FROM and TO are the beginning and end markers, respectively,
2521 for a region. If FROM is nil, it's used (point-min); if TO is
2522 nil, it's used (point-max).
2524 PS-PRINT It's a symbol function for PostScript printing. It's invoked
2525 with 3 arguments: n-up printing, file name and the list:
2526 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2528 Usually PS-PRINT function prepares the environment or buffer
2529 and then call the function `pr-mode-print' which it's used to
2530 process the buffer and send it to PostScript printer.
2532 The `pr-mode-print' definition is:
2534 (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
2536 Where N-UP, FILENAME and HEADER-LIST are like the arguments
2537 passed to PS-PRINT. FROM and TO are the beginning and end
2538 markers, respectively, for a region. If TO is nil, it's used
2539 (point-max).
2541 HEADER-LINES It's the number of header lines; if is nil, it uses
2542 `ps-header-lines' value.
2544 LEFT-HEADER It's the left header part, it's a list of string, variable
2545 symbol or function symbol (with no argument); if is nil, it
2546 uses `ps-left-header' value.
2548 RIGHT-HEADER It's the right header part, it's a list of string, variable
2549 symbol or function symbol (with no argument); if is nil, it
2550 uses `ps-right-header' value.
2552 KILL-LOCAL-VARIABLE
2553 Non-nil means to kill all buffer local variable declared in
2554 DEFAULT (see below).
2556 DEFAULT It's a way to set default values when this entry is selected.
2557 It's a cons like:
2559 (VARIABLE-SYM . VALUE)
2561 Which associates VARIABLE-SYM with VALUE. When this entry is
2562 selected, it's executed the following command:
2564 (set (make-local-variable VARIABLE-SYM) (eval VALUE))
2566 Note that VALUE can be any valid lisp expression. So, don't
2567 forget to quote symbols and constant lists.
2568 If VARIABLE is the special keyword `inherits-from:', VALUE must
2569 be a symbol name setting defined in `pr-setting-database' from
2570 which the current setting inherits the context. Take care with
2571 circular inheritance.
2572 Examples:
2573 '(ps-landscape-mode . nil)
2574 '(ps-spool-duplex . t)
2575 '(pr-gs-device . (my-gs-device t))"
2576 :type '(repeat
2577 (list
2578 :tag ""
2579 (symbol :tag "Major Mode")
2580 (function :tag "Text Printing Function")
2581 (function :tag "PS Printing Function")
2582 (choice :menu-tag "Number of Header Lines"
2583 :tag "Number of Header Lines"
2584 (integer :tag "Number")
2585 (const :tag "Default Number" nil))
2586 (repeat :tag "Left Header List"
2587 (choice :menu-tag "Left Header"
2588 :tag "Left Header"
2589 string symbol))
2590 (repeat :tag "Right Header List"
2591 (choice :menu-tag "Right Header"
2592 :tag "Right Header"
2593 string symbol))
2594 (boolean :tag "Kill Local Variable At End")
2595 (repeat
2596 :tag "Default Value List"
2597 :inline t
2598 (cons
2599 :tag ""
2600 (choice
2601 :menu-tag "Variable"
2602 :tag "Variable"
2603 (const :tag "Landscape" ps-landscape-mode)
2604 (const :tag "Print Header" ps-print-header)
2605 (const :tag "Print Header Frame" ps-print-header-frame)
2606 (const :tag "Line Number" ps-line-number)
2607 (const :tag "Zebra Stripes" ps-zebra-stripes)
2608 (const :tag "Duplex" ps-spool-duplex)
2609 (const :tag "Tumble" ps-spool-tumble)
2610 (const :tag "Upside-Down" ps-print-upside-down)
2611 (const :tag "PS File Landscape" pr-file-landscape)
2612 (const :tag "PS File Duplex" pr-file-duplex)
2613 (const :tag "PS File Tumble" pr-file-tumble)
2614 (const :tag "Auto Region" pr-auto-region)
2615 (const :tag "Auto Mode" pr-auto-mode)
2616 (const :tag "Ghostscript Device" pr-gs-device)
2617 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2618 (const :tag "inherits-from:" inherits-from:)
2619 (variable :tag "Other"))
2620 (sexp :tag "Value")))
2622 :version "20"
2623 :group 'printing)
2626 (defcustom pr-ps-utility 'mpage
2627 "*Specify PostScript utility symbol.
2629 This utility symbol should be defined on `pr-ps-utility-alist' (see it for
2630 documentation).
2632 This variable should be modified by customization engine. If this variable is
2633 modified by other means (for example, a lisp function), use `pr-update-menus'
2634 function (see it for documentation) to update PostScript utility menu.
2636 NOTE: Don't forget to download and install the utilities declared on
2637 `pr-ps-utility-alist'."
2638 :type '(symbol :tag "PS File Utility")
2639 :set 'pr-ps-utility-custom-set
2640 :version "20"
2641 :group 'printing)
2644 (defcustom pr-ps-utility-alist
2645 '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2646 (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2647 (inherits-from: . no-duplex))
2649 ;; Examples:
2650 ;; * On GNU or Unix system:
2651 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2652 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2653 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2654 ;; )
2655 ;; * On Windows system:
2656 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2657 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2658 ;; )
2659 "*Specify an alist for PostScript utility processing (PS utility database).
2661 The alist element has the form:
2663 (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
2664 SWITCHES DEFAULT...)
2666 Where:
2668 SYMBOL It's a symbol to identify a PostScript utility. It's for
2669 `pr-ps-utility' variable setting and for menu selection.
2670 Examples:
2671 'mpage
2672 'psnup
2674 UTILITY Name of utility for processing a PostScript file.
2675 See also `pr-path-alist'.
2676 Examples:
2677 . for GNU or Unix system:
2678 \"mpage\"
2679 \"psnup -q\"
2681 . for Windows system:
2682 \"c:/psutils/psnup -q\"
2684 MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
2685 program. These options are necessary to process the utility
2686 program and must be placed before any other switches.
2687 Example:
2688 . for psnup:
2689 '(\"-q\")
2691 PAPERSIZE It's a format string to specify paper size switch.
2692 Example:
2693 . for mpage
2694 \"-b%s\"
2696 N-UP It's a format string to specify n-up switch.
2697 Example:
2698 . for psnup
2699 \"-%d\"
2701 LANDSCAPE It's a string to specify landscape switch. If the utility
2702 doesn't have landscape switch, set to nil.
2703 Example:
2704 . for psnup
2705 \"-l\"
2707 DUPLEX It's a string to specify duplex switch. If the utility doesn't
2708 have duplex switch, set to nil.
2709 Example:
2710 . for psnup
2713 TUMBLE It's a string to specify tumble switch. If the utility doesn't
2714 have tumble switch, set to nil.
2715 Example:
2716 . for psnup
2719 OUTPUT It's a string to specify how to generate an output file. Some
2720 utilities accept an output file option, but some others need
2721 output redirection or some other way to specify an output file.
2722 Example:
2723 . for psnup
2724 \" \" ; psnup ... input output
2726 . for mpage
2727 \">\" ; mpage ... input > output
2729 SWITCHES List of sexp's to pass as extra options to the PostScript utility
2730 program.
2731 Example:
2732 . for psnup
2733 '(\"-q\")
2736 DEFAULT It's a way to set default values when this entry is selected.
2737 It's a cons like:
2739 (VARIABLE . VALUE)
2741 Which associates VARIABLE with VALUE. When this entry is
2742 selected, it's executed the following command:
2744 (set VARIABLE (eval VALUE))
2746 Note that VALUE can be any valid lisp expression. So, don't
2747 forget to quote symbols and constant lists.
2748 If VARIABLE is the special keyword `inherits-from:', VALUE must
2749 be a symbol name setting defined in `pr-setting-database' from
2750 which the current setting inherits the context. Take care with
2751 circular inheritance.
2752 Examples:
2753 '(pr-file-landscape . nil)
2754 '(pr-file-duplex . t)
2755 '(pr-gs-device . (my-gs-device t))
2757 This variable should be modified by customization engine. If this variable is
2758 modified by other means (for example, a lisp function), use `pr-update-menus'
2759 function (see it for documentation) to update PostScript utility menu.
2761 NOTE: Don't forget to download and install the utilities declared on
2762 `pr-ps-utility-alist'.
2764 Examples:
2766 * On GNU or Unix system:
2768 '((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
2769 (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
2770 (pr-file-duplex . nil) (pr-file-tumble . nil))
2773 * On Windows system:
2775 '((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
2776 nil (pr-file-duplex . nil) (pr-file-tumble . nil))
2779 Useful links:
2781 * mpage download (GNU or Unix)
2782 `http://www.mesa.nl/pub/mpage/'
2784 * mpage documentation (GNU or Unix - or type `man mpage')
2785 `http://www.cs.umd.edu/faq/guides/manual_unix/node48.html'
2786 `http://www.rt.com/man/mpage.1.html'
2788 * psnup (Windows, GNU or Unix)
2789 `http://www.knackered.org/angus/psutils/'
2790 `http://gershwin.ens.fr/vdaniel/Doc-Locale/Outils-Gnu-Linux/PsUtils/'
2792 * psnup (PsUtils for Windows)
2793 `http://gnuwin32.sourceforge.net/packages/psutils.htm'
2795 * psnup documentation (GNU or Unix - or type `man psnup')
2796 `http://linux.about.com/library/cmd/blcmdl1_psnup.htm'
2797 `http://amath.colorado.edu/computing/software/man/psnup.html'
2799 * GNU Enscript (Windows, GNU or Unix)
2800 `http://people.ssh.com/mtr/genscript/'
2802 * GNU Enscript documentation (Windows, GNU or Unix)
2803 `http://people.ssh.com/mtr/genscript/enscript.man.html'
2804 (on GNU or Unix, type `man enscript')
2806 :type '(repeat
2807 (list :tag "PS File Utility"
2808 (symbol :tag "Utility Symbol")
2809 (string :tag "Utility Name")
2810 (repeat :tag "Must Utility Switches"
2811 (sexp :tag "Switch" :value ""))
2812 (choice :menu-tag "Paper Size"
2813 :tag "Paper Size"
2814 (const :tag "No Paper Size" nil)
2815 (string :tag "Paper Size Format"))
2816 (choice :menu-tag "N-Up"
2817 :tag "N-Up"
2818 (const :tag "No N-Up" nil)
2819 (string :tag "N-Up Format"))
2820 (choice :menu-tag "Landscape"
2821 :tag "Landscape"
2822 (const :tag "No Landscape" nil)
2823 (string :tag "Landscape Switch"))
2824 (choice :menu-tag "Duplex"
2825 :tag "Duplex"
2826 (const :tag "No Duplex" nil)
2827 (string :tag "Duplex Switch"))
2828 (choice :menu-tag "Tumble"
2829 :tag "Tumble"
2830 (const :tag "No Tumble" nil)
2831 (string :tag "Tumble Switch"))
2832 (string :tag "Output Separator")
2833 (repeat :tag "Utility Switches"
2834 (sexp :tag "Switch" :value ""))
2835 (repeat
2836 :tag "Default Value List"
2837 :inline t
2838 (cons
2839 :tag ""
2840 (choice
2841 :menu-tag "Variable"
2842 :tag "Variable"
2843 (const :tag "PS File Landscape" pr-file-landscape)
2844 (const :tag "PS File Duplex" pr-file-duplex)
2845 (const :tag "PS File Tumble" pr-file-tumble)
2846 (const :tag "Ghostscript Device" pr-gs-device)
2847 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2848 (const :tag "inherits-from:" inherits-from:)
2849 (variable :tag "Other"))
2850 (sexp :tag "Value")))
2852 :set 'pr-alist-custom-set
2853 :version "20"
2854 :group 'printing)
2857 (defcustom pr-menu-lock t
2858 "*Non-nil means menu is locked while selecting toggle options.
2860 See also `pr-menu-char-height' and `pr-menu-char-width'."
2861 :type 'boolean
2862 :version "20"
2863 :group 'printing)
2866 (defcustom pr-menu-char-height (pr-menu-char-height)
2867 "*Specify menu char height in pixels.
2869 This variable is used to guess which vertical position should be locked the
2870 menu, so don't forget to adjust it if menu position is not ok.
2872 See also `pr-menu-lock' and `pr-menu-char-width'."
2873 :type 'integer
2874 :version "20"
2875 :group 'printing)
2878 (defcustom pr-menu-char-width (pr-menu-char-width)
2879 "*Specify menu char width in pixels.
2881 This variable is used to guess which horizontal position should be locked the
2882 menu, so don't forget to adjust it if menu position is not ok.
2884 See also `pr-menu-lock' and `pr-menu-char-height'."
2885 :type 'integer
2886 :version "20"
2887 :group 'printing)
2890 (defcustom pr-setting-database
2891 '((no-duplex ; setting symbol name
2892 nil nil nil ; inherits local kill-local
2893 (pr-file-duplex . nil) ; settings
2894 (pr-file-tumble . nil))
2896 "*Specify an alist for settings in general.
2898 The elements have the following form:
2900 (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
2902 Where:
2904 SYMBOL It's a symbol to identify the setting group.
2906 INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
2907 setting from which the current setting inherits the context.
2908 If INHERITS is nil, means that there is no inheritance.
2909 This is a simple inheritance mechanism.
2911 Let's see an example to illustrate the inheritance mechanism:
2913 (setq pr-setting-database
2914 '((no-duplex ; setting symbol name
2915 nil ; inherits
2916 nil nil ; local kill-local
2917 (pr-file-duplex . nil) ; settings
2918 (pr-file-tumble . nil)
2920 (no-duplex-and-landscape ; setting symbol name
2921 no-duplex ; inherits
2922 nil nil ; local kill-local
2923 (pr-file-landscape . nil) ; settings
2926 The example above has two setting groups: no-duplex and
2927 no-duplex-and-landscape. When setting no-duplex is activated
2928 through `inherits-from:' (see `pr-ps-utility', `pr-mode-alist'
2929 and `pr-ps-printer-alist'), the variables pr-file-duplex and
2930 pr-file-tumble are both set to nil.
2932 Now when setting no-duplex-and-landscape is activated through
2933 `inherits-from:', the variable pr-file-landscape is set to nil
2934 and also the settings for no-duplex are done, because
2935 no-duplex-and-landscape inherits settings from no-duplex.
2937 Take care with circular inheritance. It's an error if circular
2938 inheritance happens.
2940 LOCAL Non-nil means that all settings for SYMBOL group will be
2941 declared local buffer.
2943 KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
2944 killed at end. It has effect only when LOCAL is non-nil.
2946 SETTING It's a cons like:
2948 (VARIABLE . VALUE)
2950 Which associates VARIABLE with VALUE. When this entry is
2951 selected, it's executed the following command:
2953 * If LOCAL is non-nil:
2954 (set (make-local-variable VARIABLE) (eval VALUE))
2956 * If LOCAL is nil:
2957 (set VARIABLE (eval VALUE))
2959 Note that VALUE can be any valid lisp expression. So, don't
2960 forget to quote symbols and constant lists.
2961 This setting is ignored if VARIABLE is equal to keyword
2962 `inherits-from:'.
2963 Examples:
2964 '(ps-landscape-mode . nil)
2965 '(ps-spool-duplex . t)
2966 '(pr-gs-device . (my-gs-device t))"
2967 :type '(repeat
2968 (list
2969 :tag ""
2970 (symbol :tag "Setting Name")
2971 (choice :menu-tag "Inheritance"
2972 :tag "Inheritance"
2973 (const :tag "No Inheritance" nil)
2974 (symbol :tag "Inherits From"))
2975 (boolean :tag "Local Buffer Setting")
2976 (boolean :tag "Kill Local Variable At End")
2977 (repeat
2978 :tag "Setting List"
2979 :inline t
2980 (cons
2981 :tag ""
2982 (choice
2983 :menu-tag "Variable"
2984 :tag "Variable"
2985 (const :tag "Landscape" ps-landscape-mode)
2986 (const :tag "Print Header" ps-print-header)
2987 (const :tag "Print Header Frame" ps-print-header-frame)
2988 (const :tag "Line Number" ps-line-number)
2989 (const :tag "Zebra Stripes" ps-zebra-stripes)
2990 (const :tag "Duplex" ps-spool-duplex)
2991 (const :tag "Tumble" ps-spool-tumble)
2992 (const :tag "Upside-Down" ps-print-upside-down)
2993 (const :tag "PS File Landscape" pr-file-landscape)
2994 (const :tag "PS File Duplex" pr-file-duplex)
2995 (const :tag "PS File Tumble" pr-file-tumble)
2996 (const :tag "Auto Region" pr-auto-region)
2997 (const :tag "Auto Mode" pr-auto-mode)
2998 (const :tag "Ghostscript Device" pr-gs-device)
2999 (const :tag "Ghostscript Resolution" pr-gs-resolution)
3000 (variable :tag "Other"))
3001 (sexp :tag "Value")))
3003 :version "20"
3004 :group 'printing)
3007 (defcustom pr-visible-entry-list
3008 '(postscript text postscript-options postscript-process printing help)
3009 "*Specify a list of Printing menu visible entries.
3011 Valid values with the corresponding menu parts are:
3013 +------------------------------+
3014 | Printing Interface |
3015 +------------------------------+
3016 `postscript' | PostScript Preview >|
3017 | PostScript Print >|
3018 | PostScript Printer: name >|
3019 +------------------------------+
3020 `text' | Printify >|
3021 | Print >|
3022 | Text Printer: name >|
3023 +------------------------------+
3024 `postscript-options' |[ ] Landscape |
3025 |[ ] Print Header |
3026 |[ ] Print Header Frame |
3027 |[ ] Line Number |
3028 |[ ] Zebra Stripes |
3029 |[ ] Duplex |
3030 |[ ] Tumble |
3031 |[ ] Upside-Down |
3032 | Print All Pages >|
3033 +------------------------------+
3034 `postscript-process' |[ ] Spool Buffer |
3035 |[ ] Print with faces |
3036 |[ ] Print via Ghostscript |
3037 +------------------------------+
3038 `printing' |[ ] Auto Region |
3039 |[ ] Auto Mode |
3040 |[ ] Menu Lock |
3041 +------------------------------+
3042 `help' | Customize >|
3043 | Show Settings >|
3044 | Help |
3045 +------------------------------+
3047 Any other value is ignored."
3048 :type '(repeat :tag "Menu Visible Part"
3049 (choice :menu-tag "Menu Part"
3050 :tag "Menu Part"
3051 (const postscript)
3052 (const text)
3053 (const postscript-options)
3054 (const postscript-process)
3055 (const printing)
3056 (const help)))
3057 :version "20"
3058 :group 'printing)
3061 (defcustom pr-delete-temp-file t
3062 "*Non-nil means delete temporary files.
3064 Set `pr-delete-temp-file' to nil, if the following message (or a similar)
3065 happens when printing:
3067 Error: could not open \"c:\\temp\\prspool.ps\" for reading."
3068 :type 'boolean
3069 :version "20"
3070 :group 'printing)
3073 (defcustom pr-list-directory nil
3074 "*Non-nil means list directory when processing a directory.
3076 That is, any subdirectories (and the superdirectory) of the directory (given as
3077 argument of functions below) are also printed (as dired-mode listings).
3079 It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
3080 `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
3081 and `pr-txt-directory'."
3082 :type 'boolean
3083 :version "20"
3084 :group 'printing)
3087 (defcustom pr-buffer-name "*Printing Interface*"
3088 "*Specify the name of the buffer interface for printing package.
3090 It's used by `pr-interface'."
3091 :type 'string
3092 :version "20"
3093 :group 'printing)
3096 (defcustom pr-buffer-name-ignore
3097 (list (regexp-quote pr-buffer-name) ; ignore printing interface buffer
3098 "^ .*$") ; ignore invisible buffers
3099 "*Specify a regexp list for buffer names to be ignored in interface buffer.
3101 NOTE: Case is important for matching, that is, `case-fold-search' is always
3102 nil.
3104 It's used by `pr-interface'."
3105 :type '(repeat (regexp :tag "Buffer Name Regexp"))
3106 :version "20"
3107 :group 'printing)
3110 (defcustom pr-buffer-verbose t
3111 "*Non-nil means to be verbose when editing a field in interface buffer.
3113 It's used by `pr-interface'."
3114 :type 'boolean
3115 :version "20"
3116 :group 'printing)
3119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3120 ;; Internal Variables
3123 (defvar pr-txt-command nil
3124 "Name of program for printing a text file.
3125 See `pr-txt-printer-alist'.")
3128 (defvar pr-txt-switches nil
3129 "List of sexp's to pass as extra options to the text printer program.
3130 See `pr-txt-printer-alist'.")
3133 (defvar pr-txt-printer nil
3134 "Specify text printer name.
3135 See `pr-txt-printer-alist'.")
3138 (defvar pr-ps-command nil
3139 "Name of program for printing a PostScript file.
3140 See `pr-ps-printer-alist'.")
3143 (defvar pr-ps-switches nil
3144 "List of sexp's to pass as extra options to the PostScript printer program.
3145 See `pr-ps-printer-alist'.")
3148 (defvar pr-ps-printer-switch nil
3149 "Specify PostScript printer name switch.
3150 See `pr-ps-printer-alist'.")
3153 (defvar pr-ps-printer nil
3154 "Specify PostScript printer name.
3155 See `pr-ps-printer-alist'.")
3158 (defvar pr-menu-bar nil
3159 "Specify Printing menu-bar entry.")
3162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3163 ;; Macros
3166 (defmacro pr-save-file-modes (&rest body)
3167 "Set temporally file modes to `pr-file-modes'."
3168 `(let ((pr--default-file-modes (default-file-modes))) ; save default
3169 (set-default-file-modes pr-file-modes)
3170 ,@body
3171 (set-default-file-modes pr--default-file-modes))) ; restore default
3174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3175 ;; Keys & Menus
3178 (defsubst pr-visible-p (key)
3179 (memq key pr-visible-entry-list))
3182 (defsubst pr-mode-alist-p ()
3183 (cdr (assq major-mode pr-mode-alist)))
3186 (defsubst pr-auto-mode-p ()
3187 (and pr-auto-mode (pr-mode-alist-p)))
3190 (defsubst pr-using-ghostscript-p ()
3191 (and pr-print-using-ghostscript (not pr-spool-p)))
3194 (defalias 'pr-get-symbol
3195 (if (fboundp 'easy-menu-intern) ; hacked from easymenu.el
3196 'easy-menu-intern
3197 (lambda (s) (if (stringp s) (intern s) s))))
3200 (defconst pr-menu-spec
3201 ;; Menu mapping:
3202 ;; unfortunately XEmacs doesn't support :active for submenus,
3203 ;; only for items.
3204 ;; So, it uses :included instead of :active.
3205 ;; Also, XEmacs doesn't support :help tag.
3206 (let ((pr-:active (if (featurep 'xemacs)
3207 :included ; XEmacs
3208 :active)) ; GNU Emacs
3209 (pr-:help (if (featurep 'xemacs)
3210 'ignore ; XEmacs
3211 #'(lambda (text) (list :help text))))) ; GNU Emacs
3213 ["Printing Interface" pr-interface
3214 ,@(funcall
3215 pr-:help "Use buffer interface instead of menu interface")]
3216 "--"
3217 ("PostScript Preview" :included (pr-visible-p 'postscript)
3218 ,@(funcall
3219 pr-:help "Preview PostScript instead of sending to printer")
3220 ("Directory" ,pr-:active (not pr-spool-p)
3221 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
3222 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
3223 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
3224 ["Other..." (pr-ps-directory-preview nil nil nil t)
3225 :keys "\\[pr-ps-buffer-preview]"])
3226 ("Buffer" ,pr-:active (not pr-spool-p)
3227 ["1-up" (pr-ps-buffer-preview 1 t) t]
3228 ["2-up" (pr-ps-buffer-preview 2 t) t]
3229 ["4-up" (pr-ps-buffer-preview 4 t) t]
3230 ["Other..." (pr-ps-buffer-preview nil t)
3231 :keys "\\[pr-ps-buffer-preview]"])
3232 ("Region" ,pr-:active (and (not pr-spool-p) (ps-mark-active-p))
3233 ["1-up" (pr-ps-region-preview 1 t) t]
3234 ["2-up" (pr-ps-region-preview 2 t) t]
3235 ["4-up" (pr-ps-region-preview 4 t) t]
3236 ["Other..." (pr-ps-region-preview nil t)
3237 :keys "\\[pr-ps-region-preview]"])
3238 ("Mode" ,pr-:active (and (not pr-spool-p) (pr-mode-alist-p))
3239 ["1-up" (pr-ps-mode-preview 1 t) t]
3240 ["2-up" (pr-ps-mode-preview 2 t) t]
3241 ["4-up" (pr-ps-mode-preview 4 t) t]
3242 ["Other..." (pr-ps-mode-preview nil t)
3243 :keys "\\[pr-ps-mode-preview]"])
3244 ("File"
3245 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
3246 :keys "\\[pr-ps-file-preview]"
3247 ,@(funcall
3248 pr-:help "Preview PostScript file")]
3249 "--"
3250 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
3251 ,@(funcall
3252 pr-:help "Select PostScript utility")]
3253 "--"
3254 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
3255 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
3256 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
3257 ["Other..." (pr-ps-file-up-preview nil t t)
3258 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
3259 "--"
3260 ["Landscape" pr-toggle-file-landscape-menu
3261 :style toggle :selected pr-file-landscape
3262 ,@(funcall
3263 pr-:help "Toggle landscape for PostScript file")
3264 :active pr-ps-utility-alist]
3265 ["Duplex" pr-toggle-file-duplex-menu
3266 :style toggle :selected pr-file-duplex
3267 ,@(funcall
3268 pr-:help "Toggle duplex for PostScript file")
3269 :active pr-ps-utility-alist]
3270 ["Tumble" pr-toggle-file-tumble-menu
3271 :style toggle :selected pr-file-tumble
3272 ,@(funcall
3273 pr-:help "Toggle tumble for PostScript file")
3274 :active (and pr-file-duplex pr-ps-utility-alist)])
3275 ["Despool..." (call-interactively 'pr-despool-preview)
3276 :active pr-spool-p :keys "\\[pr-despool-preview]"
3277 ,@(funcall
3278 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3279 ("PostScript Print" :included (pr-visible-p 'postscript)
3280 ,@(funcall
3281 pr-:help "Send PostScript to printer or file (C-u)")
3282 ("Directory"
3283 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
3284 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
3285 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
3286 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
3287 :keys "\\[pr-ps-buffer-ps-print]"])
3288 ("Buffer"
3289 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
3290 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
3291 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
3292 ["Other..." (pr-ps-buffer-ps-print nil t)
3293 :keys "\\[pr-ps-buffer-ps-print]"])
3294 ("Region" ,pr-:active (ps-mark-active-p)
3295 ["1-up" (pr-ps-region-ps-print 1 t) t]
3296 ["2-up" (pr-ps-region-ps-print 2 t) t]
3297 ["4-up" (pr-ps-region-ps-print 4 t) t]
3298 ["Other..." (pr-ps-region-ps-print nil t)
3299 :keys "\\[pr-ps-region-ps-print]"])
3300 ("Mode" ,pr-:active (pr-mode-alist-p)
3301 ["1-up" (pr-ps-mode-ps-print 1 t) t]
3302 ["2-up" (pr-ps-mode-ps-print 2 t) t]
3303 ["4-up" (pr-ps-mode-ps-print 4 t) t]
3304 ["Other..." (pr-ps-mode-ps-print nil t)
3305 :keys "\\[pr-ps-mode-ps-print]"])
3306 ("File"
3307 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
3308 :keys "\\[pr-ps-file-ps-print]"
3309 ,@(funcall
3310 pr-:help "Send PostScript file to printer")]
3311 "--"
3312 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
3313 ,@(funcall
3314 pr-:help "Select PostScript utility")]
3315 "--"
3316 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
3317 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
3318 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
3319 ["Other..." (pr-ps-file-up-ps-print nil t t)
3320 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
3321 "--"
3322 ["Landscape" pr-toggle-file-landscape-menu
3323 :style toggle :selected pr-file-landscape
3324 ,@(funcall
3325 pr-:help "Toggle landscape for PostScript file")
3326 :active pr-ps-utility-alist]
3327 ["Duplex" pr-toggle-file-duplex-menu
3328 :style toggle :selected pr-file-duplex
3329 ,@(funcall
3330 pr-:help "Toggle duplex for PostScript file")
3331 :active pr-ps-utility-alist]
3332 ["Tumble" pr-toggle-file-tumble-menu
3333 :style toggle :selected pr-file-tumble
3334 ,@(funcall
3335 pr-:help "Toggle tumble for PostScript file")
3336 :active (and pr-file-duplex pr-ps-utility-alist)])
3337 ["Despool..." (call-interactively 'pr-despool-ps-print)
3338 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
3339 ,@(funcall
3340 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3341 ["PostScript Printers" pr-update-menus
3342 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
3343 ,@(funcall
3344 pr-:help "Select PostScript printer")]
3345 "--"
3346 ("Printify" :included (pr-visible-p 'text)
3347 ,@(funcall
3348 pr-:help
3349 "Replace non-printing chars with printable representations.")
3350 ["Directory" pr-printify-directory t]
3351 ["Buffer" pr-printify-buffer t]
3352 ["Region" pr-printify-region (ps-mark-active-p)])
3353 ("Print" :included (pr-visible-p 'text)
3354 ,@(funcall
3355 pr-:help "Send text to printer")
3356 ["Directory" pr-txt-directory t]
3357 ["Buffer" pr-txt-buffer t]
3358 ["Region" pr-txt-region (ps-mark-active-p)]
3359 ["Mode" pr-txt-mode (pr-mode-alist-p)])
3360 ["Text Printers" pr-update-menus
3361 :active pr-txt-printer-alist :included (pr-visible-p 'text)
3362 ,@(funcall
3363 pr-:help "Select text printer")]
3364 "--"
3365 ["Landscape" pr-toggle-landscape-menu
3366 :style toggle :selected ps-landscape-mode
3367 :included (pr-visible-p 'postscript-options)]
3368 ["Print Header" pr-toggle-header-menu
3369 :style toggle :selected ps-print-header
3370 :included (pr-visible-p 'postscript-options)]
3371 ["Print Header Frame" pr-toggle-header-frame-menu
3372 :style toggle :selected ps-print-header-frame :active ps-print-header
3373 :included (pr-visible-p 'postscript-options)]
3374 ["Line Number" pr-toggle-line-menu
3375 :style toggle :selected ps-line-number
3376 :included (pr-visible-p 'postscript-options)]
3377 ["Zebra Stripes" pr-toggle-zebra-menu
3378 :style toggle :selected ps-zebra-stripes
3379 :included (pr-visible-p 'postscript-options)]
3380 ["Duplex" pr-toggle-duplex-menu
3381 :style toggle :selected ps-spool-duplex
3382 :included (pr-visible-p 'postscript-options)]
3383 ["Tumble" pr-toggle-tumble-menu
3384 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
3385 :included (pr-visible-p 'postscript-options)]
3386 ["Upside-Down" pr-toggle-upside-down-menu
3387 :style toggle :selected ps-print-upside-down
3388 :included (pr-visible-p 'postscript-options)]
3389 ("Print All Pages" :included (pr-visible-p 'postscript-options)
3390 ,@(funcall
3391 pr-:help "Select odd/even pages/sheets to print")
3392 ["All Pages" (pr-even-or-odd-pages nil)
3393 :style radio :selected (eq ps-even-or-odd-pages nil)]
3394 ["Even Pages" (pr-even-or-odd-pages 'even-page)
3395 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
3396 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
3397 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
3398 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
3399 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
3400 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
3401 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
3402 "--"
3403 ["Spool Buffer" pr-toggle-spool-menu
3404 :style toggle :selected pr-spool-p
3405 :included (pr-visible-p 'postscript-process)
3406 ,@(funcall
3407 pr-:help "Toggle PostScript spooling")]
3408 ["Print with faces" pr-toggle-faces-menu
3409 :style toggle :selected pr-faces-p
3410 :included (pr-visible-p 'postscript-process)
3411 ,@(funcall
3412 pr-:help "Toggle PostScript printing with faces")]
3413 ["Print via Ghostscript" pr-toggle-ghostscript-menu
3414 :style toggle :selected pr-print-using-ghostscript
3415 :included (pr-visible-p 'postscript-process)
3416 ,@(funcall
3417 pr-:help "Toggle PostScript generation using ghostscript")]
3418 "--"
3419 ["Auto Region" pr-toggle-region-menu
3420 :style toggle :selected pr-auto-region
3421 :included (pr-visible-p 'printing)]
3422 ["Auto Mode" pr-toggle-mode-menu
3423 :style toggle :selected pr-auto-mode
3424 :included (pr-visible-p 'printing)]
3425 ["Menu Lock" pr-toggle-lock-menu
3426 :style toggle :selected pr-menu-lock
3427 :included (pr-visible-p 'printing)]
3428 "--"
3429 ("Customize" :included (pr-visible-p 'help)
3430 ["printing" pr-customize t]
3431 ["ps-print" ps-print-customize t]
3432 ["lpr" lpr-customize t])
3433 ("Show Settings" :included (pr-visible-p 'help)
3434 ["printing" pr-show-pr-setup t]
3435 ["ps-print" pr-show-ps-setup t]
3436 ["lpr" pr-show-lpr-setup t])
3437 ["Help" pr-help :active t :included (pr-visible-p 'help)]
3441 (defvar pr-menu-print-item "print"
3442 "Non-nil means that menu binding was not done.
3444 Used by `pr-menu-bind' and `pr-update-menus'.")
3447 (defun pr-menu-bind ()
3448 "Install `printing' menu in the menubar.
3450 On Emacs 20, it replaces the Tools/Print menu by Tools/Printing menu.
3452 On Emacs 21 and 22, it replaces the File/Print* menu entries by File/Print
3453 menu.
3455 Calls `pr-update-menus' to adjust menus."
3456 (interactive)
3457 (pr-global-menubar pr-menu-spec)
3458 (pr-update-menus t))
3461 ;; Key binding
3462 (let ((pr-print-key (if (featurep 'xemacs)
3463 'f22 ; XEmacs
3464 'print))) ; GNU Emacs
3465 (global-set-key `[,pr-print-key] 'pr-ps-fast-fire)
3466 ;; Well, M-print and S-print are used because in my keyboard S-print works
3467 ;; and M-print doesn't. But M-print can work in other keyboard.
3468 (global-set-key `[(meta ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3469 (global-set-key `[(shift ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3470 ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
3471 ;; and C-print doesn't. But C-print can work in other keyboard.
3472 (global-set-key `[(control ,pr-print-key)] 'pr-txt-fast-fire)
3473 (global-set-key `[(control meta ,pr-print-key)] 'pr-txt-fast-fire))
3476 ;;; You can also use something like:
3477 ;;;(global-set-key "\C-ci" 'pr-interface)
3478 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
3479 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
3480 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
3481 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
3482 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
3483 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
3486 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3487 ;; Help Message
3490 (defconst pr-help-message
3491 (concat "printing.el version " pr-version
3492 " ps-print.el version " ps-print-version
3493 "\n\n
3494 Menu Layout
3495 -----------
3497 The `printing' menu (Tools/Printing or File/Print) has the following layout:
3499 +-----------------------------+
3500 A 0 | Printing Interface |
3501 +-----------------------------+ +-A---------+ +-B------+
3502 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
3503 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
3504 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
3505 +-----------------------------+ |Mode >|-- B |Other...|
3506 II 4 | Printify >|-----\\ |File >|--\\ +--------+
3507 5 | Print >|---\\ | |Despool... | |
3508 6 | Text Printer: name >|-\\ | | +-----------+ |
3509 +-----------------------------+ | | | +---------+ +------------+
3510 III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
3511 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
3512 9 |[ ]Print Header Frame | | | |Region | | name >|- C
3513 10 |[ ]Line Number | | | +---------+ +------------+
3514 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
3515 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
3516 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
3517 14 |[ ]Upside-Down | | |Region | | Other... |
3518 15 | Print All Pages >|--\\ | |Mode | +------------+
3519 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
3520 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
3521 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
3522 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
3523 +-----------------------------+ | |... |
3524 V 19 |[ ]Auto Region | | |(*)name |
3525 20 |[ ]Auto Mode | | |... |
3526 21 |[ ]Menu Lock | | +---------+ +--------------+
3527 +-----------------------------+ \\------------------|(*)All Pages |
3528 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
3529 23 | Show Settings >|-------|printing| |( )Odd Pages |
3530 24 | Help | |ps-print| |( )Even Sheets|
3531 +-----------------------------+ |lpr | |( )Odd Sheets |
3532 +--------+ +--------------+
3534 See `pr-visible-entry-list' for hiding some parts of the menu.
3536 The menu has the following sections:
3538 A. Interface:
3540 0. You can use a buffer interface instead of menus. It looks like the
3541 customization buffer. Basically, it has the same options found in the
3542 menu and some extra options, all this on a buffer.
3544 I. PostScript printing:
3546 1. You can generate a PostScript file (if you type C-u before activating
3547 menu) or PostScript temporary file for a directory, a buffer, a region
3548 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
3549 after file generation, ghostview is activated using the file generated
3550 as argument. This option is disabled if spooling is on (option 16).
3551 Also, if you already have a PostScript file you can preview it.
3552 Instead of previewing each buffer, region or major mode at once, you
3553 can save temporarily the PostScript code generated in a buffer and
3554 preview it later. The option `Despool...' despools the PostScript
3555 spooling buffer in a temporary file and uses ghostview to preview it.
3556 If you type C-u before choosing this option, the PostScript code
3557 generated is saved in a file instead of saving in a temporary file. To
3558 spool the PostScript code generated you need to turn on the option 16.
3559 The option `Despool...' is enabled if spooling is on (option 16).
3561 NOTE 1: It's possible to customize a major mode printing, just declare
3562 the customization in `pr-mode-alist' and invoke some of
3563 `*-mode*' commands or select Mode option in Printing menu. An
3564 example for major mode usage is when you're using gnus (or mh,
3565 or rmail, etc.) and you're in the *Summary* buffer, if you
3566 forget to switch to the *Article* buffer before printing,
3567 you'll get a nicely formatted list of article subjects shows
3568 up at the printer. With major mode printing you don't need to
3569 switch from gnus *Summary* buffer first.
3571 NOTE 2: There are the following options for PostScript file processing:
3572 Ia. Print the file *No Preprocessing*, that is, send it
3573 directly to PostScript printer.
3574 Ib. PostScript utility processing selection.
3575 See `pr-ps-utility-alist' and `pr-setting-database' for
3576 documentation.
3577 Ic. Do n-up processing before printing.
3578 Id. Toggle on/off landscape for PostScript file processing.
3579 Ie. Toggle on/off duplex for PostScript file processing.
3580 If. Toggle on/off tumble for PostScript file processing.
3582 NOTE 3: Don't forget to download and install the utilities declared on
3583 `pr-ps-utility-alist'.
3585 2. Operate the same way as option 1, but it sends directly the PostScript
3586 code (or put in a file, if you've typed C-u) or it uses ghostscript to
3587 print the PostScript file generated. It depends on option 18, if it's
3588 turned on, it uses ghostscript; otherwise, it sends directly to
3589 printer. If spooling is on (option 16), the PostScript code is saved
3590 temporarily in a buffer instead of printing it or saving it in a file.
3591 Also, if you already have a PostScript file you can print it.
3592 Instead of printing each buffer, region or major mode at once, you can
3593 save temporarily the PostScript code generated in a buffer and print it
3594 later. The option `Despool...' despools the PostScript spooling buffer
3595 directly on a printer. If you type C-u before choosing this option,
3596 the PostScript code generated is saved in a file instead of sending it to
3597 the printer. To spool the PostScript code generated you need to turn on
3598 option 16. This option is enabled if spooling is on (option 16).
3599 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
3601 3. You can select a new PostScript printer to send PostScript code
3602 generated. For selection it's used all PostScript printers defined
3603 in `pr-ps-printer-alist' variable (see it for documentation).
3604 See also `pr-setting-database'.
3606 II. Text printing:
3608 4. If you have control characters (character code from \\000 to \\037) in a
3609 buffer and you want to print them in a text printer, select this
3610 option. All control characters in your buffer or region will be
3611 replaced by a printable representation. The printable representations
3612 use ^ (for ASCII control characters) or hex. The characters tab,
3613 linefeed, space, return and formfeed are not affected.
3614 You don't need to select this option if you use any option of section
3615 I, the PostScript engine treats control characters properly.
3617 5. If you want to print a directory, buffer, region or major mode in a
3618 text printer, select this option. See also the NOTE 1 on option 1.
3620 6. You can select a new text printer to send text generated. For
3621 selection it's used all text printers defined in `pr-txt-printer-alist'
3622 variable (see it for documentation).
3623 See also `pr-setting-database'.
3625 III. PostScript page toggle options:
3627 7. If you want a PostScript landscape printing, turn on this option.
3629 8. If you want to have a header in each page in your PostScript code,
3630 turn on this option.
3632 9. If you want to draw a gaudy frame around the header, turn on this
3633 option. This option is enabled if print header is on (option 8).
3635 10. If you want that the line number is printed in your PostScript code,
3636 turn on this option.
3638 11. If you want background zebra stripes in your PostScript code, turn on
3639 this option.
3641 12. If you want a duplex printing and your PostScript printer has this
3642 feature, turn on this option.
3644 13. If you turned on duplex printing, you can choose if you want to have a
3645 printing suitable for binding on the left or right (tumble off), or to
3646 have a printing suitable for binding at top or bottom (tumble on).
3647 This option is enabled if duplex is on (option 12).
3649 14. If you want a PostScript upside-down printing, turn on this option.
3651 15. With this option, you can choose if you want to print all pages, odd
3652 pages, even pages, odd sheets or even sheets.
3653 See also `ps-even-or-odd-pages'.
3655 IV. PostScript processing toggle options:
3657 16. If you want to spool the PostScript code generated, turn on this
3658 option. To spool the PostScript code generated use option 2. You can
3659 despool later by choosing option 1 or 2, sub-option `Despool...'.
3661 17. If you use colors in your buffers and want to see these colors on your
3662 PostScript code generated, turn on this option. If you have a
3663 black/white PostScript printer, these colors are displayed in gray
3664 scale by PostScript printer interpreter.
3666 18. If you don't have a PostScript printer to send PostScript files, turn
3667 on this option. When this option is on, the ghostscript is used to
3668 print PostScript files. In GNU or Unix system, if ghostscript is set
3669 as a PostScript filter, you don't need to turn on this option.
3671 V. Printing customization:
3673 19. If you want that region is automagically detected, turn on this
3674 option. Note that this will only work if you're using transient mark
3675 mode. When this option is on, the `*-buffer*' commands will behave
3676 like `*-region*' commands, that is, `*-buffer*' commands will print
3677 only the region marked instead of all buffer.
3679 20. Turn this option on if you want that when current major-mode is
3680 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3681 behave like `*-mode*' commands.
3683 21. If you want that Printing menu stays open while you are setting
3684 toggle options, turn on this option. The variables
3685 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3686 menu position, so don't forget to adjust these variables if menu
3687 position is not ok.
3689 VI. Customization:
3691 22. Besides all options in section III, IV and V, you can customize much
3692 more PostScript options in `ps-print' option. Or you can customize
3693 some `lpr' options for text printing. Or customize `printing'
3694 options.
3696 23. Show current settings for `printing', `ps-print' or `lpr'.
3698 24. Quick help for printing menu layout.
3700 "Printing help message.")
3703 (defconst pr-interface-help-message
3704 (concat "printing.el version " pr-version
3705 " ps-print.el version " ps-print-version
3706 "\n\n
3707 The printing interface buffer has the same functionality as the printing menu.
3708 The major difference is that the states (like sending PostScript generated to a
3709 file, n-up printing, etc.) are set and saved between priting buffer
3710 activation. Also, the landscape, duplex and tumble values are the same for
3711 PostScript file and directory/buffer/region/mode processing; using menu, there
3712 are different value sets for PostScript file and directory/buffer/region/mode
3713 processing.
3715 The printing interface buffer has the following sections:
3717 1. Print:
3719 Here you can choose to print/preview a buffer, a directory or a PostScript
3720 file:
3722 1a. Buffer:
3724 * Buffer List:
3725 Select a buffer from the current buffer list.
3727 * Region:
3728 If it's on, this means that the selected buffer has an active region,
3729 so you can turn on/off, as you wish.
3730 If it's off when a buffer is selected, this means that the selected
3731 buffer has no active region, so it'll not be possible to turn it on.
3732 If you want to process the region, let this option on.
3733 If you want to process the whole buffer, let this option off.
3735 * Mode:
3736 If it's on, this means that the selected buffer major mode is declared
3737 for major mode processing, so you can turn on/off, as you wish.
3738 If it's off when a buffer is selected, this means that the selected
3739 buffer major mode isn't declared for major mode processing, so it'll
3740 not be possible to turn it on.
3741 If you want the major mode processing, let this option on.
3742 If you don't want the major mode processing, let this option off.
3744 NOTE 1: It's possible to customize a major mode printing, just declare
3745 the customization in `pr-mode-alist' and invoke some of
3746 `*-mode*' commands or select Mode option in Printing menu. An
3747 example for major mode usage is when you're using gnus (or mh,
3748 or rmail, etc.) and you're in the *Summary* buffer, if you
3749 forget to switch to the *Article* buffer before printing,
3750 you'll get a nicely formatted list of article subjects shows
3751 up at the printer. With major mode printing you don't need to
3752 switch from gnus *Summary* buffer first.
3754 1b. Directory:
3756 * Directory:
3757 Specify a valid directory path.
3759 * File Regexp:
3760 Specify a file name regexp. All file names in the directory that
3761 match with regexp will be printed/previewed. An empty file name
3762 regexp means to print/preview all files in the directory.
3764 * List Directory Entry:
3765 If it's turned on, list directory entries besides file entries.
3767 1c. PostScript file:
3769 * PostScript File:
3770 Specify an existent PostScript file to print/preview.
3772 * PostScript Utility:
3773 Select a PostScript utility.
3774 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3776 NOTE 2: Don't forget to download and install the utilities declared on
3777 `pr-ps-utility-alist'.
3779 * No Preprocessing:
3780 If it's turned on, don't use the PostScript utility to preprocess the
3781 PostScript file before printing/previewing.
3783 2. PostScript printer:
3785 * PostScript Printer:
3786 You can select a new PostScript printer to send PostScript code
3787 generated. For selection it's used all PostScript printers defined
3788 in `pr-ps-printer-alist' variable (see it for documentation).
3789 See also `pr-setting-database'.
3791 * Despool:
3792 If spooling is on, you can turn it on/off, as you wish.
3793 If spooling is off, it'll not be possible to turn it on.
3794 If it's turned on, specify to despools the PostScript spooling buffer in
3795 a temporary file or in the selected PostScript file when
3796 printing/previewing.
3798 * Preview:
3799 Preview the PostScript generated.
3801 * Print:
3802 Print the PostScript generated.
3804 * Quit:
3805 Quit from printing interface buffer.
3807 * Send to Printer/Temporary File:
3808 If it's turned on, the PostScript generated is sent directly to
3809 PostScript printer or, for previewing, to a temporary file.
3811 * Send to File:
3812 Specify a file name to send the PostScript generated.
3814 * N-Up:
3815 Specify n-up printing.
3817 3. Text printer:
3819 * Text Printer:
3820 Select a new text printer to send text generated. For selection it's used
3821 all text printers defined in `pr-txt-printer-alist' variable (see it for
3822 documentation). See also `pr-setting-database'.
3824 * Printify:
3825 If you have control characters (character code from \\000 to \\037) in a
3826 buffer and you want to print them in a text printer, select this
3827 option. All control characters in your buffer or region will be
3828 replaced by a printable representation. The printable representations
3829 use ^ (for ASCII control characters) or hex. The characters tab,
3830 linefeed, space, return and formfeed are not affected.
3831 You don't need to select this option if you use any option of section
3832 I, the PostScript engine treats control characters properly.
3834 * Print:
3835 To print a directory, buffer, region or major mode in a
3836 text printer, select this option. See also the NOTE 1 on section 1.
3838 * Quit:
3839 Quit from printing interface buffer.
3841 4. Settings:
3843 There are 3 setting columns:
3845 4a. First column (left column):
3847 * Landscape:
3848 PostScript landscape printing.
3850 * Print Header:
3851 To have a header in each page in your PostScript code.
3853 * Print Header Frame:
3854 To draw a gaudy frame around the header.
3856 * Line Number:
3857 The line number is printed in your PostScript code.
3859 * Zebra Stripes:
3860 Background zebra stripes in your PostScript code.
3862 * Duplex:
3863 Duplex printing (if your PostScript printer has this feature).
3865 * Tumble:
3866 If duplex printing is on, you can choose if you want to have a
3867 printing suitable for binding on the left or right (tumble off), or to
3868 have a printing suitable for binding at top or bottom (tumble on).
3870 * Upside-Down:
3871 PostScript upside-down printing.
3873 4b. Second column (middle column):
3875 * Auto Region:
3876 If you want that region is automagically detected, turn on this
3877 option. Note that this will only work if you're using transient mark
3878 mode. When this option is on, the `*-buffer*' commands will behave
3879 like `*-region*' commands, that is, `*-buffer*' commands will print
3880 only the region marked instead of all buffer.
3882 * Auto Mode:
3883 Turn this option on if you want that when current major-mode is
3884 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3885 behave like `*-mode*' commands.
3887 * Menu Lock:
3888 If you want that Printing menu stays open while you are setting
3889 toggle options, turn on this option. The variables
3890 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3891 menu position, so don't forget to adjust these variables if menu
3892 position is not ok.
3894 * Spool Buffer:
3895 To spool the PostScript code generated. You can despool later by
3896 setting Despool option on PostScript printer section.
3898 * Print with faces:
3899 If you use colors in your buffers and want to see these colors on your
3900 PostScript code generated, turn on this option. If you have a
3901 black/white PostScript printer, these colors are displayed in gray
3902 scale by PostScript printer interpreter.
3904 * Print via Ghostscript:
3905 If you don't have a PostScript printer to send PostScript files, turn
3906 on this option. When this option is on, the ghostscript is used to
3907 print PostScript files. In GNU or Unix system, if ghostscript is set
3908 as a PostScript filter, you don't need to turn on this option.
3910 * Parity Page Menu:
3911 To print all pages, odd pages, even pages, odd sheets or even sheets.
3912 See also `ps-even-or-odd-pages'.
3914 4c. Third column (right column):
3916 * Verbose:
3917 That is, to be verbose when editing a field in interface buffer.
3919 5. Customize:
3921 Besides all options in section 4, you can customize much more PostScript
3922 options in `ps-print' option. Or you can customize some `lpr' options for
3923 text printing. Or customize `printing' options.
3925 6. Show settings:
3927 Show current settings for `printing', `ps-print' or `lpr'.
3929 7. Help:
3931 Quick help for printing interface buffer and printing menu layout. You can
3932 also quit the printing interface buffer or kill all printing help buffer.
3934 "Printing buffer interface help message.")
3937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3938 ;; Commands
3941 ;;;###autoload
3942 (defun pr-interface (&optional buffer)
3943 "Activate the printing interface buffer.
3945 If BUFFER is nil, the current buffer is used for printing.
3947 For more information, type \\[pr-interface-help]."
3948 (interactive)
3949 (save-excursion
3950 (set-buffer (or buffer (current-buffer)))
3951 (pr-create-interface)))
3954 ;;;###autoload
3955 (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3956 "Preview directory using ghostview.
3958 Interactively, the command prompts for N-UP printing number, a directory, a
3959 file name regexp for matching and, when you use a prefix argument (C-u), the
3960 command prompts the user for a file name, and saves the PostScript image in
3961 that file instead of saving it in a temporary file.
3963 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3964 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3965 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3966 save the image in a temporary file. If FILENAME is a string, save the
3967 PostScript image in a file with that name. If FILENAME is t, prompts for a
3968 file name.
3970 See also documentation for `pr-list-directory'."
3971 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3972 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3973 (pr-prompt "PS preview dir"))
3974 (setq filename (pr-ps-file filename))
3975 (pr-ps-file-list n-up dir file-regexp filename)
3976 (or pr-spool-p
3977 (pr-ps-file-preview filename)))
3980 ;;;###autoload
3981 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3982 "Print directory using PostScript through ghostscript.
3984 Interactively, the command prompts for N-UP printing number, a directory, a
3985 file name regexp for matching and, when you use a prefix argument (C-u), the
3986 command prompts the user for a file name, and saves the PostScript image in
3987 that file instead of saving it in a temporary file.
3989 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3990 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3991 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3992 save the image in a temporary file. If FILENAME is a string, save the
3993 PostScript image in a file with that name. If FILENAME is t, prompts for a
3994 file name.
3996 See also documentation for `pr-list-directory'."
3997 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3998 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3999 (pr-prompt "PS print dir GS"))
4000 (let ((file (pr-ps-file filename)))
4001 (pr-ps-file-list n-up dir file-regexp file)
4002 (pr-ps-file-using-ghostscript file)
4003 (or filename (pr-delete-file file))))
4006 ;;;###autoload
4007 (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
4008 "Print directory using PostScript printer.
4010 Interactively, the command prompts for N-UP printing number, a directory, a
4011 file name regexp for matching and, when you use a prefix argument (C-u), the
4012 command prompts the user for a file name, and saves the PostScript image in
4013 that file instead of saving it in a temporary file.
4015 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4016 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4017 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4018 save the image in a temporary file. If FILENAME is a string, save the
4019 PostScript image in a file with that name. If FILENAME is t, prompts for a
4020 file name.
4022 See also documentation for `pr-list-directory'."
4023 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
4024 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4025 (pr-prompt "PS print dir"))
4026 (let ((file (pr-ps-file filename)))
4027 (pr-ps-file-list n-up dir file-regexp file)
4028 (pr-ps-file-print file)
4029 (or filename (pr-delete-file file))))
4032 ;;;###autoload
4033 (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
4034 "Print directory using PostScript printer or through ghostscript.
4036 It depends on `pr-print-using-ghostscript'.
4038 Interactively, the command prompts for N-UP printing number, a directory, a
4039 file name regexp for matching and, when you use a prefix argument (C-u), the
4040 command prompts the user for a file name, and saves the PostScript image in
4041 that file instead of saving it in a temporary file.
4043 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4044 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4045 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4046 save the image in a temporary file. If FILENAME is a string, save the
4047 PostScript image in a file with that name. If FILENAME is t, prompts for a
4048 file name.
4050 See also documentation for `pr-list-directory'."
4051 (interactive (pr-interactive-ps-dir-args
4052 (pr-prompt (pr-prompt-gs "PS print dir"))))
4053 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4054 (pr-prompt (pr-prompt-gs "PS print dir")))
4055 (if (pr-using-ghostscript-p)
4056 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
4057 (pr-ps-directory-print n-up dir file-regexp filename)))
4060 ;;;###autoload
4061 (defun pr-ps-buffer-preview (n-up &optional filename)
4062 "Preview buffer using ghostview.
4064 Interactively, the command prompts for N-UP printing number and, when you use a
4065 prefix argument (C-u), the command prompts the user for a file name, and saves
4066 the PostScript image in that file instead of saving it in a temporary file.
4068 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4069 argument FILENAME is treated as follows: if it's nil, save the image in a
4070 temporary file. If FILENAME is a string, save the PostScript image in a file
4071 with that name. If FILENAME is t, prompts for a file name."
4072 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
4073 (if (pr-auto-mode-p)
4074 (pr-ps-mode-preview n-up filename)
4075 (pr-ps-preview (pr-region-active-symbol) n-up filename
4076 (pr-region-active-string "PS preview"))))
4079 ;;;###autoload
4080 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
4081 "Print buffer using PostScript through ghostscript.
4083 Interactively, the command prompts for N-UP printing number and, when you use a
4084 prefix argument (C-u), the command prompts the user for a file name, and saves
4085 the PostScript image in that file instead of sending it to the printer.
4087 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4088 argument FILENAME is treated as follows: if it's nil, send the image to the
4089 printer. If FILENAME is a string, save the PostScript image in a file with
4090 that name. If FILENAME is t, prompts for a file name."
4091 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
4092 (if (pr-auto-mode-p)
4093 (pr-ps-mode-using-ghostscript n-up filename)
4094 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4095 (pr-region-active-string "PS print GS"))))
4098 ;;;###autoload
4099 (defun pr-ps-buffer-print (n-up &optional filename)
4100 "Print buffer using PostScript printer.
4102 Interactively, the command prompts for N-UP printing number and, when you use a
4103 prefix argument (C-u), the command prompts the user for a file name, and saves
4104 the PostScript image in that file instead of sending it to the printer.
4106 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4107 argument FILENAME is treated as follows: if it's nil, send the image to the
4108 printer. If FILENAME is a string, save the PostScript image in a file with
4109 that name. If FILENAME is t, prompts for a file name."
4110 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
4111 (if (pr-auto-mode-p)
4112 (pr-ps-mode-print n-up filename)
4113 (pr-ps-print (pr-region-active-symbol) n-up filename
4114 (pr-region-active-string "PS print"))))
4117 ;;;###autoload
4118 (defun pr-ps-buffer-ps-print (n-up &optional filename)
4119 "Print buffer using PostScript printer or through ghostscript.
4121 It depends on `pr-print-using-ghostscript'.
4123 Interactively, the command prompts for N-UP printing number and, when you use a
4124 prefix argument (C-u), the command prompts the user for a file name, and saves
4125 the PostScript image in that file instead of sending it to the printer.
4127 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4128 argument FILENAME is treated as follows: if it's nil, send the image to the
4129 printer. If FILENAME is a string, save the PostScript image in a file with
4130 that name. If FILENAME is t, prompts for a file name."
4131 (interactive (pr-interactive-n-up-file
4132 (pr-prompt (pr-prompt-gs "PS print"))))
4133 (cond ((pr-auto-mode-p)
4134 (pr-ps-mode-ps-print n-up filename))
4135 ((pr-using-ghostscript-p)
4136 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4137 (pr-region-active-string "PS print GS")))
4139 (pr-ps-print (pr-region-active-symbol) n-up filename
4140 (pr-region-active-string "PS print")))))
4143 ;;;###autoload
4144 (defun pr-ps-region-preview (n-up &optional filename)
4145 "Preview region using ghostview.
4147 See also `pr-ps-buffer-preview'."
4148 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
4149 (if (pr-auto-mode-p)
4150 (let ((pr-auto-region t))
4151 (pr-ps-mode-preview n-up filename))
4152 (pr-ps-preview 'region n-up filename "PS preview region")))
4155 ;;;###autoload
4156 (defun pr-ps-region-using-ghostscript (n-up &optional filename)
4157 "Print region using PostScript through ghostscript.
4159 See also `pr-ps-buffer-using-ghostscript'."
4160 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
4161 (if (pr-auto-mode-p)
4162 (let ((pr-auto-region t))
4163 (pr-ps-mode-using-ghostscript n-up filename))
4164 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
4167 ;;;###autoload
4168 (defun pr-ps-region-print (n-up &optional filename)
4169 "Print region using PostScript printer.
4171 See also `pr-ps-buffer-print'."
4172 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
4173 (if (pr-auto-mode-p)
4174 (let ((pr-auto-region t))
4175 (pr-ps-mode-print n-up filename))
4176 (pr-ps-print 'region n-up filename "PS print region")))
4179 ;;;###autoload
4180 (defun pr-ps-region-ps-print (n-up &optional filename)
4181 "Print region using PostScript printer or through ghostscript.
4183 See also `pr-ps-buffer-ps-print'."
4184 (interactive (pr-interactive-n-up-file
4185 (pr-prompt-region (pr-prompt-gs "PS print"))))
4186 (cond ((pr-auto-mode-p)
4187 (let ((pr-auto-region t))
4188 (pr-ps-mode-ps-print n-up filename)))
4189 ((pr-using-ghostscript-p)
4190 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
4192 (pr-ps-print 'region n-up filename "PS print region"))))
4195 ;;;###autoload
4196 (defun pr-ps-mode-preview (n-up &optional filename)
4197 "Preview major mode using ghostview.
4199 See also `pr-ps-buffer-preview'."
4200 (interactive (pr-interactive-n-up-file "PS preview mode"))
4201 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
4202 (let ((file (pr-ps-file filename)))
4203 (and (pr-ps-mode n-up file)
4204 (not pr-spool-p)
4205 (pr-ps-file-preview file))))
4208 ;;;###autoload
4209 (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
4210 "Print major mode using PostScript through ghostscript.
4212 See also `pr-ps-buffer-using-ghostscript'."
4213 (interactive (pr-interactive-n-up-file "PS print GS mode"))
4214 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
4215 (let ((file (pr-ps-file filename)))
4216 (when (and (pr-ps-mode n-up file)
4217 (not pr-spool-p))
4218 (pr-ps-file-using-ghostscript file)
4219 (or filename (pr-delete-file file)))))
4222 ;;;###autoload
4223 (defun pr-ps-mode-print (n-up &optional filename)
4224 "Print major mode using PostScript printer.
4226 See also `pr-ps-buffer-print'."
4227 (interactive (pr-interactive-n-up-file "PS print mode"))
4228 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
4229 (pr-ps-mode n-up filename))
4232 ;;;###autoload
4233 (defun pr-ps-mode-ps-print (n-up &optional filename)
4234 "Print major mode using PostScript or through ghostscript.
4236 See also `pr-ps-buffer-ps-print'."
4237 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
4238 (if (pr-using-ghostscript-p)
4239 (pr-ps-mode-using-ghostscript n-up filename)
4240 (pr-ps-mode-print n-up filename)))
4243 ;;;###autoload
4244 (defun pr-printify-directory (&optional dir file-regexp)
4245 "Replace nonprinting characters in directory with printable representations.
4246 The printable representations use ^ (for ASCII control characters) or hex.
4247 The characters tab, linefeed, space, return and formfeed are not affected.
4249 Interactively, the command prompts for a directory and a file name regexp for
4250 matching.
4252 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4253 prompts for FILE(name)-REGEXP.
4255 See also documentation for `pr-list-directory'."
4256 (interactive (pr-interactive-dir-args "Printify dir"))
4257 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
4258 (pr-file-list dir file-regexp 'pr-printify-buffer))
4261 ;;;###autoload
4262 (defun pr-printify-buffer ()
4263 "Replace nonprinting characters in buffer with printable representations.
4264 The printable representations use ^ (for ASCII control characters) or hex.
4265 The characters tab, linefeed, space, return and formfeed are not affected."
4266 (interactive "*")
4267 (if (pr-region-active-p)
4268 (pr-printify-region)
4269 (printify-region (point-min) (point-max))))
4272 ;;;###autoload
4273 (defun pr-printify-region ()
4274 "Replace nonprinting characters in region with printable representations.
4275 The printable representations use ^ (for ASCII control characters) or hex.
4276 The characters tab, linefeed, space, return and formfeed are not affected."
4277 (interactive "*")
4278 (printify-region (point) (mark)))
4281 ;;;###autoload
4282 (defun pr-txt-directory (&optional dir file-regexp)
4283 "Print directory using text printer.
4285 Interactively, the command prompts for a directory and a file name regexp for
4286 matching.
4288 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4289 prompts for FILE(name)-REGEXP.
4291 See also documentation for `pr-list-directory'."
4292 (interactive (pr-interactive-dir-args "Print dir"))
4293 (pr-set-dir-args 'dir 'file-regexp "Print dir")
4294 (pr-file-list dir file-regexp 'pr-txt-buffer))
4297 ;;;###autoload
4298 (defun pr-txt-buffer ()
4299 "Print buffer using text printer."
4300 (interactive)
4301 (cond ((pr-auto-mode-p)
4302 (pr-txt-mode))
4303 ((pr-region-active-p)
4304 (pr-txt-region))
4306 (pr-txt-print (point-min) (point-max)))))
4309 ;;;###autoload
4310 (defun pr-txt-region ()
4311 "Print region using text printer."
4312 (interactive)
4313 (if (pr-auto-mode-p)
4314 (let ((pr-auto-region t))
4315 (pr-txt-mode))
4316 (pr-txt-print (point) (mark))))
4319 ;;;###autoload
4320 (defun pr-txt-mode ()
4321 "Print major mode using text printer."
4322 (interactive)
4323 (let ((args (pr-mode-alist-p)))
4324 (if args
4325 (funcall (car args) (nthcdr 2 args))
4326 (ding)
4327 (message "`%s' major mode not declared." major-mode))))
4330 ;;;###autoload
4331 (defun pr-despool-preview (&optional filename)
4332 "Preview spooled PostScript.
4334 Interactively, when you use a prefix argument (C-u), the command prompts the
4335 user for a file name, and saves the spooled PostScript image in that file
4336 instead of saving it in a temporary file.
4338 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4339 save the image in a temporary file. If FILENAME is a string, save the
4340 PostScript image in a file with that name."
4341 (interactive (list (ps-print-preprint current-prefix-arg)))
4342 (let ((file (pr-ps-file filename)))
4343 (when (stringp file)
4344 (pr-despool-print file)
4345 (pr-ps-file-preview file))))
4348 ;;;###autoload
4349 (defun pr-despool-using-ghostscript (&optional filename)
4350 "Print spooled PostScript using ghostscript.
4352 Interactively, when you use a prefix argument (C-u), the command prompts the
4353 user for a file name, and saves the spooled PostScript image in that file
4354 instead of sending it to the printer.
4356 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4357 send the image to the printer. If FILENAME is a string, save the PostScript
4358 image in a file with that name."
4359 (interactive (list (ps-print-preprint current-prefix-arg)))
4360 (let ((file (pr-ps-file filename)))
4361 (when (stringp file)
4362 (pr-despool-print file)
4363 (pr-ps-file-using-ghostscript file)
4364 (or filename (pr-delete-file file)))))
4367 ;;;###autoload
4368 (defun pr-despool-print (&optional filename)
4369 "Send the spooled PostScript to the printer.
4371 Interactively, when you use a prefix argument (C-u), the command prompts the
4372 user for a file name, and saves the spooled PostScript image in that file
4373 instead of sending it to the printer.
4375 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4376 send the image to the printer. If FILENAME is a string, save the PostScript
4377 image in a file with that name."
4378 (interactive (list (ps-print-preprint current-prefix-arg)))
4379 (pr-save-file-modes
4380 (let ((ps-lpr-command (pr-command pr-ps-command))
4381 (ps-lpr-switches pr-ps-switches)
4382 (ps-printer-name-option pr-ps-printer-switch)
4383 (ps-printer-name pr-ps-printer))
4384 (ps-despool filename))))
4387 ;;;###autoload
4388 (defun pr-despool-ps-print (&optional filename)
4389 "Send the spooled PostScript to the printer or use ghostscript to print it.
4391 Interactively, when you use a prefix argument (C-u), the command prompts the
4392 user for a file name, and saves the spooled PostScript image in that file
4393 instead of sending it to the printer.
4395 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4396 send the image to the printer. If FILENAME is a string, save the PostScript
4397 image in a file with that name."
4398 (interactive (list (ps-print-preprint current-prefix-arg)))
4399 (if pr-print-using-ghostscript
4400 (pr-despool-using-ghostscript filename)
4401 (pr-despool-print filename)))
4404 ;;;###autoload
4405 (defun pr-ps-file-preview (filename)
4406 "Preview PostScript file FILENAME."
4407 (interactive (list (pr-ps-infile-preprint "Preview ")))
4408 (and (stringp filename) (file-exists-p filename)
4409 (pr-call-process pr-gv-command filename)))
4412 ;;;###autoload
4413 (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
4414 "Preview PostScript file FILENAME."
4415 (interactive (pr-interactive-n-up-inout "PS preview"))
4416 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4417 "PS preview ")))
4418 (pr-ps-utility-process n-up ifilename outfile)
4419 (pr-ps-file-preview outfile)))
4422 ;;;###autoload
4423 (defun pr-ps-file-using-ghostscript (filename)
4424 "Print PostScript file FILENAME using ghostscript."
4425 (interactive (list (pr-ps-infile-preprint "Print preview ")))
4426 (and (stringp filename) (file-exists-p filename)
4427 (let* ((file (pr-expand-file-name filename))
4428 (tempfile (pr-dosify-file-name (make-temp-file file))))
4429 ;; gs use
4430 (pr-call-process pr-gs-command
4431 (format "-sDEVICE=%s" pr-gs-device)
4432 (format "-r%d" pr-gs-resolution)
4433 (pr-switches-string pr-gs-switches "pr-gs-switches")
4434 (format "-sOutputFile=\"%s\"" tempfile)
4435 file
4436 "-c quit")
4437 ;; printing
4438 (pr-ps-file-print tempfile)
4439 ;; deleting
4440 (pr-delete-file tempfile))))
4443 ;;;###autoload
4444 (defun pr-ps-file-print (filename)
4445 "Print PostScript file FILENAME."
4446 (interactive (list (pr-ps-infile-preprint "Print ")))
4447 (and (stringp filename) (file-exists-p filename)
4448 ;; printing
4449 (let ((file (pr-expand-file-name filename)))
4450 (if (string= pr-ps-command "")
4451 ;; default action
4452 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
4453 (save-excursion
4454 (set-buffer ps-spool-buffer)
4455 (erase-buffer)
4456 (insert-file-contents-literally file))
4457 (pr-despool-print))
4458 ;; use `pr-ps-command' to print
4459 (apply 'pr-call-process
4460 pr-ps-command
4461 (pr-switches-string pr-ps-switches "pr-ps-switches")
4462 (if (string-match "cp" pr-ps-command)
4463 ;; for "cp" (cmd in out)
4464 (list file
4465 (concat pr-ps-printer-switch pr-ps-printer))
4466 ;; else, for others (cmd out in)
4467 (list (concat pr-ps-printer-switch pr-ps-printer)
4468 file)))))))
4471 ;;;###autoload
4472 (defun pr-ps-file-ps-print (filename)
4473 "Send PostScript file FILENAME to printer or use ghostscript to print it."
4474 (interactive (list (pr-ps-infile-preprint
4475 (if pr-print-using-ghostscript
4476 "Print preview "
4477 "Print "))))
4478 (if pr-print-using-ghostscript
4479 (pr-ps-file-using-ghostscript filename)
4480 (pr-ps-file-print filename)))
4483 ;;;###autoload
4484 (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
4485 "Process a PostScript file IFILENAME and send it to printer.
4487 Interactively, the command prompts for N-UP printing number, for an input
4488 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
4489 command prompts the user for an output PostScript file name OFILENAME, and
4490 saves the PostScript image in that file instead of sending it to the printer.
4492 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4493 argument IFILENAME is treated as follows: if it's t, prompts for an input
4494 PostScript file name; otherwise, it *must* be a string that it's an input
4495 PostScript file name. The argument OFILENAME is treated as follows: if it's
4496 nil, send the image to the printer. If OFILENAME is a string, save the
4497 PostScript image in a file with that name. If OFILENAME is t, prompts for a
4498 file name."
4499 (interactive (pr-interactive-n-up-inout
4500 (if pr-print-using-ghostscript
4501 "PS print GS"
4502 "PS print")))
4503 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4504 (if pr-print-using-ghostscript
4505 "PS print GS "
4506 "PS print "))))
4507 (pr-ps-utility-process n-up ifilename outfile)
4508 (unless ofilename
4509 (pr-ps-file-ps-print outfile)
4510 (pr-delete-file outfile))))
4513 ;;;###autoload
4514 (defun pr-toggle-file-duplex ()
4515 "Toggle duplex for PostScript file."
4516 (interactive)
4517 (pr-toggle-file-duplex-menu t))
4520 ;;;###autoload
4521 (defun pr-toggle-file-tumble ()
4522 "Toggle tumble for PostScript file.
4524 If tumble is off, produces a printing suitable for binding on the left or
4525 right.
4526 If tumble is on, produces a printing suitable for binding at the top or
4527 bottom."
4528 (interactive)
4529 (pr-toggle-file-tumble-menu t))
4532 ;;;###autoload
4533 (defun pr-toggle-file-landscape ()
4534 "Toggle landscape for PostScript file."
4535 (interactive)
4536 (pr-toggle-file-landscape-menu t))
4539 ;;;###autoload
4540 (defun pr-toggle-ghostscript ()
4541 "Toggle printing using ghostscript."
4542 (interactive)
4543 (pr-toggle-ghostscript-menu t))
4546 ;;;###autoload
4547 (defun pr-toggle-faces ()
4548 "Toggle printing with faces."
4549 (interactive)
4550 (pr-toggle-faces-menu t))
4553 ;;;###autoload
4554 (defun pr-toggle-spool ()
4555 "Toggle spooling."
4556 (interactive)
4557 (pr-toggle-spool-menu t))
4560 ;;;###autoload
4561 (defun pr-toggle-duplex ()
4562 "Toggle duplex."
4563 (interactive)
4564 (pr-toggle-duplex-menu t))
4567 ;;;###autoload
4568 (defun pr-toggle-tumble ()
4569 "Toggle tumble.
4571 If tumble is off, produces a printing suitable for binding on the left or
4572 right.
4573 If tumble is on, produces a printing suitable for binding at the top or
4574 bottom."
4575 (interactive)
4576 (pr-toggle-tumble-menu t))
4579 ;;;###autoload
4580 (defun pr-toggle-landscape ()
4581 "Toggle landscape."
4582 (interactive)
4583 (pr-toggle-landscape-menu t))
4586 ;;;###autoload
4587 (defun pr-toggle-upside-down ()
4588 "Toggle upside-down."
4589 (interactive)
4590 (pr-toggle-upside-down-menu t))
4593 ;;;###autoload
4594 (defun pr-toggle-line ()
4595 "Toggle line number."
4596 (interactive)
4597 (pr-toggle-line-menu t))
4600 ;;;###autoload
4601 (defun pr-toggle-zebra ()
4602 "Toggle zebra stripes."
4603 (interactive)
4604 (pr-toggle-zebra-menu t))
4607 ;;;###autoload
4608 (defun pr-toggle-header ()
4609 "Toggle printing header."
4610 (interactive)
4611 (pr-toggle-header-menu t))
4614 ;;;###autoload
4615 (defun pr-toggle-header-frame ()
4616 "Toggle printing header frame."
4617 (interactive)
4618 (pr-toggle-header-frame-menu t))
4621 ;;;###autoload
4622 (defun pr-toggle-lock ()
4623 "Toggle menu lock."
4624 (interactive)
4625 (pr-toggle-lock-menu t))
4628 ;;;###autoload
4629 (defun pr-toggle-region ()
4630 "Toggle auto region."
4631 (interactive)
4632 (pr-toggle-region-menu t))
4635 ;;;###autoload
4636 (defun pr-toggle-mode ()
4637 "Toggle auto mode."
4638 (interactive)
4639 (pr-toggle-mode-menu t))
4642 ;;;###autoload
4643 (defun pr-customize (&rest ignore)
4644 "Customization of the `printing' group."
4645 (interactive)
4646 (customize-group 'printing))
4649 ;;;###autoload
4650 (defun lpr-customize (&rest ignore)
4651 "Customization of the `lpr' group."
4652 (interactive)
4653 (customize-group 'lpr))
4656 ;;;###autoload
4657 (defun pr-help (&rest ignore)
4658 "Help for the printing package."
4659 (interactive)
4660 (pr-show-setup pr-help-message "*Printing Help*"))
4663 ;;;###autoload
4664 (defun pr-ps-name ()
4665 "Interactively select a PostScript printer."
4666 (interactive)
4667 (pr-menu-set-ps-title
4668 (pr-complete-alist "PostScript printer"
4669 pr-ps-printer-alist pr-ps-name)))
4672 ;;;###autoload
4673 (defun pr-txt-name ()
4674 "Interactively select a text printer."
4675 (interactive)
4676 (pr-menu-set-txt-title
4677 (pr-complete-alist "Text printer"
4678 pr-txt-printer-alist pr-txt-name)))
4681 ;;;###autoload
4682 (defun pr-ps-utility ()
4683 "Interactively select a PostScript utility."
4684 (interactive)
4685 (pr-menu-set-utility-title
4686 (pr-complete-alist "Postscript utility"
4687 pr-ps-utility-alist pr-ps-utility)))
4690 ;;;###autoload
4691 (defun pr-show-ps-setup (&rest ignore)
4692 "Show current ps-print settings."
4693 (interactive)
4694 (pr-show-setup (ps-setup) "*PS Setup*"))
4697 ;;;###autoload
4698 (defun pr-show-pr-setup (&rest ignore)
4699 "Show current printing settings."
4700 (interactive)
4701 (pr-show-setup (pr-setup) "*PR Setup*"))
4704 ;;;###autoload
4705 (defun pr-show-lpr-setup (&rest ignore)
4706 "Show current lpr settings."
4707 (interactive)
4708 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4711 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4712 ;; Fast Commands
4715 ;;;###autoload
4716 (defun pr-ps-fast-fire (n-up &optional select)
4717 "Fast fire function for PostScript printing.
4719 If a region is active, the region will be printed instead of the whole buffer.
4720 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4721 `pr-mode-alist' will be used, that is, the current buffer or region will be
4722 printed using `pr-ps-mode-ps-print'.
4725 Interactively, you have the following situations:
4727 M-x pr-ps-fast-fire RET
4728 The command prompts the user for a N-UP value and printing will
4729 immediatelly be done using the current active printer.
4731 C-u M-x pr-ps-fast-fire RET
4732 C-u 0 M-x pr-ps-fast-fire RET
4733 The command prompts the user for a N-UP value and also for a current
4734 PostScript printer, then printing will immediatelly be done using the new
4735 current active printer.
4737 C-u 1 M-x pr-ps-fast-fire RET
4738 The command prompts the user for a N-UP value and also for a file name,
4739 and saves the PostScript image in that file instead of sending it to the
4740 printer.
4742 C-u 2 M-x pr-ps-fast-fire RET
4743 The command prompts the user for a N-UP value, then for a current
4744 PostScript printer and, finally, for a file name. Then change the active
4745 printer to that chosen by user and saves the PostScript image in
4746 that file instead of sending it to the printer.
4749 Noninteractively, the argument N-UP should be a positive integer greater than
4750 zero and the argument SELECT is treated as follows:
4752 If it's nil, send the image to the printer.
4754 If it's a list or an integer lesser or equal to zero, the command prompts
4755 the user for a current PostScript printer, then printing will immediatelly
4756 be done using the new current active printer.
4758 If it's an integer equal to 1, the command prompts the user for a file name
4759 and saves the PostScript image in that file instead of sending it to the
4760 printer.
4762 If it's an integer greater or equal to 2, the command prompts the user for a
4763 current PostScript printer and for a file name. Then change the active
4764 printer to that chosen by user and saves the PostScript image in that file
4765 instead of sending it to the printer.
4767 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4768 active printer and printing will immediatelly be done using the new active
4769 printer.
4771 Otherwise, send the image to the printer.
4774 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4775 are both set to t."
4776 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4777 current-prefix-arg))
4778 (let ((pr-auto-region t)
4779 (pr-auto-mode t)
4780 filename)
4781 (cond ((null select))
4782 ((listp select)
4783 (pr-ps-name))
4784 ((and (symbolp select)
4785 (assq select pr-ps-printer-alist))
4786 (pr-menu-set-ps-title select))
4787 ((integerp select)
4788 (and (/= select 1)
4789 (pr-ps-name))
4790 (and (>= select 1) (not pr-spool-p)
4791 (setq filename (pr-ps-outfile-preprint
4792 (if pr-print-using-ghostscript
4793 "Fast GS "
4794 "Fast "))))))
4795 (pr-ps-buffer-ps-print
4796 (if (integerp n-up)
4797 (min (max n-up 1) 100)
4798 (error "n-up must be an integer greater than zero"))
4799 filename)))
4802 ;;;###autoload
4803 (defun pr-txt-fast-fire (&optional select-printer)
4804 "Fast fire function for text printing.
4806 If a region is active, the region will be printed instead of the whole buffer.
4807 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4808 `pr-mode-alist' will be used, that is, the current buffer or region will be
4809 printed using `pr-txt-mode'.
4811 Interactively, when you use a prefix argument (C-u), the command prompts the
4812 user for a new active text printer.
4814 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4816 If it's nil, the printing is sent to the current active text printer.
4818 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4819 active printer and printing will immediatelly be done using the new active
4820 printer.
4822 If it's non-nil, the command prompts the user for a new active text printer.
4824 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4825 are both set to t."
4826 (interactive (list current-prefix-arg))
4827 (cond ((null select-printer))
4828 ((and (symbolp select-printer)
4829 (assq select-printer pr-txt-printer-alist))
4830 (pr-menu-set-txt-title select-printer))
4832 (pr-txt-name)))
4833 (let ((pr-auto-region t)
4834 (pr-auto-mode t))
4835 (pr-txt-buffer)))
4838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4839 ;; Utilities
4842 (defun pr-setup ()
4843 "Return the current `printing' setup.
4845 This is *not* an interactive command.
4846 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4848 M-: (insert (pr-setup)) RET
4850 Or choose the menu option Printing/Show Settings/printing."
4851 (let (ps-prefix-quote)
4852 (mapconcat
4853 #'ps-print-quote
4854 (list
4855 (concat "\n;;; printing.el version " pr-version "\n")
4856 ";; internal vars"
4857 (ps-comment-string "emacs-version " emacs-version)
4858 (ps-comment-string "pr-txt-command " pr-txt-command)
4859 (ps-comment-string "pr-txt-switches "
4860 (pr-switches-string pr-txt-switches "pr-txt-switches"))
4861 (ps-comment-string "pr-txt-printer " pr-txt-printer)
4862 (ps-comment-string "pr-ps-command " pr-ps-command)
4863 (ps-comment-string "pr-ps-switches "
4864 (pr-switches-string pr-ps-switches "pr-ps-switches"))
4865 (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
4866 (ps-comment-string "pr-ps-printer " pr-ps-printer)
4867 (ps-comment-string "pr-cygwin-system " pr-cygwin-system)
4868 (ps-comment-string "ps-windows-system " ps-windows-system)
4869 (ps-comment-string "ps-lp-system " ps-lp-system)
4871 '(14 . pr-path-style)
4872 '(14 . pr-path-alist)
4874 '(21 . pr-txt-name)
4875 '(21 . pr-txt-printer-alist)
4877 '(20 . pr-ps-name)
4878 '(20 . pr-ps-printer-alist)
4880 '(20 . pr-temp-dir)
4881 '(20 . pr-ps-temp-file)
4882 '(20 . pr-file-modes)
4883 '(20 . pr-delete-temp-file)
4884 '(20 . pr-list-directory)
4886 '(17 . pr-gv-command)
4887 '(17 . pr-gs-command)
4888 '(17 . pr-gs-switches)
4889 '(17 . pr-gs-device)
4890 '(17 . pr-gs-resolution)
4892 '(27 . pr-print-using-ghostscript)
4893 '(27 . pr-faces-p)
4894 '(27 . pr-spool-p)
4895 '(27 . pr-file-landscape)
4896 '(27 . pr-file-duplex)
4897 '(27 . pr-file-tumble)
4898 '(27 . pr-auto-region)
4899 '(27 . pr-auto-mode)
4901 '(20 . pr-ps-utility)
4902 '(20 . pr-ps-utility-alist)
4904 '(14 . pr-mode-alist)
4906 '(20 . pr-menu-lock)
4907 '(20 . pr-menu-char-height)
4908 '(20 . pr-menu-char-width)
4910 '(20 . pr-setting-database)
4912 '(22 . pr-visible-entry-list)
4914 '(22 . pr-buffer-verbose)
4915 '(22 . pr-buffer-name)
4916 '(22 . pr-buffer-name-ignore)
4917 ")\n\n;;; printing.el - end of settings\n")
4918 "\n")))
4921 (defun lpr-setup ()
4922 "Return the current `lpr' setup.
4924 This is *not* an interactive command.
4925 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4927 M-: (insert (lpr-setup)) RET
4929 Or choose the menu option Printing/Show Settings/lpr."
4930 (let (ps-prefix-quote)
4931 (mapconcat
4932 #'ps-print-quote
4933 (list
4934 "\n;;; lpr.el settings\n"
4935 (ps-comment-string "emacs-version" emacs-version)
4937 '(25 . printer-name)
4938 '(25 . lpr-switches)
4939 '(25 . lpr-add-switches)
4940 '(25 . lpr-command)
4941 '(25 . lpr-headers-switches)
4942 '(25 . print-region-function)
4943 '(25 . lpr-page-header-program)
4944 '(25 . lpr-page-header-switches)
4945 ")\n\n;;; lpr.el - end of settings\n")
4946 "\n")))
4949 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4950 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4953 (defalias 'pr-mh-get-msg-num 'mh-get-msg-num)
4954 (defalias 'pr-mh-show 'mh-show)
4955 (defalias 'pr-mh-start-of-uncleaned-message 'mh-start-of-uncleaned-message)
4956 (defvar mh-show-buffer nil)
4959 (defun pr-article-date ()
4960 "Find the date of an article or mail message in current buffer.
4961 Return only the dayname, if present, weekday, month, and year."
4962 (save-excursion
4963 (goto-char (point-min))
4964 (if (re-search-forward
4965 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4966 (buffer-substring (match-beginning 1) (match-end 1))
4967 (format-time-string "%Y/%m/%d"))))
4970 (defun pr-mh-current-message ()
4971 "Go to mh-inbox current message."
4972 (let ((msg (or (pr-mh-get-msg-num nil) 0)))
4973 (pr-mh-show)
4974 (set-buffer mh-show-buffer)
4975 (goto-char (point-min))
4976 (pr-mh-start-of-uncleaned-message)
4977 (message "Printing message %d" msg)))
4980 (defun pr-mh-print-1 (n-up filename header-list)
4981 "Print mh-inbox current message in PostScript."
4982 (save-excursion
4983 (save-window-excursion
4984 (pr-mh-current-message)
4985 (pr-mode-print n-up filename header-list (point)))))
4988 (defun pr-mh-lpr-1 (header-list)
4989 "Print mh-inbox current message in text printer."
4990 (save-excursion
4991 (save-window-excursion
4992 (pr-mh-current-message)
4993 (pr-mode-lpr header-list (point)))))
4996 (defalias 'pr-mh-print-2 'pr-mode-print)
4999 (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
5002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5003 ;; rmail (hacked from ps-print.el)
5006 (defun pr-rmail-lpr (header-list)
5007 "Print RMAIL current message in text printer."
5008 (pr-lpr-message-from-summary header-list
5009 'rmail-buffer 'rmail-summary-buffer))
5012 (defun pr-rmail-print (n-up filename header-list)
5013 "Print RMAIL current message in PostScript."
5014 (pr-ps-message-from-summary n-up filename header-list
5015 'rmail-buffer 'rmail-summary-buffer))
5018 (defun pr-ps-message-from-summary (n-up filename header-list
5019 summary-buffer summary-default)
5020 "Print current message in PostScript."
5021 (let ((buf (or (and (boundp summary-buffer)
5022 (symbol-value summary-buffer))
5023 (symbol-value summary-default))))
5024 (and (get-buffer buf)
5025 (save-excursion
5026 (set-buffer buf)
5027 (pr-mode-print n-up filename header-list)))))
5030 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
5031 "Print current message in text printer."
5032 (let ((buf (or (and (boundp summary-buffer)
5033 (symbol-value summary-buffer))
5034 (symbol-value summary-default))))
5035 (and (get-buffer buf)
5036 (save-excursion
5037 (set-buffer buf)
5038 (pr-mode-lpr header-list)))))
5041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5042 ;; gnus (hacked from ps-print.el)
5045 (defvar pr-gnus-article "*Article*")
5048 (defun pr-gnus-print (n-up filename header-list)
5049 "Print *Article* current message in PostScript."
5050 (pr-ps-message-from-summary n-up filename header-list
5051 'gnus-article-buffer 'pr-gnus-article))
5054 (defun pr-gnus-lpr (header-list)
5055 "Print *Article* current message in text printer."
5056 (pr-lpr-message-from-summary header-list
5057 'gnus-article-buffer 'pr-gnus-article))
5060 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5061 ;; vm (hacked from ps-print.el)
5064 (defvar pr-vm-summary "")
5067 (defun pr-vm-print (n-up filename header-list)
5068 "Print current vm message in PostScript."
5069 (pr-ps-message-from-summary n-up filename header-list
5070 'vm-mail-buffer 'pr-vm-summary))
5073 (defun pr-vm-lpr (header-list)
5074 "Print current vm message in text printer."
5075 (pr-lpr-message-from-summary header-list
5076 'vm-mail-buffer 'pr-vm-summary))
5079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5080 ;; Mode Functions
5083 (defun pr-ps-mode (n-up filename)
5084 "If current major mode is declared, print it in PostScript."
5085 (let ((args (pr-mode-alist-p)))
5086 (if args
5087 (let ((fun (cdr args)))
5088 (funcall (car fun) n-up filename (cdr fun))
5090 (ding)
5091 (message "`%s' major mode not declared." major-mode)
5092 nil)))
5095 (defmacro pr-local-variable (header-list &rest body)
5096 `(save-excursion
5097 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
5098 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
5099 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
5100 ps-razzle-dazzle)
5101 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
5102 ,@body
5103 (and (nth 3 ,header-list)
5104 (pr-kill-local-variable local-var-list))))))
5107 (defun pr-mode-print (n-up filename header-list &optional from to)
5108 "Print current major mode in PostScript."
5109 (pr-local-variable
5110 header-list
5111 (let ((file (pr-ps-file filename))
5112 (start (cond (from)
5113 ((pr-region-active-p) (region-beginning))
5114 (t nil)
5116 (pr-text2ps (pr-region-active-symbol start) n-up file start
5117 (cond (to)
5118 ((pr-region-active-p) (region-end))
5119 (from (point-max))
5121 (unless (or pr-spool-p filename)
5122 (pr-ps-file-print file)
5123 (pr-delete-file file)))))
5126 (defun pr-mode-lpr (header-list &optional from to)
5127 "Print current major mode in text printer."
5128 (pr-local-variable
5129 header-list
5130 (pr-txt-print (cond (from)
5131 ((pr-region-active-p) (region-beginning))
5132 (t (point-min)))
5133 (cond (to)
5134 ((pr-region-active-p) (region-end))
5135 (t (point-max))))))
5138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5139 ;; Menu Lock
5142 (defconst pr-menu-entry-alist
5143 '((postscript . 3)
5144 (text . 3)
5145 (postscript-options . 9)
5146 (postscript-process . 3)
5147 (printing . 3)
5148 (help . 3)
5150 "Alist that associates menu part with number of items per part.
5152 It's used by `pr-menu-index'.
5154 Each element has the form:
5156 (MENU-PART . NUMBER-OF-ITEMS)
5158 See `pr-visible-entry-alist'.")
5161 (defun pr-menu-index (entry index)
5162 (let ((base-list
5163 (cond ((eq entry 'text)
5164 '(postscript))
5165 ((eq entry 'postscript-options)
5166 '(postscript text))
5167 ((eq entry 'postscript-process)
5168 '(postscript text postscript-options))
5169 ((eq entry 'printing)
5170 '(postscript text postscript-options postscript-process))
5172 nil)
5174 key)
5175 (while base-list
5176 (setq key (car base-list)
5177 base-list (cdr base-list))
5178 (and (pr-visible-p key)
5179 (setq index (+ index
5180 (cdr (assq key pr-menu-entry-alist)))))))
5181 (+ index 2))
5184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5185 ;; Printer & Utility Selection
5188 (defun pr-update-var (var-sym alist)
5189 (or (assq (symbol-value var-sym) alist)
5190 (set var-sym (car (car alist)))))
5193 (defun pr-update-menus (&optional force)
5194 "Update utility, PostScript and text printer menus.
5196 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
5197 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
5198 otherwise, update PostScript printer menu if `pr-ps-printer-menu-modified' is
5199 non-nil, update text printer menu if `pr-txt-printer-menu-modified' is
5200 non-nil, and update PostScript File menus if `pr-ps-utility-menu-modified' is
5201 non-nil.
5203 If menu binding was not done, calls `pr-menu-bind'."
5204 (interactive "P")
5205 (if pr-menu-print-item ; since v6.8.4
5206 ;; There was no menu binding yet, so do it now!
5207 ;; This is a hack to be compatible with old versions of printing.
5208 ;; So, user does not need to change printing calling in init files.
5209 (pr-menu-bind)
5210 ;; Here menu binding is ok.
5211 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
5212 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
5213 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
5214 (pr-do-update-menus force)))
5217 (defvar pr-ps-printer-menu-modified t
5218 "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
5219 (defvar pr-txt-printer-menu-modified t
5220 "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
5221 (defvar pr-ps-utility-menu-modified t
5222 "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
5225 (defconst pr-even-or-odd-alist
5226 '((nil . "Print All Pages")
5227 (even-page . "Print Even Pages")
5228 (odd-page . "Print Odd Pages")
5229 (even-sheet . "Print Even Sheets")
5230 (odd-sheet . "Print Odd Sheets")))
5233 (defun pr-menu-create (name alist var-sym fun entry index)
5234 (cons name
5235 (mapcar
5236 #'(lambda (elt)
5237 (let ((sym (car elt)))
5238 (vector
5239 (symbol-name sym)
5240 (list fun (list 'quote sym) nil (list 'quote entry) index)
5241 :style 'radio
5242 :selected (list 'eq var-sym (list 'quote sym)))))
5243 alist)))
5246 (defun pr-ps-set-utility (value)
5247 (let ((item (cdr (assq value pr-ps-utility-alist))))
5248 (or item
5249 (error
5250 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
5251 value))
5252 (setq pr-ps-utility value)
5253 (pr-eval-alist (nthcdr 9 item)))
5254 (pr-update-mode-line))
5257 (defun pr-ps-set-printer (value)
5258 (let ((ps (cdr (assq value pr-ps-printer-alist))))
5259 (or ps
5260 (error
5261 "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
5262 value))
5263 (setq pr-ps-name value
5264 pr-ps-command (pr-dosify-file-name (nth 0 ps))
5265 pr-ps-switches (nth 1 ps)
5266 pr-ps-printer-switch (nth 2 ps)
5267 pr-ps-printer (nth 3 ps))
5268 (or (stringp pr-ps-command)
5269 (setq pr-ps-command
5270 (cond (ps-windows-system "print")
5271 (ps-lp-system "lp")
5272 (t "lpr")
5274 (or (stringp pr-ps-printer-switch)
5275 (setq pr-ps-printer-switch
5276 (cond (ps-windows-system "/D:")
5277 (ps-lp-system "-d")
5278 (t "-P")
5280 (pr-eval-alist (nthcdr 4 ps)))
5281 (pr-update-mode-line))
5284 (defun pr-txt-set-printer (value)
5285 (let ((txt (cdr (assq value pr-txt-printer-alist))))
5286 (or txt
5287 (error "Invalid text printer name `%s' for variable `pr-txt-name'"
5288 value))
5289 (setq pr-txt-name value
5290 pr-txt-command (pr-dosify-file-name (nth 0 txt))
5291 pr-txt-switches (nth 1 txt)
5292 pr-txt-printer (nth 2 txt)))
5293 (or (stringp pr-txt-command)
5294 (setq pr-txt-command
5295 (cond (ps-windows-system "print")
5296 (ps-lp-system "lp")
5297 (t "lpr")
5299 (pr-update-mode-line))
5302 (defun pr-eval-alist (alist)
5303 (mapcar #'(lambda (option)
5304 (let ((var-sym (car option))
5305 (value (cdr option)))
5306 (if (eq var-sym 'inherits-from:)
5307 (pr-eval-setting-alist value 'global)
5308 (set var-sym (eval value)))))
5309 alist))
5312 (defun pr-eval-local-alist (alist)
5313 (let (local-list)
5314 (mapc #'(lambda (option)
5315 (let ((var-sym (car option))
5316 (value (cdr option)))
5317 (setq local-list
5318 (if (eq var-sym 'inherits-from:)
5319 (nconc (pr-eval-setting-alist value) local-list)
5320 (set (make-local-variable var-sym) (eval value))
5321 (cons var-sym local-list)))))
5322 alist)
5323 local-list))
5326 (defun pr-eval-setting-alist (key &optional global old)
5327 (let ((setting (cdr (assq key pr-setting-database))))
5328 (and setting
5329 (let ((inherits (nth 0 setting))
5330 (local (nth 1 setting))
5331 (kill (nth 2 setting))
5332 local-list)
5333 (and local global
5334 (progn
5335 (ding)
5336 (message "There are local buffer settings for `%S'." key)
5337 (setq global nil)))
5338 (and inherits
5339 (if (memq inherits old)
5340 (error "Circular inheritance for `%S'" inherits)
5341 (setq local-list
5342 (pr-eval-setting-alist inherits global
5343 (cons inherits old)))))
5344 (mapc
5345 (cond ((not local) ; global settings
5346 #'(lambda (option)
5347 (let ((var-sym (car option)))
5348 (or (eq var-sym 'inherits-from:)
5349 (set var-sym (eval (cdr option)))))))
5350 (kill ; local settings with killing
5351 #'(lambda (option)
5352 (let ((var-sym (car option)))
5353 (unless (eq var-sym 'inherits-from:)
5354 (setq local-list (cons var-sym local-list))
5355 (set (make-local-variable var-sym)
5356 (eval (cdr option)))))))
5357 (t ; local settings without killing
5358 #'(lambda (option)
5359 (let ((var-sym (car option)))
5360 (or (eq var-sym 'inherits-from:)
5361 (set (make-local-variable var-sym)
5362 (eval (cdr option))))))))
5363 (nthcdr 3 setting))
5364 local-list))))
5367 (defun pr-kill-local-variable (local-var-list)
5368 (mapcar 'kill-local-variable local-var-list))
5371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5372 ;; Internal Functions (II)
5375 (defun pr-toggle (var-sym mess entry index horizontal state
5376 &optional path no-menu)
5377 (set var-sym (not (symbol-value var-sym)))
5378 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5379 (or no-menu
5380 (pr-menu-lock entry index horizontal state path)))
5383 (defun pr-toggle-file-duplex-menu (&optional no-menu)
5384 (interactive)
5385 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
5386 '("PostScript Print" "File") no-menu))
5389 (defun pr-toggle-file-tumble-menu (&optional no-menu)
5390 (interactive)
5391 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
5392 '("PostScript Print" "File") no-menu))
5395 (defun pr-toggle-file-landscape-menu (&optional no-menu)
5396 (interactive)
5397 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
5398 '("PostScript Print" "File") no-menu))
5401 (defun pr-toggle-ghostscript-menu (&optional no-menu)
5402 (interactive)
5403 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
5404 'postscript-process 2 12 'toggle nil no-menu))
5407 (defun pr-toggle-faces-menu (&optional no-menu)
5408 (interactive)
5409 (pr-toggle 'pr-faces-p "Printing with faces"
5410 'postscript-process 1 12 'toggle nil no-menu))
5413 (defun pr-toggle-spool-menu (&optional no-menu)
5414 (interactive)
5415 (pr-toggle 'pr-spool-p "Spooling printing"
5416 'postscript-process 0 12 'toggle nil no-menu))
5419 (defun pr-toggle-duplex-menu (&optional no-menu)
5420 (interactive)
5421 (pr-toggle 'ps-spool-duplex "Printing duplex"
5422 'postscript-options 5 12 'toggle nil no-menu))
5425 (defun pr-toggle-tumble-menu (&optional no-menu)
5426 (interactive)
5427 (pr-toggle 'ps-spool-tumble "Tumble"
5428 'postscript-options 6 12 'toggle nil no-menu))
5431 (defun pr-toggle-landscape-menu (&optional no-menu)
5432 (interactive)
5433 (pr-toggle 'ps-landscape-mode "Landscape"
5434 'postscript-options 0 12 'toggle nil no-menu))
5437 (defun pr-toggle-upside-down-menu (&optional no-menu)
5438 (interactive)
5439 (pr-toggle 'ps-print-upside-down "Upside-Down"
5440 'postscript-options 7 12 'toggle nil no-menu))
5443 (defun pr-toggle-line-menu (&optional no-menu)
5444 (interactive)
5445 (pr-toggle 'ps-line-number "Line number"
5446 'postscript-options 3 12 'toggle nil no-menu))
5449 (defun pr-toggle-zebra-menu (&optional no-menu)
5450 (interactive)
5451 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
5452 'postscript-options 4 12 'toggle nil no-menu))
5455 (defun pr-toggle-header-menu (&optional no-menu)
5456 (interactive)
5457 (pr-toggle 'ps-print-header "Print header"
5458 'postscript-options 1 12 'toggle nil no-menu))
5461 (defun pr-toggle-header-frame-menu (&optional no-menu)
5462 (interactive)
5463 (pr-toggle 'ps-print-header-frame "Print header frame"
5464 'postscript-options 2 12 'toggle nil no-menu))
5467 (defun pr-toggle-lock-menu (&optional no-menu)
5468 (interactive)
5469 (pr-toggle 'pr-menu-lock "Menu lock"
5470 'printing 2 12 'toggle nil no-menu))
5473 (defun pr-toggle-region-menu (&optional no-menu)
5474 (interactive)
5475 (pr-toggle 'pr-auto-region "Auto region"
5476 'printing 0 12 'toggle nil no-menu))
5479 (defun pr-toggle-mode-menu (&optional no-menu)
5480 (interactive)
5481 (pr-toggle 'pr-auto-mode "Auto mode"
5482 'printing 1 12 'toggle nil no-menu))
5485 (defun pr-prompt (str)
5486 (if (pr-auto-mode-p)
5487 (concat str " mode")
5488 (pr-region-active-string str)))
5491 (defun pr-prompt-region (str)
5492 (concat str (if (pr-auto-mode-p)
5493 " mode"
5494 " region")))
5497 (defun pr-prompt-gs (str)
5498 (if (pr-using-ghostscript-p)
5499 (concat str " GS")
5500 str))
5503 (defun pr-region-active-symbol (&optional region-p)
5504 (if (or region-p (pr-region-active-p))
5505 'region
5506 'buffer))
5509 (defun pr-region-active-string (prefix)
5510 (concat prefix
5511 (if (pr-region-active-p)
5512 " region"
5513 " buffer")))
5516 (defun pr-show-setup (settings buffer-name)
5517 (with-output-to-temp-buffer buffer-name
5518 (princ settings)
5519 (print-help-return-message)))
5522 (defun pr-complete-alist (prompt alist default)
5523 (let ((collection (mapcar #'(lambda (elt)
5524 (setq elt (car elt))
5525 (cons (symbol-name elt) elt))
5526 alist)))
5527 (cdr (assoc (completing-read (concat prompt ": ")
5528 collection nil t
5529 (symbol-name default) nil
5530 (symbol-name default))
5531 collection))))
5534 (defun pr-delete-file (file)
5535 (and pr-delete-temp-file (file-exists-p file)
5536 (delete-file file)))
5539 (defun pr-expand-file-name (filename)
5540 (pr-dosify-file-name (expand-file-name filename)))
5543 (defun pr-ps-outfile-preprint (&optional mess)
5544 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5545 (res (read-file-name prompt default-directory "" nil)))
5546 (while (cond ((not (file-writable-p res))
5547 (ding)
5548 (setq prompt "is unwritable"))
5549 ((file-directory-p res)
5550 (ding)
5551 (setq prompt "is a directory"))
5552 ((file-exists-p res)
5553 (ding)
5554 (setq prompt "exists")
5555 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5556 res))))
5557 (t nil))
5558 (setq res (read-file-name
5559 (format "File %s; PostScript file: " prompt)
5560 (file-name-directory res) nil nil
5561 (file-name-nondirectory res))))
5562 (pr-expand-file-name res)))
5565 (defun pr-ps-infile-preprint (&optional mess)
5566 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5567 (res (read-file-name prompt default-directory "" nil)))
5568 (while (cond ((not (file-exists-p res))
5569 (ding)
5570 (setq prompt "doesn't exist"))
5571 ((not (file-readable-p res))
5572 (ding)
5573 (setq prompt "is unreadable"))
5574 ((file-directory-p res)
5575 (ding)
5576 (setq prompt "is a directory"))
5577 (t nil))
5578 (setq res (read-file-name
5579 (format "File %s; PostScript file: " prompt)
5580 (file-name-directory res) nil nil
5581 (file-name-nondirectory res))))
5582 (pr-expand-file-name res)))
5585 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
5586 ;; check arguments for PostScript file processing.
5587 ;; n-up
5588 (or (symbol-value n-up-sym)
5589 (set n-up-sym (pr-interactive-n-up prompt)))
5590 ;; input file
5591 (and (eq (symbol-value infile-sym) t)
5592 (set infile-sym (pr-ps-infile-preprint prompt)))
5593 (or (symbol-value infile-sym)
5594 (error "%s: input PostScript file name is missing" prompt))
5595 (set infile-sym (pr-dosify-file-name (symbol-value infile-sym)))
5596 ;; output file
5597 (and (eq (symbol-value outfile-sym) t)
5598 (set outfile-sym (and current-prefix-arg
5599 (pr-ps-outfile-preprint prompt))))
5600 (and (symbol-value outfile-sym)
5601 (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym))))
5602 (pr-ps-file (symbol-value outfile-sym)))
5605 (defun pr-ps-utility-process (n-up infile outfile)
5606 ;; activate utility to process a PostScript file.
5607 (let (item)
5608 (and (stringp infile) (file-exists-p infile)
5609 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
5610 (pr-call-process (nth 0 item)
5611 (pr-switches-string (nth 1 item)
5612 "pr-ps-utility-alist entry")
5613 (pr-switches-string (nth 8 item)
5614 "pr-ps-utility-alist entry")
5615 (and (nth 2 item)
5616 (format (nth 2 item) ps-paper-type))
5617 (format (nth 3 item) n-up)
5618 (and pr-file-landscape (nth 4 item))
5619 (and pr-file-duplex (nth 5 item))
5620 (and pr-file-tumble (nth 6 item))
5621 (pr-expand-file-name infile)
5622 (nth 7 item)
5623 (pr-expand-file-name outfile)))))
5626 (defun pr-remove-nil-from-list (lst)
5627 (while (and lst (null (car lst)))
5628 (setq lst (cdr lst)))
5629 (let ((b lst)
5630 (l (cdr lst)))
5631 (while l
5632 (if (car l)
5633 (setq b l
5634 l (cdr l))
5635 (setq l (cdr l))
5636 (setcdr b l))))
5637 lst)
5640 (defun pr-call-process (command &rest args)
5641 (let ((buffer (get-buffer-create "*Printing Command Output*"))
5642 (cmd (pr-command command))
5643 status)
5644 (setq args (pr-remove-nil-from-list args))
5645 ;; *Printing Command Output* == show command & args
5646 (save-excursion
5647 (set-buffer buffer)
5648 (goto-char (point-max))
5649 (insert (format "%s %S\n" cmd args)))
5650 ;; *Printing Command Output* == show any return message from command
5651 (pr-save-file-modes
5652 (setq status
5653 (condition-case data
5654 (apply 'call-process cmd nil buffer nil args)
5655 ((quit error)
5656 (error-message-string data)))))
5657 ;; *Printing Command Output* == show exit status
5658 (save-excursion
5659 (set-buffer buffer)
5660 (goto-char (point-max))
5661 (insert (format "Exit status: %s\n\n" status)))
5662 ;; message if error status
5663 (if (or (stringp status)
5664 (and (integerp status) (/= status 0)))
5665 (message
5666 "Printing error status: %s (see *Printing Command Output* buffer)"
5667 status))))
5670 (defun pr-txt-print (from to)
5671 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command)))
5672 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5673 (printer-name pr-txt-printer))
5674 (lpr-region from to)))
5677 (defun pr-switches-string (switches mess)
5678 ;; If SWITCHES is nil, return nil.
5679 ;; Otherwise, return the list of string in a string.
5680 (and switches
5681 (mapconcat 'identity (pr-switches switches mess) " ")))
5684 (defun pr-switches (switches mess)
5685 (or (listp switches)
5686 (error "%S should have a list of strings" mess))
5687 (ps-flatten-list ; dynamic evaluation
5688 (mapcar 'ps-eval-switch switches)))
5691 (defun pr-ps-preview (kind n-up filename mess)
5692 (pr-set-n-up-and-filename 'n-up 'filename mess)
5693 (let ((file (pr-ps-file filename)))
5694 (pr-text2ps kind n-up file)
5695 (or pr-spool-p (pr-ps-file-preview file))))
5698 (defun pr-ps-using-ghostscript (kind n-up filename mess)
5699 (pr-set-n-up-and-filename 'n-up 'filename mess)
5700 (let ((file (pr-ps-file filename)))
5701 (pr-text2ps kind n-up file)
5702 (unless (or pr-spool-p filename)
5703 (pr-ps-file-using-ghostscript file)
5704 (pr-delete-file file))))
5707 (defun pr-ps-print (kind n-up filename mess)
5708 (pr-set-n-up-and-filename 'n-up 'filename mess)
5709 (let ((file (pr-ps-file filename)))
5710 (pr-text2ps kind n-up file)
5711 (unless (or pr-spool-p filename)
5712 (pr-ps-file-print file)
5713 (pr-delete-file file))))
5716 (defun pr-ps-file (&optional filename)
5717 (pr-dosify-file-name (or filename
5718 (make-temp-file
5719 (convert-standard-filename
5720 (expand-file-name pr-ps-temp-file pr-temp-dir))
5721 nil ".ps"))))
5724 (defun pr-interactive-n-up (mess)
5725 (or (stringp mess) (setq mess "*"))
5726 (save-match-data
5727 (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
5728 (prompt "")
5729 (str (pr-f-read-string (format fmt-prompt prompt mess) "1" nil "1"))
5730 int)
5731 (while (if (string-match "^\\s *[0-9]+$" str)
5732 (setq int (string-to-number str)
5733 prompt (cond ((< int 1) "Integer below 1; ")
5734 ((> int 100) "Integer above 100; ")
5735 (t nil)))
5736 (setq prompt "Invalid integer syntax; "))
5737 (ding)
5738 (setq str
5739 (pr-f-read-string (format fmt-prompt prompt mess) str nil "1")))
5740 int)))
5743 (defun pr-interactive-dir (mess)
5744 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5745 default-directory)))
5746 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
5747 (dir (read-file-name (format fmt-prompt "")
5748 "" dir-name nil dir-name))
5749 prompt)
5750 (while (cond ((not (file-directory-p dir))
5751 (ding)
5752 (setq prompt "It's not a directory! "))
5753 ((not (file-readable-p dir))
5754 (ding)
5755 (setq prompt "Directory is unreadable! "))
5756 (t nil))
5757 (setq dir-name (file-name-directory dir)
5758 dir (read-file-name (format fmt-prompt prompt)
5759 "" dir-name nil dir-name)))
5760 (file-name-as-directory dir)))
5763 (defun pr-interactive-regexp (mess)
5764 (pr-f-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
5767 (defun pr-interactive-dir-args (mess)
5768 (list
5769 ;; get directory argument
5770 (pr-interactive-dir mess)
5771 ;; get file name regexp
5772 (pr-interactive-regexp mess)))
5775 (defun pr-interactive-ps-dir-args (mess)
5776 (list
5777 ;; get n-up argument
5778 (pr-interactive-n-up mess)
5779 ;; get directory argument
5780 (pr-interactive-dir mess)
5781 ;; get file name regexp
5782 (pr-interactive-regexp mess)
5783 ;; get output file name
5784 (and (not pr-spool-p)
5785 (ps-print-preprint current-prefix-arg))))
5788 (defun pr-interactive-n-up-file (mess)
5789 (list
5790 ;; get n-up argument
5791 (pr-interactive-n-up mess)
5792 ;; get output file name
5793 (and (not pr-spool-p)
5794 (ps-print-preprint current-prefix-arg))))
5797 (defun pr-interactive-n-up-inout (mess)
5798 (list
5799 ;; get n-up argument
5800 (pr-interactive-n-up mess)
5801 ;; get input file name
5802 (pr-ps-infile-preprint (concat mess " "))
5803 ;; get output file name
5804 (ps-print-preprint current-prefix-arg)))
5807 (defun pr-set-outfilename (filename-sym)
5808 (and (not pr-spool-p)
5809 (eq (symbol-value filename-sym) t)
5810 (set filename-sym (and current-prefix-arg
5811 (ps-print-preprint current-prefix-arg))))
5812 (and (symbol-value filename-sym)
5813 (set filename-sym (pr-dosify-file-name (symbol-value filename-sym)))))
5816 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5817 ;; n-up
5818 (or (symbol-value n-up-sym)
5819 (set n-up-sym (pr-interactive-n-up mess)))
5820 ;; output file
5821 (pr-set-outfilename filename-sym))
5824 (defun pr-set-dir-args (dir-sym regexp-sym mess)
5825 ;; directory
5826 (or (symbol-value dir-sym)
5827 (set dir-sym (pr-interactive-dir mess)))
5828 ;; file name regexp
5829 (or (symbol-value regexp-sym)
5830 (set regexp-sym (pr-interactive-regexp mess))))
5833 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5834 ;; n-up
5835 (or (symbol-value n-up-sym)
5836 (set n-up-sym (pr-interactive-n-up mess)))
5837 ;; directory & file name regexp
5838 (pr-set-dir-args dir-sym regexp-sym mess)
5839 ;; output file
5840 (pr-set-outfilename filename-sym))
5843 (defun pr-find-buffer-visiting (file)
5844 (if (not (file-directory-p file))
5845 (find-buffer-visiting (if ps-windows-system
5846 (downcase file)
5847 file))
5848 (let ((truename (file-truename file))
5849 (blist (buffer-list))
5850 found)
5851 (while (and (not found) blist)
5852 (save-excursion
5853 (set-buffer (car blist))
5854 (and (eq major-mode 'dired-mode)
5855 (save-excursion
5856 (goto-char (point-min))
5857 (string= (buffer-substring-no-properties
5858 (+ (point-min) 2)
5859 (progn
5860 (end-of-line)
5861 (1- (point))))
5862 truename))
5863 (setq found (car blist))))
5864 (setq blist (cdr blist)))
5865 found)))
5868 (defun pr-file-list (dir file-regexp fun)
5869 (mapcar #'(lambda (file)
5870 (and (or pr-list-directory
5871 (not (file-directory-p file)))
5872 (let ((buffer (pr-find-buffer-visiting file))
5873 pop-up-windows
5874 pop-up-frames)
5875 (and (or buffer
5876 (file-readable-p file))
5877 (save-excursion
5878 (set-buffer (or buffer
5879 (find-file-noselect file)))
5880 (funcall fun)
5881 (or buffer
5882 (kill-buffer (current-buffer))))))))
5883 (directory-files dir t file-regexp)))
5886 (defun pr-delete-file-if-exists (filename)
5887 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5888 (delete-file filename)))
5891 (defun pr-ps-file-list (n-up dir file-regexp filename)
5892 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5893 (let ((pr-spool-p t))
5894 (pr-file-list dir file-regexp
5895 #'(lambda ()
5896 (if (pr-auto-mode-p)
5897 (pr-ps-mode n-up filename)
5898 (pr-text2ps 'buffer n-up filename)))))
5899 (or pr-spool-p
5900 (pr-despool-print filename)))
5903 (defun pr-text2ps (kind n-up filename &optional from to)
5904 (pr-save-file-modes
5905 (let ((ps-n-up-printing n-up)
5906 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5907 'setpagedevice)))
5908 (pr-delete-file-if-exists filename)
5909 (cond (pr-faces-p
5910 (cond (pr-spool-p
5911 ;; pr-faces-p and pr-spool-p
5912 ;; here FILENAME arg is ignored
5913 (cond ((eq kind 'buffer)
5914 (ps-spool-buffer-with-faces))
5915 ((eq kind 'region)
5916 (ps-spool-region-with-faces (or from (point))
5917 (or to (mark))))
5919 ;; pr-faces-p and not pr-spool-p
5920 ((eq kind 'buffer)
5921 (ps-print-buffer-with-faces filename))
5922 ((eq kind 'region)
5923 (ps-print-region-with-faces (or from (point))
5924 (or to (mark)) filename))
5926 (pr-spool-p
5927 ;; not pr-faces-p and pr-spool-p
5928 ;; here FILENAME arg is ignored
5929 (cond ((eq kind 'buffer)
5930 (ps-spool-buffer))
5931 ((eq kind 'region)
5932 (ps-spool-region (or from (point)) (or to (mark))))
5934 ;; not pr-faces-p and not pr-spool-p
5935 ((eq kind 'buffer)
5936 (ps-print-buffer filename))
5937 ((eq kind 'region)
5938 (ps-print-region (or from (point)) (or to (mark)) filename))
5939 ))))
5942 (defun pr-command (command)
5943 "Return absolute file name specification for COMMAND.
5945 If COMMAND is an empty string, return it.
5947 If COMMAND is already an absolute file name specification, return it.
5948 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5949 otherwise, gives an error.
5951 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5952 `unix' are used (see `pr-path-alist' for documentation).
5954 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5955 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5956 (if (string= command "")
5957 command
5958 (pr-dosify-file-name
5959 (or (pr-find-command command)
5960 (pr-path-command (cond (pr-cygwin-system 'cygwin)
5961 (ps-windows-system 'windows)
5962 (t 'unix))
5963 (file-name-nondirectory command)
5964 nil)
5965 (error "Command not found: %s"
5966 (file-name-nondirectory command))))))
5969 (defun pr-path-command (symbol command sym-list)
5970 (let ((lpath (cdr (assq symbol pr-path-alist)))
5971 cmd)
5972 ;; PATH expansion
5973 (and (eq symbol 'PATH) (null lpath)
5974 (setq lpath (parse-colon-path (getenv "PATH"))))
5975 (while (and lpath
5976 (not
5977 (setq cmd
5978 (let ((path (car lpath)))
5979 (cond
5980 ;; symbol expansion
5981 ((symbolp path)
5982 (and (not (memq path sym-list))
5983 (pr-path-command path command
5984 (cons path sym-list))))
5985 ;; normal path
5986 ((stringp path)
5987 (pr-find-command
5988 (expand-file-name
5989 (substitute-in-file-name
5990 (concat (file-name-as-directory path)
5991 command)))))
5992 )))))
5993 (setq lpath (cdr lpath)))
5994 cmd))
5997 (defun pr-find-command (cmd)
5998 (if ps-windows-system
5999 ;; windows system
6000 (let ((ext (cons (file-name-extension cmd t)
6001 (list ".exe" ".bat" ".com")))
6002 found)
6003 (setq cmd (file-name-sans-extension cmd))
6004 (while (and ext
6005 (setq found (concat cmd (car ext)))
6006 (not (and (file-regular-p found)
6007 (file-executable-p found))))
6008 (setq ext (cdr ext)
6009 found nil))
6010 found)
6011 ;; non-windows systems
6012 (and (file-regular-p cmd)
6013 (file-executable-p cmd)
6014 cmd)))
6017 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6018 ;; Printing Interface (inspired on ps-print-interface.el)
6021 (eval-when-compile
6022 (require 'cus-edit)
6023 (require 'wid-edit)
6024 (require 'widget))
6027 (defvar pr-i-window-configuration nil)
6029 (defvar pr-i-buffer nil)
6030 (defvar pr-i-region nil)
6031 (defvar pr-i-mode nil)
6032 (defvar pr-i-despool nil)
6033 (defvar pr-i-ps-as-is t)
6034 (defvar pr-i-n-up 1)
6035 (defvar pr-i-directory "./")
6036 (defvar pr-i-regexp "")
6037 (defvar pr-i-ps-file "")
6038 (defvar pr-i-out-file "")
6039 (defvar pr-i-answer-yes nil)
6040 (defvar pr-i-process 'buffer)
6041 (defvar pr-i-ps-send 'printer)
6044 (defvar pr-interface-map nil
6045 "Keymap for pr-interface.")
6047 (unless pr-interface-map
6048 (setq pr-interface-map (make-sparse-keymap))
6049 (cond ((featurep 'xemacs) ; XEmacs
6050 (pr-f-set-keymap-parents pr-interface-map (list widget-keymap))
6051 (pr-f-set-keymap-name pr-interface-map 'pr-interface-map))
6052 (t ; GNU Emacs
6053 (pr-f-set-keymap-parents pr-interface-map widget-keymap)))
6054 (define-key pr-interface-map "q" 'pr-interface-quit)
6055 (define-key pr-interface-map "?" 'pr-interface-help))
6058 (defmacro pr-interface-save (&rest body)
6059 `(save-excursion
6060 (set-buffer pr-i-buffer)
6061 ,@body))
6064 (defun pr-create-interface ()
6065 "Create the front end for printing package."
6066 (setq pr-i-buffer (buffer-name (current-buffer))
6067 pr-i-region (ps-mark-active-p)
6068 pr-i-mode (pr-mode-alist-p)
6069 pr-i-window-configuration (current-window-configuration))
6071 (put 'pr-i-process 'pr-widget-list nil)
6072 (put 'pr-i-ps-send 'pr-widget-list nil)
6074 (delete-other-windows)
6075 (kill-buffer (get-buffer-create pr-buffer-name))
6076 (switch-to-buffer (get-buffer-create pr-buffer-name))
6078 ;; header
6079 (let ((versions (concat "printing v" pr-version
6080 " ps-print v" ps-print-version)))
6081 ;; to keep compatibility with Emacs 20 & 21:
6082 ;; DO NOT REPLACE `?\ ' BY `?\s'
6083 (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
6084 (pr-insert-italic "\nCurrent Directory : " 1)
6085 (pr-insert-italic default-directory)
6087 (pr-insert-section-1) ; 1. Print
6088 (pr-insert-section-2) ; 2. PostScript Printer
6089 (pr-insert-section-3) ; 3. Text Printer
6091 ;; separator
6092 (widget-insert "\n\n " (make-string 77 ?-))
6094 (pr-insert-section-4) ; 4. Settings
6095 (pr-insert-section-5) ; 5. Customize
6096 (pr-insert-section-6) ; 6. Show Settings
6097 (pr-insert-section-7) ; 7. Help
6099 (use-local-map pr-interface-map)
6100 (widget-setup)
6101 (goto-char (point-min))
6103 (and pr-i-region ; let region activated
6104 (pr-keep-region-active)))
6107 (defun pr-insert-section-1 ()
6108 ;; 1. Print:
6109 (pr-insert-italic "\nPrint :" 1)
6111 ;; 1a. Buffer:
6112 ;; 1a. Buffer: Buffer List
6113 (pr-insert-radio-button 'pr-i-process 'buffer)
6114 (pr-insert-menu "Buffer List" 'pr-i-buffer
6115 (let ((blist (buffer-list))
6116 case-fold-search choices)
6117 (while blist
6118 (let ((name (buffer-name (car blist)))
6119 (ignore pr-buffer-name-ignore)
6120 found)
6121 (setq blist (cdr blist))
6122 (while (and ignore (not found))
6123 (setq found (string-match (car ignore) name)
6124 ignore (cdr ignore)))
6125 (or found
6126 (setq choices
6127 (cons (list 'quote
6128 (list 'choice-item
6129 :format "%[%t%]"
6130 name))
6131 choices)))))
6132 (nreverse choices))
6133 " Buffer : " nil
6134 '(progn
6135 (pr-interface-save
6136 (setq pr-i-region (ps-mark-active-p)
6137 pr-i-mode (pr-mode-alist-p)))
6138 (pr-update-checkbox 'pr-i-region)
6139 (pr-update-checkbox 'pr-i-mode)))
6140 ;; 1a. Buffer: Region
6141 (put 'pr-i-region 'pr-widget
6142 (pr-insert-checkbox
6143 "\n "
6144 'pr-i-region
6145 #'(lambda (widget &rest ignore)
6146 (let ((region-p (pr-interface-save
6147 (ps-mark-active-p))))
6148 (cond ((null (widget-value widget)) ; widget is nil
6149 (setq pr-i-region nil))
6150 (region-p ; widget is true and there is a region
6151 (setq pr-i-region t)
6152 (widget-value-set widget t)
6153 (widget-setup)) ; MUST be called after widget-value-set
6154 (t ; widget is true and there is no region
6155 (ding)
6156 (message "There is no region active")
6157 (setq pr-i-region nil)
6158 (widget-value-set widget nil)
6159 (widget-setup))))) ; MUST be called after widget-value-set
6160 " Region"))
6161 ;; 1a. Buffer: Mode
6162 (put 'pr-i-mode 'pr-widget
6163 (pr-insert-checkbox
6165 'pr-i-mode
6166 #'(lambda (widget &rest ignore)
6167 (let ((mode-p (pr-interface-save
6168 (pr-mode-alist-p))))
6169 (cond
6170 ((null (widget-value widget)) ; widget is nil
6171 (setq pr-i-mode nil))
6172 (mode-p ; widget is true and there is a `mode'
6173 (setq pr-i-mode t)
6174 (widget-value-set widget t)
6175 (widget-setup)) ; MUST be called after widget-value-set
6176 (t ; widget is true and there is no `mode'
6177 (ding)
6178 (message
6179 "This buffer isn't in a mode that printing treats specially.")
6180 (setq pr-i-mode nil)
6181 (widget-value-set widget nil)
6182 (widget-setup))))) ; MUST be called after widget-value-set
6183 " Mode\n"))
6185 ;; 1b. Directory:
6186 (pr-insert-radio-button 'pr-i-process 'directory)
6187 (widget-create
6188 'directory
6189 :size 58
6190 :format " Directory : %v"
6191 :notify 'pr-interface-directory
6192 :action (lambda (widget &optional event)
6193 (if (pr-interface-directory widget)
6194 (pr-widget-field-action widget event)
6195 (ding)
6196 (message "Please specify a readable directory")))
6197 pr-i-directory)
6198 ;; 1b. Directory: File Regexp
6199 (widget-create 'regexp
6200 :size 58
6201 :format "\n File Regexp : %v\n"
6202 :notify (lambda (widget &rest ignore)
6203 (setq pr-i-regexp (widget-value widget)))
6204 pr-i-regexp)
6205 ;; 1b. Directory: List Directory Entry
6206 (widget-insert " ")
6207 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
6209 ;; 1c. PostScript File:
6210 (pr-insert-radio-button 'pr-i-process 'file)
6211 (widget-create
6212 'file
6213 :size 51
6214 :format " PostScript File : %v"
6215 :notify 'pr-interface-infile
6216 :action (lambda (widget &rest event)
6217 (if (pr-interface-infile widget)
6218 (pr-widget-field-action widget event)
6219 (ding)
6220 (message "Please specify a readable PostScript file")))
6221 pr-i-ps-file)
6222 ;; 1c. PostScript File: PostScript Utility
6223 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
6224 (pr-choice-alist pr-ps-utility-alist)
6225 "\n PostScript Utility : "
6226 " ")
6227 ;; 1c. PostScript File: No Preprocessing
6228 (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
6231 (defun pr-insert-section-2 ()
6232 ;; 2. PostScript Printer:
6233 ;; 2. PostScript Printer: PostScript Printer List
6234 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
6235 (pr-insert-menu "PostScript Printer" 'pr-ps-name
6236 (pr-choice-alist pr-ps-printer-alist))
6237 ;; 2. PostScript Printer: Despool
6238 (put 'pr-i-despool 'pr-widget
6239 (pr-insert-checkbox
6241 'pr-i-despool
6242 #'(lambda (widget &rest ignore)
6243 (if pr-spool-p
6244 (setq pr-i-despool (not pr-i-despool))
6245 (ding)
6246 (message "Can despool only when spooling is actually selected")
6247 (setq pr-i-despool nil))
6248 (widget-value-set widget pr-i-despool)
6249 (widget-setup)) ; MUST be called after widget-value-set
6250 " Despool "))
6251 ;; 2. PostScript Printer: Preview Print Quit
6252 (pr-insert-button 'pr-interface-preview "Preview" " ")
6253 (pr-insert-button 'pr-interface-ps-print "Print" " ")
6254 (pr-insert-button 'pr-interface-quit "Quit")
6255 ;; 2. PostScript Printer: Send to Printer/Temporary File
6256 (pr-insert-radio-button 'pr-i-ps-send 'printer)
6257 (widget-insert " Send to Printer/Temporary File")
6258 ;; 2. PostScript Printer: Send to File
6259 (pr-insert-radio-button 'pr-i-ps-send 'file)
6260 (widget-create
6261 'file
6262 :size 57
6263 :format " Send to File : %v"
6264 :notify 'pr-interface-outfile
6265 :action (lambda (widget &rest event)
6266 (if (and (pr-interface-outfile widget)
6267 (or (not (file-exists-p pr-i-out-file))
6268 (setq pr-i-answer-yes
6269 (y-or-n-p "File exists; overwrite? "))))
6270 (pr-widget-field-action widget event)
6271 (ding)
6272 (message "Please specify a writable PostScript file")))
6273 pr-i-out-file)
6274 ;; 2. PostScript Printer: N-Up
6275 (widget-create
6276 'integer
6277 :size 3
6278 :format "\n N-Up : %v"
6279 :notify (lambda (widget &rest ignore)
6280 (let ((value (if (string= (widget-apply widget :value-get) "")
6282 (widget-value widget))))
6283 (if (and (integerp value)
6284 (<= 1 value) (<= value 100))
6285 (progn
6286 (message " ")
6287 (setq pr-i-n-up value))
6288 (ding)
6289 (message "Please specify an integer between 1 and 100"))))
6290 pr-i-n-up))
6293 (defun pr-insert-section-3 ()
6294 ;; 3. Text Printer:
6295 (pr-insert-italic "\n\nText Printer : " 2 14)
6296 (pr-insert-menu "Text Printer" 'pr-txt-name
6297 (pr-choice-alist pr-txt-printer-alist)
6298 nil " ")
6299 (pr-insert-button 'pr-interface-printify "Printify" " ")
6300 (pr-insert-button 'pr-interface-txt-print "Print" " ")
6301 (pr-insert-button 'pr-interface-quit "Quit"))
6304 (defun pr-insert-section-4 ()
6305 ;; 4. Settings:
6306 ;; 4. Settings: Landscape Auto Region Verbose
6307 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
6308 #'(lambda (&rest ignore)
6309 (setq ps-landscape-mode (not ps-landscape-mode)
6310 pr-file-landscape ps-landscape-mode))
6311 " Landscape ")
6312 (pr-insert-toggle 'pr-auto-region " Auto Region ")
6313 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
6315 ;; 4. Settings: Print Header Auto Mode
6316 (pr-insert-toggle 'ps-print-header " Print Header ")
6317 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
6319 ;; 4. Settings: Print Header Frame Menu Lock
6320 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
6321 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
6323 ;; 4. Settings: Line Number
6324 (pr-insert-toggle 'ps-line-number " Line Number\n ")
6326 ;; 4. Settings: Zebra Stripes Spool Buffer
6327 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
6328 (pr-insert-checkbox " "
6329 'pr-spool-p
6330 #'(lambda (&rest ignore)
6331 (setq pr-spool-p (not pr-spool-p))
6332 (unless pr-spool-p
6333 (setq pr-i-despool nil)
6334 (pr-update-checkbox 'pr-i-despool)))
6335 " Spool Buffer")
6337 ;; 4. Settings: Duplex Print with faces
6338 (pr-insert-checkbox "\n "
6339 'ps-spool-duplex
6340 #'(lambda (&rest ignore)
6341 (setq ps-spool-duplex (not ps-spool-duplex)
6342 pr-file-duplex ps-spool-duplex))
6343 " Duplex ")
6344 (pr-insert-toggle 'pr-faces-p " Print with faces")
6346 ;; 4. Settings: Tumble Print via Ghostscript
6347 (pr-insert-checkbox "\n "
6348 'ps-spool-tumble
6349 #'(lambda (&rest ignore)
6350 (setq ps-spool-tumble (not ps-spool-tumble)
6351 pr-file-tumble ps-spool-tumble))
6352 " Tumble ")
6353 (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
6355 ;; 4. Settings: Upside-Down Page Parity
6356 (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
6357 (pr-insert-italic "\n\nSelect Pages : " 2 14)
6358 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
6359 (mapcar #'(lambda (alist)
6360 (list 'quote
6361 (list 'choice-item
6362 :format "%[%t%]"
6363 :tag (cdr alist)
6364 :value (car alist))))
6365 pr-even-or-odd-alist)))
6368 (defun pr-insert-section-5 ()
6369 ;; 5. Customize:
6370 (pr-insert-italic "\n\nCustomize : " 2 11)
6371 (pr-insert-button 'pr-customize "printing" " ")
6372 (pr-insert-button #'(lambda (&rest ignore) (ps-print-customize))
6373 "ps-print" " ")
6374 (pr-insert-button 'lpr-customize "lpr"))
6377 (defun pr-insert-section-6 ()
6378 ;; 6. Show Settings:
6379 (pr-insert-italic "\nShow Settings : " 1 14)
6380 (pr-insert-button 'pr-show-pr-setup "printing" " ")
6381 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
6382 (pr-insert-button 'pr-show-lpr-setup "lpr"))
6385 (defun pr-insert-section-7 ()
6386 ;; 7. Help:
6387 (pr-insert-italic "\nHelp : " 1 5)
6388 (pr-insert-button 'pr-interface-help "Interface Help" " ")
6389 (pr-insert-button 'pr-help "Menu Help" " ")
6390 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
6391 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
6394 (defun pr-kill-help (&rest ignore)
6395 "Kill all printing help buffer."
6396 (interactive)
6397 (let ((help '("*Printing Interface Help*" "*Printing Help*"
6398 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
6399 (while help
6400 (let ((buffer (get-buffer (car help))))
6401 (setq help (cdr help))
6402 (when buffer
6403 (delete-windows-on buffer)
6404 (kill-buffer buffer)))))
6405 (recenter (- (window-height) 2)))
6408 (defun pr-interface-quit (&rest ignore)
6409 "Kill the printing buffer interface and quit."
6410 (interactive)
6411 (kill-buffer pr-buffer-name)
6412 (set-window-configuration pr-i-window-configuration))
6415 (defun pr-interface-help (&rest ignore)
6416 "printing buffer interface help."
6417 (interactive)
6418 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
6421 (defun pr-interface-txt-print (&rest ignore)
6422 "Print using lpr package."
6423 (interactive)
6424 (condition-case data
6425 (cond
6426 ((eq pr-i-process 'directory)
6427 (pr-i-directory)
6428 (pr-interface-save
6429 (pr-txt-directory pr-i-directory pr-i-regexp)))
6430 ((eq pr-i-process 'buffer)
6431 (pr-interface-save
6432 (cond (pr-i-region
6433 (let ((pr-auto-mode pr-i-mode))
6434 (pr-txt-region)))
6435 (pr-i-mode
6436 (let (pr-auto-region)
6437 (pr-txt-mode)))
6439 (let (pr-auto-mode pr-auto-region)
6440 (pr-txt-buffer)))
6442 ((eq pr-i-process 'file)
6443 (error "Please specify a text file"))
6445 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6447 ;; handlers
6448 ((quit error)
6449 (ding)
6450 (message "%s" (error-message-string data)))))
6453 (defun pr-interface-printify (&rest ignore)
6454 "Printify a buffer."
6455 (interactive)
6456 (condition-case data
6457 (cond
6458 ((eq pr-i-process 'directory)
6459 (pr-i-directory)
6460 (pr-interface-save
6461 (pr-printify-directory pr-i-directory pr-i-regexp)))
6462 ((eq pr-i-process 'buffer)
6463 (pr-interface-save
6464 (if pr-i-region
6465 (pr-printify-region)
6466 (pr-printify-buffer))))
6467 ((eq pr-i-process 'file)
6468 (error "Cannot printify a PostScript file"))
6470 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6472 ;; handlers
6473 ((quit error)
6474 (ding)
6475 (message "%s" (error-message-string data)))))
6478 (defun pr-interface-ps-print (&rest ignore)
6479 "Print using ps-print package."
6480 (interactive)
6481 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6482 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6483 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6484 'pr-ps-buffer-ps-print))
6487 (defun pr-interface-preview (&rest ignore)
6488 "Preview a PostScript file."
6489 (interactive)
6490 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6491 'pr-ps-file-preview 'pr-ps-file-up-preview
6492 'pr-ps-region-preview 'pr-ps-mode-preview
6493 'pr-ps-buffer-preview))
6496 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6497 ps-mode ps-buffer)
6498 (condition-case data
6499 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6500 (pr-i-ps-send))))
6501 (cond
6502 ((and pr-i-despool pr-spool-p)
6503 (pr-interface-save
6504 (funcall ps-despool outfile))
6505 (setq pr-i-despool nil)
6506 (pr-update-checkbox 'pr-i-despool))
6507 ((eq pr-i-process 'directory)
6508 (pr-i-directory)
6509 (pr-interface-save
6510 (funcall ps-directory
6511 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6512 ((eq pr-i-process 'file)
6513 (cond ((or (file-directory-p pr-i-ps-file)
6514 (not (file-readable-p pr-i-ps-file)))
6515 (error "Please specify a readable PostScript file"))
6516 (pr-i-ps-as-is
6517 (pr-interface-save
6518 (funcall ps-file pr-i-ps-file)))
6520 (pr-interface-save
6521 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6523 ((eq pr-i-process 'buffer)
6524 (pr-interface-save
6525 (cond (pr-i-region
6526 (let ((pr-auto-mode pr-i-mode))
6527 (funcall ps-region pr-i-n-up outfile)))
6528 (pr-i-mode
6529 (let (pr-auto-region)
6530 (funcall ps-mode pr-i-n-up outfile)))
6532 (let (pr-auto-mode pr-auto-region)
6533 (funcall ps-buffer pr-i-n-up outfile)))
6536 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6538 ;; handlers
6539 ((quit error)
6540 (ding)
6541 (message "%s" (error-message-string data)))))
6544 (defun pr-i-ps-send ()
6545 (cond ((eq pr-i-ps-send 'printer)
6546 nil)
6547 ((not (eq pr-i-ps-send 'file))
6548 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6549 ((or (file-directory-p pr-i-out-file)
6550 (not (file-writable-p pr-i-out-file)))
6551 (error "Please specify a writable PostScript file"))
6552 ((or (not (file-exists-p pr-i-out-file))
6553 pr-i-answer-yes
6554 (setq pr-i-answer-yes
6555 (y-or-n-p (format "File `%s' exists; overwrite? "
6556 pr-i-out-file))))
6557 pr-i-out-file)
6559 (error "File already exists"))))
6562 (defun pr-i-directory ()
6563 (or (and (file-directory-p pr-i-directory)
6564 (file-readable-p pr-i-directory))
6565 (error "Please specify be a readable directory")))
6568 (defun pr-interface-directory (widget &rest ignore)
6569 (and pr-buffer-verbose
6570 (message "You can use M-TAB or ESC TAB for file completion"))
6571 (let ((dir (widget-value widget)))
6572 (and (file-directory-p dir)
6573 (file-readable-p dir)
6574 (setq pr-i-directory dir))))
6577 (defun pr-interface-infile (widget &rest ignore)
6578 (and pr-buffer-verbose
6579 (message "You can use M-TAB or ESC TAB for file completion"))
6580 (let ((file (widget-value widget)))
6581 (and (not (file-directory-p file))
6582 (file-readable-p file)
6583 (setq pr-i-ps-file file))))
6586 (defun pr-interface-outfile (widget &rest ignore)
6587 (setq pr-i-answer-yes nil)
6588 (and pr-buffer-verbose
6589 (message "You can use M-TAB or ESC TAB for file completion"))
6590 (let ((file (widget-value widget)))
6591 (and (not (file-directory-p file))
6592 (file-writable-p file)
6593 (setq pr-i-out-file file))))
6596 (defun pr-widget-field-action (widget event)
6597 (and (get-buffer "*Completions*") ; clean frame window
6598 (delete-windows-on "*Completions*"))
6599 (message " ") ; clean echo area
6600 (widget-field-action widget event))
6603 (defun pr-insert-italic (str &optional from to)
6604 (let ((len (length str)))
6605 (put-text-property (if from (max from 0) 0)
6606 (if to (max to len) len)
6607 'face 'italic str)
6608 (widget-insert str)))
6611 (defun pr-insert-checkbox (before var-sym fun label)
6612 (widget-insert before)
6613 (prog1
6614 (widget-create 'checkbox
6615 :notify fun
6616 (symbol-value var-sym))
6617 (widget-insert label)))
6620 (defun pr-insert-toggle (var-sym label)
6621 (widget-create 'checkbox
6622 :notify `(lambda (&rest ignore)
6623 (setq ,var-sym (not ,var-sym)))
6624 (symbol-value var-sym))
6625 (widget-insert label))
6628 (defun pr-insert-button (fun label &optional separator)
6629 (widget-create 'push-button
6630 :notify fun
6631 label)
6632 (and separator
6633 (widget-insert separator)))
6636 (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6637 (and before (widget-insert before))
6638 (eval `(widget-create 'menu-choice
6639 :tag ,tag
6640 :format "%v"
6641 :inline t
6642 :value ,var-sym
6643 :notify (lambda (widget &rest ignore)
6644 (setq ,var-sym (widget-value widget))
6645 ,@body)
6646 :void '(choice-item :format "%[%t%]"
6647 :tag "Can not display value!")
6648 ,@choices))
6649 (and after (widget-insert after)))
6652 (defun pr-insert-radio-button (var-sym sym)
6653 (widget-insert "\n")
6654 (let ((wid-list (get var-sym 'pr-widget-list))
6655 (wid (eval `(widget-create
6656 'radio-button
6657 :format " %[%v%]"
6658 :value (eq ,var-sym (quote ,sym))
6659 :notify (lambda (&rest ignore)
6660 (setq ,var-sym (quote ,sym))
6661 (pr-update-radio-button (quote ,var-sym)))))))
6662 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6665 (defun pr-update-radio-button (var-sym)
6666 (let ((wid-list (get var-sym 'pr-widget-list)))
6667 (while wid-list
6668 (let ((wid (car (car wid-list)))
6669 (value (cdr (car wid-list))))
6670 (setq wid-list (cdr wid-list))
6671 (widget-value-set wid (eq (symbol-value var-sym) value))))
6672 (widget-setup)))
6675 (defun pr-update-checkbox (var-sym)
6676 (let ((wid (get var-sym 'pr-widget)))
6677 (when wid
6678 (widget-value-set wid (symbol-value var-sym))
6679 (widget-setup))))
6682 (defun pr-choice-alist (alist)
6683 (let ((max (apply 'max (mapcar #'(lambda (alist)
6684 (length (symbol-name (car alist))))
6685 alist))))
6686 (mapcar #'(lambda (alist)
6687 (let* ((sym (car alist))
6688 (name (symbol-name sym)))
6689 (list
6690 'quote
6691 (list
6692 'choice-item
6693 :format "%[%t%]"
6694 :tag (concat name
6695 (make-string (- max (length name)) ?_))
6696 :value sym))))
6697 alist)))
6700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6703 (provide 'printing)
6706 ;; arch-tag: 9ce9ac3f-0f60-4370-900b-1943215d9d18
6707 ;;; printing.el ends here