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