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