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