Explain combine-and-quote-strings, split-string-and-unquote.
[emacs.git] / lisp / printing.el
blobf83509d085e397eaa51fb859da7b89bd9571be57
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.8.4
10 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
12 (defconst pr-version "6.8.4"
13 "printing.el, v 6.8.4 <2005/06/11 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)))))
1096 ;; GNU Emacs
1097 (defalias 'pr-e-frame-char-height 'frame-char-height)
1098 (defalias 'pr-e-frame-char-width 'frame-char-width)
1099 (defalias 'pr-e-mouse-pixel-position 'mouse-pixel-position)
1100 ;; XEmacs
1101 (defalias 'pr-x-add-submenu 'add-submenu)
1102 (defalias 'pr-x-event-function 'event-function)
1103 (defalias 'pr-x-event-object 'event-object)
1104 (defalias 'pr-x-find-menu-item 'find-menu-item)
1105 (defalias 'pr-x-font-height 'font-height)
1106 (defalias 'pr-x-font-width 'font-width)
1107 (defalias 'pr-x-get-popup-menu-response 'get-popup-menu-response)
1108 (defalias 'pr-x-make-event 'make-event)
1109 (defalias 'pr-x-misc-user-event-p 'misc-user-event-p)
1110 (defalias 'pr-x-relabel-menu-item 'relabel-menu-item)
1111 (defalias 'pr-x-event-x-pixel 'event-x-pixel)
1112 (defalias 'pr-x-event-y-pixel 'event-y-pixel)
1114 (cond
1115 ((featurep 'xemacs) ; XEmacs
1116 (defvar current-menubar nil)
1117 (defvar current-mouse-event nil)
1118 (defvar zmacs-region-stays nil)
1119 (defalias 'pr-f-set-keymap-parents 'set-keymap-parents)
1120 (defalias 'pr-f-set-keymap-name 'set-keymap-name)
1121 (defun pr-f-read-string (prompt initial history default)
1122 (let ((str (read-string prompt initial)))
1123 (if (and str (not (string= str "")))
1125 default)))
1126 (defun pr-keep-region-active ()
1127 (setq zmacs-region-stays t)))
1129 (t ; GNU Emacs
1130 (defvar deactivate-mark nil)
1131 (defalias 'pr-f-set-keymap-parents 'set-keymap-parent)
1132 (defalias 'pr-f-set-keymap-name 'ignore)
1133 (defalias 'pr-f-read-string 'read-string)
1134 (defun pr-keep-region-active ()
1135 (setq deactivate-mark nil))))
1138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1139 ;; Customization Functions
1142 (defun pr-alist-custom-set (symbol value)
1143 "Set the value of custom variables for printer & utility selection."
1144 (set symbol value)
1145 (and (featurep 'printing) ; update only after printing is loaded
1146 (pr-update-menus t)))
1149 (defun pr-ps-utility-custom-set (symbol value)
1150 "Update utility menu entry."
1151 (set symbol value)
1152 (and (featurep 'printing) ; update only after printing is loaded
1153 (pr-menu-set-utility-title value)))
1156 (defun pr-ps-name-custom-set (symbol value)
1157 "Update `PostScript Printer:' menu entry."
1158 (set symbol value)
1159 (and (featurep 'printing) ; update only after printing is loaded
1160 (pr-menu-set-ps-title value)))
1163 (defun pr-txt-name-custom-set (symbol value)
1164 "Update `Text Printer:' menu entry."
1165 (set symbol value)
1166 (and (featurep 'printing) ; update only after printing is loaded
1167 (pr-menu-set-txt-title value)))
1170 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1171 ;; User Interface (I)
1174 (defgroup printing nil
1175 "Printing Utilities group."
1176 :tag "Printing Utilities"
1177 :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
1178 :prefix "pr-"
1179 :version "22.1"
1180 :group 'wp
1181 :group 'postscript)
1184 (defcustom pr-path-style
1185 (if (and (not pr-cygwin-system)
1186 ps-windows-system)
1187 'windows
1188 'unix)
1189 "*Specify which path style to use for external commands.
1191 Valid values are:
1193 windows Windows 9x/NT style (\\)
1195 unix Unix style (/)"
1196 :type '(choice :tag "Path style"
1197 (const :tag "Windows 9x/NT Style (\\)" :value windows)
1198 (const :tag "Unix Style (/)" :value unix))
1199 :group 'printing)
1202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1203 ;; Internal Functions (I)
1206 (defun pr-dosify-file-name (path)
1207 "Replace unix-style directory separator character with dos/windows one."
1208 (interactive "sPath: ")
1209 (if (eq pr-path-style 'windows)
1210 (subst-char-in-string ?/ ?\\ path)
1211 path))
1214 (defun pr-unixify-file-name (path)
1215 "Replace dos/windows-style directory separator character with unix one."
1216 (interactive "sPath: ")
1217 (if (eq pr-path-style 'windows)
1218 (subst-char-in-string ?\\ ?/ path)
1219 path))
1222 (defun pr-standard-file-name (path)
1223 "Ensure the proper directory separator depending on the OS.
1224 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
1225 separator; otherwise, ensure unix-style directory separator."
1226 (if (or pr-cygwin-system ps-windows-system)
1227 (subst-char-in-string ?/ ?\\ path)
1228 (subst-char-in-string ?\\ ?/ path)))
1231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1232 ;; User Interface (II)
1235 (defcustom pr-path-alist
1236 '((unix PATH)
1237 (cygwin PATH)
1238 (windows PATH))
1239 "*Specify an alist for command paths.
1241 It's used to find commands used for printing package, like gv, gs, gsview.exe,
1242 mpage, print.exe, etc. See also `pr-command' function.
1244 Each element has the form:
1246 (ENTRY DIRECTORY...)
1248 Where:
1250 ENTRY It's a symbol, used to identify this entry.
1251 There must exist at least one of the following entries:
1253 unix this entry is used when Emacs is running on GNU or
1254 Unix system.
1256 cygwin this entry is used when Emacs is running on Windows
1257 95/98/NT/2000 with Cygwin.
1259 windows this entry is used when Emacs is running on Windows
1260 95/98/NT/2000.
1262 DIRECTORY It should be a string or a symbol. If it's a symbol, it should
1263 exist an equal entry in `pr-path-alist'. If it's a string,
1264 it's considered a directory specification.
1266 The directory specification may contain:
1267 $var environment variable expansion
1268 ~/ tilde expansion
1269 ./ current directory
1270 ../ previous directory
1272 For example, let's say the home directory is /home/my and the
1273 current directory is /home/my/dir, so:
1275 THE ENTRY IS EXPANDED TO
1276 ~/entry /home/my/entry
1277 ./entry /home/my/dir/entry
1278 ../entry /home/my/entry
1279 $HOME/entry /home/my/entry
1280 $HOME/~/other/../my/entry /home/my/entry
1282 SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
1283 list and there isn't a `PATH' entry in `pr-path-alist' or the
1284 `PATH' entry has a null directory list, the PATH environment
1285 variable is used.
1287 Examples:
1289 * On GNU or Unix system:
1291 '((unix \".\" \"~/bin\" ghostview mpage PATH)
1292 (ghostview \"$HOME/bin/gsview-dir\")
1293 (mpage \"$HOME/bin/mpage-dir\")
1296 * On Windows system:
1298 '((windows \"c:/applications/executables\" PATH ghostview mpage)
1299 (ghostview \"c:/gs/gsview-dir\")
1300 (mpage \"c:/mpage-dir\")
1302 :type '(repeat
1303 (cons :tag ""
1304 (symbol :tag "Identifier ")
1305 (repeat :tag "Directory List"
1306 (choice :menu-tag "Directory"
1307 :tag "Directory"
1308 (string :value "")
1309 (symbol :value symbol)))))
1310 :group 'printing)
1313 (defcustom pr-txt-name 'default
1314 "*Specify a printer for printing a text file.
1316 The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
1317 documentation).
1319 This variable should be modified by customization engine. If this variable is
1320 modified by other means (for example, a lisp function), use `pr-update-menus'
1321 function (see it for documentation) to update text printer menu."
1322 :type 'symbol
1323 :set 'pr-txt-name-custom-set
1324 :group 'printing)
1327 (defcustom pr-txt-printer-alist
1328 (list (list 'default lpr-command nil
1329 (cond ((boundp 'printer-name) printer-name)
1330 (ps-windows-system "PRN")
1331 (t nil)
1333 ;; Examples:
1334 ;; * On GNU or Unix system:
1335 ;; '((prt_06a "lpr" nil "prt_06a")
1336 ;; (prt_07c nil nil "prt_07c")
1337 ;; )
1338 ;; * On Windows system:
1339 ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
1340 ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
1341 ;; (PRN "" nil "PRN")
1342 ;; (standard "redpr.exe" nil "")
1343 ;; )
1344 "*Specify an alist of all text printers (text printer database).
1346 The alist element has the form:
1348 (SYMBOL COMMAND SWITCHES NAME)
1350 Where:
1352 SYMBOL It's a symbol to identify a text printer. It's for
1353 `pr-txt-name' variable setting and for menu selection.
1354 Examples:
1355 'prt_06a
1356 'my_printer
1358 COMMAND Name of the program for printing a text file. On MS-DOS and
1359 MS-Windows systems, if the value is an empty string, then Emacs
1360 will write directly to the printer port given by NAME (see text
1361 below), that is, the NAME should be something like \"PRN\" or
1362 \"LPT1:\".
1363 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1364 COMMAND shouldn't be an empty string.
1365 The programs `print' and `nprint' (the standard print programs
1366 on Windows NT and Novell Netware respectively) are handled
1367 specially, using NAME as the destination for output; any other
1368 program is treated like `lpr' except that an explicit filename
1369 is given as the last argument.
1370 If COMMAND is nil, it's used the default printing program:
1371 `print' for Windows system, `lp' for lp system and `lpr' for
1372 all other systems. See also `pr-path-alist'.
1373 Examples:
1374 \"print\"
1375 \"lpr\"
1376 \"lp\"
1378 SWITCHES List of sexp's to pass as extra options for text printer
1379 program. It is recommended to set NAME (see text below)
1380 instead of including an explicit switch on this list.
1381 Example:
1382 . for lpr
1383 '(\"-#3\" \"-l\")
1386 NAME A string that specifies a text printer name.
1387 On Unix-like systems, a string value should be a name
1388 understood by lpr's -P option (or lp's -d option).
1389 On MS-DOS and MS-Windows systems, it is the name of a printer
1390 device or port. Typical non-default settings would be \"LPT1:\"
1391 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1392 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1393 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1394 printer. You can also set it to a name of a file, in which
1395 case the output gets appended to that file. If you want to
1396 discard the printed output, set this to \"NUL\".
1397 Examples:
1398 . for print.exe
1399 \"/D:\\\\\\\\host\\\\share-name\"
1400 \"LPT1:\"
1401 \"PRN\"
1403 . for lpr or lp
1404 \"share-name\"
1406 This variable should be modified by customization engine. If this variable is
1407 modified by other means (for example, a lisp function), use `pr-update-menus'
1408 function (see it for documentation) to update text printer menu.
1410 Examples:
1412 * On GNU or Unix system:
1414 '((prt_06a \"lpr\" nil \"prt_06a\")
1415 (prt_07c nil nil \"prt_07c\")
1418 * On Windows system:
1420 '((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1421 (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
1422 (PRN \"\" nil \"PRN\")
1423 (standard \"redpr.exe\" nil \"\")
1426 Useful links:
1428 * Information about the print command (print.exe)
1429 `http://www.computerhope.com/printhlp.htm'
1431 * RedMon - Redirection Port Monitor (redpr.exe)
1432 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1434 * Redirection Port Monitor (redpr.exe on-line help)
1435 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1437 * UNIX man pages: lpr (or type `man lpr')
1438 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1439 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1441 * UNIX man pages: lp (or type `man lp')
1442 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1443 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1445 :type '(repeat
1446 (list :tag "Text Printer"
1447 (symbol :tag "Printer Symbol Name")
1448 (string :tag "Printer Command")
1449 (repeat :tag "Printer Switches"
1450 (sexp :tag "Switch" :value ""))
1451 (choice :menu-tag "Printer Name"
1452 :tag "Printer Name"
1453 (const :tag "None" nil)
1454 string)))
1455 :set 'pr-alist-custom-set
1456 :group 'printing)
1459 (defcustom pr-ps-name 'default
1460 "*Specify a printer for printing a PostScript file.
1462 This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
1463 documentation).
1465 This variable should be modified by customization engine. If this variable is
1466 modified by other means (for example, a lisp function), use `pr-update-menus'
1467 function (see it for documentation) to update PostScript printer menu."
1468 :type 'symbol
1469 :set 'pr-ps-name-custom-set
1470 :group 'printing)
1473 (defcustom pr-ps-printer-alist
1474 (list (list 'default lpr-command nil
1475 (cond (ps-windows-system nil)
1476 (ps-lp-system "-d")
1477 (t "-P"))
1478 (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
1479 ;; Examples:
1480 ;; * On GNU or Unix system:
1481 ;; '((lps_06b "lpr" nil "-P" "lps_06b")
1482 ;; (lps_07c "lpr" nil nil "lps_07c")
1483 ;; (lps_08c nil nil nil "lps_08c")
1484 ;; )
1485 ;; * On Windows system:
1486 ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
1487 ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
1488 ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
1489 ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
1490 ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
1491 ;; (LPT1 "" nil "" "LPT1:")
1492 ;; (PRN "" nil "" "PRN")
1493 ;; (standard "redpr.exe" nil "" "")
1494 ;; )
1495 "*Specify an alist for all PostScript printers (PostScript printer database).
1497 The alist element has the form:
1499 (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
1501 Where:
1503 SYMBOL It's a symbol to identify a PostScript printer. It's for
1504 `pr-ps-name' variable setting and for menu selection.
1505 Examples:
1506 'prt_06a
1507 'my_printer
1509 COMMAND Name of the program for printing a PostScript file. On MS-DOS
1510 and MS-Windows systems, if the value is an empty string then
1511 Emacs will write directly to the printer port given by NAME
1512 (see text below), that is, the NAME should be something like
1513 \"PRN\" or \"LPT1:\".
1514 If NAME is something like \"\\\\\\\\host\\\\share-name\" then
1515 COMMAND shouldn't be an empty string.
1516 The programs `print' and `nprint' (the standard print programs
1517 on Windows NT and Novell Netware respectively) are handled
1518 specially, using NAME as the destination for output; any other
1519 program is treated like `lpr' except that an explicit filename
1520 is given as the last argument.
1521 If COMMAND is nil, it's used the default printing program:
1522 `print' for Windows system, `lp' for lp system and `lpr' for
1523 all other systems. See also `pr-path-alist'.
1524 Examples:
1525 \"print\"
1526 \"lpr\"
1527 \"lp\"
1528 \"cp\"
1529 \"gsprint\"
1531 SWITCHES List of sexp's to pass as extra options for PostScript printer
1532 program. It is recommended to set NAME (see text below)
1533 instead of including an explicit switch on this list.
1534 Example:
1535 . for lpr
1536 '(\"-#3\" \"-l\")
1539 . for gsprint.exe
1540 '(\"-all\" \"-twoup\")
1542 PRINTER-SWITCH A string that specifies PostScript printer name switch. If
1543 it's necessary to have a space between PRINTER-SWITCH and NAME,
1544 it should be inserted at the end of PRINTER-SWITCH string.
1545 If PRINTER-SWITCH is nil, it's used the default printer name
1546 switch: `/D:' for Windows system, `-d' for lp system and `-P'
1547 for all other systems.
1548 Examples:
1549 . for lpr
1550 \"-P \"
1552 . for lp
1553 \"-d \"
1555 . for print.exe
1556 \"/D:\"
1558 . for gsprint.exe
1559 \"-printer \"
1561 NAME A string that specifies a PostScript printer name.
1562 On Unix-like systems, a string value should be a name
1563 understood by lpr's -P option (or lp's -d option).
1564 On MS-DOS and MS-Windows systems, it is the name of a printer
1565 device or port. Typical non-default settings would be \"LPT1:\"
1566 to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
1567 \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
1568 (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
1569 printer. You can also set it to a name of a file, in which
1570 case the output gets appended to that file. If you want to
1571 discard the printed output, set this to \"NUL\".
1572 Examples:
1573 . for cp.exe
1574 \"\\\\\\\\host\\\\share-name\"
1576 . for print.exe or gsprint.exe
1577 \"/D:\\\\\\\\host\\\\share-name\"
1578 \"\\\\\\\\host\\\\share-name\"
1579 \"LPT1:\"
1580 \"PRN\"
1582 . for lpr or lp
1583 \"share-name\"
1585 DEFAULT It's a way to set default values when this entry is selected.
1586 It's a cons like:
1588 (VARIABLE . VALUE)
1590 That associates VARIABLE with VALUE. when this entry is
1591 selected, it's executed the following command:
1593 (set VARIABLE (eval VALUE))
1595 Note that VALUE can be any valid lisp expression. So, don't
1596 forget to quote symbols and constant lists.
1597 If VARIABLE is the special keyword `inherits-from:', VALUE must
1598 be a symbol name setting defined in `pr-setting-database' from
1599 which the current setting inherits the context. Take care with
1600 circular inheritance.
1601 Examples:
1602 '(ps-landscape-mode . nil)
1603 '(ps-spool-duplex . t)
1604 '(pr-gs-device . (my-gs-device t))
1606 This variable should be modified by customization engine. If this variable is
1607 modified by other means (for example, a lisp function), use `pr-update-menus'
1608 function (see it for documentation) to update PostScript printer menu.
1610 Examples:
1612 * On GNU or Unix system:
1614 '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
1615 (lps_07c \"lpr\" nil nil \"lps_07c\")
1616 (lps_08c nil nil nil \"lps_08c\")
1619 * On Windows system:
1621 '((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
1622 (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
1623 (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
1624 (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
1625 (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
1626 (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
1627 (LPT1 \"\" nil \"\" \"LPT1:\")
1628 (PRN \"\" nil \"\" \"PRN\")
1629 (standard \"redpr.exe\" nil \"\" \"\")
1633 gsprint:
1635 You can use gsprint instead of ghostscript to print monochrome PostScript files
1636 in Windows. The gsprint utility documentation says that it is more efficient
1637 than ghostscript to print monochrome PostScript.
1639 To print non-monochrome PostScript file, the efficiency of ghostscript is
1640 similar to gsprint.
1642 Also the gsprint utility comes together with gsview distribution.
1644 As an example of gsprint declaration:
1646 (setq pr-ps-printer-alist
1647 '((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
1648 (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
1649 ;; some other printer declaration
1652 The example above declares that printer A prints all pages (-all) and two pages
1653 per sheet (-twoup). The printer B declaration does the same as the printer A
1654 declaration, the only difference is the printer name selection.
1656 There are other command line options like:
1658 -mono Render in monochrome as 1bit/pixel (only black and white).
1659 -grey Render in greyscale as 8bits/pixel.
1660 -color Render in color as 24bits/pixel.
1662 The default is `-mono'. So, printer A and B in the example above are using
1663 implicitly the `-mono' option. Note that in `-mono' no gray tone or color is
1664 printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
1665 are not printed.
1668 Useful links:
1670 * GSPRINT - Ghostscript print to Windows printer
1671 `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
1673 * Introduction to Ghostscript
1674 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
1676 * How to use Ghostscript
1677 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
1679 * Information about the print command (print.exe)
1680 `http://www.computerhope.com/printhlp.htm'
1682 * RedMon - Redirection Port Monitor (redpr.exe)
1683 `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
1685 * Redirection Port Monitor (redpr.exe on-line help)
1686 `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
1688 * UNIX man pages: lpr (or type `man lpr')
1689 `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
1690 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
1692 * UNIX man pages: lp (or type `man lp')
1693 `http://bama.ua.edu/cgi-bin/man-cgi?lp'
1694 `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
1696 * GNU utilities for Win32 (cp.exe)
1697 `http://unxutils.sourceforge.net/'
1699 :type '(repeat
1700 (list
1701 :tag "PostScript Printer"
1702 (symbol :tag "Printer Symbol Name")
1703 (string :tag "Printer Command")
1704 (repeat :tag "Printer Switches"
1705 (sexp :tag "Switch" :value ""))
1706 (choice :menu-tag "Printer Name Switch"
1707 :tag "Printer Name Switch"
1708 (const :tag "None" nil)
1709 string)
1710 (choice :menu-tag "Printer Name"
1711 :tag "Printer Name"
1712 (const :tag "None" nil)
1713 string)
1714 (repeat
1715 :tag "Default Value List"
1716 :inline t
1717 (cons
1718 :tag ""
1719 (choice
1720 :menu-tag "Variable"
1721 :tag "Variable"
1722 (const :tag "Landscape" ps-landscape-mode)
1723 (const :tag "Print Header" ps-print-header)
1724 (const :tag "Print Header Frame" ps-print-header-frame)
1725 (const :tag "Line Number" ps-line-number)
1726 (const :tag "Zebra Stripes" ps-zebra-stripes)
1727 (const :tag "Duplex" ps-spool-duplex)
1728 (const :tag "Tumble" ps-spool-tumble)
1729 (const :tag "Upside-Down" ps-print-upside-down)
1730 (const :tag "PS File Landscape" pr-file-landscape)
1731 (const :tag "PS File Duplex" pr-file-duplex)
1732 (const :tag "PS File Tumble" pr-file-tumble)
1733 (const :tag "Auto Region" pr-auto-region)
1734 (const :tag "Auto Mode" pr-auto-mode)
1735 (const :tag "Ghostscript Device" pr-gs-device)
1736 (const :tag "Ghostscript Resolution" pr-gs-resolution)
1737 (const :tag "inherits-from:" inherits-from:)
1738 (variable :tag "Other"))
1739 (sexp :tag "Value")))
1741 :set 'pr-alist-custom-set
1742 :group 'printing)
1745 (defcustom pr-temp-dir
1746 (pr-dosify-file-name
1747 (if (boundp 'temporary-file-directory)
1748 (symbol-value 'temporary-file-directory)
1749 ;; hacked from `temporary-file-directory' variable in files.el
1750 (file-name-as-directory
1751 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
1752 (cond (ps-windows-system "c:/temp")
1753 ((memq system-type '(vax-vms axp-vms)) "SYS$SCRATCH:")
1754 (t "/tmp")
1755 )))))
1756 "*Specify a directory for temporary files during printing.
1758 See also `pr-ps-temp-file' and `pr-file-modes'."
1759 :type '(directory :tag "Temporary Directory")
1760 :group 'printing)
1763 (defcustom pr-ps-temp-file "prspool-"
1764 "*Specify PostScript temporary file name prefix.
1766 See also `pr-temp-dir' and `pr-file-modes'."
1767 :type '(file :tag "PostScript Temporary File Name")
1768 :group 'printing)
1771 ;; It uses 0600 as default instead of (default-file-modes).
1772 ;; So, by default, only the session owner have permission to deal with files
1773 ;; generated by `printing'.
1774 (defcustom pr-file-modes ?\600
1775 "*Specify the file permission bits for newly created files.
1777 It should be an integer; only the low 9 bits are used.
1779 See also `pr-temp-dir' and `pr-ps-temp-file'."
1780 :type '(integer :tag "File Permission Bits")
1781 :group 'printing)
1784 (defcustom pr-gv-command
1785 (if ps-windows-system
1786 "gsview32.exe"
1787 "gv")
1788 "*Specify path and name of the gsview/gv utility.
1790 See also `pr-path-alist'.
1792 Useful links:
1794 * GNU gv manual
1795 `http://www.gnu.org/software/gv/manual/gv.html'
1797 * GSview Help
1798 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'
1800 * GSview Help - Common Problems
1801 `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'
1803 * GSview Readme (compilation & installation)
1804 `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'
1806 * GSview (main site)
1807 `http://www.cs.wisc.edu/~ghost/gsview/index.htm'
1809 * Ghostscript, Ghostview and GSview
1810 `http://www.cs.wisc.edu/~ghost/'
1812 * Ghostview
1813 `http://www.cs.wisc.edu/~ghost/gv/index.htm'
1815 * gv 3.5, June 1997
1816 `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'
1818 * MacGSView (MacOS)
1819 `http://www.cs.wisc.edu/~ghost/macos/index.htm'
1821 :type '(string :tag "Ghostview Utility")
1822 :group 'printing)
1825 (defcustom pr-gs-command
1826 (if ps-windows-system
1827 "gswin32.exe"
1828 "gs")
1829 "*Specify path and name of the ghostscript utility.
1831 See also `pr-path-alist'.
1833 Useful links:
1835 * Ghostscript, Ghostview and GSview
1836 `http://www.cs.wisc.edu/~ghost/'
1838 * Introduction to Ghostscript
1839 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
1841 * How to use Ghostscript
1842 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
1844 * Printer compatibility
1845 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
1847 :type '(string :tag "Ghostscript Utility")
1848 :group 'printing)
1851 (defcustom pr-gs-switches
1852 (if ps-windows-system
1853 '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
1854 '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
1855 "*Specify ghostscript switches. See the documentation on GS for more info.
1857 It's a list of strings, where each string is one or more ghostscript switches.
1859 A note on the gs switches:
1861 -q quiet
1862 -dNOPAUSE don't wait for user intervention
1863 -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
1864 -c quit it's added at the end to terminate gs
1866 To see ghostscript documentation for more information:
1868 * On GNU or Unix system:
1869 - for full documentation, type: man gs
1870 - for brief documentation, type: gs -h
1872 * On Windows system:
1873 - for full documentation, see in a browser the file
1874 c:/gstools/gs5.50/index.html, that is, the file index.html which is
1875 located in the same directory as gswin32.exe.
1876 - for brief documentation, type: gswin32.exe -h
1878 Useful links:
1880 * Introduction to Ghostscript
1881 `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
1883 * How to use Ghostscript
1884 `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
1886 * Printer compatibility
1887 `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
1889 :type '(repeat (string :tag "Ghostscript Switch"))
1890 :group 'printing)
1893 (defcustom pr-gs-device
1894 (if ps-windows-system
1895 "mswinpr2"
1896 "uniprint")
1897 "*Specify the ghostscript device switch value (-sDEVICE=).
1899 A note on the gs switches:
1901 -sDEVICE=djet500 the printer - works with HP DeskJet 540
1903 See `pr-gs-switches' for documentation.
1904 See also `pr-ps-printer-alist'."
1905 :type '(string :tag "Ghostscript Device")
1906 :group 'printing)
1909 (defcustom pr-gs-resolution 300
1910 "*Specify ghostscript resolution switch value (-r).
1912 A note on the gs switches:
1914 -r300 resolution 300x300
1916 See `pr-gs-switches' for documentation.
1917 See also `pr-ps-printer-alist'."
1918 :type '(integer :tag "Ghostscript Resolution")
1919 :group 'printing)
1922 (defcustom pr-print-using-ghostscript nil
1923 "*Non-nil means print using ghostscript.
1925 This is useful if you don't have a PostScript printer, so you could use the
1926 ghostscript to print a PostScript file.
1928 In GNU or Unix system, if ghostscript is set as a PostScript filter, this
1929 variable should be nil."
1930 :type 'boolean
1931 :group 'printing)
1934 (defcustom pr-faces-p nil
1935 "*Non-nil means print with face attributes."
1936 :type 'boolean
1937 :group 'printing)
1940 (defcustom pr-spool-p nil
1941 "*Non-nil means spool printing in a buffer."
1942 :type 'boolean
1943 :group 'printing)
1946 (defcustom pr-file-landscape nil
1947 "*Non-nil means print PostScript file in landscape orientation."
1948 :type 'boolean
1949 :group 'printing)
1952 (defcustom pr-file-duplex nil
1953 "*Non-nil means print PostScript file in duplex mode."
1954 :type 'boolean
1955 :group 'printing)
1958 (defcustom pr-file-tumble nil
1959 "*Non-nil means print PostScript file in tumble mode.
1961 If tumble is off, produces a printing suitable for binding on the left or
1962 right.
1963 If tumble is on, produces a printing suitable for binding at the top or
1964 bottom."
1965 :type 'boolean
1966 :group 'printing)
1969 (defcustom pr-auto-region t
1970 "*Non-nil means region is automagically detected.
1972 Note that this will only work if you're using transient mark mode.
1974 When this variable is non-nil, the `*-buffer*' commands will behave like
1975 `*-region*' commands, that is, `*-buffer*' commands will print only the region
1976 marked instead of all buffer."
1977 :type 'boolean
1978 :group 'printing)
1981 (defcustom pr-auto-mode t
1982 "*Non-nil means major-mode specific printing is prefered over normal printing.
1984 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
1985 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
1986 `*-buffer*' commands will print the current buffer and `*-region*' commands
1987 will print the current region."
1988 :type 'boolean
1989 :group 'printing)
1992 (defcustom pr-mode-alist
1993 '((mh-folder-mode ; mh summary buffer
1994 pr-mh-lpr-1 pr-mh-print-1
1996 (ps-article-author ps-article-subject)
1997 ("/pagenumberstring load" pr-article-date)
2000 (mh-letter-mode ; mh letter buffer
2001 pr-mh-lpr-2 pr-mh-print-2
2003 (ps-article-author ps-article-subject)
2004 ("/pagenumberstring load" pr-article-date)
2007 (rmail-summary-mode ; rmail summary buffer
2008 pr-rmail-lpr pr-rmail-print
2010 (ps-article-subject ps-article-author buffer-name)
2014 (rmail-mode ; rmail buffer
2015 pr-rmail-lpr pr-rmail-print
2017 (ps-article-subject ps-article-author buffer-name)
2021 (gnus-summary-mode ; gnus summary buffer
2022 pr-gnus-lpr pr-gnus-print
2024 (ps-article-subject ps-article-author gnus-newsgroup-name)
2028 (gnus-article-mode ; gnus article buffer
2029 pr-gnus-lpr pr-gnus-print
2031 (ps-article-subject ps-article-author gnus-newsgroup-name)
2035 (Info-mode ; Info buffer
2036 pr-mode-lpr pr-mode-print
2038 (ps-info-node ps-info-file)
2042 (vm-mode ; vm mode
2043 pr-vm-lpr pr-vm-print
2045 (ps-article-subject ps-article-author buffer-name)
2050 "*Specify an alist for a major-mode and printing functions.
2052 To customize a major mode printing, just declare the customization in
2053 `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
2054 mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
2055 *Summary* buffer, if you forget to switch to the *Article* buffer before
2056 printing, you'll get a nicely formatted list of article subjects shows up at
2057 the printer. With major mode printing you don't need to switch from gnus
2058 *Summary* buffer first.
2060 The elements have the following form:
2062 (MAJOR-MODE
2063 LPR-PRINT PS-PRINT
2064 HEADER-LINES
2065 LEFT-HEADER
2066 RIGHT-HEADER
2067 KILL-LOCAL-VARIABLE
2068 DEFAULT...)
2070 Where:
2072 MAJOR-MODE It's the major mode symbol.
2074 LPR-PRINT It's a symbol function for text printing. It's invoked with
2075 one argument:
2076 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2078 Usually LPR-PRINT function prepares the environment or buffer
2079 and then call the function `pr-mode-lpr' which it's used to
2080 process the buffer and send it to text printer.
2082 The `pr-mode-lpr' definition is:
2084 (pr-mode-lpr HEADER-LIST &optional FROM TO)
2086 Where HEADER-LIST is like the argument passed to LPR-PRINT.
2087 FROM and TO are the beginning and end markers, respectively,
2088 for a region. If FROM is nil, it's used (point-min); if TO is
2089 nil, it's used (point-max).
2091 PS-PRINT It's a symbol function for PostScript printing. It's invoked
2092 with 3 arguments: n-up printing, file name and the list:
2093 (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
2095 Usually PS-PRINT function prepares the environment or buffer
2096 and then call the function `pr-mode-print' which it's used to
2097 process the buffer and send it to PostScript printer.
2099 The `pr-mode-print' definition is:
2101 (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
2103 Where N-UP, FILENAME and HEADER-LIST are like the arguments
2104 passed to PS-PRINT. FROM and TO are the beginning and end
2105 markers, respectively, for a region. If TO is nil, it's used
2106 (point-max).
2108 HEADER-LINES It's the number of header lines; if is nil, it uses
2109 `ps-header-lines' value.
2111 LEFT-HEADER It's the left header part, it's a list of string, variable
2112 symbol or function symbol (with no argument); if is nil, it
2113 uses `ps-left-header' value.
2115 RIGHT-HEADER It's the right header part, it's a list of string, variable
2116 symbol or function symbol (with no argument); if is nil, it
2117 uses `ps-right-header' value.
2119 KILL-LOCAL-VARIABLE
2120 Non-nil means to kill all buffer local variable declared in
2121 DEFAULT (see below).
2123 DEFAULT It's a way to set default values when this entry is selected.
2124 It's a cons like:
2126 (VARIABLE-SYM . VALUE)
2128 That associates VARIABLE-SYM with VALUE. when this entry is
2129 selected, it's executed the following command:
2131 (set (make-local-variable VARIABLE-SYM) (eval VALUE))
2133 Note that VALUE can be any valid lisp expression. So, don't
2134 forget to quote symbols and constant lists.
2135 If VARIABLE is the special keyword `inherits-from:', VALUE must
2136 be a symbol name setting defined in `pr-setting-database' from
2137 which the current setting inherits the context. Take care with
2138 circular inheritance.
2139 Examples:
2140 '(ps-landscape-mode . nil)
2141 '(ps-spool-duplex . t)
2142 '(pr-gs-device . (my-gs-device t))"
2143 :type '(repeat
2144 (list
2145 :tag ""
2146 (symbol :tag "Major Mode")
2147 (function :tag "Text Printing Function")
2148 (function :tag "PS Printing Function")
2149 (choice :menu-tag "Number of Header Lines"
2150 :tag "Number of Header Lines"
2151 (integer :tag "Number")
2152 (const :tag "Default Number" nil))
2153 (repeat :tag "Left Header List"
2154 (choice :menu-tag "Left Header"
2155 :tag "Left Header"
2156 string symbol))
2157 (repeat :tag "Right Header List"
2158 (choice :menu-tag "Right Header"
2159 :tag "Right Header"
2160 string symbol))
2161 (boolean :tag "Kill Local Variable At End")
2162 (repeat
2163 :tag "Default Value List"
2164 :inline t
2165 (cons
2166 :tag ""
2167 (choice
2168 :menu-tag "Variable"
2169 :tag "Variable"
2170 (const :tag "Landscape" ps-landscape-mode)
2171 (const :tag "Print Header" ps-print-header)
2172 (const :tag "Print Header Frame" ps-print-header-frame)
2173 (const :tag "Line Number" ps-line-number)
2174 (const :tag "Zebra Stripes" ps-zebra-stripes)
2175 (const :tag "Duplex" ps-spool-duplex)
2176 (const :tag "Tumble" ps-spool-tumble)
2177 (const :tag "Upside-Down" ps-print-upside-down)
2178 (const :tag "PS File Landscape" pr-file-landscape)
2179 (const :tag "PS File Duplex" pr-file-duplex)
2180 (const :tag "PS File Tumble" pr-file-tumble)
2181 (const :tag "Auto Region" pr-auto-region)
2182 (const :tag "Auto Mode" pr-auto-mode)
2183 (const :tag "Ghostscript Device" pr-gs-device)
2184 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2185 (const :tag "inherits-from:" inherits-from:)
2186 (variable :tag "Other"))
2187 (sexp :tag "Value")))
2189 :group 'printing)
2192 (defcustom pr-ps-utility 'mpage
2193 "*Specify PostScript utility symbol.
2195 This utility symbol should be defined on `pr-ps-utility-alist' (see it for
2196 documentation).
2198 This variable should be modified by customization engine. If this variable is
2199 modified by other means (for example, a lisp function), use `pr-update-menus'
2200 function (see it for documentation) to update PostScript utility menu.
2202 NOTE: Don't forget to download and install the utilities declared on
2203 `pr-ps-utility-alist'."
2204 :type '(symbol :tag "PS File Utility")
2205 :set 'pr-ps-utility-custom-set
2206 :group 'printing)
2209 (defcustom pr-ps-utility-alist
2210 '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2211 (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2212 (inherits-from: . no-duplex))
2214 ;; Examples:
2215 ;; * On GNU or Unix system:
2216 ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
2217 ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2218 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2219 ;; )
2220 ;; * On Windows system:
2221 ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
2222 ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
2223 ;; )
2224 "*Specify an alist for PostScript utility processing (PS utility database).
2226 The alist element has the form:
2228 (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
2229 SWITCHES DEFAULT...)
2231 Where:
2233 SYMBOL It's a symbol to identify a PostScript utility. It's for
2234 `pr-ps-utility' variable setting and for menu selection.
2235 Examples:
2236 'mpage
2237 'psnup
2239 UTILITY Name of utility for processing a PostScript file.
2240 See also `pr-path-alist'.
2241 Examples:
2242 . for GNU or Unix system:
2243 \"mpage\"
2244 \"psnup -q\"
2246 . for Windows system:
2247 \"c:/psutils/psnup -q\"
2249 MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
2250 program. These options are necessary to process the utility
2251 program and must be placed before any other switches.
2252 Example:
2253 . for psnup:
2254 '(\"-q\")
2256 PAPERSIZE It's a format string to specify paper size switch.
2257 Example:
2258 . for mpage
2259 \"-b%s\"
2261 N-UP It's a format string to specify n-up switch.
2262 Example:
2263 . for psnup
2264 \"-%d\"
2266 LANDSCAPE It's a string to specify landscape switch. If the utility
2267 doesn't have landscape switch, set to nil.
2268 Example:
2269 . for psnup
2270 \"-l\"
2272 DUPLEX It's a string to specify duplex switch. If the utility doesn't
2273 have duplex switch, set to nil.
2274 Example:
2275 . for psnup
2278 TUMBLE It's a string to specify tumble switch. If the utility doesn't
2279 have tumble switch, set to nil.
2280 Example:
2281 . for psnup
2284 OUTPUT It's a string to specify how to generate an output file. Some
2285 utilities accept an output file option, but some others need
2286 output redirection or some other way to specify an output file.
2287 Example:
2288 . for psnup
2289 \" \" ; psnup ... input output
2291 . for mpage
2292 \">\" ; mpage ... input > output
2294 SWITCHES List of sexp's to pass as extra options to the PostScript utility
2295 program.
2296 Example:
2297 . for psnup
2298 '(\"-q\")
2301 DEFAULT It's a way to set default values when this entry is selected.
2302 It's a cons like:
2304 (VARIABLE . VALUE)
2306 That associates VARIABLE with VALUE. when this entry is
2307 selected, it's executed the following command:
2309 (set VARIABLE (eval VALUE))
2311 Note that VALUE can be any valid lisp expression. So, don't
2312 forget to quote symbols and constant lists.
2313 If VARIABLE is the special keyword `inherits-from:', VALUE must
2314 be a symbol name setting defined in `pr-setting-database' from
2315 which the current setting inherits the context. Take care with
2316 circular inheritance.
2317 Examples:
2318 '(pr-file-landscape . nil)
2319 '(pr-file-duplex . t)
2320 '(pr-gs-device . (my-gs-device t))
2322 This variable should be modified by customization engine. If this variable is
2323 modified by other means (for example, a lisp function), use `pr-update-menus'
2324 function (see it for documentation) to update PostScript utility menu.
2326 NOTE: Don't forget to download and install the utilities declared on
2327 `pr-ps-utility-alist'.
2329 Examples:
2331 * On GNU or Unix system:
2333 '((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
2334 (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
2335 (pr-file-duplex . nil) (pr-file-tumble . nil))
2338 * On Windows system:
2340 '((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
2341 nil (pr-file-duplex . nil) (pr-file-tumble . nil))
2344 Useful links:
2346 * mpage download (GNU or Unix)
2347 `http://www.mesa.nl/pub/mpage/'
2349 * mpage documentation (GNU or Unix - or type `man mpage')
2350 `http://www.cs.umd.edu/faq/guides/manual_unix/node48.html'
2351 `http://www.rt.com/man/mpage.1.html'
2353 * psnup (Windows, GNU or Unix)
2354 `http://www.knackered.org/angus/psutils/'
2355 `http://gershwin.ens.fr/vdaniel/Doc-Locale/Outils-Gnu-Linux/PsUtils/'
2357 * psnup (PsUtils for Windows)
2358 `http://gnuwin32.sourceforge.net/packages/psutils.htm'
2360 * psnup documentation (GNU or Unix - or type `man psnup')
2361 `http://linux.about.com/library/cmd/blcmdl1_psnup.htm'
2362 `http://amath.colorado.edu/computing/software/man/psnup.html'
2364 * GNU Enscript (Windows, GNU or Unix)
2365 `http://people.ssh.com/mtr/genscript/'
2367 * GNU Enscript documentation (Windows, GNU or Unix)
2368 `http://people.ssh.com/mtr/genscript/enscript.man.html'
2369 (on GNU or Unix, type `man enscript')
2371 :type '(repeat
2372 (list :tag "PS File Utility"
2373 (symbol :tag "Utility Symbol")
2374 (string :tag "Utility Name")
2375 (repeat :tag "Must Utility Switches"
2376 (sexp :tag "Switch" :value ""))
2377 (choice :menu-tag "Paper Size"
2378 :tag "Paper Size"
2379 (const :tag "No Paper Size" nil)
2380 (string :tag "Paper Size Format"))
2381 (choice :menu-tag "N-Up"
2382 :tag "N-Up"
2383 (const :tag "No N-Up" nil)
2384 (string :tag "N-Up Format"))
2385 (choice :menu-tag "Landscape"
2386 :tag "Landscape"
2387 (const :tag "No Landscape" nil)
2388 (string :tag "Landscape Switch"))
2389 (choice :menu-tag "Duplex"
2390 :tag "Duplex"
2391 (const :tag "No Duplex" nil)
2392 (string :tag "Duplex Switch"))
2393 (choice :menu-tag "Tumble"
2394 :tag "Tumble"
2395 (const :tag "No Tumble" nil)
2396 (string :tag "Tumble Switch"))
2397 (string :tag "Output Separator")
2398 (repeat :tag "Utility Switches"
2399 (sexp :tag "Switch" :value ""))
2400 (repeat
2401 :tag "Default Value List"
2402 :inline t
2403 (cons
2404 :tag ""
2405 (choice
2406 :menu-tag "Variable"
2407 :tag "Variable"
2408 (const :tag "PS File Landscape" pr-file-landscape)
2409 (const :tag "PS File Duplex" pr-file-duplex)
2410 (const :tag "PS File Tumble" pr-file-tumble)
2411 (const :tag "Ghostscript Device" pr-gs-device)
2412 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2413 (const :tag "inherits-from:" inherits-from:)
2414 (variable :tag "Other"))
2415 (sexp :tag "Value")))
2417 :set 'pr-alist-custom-set
2418 :group 'printing)
2421 (defcustom pr-menu-lock t
2422 "*Non-nil means menu is locked while selecting toggle options.
2424 See also `pr-menu-char-height' and `pr-menu-char-width'."
2425 :type 'boolean
2426 :group 'printing)
2429 (defcustom pr-menu-char-height
2430 (cond ((featurep 'xemacs) ; XEmacs
2431 (pr-x-font-height (face-font 'default)))
2432 (t ; GNU Emacs
2433 (pr-e-frame-char-height)))
2434 "*Specify menu char height in pixels.
2436 This variable is used to guess which vertical position should be locked the
2437 menu, so don't forget to adjust it if menu position is not ok.
2439 See also `pr-menu-lock' and `pr-menu-char-width'."
2440 :type 'integer
2441 :group 'printing)
2444 (defcustom pr-menu-char-width
2445 (cond ((featurep 'xemacs) ; XEmacs
2446 (pr-x-font-width (face-font 'default)))
2447 (t ; GNU Emacs
2448 (pr-e-frame-char-width)))
2449 "*Specify menu char width in pixels.
2451 This variable is used to guess which horizontal position should be locked the
2452 menu, so don't forget to adjust it if menu position is not ok.
2454 See also `pr-menu-lock' and `pr-menu-char-height'."
2455 :type 'integer
2456 :group 'printing)
2459 (defcustom pr-setting-database
2460 '((no-duplex ; setting symbol name
2461 nil nil nil ; inherits local kill-local
2462 (pr-file-duplex . nil) ; settings
2463 (pr-file-tumble . nil))
2465 "*Specify an alist for settings in general.
2467 The elements have the following form:
2469 (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
2471 Where:
2473 SYMBOL It's a symbol to identify the setting group.
2475 INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
2476 setting from which the current setting inherits the context.
2477 If INHERITS is nil, means that there is no inheritance.
2478 This is a simple inheritance mechanism.
2480 Let's see an example to illustrate the inheritance mechanism:
2482 (setq pr-setting-database
2483 '((no-duplex ; setting symbol name
2484 nil ; inherits
2485 nil nil ; local kill-local
2486 (pr-file-duplex . nil) ; settings
2487 (pr-file-tumble . nil)
2489 (no-duplex-and-landscape ; setting symbol name
2490 no-duplex ; inherits
2491 nil nil ; local kill-local
2492 (pr-file-landscape . nil) ; settings
2495 The example above has two setting groups: no-duplex and
2496 no-duplex-and-landscape. When setting no-duplex is activated
2497 through `inherits-from:' (see `pr-ps-utility', `pr-mode-alist'
2498 and `pr-ps-printer-alist'), the variables pr-file-duplex and
2499 pr-file-tumble are both set to nil.
2501 Now when setting no-duplex-and-landscape is activated through
2502 `inherits-from:', the variable pr-file-landscape is set to nil
2503 and also the settings for no-duplex are done, because
2504 no-duplex-and-landscape inherits settings from no-duplex.
2506 Take care with circular inheritance. It's an error if circular
2507 inheritance happens.
2509 LOCAL Non-nil means that all settings for SYMBOL group will be
2510 declared local buffer.
2512 KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
2513 killed at end. It has effect only when LOCAL is non-nil.
2515 SETTING It's a cons like:
2517 (VARIABLE . VALUE)
2519 That associates VARIABLE with VALUE. when this entry is
2520 selected, it's executed the following command:
2522 * If LOCAL is non-nil:
2523 (set (make-local-variable VARIABLE) (eval VALUE))
2525 * If LOCAL is nil:
2526 (set VARIABLE (eval VALUE))
2528 Note that VALUE can be any valid lisp expression. So, don't
2529 forget to quote symbols and constant lists.
2530 This setting is ignored if VARIABLE is equal to keyword
2531 `inherits-from:'.
2532 Examples:
2533 '(ps-landscape-mode . nil)
2534 '(ps-spool-duplex . t)
2535 '(pr-gs-device . (my-gs-device t))"
2536 :type '(repeat
2537 (list
2538 :tag ""
2539 (symbol :tag "Setting Name")
2540 (choice :menu-tag "Inheritance"
2541 :tag "Inheritance"
2542 (const :tag "No Inheritance" nil)
2543 (symbol :tag "Inherits From"))
2544 (boolean :tag "Local Buffer Setting")
2545 (boolean :tag "Kill Local Variable At End")
2546 (repeat
2547 :tag "Setting List"
2548 :inline t
2549 (cons
2550 :tag ""
2551 (choice
2552 :menu-tag "Variable"
2553 :tag "Variable"
2554 (const :tag "Landscape" ps-landscape-mode)
2555 (const :tag "Print Header" ps-print-header)
2556 (const :tag "Print Header Frame" ps-print-header-frame)
2557 (const :tag "Line Number" ps-line-number)
2558 (const :tag "Zebra Stripes" ps-zebra-stripes)
2559 (const :tag "Duplex" ps-spool-duplex)
2560 (const :tag "Tumble" ps-spool-tumble)
2561 (const :tag "Upside-Down" ps-print-upside-down)
2562 (const :tag "PS File Landscape" pr-file-landscape)
2563 (const :tag "PS File Duplex" pr-file-duplex)
2564 (const :tag "PS File Tumble" pr-file-tumble)
2565 (const :tag "Auto Region" pr-auto-region)
2566 (const :tag "Auto Mode" pr-auto-mode)
2567 (const :tag "Ghostscript Device" pr-gs-device)
2568 (const :tag "Ghostscript Resolution" pr-gs-resolution)
2569 (variable :tag "Other"))
2570 (sexp :tag "Value")))
2572 :group 'printing)
2575 (defcustom pr-visible-entry-list
2576 '(postscript text postscript-options postscript-process printing help)
2577 "*Specify a list of Printing menu visible entries.
2579 Valid values with the corresponding menu parts are:
2581 +------------------------------+
2582 | Printing Interface |
2583 +------------------------------+
2584 `postscript' | PostScript Preview >|
2585 | PostScript Print >|
2586 | PostScript Printer: name >|
2587 +------------------------------+
2588 `text' | Printify >|
2589 | Print >|
2590 | Text Printer: name >|
2591 +------------------------------+
2592 `postscript-options' |[ ] Landscape |
2593 |[ ] Print Header |
2594 |[ ] Print Header Frame |
2595 |[ ] Line Number |
2596 |[ ] Zebra Stripes |
2597 |[ ] Duplex |
2598 |[ ] Tumble |
2599 |[ ] Upside-Down |
2600 | Print All Pages >|
2601 +------------------------------+
2602 `postscript-process' |[ ] Spool Buffer |
2603 |[ ] Print with faces |
2604 |[ ] Print via Ghostscript |
2605 +------------------------------+
2606 `printing' |[ ] Auto Region |
2607 |[ ] Auto Mode |
2608 |[ ] Menu Lock |
2609 +------------------------------+
2610 `help' | Customize >|
2611 | Show Settings >|
2612 | Help |
2613 +------------------------------+
2615 Any other value is ignored."
2616 :type '(repeat :tag "Menu Visible Part"
2617 (choice :menu-tag "Menu Part"
2618 :tag "Menu Part"
2619 (const postscript)
2620 (const text)
2621 (const postscript-options)
2622 (const postscript-process)
2623 (const printing)
2624 (const help)))
2625 :group 'printing)
2628 (defcustom pr-delete-temp-file t
2629 "*Non-nil means delete temporary files.
2631 Set `pr-delete-temp-file' to nil, if the following message (or a similar)
2632 happens when printing:
2634 Error: could not open \"c:\\temp\\prspool.ps\" for reading."
2635 :type 'boolean
2636 :group 'printing)
2639 (defcustom pr-list-directory nil
2640 "*Non-nil means list directory when processing a directory.
2642 That is, any subdirectories (and the superdirectory) of the directory (given as
2643 argument of functions below) are also printed (as dired-mode listings).
2645 It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
2646 `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
2647 and `pr-txt-directory'."
2648 :type 'boolean
2649 :group 'printing)
2652 (defcustom pr-buffer-name "*Printing Interface*"
2653 "*Specify the name of the buffer interface for printing package.
2655 It's used by `pr-interface'."
2656 :type 'string
2657 :group 'printing)
2660 (defcustom pr-buffer-name-ignore
2661 (list (regexp-quote pr-buffer-name) ; ignore printing interface buffer
2662 "^ .*$") ; ignore invisible buffers
2663 "*Specify a regexp list for buffer names to be ignored in interface buffer.
2665 NOTE: Case is important for matching, that is, `case-fold-search' is always
2666 nil.
2668 It's used by `pr-interface'."
2669 :type '(repeat (regexp :tag "Buffer Name Regexp"))
2670 :group 'printing)
2673 (defcustom pr-buffer-verbose t
2674 "*Non-nil means to be verbose when editing a field in interface buffer.
2676 It's used by `pr-interface'."
2677 :type 'boolean
2678 :group 'printing)
2681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2682 ;; Internal Variables
2685 (defvar pr-txt-command nil
2686 "Name of program for printing a text file.
2687 See `pr-txt-printer-alist'.")
2690 (defvar pr-txt-switches nil
2691 "List of sexp's to pass as extra options to the text printer program.
2692 See `pr-txt-printer-alist'.")
2695 (defvar pr-txt-printer nil
2696 "Specify text printer name.
2697 See `pr-txt-printer-alist'.")
2700 (defvar pr-ps-command nil
2701 "Name of program for printing a PostScript file.
2702 See `pr-ps-printer-alist'.")
2705 (defvar pr-ps-switches nil
2706 "List of sexp's to pass as extra options to the PostScript printer program.
2707 See `pr-ps-printer-alist'.")
2710 (defvar pr-ps-printer-switch nil
2711 "Specify PostScript printer name switch.
2712 See `pr-ps-printer-alist'.")
2715 (defvar pr-ps-printer nil
2716 "Specify PostScript printer name.
2717 See `pr-ps-printer-alist'.")
2720 (defvar pr-menu-bar nil
2721 "Specify Printing menu-bar entry.")
2724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2725 ;; Macros
2728 (defmacro pr-save-file-modes (&rest body)
2729 "Set temporally file modes to `pr-file-modes'."
2730 `(let ((pr--default-file-modes (default-file-modes))) ; save default
2731 (set-default-file-modes pr-file-modes)
2732 ,@body
2733 (set-default-file-modes pr--default-file-modes))) ; restore default
2736 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2737 ;; Keys & Menus
2740 (defmacro pr-xemacs-global-menubar (&rest body)
2741 `(save-excursion
2742 (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
2743 ;; be sure to access global menubar
2744 (set-buffer temp)
2745 ,@body
2746 (kill-buffer temp))))
2749 (defsubst pr-visible-p (key)
2750 (memq key pr-visible-entry-list))
2753 (defsubst pr-mode-alist-p ()
2754 (cdr (assq major-mode pr-mode-alist)))
2757 (defsubst pr-auto-mode-p ()
2758 (and pr-auto-mode (pr-mode-alist-p)))
2761 (defsubst pr-using-ghostscript-p ()
2762 (and pr-print-using-ghostscript (not pr-spool-p)))
2765 (defalias 'pr-get-symbol
2766 (if (fboundp 'easy-menu-intern) ; hacked from easymenu.el
2767 'easy-menu-intern
2768 (lambda (s) (if (stringp s) (intern s) s))))
2770 (cond
2771 ((featurep 'xemacs) ; XEmacs
2772 (defvar zmacs-region-stays nil) ; to avoid compilation gripes
2773 (defun pr-region-active-p ()
2774 (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p))))
2776 (t ; GNU Emacs
2777 (defun pr-region-active-p ()
2778 (and pr-auto-region transient-mark-mode mark-active))))
2781 (defconst pr-menu-spec
2782 ;; Menu mapping:
2783 ;; unfortunately XEmacs doesn't support :active for submenus,
2784 ;; only for items.
2785 ;; So, it uses :included instead of :active.
2786 ;; Also, XEmacs doesn't support :help tag.
2787 (let ((pr-:active (if (featurep 'xemacs)
2788 :included ; XEmacs
2789 :active)) ; GNU Emacs
2790 (pr-:help (if (featurep 'xemacs)
2791 'ignore ; XEmacs
2792 #'(lambda (text) (list :help text))))) ; GNU Emacs
2794 ["Printing Interface" pr-interface
2795 ,@(funcall
2796 pr-:help "Use buffer interface instead of menu interface")]
2797 "--"
2798 ("PostScript Preview" :included (pr-visible-p 'postscript)
2799 ,@(funcall
2800 pr-:help "Preview PostScript instead of sending to printer")
2801 ("Directory" ,pr-:active (not pr-spool-p)
2802 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
2803 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
2804 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
2805 ["Other..." (pr-ps-directory-preview nil nil nil t)
2806 :keys "\\[pr-ps-buffer-preview]"])
2807 ("Buffer" ,pr-:active (not pr-spool-p)
2808 ["1-up" (pr-ps-buffer-preview 1 t) t]
2809 ["2-up" (pr-ps-buffer-preview 2 t) t]
2810 ["4-up" (pr-ps-buffer-preview 4 t) t]
2811 ["Other..." (pr-ps-buffer-preview nil t)
2812 :keys "\\[pr-ps-buffer-preview]"])
2813 ("Region" ,pr-:active (and (not pr-spool-p) (ps-mark-active-p))
2814 ["1-up" (pr-ps-region-preview 1 t) t]
2815 ["2-up" (pr-ps-region-preview 2 t) t]
2816 ["4-up" (pr-ps-region-preview 4 t) t]
2817 ["Other..." (pr-ps-region-preview nil t)
2818 :keys "\\[pr-ps-region-preview]"])
2819 ("Mode" ,pr-:active (and (not pr-spool-p) (pr-mode-alist-p))
2820 ["1-up" (pr-ps-mode-preview 1 t) t]
2821 ["2-up" (pr-ps-mode-preview 2 t) t]
2822 ["4-up" (pr-ps-mode-preview 4 t) t]
2823 ["Other..." (pr-ps-mode-preview nil t)
2824 :keys "\\[pr-ps-mode-preview]"])
2825 ("File"
2826 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
2827 :keys "\\[pr-ps-file-preview]"
2828 ,@(funcall
2829 pr-:help "Preview PostScript file")]
2830 "--"
2831 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2832 ,@(funcall
2833 pr-:help "Select PostScript utility")]
2834 "--"
2835 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
2836 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
2837 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
2838 ["Other..." (pr-ps-file-up-preview nil t t)
2839 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
2840 "--"
2841 ["Landscape" pr-toggle-file-landscape-menu
2842 :style toggle :selected pr-file-landscape
2843 ,@(funcall
2844 pr-:help "Toggle landscape for PostScript file")
2845 :active pr-ps-utility-alist]
2846 ["Duplex" pr-toggle-file-duplex-menu
2847 :style toggle :selected pr-file-duplex
2848 ,@(funcall
2849 pr-:help "Toggle duplex for PostScript file")
2850 :active pr-ps-utility-alist]
2851 ["Tumble" pr-toggle-file-tumble-menu
2852 :style toggle :selected pr-file-tumble
2853 ,@(funcall
2854 pr-:help "Toggle tumble for PostScript file")
2855 :active (and pr-file-duplex pr-ps-utility-alist)])
2856 ["Despool..." (call-interactively 'pr-despool-preview)
2857 :active pr-spool-p :keys "\\[pr-despool-preview]"
2858 ,@(funcall
2859 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
2860 ("PostScript Print" :included (pr-visible-p 'postscript)
2861 ,@(funcall
2862 pr-:help "Send PostScript to printer or file (C-u)")
2863 ("Directory"
2864 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
2865 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
2866 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
2867 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
2868 :keys "\\[pr-ps-buffer-ps-print]"])
2869 ("Buffer"
2870 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
2871 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
2872 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
2873 ["Other..." (pr-ps-buffer-ps-print nil t)
2874 :keys "\\[pr-ps-buffer-ps-print]"])
2875 ("Region" ,pr-:active (ps-mark-active-p)
2876 ["1-up" (pr-ps-region-ps-print 1 t) t]
2877 ["2-up" (pr-ps-region-ps-print 2 t) t]
2878 ["4-up" (pr-ps-region-ps-print 4 t) t]
2879 ["Other..." (pr-ps-region-ps-print nil t)
2880 :keys "\\[pr-ps-region-ps-print]"])
2881 ("Mode" ,pr-:active (pr-mode-alist-p)
2882 ["1-up" (pr-ps-mode-ps-print 1 t) t]
2883 ["2-up" (pr-ps-mode-ps-print 2 t) t]
2884 ["4-up" (pr-ps-mode-ps-print 4 t) t]
2885 ["Other..." (pr-ps-mode-ps-print nil t)
2886 :keys "\\[pr-ps-mode-ps-print]"])
2887 ("File"
2888 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
2889 :keys "\\[pr-ps-file-ps-print]"
2890 ,@(funcall
2891 pr-:help "Send PostScript file to printer")]
2892 "--"
2893 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
2894 ,@(funcall
2895 pr-:help "Select PostScript utility")]
2896 "--"
2897 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
2898 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
2899 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
2900 ["Other..." (pr-ps-file-up-ps-print nil t t)
2901 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
2902 "--"
2903 ["Landscape" pr-toggle-file-landscape-menu
2904 :style toggle :selected pr-file-landscape
2905 ,@(funcall
2906 pr-:help "Toggle landscape for PostScript file")
2907 :active pr-ps-utility-alist]
2908 ["Duplex" pr-toggle-file-duplex-menu
2909 :style toggle :selected pr-file-duplex
2910 ,@(funcall
2911 pr-:help "Toggle duplex for PostScript file")
2912 :active pr-ps-utility-alist]
2913 ["Tumble" pr-toggle-file-tumble-menu
2914 :style toggle :selected pr-file-tumble
2915 ,@(funcall
2916 pr-:help "Toggle tumble for PostScript file")
2917 :active (and pr-file-duplex pr-ps-utility-alist)])
2918 ["Despool..." (call-interactively 'pr-despool-ps-print)
2919 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
2920 ,@(funcall
2921 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
2922 ["PostScript Printers" pr-update-menus
2923 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
2924 ,@(funcall
2925 pr-:help "Select PostScript printer")]
2926 "--"
2927 ("Printify" :included (pr-visible-p 'text)
2928 ,@(funcall
2929 pr-:help
2930 "Replace non-printing chars with printable representations.")
2931 ["Directory" pr-printify-directory t]
2932 ["Buffer" pr-printify-buffer t]
2933 ["Region" pr-printify-region (ps-mark-active-p)])
2934 ("Print" :included (pr-visible-p 'text)
2935 ,@(funcall
2936 pr-:help "Send text to printer")
2937 ["Directory" pr-txt-directory t]
2938 ["Buffer" pr-txt-buffer t]
2939 ["Region" pr-txt-region (ps-mark-active-p)]
2940 ["Mode" pr-txt-mode (pr-mode-alist-p)])
2941 ["Text Printers" pr-update-menus
2942 :active pr-txt-printer-alist :included (pr-visible-p 'text)
2943 ,@(funcall
2944 pr-:help "Select text printer")]
2945 "--"
2946 ["Landscape" pr-toggle-landscape-menu
2947 :style toggle :selected ps-landscape-mode
2948 :included (pr-visible-p 'postscript-options)]
2949 ["Print Header" pr-toggle-header-menu
2950 :style toggle :selected ps-print-header
2951 :included (pr-visible-p 'postscript-options)]
2952 ["Print Header Frame" pr-toggle-header-frame-menu
2953 :style toggle :selected ps-print-header-frame :active ps-print-header
2954 :included (pr-visible-p 'postscript-options)]
2955 ["Line Number" pr-toggle-line-menu
2956 :style toggle :selected ps-line-number
2957 :included (pr-visible-p 'postscript-options)]
2958 ["Zebra Stripes" pr-toggle-zebra-menu
2959 :style toggle :selected ps-zebra-stripes
2960 :included (pr-visible-p 'postscript-options)]
2961 ["Duplex" pr-toggle-duplex-menu
2962 :style toggle :selected ps-spool-duplex
2963 :included (pr-visible-p 'postscript-options)]
2964 ["Tumble" pr-toggle-tumble-menu
2965 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
2966 :included (pr-visible-p 'postscript-options)]
2967 ["Upside-Down" pr-toggle-upside-down-menu
2968 :style toggle :selected ps-print-upside-down
2969 :included (pr-visible-p 'postscript-options)]
2970 ("Print All Pages" :included (pr-visible-p 'postscript-options)
2971 ,@(funcall
2972 pr-:help "Select odd/even pages/sheets to print")
2973 ["All Pages" (pr-even-or-odd-pages nil)
2974 :style radio :selected (eq ps-even-or-odd-pages nil)]
2975 ["Even Pages" (pr-even-or-odd-pages 'even-page)
2976 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
2977 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
2978 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
2979 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
2980 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
2981 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
2982 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
2983 "--"
2984 ["Spool Buffer" pr-toggle-spool-menu
2985 :style toggle :selected pr-spool-p
2986 :included (pr-visible-p 'postscript-process)
2987 ,@(funcall
2988 pr-:help "Toggle PostScript spooling")]
2989 ["Print with faces" pr-toggle-faces-menu
2990 :style toggle :selected pr-faces-p
2991 :included (pr-visible-p 'postscript-process)
2992 ,@(funcall
2993 pr-:help "Toggle PostScript printing with faces")]
2994 ["Print via Ghostscript" pr-toggle-ghostscript-menu
2995 :style toggle :selected pr-print-using-ghostscript
2996 :included (pr-visible-p 'postscript-process)
2997 ,@(funcall
2998 pr-:help "Toggle PostScript generation using ghostscript")]
2999 "--"
3000 ["Auto Region" pr-toggle-region-menu
3001 :style toggle :selected pr-auto-region
3002 :included (pr-visible-p 'printing)]
3003 ["Auto Mode" pr-toggle-mode-menu
3004 :style toggle :selected pr-auto-mode
3005 :included (pr-visible-p 'printing)]
3006 ["Menu Lock" pr-toggle-lock-menu
3007 :style toggle :selected pr-menu-lock
3008 :included (pr-visible-p 'printing)]
3009 "--"
3010 ("Customize" :included (pr-visible-p 'help)
3011 ["printing" pr-customize t]
3012 ["ps-print" ps-print-customize t]
3013 ["lpr" lpr-customize t])
3014 ("Show Settings" :included (pr-visible-p 'help)
3015 ["printing" pr-show-pr-setup t]
3016 ["ps-print" pr-show-ps-setup t]
3017 ["lpr" pr-show-lpr-setup t])
3018 ["Help" pr-help :active t :included (pr-visible-p 'help)]
3022 (defvar pr-menu-print-item "print"
3023 "Non-nil means that menu binding was not done.
3025 Used by `pr-menu-bind' and `pr-update-menus'.")
3028 (defun pr-menu-bind ()
3029 "Install `printing' menu in the menubar.
3031 On Emacs 20, it replaces the Tools/Print menu by Tools/Printing menu.
3033 On Emacs 21 and 22, it replaces the File/Print* menu entries by File/Print
3034 menu.
3036 Calls `pr-update-menus' to adjust menus."
3037 (interactive)
3038 (cond
3039 ((featurep 'xemacs) ; XEmacs
3040 ;; Menu binding
3041 (pr-xemacs-global-menubar
3042 (pr-x-add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
3043 (setq pr-menu-print-item nil))
3046 (t ; GNU Emacs
3047 ;; Menu binding
3048 (require 'easymenu)
3049 ;; Replace existing "print" item by "Printing" item.
3050 ;; If you're changing this file, you'll load it a second,
3051 ;; third... time, but "print" item exists only in the first load.
3052 (cond
3053 ;; Emacs 20
3054 ((< emacs-major-version 21)
3055 (easy-menu-change '("tools") "Printing" pr-menu-spec pr-menu-print-item)
3056 (when pr-menu-print-item
3057 (easy-menu-remove-item nil '("tools") pr-menu-print-item)
3058 (setq pr-menu-print-item nil
3059 pr-menu-bar (vector 'menu-bar 'tools
3060 (pr-get-symbol "Printing")))))
3061 ;; Emacs 21 & 22
3063 (let ((menu-file (if (= emacs-major-version 21)
3064 '("menu-bar" "files") ; Emacs 21
3065 '("menu-bar" "file")))) ; Emacs 22 or higher
3066 (cond
3067 (pr-menu-print-item
3068 (easy-menu-add-item global-map menu-file
3069 (easy-menu-create-menu "Print" pr-menu-spec)
3070 "print-buffer")
3071 (dolist (item '("print-buffer" "print-region"
3072 "ps-print-buffer-faces" "ps-print-region-faces"
3073 "ps-print-buffer" "ps-print-region"))
3074 (easy-menu-remove-item global-map menu-file item))
3075 (setq pr-menu-print-item nil
3076 pr-menu-bar (vector 'menu-bar
3077 (pr-get-symbol (nth 1 menu-file))
3078 (pr-get-symbol "Print"))))
3080 (easy-menu-add-item global-map menu-file
3081 (easy-menu-create-menu "Print" pr-menu-spec)))
3082 ))))))
3083 (pr-update-menus t))
3086 ;; Key binding
3087 (let ((pr-print-key (if (featurep 'xemacs)
3088 'f22 ; XEmacs
3089 'print))) ; GNU Emacs
3090 (global-set-key `[,pr-print-key] 'pr-ps-fast-fire)
3091 ;; Well, M-print and S-print are used because in my keyboard S-print works
3092 ;; and M-print doesn't. But M-print can work in other keyboard.
3093 (global-set-key `[(meta ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3094 (global-set-key `[(shift ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3095 ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
3096 ;; and C-print doesn't. But C-print can work in other keyboard.
3097 (global-set-key `[(control ,pr-print-key)] 'pr-txt-fast-fire)
3098 (global-set-key `[(control meta ,pr-print-key)] 'pr-txt-fast-fire))
3101 ;;; You can also use something like:
3102 ;;;(global-set-key "\C-ci" 'pr-interface)
3103 ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
3104 ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
3105 ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
3106 ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
3107 ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
3108 ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
3111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3112 ;; Help Message
3115 (defconst pr-help-message
3116 (concat "printing.el version " pr-version
3117 " ps-print.el version " ps-print-version
3118 "\n\n
3119 Menu Layout
3120 -----------
3122 The `printing' menu (Tools/Printing or File/Print) has the following layout:
3124 +-----------------------------+
3125 A 0 | Printing Interface |
3126 +-----------------------------+ +-A---------+ +-B------+
3127 I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
3128 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
3129 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
3130 +-----------------------------+ |Mode >|-- B |Other...|
3131 II 4 | Printify >|-----\\ |File >|--\\ +--------+
3132 5 | Print >|---\\ | |Despool... | |
3133 6 | Text Printer: name >|-\\ | | +-----------+ |
3134 +-----------------------------+ | | | +---------+ +------------+
3135 III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
3136 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
3137 9 |[ ]Print Header Frame | | | |Region | | name >|- C
3138 10 |[ ]Line Number | | | +---------+ +------------+
3139 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
3140 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
3141 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
3142 14 |[ ]Upside-Down | | |Region | | Other... |
3143 15 | Print All Pages >|--\\ | |Mode | +------------+
3144 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
3145 IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
3146 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
3147 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
3148 +-----------------------------+ | |... |
3149 V 19 |[ ]Auto Region | | |(*)name |
3150 20 |[ ]Auto Mode | | |... |
3151 21 |[ ]Menu Lock | | +---------+ +--------------+
3152 +-----------------------------+ \\------------------|(*)All Pages |
3153 VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
3154 23 | Show Settings >|-------|printing| |( )Odd Pages |
3155 24 | Help | |ps-print| |( )Even Sheets|
3156 +-----------------------------+ |lpr | |( )Odd Sheets |
3157 +--------+ +--------------+
3159 See `pr-visible-entry-list' for hiding some parts of the menu.
3161 The menu has the following sections:
3163 A. Interface:
3165 0. You can use a buffer interface instead of menus. It looks like the
3166 customization buffer. Basically, it has the same options found in the
3167 menu and some extra options, all this on a buffer.
3169 I. PostScript printing:
3171 1. You can generate a PostScript file (if you type C-u before activating
3172 menu) or PostScript temporary file for a directory, a buffer, a region
3173 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
3174 after file generation, ghostview is activated using the file generated
3175 as argument. This option is disabled if spooling is on (option 16).
3176 Also, if you already have a PostScript file you can preview it.
3177 Instead of previewing each buffer, region or major mode at once, you
3178 can save temporarily the PostScript code generated in a buffer and
3179 preview it later. The option `Despool...' despools the PostScript
3180 spooling buffer in a temporary file and uses ghostview to preview it.
3181 If you type C-u before choosing this option, the PostScript code
3182 generated is saved in a file instead of saving in a temporary file. To
3183 spool the PostScript code generated you need to turn on the option 16.
3184 The option `Despool...' is enabled if spooling is on (option 16).
3186 NOTE 1: It's possible to customize a major mode printing, just declare
3187 the customization in `pr-mode-alist' and invoke some of
3188 `*-mode*' commands or select Mode option in Printing menu. An
3189 example for major mode usage is when you're using gnus (or mh,
3190 or rmail, etc.) and you're in the *Summary* buffer, if you
3191 forget to switch to the *Article* buffer before printing,
3192 you'll get a nicely formatted list of article subjects shows
3193 up at the printer. With major mode printing you don't need to
3194 switch from gnus *Summary* buffer first.
3196 NOTE 2: There are the following options for PostScript file processing:
3197 Ia. Print the file *No Preprocessing*, that is, send it
3198 directly to PostScript printer.
3199 Ib. PostScript utility processing selection.
3200 See `pr-ps-utility-alist' and `pr-setting-database' for
3201 documentation.
3202 Ic. Do n-up processing before printing.
3203 Id. Toggle on/off landscape for PostScript file processing.
3204 Ie. Toggle on/off duplex for PostScript file processing.
3205 If. Toggle on/off tumble for PostScript file processing.
3207 NOTE 3: Don't forget to download and install the utilities declared on
3208 `pr-ps-utility-alist'.
3210 2. Operate the same way as option 1, but it sends directly the PostScript
3211 code (or put in a file, if you've typed C-u) or it uses ghostscript to
3212 print the PostScript file generated. It depends on option 18, if it's
3213 turned on, it uses ghostscript; otherwise, it sends directly to
3214 printer. If spooling is on (option 16), the PostScript code is saved
3215 temporarily in a buffer instead of printing it or saving it in a file.
3216 Also, if you already have a PostScript file you can print it.
3217 Instead of printing each buffer, region or major mode at once, you can
3218 save temporarily the PostScript code generated in a buffer and print it
3219 later. The option `Despool...' despools the PostScript spooling buffer
3220 directly on a printer. If you type C-u before choosing this option,
3221 the PostScript code generated is saved in a file instead of sending it to
3222 the printer. To spool the PostScript code generated you need to turn on
3223 option 16. This option is enabled if spooling is on (option 16).
3224 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
3226 3. You can select a new PostScript printer to send PostScript code
3227 generated. For selection it's used all PostScript printers defined
3228 in `pr-ps-printer-alist' variable (see it for documentation).
3229 See also `pr-setting-database'.
3231 II. Text printing:
3233 4. If you have control characters (character code from \\000 to \\037) in a
3234 buffer and you want to print them in a text printer, select this
3235 option. All control characters in your buffer or region will be
3236 replaced by a printable representation. The printable representations
3237 use ^ (for ASCII control characters) or hex. The characters tab,
3238 linefeed, space, return and formfeed are not affected.
3239 You don't need to select this option if you use any option of section
3240 I, the PostScript engine treats control characters properly.
3242 5. If you want to print a directory, buffer, region or major mode in a
3243 text printer, select this option. See also the NOTE 1 on option 1.
3245 6. You can select a new text printer to send text generated. For
3246 selection it's used all text printers defined in `pr-txt-printer-alist'
3247 variable (see it for documentation).
3248 See also `pr-setting-database'.
3250 III. PostScript page toggle options:
3252 7. If you want a PostScript landscape printing, turn on this option.
3254 8. If you want to have a header in each page in your PostScript code,
3255 turn on this option.
3257 9. If you want to draw a gaudy frame around the header, turn on this
3258 option. This option is enabled if print header is on (option 8).
3260 10. If you want that the line number is printed in your PostScript code,
3261 turn on this option.
3263 11. If you want background zebra stripes in your PostScript code, turn on
3264 this option.
3266 12. If you want a duplex printing and your PostScript printer has this
3267 feature, turn on this option.
3269 13. If you turned on duplex printing, you can choose if you want to have a
3270 printing suitable for binding on the left or right (tumble off), or to
3271 have a printing suitable for binding at top or bottom (tumble on).
3272 This option is enabled if duplex is on (option 12).
3274 14. If you want a PostScript upside-down printing, turn on this option.
3276 15. With this option, you can choose if you want to print all pages, odd
3277 pages, even pages, odd sheets or even sheets.
3278 See also `ps-even-or-odd-pages'.
3280 IV. PostScript processing toggle options:
3282 16. If you want to spool the PostScript code generated, turn on this
3283 option. To spool the PostScript code generated use option 2. You can
3284 despool later by choosing option 1 or 2, sub-option `Despool...'.
3286 17. If you use colors in your buffers and want to see these colors on your
3287 PostScript code generated, turn on this option. If you have a
3288 black/white PostScript printer, these colors are displayed in gray
3289 scale by PostScript printer interpreter.
3291 18. If you don't have a PostScript printer to send PostScript files, turn
3292 on this option. When this option is on, the ghostscript is used to
3293 print PostScript files. In GNU or Unix system, if ghostscript is set
3294 as a PostScript filter, you don't need to turn on this option.
3296 V. Printing customization:
3298 19. If you want that region is automagically detected, turn on this
3299 option. Note that this will only work if you're using transient mark
3300 mode. When this option is on, the `*-buffer*' commands will behave
3301 like `*-region*' commands, that is, `*-buffer*' commands will print
3302 only the region marked instead of all buffer.
3304 20. Turn this option on if you want that when current major-mode is
3305 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3306 behave like `*-mode*' commands.
3308 21. If you want that Printing menu stays open while you are setting
3309 toggle options, turn on this option. The variables
3310 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3311 menu position, so don't forget to adjust these variables if menu
3312 position is not ok.
3314 VI. Customization:
3316 22. Besides all options in section III, IV and V, you can customize much
3317 more PostScript options in `ps-print' option. Or you can customize
3318 some `lpr' options for text printing. Or customize `printing'
3319 options.
3321 23. Show current settings for `printing', `ps-print' or `lpr'.
3323 24. Quick help for printing menu layout.
3325 "Printing help message.")
3328 (defconst pr-interface-help-message
3329 (concat "printing.el version " pr-version
3330 " ps-print.el version " ps-print-version
3331 "\n\n
3332 The printing interface buffer has the same functionality as the printing menu.
3333 The major difference is that the states (like sending PostScript generated to a
3334 file, n-up printing, etc.) are set and saved between priting buffer
3335 activation. Also, the landscape, duplex and tumble values are the same for
3336 PostScript file and directory/buffer/region/mode processing; using menu, there
3337 are different value sets for PostScript file and directory/buffer/region/mode
3338 processing.
3340 The printing interface buffer has the following sections:
3342 1. Print:
3344 Here you can choose to print/preview a buffer, a directory or a PostScript
3345 file:
3347 1a. Buffer:
3349 * Buffer List:
3350 Select a buffer from the current buffer list.
3352 * Region:
3353 If it's on, this means that the selected buffer has an active region,
3354 so you can turn on/off, as you wish.
3355 If it's off when a buffer is selected, this means that the selected
3356 buffer has no active region, so it'll not be possible to turn it on.
3357 If you want to process the region, let this option on.
3358 If you want to process the whole buffer, let this option off.
3360 * Mode:
3361 If it's on, this means that the selected buffer major mode is declared
3362 for major mode processing, so you can turn on/off, as you wish.
3363 If it's off when a buffer is selected, this means that the selected
3364 buffer major mode isn't declared for major mode processing, so it'll
3365 not be possible to turn it on.
3366 If you want the major mode processing, let this option on.
3367 If you don't want the major mode processing, let this option off.
3369 NOTE 1: It's possible to customize a major mode printing, just declare
3370 the customization in `pr-mode-alist' and invoke some of
3371 `*-mode*' commands or select Mode option in Printing menu. An
3372 example for major mode usage is when you're using gnus (or mh,
3373 or rmail, etc.) and you're in the *Summary* buffer, if you
3374 forget to switch to the *Article* buffer before printing,
3375 you'll get a nicely formatted list of article subjects shows
3376 up at the printer. With major mode printing you don't need to
3377 switch from gnus *Summary* buffer first.
3379 1b. Directory:
3381 * Directory:
3382 Specify a valid directory path.
3384 * File Regexp:
3385 Specify a file name regexp. All file names in the directory that
3386 match with regexp will be printed/previewed. An empty file name
3387 regexp means to print/preview all files in the directory.
3389 * List Directory Entry:
3390 If it's turned on, list directory entries besides file entries.
3392 1c. PostScript file:
3394 * PostScript File:
3395 Specify an existent PostScript file to print/preview.
3397 * PostScript Utility:
3398 Select a PostScript utility.
3399 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3401 NOTE 2: Don't forget to download and install the utilities declared on
3402 `pr-ps-utility-alist'.
3404 * No Preprocessing:
3405 If it's turned on, don't use the PostScript utility to preprocess the
3406 PostScript file before printing/previewing.
3408 2. PostScript printer:
3410 * PostScript Printer:
3411 You can select a new PostScript printer to send PostScript code
3412 generated. For selection it's used all PostScript printers defined
3413 in `pr-ps-printer-alist' variable (see it for documentation).
3414 See also `pr-setting-database'.
3416 * Despool:
3417 If spooling is on, you can turn it on/off, as you wish.
3418 If spooling is off, it'll not be possible to turn it on.
3419 If it's turned on, specify to despools the PostScript spooling buffer in
3420 a temporary file or in the selected PostScript file when
3421 printing/previewing.
3423 * Preview:
3424 Preview the PostScript generated.
3426 * Print:
3427 Print the PostScript generated.
3429 * Quit:
3430 Quit from printing interface buffer.
3432 * Send to Printer/Temporary File:
3433 If it's turned on, the PostScript generated is sent directly to
3434 PostScript printer or, for previewing, to a temporary file.
3436 * Send to File:
3437 Specify a file name to send the PostScript generated.
3439 * N-Up:
3440 Specify n-up printing.
3442 3. Text printer:
3444 * Text Printer:
3445 Select a new text printer to send text generated. For selection it's used
3446 all text printers defined in `pr-txt-printer-alist' variable (see it for
3447 documentation). See also `pr-setting-database'.
3449 * Printify:
3450 If you have control characters (character code from \\000 to \\037) in a
3451 buffer and you want to print them in a text printer, select this
3452 option. All control characters in your buffer or region will be
3453 replaced by a printable representation. The printable representations
3454 use ^ (for ASCII control characters) or hex. The characters tab,
3455 linefeed, space, return and formfeed are not affected.
3456 You don't need to select this option if you use any option of section
3457 I, the PostScript engine treats control characters properly.
3459 * Print:
3460 To print a directory, buffer, region or major mode in a
3461 text printer, select this option. See also the NOTE 1 on section 1.
3463 * Quit:
3464 Quit from printing interface buffer.
3466 4. Settings:
3468 There are 3 setting columns:
3470 4a. First column (left column):
3472 * Landscape:
3473 PostScript landscape printing.
3475 * Print Header:
3476 To have a header in each page in your PostScript code.
3478 * Print Header Frame:
3479 To draw a gaudy frame around the header.
3481 * Line Number:
3482 The line number is printed in your PostScript code.
3484 * Zebra Stripes:
3485 Background zebra stripes in your PostScript code.
3487 * Duplex:
3488 Duplex printing (if your PostScript printer has this feature).
3490 * Tumble:
3491 If duplex printing is on, you can choose if you want to have a
3492 printing suitable for binding on the left or right (tumble off), or to
3493 have a printing suitable for binding at top or bottom (tumble on).
3495 * Upside-Down:
3496 PostScript upside-down printing.
3498 4b. Second column (middle column):
3500 * Auto Region:
3501 If you want that region is automagically detected, turn on this
3502 option. Note that this will only work if you're using transient mark
3503 mode. When this option is on, the `*-buffer*' commands will behave
3504 like `*-region*' commands, that is, `*-buffer*' commands will print
3505 only the region marked instead of all buffer.
3507 * Auto Mode:
3508 Turn this option on if you want that when current major-mode is
3509 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3510 behave like `*-mode*' commands.
3512 * Menu Lock:
3513 If you want that Printing menu stays open while you are setting
3514 toggle options, turn on this option. The variables
3515 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3516 menu position, so don't forget to adjust these variables if menu
3517 position is not ok.
3519 * Spool Buffer:
3520 To spool the PostScript code generated. You can despool later by
3521 setting Despool option on PostScript printer section.
3523 * Print with faces:
3524 If you use colors in your buffers and want to see these colors on your
3525 PostScript code generated, turn on this option. If you have a
3526 black/white PostScript printer, these colors are displayed in gray
3527 scale by PostScript printer interpreter.
3529 * Print via Ghostscript:
3530 If you don't have a PostScript printer to send PostScript files, turn
3531 on this option. When this option is on, the ghostscript is used to
3532 print PostScript files. In GNU or Unix system, if ghostscript is set
3533 as a PostScript filter, you don't need to turn on this option.
3535 * Parity Page Menu:
3536 To print all pages, odd pages, even pages, odd sheets or even sheets.
3537 See also `ps-even-or-odd-pages'.
3539 4c. Third column (right column):
3541 * Verbose:
3542 That is, to be verbose when editing a field in interface buffer.
3544 5. Customize:
3546 Besides all options in section 4, you can customize much more PostScript
3547 options in `ps-print' option. Or you can customize some `lpr' options for
3548 text printing. Or customize `printing' options.
3550 6. Show settings:
3552 Show current settings for `printing', `ps-print' or `lpr'.
3554 7. Help:
3556 Quick help for printing interface buffer and printing menu layout. You can
3557 also quit the printing interface buffer or kill all printing help buffer.
3559 "Printing buffer interface help message.")
3562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3563 ;; Commands
3566 ;;;###autoload
3567 (defun pr-interface (&optional buffer)
3568 "Activate the printing interface buffer.
3570 If BUFFER is nil, the current buffer is used for printing.
3572 For more information, type \\[pr-interface-help]."
3573 (interactive)
3574 (save-excursion
3575 (set-buffer (or buffer (current-buffer)))
3576 (pr-create-interface)))
3579 ;;;###autoload
3580 (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3581 "Preview directory using ghostview.
3583 Interactively, the command prompts for N-UP printing number, a directory, a
3584 file name regexp for matching and, when you use a prefix argument (C-u), the
3585 command prompts the user for a file name, and saves the PostScript image in
3586 that file instead of saving it in a temporary file.
3588 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3589 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3590 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3591 save the image in a temporary file. If FILENAME is a string, save the
3592 PostScript image in a file with that name. If FILENAME is t, prompts for a
3593 file name.
3595 See also documentation for `pr-list-directory'."
3596 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
3597 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3598 (pr-prompt "PS preview dir"))
3599 (setq filename (pr-ps-file filename))
3600 (pr-ps-file-list n-up dir file-regexp filename)
3601 (or pr-spool-p
3602 (pr-ps-file-preview filename)))
3605 ;;;###autoload
3606 (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3607 "Print directory using PostScript through ghostscript.
3609 Interactively, the command prompts for N-UP printing number, a directory, a
3610 file name regexp for matching and, when you use a prefix argument (C-u), the
3611 command prompts the user for a file name, and saves the PostScript image in
3612 that file instead of saving it in a temporary file.
3614 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3615 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3616 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3617 save the image in a temporary file. If FILENAME is a string, save the
3618 PostScript image in a file with that name. If FILENAME is t, prompts for a
3619 file name.
3621 See also documentation for `pr-list-directory'."
3622 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
3623 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3624 (pr-prompt "PS print dir GS"))
3625 (let ((file (pr-ps-file filename)))
3626 (pr-ps-file-list n-up dir file-regexp file)
3627 (pr-ps-file-using-ghostscript file)
3628 (or filename (pr-delete-file file))))
3631 ;;;###autoload
3632 (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
3633 "Print directory using PostScript printer.
3635 Interactively, the command prompts for N-UP printing number, a directory, a
3636 file name regexp for matching and, when you use a prefix argument (C-u), the
3637 command prompts the user for a file name, and saves the PostScript image in
3638 that file instead of saving it in a temporary file.
3640 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3641 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3642 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3643 save the image in a temporary file. If FILENAME is a string, save the
3644 PostScript image in a file with that name. If FILENAME is t, prompts for a
3645 file name.
3647 See also documentation for `pr-list-directory'."
3648 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
3649 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3650 (pr-prompt "PS print dir"))
3651 (let ((file (pr-ps-file filename)))
3652 (pr-ps-file-list n-up dir file-regexp file)
3653 (pr-ps-file-print file)
3654 (or filename (pr-delete-file file))))
3657 ;;;###autoload
3658 (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
3659 "Print directory using PostScript printer or through ghostscript.
3661 It depends on `pr-print-using-ghostscript'.
3663 Interactively, the command prompts for N-UP printing number, a directory, a
3664 file name regexp for matching and, when you use a prefix argument (C-u), the
3665 command prompts the user for a file name, and saves the PostScript image in
3666 that file instead of saving it in a temporary file.
3668 Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3669 nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3670 FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3671 save the image in a temporary file. If FILENAME is a string, save the
3672 PostScript image in a file with that name. If FILENAME is t, prompts for a
3673 file name.
3675 See also documentation for `pr-list-directory'."
3676 (interactive (pr-interactive-ps-dir-args
3677 (pr-prompt (pr-prompt-gs "PS print dir"))))
3678 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3679 (pr-prompt (pr-prompt-gs "PS print dir")))
3680 (if (pr-using-ghostscript-p)
3681 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
3682 (pr-ps-directory-print n-up dir file-regexp filename)))
3685 ;;;###autoload
3686 (defun pr-ps-buffer-preview (n-up &optional filename)
3687 "Preview buffer using ghostview.
3689 Interactively, the command prompts for N-UP printing number and, when you use a
3690 prefix argument (C-u), the command prompts the user for a file name, and saves
3691 the PostScript image in that file instead of saving it in a temporary file.
3693 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3694 argument FILENAME is treated as follows: if it's nil, save the image in a
3695 temporary file. If FILENAME is a string, save the PostScript image in a file
3696 with that name. If FILENAME is t, prompts for a file name."
3697 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
3698 (if (pr-auto-mode-p)
3699 (pr-ps-mode-preview n-up filename)
3700 (pr-ps-preview (pr-region-active-symbol) n-up filename
3701 (pr-region-active-string "PS preview"))))
3704 ;;;###autoload
3705 (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
3706 "Print buffer using PostScript through ghostscript.
3708 Interactively, the command prompts for N-UP printing number and, when you use a
3709 prefix argument (C-u), the command prompts the user for a file name, and saves
3710 the PostScript image in that file instead of sending it to the printer.
3712 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3713 argument FILENAME is treated as follows: if it's nil, send the image to the
3714 printer. If FILENAME is a string, save the PostScript image in a file with
3715 that name. If FILENAME is t, prompts for a file name."
3716 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
3717 (if (pr-auto-mode-p)
3718 (pr-ps-mode-using-ghostscript n-up filename)
3719 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3720 (pr-region-active-string "PS print GS"))))
3723 ;;;###autoload
3724 (defun pr-ps-buffer-print (n-up &optional filename)
3725 "Print buffer using PostScript printer.
3727 Interactively, the command prompts for N-UP printing number and, when you use a
3728 prefix argument (C-u), the command prompts the user for a file name, and saves
3729 the PostScript image in that file instead of sending it to the printer.
3731 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3732 argument FILENAME is treated as follows: if it's nil, send the image to the
3733 printer. If FILENAME is a string, save the PostScript image in a file with
3734 that name. If FILENAME is t, prompts for a file name."
3735 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
3736 (if (pr-auto-mode-p)
3737 (pr-ps-mode-print n-up filename)
3738 (pr-ps-print (pr-region-active-symbol) n-up filename
3739 (pr-region-active-string "PS print"))))
3742 ;;;###autoload
3743 (defun pr-ps-buffer-ps-print (n-up &optional filename)
3744 "Print buffer using PostScript printer or through ghostscript.
3746 It depends on `pr-print-using-ghostscript'.
3748 Interactively, the command prompts for N-UP printing number and, when you use a
3749 prefix argument (C-u), the command prompts the user for a file name, and saves
3750 the PostScript image in that file instead of sending it to the printer.
3752 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
3753 argument FILENAME is treated as follows: if it's nil, send the image to the
3754 printer. If FILENAME is a string, save the PostScript image in a file with
3755 that name. If FILENAME is t, prompts for a file name."
3756 (interactive (pr-interactive-n-up-file
3757 (pr-prompt (pr-prompt-gs "PS print"))))
3758 (cond ((pr-auto-mode-p)
3759 (pr-ps-mode-ps-print n-up filename))
3760 ((pr-using-ghostscript-p)
3761 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
3762 (pr-region-active-string "PS print GS")))
3764 (pr-ps-print (pr-region-active-symbol) n-up filename
3765 (pr-region-active-string "PS print")))))
3768 ;;;###autoload
3769 (defun pr-ps-region-preview (n-up &optional filename)
3770 "Preview region using ghostview.
3772 See also `pr-ps-buffer-preview'."
3773 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
3774 (if (pr-auto-mode-p)
3775 (let ((pr-auto-region t))
3776 (pr-ps-mode-preview n-up filename))
3777 (pr-ps-preview 'region n-up filename "PS preview region")))
3780 ;;;###autoload
3781 (defun pr-ps-region-using-ghostscript (n-up &optional filename)
3782 "Print region using PostScript through ghostscript.
3784 See also `pr-ps-buffer-using-ghostscript'."
3785 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
3786 (if (pr-auto-mode-p)
3787 (let ((pr-auto-region t))
3788 (pr-ps-mode-using-ghostscript n-up filename))
3789 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
3792 ;;;###autoload
3793 (defun pr-ps-region-print (n-up &optional filename)
3794 "Print region using PostScript printer.
3796 See also `pr-ps-buffer-print'."
3797 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
3798 (if (pr-auto-mode-p)
3799 (let ((pr-auto-region t))
3800 (pr-ps-mode-print n-up filename))
3801 (pr-ps-print 'region n-up filename "PS print region")))
3804 ;;;###autoload
3805 (defun pr-ps-region-ps-print (n-up &optional filename)
3806 "Print region using PostScript printer or through ghostscript.
3808 See also `pr-ps-buffer-ps-print'."
3809 (interactive (pr-interactive-n-up-file
3810 (pr-prompt-region (pr-prompt-gs "PS print"))))
3811 (cond ((pr-auto-mode-p)
3812 (let ((pr-auto-region t))
3813 (pr-ps-mode-ps-print n-up filename)))
3814 ((pr-using-ghostscript-p)
3815 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
3817 (pr-ps-print 'region n-up filename "PS print region"))))
3820 ;;;###autoload
3821 (defun pr-ps-mode-preview (n-up &optional filename)
3822 "Preview major mode using ghostview.
3824 See also `pr-ps-buffer-preview'."
3825 (interactive (pr-interactive-n-up-file "PS preview mode"))
3826 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
3827 (let ((file (pr-ps-file filename)))
3828 (and (pr-ps-mode n-up file)
3829 (not pr-spool-p)
3830 (pr-ps-file-preview file))))
3833 ;;;###autoload
3834 (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
3835 "Print major mode using PostScript through ghostscript.
3837 See also `pr-ps-buffer-using-ghostscript'."
3838 (interactive (pr-interactive-n-up-file "PS print GS mode"))
3839 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
3840 (let ((file (pr-ps-file filename)))
3841 (when (and (pr-ps-mode n-up file)
3842 (not pr-spool-p))
3843 (pr-ps-file-using-ghostscript file)
3844 (or filename (pr-delete-file file)))))
3847 ;;;###autoload
3848 (defun pr-ps-mode-print (n-up &optional filename)
3849 "Print major mode using PostScript printer.
3851 See also `pr-ps-buffer-print'."
3852 (interactive (pr-interactive-n-up-file "PS print mode"))
3853 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
3854 (pr-ps-mode n-up filename))
3857 ;;;###autoload
3858 (defun pr-ps-mode-ps-print (n-up &optional filename)
3859 "Print major mode using PostScript or through ghostscript.
3861 See also `pr-ps-buffer-ps-print'."
3862 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
3863 (if (pr-using-ghostscript-p)
3864 (pr-ps-mode-using-ghostscript n-up filename)
3865 (pr-ps-mode-print n-up filename)))
3868 ;;;###autoload
3869 (defun pr-printify-directory (&optional dir file-regexp)
3870 "Replace nonprinting characters in directory with printable representations.
3871 The printable representations use ^ (for ASCII control characters) or hex.
3872 The characters tab, linefeed, space, return and formfeed are not affected.
3874 Interactively, the command prompts for a directory and a file name regexp for
3875 matching.
3877 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3878 prompts for FILE(name)-REGEXP.
3880 See also documentation for `pr-list-directory'."
3881 (interactive (pr-interactive-dir-args "Printify dir"))
3882 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
3883 (pr-file-list dir file-regexp 'pr-printify-buffer))
3886 ;;;###autoload
3887 (defun pr-printify-buffer ()
3888 "Replace nonprinting characters in buffer with printable representations.
3889 The printable representations use ^ (for ASCII control characters) or hex.
3890 The characters tab, linefeed, space, return and formfeed are not affected."
3891 (interactive "*")
3892 (if (pr-region-active-p)
3893 (pr-printify-region)
3894 (printify-region (point-min) (point-max))))
3897 ;;;###autoload
3898 (defun pr-printify-region ()
3899 "Replace nonprinting characters in region with printable representations.
3900 The printable representations use ^ (for ASCII control characters) or hex.
3901 The characters tab, linefeed, space, return and formfeed are not affected."
3902 (interactive "*")
3903 (printify-region (point) (mark)))
3906 ;;;###autoload
3907 (defun pr-txt-directory (&optional dir file-regexp)
3908 "Print directory using text printer.
3910 Interactively, the command prompts for a directory and a file name regexp for
3911 matching.
3913 Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
3914 prompts for FILE(name)-REGEXP.
3916 See also documentation for `pr-list-directory'."
3917 (interactive (pr-interactive-dir-args "Print dir"))
3918 (pr-set-dir-args 'dir 'file-regexp "Print dir")
3919 (pr-file-list dir file-regexp 'pr-txt-buffer))
3922 ;;;###autoload
3923 (defun pr-txt-buffer ()
3924 "Print buffer using text printer."
3925 (interactive)
3926 (cond ((pr-auto-mode-p)
3927 (pr-txt-mode))
3928 ((pr-region-active-p)
3929 (pr-txt-region))
3931 (pr-txt-print (point-min) (point-max)))))
3934 ;;;###autoload
3935 (defun pr-txt-region ()
3936 "Print region using text printer."
3937 (interactive)
3938 (if (pr-auto-mode-p)
3939 (let ((pr-auto-region t))
3940 (pr-txt-mode))
3941 (pr-txt-print (point) (mark))))
3944 ;;;###autoload
3945 (defun pr-txt-mode ()
3946 "Print major mode using text printer."
3947 (interactive)
3948 (let ((args (pr-mode-alist-p)))
3949 (if args
3950 (funcall (car args) (nthcdr 2 args))
3951 (ding)
3952 (message "`%s' major mode not declared." major-mode))))
3955 ;;;###autoload
3956 (defun pr-despool-preview (&optional filename)
3957 "Preview spooled PostScript.
3959 Interactively, when you use a prefix argument (C-u), the command prompts the
3960 user for a file name, and saves the spooled PostScript image in that file
3961 instead of saving it in a temporary file.
3963 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3964 save the image in a temporary file. If FILENAME is a string, save the
3965 PostScript image in a file with that name."
3966 (interactive (list (ps-print-preprint current-prefix-arg)))
3967 (let ((file (pr-ps-file filename)))
3968 (when (stringp file)
3969 (pr-despool-print file)
3970 (pr-ps-file-preview file))))
3973 ;;;###autoload
3974 (defun pr-despool-using-ghostscript (&optional filename)
3975 "Print spooled PostScript using ghostscript.
3977 Interactively, when you use a prefix argument (C-u), the command prompts the
3978 user for a file name, and saves the spooled PostScript image in that file
3979 instead of sending it to the printer.
3981 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
3982 send the image to the printer. If FILENAME is a string, save the PostScript
3983 image in a file with that name."
3984 (interactive (list (ps-print-preprint current-prefix-arg)))
3985 (let ((file (pr-ps-file filename)))
3986 (when (stringp file)
3987 (pr-despool-print file)
3988 (pr-ps-file-using-ghostscript file)
3989 (or filename (pr-delete-file file)))))
3992 ;;;###autoload
3993 (defun pr-despool-print (&optional filename)
3994 "Send the spooled PostScript to the printer.
3996 Interactively, when you use a prefix argument (C-u), the command prompts the
3997 user for a file name, and saves the spooled PostScript image in that file
3998 instead of sending it to the printer.
4000 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4001 send the image to the printer. If FILENAME is a string, save the PostScript
4002 image in a file with that name."
4003 (interactive (list (ps-print-preprint current-prefix-arg)))
4004 (pr-save-file-modes
4005 (let ((ps-lpr-command (pr-command pr-ps-command))
4006 (ps-lpr-switches pr-ps-switches)
4007 (ps-printer-name-option pr-ps-printer-switch)
4008 (ps-printer-name pr-ps-printer))
4009 (ps-despool filename))))
4012 ;;;###autoload
4013 (defun pr-despool-ps-print (&optional filename)
4014 "Send the spooled PostScript to the printer or use ghostscript to print it.
4016 Interactively, when you use a prefix argument (C-u), the command prompts the
4017 user for a file name, and saves the spooled PostScript image in that file
4018 instead of sending it to the printer.
4020 Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4021 send the image to the printer. If FILENAME is a string, save the PostScript
4022 image in a file with that name."
4023 (interactive (list (ps-print-preprint current-prefix-arg)))
4024 (if pr-print-using-ghostscript
4025 (pr-despool-using-ghostscript filename)
4026 (pr-despool-print filename)))
4029 ;;;###autoload
4030 (defun pr-ps-file-preview (filename)
4031 "Preview PostScript file FILENAME."
4032 (interactive (list (pr-ps-infile-preprint "Preview ")))
4033 (and (stringp filename) (file-exists-p filename)
4034 (pr-call-process pr-gv-command filename)))
4037 ;;;###autoload
4038 (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
4039 "Preview PostScript file FILENAME."
4040 (interactive (pr-interactive-n-up-inout "PS preview"))
4041 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4042 "PS preview ")))
4043 (pr-ps-utility-process n-up ifilename outfile)
4044 (pr-ps-file-preview outfile)))
4047 ;;;###autoload
4048 (defun pr-ps-file-using-ghostscript (filename)
4049 "Print PostScript file FILENAME using ghostscript."
4050 (interactive (list (pr-ps-infile-preprint "Print preview ")))
4051 (and (stringp filename) (file-exists-p filename)
4052 (let* ((file (pr-expand-file-name filename))
4053 (tempfile (pr-dosify-file-name (make-temp-file file))))
4054 ;; gs use
4055 (pr-call-process pr-gs-command
4056 (format "-sDEVICE=%s" pr-gs-device)
4057 (format "-r%d" pr-gs-resolution)
4058 (pr-switches-string pr-gs-switches "pr-gs-switches")
4059 (format "-sOutputFile=\"%s\"" tempfile)
4060 file
4061 "-c quit")
4062 ;; printing
4063 (pr-ps-file-print tempfile)
4064 ;; deleting
4065 (pr-delete-file tempfile))))
4068 ;;;###autoload
4069 (defun pr-ps-file-print (filename)
4070 "Print PostScript file FILENAME."
4071 (interactive (list (pr-ps-infile-preprint "Print ")))
4072 (and (stringp filename) (file-exists-p filename)
4073 ;; printing
4074 (let ((file (pr-expand-file-name filename)))
4075 (if (string= pr-ps-command "")
4076 ;; default action
4077 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
4078 (save-excursion
4079 (set-buffer ps-spool-buffer)
4080 (erase-buffer)
4081 (insert-file-contents-literally file))
4082 (pr-despool-print))
4083 ;; use `pr-ps-command' to print
4084 (apply 'pr-call-process
4085 pr-ps-command
4086 (pr-switches-string pr-ps-switches "pr-ps-switches")
4087 (if (string-match "cp" pr-ps-command)
4088 ;; for "cp" (cmd in out)
4089 (list file
4090 (concat pr-ps-printer-switch pr-ps-printer))
4091 ;; else, for others (cmd out in)
4092 (list (concat pr-ps-printer-switch pr-ps-printer)
4093 file)))))))
4096 ;;;###autoload
4097 (defun pr-ps-file-ps-print (filename)
4098 "Send PostScript file FILENAME to printer or use ghostscript to print it."
4099 (interactive (list (pr-ps-infile-preprint
4100 (if pr-print-using-ghostscript
4101 "Print preview "
4102 "Print "))))
4103 (if pr-print-using-ghostscript
4104 (pr-ps-file-using-ghostscript filename)
4105 (pr-ps-file-print filename)))
4108 ;;;###autoload
4109 (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
4110 "Process a PostScript file IFILENAME and send it to printer.
4112 Interactively, the command prompts for N-UP printing number, for an input
4113 PostScript file IFILENAME and, when you use a prefix argument (C-u), the
4114 command prompts the user for an output PostScript file name OFILENAME, and
4115 saves the PostScript image in that file instead of sending it to the printer.
4117 Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4118 argument IFILENAME is treated as follows: if it's t, prompts for an input
4119 PostScript file name; otherwise, it *must* be a string that it's an input
4120 PostScript file name. The argument OFILENAME is treated as follows: if it's
4121 nil, send the image to the printer. If OFILENAME is a string, save the
4122 PostScript image in a file with that name. If OFILENAME is t, prompts for a
4123 file name."
4124 (interactive (pr-interactive-n-up-inout
4125 (if pr-print-using-ghostscript
4126 "PS print GS"
4127 "PS print")))
4128 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4129 (if pr-print-using-ghostscript
4130 "PS print GS "
4131 "PS print "))))
4132 (pr-ps-utility-process n-up ifilename outfile)
4133 (unless ofilename
4134 (pr-ps-file-ps-print outfile)
4135 (pr-delete-file outfile))))
4138 ;;;###autoload
4139 (defun pr-toggle-file-duplex ()
4140 "Toggle duplex for PostScript file."
4141 (interactive)
4142 (pr-toggle-file-duplex-menu t))
4145 ;;;###autoload
4146 (defun pr-toggle-file-tumble ()
4147 "Toggle tumble for PostScript file.
4149 If tumble is off, produces a printing suitable for binding on the left or
4150 right.
4151 If tumble is on, produces a printing suitable for binding at the top or
4152 bottom."
4153 (interactive)
4154 (pr-toggle-file-tumble-menu t))
4157 ;;;###autoload
4158 (defun pr-toggle-file-landscape ()
4159 "Toggle landscape for PostScript file."
4160 (interactive)
4161 (pr-toggle-file-landscape-menu t))
4164 ;;;###autoload
4165 (defun pr-toggle-ghostscript ()
4166 "Toggle printing using ghostscript."
4167 (interactive)
4168 (pr-toggle-ghostscript-menu t))
4171 ;;;###autoload
4172 (defun pr-toggle-faces ()
4173 "Toggle printing with faces."
4174 (interactive)
4175 (pr-toggle-faces-menu t))
4178 ;;;###autoload
4179 (defun pr-toggle-spool ()
4180 "Toggle spooling."
4181 (interactive)
4182 (pr-toggle-spool-menu t))
4185 ;;;###autoload
4186 (defun pr-toggle-duplex ()
4187 "Toggle duplex."
4188 (interactive)
4189 (pr-toggle-duplex-menu t))
4192 ;;;###autoload
4193 (defun pr-toggle-tumble ()
4194 "Toggle tumble.
4196 If tumble is off, produces a printing suitable for binding on the left or
4197 right.
4198 If tumble is on, produces a printing suitable for binding at the top or
4199 bottom."
4200 (interactive)
4201 (pr-toggle-tumble-menu t))
4204 ;;;###autoload
4205 (defun pr-toggle-landscape ()
4206 "Toggle landscape."
4207 (interactive)
4208 (pr-toggle-landscape-menu t))
4211 ;;;###autoload
4212 (defun pr-toggle-upside-down ()
4213 "Toggle upside-down."
4214 (interactive)
4215 (pr-toggle-upside-down-menu t))
4218 ;;;###autoload
4219 (defun pr-toggle-line ()
4220 "Toggle line number."
4221 (interactive)
4222 (pr-toggle-line-menu t))
4225 ;;;###autoload
4226 (defun pr-toggle-zebra ()
4227 "Toggle zebra stripes."
4228 (interactive)
4229 (pr-toggle-zebra-menu t))
4232 ;;;###autoload
4233 (defun pr-toggle-header ()
4234 "Toggle printing header."
4235 (interactive)
4236 (pr-toggle-header-menu t))
4239 ;;;###autoload
4240 (defun pr-toggle-header-frame ()
4241 "Toggle printing header frame."
4242 (interactive)
4243 (pr-toggle-header-frame-menu t))
4246 ;;;###autoload
4247 (defun pr-toggle-lock ()
4248 "Toggle menu lock."
4249 (interactive)
4250 (pr-toggle-lock-menu t))
4253 ;;;###autoload
4254 (defun pr-toggle-region ()
4255 "Toggle auto region."
4256 (interactive)
4257 (pr-toggle-region-menu t))
4260 ;;;###autoload
4261 (defun pr-toggle-mode ()
4262 "Toggle auto mode."
4263 (interactive)
4264 (pr-toggle-mode-menu t))
4267 ;;;###autoload
4268 (defun pr-customize (&rest ignore)
4269 "Customization of the `printing' group."
4270 (interactive)
4271 (customize-group 'printing))
4274 ;;;###autoload
4275 (defun lpr-customize (&rest ignore)
4276 "Customization of the `lpr' group."
4277 (interactive)
4278 (customize-group 'lpr))
4281 ;;;###autoload
4282 (defun pr-help (&rest ignore)
4283 "Help for the printing package."
4284 (interactive)
4285 (pr-show-setup pr-help-message "*Printing Help*"))
4288 ;;;###autoload
4289 (defun pr-ps-name ()
4290 "Interactively select a PostScript printer."
4291 (interactive)
4292 (pr-menu-set-ps-title
4293 (pr-complete-alist "PostScript printer"
4294 pr-ps-printer-alist pr-ps-name)))
4297 ;;;###autoload
4298 (defun pr-txt-name ()
4299 "Interactively select a text printer."
4300 (interactive)
4301 (pr-menu-set-txt-title
4302 (pr-complete-alist "Text printer"
4303 pr-txt-printer-alist pr-txt-name)))
4306 ;;;###autoload
4307 (defun pr-ps-utility ()
4308 "Interactively select a PostScript utility."
4309 (interactive)
4310 (pr-menu-set-utility-title
4311 (pr-complete-alist "Postscript utility"
4312 pr-ps-utility-alist pr-ps-utility)))
4315 ;;;###autoload
4316 (defun pr-show-ps-setup (&rest ignore)
4317 "Show current ps-print settings."
4318 (interactive)
4319 (pr-show-setup (ps-setup) "*PS Setup*"))
4322 ;;;###autoload
4323 (defun pr-show-pr-setup (&rest ignore)
4324 "Show current printing settings."
4325 (interactive)
4326 (pr-show-setup (pr-setup) "*PR Setup*"))
4329 ;;;###autoload
4330 (defun pr-show-lpr-setup (&rest ignore)
4331 "Show current lpr settings."
4332 (interactive)
4333 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4337 ;; Fast Commands
4340 ;;;###autoload
4341 (defun pr-ps-fast-fire (n-up &optional select)
4342 "Fast fire function for PostScript printing.
4344 If a region is active, the region will be printed instead of the whole buffer.
4345 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4346 `pr-mode-alist' will be used, that is, the current buffer or region will be
4347 printed using `pr-ps-mode-ps-print'.
4350 Interactively, you have the following situations:
4352 M-x pr-ps-fast-fire RET
4353 The command prompts the user for a N-UP value and printing will
4354 immediatelly be done using the current active printer.
4356 C-u M-x pr-ps-fast-fire RET
4357 C-u 0 M-x pr-ps-fast-fire RET
4358 The command prompts the user for a N-UP value and also for a current
4359 PostScript printer, then printing will immediatelly be done using the new
4360 current active printer.
4362 C-u 1 M-x pr-ps-fast-fire RET
4363 The command prompts the user for a N-UP value and also for a file name,
4364 and saves the PostScript image in that file instead of sending it to the
4365 printer.
4367 C-u 2 M-x pr-ps-fast-fire RET
4368 The command prompts the user for a N-UP value, then for a current
4369 PostScript printer and, finally, for a file name. Then change the active
4370 printer to that chosen by user and saves the PostScript image in
4371 that file instead of sending it to the printer.
4374 Noninteractively, the argument N-UP should be a positive integer greater than
4375 zero and the argument SELECT is treated as follows:
4377 If it's nil, send the image to the printer.
4379 If it's a list or an integer lesser or equal to zero, the command prompts
4380 the user for a current PostScript printer, then printing will immediatelly
4381 be done using the new current active printer.
4383 If it's an integer equal to 1, the command prompts the user for a file name
4384 and saves the PostScript image in that file instead of sending it to the
4385 printer.
4387 If it's an integer greater or equal to 2, the command prompts the user for a
4388 current PostScript printer and for a file name. Then change the active
4389 printer to that chosen by user and saves the PostScript image in that file
4390 instead of sending it to the printer.
4392 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
4393 active printer and printing will immediatelly be done using the new active
4394 printer.
4396 Otherwise, send the image to the printer.
4399 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4400 are both set to t."
4401 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4402 current-prefix-arg))
4403 (let ((pr-auto-region t)
4404 (pr-auto-mode t)
4405 filename)
4406 (cond ((null select))
4407 ((listp select)
4408 (pr-ps-name))
4409 ((and (symbolp select)
4410 (assq select pr-ps-printer-alist))
4411 (pr-menu-set-ps-title select))
4412 ((integerp select)
4413 (and (/= select 1)
4414 (pr-ps-name))
4415 (and (>= select 1) (not pr-spool-p)
4416 (setq filename (pr-ps-outfile-preprint
4417 (if pr-print-using-ghostscript
4418 "Fast GS "
4419 "Fast "))))))
4420 (pr-ps-buffer-ps-print
4421 (if (integerp n-up)
4422 (min (max n-up 1) 100)
4423 (error "n-up must be an integer greater than zero"))
4424 filename)))
4427 ;;;###autoload
4428 (defun pr-txt-fast-fire (&optional select-printer)
4429 "Fast fire function for text printing.
4431 If a region is active, the region will be printed instead of the whole buffer.
4432 Also if the current major-mode is defined in `pr-mode-alist', the settings in
4433 `pr-mode-alist' will be used, that is, the current buffer or region will be
4434 printed using `pr-txt-mode'.
4436 Interactively, when you use a prefix argument (C-u), the command prompts the
4437 user for a new active text printer.
4439 Noninteractively, the argument SELECT-PRINTER is treated as follows:
4441 If it's nil, the printing is sent to the current active text printer.
4443 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
4444 active printer and printing will immediatelly be done using the new active
4445 printer.
4447 If it's non-nil, the command prompts the user for a new active text printer.
4449 Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4450 are both set to t."
4451 (interactive (list current-prefix-arg))
4452 (cond ((null select-printer))
4453 ((and (symbolp select-printer)
4454 (assq select-printer pr-txt-printer-alist))
4455 (pr-menu-set-txt-title select-printer))
4457 (pr-txt-name)))
4458 (let ((pr-auto-region t)
4459 (pr-auto-mode t))
4460 (pr-txt-buffer)))
4463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4464 ;; Utilities
4467 (defun pr-setup ()
4468 "Return the current `printing' setup.
4470 This is *not* an interactive command.
4471 One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4473 M-: (insert (pr-setup)) RET
4475 Or choose the menu option Printing/Show Settings/printing."
4476 (let (ps-prefix-quote)
4477 (mapconcat
4478 #'ps-print-quote
4479 (list
4480 (concat "\n;;; printing.el version " pr-version "\n")
4481 ";; internal vars"
4482 (ps-comment-string "emacs-version " emacs-version)
4483 (ps-comment-string "pr-txt-command " pr-txt-command)
4484 (ps-comment-string "pr-txt-switches "
4485 (pr-switches-string pr-txt-switches "pr-txt-switches"))
4486 (ps-comment-string "pr-txt-printer " pr-txt-printer)
4487 (ps-comment-string "pr-ps-command " pr-ps-command)
4488 (ps-comment-string "pr-ps-switches "
4489 (pr-switches-string pr-ps-switches "pr-ps-switches"))
4490 (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
4491 (ps-comment-string "pr-ps-printer " pr-ps-printer)
4492 (ps-comment-string "pr-cygwin-system " pr-cygwin-system)
4493 (ps-comment-string "ps-windows-system " ps-windows-system)
4494 (ps-comment-string "ps-lp-system " ps-lp-system)
4496 '(14 . pr-path-style)
4497 '(14 . pr-path-alist)
4499 '(21 . pr-txt-name)
4500 '(21 . pr-txt-printer-alist)
4502 '(20 . pr-ps-name)
4503 '(20 . pr-ps-printer-alist)
4505 '(20 . pr-temp-dir)
4506 '(20 . pr-ps-temp-file)
4507 '(20 . pr-file-modes)
4508 '(20 . pr-delete-temp-file)
4509 '(20 . pr-list-directory)
4511 '(17 . pr-gv-command)
4512 '(17 . pr-gs-command)
4513 '(17 . pr-gs-switches)
4514 '(17 . pr-gs-device)
4515 '(17 . pr-gs-resolution)
4517 '(27 . pr-print-using-ghostscript)
4518 '(27 . pr-faces-p)
4519 '(27 . pr-spool-p)
4520 '(27 . pr-file-landscape)
4521 '(27 . pr-file-duplex)
4522 '(27 . pr-file-tumble)
4523 '(27 . pr-auto-region)
4524 '(27 . pr-auto-mode)
4526 '(20 . pr-ps-utility)
4527 '(20 . pr-ps-utility-alist)
4529 '(14 . pr-mode-alist)
4531 '(20 . pr-menu-lock)
4532 '(20 . pr-menu-char-height)
4533 '(20 . pr-menu-char-width)
4535 '(20 . pr-setting-database)
4537 '(22 . pr-visible-entry-list)
4539 '(22 . pr-buffer-verbose)
4540 '(22 . pr-buffer-name)
4541 '(22 . pr-buffer-name-ignore)
4542 ")\n\n;;; printing.el - end of settings\n")
4543 "\n")))
4546 (defun lpr-setup ()
4547 "Return the current `lpr' setup.
4549 This is *not* an interactive command.
4550 One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4552 M-: (insert (lpr-setup)) RET
4554 Or choose the menu option Printing/Show Settings/lpr."
4555 (let (ps-prefix-quote)
4556 (mapconcat
4557 #'ps-print-quote
4558 (list
4559 "\n;;; lpr.el settings\n"
4560 (ps-comment-string "emacs-version" emacs-version)
4562 '(25 . printer-name)
4563 '(25 . lpr-switches)
4564 '(25 . lpr-add-switches)
4565 '(25 . lpr-command)
4566 '(25 . lpr-headers-switches)
4567 '(25 . print-region-function)
4568 '(25 . lpr-page-header-program)
4569 '(25 . lpr-page-header-switches)
4570 ")\n\n;;; lpr.el - end of settings\n")
4571 "\n")))
4574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4575 ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4578 (defalias 'pr-mh-get-msg-num 'mh-get-msg-num)
4579 (defalias 'pr-mh-show 'mh-show)
4580 (defalias 'pr-mh-start-of-uncleaned-message 'mh-start-of-uncleaned-message)
4581 (defvar mh-show-buffer nil)
4584 (defun pr-article-date ()
4585 "Find the date of an article or mail message in current buffer.
4586 Return only the dayname, if present, weekday, month, and year."
4587 (save-excursion
4588 (goto-char (point-min))
4589 (if (re-search-forward
4590 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4591 (buffer-substring (match-beginning 1) (match-end 1))
4592 (format-time-string "%Y/%m/%d"))))
4595 (defun pr-mh-current-message ()
4596 "Go to mh-inbox current message."
4597 (let ((msg (or (pr-mh-get-msg-num nil) 0)))
4598 (pr-mh-show)
4599 (set-buffer mh-show-buffer)
4600 (goto-char (point-min))
4601 (pr-mh-start-of-uncleaned-message)
4602 (message "Printing message %d" msg)))
4605 (defun pr-mh-print-1 (n-up filename header-list)
4606 "Print mh-inbox current message in PostScript."
4607 (save-excursion
4608 (save-window-excursion
4609 (pr-mh-current-message)
4610 (pr-mode-print n-up filename header-list (point)))))
4613 (defun pr-mh-lpr-1 (header-list)
4614 "Print mh-inbox current message in text printer."
4615 (save-excursion
4616 (save-window-excursion
4617 (pr-mh-current-message)
4618 (pr-mode-lpr header-list (point)))))
4621 (defalias 'pr-mh-print-2 'pr-mode-print)
4624 (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
4627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4628 ;; rmail (hacked from ps-print.el)
4631 (defun pr-rmail-lpr (header-list)
4632 "Print RMAIL current message in text printer."
4633 (pr-lpr-message-from-summary header-list
4634 'rmail-buffer 'rmail-summary-buffer))
4637 (defun pr-rmail-print (n-up filename header-list)
4638 "Print RMAIL current message in PostScript."
4639 (pr-ps-message-from-summary n-up filename header-list
4640 'rmail-buffer 'rmail-summary-buffer))
4643 (defun pr-ps-message-from-summary (n-up filename header-list
4644 summary-buffer summary-default)
4645 "Print current message in PostScript."
4646 (let ((buf (or (and (boundp summary-buffer)
4647 (symbol-value summary-buffer))
4648 (symbol-value summary-default))))
4649 (and (get-buffer buf)
4650 (save-excursion
4651 (set-buffer buf)
4652 (pr-mode-print n-up filename header-list)))))
4655 (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
4656 "Print current message in text printer."
4657 (let ((buf (or (and (boundp summary-buffer)
4658 (symbol-value summary-buffer))
4659 (symbol-value summary-default))))
4660 (and (get-buffer buf)
4661 (save-excursion
4662 (set-buffer buf)
4663 (pr-mode-lpr header-list)))))
4666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4667 ;; gnus (hacked from ps-print.el)
4670 (defvar pr-gnus-article "*Article*")
4673 (defun pr-gnus-print (n-up filename header-list)
4674 "Print *Article* current message in PostScript."
4675 (pr-ps-message-from-summary n-up filename header-list
4676 'gnus-article-buffer 'pr-gnus-article))
4679 (defun pr-gnus-lpr (header-list)
4680 "Print *Article* current message in text printer."
4681 (pr-lpr-message-from-summary header-list
4682 'gnus-article-buffer 'pr-gnus-article))
4685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4686 ;; vm (hacked from ps-print.el)
4689 (defvar pr-vm-summary "")
4692 (defun pr-vm-print (n-up filename header-list)
4693 "Print current vm message in PostScript."
4694 (pr-ps-message-from-summary n-up filename header-list
4695 'vm-mail-buffer 'pr-vm-summary))
4698 (defun pr-vm-lpr (header-list)
4699 "Print current vm message in text printer."
4700 (pr-lpr-message-from-summary header-list
4701 'vm-mail-buffer 'pr-vm-summary))
4704 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4705 ;; Mode Functions
4708 (defun pr-ps-mode (n-up filename)
4709 "If current major mode is declared, print it in PostScript."
4710 (let ((args (pr-mode-alist-p)))
4711 (if args
4712 (let ((fun (cdr args)))
4713 (funcall (car fun) n-up filename (cdr fun))
4715 (ding)
4716 (message "`%s' major mode not declared." major-mode)
4717 nil)))
4720 (defmacro pr-local-variable (header-list &rest body)
4721 `(save-excursion
4722 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
4723 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
4724 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
4725 ps-razzle-dazzle)
4726 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
4727 ,@body
4728 (and (nth 3 ,header-list)
4729 (pr-kill-local-variable local-var-list))))))
4732 (defun pr-mode-print (n-up filename header-list &optional from to)
4733 "Print current major mode in PostScript."
4734 (pr-local-variable
4735 header-list
4736 (let ((file (pr-ps-file filename))
4737 (start (cond (from)
4738 ((pr-region-active-p) (region-beginning))
4739 (t nil)
4741 (pr-text2ps (pr-region-active-symbol start) n-up file start
4742 (cond (to)
4743 ((pr-region-active-p) (region-end))
4744 (from (point-max))
4746 (unless (or pr-spool-p filename)
4747 (pr-ps-file-print file)
4748 (pr-delete-file file)))))
4751 (defun pr-mode-lpr (header-list &optional from to)
4752 "Print current major mode in text printer."
4753 (pr-local-variable
4754 header-list
4755 (pr-txt-print (cond (from)
4756 ((pr-region-active-p) (region-beginning))
4757 (t (point-min)))
4758 (cond (to)
4759 ((pr-region-active-p) (region-end))
4760 (t (point-max))))))
4763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4764 ;; Menu Lock
4767 (defconst pr-menu-entry-alist
4768 '((postscript . 3)
4769 (text . 3)
4770 (postscript-options . 9)
4771 (postscript-process . 3)
4772 (printing . 3)
4773 (help . 3)
4775 "Alist that associates menu part with number of items per part.
4777 It's used by `pr-menu-index'.
4779 Each element has the form:
4781 (MENU-PART . NUMBER-OF-ITEMS)
4783 See `pr-visible-entry-alist'.")
4786 (defun pr-menu-index (entry index)
4787 (let ((base-list
4788 (cond ((eq entry 'text)
4789 '(postscript))
4790 ((eq entry 'postscript-options)
4791 '(postscript text))
4792 ((eq entry 'postscript-process)
4793 '(postscript text postscript-options))
4794 ((eq entry 'printing)
4795 '(postscript text postscript-options postscript-process))
4797 nil)
4799 key)
4800 (while base-list
4801 (setq key (car base-list)
4802 base-list (cdr base-list))
4803 (and (pr-visible-p key)
4804 (setq index (+ index
4805 (cdr (assq key pr-menu-entry-alist)))))))
4806 (+ index 2))
4809 (defvar pr-menu-position nil)
4810 (defvar pr-menu-state nil)
4813 (cond
4814 ((featurep 'xemacs)
4815 ;; XEmacs
4816 (defvar current-mouse-event nil) ; to avoid compilation gripes
4817 (defun pr-menu-position (entry index horizontal)
4818 (pr-x-make-event
4819 'button-release
4820 (list 'button 1
4821 'x (- (pr-x-event-x-pixel current-mouse-event) ; X
4822 (* horizontal pr-menu-char-width))
4823 'y (- (pr-x-event-y-pixel current-mouse-event) ; Y
4824 (* (pr-menu-index entry index) pr-menu-char-height)))))
4826 (ps-windows-system
4827 ;; GNU Emacs for Windows 9x/NT
4828 (defun pr-menu-position (entry index horizontal)
4829 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4830 (list
4831 (list (or (car pos) 0) ; X
4832 (- (or (cdr pos) 0) ; Y
4833 (* (pr-menu-index entry index) pr-menu-char-height)))
4834 (selected-frame)))) ; frame
4837 ;; GNU Emacs
4838 (defun pr-menu-position (entry index horizontal)
4839 (let ((pos (cdr (pr-e-mouse-pixel-position))))
4840 (list
4841 (list (- (or (car pos) 0) ; X
4842 (* horizontal pr-menu-char-width))
4843 (- (or (cdr pos) 0) ; Y
4844 (* (pr-menu-index entry index) pr-menu-char-height)))
4845 (selected-frame)))) ; frame
4848 (cond
4849 ((featurep 'xemacs)
4850 ;; XEmacs
4851 (defvar current-menubar nil) ; to avoid compilation gripes
4852 (defun pr-menu-lookup (path)
4853 (car (pr-x-find-menu-item current-menubar (cons "Printing" path))))
4855 ;; XEmacs
4856 (defun pr-menu-lock (entry index horizontal state path)
4857 (when pr-menu-lock
4858 (or (and pr-menu-position (eq state pr-menu-state))
4859 (setq pr-menu-position (pr-menu-position entry index horizontal)
4860 pr-menu-state state))
4861 (let* ((menu (pr-menu-lookup path))
4862 (result (pr-x-get-popup-menu-response menu pr-menu-position)))
4863 (and (pr-x-misc-user-event-p result)
4864 (funcall (pr-x-event-function result)
4865 (pr-x-event-object result))))
4866 (setq pr-menu-position nil))))
4870 ;; GNU Emacs
4871 (defun pr-menu-lookup (path)
4872 (lookup-key global-map
4873 (if path
4874 (vconcat pr-menu-bar
4875 (mapcar 'pr-get-symbol
4876 (if (listp path)
4877 path
4878 (list path))))
4879 pr-menu-bar)))
4881 ;; GNU Emacs
4882 (defun pr-menu-lock (entry index horizontal state path)
4883 (when pr-menu-lock
4884 (or (and pr-menu-position (eq state pr-menu-state))
4885 (setq pr-menu-position (pr-menu-position entry index horizontal)
4886 pr-menu-state state))
4887 (let* ((menu (pr-menu-lookup path))
4888 (result (x-popup-menu pr-menu-position menu)))
4889 (and result
4890 (let ((command (lookup-key menu (vconcat result))))
4891 (if (fboundp command)
4892 (funcall command)
4893 (eval command)))))
4894 (setq pr-menu-position nil)))))
4897 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4898 ;; Printer & Utility Selection
4901 (defun pr-update-var (var-sym alist)
4902 (or (assq (symbol-value var-sym) alist)
4903 (set var-sym (car (car alist)))))
4906 (defun pr-update-menus (&optional force)
4907 "Update utility, PostScript and text printer menus.
4909 If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
4910 `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
4911 otherwise, update PostScript printer menu if `pr-ps-printer-menu-modified' is
4912 non-nil, update text printer menu if `pr-txt-printer-menu-modified' is
4913 non-nil, and update PostScript File menus if `pr-ps-utility-menu-modified' is
4914 non-nil.
4916 If menu binding was not done, calls `pr-menu-bind'."
4917 (interactive "P")
4918 (if pr-menu-print-item ; since v6.8.4
4919 ;; There was no menu binding yet, so do it now!
4920 ;; This is a hack to be compatible with old versions of printing.
4921 ;; So, user does not need to change printing calling in init files.
4922 (pr-menu-bind)
4923 ;; Here menu binding is ok.
4924 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
4925 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
4926 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
4927 (pr-do-update-menus force)))
4930 (defvar pr-ps-printer-menu-modified t
4931 "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
4932 (defvar pr-txt-printer-menu-modified t
4933 "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
4934 (defvar pr-ps-utility-menu-modified t
4935 "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
4938 (defconst pr-even-or-odd-alist
4939 '((nil . "Print All Pages")
4940 (even-page . "Print Even Pages")
4941 (odd-page . "Print Odd Pages")
4942 (even-sheet . "Print Even Sheets")
4943 (odd-sheet . "Print Odd Sheets")))
4946 (defun pr-menu-create (name alist var-sym fun entry index)
4947 (cons name
4948 (mapcar
4949 #'(lambda (elt)
4950 (let ((sym (car elt)))
4951 (vector
4952 (symbol-name sym)
4953 (list fun (list 'quote sym) nil (list 'quote entry) index)
4954 :style 'radio
4955 :selected (list 'eq var-sym (list 'quote sym)))))
4956 alist)))
4959 (cond
4960 ((featurep 'xemacs)
4961 ;; XEmacs
4962 (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
4964 ;; XEmacs
4965 (defvar pr-ps-name-old "PostScript Printers")
4966 (defvar pr-txt-name-old "Text Printers")
4967 (defvar pr-ps-utility-old "PostScript Utility")
4968 (defvar pr-even-or-odd-old "Print All Pages")
4970 ;; XEmacs
4971 (defun pr-do-update-menus (&optional force)
4972 (pr-menu-alist pr-ps-printer-alist
4973 'pr-ps-name
4974 'pr-menu-set-ps-title
4975 '("Printing")
4976 'pr-ps-printer-menu-modified
4977 force
4978 pr-ps-name-old
4979 'postscript 2)
4980 (pr-menu-alist pr-txt-printer-alist
4981 'pr-txt-name
4982 'pr-menu-set-txt-title
4983 '("Printing")
4984 'pr-txt-printer-menu-modified
4985 force
4986 pr-txt-name-old
4987 'text 2)
4988 (let ((save-var pr-ps-utility-menu-modified))
4989 (pr-menu-alist pr-ps-utility-alist
4990 'pr-ps-utility
4991 'pr-menu-set-utility-title
4992 '("Printing" "PostScript Print" "File")
4993 'save-var
4994 force
4995 pr-ps-utility-old
4996 nil 1))
4997 (pr-menu-alist pr-ps-utility-alist
4998 'pr-ps-utility
4999 'pr-menu-set-utility-title
5000 '("Printing" "PostScript Preview" "File")
5001 'pr-ps-utility-menu-modified
5002 force
5003 pr-ps-utility-old
5004 nil 1)
5005 (pr-even-or-odd-pages ps-even-or-odd-pages force))
5007 ;; XEmacs
5008 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
5009 entry index)
5010 (when (and alist (or force (symbol-value modified-sym)))
5011 (pr-xemacs-global-menubar
5012 (pr-x-add-submenu menu-path
5013 (pr-menu-create name alist var-sym
5014 fun entry index)))
5015 (funcall fun (symbol-value var-sym))
5016 (set modified-sym nil)))
5018 ;; XEmacs
5019 (defun pr-relabel-menu-item (newname var-sym)
5020 (pr-xemacs-global-menubar
5021 (pr-x-relabel-menu-item
5022 (list "Printing" (symbol-value var-sym))
5023 newname)
5024 (set var-sym newname)))
5026 ;; XEmacs
5027 (defun pr-menu-set-ps-title (value &optional item entry index)
5028 (pr-relabel-menu-item (format "PostScript Printer: %s" value)
5029 'pr-ps-name-old)
5030 (pr-ps-set-printer value)
5031 (and index
5032 (pr-menu-lock entry index 12 'toggle nil)))
5034 ;; XEmacs
5035 (defun pr-menu-set-txt-title (value &optional item entry index)
5036 (pr-relabel-menu-item (format "Text Printer: %s" value)
5037 'pr-txt-name-old)
5038 (pr-txt-set-printer value)
5039 (and index
5040 (pr-menu-lock entry index 12 'toggle nil)))
5042 ;; XEmacs
5043 (defun pr-menu-set-utility-title (value &optional item entry index)
5044 (pr-xemacs-global-menubar
5045 (let ((newname (format "%s" value)))
5046 (pr-x-relabel-menu-item
5047 (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
5048 newname)
5049 (pr-x-relabel-menu-item
5050 (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
5051 newname)
5052 (setq pr-ps-utility-old newname)))
5053 (pr-ps-set-utility value)
5054 (and index
5055 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
5057 ;; XEmacs
5058 (defun pr-even-or-odd-pages (value &optional no-lock)
5059 (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
5060 'pr-even-or-odd-old)
5061 (setq ps-even-or-odd-pages value)
5062 (or no-lock
5063 (pr-menu-lock 'postscript-options 8 12 'toggle nil))))
5067 ;; GNU Emacs
5068 (defalias 'pr-update-mode-line 'force-mode-line-update)
5070 ;; GNU Emacs
5071 (defun pr-do-update-menus (&optional force)
5072 (pr-menu-alist pr-ps-printer-alist
5073 'pr-ps-name
5074 'pr-menu-set-ps-title
5075 "PostScript Printers"
5076 'pr-ps-printer-menu-modified
5077 force
5078 "PostScript Printers"
5079 'postscript 2)
5080 (pr-menu-alist pr-txt-printer-alist
5081 'pr-txt-name
5082 'pr-menu-set-txt-title
5083 "Text Printers"
5084 'pr-txt-printer-menu-modified
5085 force
5086 "Text Printers"
5087 'text 2)
5088 (let ((save-var pr-ps-utility-menu-modified))
5089 (pr-menu-alist pr-ps-utility-alist
5090 'pr-ps-utility
5091 'pr-menu-set-utility-title
5092 '("PostScript Print" "File" "PostScript Utility")
5093 'save-var
5094 force
5095 "PostScript Utility"
5096 nil 1))
5097 (pr-menu-alist pr-ps-utility-alist
5098 'pr-ps-utility
5099 'pr-menu-set-utility-title
5100 '("PostScript Preview" "File" "PostScript Utility")
5101 'pr-ps-utility-menu-modified
5102 force
5103 "PostScript Utility"
5104 nil 1)
5105 (pr-even-or-odd-pages ps-even-or-odd-pages force))
5107 ;; GNU Emacs
5108 (defun pr-menu-get-item (name-list)
5109 ;; NAME-LIST is a string or a list of strings.
5110 (or (listp name-list)
5111 (setq name-list (list name-list)))
5112 (and name-list
5113 (let* ((reversed (reverse name-list))
5114 (name (pr-get-symbol (car reversed)))
5115 (path (nreverse (cdr reversed)))
5116 (menu (lookup-key
5117 global-map
5118 (vconcat pr-menu-bar
5119 (mapcar 'pr-get-symbol path)))))
5120 (assq name (nthcdr 2 menu)))))
5122 ;; GNU Emacs
5123 (defvar pr-temp-menu nil)
5125 ;; GNU Emacs
5126 (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
5127 entry index)
5128 (when (and alist (or force (symbol-value modified-sym)))
5129 (easy-menu-define pr-temp-menu nil ""
5130 (pr-menu-create name alist var-sym fun entry index))
5131 (let ((item (pr-menu-get-item menu-path)))
5132 (and item
5133 (let* ((binding (nthcdr 3 item))
5134 (key-binding (cdr binding)))
5135 (setcar binding pr-temp-menu)
5136 (and key-binding (listp (car key-binding))
5137 (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
5138 (funcall fun (symbol-value var-sym) item))))
5139 (set modified-sym nil)))
5141 ;; GNU Emacs
5142 (defun pr-menu-set-item-name (item name)
5143 (and item
5144 (setcar (nthcdr 2 item) name))) ; ITEM-NAME
5146 ;; GNU Emacs
5147 (defun pr-menu-set-ps-title (value &optional item entry index)
5148 (pr-menu-set-item-name (or item
5149 (pr-menu-get-item "PostScript Printers"))
5150 (format "PostScript Printer: %s" value))
5151 (pr-ps-set-printer value)
5152 (and index
5153 (pr-menu-lock entry index 12 'toggle nil)))
5155 ;; GNU Emacs
5156 (defun pr-menu-set-txt-title (value &optional item entry index)
5157 (pr-menu-set-item-name (or item
5158 (pr-menu-get-item "Text Printers"))
5159 (format "Text Printer: %s" value))
5160 (pr-txt-set-printer value)
5161 (and index
5162 (pr-menu-lock entry index 12 'toggle nil)))
5164 ;; GNU Emacs
5165 (defun pr-menu-set-utility-title (value &optional item entry index)
5166 (let ((name (symbol-name value)))
5167 (if item
5168 (pr-menu-set-item-name item name)
5169 (pr-menu-set-item-name
5170 (pr-menu-get-item
5171 '("PostScript Print" "File" "PostScript Utility"))
5172 name)
5173 (pr-menu-set-item-name
5174 (pr-menu-get-item
5175 '("PostScript Preview" "File" "PostScript Utility"))
5176 name)))
5177 (pr-ps-set-utility value)
5178 (and index
5179 (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
5181 ;; GNU Emacs
5182 (defun pr-even-or-odd-pages (value &optional no-lock)
5183 (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
5184 (cdr (assq value pr-even-or-odd-alist)))
5185 (setq ps-even-or-odd-pages value)
5186 (or no-lock
5187 (pr-menu-lock 'postscript-options 8 12 'toggle nil)))))
5190 (defun pr-ps-set-utility (value)
5191 (let ((item (cdr (assq value pr-ps-utility-alist))))
5192 (or item
5193 (error
5194 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
5195 value))
5196 (setq pr-ps-utility value)
5197 (pr-eval-alist (nthcdr 9 item)))
5198 (pr-update-mode-line))
5201 (defun pr-ps-set-printer (value)
5202 (let ((ps (cdr (assq value pr-ps-printer-alist))))
5203 (or ps
5204 (error
5205 "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
5206 value))
5207 (setq pr-ps-name value
5208 pr-ps-command (pr-dosify-file-name (nth 0 ps))
5209 pr-ps-switches (nth 1 ps)
5210 pr-ps-printer-switch (nth 2 ps)
5211 pr-ps-printer (nth 3 ps))
5212 (or (stringp pr-ps-command)
5213 (setq pr-ps-command
5214 (cond (ps-windows-system "print")
5215 (ps-lp-system "lp")
5216 (t "lpr")
5218 (or (stringp pr-ps-printer-switch)
5219 (setq pr-ps-printer-switch
5220 (cond (ps-windows-system "/D:")
5221 (ps-lp-system "-d")
5222 (t "-P")
5224 (pr-eval-alist (nthcdr 4 ps)))
5225 (pr-update-mode-line))
5228 (defun pr-txt-set-printer (value)
5229 (let ((txt (cdr (assq value pr-txt-printer-alist))))
5230 (or txt
5231 (error "Invalid text printer name `%s' for variable `pr-txt-name'"
5232 value))
5233 (setq pr-txt-name value
5234 pr-txt-command (pr-dosify-file-name (nth 0 txt))
5235 pr-txt-switches (nth 1 txt)
5236 pr-txt-printer (nth 2 txt)))
5237 (or (stringp pr-txt-command)
5238 (setq pr-txt-command
5239 (cond (ps-windows-system "print")
5240 (ps-lp-system "lp")
5241 (t "lpr")
5243 (pr-update-mode-line))
5246 (defun pr-eval-alist (alist)
5247 (mapcar #'(lambda (option)
5248 (let ((var-sym (car option))
5249 (value (cdr option)))
5250 (if (eq var-sym 'inherits-from:)
5251 (pr-eval-setting-alist value 'global)
5252 (set var-sym (eval value)))))
5253 alist))
5256 (defun pr-eval-local-alist (alist)
5257 (let (local-list)
5258 (mapcar #'(lambda (option)
5259 (let ((var-sym (car option))
5260 (value (cdr option)))
5261 (setq local-list
5262 (if (eq var-sym 'inherits-from:)
5263 (nconc (pr-eval-setting-alist value) local-list)
5264 (set (make-local-variable var-sym) (eval value))
5265 (cons var-sym local-list)))))
5266 alist)
5267 local-list))
5270 (defun pr-eval-setting-alist (key &optional global old)
5271 (let ((setting (cdr (assq key pr-setting-database))))
5272 (and setting
5273 (let ((inherits (nth 0 setting))
5274 (local (nth 1 setting))
5275 (kill (nth 2 setting))
5276 local-list)
5277 (and local global
5278 (progn
5279 (ding)
5280 (message "There are local buffer settings for `%S'." key)
5281 (setq global nil)))
5282 (and inherits
5283 (if (memq inherits old)
5284 (error "Circular inheritance for `%S'" inherits)
5285 (setq local-list
5286 (pr-eval-setting-alist inherits global
5287 (cons inherits old)))))
5288 (mapcar
5289 (cond ((not local) ; global settings
5290 #'(lambda (option)
5291 (let ((var-sym (car option)))
5292 (or (eq var-sym 'inherits-from:)
5293 (set var-sym (eval (cdr option)))))))
5294 (kill ; local settings with killing
5295 #'(lambda (option)
5296 (let ((var-sym (car option)))
5297 (unless (eq var-sym 'inherits-from:)
5298 (setq local-list (cons var-sym local-list))
5299 (set (make-local-variable var-sym)
5300 (eval (cdr option)))))))
5301 (t ; local settings without killing
5302 #'(lambda (option)
5303 (let ((var-sym (car option)))
5304 (or (eq var-sym 'inherits-from:)
5305 (set (make-local-variable var-sym)
5306 (eval (cdr option))))))))
5307 (nthcdr 3 setting))
5308 local-list))))
5311 (defun pr-kill-local-variable (local-var-list)
5312 (mapcar 'kill-local-variable local-var-list))
5315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5316 ;; Internal Functions (II)
5319 (defun pr-toggle (var-sym mess entry index horizontal state
5320 &optional path no-menu)
5321 (set var-sym (not (symbol-value var-sym)))
5322 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5323 (or no-menu
5324 (pr-menu-lock entry index horizontal state path)))
5327 (defun pr-toggle-file-duplex-menu (&optional no-menu)
5328 (interactive)
5329 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
5330 '("PostScript Print" "File") no-menu))
5333 (defun pr-toggle-file-tumble-menu (&optional no-menu)
5334 (interactive)
5335 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
5336 '("PostScript Print" "File") no-menu))
5339 (defun pr-toggle-file-landscape-menu (&optional no-menu)
5340 (interactive)
5341 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
5342 '("PostScript Print" "File") no-menu))
5345 (defun pr-toggle-ghostscript-menu (&optional no-menu)
5346 (interactive)
5347 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
5348 'postscript-process 2 12 'toggle nil no-menu))
5351 (defun pr-toggle-faces-menu (&optional no-menu)
5352 (interactive)
5353 (pr-toggle 'pr-faces-p "Printing with faces"
5354 'postscript-process 1 12 'toggle nil no-menu))
5357 (defun pr-toggle-spool-menu (&optional no-menu)
5358 (interactive)
5359 (pr-toggle 'pr-spool-p "Spooling printing"
5360 'postscript-process 0 12 'toggle nil no-menu))
5363 (defun pr-toggle-duplex-menu (&optional no-menu)
5364 (interactive)
5365 (pr-toggle 'ps-spool-duplex "Printing duplex"
5366 'postscript-options 5 12 'toggle nil no-menu))
5369 (defun pr-toggle-tumble-menu (&optional no-menu)
5370 (interactive)
5371 (pr-toggle 'ps-spool-tumble "Tumble"
5372 'postscript-options 6 12 'toggle nil no-menu))
5375 (defun pr-toggle-landscape-menu (&optional no-menu)
5376 (interactive)
5377 (pr-toggle 'ps-landscape-mode "Landscape"
5378 'postscript-options 0 12 'toggle nil no-menu))
5381 (defun pr-toggle-upside-down-menu (&optional no-menu)
5382 (interactive)
5383 (pr-toggle 'ps-print-upside-down "Upside-Down"
5384 'postscript-options 7 12 'toggle nil no-menu))
5387 (defun pr-toggle-line-menu (&optional no-menu)
5388 (interactive)
5389 (pr-toggle 'ps-line-number "Line number"
5390 'postscript-options 3 12 'toggle nil no-menu))
5393 (defun pr-toggle-zebra-menu (&optional no-menu)
5394 (interactive)
5395 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
5396 'postscript-options 4 12 'toggle nil no-menu))
5399 (defun pr-toggle-header-menu (&optional no-menu)
5400 (interactive)
5401 (pr-toggle 'ps-print-header "Print header"
5402 'postscript-options 1 12 'toggle nil no-menu))
5405 (defun pr-toggle-header-frame-menu (&optional no-menu)
5406 (interactive)
5407 (pr-toggle 'ps-print-header-frame "Print header frame"
5408 'postscript-options 2 12 'toggle nil no-menu))
5411 (defun pr-toggle-lock-menu (&optional no-menu)
5412 (interactive)
5413 (pr-toggle 'pr-menu-lock "Menu lock"
5414 'printing 2 12 'toggle nil no-menu))
5417 (defun pr-toggle-region-menu (&optional no-menu)
5418 (interactive)
5419 (pr-toggle 'pr-auto-region "Auto region"
5420 'printing 0 12 'toggle nil no-menu))
5423 (defun pr-toggle-mode-menu (&optional no-menu)
5424 (interactive)
5425 (pr-toggle 'pr-auto-mode "Auto mode"
5426 'printing 1 12 'toggle nil no-menu))
5429 (defun pr-prompt (str)
5430 (if (pr-auto-mode-p)
5431 (concat str " mode")
5432 (pr-region-active-string str)))
5435 (defun pr-prompt-region (str)
5436 (concat str (if (pr-auto-mode-p)
5437 " mode"
5438 " region")))
5441 (defun pr-prompt-gs (str)
5442 (if (pr-using-ghostscript-p)
5443 (concat str " GS")
5444 str))
5447 (defun pr-region-active-symbol (&optional region-p)
5448 (if (or region-p (pr-region-active-p))
5449 'region
5450 'buffer))
5453 (defun pr-region-active-string (prefix)
5454 (concat prefix
5455 (if (pr-region-active-p)
5456 " region"
5457 " buffer")))
5460 (defun pr-show-setup (settings buffer-name)
5461 (with-output-to-temp-buffer buffer-name
5462 (princ settings)
5463 (print-help-return-message)))
5466 (defun pr-complete-alist (prompt alist default)
5467 (let ((collection (mapcar #'(lambda (elt)
5468 (setq elt (car elt))
5469 (cons (symbol-name elt) elt))
5470 alist)))
5471 (cdr (assoc (completing-read (concat prompt ": ")
5472 collection nil t
5473 (symbol-name default) nil
5474 (symbol-name default))
5475 collection))))
5478 (defun pr-delete-file (file)
5479 (and pr-delete-temp-file (file-exists-p file)
5480 (delete-file file)))
5483 (defun pr-expand-file-name (filename)
5484 (pr-dosify-file-name (expand-file-name filename)))
5487 (defun pr-ps-outfile-preprint (&optional mess)
5488 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5489 (res (read-file-name prompt default-directory "" nil)))
5490 (while (cond ((not (file-writable-p res))
5491 (ding)
5492 (setq prompt "is unwritable"))
5493 ((file-directory-p res)
5494 (ding)
5495 (setq prompt "is a directory"))
5496 ((file-exists-p res)
5497 (ding)
5498 (setq prompt "exists")
5499 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5500 res))))
5501 (t nil))
5502 (setq res (read-file-name
5503 (format "File %s; PostScript file: " prompt)
5504 (file-name-directory res) nil nil
5505 (file-name-nondirectory res))))
5506 (pr-expand-file-name res)))
5509 (defun pr-ps-infile-preprint (&optional mess)
5510 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5511 (res (read-file-name prompt default-directory "" nil)))
5512 (while (cond ((not (file-exists-p res))
5513 (ding)
5514 (setq prompt "doesn't exist"))
5515 ((not (file-readable-p res))
5516 (ding)
5517 (setq prompt "is unreadable"))
5518 ((file-directory-p res)
5519 (ding)
5520 (setq prompt "is a directory"))
5521 (t nil))
5522 (setq res (read-file-name
5523 (format "File %s; PostScript file: " prompt)
5524 (file-name-directory res) nil nil
5525 (file-name-nondirectory res))))
5526 (pr-expand-file-name res)))
5529 (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
5530 ;; check arguments for PostScript file processing.
5531 ;; n-up
5532 (or (symbol-value n-up-sym)
5533 (set n-up-sym (pr-interactive-n-up prompt)))
5534 ;; input file
5535 (and (eq (symbol-value infile-sym) t)
5536 (set infile-sym (pr-ps-infile-preprint prompt)))
5537 (or (symbol-value infile-sym)
5538 (error "%s: input PostScript file name is missing" prompt))
5539 (set infile-sym (pr-dosify-file-name (symbol-value infile-sym)))
5540 ;; output file
5541 (and (eq (symbol-value outfile-sym) t)
5542 (set outfile-sym (and current-prefix-arg
5543 (pr-ps-outfile-preprint prompt))))
5544 (and (symbol-value outfile-sym)
5545 (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym))))
5546 (pr-ps-file (symbol-value outfile-sym)))
5549 (defun pr-ps-utility-process (n-up infile outfile)
5550 ;; activate utility to process a PostScript file.
5551 (let (item)
5552 (and (stringp infile) (file-exists-p infile)
5553 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
5554 (pr-call-process (nth 0 item)
5555 (pr-switches-string (nth 1 item)
5556 "pr-ps-utility-alist entry")
5557 (pr-switches-string (nth 8 item)
5558 "pr-ps-utility-alist entry")
5559 (and (nth 2 item)
5560 (format (nth 2 item) ps-paper-type))
5561 (format (nth 3 item) n-up)
5562 (and pr-file-landscape (nth 4 item))
5563 (and pr-file-duplex (nth 5 item))
5564 (and pr-file-tumble (nth 6 item))
5565 (pr-expand-file-name infile)
5566 (nth 7 item)
5567 (pr-expand-file-name outfile)))))
5570 (defun pr-remove-nil-from-list (lst)
5571 (while (and lst (null (car lst)))
5572 (setq lst (cdr lst)))
5573 (let ((b lst)
5574 (l (cdr lst)))
5575 (while l
5576 (if (car l)
5577 (setq b l
5578 l (cdr l))
5579 (setq l (cdr l))
5580 (setcdr b l))))
5581 lst)
5584 (defun pr-call-process (command &rest args)
5585 (let ((buffer (get-buffer-create "*Printing Command Output*"))
5586 (cmd (pr-command command))
5587 status)
5588 (setq args (pr-remove-nil-from-list args))
5589 ;; *Printing Command Output* == show command & args
5590 (save-excursion
5591 (set-buffer buffer)
5592 (goto-char (point-max))
5593 (insert (format "%s %S\n" cmd args)))
5594 ;; *Printing Command Output* == show any return message from command
5595 (pr-save-file-modes
5596 (setq status
5597 (condition-case data
5598 (apply 'call-process cmd nil buffer nil args)
5599 ((quit error)
5600 (error-message-string data)))))
5601 ;; *Printing Command Output* == show exit status
5602 (save-excursion
5603 (set-buffer buffer)
5604 (goto-char (point-max))
5605 (insert (format "Exit status: %s\n\n" status)))
5606 ;; message if error status
5607 (if (or (stringp status)
5608 (and (integerp status) (/= status 0)))
5609 (message
5610 "Printing error status: %s (see *Printing Command Output* buffer)"
5611 status))))
5614 (defun pr-txt-print (from to)
5615 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command)))
5616 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5617 (printer-name pr-txt-printer))
5618 (lpr-region from to)))
5621 (defun pr-switches-string (switches mess)
5622 ;; If SWITCHES is nil, return nil.
5623 ;; Otherwise, return the list of string in a string.
5624 (and switches
5625 (mapconcat 'identity (pr-switches switches mess) " ")))
5628 (defun pr-switches (switches mess)
5629 (or (listp switches)
5630 (error "%S should have a list of strings" mess))
5631 (ps-flatten-list ; dynamic evaluation
5632 (mapcar 'ps-eval-switch switches)))
5635 (defun pr-ps-preview (kind n-up filename mess)
5636 (pr-set-n-up-and-filename 'n-up 'filename mess)
5637 (let ((file (pr-ps-file filename)))
5638 (pr-text2ps kind n-up file)
5639 (or pr-spool-p (pr-ps-file-preview file))))
5642 (defun pr-ps-using-ghostscript (kind n-up filename mess)
5643 (pr-set-n-up-and-filename 'n-up 'filename mess)
5644 (let ((file (pr-ps-file filename)))
5645 (pr-text2ps kind n-up file)
5646 (unless (or pr-spool-p filename)
5647 (pr-ps-file-using-ghostscript file)
5648 (pr-delete-file file))))
5651 (defun pr-ps-print (kind n-up filename mess)
5652 (pr-set-n-up-and-filename 'n-up 'filename mess)
5653 (let ((file (pr-ps-file filename)))
5654 (pr-text2ps kind n-up file)
5655 (unless (or pr-spool-p filename)
5656 (pr-ps-file-print file)
5657 (pr-delete-file file))))
5660 (defun pr-ps-file (&optional filename)
5661 (pr-dosify-file-name (or filename
5662 (make-temp-file
5663 (convert-standard-filename
5664 (expand-file-name pr-ps-temp-file pr-temp-dir))
5665 nil ".ps"))))
5668 (defun pr-interactive-n-up (mess)
5669 (or (stringp mess) (setq mess "*"))
5670 (save-match-data
5671 (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
5672 (prompt "")
5673 (str (pr-f-read-string (format fmt-prompt prompt mess) "1" nil "1"))
5674 int)
5675 (while (if (string-match "^\\s *[0-9]+$" str)
5676 (setq int (string-to-number str)
5677 prompt (cond ((< int 1) "Integer below 1; ")
5678 ((> int 100) "Integer above 100; ")
5679 (t nil)))
5680 (setq prompt "Invalid integer syntax; "))
5681 (ding)
5682 (setq str
5683 (pr-f-read-string (format fmt-prompt prompt mess) str nil "1")))
5684 int)))
5687 (defun pr-interactive-dir (mess)
5688 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5689 default-directory)))
5690 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
5691 (dir (read-file-name (format fmt-prompt "")
5692 "" dir-name nil dir-name))
5693 prompt)
5694 (while (cond ((not (file-directory-p dir))
5695 (ding)
5696 (setq prompt "It's not a directory! "))
5697 ((not (file-readable-p dir))
5698 (ding)
5699 (setq prompt "Directory is unreadable! "))
5700 (t nil))
5701 (setq dir-name (file-name-directory dir)
5702 dir (read-file-name (format fmt-prompt prompt)
5703 "" dir-name nil dir-name)))
5704 (file-name-as-directory dir)))
5707 (defun pr-interactive-regexp (mess)
5708 (pr-f-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
5711 (defun pr-interactive-dir-args (mess)
5712 (list
5713 ;; get directory argument
5714 (pr-interactive-dir mess)
5715 ;; get file name regexp
5716 (pr-interactive-regexp mess)))
5719 (defun pr-interactive-ps-dir-args (mess)
5720 (list
5721 ;; get n-up argument
5722 (pr-interactive-n-up mess)
5723 ;; get directory argument
5724 (pr-interactive-dir mess)
5725 ;; get file name regexp
5726 (pr-interactive-regexp mess)
5727 ;; get output file name
5728 (and (not pr-spool-p)
5729 (ps-print-preprint current-prefix-arg))))
5732 (defun pr-interactive-n-up-file (mess)
5733 (list
5734 ;; get n-up argument
5735 (pr-interactive-n-up mess)
5736 ;; get output file name
5737 (and (not pr-spool-p)
5738 (ps-print-preprint current-prefix-arg))))
5741 (defun pr-interactive-n-up-inout (mess)
5742 (list
5743 ;; get n-up argument
5744 (pr-interactive-n-up mess)
5745 ;; get input file name
5746 (pr-ps-infile-preprint (concat mess " "))
5747 ;; get output file name
5748 (ps-print-preprint current-prefix-arg)))
5751 (defun pr-set-outfilename (filename-sym)
5752 (and (not pr-spool-p)
5753 (eq (symbol-value filename-sym) t)
5754 (set filename-sym (and current-prefix-arg
5755 (ps-print-preprint current-prefix-arg))))
5756 (and (symbol-value filename-sym)
5757 (set filename-sym (pr-dosify-file-name (symbol-value filename-sym)))))
5760 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5761 ;; n-up
5762 (or (symbol-value n-up-sym)
5763 (set n-up-sym (pr-interactive-n-up mess)))
5764 ;; output file
5765 (pr-set-outfilename filename-sym))
5768 (defun pr-set-dir-args (dir-sym regexp-sym mess)
5769 ;; directory
5770 (or (symbol-value dir-sym)
5771 (set dir-sym (pr-interactive-dir mess)))
5772 ;; file name regexp
5773 (or (symbol-value regexp-sym)
5774 (set regexp-sym (pr-interactive-regexp mess))))
5777 (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5778 ;; n-up
5779 (or (symbol-value n-up-sym)
5780 (set n-up-sym (pr-interactive-n-up mess)))
5781 ;; directory & file name regexp
5782 (pr-set-dir-args dir-sym regexp-sym mess)
5783 ;; output file
5784 (pr-set-outfilename filename-sym))
5787 (defun pr-find-buffer-visiting (file)
5788 (if (not (file-directory-p file))
5789 (find-buffer-visiting (if ps-windows-system
5790 (downcase file)
5791 file))
5792 (let ((truename (file-truename file))
5793 (blist (buffer-list))
5794 found)
5795 (while (and (not found) blist)
5796 (save-excursion
5797 (set-buffer (car blist))
5798 (and (eq major-mode 'dired-mode)
5799 (save-excursion
5800 (goto-char (point-min))
5801 (string= (buffer-substring-no-properties
5802 (+ (point-min) 2)
5803 (progn
5804 (end-of-line)
5805 (1- (point))))
5806 truename))
5807 (setq found (car blist))))
5808 (setq blist (cdr blist)))
5809 found)))
5812 (defun pr-file-list (dir file-regexp fun)
5813 (mapcar #'(lambda (file)
5814 (and (or pr-list-directory
5815 (not (file-directory-p file)))
5816 (let ((buffer (pr-find-buffer-visiting file))
5817 pop-up-windows
5818 pop-up-frames)
5819 (and (or buffer
5820 (file-readable-p file))
5821 (save-excursion
5822 (set-buffer (or buffer
5823 (find-file-noselect file)))
5824 (funcall fun)
5825 (or buffer
5826 (kill-buffer (current-buffer))))))))
5827 (directory-files dir t file-regexp)))
5830 (defun pr-delete-file-if-exists (filename)
5831 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5832 (delete-file filename)))
5835 (defun pr-ps-file-list (n-up dir file-regexp filename)
5836 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5837 (let ((pr-spool-p t))
5838 (pr-file-list dir file-regexp
5839 #'(lambda ()
5840 (if (pr-auto-mode-p)
5841 (pr-ps-mode n-up filename)
5842 (pr-text2ps 'buffer n-up filename)))))
5843 (or pr-spool-p
5844 (pr-despool-print filename)))
5847 (defun pr-text2ps (kind n-up filename &optional from to)
5848 (pr-save-file-modes
5849 (let ((ps-n-up-printing n-up)
5850 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5851 'setpagedevice)))
5852 (pr-delete-file-if-exists filename)
5853 (cond (pr-faces-p
5854 (cond (pr-spool-p
5855 ;; pr-faces-p and pr-spool-p
5856 ;; here FILENAME arg is ignored
5857 (cond ((eq kind 'buffer)
5858 (ps-spool-buffer-with-faces))
5859 ((eq kind 'region)
5860 (ps-spool-region-with-faces (or from (point))
5861 (or to (mark))))
5863 ;; pr-faces-p and not pr-spool-p
5864 ((eq kind 'buffer)
5865 (ps-print-buffer-with-faces filename))
5866 ((eq kind 'region)
5867 (ps-print-region-with-faces (or from (point))
5868 (or to (mark)) filename))
5870 (pr-spool-p
5871 ;; not pr-faces-p and pr-spool-p
5872 ;; here FILENAME arg is ignored
5873 (cond ((eq kind 'buffer)
5874 (ps-spool-buffer))
5875 ((eq kind 'region)
5876 (ps-spool-region (or from (point)) (or to (mark))))
5878 ;; not pr-faces-p and not pr-spool-p
5879 ((eq kind 'buffer)
5880 (ps-print-buffer filename))
5881 ((eq kind 'region)
5882 (ps-print-region (or from (point)) (or to (mark)) filename))
5883 ))))
5886 (defun pr-command (command)
5887 "Return absolute file name specification for COMMAND.
5889 If COMMAND is an empty string, return it.
5891 If COMMAND is already an absolute file name specification, return it.
5892 Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5893 otherwise, gives an error.
5895 When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5896 `unix' are used (see `pr-path-alist' for documentation).
5898 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5899 COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
5900 (if (string= command "")
5901 command
5902 (pr-dosify-file-name
5903 (or (pr-find-command command)
5904 (pr-path-command (cond (pr-cygwin-system 'cygwin)
5905 (ps-windows-system 'windows)
5906 (t 'unix))
5907 (file-name-nondirectory command)
5908 nil)
5909 (error "Command not found: %s"
5910 (file-name-nondirectory command))))))
5913 (defun pr-path-command (symbol command sym-list)
5914 (let ((lpath (cdr (assq symbol pr-path-alist)))
5915 cmd)
5916 ;; PATH expansion
5917 (and (eq symbol 'PATH) (null lpath)
5918 (setq lpath (parse-colon-path (getenv "PATH"))))
5919 (while (and lpath
5920 (not
5921 (setq cmd
5922 (let ((path (car lpath)))
5923 (cond
5924 ;; symbol expansion
5925 ((symbolp path)
5926 (and (not (memq path sym-list))
5927 (pr-path-command path command
5928 (cons path sym-list))))
5929 ;; normal path
5930 ((stringp path)
5931 (pr-find-command
5932 (expand-file-name
5933 (substitute-in-file-name
5934 (concat (file-name-as-directory path)
5935 command)))))
5936 )))))
5937 (setq lpath (cdr lpath)))
5938 cmd))
5941 (defun pr-find-command (cmd)
5942 (if ps-windows-system
5943 ;; windows system
5944 (let ((ext (cons (file-name-extension cmd t)
5945 (list ".exe" ".bat" ".com")))
5946 found)
5947 (setq cmd (file-name-sans-extension cmd))
5948 (while (and ext
5949 (setq found (concat cmd (car ext)))
5950 (not (and (file-regular-p found)
5951 (file-executable-p found))))
5952 (setq ext (cdr ext)
5953 found nil))
5954 found)
5955 ;; non-windows systems
5956 (and (file-regular-p cmd)
5957 (file-executable-p cmd)
5958 cmd)))
5961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5962 ;; Printing Interface (inspired on ps-print-interface.el)
5965 (require 'widget)
5966 (require 'wid-edit)
5967 (require 'cus-edit)
5970 (defvar pr-i-window-configuration nil)
5972 (defvar pr-i-buffer nil)
5973 (defvar pr-i-region nil)
5974 (defvar pr-i-mode nil)
5975 (defvar pr-i-despool nil)
5976 (defvar pr-i-ps-as-is t)
5977 (defvar pr-i-n-up 1)
5978 (defvar pr-i-directory "./")
5979 (defvar pr-i-regexp "")
5980 (defvar pr-i-ps-file "")
5981 (defvar pr-i-out-file "")
5982 (defvar pr-i-answer-yes nil)
5983 (defvar pr-i-process 'buffer)
5984 (defvar pr-i-ps-send 'printer)
5987 (defvar pr-interface-map nil
5988 "Keymap for pr-interface.")
5990 (unless pr-interface-map
5991 (setq pr-interface-map (make-sparse-keymap))
5992 (cond ((featurep 'xemacs) ; XEmacs
5993 (pr-f-set-keymap-parents pr-interface-map (list widget-keymap))
5994 (pr-f-set-keymap-name pr-interface-map 'pr-interface-map))
5995 (t ; GNU Emacs
5996 (pr-f-set-keymap-parents pr-interface-map widget-keymap)))
5997 (define-key pr-interface-map "q" 'pr-interface-quit)
5998 (define-key pr-interface-map "?" 'pr-interface-help))
6001 (defmacro pr-interface-save (&rest body)
6002 `(save-excursion
6003 (set-buffer pr-i-buffer)
6004 ,@body))
6007 (defun pr-create-interface ()
6008 "Create the front end for printing package."
6009 (setq pr-i-buffer (buffer-name (current-buffer))
6010 pr-i-region (ps-mark-active-p)
6011 pr-i-mode (pr-mode-alist-p)
6012 pr-i-window-configuration (current-window-configuration))
6014 (put 'pr-i-process 'pr-widget-list nil)
6015 (put 'pr-i-ps-send 'pr-widget-list nil)
6017 (delete-other-windows)
6018 (kill-buffer (get-buffer-create pr-buffer-name))
6019 (switch-to-buffer (get-buffer-create pr-buffer-name))
6021 ;; header
6022 (let ((versions (concat "printing v" pr-version
6023 " ps-print v" ps-print-version)))
6024 ;; to keep compatibility with Emacs 20 & 21:
6025 ;; DO NOT REPLACE `?\ ' BY `?\s'
6026 (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
6027 (pr-insert-italic "\nCurrent Directory : " 1)
6028 (pr-insert-italic default-directory)
6030 (pr-insert-section-1) ; 1. Print
6031 (pr-insert-section-2) ; 2. PostScript Printer
6032 (pr-insert-section-3) ; 3. Text Printer
6034 ;; separator
6035 (widget-insert "\n\n " (make-string 77 ?-))
6037 (pr-insert-section-4) ; 4. Settings
6038 (pr-insert-section-5) ; 5. Customize
6039 (pr-insert-section-6) ; 6. Show Settings
6040 (pr-insert-section-7) ; 7. Help
6042 (use-local-map pr-interface-map)
6043 (widget-setup)
6044 (goto-char (point-min))
6046 (and pr-i-region ; let region activated
6047 (pr-keep-region-active)))
6050 (defun pr-insert-section-1 ()
6051 ;; 1. Print:
6052 (pr-insert-italic "\nPrint :" 1)
6054 ;; 1a. Buffer:
6055 ;; 1a. Buffer: Buffer List
6056 (pr-insert-radio-button 'pr-i-process 'buffer)
6057 (pr-insert-menu "Buffer List" 'pr-i-buffer
6058 (let ((blist (buffer-list))
6059 case-fold-search choices)
6060 (while blist
6061 (let ((name (buffer-name (car blist)))
6062 (ignore pr-buffer-name-ignore)
6063 found)
6064 (setq blist (cdr blist))
6065 (while (and ignore (not found))
6066 (setq found (string-match (car ignore) name)
6067 ignore (cdr ignore)))
6068 (or found
6069 (setq choices
6070 (cons (list 'quote
6071 (list 'choice-item
6072 :format "%[%t%]"
6073 name))
6074 choices)))))
6075 (nreverse choices))
6076 " Buffer : " nil
6077 '(progn
6078 (pr-interface-save
6079 (setq pr-i-region (ps-mark-active-p)
6080 pr-i-mode (pr-mode-alist-p)))
6081 (pr-update-checkbox 'pr-i-region)
6082 (pr-update-checkbox 'pr-i-mode)))
6083 ;; 1a. Buffer: Region
6084 (put 'pr-i-region 'pr-widget
6085 (pr-insert-checkbox
6086 "\n "
6087 'pr-i-region
6088 #'(lambda (widget &rest ignore)
6089 (let ((region-p (pr-interface-save
6090 (ps-mark-active-p))))
6091 (cond ((null (widget-value widget)) ; widget is nil
6092 (setq pr-i-region nil))
6093 (region-p ; widget is true and there is a region
6094 (setq pr-i-region t)
6095 (widget-value-set widget t)
6096 (widget-setup)) ; MUST be called after widget-value-set
6097 (t ; widget is true and there is no region
6098 (ding)
6099 (message "There is no region active")
6100 (setq pr-i-region nil)
6101 (widget-value-set widget nil)
6102 (widget-setup))))) ; MUST be called after widget-value-set
6103 " Region"))
6104 ;; 1a. Buffer: Mode
6105 (put 'pr-i-mode 'pr-widget
6106 (pr-insert-checkbox
6108 'pr-i-mode
6109 #'(lambda (widget &rest ignore)
6110 (let ((mode-p (pr-interface-save
6111 (pr-mode-alist-p))))
6112 (cond
6113 ((null (widget-value widget)) ; widget is nil
6114 (setq pr-i-mode nil))
6115 (mode-p ; widget is true and there is a `mode'
6116 (setq pr-i-mode t)
6117 (widget-value-set widget t)
6118 (widget-setup)) ; MUST be called after widget-value-set
6119 (t ; widget is true and there is no `mode'
6120 (ding)
6121 (message
6122 "This buffer isn't in a mode that printing treats specially.")
6123 (setq pr-i-mode nil)
6124 (widget-value-set widget nil)
6125 (widget-setup))))) ; MUST be called after widget-value-set
6126 " Mode\n"))
6128 ;; 1b. Directory:
6129 (pr-insert-radio-button 'pr-i-process 'directory)
6130 (widget-create
6131 'directory
6132 :size 58
6133 :format " Directory : %v"
6134 :notify 'pr-interface-directory
6135 :action (lambda (widget &optional event)
6136 (if (pr-interface-directory widget)
6137 (pr-widget-field-action widget event)
6138 (ding)
6139 (message "Please specify a readable directory")))
6140 pr-i-directory)
6141 ;; 1b. Directory: File Regexp
6142 (widget-create 'regexp
6143 :size 58
6144 :format "\n File Regexp : %v\n"
6145 :notify (lambda (widget &rest ignore)
6146 (setq pr-i-regexp (widget-value widget)))
6147 pr-i-regexp)
6148 ;; 1b. Directory: List Directory Entry
6149 (widget-insert " ")
6150 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
6152 ;; 1c. PostScript File:
6153 (pr-insert-radio-button 'pr-i-process 'file)
6154 (widget-create
6155 'file
6156 :size 51
6157 :format " PostScript File : %v"
6158 :notify 'pr-interface-infile
6159 :action (lambda (widget &rest event)
6160 (if (pr-interface-infile widget)
6161 (pr-widget-field-action widget event)
6162 (ding)
6163 (message "Please specify a readable PostScript file")))
6164 pr-i-ps-file)
6165 ;; 1c. PostScript File: PostScript Utility
6166 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
6167 (pr-choice-alist pr-ps-utility-alist)
6168 "\n PostScript Utility : "
6169 " ")
6170 ;; 1c. PostScript File: No Preprocessing
6171 (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
6174 (defun pr-insert-section-2 ()
6175 ;; 2. PostScript Printer:
6176 ;; 2. PostScript Printer: PostScript Printer List
6177 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
6178 (pr-insert-menu "PostScript Printer" 'pr-ps-name
6179 (pr-choice-alist pr-ps-printer-alist))
6180 ;; 2. PostScript Printer: Despool
6181 (put 'pr-i-despool 'pr-widget
6182 (pr-insert-checkbox
6184 'pr-i-despool
6185 #'(lambda (widget &rest ignore)
6186 (if pr-spool-p
6187 (setq pr-i-despool (not pr-i-despool))
6188 (ding)
6189 (message "Can despool only when spooling is actually selected")
6190 (setq pr-i-despool nil))
6191 (widget-value-set widget pr-i-despool)
6192 (widget-setup)) ; MUST be called after widget-value-set
6193 " Despool "))
6194 ;; 2. PostScript Printer: Preview Print Quit
6195 (pr-insert-button 'pr-interface-preview "Preview" " ")
6196 (pr-insert-button 'pr-interface-ps-print "Print" " ")
6197 (pr-insert-button 'pr-interface-quit "Quit")
6198 ;; 2. PostScript Printer: Send to Printer/Temporary File
6199 (pr-insert-radio-button 'pr-i-ps-send 'printer)
6200 (widget-insert " Send to Printer/Temporary File")
6201 ;; 2. PostScript Printer: Send to File
6202 (pr-insert-radio-button 'pr-i-ps-send 'file)
6203 (widget-create
6204 'file
6205 :size 57
6206 :format " Send to File : %v"
6207 :notify 'pr-interface-outfile
6208 :action (lambda (widget &rest event)
6209 (if (and (pr-interface-outfile widget)
6210 (or (not (file-exists-p pr-i-out-file))
6211 (setq pr-i-answer-yes
6212 (y-or-n-p "File exists; overwrite? "))))
6213 (pr-widget-field-action widget event)
6214 (ding)
6215 (message "Please specify a writable PostScript file")))
6216 pr-i-out-file)
6217 ;; 2. PostScript Printer: N-Up
6218 (widget-create
6219 'integer
6220 :size 3
6221 :format "\n N-Up : %v"
6222 :notify (lambda (widget &rest ignore)
6223 (let ((value (if (string= (widget-apply widget :value-get) "")
6225 (widget-value widget))))
6226 (if (and (integerp value)
6227 (<= 1 value) (<= value 100))
6228 (progn
6229 (message " ")
6230 (setq pr-i-n-up value))
6231 (ding)
6232 (message "Please specify an integer between 1 and 100"))))
6233 pr-i-n-up))
6236 (defun pr-insert-section-3 ()
6237 ;; 3. Text Printer:
6238 (pr-insert-italic "\n\nText Printer : " 2 14)
6239 (pr-insert-menu "Text Printer" 'pr-txt-name
6240 (pr-choice-alist pr-txt-printer-alist)
6241 nil " ")
6242 (pr-insert-button 'pr-interface-printify "Printify" " ")
6243 (pr-insert-button 'pr-interface-txt-print "Print" " ")
6244 (pr-insert-button 'pr-interface-quit "Quit"))
6247 (defun pr-insert-section-4 ()
6248 ;; 4. Settings:
6249 ;; 4. Settings: Landscape Auto Region Verbose
6250 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
6251 #'(lambda (&rest ignore)
6252 (setq ps-landscape-mode (not ps-landscape-mode)
6253 pr-file-landscape ps-landscape-mode))
6254 " Landscape ")
6255 (pr-insert-toggle 'pr-auto-region " Auto Region ")
6256 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
6258 ;; 4. Settings: Print Header Auto Mode
6259 (pr-insert-toggle 'ps-print-header " Print Header ")
6260 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
6262 ;; 4. Settings: Print Header Frame Menu Lock
6263 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
6264 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
6266 ;; 4. Settings: Line Number
6267 (pr-insert-toggle 'ps-line-number " Line Number\n ")
6269 ;; 4. Settings: Zebra Stripes Spool Buffer
6270 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
6271 (pr-insert-checkbox " "
6272 'pr-spool-p
6273 #'(lambda (&rest ignore)
6274 (setq pr-spool-p (not pr-spool-p))
6275 (unless pr-spool-p
6276 (setq pr-i-despool nil)
6277 (pr-update-checkbox 'pr-i-despool)))
6278 " Spool Buffer")
6280 ;; 4. Settings: Duplex Print with faces
6281 (pr-insert-checkbox "\n "
6282 'ps-spool-duplex
6283 #'(lambda (&rest ignore)
6284 (setq ps-spool-duplex (not ps-spool-duplex)
6285 pr-file-duplex ps-spool-duplex))
6286 " Duplex ")
6287 (pr-insert-toggle 'pr-faces-p " Print with faces")
6289 ;; 4. Settings: Tumble Print via Ghostscript
6290 (pr-insert-checkbox "\n "
6291 'ps-spool-tumble
6292 #'(lambda (&rest ignore)
6293 (setq ps-spool-tumble (not ps-spool-tumble)
6294 pr-file-tumble ps-spool-tumble))
6295 " Tumble ")
6296 (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
6298 ;; 4. Settings: Upside-Down Page Parity
6299 (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
6300 (pr-insert-italic "\n\nSelect Pages : " 2 14)
6301 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
6302 (mapcar #'(lambda (alist)
6303 (list 'quote
6304 (list 'choice-item
6305 :format "%[%t%]"
6306 :tag (cdr alist)
6307 :value (car alist))))
6308 pr-even-or-odd-alist)))
6311 (defun pr-insert-section-5 ()
6312 ;; 5. Customize:
6313 (pr-insert-italic "\n\nCustomize : " 2 11)
6314 (pr-insert-button 'pr-customize "printing" " ")
6315 (pr-insert-button #'(lambda (&rest ignore) (ps-print-customize))
6316 "ps-print" " ")
6317 (pr-insert-button 'lpr-customize "lpr"))
6320 (defun pr-insert-section-6 ()
6321 ;; 6. Show Settings:
6322 (pr-insert-italic "\nShow Settings : " 1 14)
6323 (pr-insert-button 'pr-show-pr-setup "printing" " ")
6324 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
6325 (pr-insert-button 'pr-show-lpr-setup "lpr"))
6328 (defun pr-insert-section-7 ()
6329 ;; 7. Help:
6330 (pr-insert-italic "\nHelp : " 1 5)
6331 (pr-insert-button 'pr-interface-help "Interface Help" " ")
6332 (pr-insert-button 'pr-help "Menu Help" " ")
6333 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
6334 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
6337 (defun pr-kill-help (&rest ignore)
6338 "Kill all printing help buffer."
6339 (interactive)
6340 (let ((help '("*Printing Interface Help*" "*Printing Help*"
6341 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
6342 (while help
6343 (let ((buffer (get-buffer (car help))))
6344 (setq help (cdr help))
6345 (when buffer
6346 (delete-windows-on buffer)
6347 (kill-buffer buffer)))))
6348 (recenter (- (window-height) 2)))
6351 (defun pr-interface-quit (&rest ignore)
6352 "Kill the printing buffer interface and quit."
6353 (interactive)
6354 (kill-buffer pr-buffer-name)
6355 (set-window-configuration pr-i-window-configuration))
6358 (defun pr-interface-help (&rest ignore)
6359 "printing buffer interface help."
6360 (interactive)
6361 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
6364 (defun pr-interface-txt-print (&rest ignore)
6365 "Print using lpr package."
6366 (interactive)
6367 (condition-case data
6368 (cond
6369 ((eq pr-i-process 'directory)
6370 (pr-i-directory)
6371 (pr-interface-save
6372 (pr-txt-directory pr-i-directory pr-i-regexp)))
6373 ((eq pr-i-process 'buffer)
6374 (pr-interface-save
6375 (cond (pr-i-region
6376 (let ((pr-auto-mode pr-i-mode))
6377 (pr-txt-region)))
6378 (pr-i-mode
6379 (let (pr-auto-region)
6380 (pr-txt-mode)))
6382 (let (pr-auto-mode pr-auto-region)
6383 (pr-txt-buffer)))
6385 ((eq pr-i-process 'file)
6386 (error "Please specify a text file"))
6388 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6390 ;; handlers
6391 ((quit error)
6392 (ding)
6393 (message "%s" (error-message-string data)))))
6396 (defun pr-interface-printify (&rest ignore)
6397 "Printify a buffer."
6398 (interactive)
6399 (condition-case data
6400 (cond
6401 ((eq pr-i-process 'directory)
6402 (pr-i-directory)
6403 (pr-interface-save
6404 (pr-printify-directory pr-i-directory pr-i-regexp)))
6405 ((eq pr-i-process 'buffer)
6406 (pr-interface-save
6407 (if pr-i-region
6408 (pr-printify-region)
6409 (pr-printify-buffer))))
6410 ((eq pr-i-process 'file)
6411 (error "Cannot printify a PostScript file"))
6413 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6415 ;; handlers
6416 ((quit error)
6417 (ding)
6418 (message "%s" (error-message-string data)))))
6421 (defun pr-interface-ps-print (&rest ignore)
6422 "Print using ps-print package."
6423 (interactive)
6424 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6425 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6426 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6427 'pr-ps-buffer-ps-print))
6430 (defun pr-interface-preview (&rest ignore)
6431 "Preview a PostScript file."
6432 (interactive)
6433 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6434 'pr-ps-file-preview 'pr-ps-file-up-preview
6435 'pr-ps-region-preview 'pr-ps-mode-preview
6436 'pr-ps-buffer-preview))
6439 (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6440 ps-mode ps-buffer)
6441 (condition-case data
6442 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6443 (pr-i-ps-send))))
6444 (cond
6445 ((and pr-i-despool pr-spool-p)
6446 (pr-interface-save
6447 (funcall ps-despool outfile))
6448 (setq pr-i-despool nil)
6449 (pr-update-checkbox 'pr-i-despool))
6450 ((eq pr-i-process 'directory)
6451 (pr-i-directory)
6452 (pr-interface-save
6453 (funcall ps-directory
6454 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6455 ((eq pr-i-process 'file)
6456 (cond ((or (file-directory-p pr-i-ps-file)
6457 (not (file-readable-p pr-i-ps-file)))
6458 (error "Please specify a readable PostScript file"))
6459 (pr-i-ps-as-is
6460 (pr-interface-save
6461 (funcall ps-file pr-i-ps-file)))
6463 (pr-interface-save
6464 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6466 ((eq pr-i-process 'buffer)
6467 (pr-interface-save
6468 (cond (pr-i-region
6469 (let ((pr-auto-mode pr-i-mode))
6470 (funcall ps-region pr-i-n-up outfile)))
6471 (pr-i-mode
6472 (let (pr-auto-region)
6473 (funcall ps-mode pr-i-n-up outfile)))
6475 (let (pr-auto-mode pr-auto-region)
6476 (funcall ps-buffer pr-i-n-up outfile)))
6479 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6481 ;; handlers
6482 ((quit error)
6483 (ding)
6484 (message "%s" (error-message-string data)))))
6487 (defun pr-i-ps-send ()
6488 (cond ((eq pr-i-ps-send 'printer)
6489 nil)
6490 ((not (eq pr-i-ps-send 'file))
6491 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6492 ((or (file-directory-p pr-i-out-file)
6493 (not (file-writable-p pr-i-out-file)))
6494 (error "Please specify a writable PostScript file"))
6495 ((or (not (file-exists-p pr-i-out-file))
6496 pr-i-answer-yes
6497 (setq pr-i-answer-yes
6498 (y-or-n-p (format "File `%s' exists; overwrite? "
6499 pr-i-out-file))))
6500 pr-i-out-file)
6502 (error "File already exists"))))
6505 (defun pr-i-directory ()
6506 (or (and (file-directory-p pr-i-directory)
6507 (file-readable-p pr-i-directory))
6508 (error "Please specify be a readable directory")))
6511 (defun pr-interface-directory (widget &rest ignore)
6512 (and pr-buffer-verbose
6513 (message "You can use M-TAB or ESC TAB for file completion"))
6514 (let ((dir (widget-value widget)))
6515 (and (file-directory-p dir)
6516 (file-readable-p dir)
6517 (setq pr-i-directory dir))))
6520 (defun pr-interface-infile (widget &rest ignore)
6521 (and pr-buffer-verbose
6522 (message "You can use M-TAB or ESC TAB for file completion"))
6523 (let ((file (widget-value widget)))
6524 (and (not (file-directory-p file))
6525 (file-readable-p file)
6526 (setq pr-i-ps-file file))))
6529 (defun pr-interface-outfile (widget &rest ignore)
6530 (setq pr-i-answer-yes nil)
6531 (and pr-buffer-verbose
6532 (message "You can use M-TAB or ESC TAB for file completion"))
6533 (let ((file (widget-value widget)))
6534 (and (not (file-directory-p file))
6535 (file-writable-p file)
6536 (setq pr-i-out-file file))))
6539 (defun pr-widget-field-action (widget event)
6540 (and (get-buffer "*Completions*") ; clean frame window
6541 (delete-windows-on "*Completions*"))
6542 (message " ") ; clean echo area
6543 (widget-field-action widget event))
6546 (defun pr-insert-italic (str &optional from to)
6547 (let ((len (length str)))
6548 (put-text-property (if from (max from 0) 0)
6549 (if to (max to len) len)
6550 'face 'italic str)
6551 (widget-insert str)))
6554 (defun pr-insert-checkbox (before var-sym fun label)
6555 (widget-insert before)
6556 (prog1
6557 (widget-create 'checkbox
6558 :notify fun
6559 (symbol-value var-sym))
6560 (widget-insert label)))
6563 (defun pr-insert-toggle (var-sym label)
6564 (widget-create 'checkbox
6565 :notify `(lambda (&rest ignore)
6566 (setq ,var-sym (not ,var-sym)))
6567 (symbol-value var-sym))
6568 (widget-insert label))
6571 (defun pr-insert-button (fun label &optional separator)
6572 (widget-create 'push-button
6573 :notify fun
6574 label)
6575 (and separator
6576 (widget-insert separator)))
6579 (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6580 (and before (widget-insert before))
6581 (eval `(widget-create 'menu-choice
6582 :tag ,tag
6583 :format "%v"
6584 :inline t
6585 :value ,var-sym
6586 :notify (lambda (widget &rest ignore)
6587 (setq ,var-sym (widget-value widget))
6588 ,@body)
6589 :void '(choice-item :format "%[%t%]"
6590 :tag "Can not display value!")
6591 ,@choices))
6592 (and after (widget-insert after)))
6595 (defun pr-insert-radio-button (var-sym sym)
6596 (widget-insert "\n")
6597 (let ((wid-list (get var-sym 'pr-widget-list))
6598 (wid (eval `(widget-create
6599 'radio-button
6600 :format " %[%v%]"
6601 :value (eq ,var-sym (quote ,sym))
6602 :notify (lambda (&rest ignore)
6603 (setq ,var-sym (quote ,sym))
6604 (pr-update-radio-button (quote ,var-sym)))))))
6605 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6608 (defun pr-update-radio-button (var-sym)
6609 (let ((wid-list (get var-sym 'pr-widget-list)))
6610 (while wid-list
6611 (let ((wid (car (car wid-list)))
6612 (value (cdr (car wid-list))))
6613 (setq wid-list (cdr wid-list))
6614 (widget-value-set wid (eq (symbol-value var-sym) value))))
6615 (widget-setup)))
6618 (defun pr-update-checkbox (var-sym)
6619 (let ((wid (get var-sym 'pr-widget)))
6620 (when wid
6621 (widget-value-set wid (symbol-value var-sym))
6622 (widget-setup))))
6625 (defun pr-choice-alist (alist)
6626 (let ((max (apply 'max (mapcar #'(lambda (alist)
6627 (length (symbol-name (car alist))))
6628 alist))))
6629 (mapcar #'(lambda (alist)
6630 (let* ((sym (car alist))
6631 (name (symbol-name sym)))
6632 (list
6633 'quote
6634 (list
6635 'choice-item
6636 :format "%[%t%]"
6637 :tag (concat name
6638 (make-string (- max (length name)) ?_))
6639 :value sym))))
6640 alist)))
6643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6646 (provide 'printing)
6649 ;; arch-tag: 9ce9ac3f-0f60-4370-900b-1943215d9d18
6650 ;;; printing.el ends here