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