Move lisp/emacs-lisp/authors.el to admin/
[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 3173(defmacro pr-save-file-modes (&rest body)
d63d883a
GM
3174 "Execute BODY with file permissions temporarily set to `pr-file-modes'."
3175 (declare (obsolete with-file-modes "24.5"))
3176 `(with-file-modes pr-file-modes ,@body))
6367b616 3177
2c840b90
KS
3178;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3179;; Keys & Menus
3180
3181
2c840b90
KS
3182(defsubst pr-visible-p (key)
3183 (memq key pr-visible-entry-list))
3184
3185
3186(defsubst pr-mode-alist-p ()
3187 (cdr (assq major-mode pr-mode-alist)))
3188
3189
3190(defsubst pr-auto-mode-p ()
3191 (and pr-auto-mode (pr-mode-alist-p)))
3192
3193
3194(defsubst pr-using-ghostscript-p ()
3195 (and pr-print-using-ghostscript (not pr-spool-p)))
3196
3197
bead134f 3198(defalias 'pr-get-symbol
f0036ec2
GM
3199 (if (featurep 'emacs) 'easy-menu-intern ; since 22.1
3200 (if (fboundp 'easy-menu-intern) ; hacked from easymenu.el
3201 'easy-menu-intern
3202 (lambda (s) (if (stringp s) (intern s) s)))))
9f7a9918 3203
9f7a9918
VJL
3204
3205(defconst pr-menu-spec
3206 ;; Menu mapping:
3207 ;; unfortunately XEmacs doesn't support :active for submenus,
3208 ;; only for items.
3209 ;; So, it uses :included instead of :active.
3210 ;; Also, XEmacs doesn't support :help tag.
3211 (let ((pr-:active (if (featurep 'xemacs)
3212 :included ; XEmacs
3213 :active)) ; GNU Emacs
3214 (pr-:help (if (featurep 'xemacs)
3215 'ignore ; XEmacs
3216 #'(lambda (text) (list :help text))))) ; GNU Emacs
3217 `(
3218 ["Printing Interface" pr-interface
3219 ,@(funcall
3220 pr-:help "Use buffer interface instead of menu interface")]
3221 "--"
3222 ("PostScript Preview" :included (pr-visible-p 'postscript)
3223 ,@(funcall
3224 pr-:help "Preview PostScript instead of sending to printer")
3225 ("Directory" ,pr-:active (not pr-spool-p)
3226 ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
3227 ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
3228 ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
3229 ["Other..." (pr-ps-directory-preview nil nil nil t)
3230 :keys "\\[pr-ps-buffer-preview]"])
3231 ("Buffer" ,pr-:active (not pr-spool-p)
3232 ["1-up" (pr-ps-buffer-preview 1 t) t]
3233 ["2-up" (pr-ps-buffer-preview 2 t) t]
3234 ["4-up" (pr-ps-buffer-preview 4 t) t]
3235 ["Other..." (pr-ps-buffer-preview nil t)
3236 :keys "\\[pr-ps-buffer-preview]"])
3237 ("Region" ,pr-:active (and (not pr-spool-p) (ps-mark-active-p))
3238 ["1-up" (pr-ps-region-preview 1 t) t]
3239 ["2-up" (pr-ps-region-preview 2 t) t]
3240 ["4-up" (pr-ps-region-preview 4 t) t]
3241 ["Other..." (pr-ps-region-preview nil t)
3242 :keys "\\[pr-ps-region-preview]"])
3243 ("Mode" ,pr-:active (and (not pr-spool-p) (pr-mode-alist-p))
3244 ["1-up" (pr-ps-mode-preview 1 t) t]
3245 ["2-up" (pr-ps-mode-preview 2 t) t]
3246 ["4-up" (pr-ps-mode-preview 4 t) t]
3247 ["Other..." (pr-ps-mode-preview nil t)
3248 :keys "\\[pr-ps-mode-preview]"])
3249 ("File"
3250 ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
3251 :keys "\\[pr-ps-file-preview]"
bf490c7b 3252 ,@(funcall
9f7a9918 3253 pr-:help "Preview PostScript file")]
2c840b90 3254 "--"
9f7a9918 3255 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
bf490c7b 3256 ,@(funcall
9f7a9918
VJL
3257 pr-:help "Select PostScript utility")]
3258 "--"
3259 ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
3260 ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
3261 ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
3262 ["Other..." (pr-ps-file-up-preview nil t t)
3263 :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
2c840b90 3264 "--"
9f7a9918
VJL
3265 ["Landscape" pr-toggle-file-landscape-menu
3266 :style toggle :selected pr-file-landscape
bf490c7b 3267 ,@(funcall
9f7a9918
VJL
3268 pr-:help "Toggle landscape for PostScript file")
3269 :active pr-ps-utility-alist]
3270 ["Duplex" pr-toggle-file-duplex-menu
3271 :style toggle :selected pr-file-duplex
bf490c7b 3272 ,@(funcall
9f7a9918
VJL
3273 pr-:help "Toggle duplex for PostScript file")
3274 :active pr-ps-utility-alist]
3275 ["Tumble" pr-toggle-file-tumble-menu
3276 :style toggle :selected pr-file-tumble
bf490c7b 3277 ,@(funcall
9f7a9918
VJL
3278 pr-:help "Toggle tumble for PostScript file")
3279 :active (and pr-file-duplex pr-ps-utility-alist)])
3280 ["Despool..." (call-interactively 'pr-despool-preview)
3281 :active pr-spool-p :keys "\\[pr-despool-preview]"
3282 ,@(funcall
3283 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3284 ("PostScript Print" :included (pr-visible-p 'postscript)
3285 ,@(funcall
3286 pr-:help "Send PostScript to printer or file (C-u)")
3287 ("Directory"
3288 ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
3289 ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
3290 ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
3291 ["Other..." (pr-ps-directory-ps-print nil nil nil t)
3292 :keys "\\[pr-ps-buffer-ps-print]"])
3293 ("Buffer"
3294 ["1-up" (pr-ps-buffer-ps-print 1 t) t]
3295 ["2-up" (pr-ps-buffer-ps-print 2 t) t]
3296 ["4-up" (pr-ps-buffer-ps-print 4 t) t]
3297 ["Other..." (pr-ps-buffer-ps-print nil t)
3298 :keys "\\[pr-ps-buffer-ps-print]"])
3299 ("Region" ,pr-:active (ps-mark-active-p)
3300 ["1-up" (pr-ps-region-ps-print 1 t) t]
3301 ["2-up" (pr-ps-region-ps-print 2 t) t]
3302 ["4-up" (pr-ps-region-ps-print 4 t) t]
3303 ["Other..." (pr-ps-region-ps-print nil t)
3304 :keys "\\[pr-ps-region-ps-print]"])
3305 ("Mode" ,pr-:active (pr-mode-alist-p)
3306 ["1-up" (pr-ps-mode-ps-print 1 t) t]
3307 ["2-up" (pr-ps-mode-ps-print 2 t) t]
3308 ["4-up" (pr-ps-mode-ps-print 4 t) t]
3309 ["Other..." (pr-ps-mode-ps-print nil t)
3310 :keys "\\[pr-ps-mode-ps-print]"])
3311 ("File"
3312 ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
3313 :keys "\\[pr-ps-file-ps-print]"
3314 ,@(funcall
3315 pr-:help "Send PostScript file to printer")]
2c840b90 3316 "--"
9f7a9918 3317 ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
bf490c7b 3318 ,@(funcall
9f7a9918
VJL
3319 pr-:help "Select PostScript utility")]
3320 "--"
3321 ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
3322 ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
3323 ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
3324 ["Other..." (pr-ps-file-up-ps-print nil t t)
3325 :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
2c840b90 3326 "--"
9f7a9918
VJL
3327 ["Landscape" pr-toggle-file-landscape-menu
3328 :style toggle :selected pr-file-landscape
bf490c7b 3329 ,@(funcall
9f7a9918
VJL
3330 pr-:help "Toggle landscape for PostScript file")
3331 :active pr-ps-utility-alist]
3332 ["Duplex" pr-toggle-file-duplex-menu
3333 :style toggle :selected pr-file-duplex
bf490c7b 3334 ,@(funcall
9f7a9918
VJL
3335 pr-:help "Toggle duplex for PostScript file")
3336 :active pr-ps-utility-alist]
3337 ["Tumble" pr-toggle-file-tumble-menu
3338 :style toggle :selected pr-file-tumble
bf490c7b 3339 ,@(funcall
9f7a9918
VJL
3340 pr-:help "Toggle tumble for PostScript file")
3341 :active (and pr-file-duplex pr-ps-utility-alist)])
3342 ["Despool..." (call-interactively 'pr-despool-ps-print)
3343 :active pr-spool-p :keys "\\[pr-despool-ps-print]"
3344 ,@(funcall
3345 pr-:help "Despool PostScript buffer to printer or file (C-u)")])
3346 ["PostScript Printers" pr-update-menus
3347 :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
3348 ,@(funcall
3349 pr-:help "Select PostScript printer")]
3350 "--"
3351 ("Printify" :included (pr-visible-p 'text)
3352 ,@(funcall
3353 pr-:help
3354 "Replace non-printing chars with printable representations.")
3355 ["Directory" pr-printify-directory t]
3356 ["Buffer" pr-printify-buffer t]
3357 ["Region" pr-printify-region (ps-mark-active-p)])
3358 ("Print" :included (pr-visible-p 'text)
3359 ,@(funcall
3360 pr-:help "Send text to printer")
3361 ["Directory" pr-txt-directory t]
3362 ["Buffer" pr-txt-buffer t]
3363 ["Region" pr-txt-region (ps-mark-active-p)]
3364 ["Mode" pr-txt-mode (pr-mode-alist-p)])
3365 ["Text Printers" pr-update-menus
3366 :active pr-txt-printer-alist :included (pr-visible-p 'text)
3367 ,@(funcall
3368 pr-:help "Select text printer")]
3369 "--"
3370 ["Landscape" pr-toggle-landscape-menu
3371 :style toggle :selected ps-landscape-mode
3372 :included (pr-visible-p 'postscript-options)]
3373 ["Print Header" pr-toggle-header-menu
3374 :style toggle :selected ps-print-header
3375 :included (pr-visible-p 'postscript-options)]
3376 ["Print Header Frame" pr-toggle-header-frame-menu
3377 :style toggle :selected ps-print-header-frame :active ps-print-header
3378 :included (pr-visible-p 'postscript-options)]
3379 ["Line Number" pr-toggle-line-menu
3380 :style toggle :selected ps-line-number
3381 :included (pr-visible-p 'postscript-options)]
3382 ["Zebra Stripes" pr-toggle-zebra-menu
3383 :style toggle :selected ps-zebra-stripes
3384 :included (pr-visible-p 'postscript-options)]
3385 ["Duplex" pr-toggle-duplex-menu
3386 :style toggle :selected ps-spool-duplex
3387 :included (pr-visible-p 'postscript-options)]
3388 ["Tumble" pr-toggle-tumble-menu
3389 :style toggle :selected ps-spool-tumble :active ps-spool-duplex
3390 :included (pr-visible-p 'postscript-options)]
3391 ["Upside-Down" pr-toggle-upside-down-menu
3392 :style toggle :selected ps-print-upside-down
3393 :included (pr-visible-p 'postscript-options)]
3394 ("Print All Pages" :included (pr-visible-p 'postscript-options)
3395 ,@(funcall
3396 pr-:help "Select odd/even pages/sheets to print")
3397 ["All Pages" (pr-even-or-odd-pages nil)
3398 :style radio :selected (eq ps-even-or-odd-pages nil)]
3399 ["Even Pages" (pr-even-or-odd-pages 'even-page)
3400 :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
3401 ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
3402 :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
3403 ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
3404 :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
3405 ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
3406 :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
3407 "--"
3408 ["Spool Buffer" pr-toggle-spool-menu
3409 :style toggle :selected pr-spool-p
3410 :included (pr-visible-p 'postscript-process)
3411 ,@(funcall
3412 pr-:help "Toggle PostScript spooling")]
3413 ["Print with faces" pr-toggle-faces-menu
3414 :style toggle :selected pr-faces-p
3415 :included (pr-visible-p 'postscript-process)
3416 ,@(funcall
3417 pr-:help "Toggle PostScript printing with faces")]
3418 ["Print via Ghostscript" pr-toggle-ghostscript-menu
3419 :style toggle :selected pr-print-using-ghostscript
3420 :included (pr-visible-p 'postscript-process)
3421 ,@(funcall
3422 pr-:help "Toggle PostScript generation using ghostscript")]
3423 "--"
3424 ["Auto Region" pr-toggle-region-menu
3425 :style toggle :selected pr-auto-region
3426 :included (pr-visible-p 'printing)]
3427 ["Auto Mode" pr-toggle-mode-menu
3428 :style toggle :selected pr-auto-mode
3429 :included (pr-visible-p 'printing)]
3430 ["Menu Lock" pr-toggle-lock-menu
3431 :style toggle :selected pr-menu-lock
3432 :included (pr-visible-p 'printing)]
3433 "--"
3434 ("Customize" :included (pr-visible-p 'help)
3435 ["printing" pr-customize t]
3436 ["ps-print" ps-print-customize t]
3437 ["lpr" lpr-customize t])
3438 ("Show Settings" :included (pr-visible-p 'help)
3439 ["printing" pr-show-pr-setup t]
3440 ["ps-print" pr-show-ps-setup t]
3441 ["lpr" pr-show-lpr-setup t])
3442 ["Help" pr-help :active t :included (pr-visible-p 'help)]
3443 )))
3444
3445
b2c9cbd3
VJL
3446(defun pr-menu-bind ()
3447 "Install `printing' menu in the menubar.
aa514451 3448This replaces the File/Print* menu entries with a File/Print sub-menu.
b2c9cbd3
VJL
3449Calls `pr-update-menus' to adjust menus."
3450 (interactive)
bafb1102 3451 (pr-global-menubar pr-menu-spec)
b2c9cbd3 3452 (pr-update-menus t))
6367b616
VJL
3453
3454
9f7a9918
VJL
3455;; Key binding
3456(let ((pr-print-key (if (featurep 'xemacs)
3457 'f22 ; XEmacs
3458 'print))) ; GNU Emacs
3459 (global-set-key `[,pr-print-key] 'pr-ps-fast-fire)
3460 ;; Well, M-print and S-print are used because in my keyboard S-print works
3461 ;; and M-print doesn't. But M-print can work in other keyboard.
3462 (global-set-key `[(meta ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3463 (global-set-key `[(shift ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
3464 ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
3465 ;; and C-print doesn't. But C-print can work in other keyboard.
3466 (global-set-key `[(control ,pr-print-key)] 'pr-txt-fast-fire)
3467 (global-set-key `[(control meta ,pr-print-key)] 'pr-txt-fast-fire))
2c840b90
KS
3468
3469
3470;;; You can also use something like:
3471;;;(global-set-key "\C-ci" 'pr-interface)
3472;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
3473;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
3474;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
3475;;;(global-set-key "\C-crp" 'pr-ps-region-print)
3476;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
3477;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
3478
3479
3480;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3481;; Help Message
3482
3483
3484(defconst pr-help-message
3485 (concat "printing.el version " pr-version
3486 " ps-print.el version " ps-print-version
3487 "\n\n
3488Menu Layout
3489-----------
3490
3491The `printing' menu (Tools/Printing or File/Print) has the following layout:
3492
3493 +-----------------------------+
3494A 0 | Printing Interface |
3495 +-----------------------------+ +-A---------+ +-B------+
3496I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
3497 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
3498 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
3499 +-----------------------------+ |Mode >|-- B |Other...|
3500II 4 | Printify >|-----\\ |File >|--\\ +--------+
3501 5 | Print >|---\\ | |Despool... | |
3502 6 | Text Printer: name >|-\\ | | +-----------+ |
3503 +-----------------------------+ | | | +---------+ +------------+
b8d955f4 3504III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
2c840b90
KS
3505 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
3506 9 |[ ]Print Header Frame | | | |Region | | name >|- C
3507 10 |[ ]Line Number | | | +---------+ +------------+
3508 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
3509 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
3510 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
3511 14 |[ ]Upside-Down | | |Region | | Other... |
3512 15 | Print All Pages >|--\\ | |Mode | +------------+
3513 +-----------------------------+ | | +---------+ |[ ]Landscape| Id
3514IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
449cba44
VJL
3515 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
3516 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
2c840b90
KS
3517 +-----------------------------+ | |... |
3518V 19 |[ ]Auto Region | | |(*)name |
3519 20 |[ ]Auto Mode | | |... |
3520 21 |[ ]Menu Lock | | +---------+ +--------------+
3521 +-----------------------------+ \\------------------|(*)All Pages |
3522VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
3523 23 | Show Settings >|-------|printing| |( )Odd Pages |
3524 24 | Help | |ps-print| |( )Even Sheets|
3525 +-----------------------------+ |lpr | |( )Odd Sheets |
3526 +--------+ +--------------+
3527
3528See `pr-visible-entry-list' for hiding some parts of the menu.
3529
3530The menu has the following sections:
3531
3532A. Interface:
3533
3534 0. You can use a buffer interface instead of menus. It looks like the
3535 customization buffer. Basically, it has the same options found in the
3536 menu and some extra options, all this on a buffer.
3537
3538I. PostScript printing:
3539
3540 1. You can generate a PostScript file (if you type C-u before activating
3541 menu) or PostScript temporary file for a directory, a buffer, a region
3542 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
3543 after file generation, ghostview is activated using the file generated
3544 as argument. This option is disabled if spooling is on (option 16).
3545 Also, if you already have a PostScript file you can preview it.
3546 Instead of previewing each buffer, region or major mode at once, you
3547 can save temporarily the PostScript code generated in a buffer and
3548 preview it later. The option `Despool...' despools the PostScript
3549 spooling buffer in a temporary file and uses ghostview to preview it.
3550 If you type C-u before choosing this option, the PostScript code
3551 generated is saved in a file instead of saving in a temporary file. To
3552 spool the PostScript code generated you need to turn on the option 16.
3553 The option `Despool...' is enabled if spooling is on (option 16).
3554
3555 NOTE 1: It's possible to customize a major mode printing, just declare
3556 the customization in `pr-mode-alist' and invoke some of
3557 `*-mode*' commands or select Mode option in Printing menu. An
3558 example for major mode usage is when you're using gnus (or mh,
3559 or rmail, etc.) and you're in the *Summary* buffer, if you
3560 forget to switch to the *Article* buffer before printing,
3561 you'll get a nicely formatted list of article subjects shows
3562 up at the printer. With major mode printing you don't need to
3563 switch from gnus *Summary* buffer first.
3564
3565 NOTE 2: There are the following options for PostScript file processing:
b8d955f4
VJL
3566 Ia. Print the file *No Preprocessing*, that is, send it
3567 directly to PostScript printer.
2c840b90
KS
3568 Ib. PostScript utility processing selection.
3569 See `pr-ps-utility-alist' and `pr-setting-database' for
3570 documentation.
3571 Ic. Do n-up processing before printing.
3572 Id. Toggle on/off landscape for PostScript file processing.
3573 Ie. Toggle on/off duplex for PostScript file processing.
3574 If. Toggle on/off tumble for PostScript file processing.
3575
3576 NOTE 3: Don't forget to download and install the utilities declared on
3577 `pr-ps-utility-alist'.
3578
3579 2. Operate the same way as option 1, but it sends directly the PostScript
3580 code (or put in a file, if you've typed C-u) or it uses ghostscript to
3581 print the PostScript file generated. It depends on option 18, if it's
3582 turned on, it uses ghostscript; otherwise, it sends directly to
3583 printer. If spooling is on (option 16), the PostScript code is saved
3584 temporarily in a buffer instead of printing it or saving it in a file.
3585 Also, if you already have a PostScript file you can print it.
3586 Instead of printing each buffer, region or major mode at once, you can
3587 save temporarily the PostScript code generated in a buffer and print it
3588 later. The option `Despool...' despools the PostScript spooling buffer
3589 directly on a printer. If you type C-u before choosing this option,
449cba44
VJL
3590 the PostScript code generated is saved in a file instead of sending it to
3591 the printer. To spool the PostScript code generated you need to turn on
3592 option 16. This option is enabled if spooling is on (option 16).
2c840b90
KS
3593 See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
3594
3595 3. You can select a new PostScript printer to send PostScript code
3596 generated. For selection it's used all PostScript printers defined
3597 in `pr-ps-printer-alist' variable (see it for documentation).
3598 See also `pr-setting-database'.
3599
3600II. Text printing:
3601
3602 4. If you have control characters (character code from \\000 to \\037) in a
3603 buffer and you want to print them in a text printer, select this
3604 option. All control characters in your buffer or region will be
3605 replaced by a printable representation. The printable representations
3606 use ^ (for ASCII control characters) or hex. The characters tab,
3607 linefeed, space, return and formfeed are not affected.
3608 You don't need to select this option if you use any option of section
3609 I, the PostScript engine treats control characters properly.
3610
3611 5. If you want to print a directory, buffer, region or major mode in a
3612 text printer, select this option. See also the NOTE 1 on option 1.
3613
3614 6. You can select a new text printer to send text generated. For
3615 selection it's used all text printers defined in `pr-txt-printer-alist'
3616 variable (see it for documentation).
3617 See also `pr-setting-database'.
3618
3619III. PostScript page toggle options:
3620
3621 7. If you want a PostScript landscape printing, turn on this option.
3622
3623 8. If you want to have a header in each page in your PostScript code,
3624 turn on this option.
3625
3626 9. If you want to draw a gaudy frame around the header, turn on this
3627 option. This option is enabled if print header is on (option 8).
3628
3629 10. If you want that the line number is printed in your PostScript code,
3630 turn on this option.
3631
3632 11. If you want background zebra stripes in your PostScript code, turn on
3633 this option.
3634
3635 12. If you want a duplex printing and your PostScript printer has this
3636 feature, turn on this option.
3637
3638 13. If you turned on duplex printing, you can choose if you want to have a
3639 printing suitable for binding on the left or right (tumble off), or to
3640 have a printing suitable for binding at top or bottom (tumble on).
3641 This option is enabled if duplex is on (option 12).
3642
3643 14. If you want a PostScript upside-down printing, turn on this option.
3644
3645 15. With this option, you can choose if you want to print all pages, odd
3646 pages, even pages, odd sheets or even sheets.
3647 See also `ps-even-or-odd-pages'.
3648
3649IV. PostScript processing toggle options:
3650
3651 16. If you want to spool the PostScript code generated, turn on this
3652 option. To spool the PostScript code generated use option 2. You can
3653 despool later by choosing option 1 or 2, sub-option `Despool...'.
3654
3655 17. If you use colors in your buffers and want to see these colors on your
3656 PostScript code generated, turn on this option. If you have a
3657 black/white PostScript printer, these colors are displayed in gray
3658 scale by PostScript printer interpreter.
3659
3660 18. If you don't have a PostScript printer to send PostScript files, turn
3661 on this option. When this option is on, the ghostscript is used to
3662 print PostScript files. In GNU or Unix system, if ghostscript is set
3663 as a PostScript filter, you don't need to turn on this option.
3664
3665V. Printing customization:
3666
3667 19. If you want that region is automagically detected, turn on this
3668 option. Note that this will only work if you're using transient mark
3669 mode. When this option is on, the `*-buffer*' commands will behave
3670 like `*-region*' commands, that is, `*-buffer*' commands will print
3671 only the region marked instead of all buffer.
3672
3673 20. Turn this option on if you want that when current major-mode is
3674 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3675 behave like `*-mode*' commands.
3676
449cba44 3677 21. If you want that Printing menu stays open while you are setting
2c840b90
KS
3678 toggle options, turn on this option. The variables
3679 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3680 menu position, so don't forget to adjust these variables if menu
3681 position is not ok.
3682
3683VI. Customization:
3684
3685 22. Besides all options in section III, IV and V, you can customize much
3686 more PostScript options in `ps-print' option. Or you can customize
3687 some `lpr' options for text printing. Or customize `printing'
3688 options.
3689
3690 23. Show current settings for `printing', `ps-print' or `lpr'.
3691
3692 24. Quick help for printing menu layout.
3693")
3694 "Printing help message.")
3695
3696
3697(defconst pr-interface-help-message
3698 (concat "printing.el version " pr-version
3699 " ps-print.el version " ps-print-version
3700 "\n\n
3701The printing interface buffer has the same functionality as the printing menu.
3702The major difference is that the states (like sending PostScript generated to a
e1dbe924 3703file, n-up printing, etc.) are set and saved between printing buffer
2c840b90
KS
3704activation. Also, the landscape, duplex and tumble values are the same for
3705PostScript file and directory/buffer/region/mode processing; using menu, there
3706are different value sets for PostScript file and directory/buffer/region/mode
3707processing.
3708
3709The printing interface buffer has the following sections:
3710
37111. Print:
3712
3713 Here you can choose to print/preview a buffer, a directory or a PostScript
3714 file:
3715
3716 1a. Buffer:
3717
3718 * Buffer List:
3719 Select a buffer from the current buffer list.
3720
3721 * Region:
3722 If it's on, this means that the selected buffer has an active region,
3723 so you can turn on/off, as you wish.
3724 If it's off when a buffer is selected, this means that the selected
3725 buffer has no active region, so it'll not be possible to turn it on.
3726 If you want to process the region, let this option on.
3727 If you want to process the whole buffer, let this option off.
3728
3729 * Mode:
3730 If it's on, this means that the selected buffer major mode is declared
3731 for major mode processing, so you can turn on/off, as you wish.
3732 If it's off when a buffer is selected, this means that the selected
3733 buffer major mode isn't declared for major mode processing, so it'll
3734 not be possible to turn it on.
3735 If you want the major mode processing, let this option on.
3736 If you don't want the major mode processing, let this option off.
3737
3738 NOTE 1: It's possible to customize a major mode printing, just declare
3739 the customization in `pr-mode-alist' and invoke some of
3740 `*-mode*' commands or select Mode option in Printing menu. An
3741 example for major mode usage is when you're using gnus (or mh,
3742 or rmail, etc.) and you're in the *Summary* buffer, if you
3743 forget to switch to the *Article* buffer before printing,
3744 you'll get a nicely formatted list of article subjects shows
3745 up at the printer. With major mode printing you don't need to
3746 switch from gnus *Summary* buffer first.
3747
3748 1b. Directory:
3749
3750 * Directory:
3751 Specify a valid directory path.
3752
3753 * File Regexp:
3754 Specify a file name regexp. All file names in the directory that
3755 match with regexp will be printed/previewed. An empty file name
3756 regexp means to print/preview all files in the directory.
3757
3758 * List Directory Entry:
3759 If it's turned on, list directory entries besides file entries.
3760
3761 1c. PostScript file:
3762
3763 * PostScript File:
3764 Specify an existent PostScript file to print/preview.
3765
3766 * PostScript Utility:
3767 Select a PostScript utility.
3768 See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
3769
3770 NOTE 2: Don't forget to download and install the utilities declared on
3771 `pr-ps-utility-alist'.
3772
b8d955f4 3773 * No Preprocessing:
2c840b90
KS
3774 If it's turned on, don't use the PostScript utility to preprocess the
3775 PostScript file before printing/previewing.
3776
37772. PostScript printer:
3778
3779 * PostScript Printer:
3780 You can select a new PostScript printer to send PostScript code
3781 generated. For selection it's used all PostScript printers defined
3782 in `pr-ps-printer-alist' variable (see it for documentation).
3783 See also `pr-setting-database'.
3784
3785 * Despool:
3786 If spooling is on, you can turn it on/off, as you wish.
3787 If spooling is off, it'll not be possible to turn it on.
3788 If it's turned on, specify to despools the PostScript spooling buffer in
3789 a temporary file or in the selected PostScript file when
3790 printing/previewing.
3791
3792 * Preview:
3793 Preview the PostScript generated.
3794
3795 * Print:
3796 Print the PostScript generated.
3797
3798 * Quit:
3799 Quit from printing interface buffer.
3800
3801 * Send to Printer/Temporary File:
3802 If it's turned on, the PostScript generated is sent directly to
3803 PostScript printer or, for previewing, to a temporary file.
3804
3805 * Send to File:
3806 Specify a file name to send the PostScript generated.
3807
3808 * N-Up:
3809 Specify n-up printing.
3810
38113. Text printer:
3812
3813 * Text Printer:
3814 Select a new text printer to send text generated. For selection it's used
3815 all text printers defined in `pr-txt-printer-alist' variable (see it for
3816 documentation). See also `pr-setting-database'.
3817
3818 * Printify:
3819 If you have control characters (character code from \\000 to \\037) in a
3820 buffer and you want to print them in a text printer, select this
3821 option. All control characters in your buffer or region will be
3822 replaced by a printable representation. The printable representations
3823 use ^ (for ASCII control characters) or hex. The characters tab,
3824 linefeed, space, return and formfeed are not affected.
3825 You don't need to select this option if you use any option of section
3826 I, the PostScript engine treats control characters properly.
3827
3828 * Print:
3829 To print a directory, buffer, region or major mode in a
3830 text printer, select this option. See also the NOTE 1 on section 1.
3831
3832 * Quit:
3833 Quit from printing interface buffer.
3834
38354. Settings:
3836
3837 There are 3 setting columns:
3838
3839 4a. First column (left column):
3840
3841 * Landscape:
3842 PostScript landscape printing.
3843
3844 * Print Header:
3845 To have a header in each page in your PostScript code.
3846
3847 * Print Header Frame:
3848 To draw a gaudy frame around the header.
3849
3850 * Line Number:
3851 The line number is printed in your PostScript code.
3852
3853 * Zebra Stripes:
3854 Background zebra stripes in your PostScript code.
3855
3856 * Duplex:
3857 Duplex printing (if your PostScript printer has this feature).
3858
3859 * Tumble:
3860 If duplex printing is on, you can choose if you want to have a
3861 printing suitable for binding on the left or right (tumble off), or to
3862 have a printing suitable for binding at top or bottom (tumble on).
3863
3864 * Upside-Down:
3865 PostScript upside-down printing.
3866
3867 4b. Second column (middle column):
3868
3869 * Auto Region:
3870 If you want that region is automagically detected, turn on this
3871 option. Note that this will only work if you're using transient mark
3872 mode. When this option is on, the `*-buffer*' commands will behave
3873 like `*-region*' commands, that is, `*-buffer*' commands will print
3874 only the region marked instead of all buffer.
3875
3876 * Auto Mode:
3877 Turn this option on if you want that when current major-mode is
3878 declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
3879 behave like `*-mode*' commands.
3880
3881 * Menu Lock:
449cba44 3882 If you want that Printing menu stays open while you are setting
2c840b90
KS
3883 toggle options, turn on this option. The variables
3884 `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
3885 menu position, so don't forget to adjust these variables if menu
3886 position is not ok.
3887
3888 * Spool Buffer:
3889 To spool the PostScript code generated. You can despool later by
3890 setting Despool option on PostScript printer section.
3891
449cba44 3892 * Print with faces:
2c840b90
KS
3893 If you use colors in your buffers and want to see these colors on your
3894 PostScript code generated, turn on this option. If you have a
3895 black/white PostScript printer, these colors are displayed in gray
3896 scale by PostScript printer interpreter.
3897
449cba44 3898 * Print via Ghostscript:
2c840b90
KS
3899 If you don't have a PostScript printer to send PostScript files, turn
3900 on this option. When this option is on, the ghostscript is used to
3901 print PostScript files. In GNU or Unix system, if ghostscript is set
3902 as a PostScript filter, you don't need to turn on this option.
3903
3904 * Parity Page Menu:
3905 To print all pages, odd pages, even pages, odd sheets or even sheets.
3906 See also `ps-even-or-odd-pages'.
3907
3908 4c. Third column (right column):
3909
3910 * Verbose:
3911 That is, to be verbose when editing a field in interface buffer.
3912
39135. Customize:
3914
3915 Besides all options in section 4, you can customize much more PostScript
3916 options in `ps-print' option. Or you can customize some `lpr' options for
3917 text printing. Or customize `printing' options.
3918
39196. Show settings:
3920
3921 Show current settings for `printing', `ps-print' or `lpr'.
3922
39237. Help:
3924
3925 Quick help for printing interface buffer and printing menu layout. You can
3926 also quit the printing interface buffer or kill all printing help buffer.
3927")
3928 "Printing buffer interface help message.")
3929
3930
3931;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3932;; Commands
3933
3934
3935;;;###autoload
3936(defun pr-interface (&optional buffer)
3937 "Activate the printing interface buffer.
3938
449cba44 3939If BUFFER is nil, the current buffer is used for printing.
2c840b90 3940
449cba44 3941For more information, type \\[pr-interface-help]."
2c840b90 3942 (interactive)
7fdbcd83 3943 (with-current-buffer (or buffer (current-buffer))
9f7a9918 3944 (pr-create-interface)))
2c840b90
KS
3945
3946
3947;;;###autoload
3948(defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
3949 "Preview directory using ghostview.
3950
3951Interactively, the command prompts for N-UP printing number, a directory, a
3952file name regexp for matching and, when you use a prefix argument (C-u), the
3953command prompts the user for a file name, and saves the PostScript image in
3954that file instead of saving it in a temporary file.
3955
3956Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3957nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3958FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3959save the image in a temporary file. If FILENAME is a string, save the
3960PostScript image in a file with that name. If FILENAME is t, prompts for a
3961file name.
3962
3963See also documentation for `pr-list-directory'."
3964 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
9f7a9918
VJL
3965 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3966 (pr-prompt "PS preview dir"))
3967 (setq filename (pr-ps-file filename))
3968 (pr-ps-file-list n-up dir file-regexp filename)
3969 (or pr-spool-p
3970 (pr-ps-file-preview filename)))
2c840b90
KS
3971
3972
3973;;;###autoload
3974(defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
3975 "Print directory using PostScript through ghostscript.
3976
3977Interactively, the command prompts for N-UP printing number, a directory, a
3978file name regexp for matching and, when you use a prefix argument (C-u), the
3979command prompts the user for a file name, and saves the PostScript image in
3980that file instead of saving it in a temporary file.
3981
3982Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
3983nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
3984FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
3985save the image in a temporary file. If FILENAME is a string, save the
3986PostScript image in a file with that name. If FILENAME is t, prompts for a
3987file name.
3988
3989See also documentation for `pr-list-directory'."
3990 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
9f7a9918
VJL
3991 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
3992 (pr-prompt "PS print dir GS"))
3993 (let ((file (pr-ps-file filename)))
3994 (pr-ps-file-list n-up dir file-regexp file)
3995 (pr-ps-file-using-ghostscript file)
3996 (or filename (pr-delete-file file))))
2c840b90
KS
3997
3998
3999;;;###autoload
4000(defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
4001 "Print directory using PostScript printer.
4002
4003Interactively, the command prompts for N-UP printing number, a directory, a
4004file name regexp for matching and, when you use a prefix argument (C-u), the
4005command prompts the user for a file name, and saves the PostScript image in
4006that file instead of saving it in a temporary file.
4007
4008Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4009nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4010FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4011save the image in a temporary file. If FILENAME is a string, save the
4012PostScript image in a file with that name. If FILENAME is t, prompts for a
4013file name.
4014
4015See also documentation for `pr-list-directory'."
4016 (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
9f7a9918
VJL
4017 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4018 (pr-prompt "PS print dir"))
4019 (let ((file (pr-ps-file filename)))
4020 (pr-ps-file-list n-up dir file-regexp file)
4021 (pr-ps-file-print file)
4022 (or filename (pr-delete-file file))))
2c840b90
KS
4023
4024
4025;;;###autoload
4026(defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
4027 "Print directory using PostScript printer or through ghostscript.
4028
4029It depends on `pr-print-using-ghostscript'.
4030
4031Interactively, the command prompts for N-UP printing number, a directory, a
4032file name regexp for matching and, when you use a prefix argument (C-u), the
4033command prompts the user for a file name, and saves the PostScript image in
4034that file instead of saving it in a temporary file.
4035
4036Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
4037nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
4038FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
4039save the image in a temporary file. If FILENAME is a string, save the
4040PostScript image in a file with that name. If FILENAME is t, prompts for a
4041file name.
4042
4043See also documentation for `pr-list-directory'."
4044 (interactive (pr-interactive-ps-dir-args
4045 (pr-prompt (pr-prompt-gs "PS print dir"))))
9f7a9918
VJL
4046 (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
4047 (pr-prompt (pr-prompt-gs "PS print dir")))
4048 (if (pr-using-ghostscript-p)
4049 (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
4050 (pr-ps-directory-print n-up dir file-regexp filename)))
2c840b90
KS
4051
4052
4053;;;###autoload
4054(defun pr-ps-buffer-preview (n-up &optional filename)
4055 "Preview buffer using ghostview.
4056
4057Interactively, the command prompts for N-UP printing number and, when you use a
4058prefix argument (C-u), the command prompts the user for a file name, and saves
4059the PostScript image in that file instead of saving it in a temporary file.
4060
4061Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4062argument FILENAME is treated as follows: if it's nil, save the image in a
4063temporary file. If FILENAME is a string, save the PostScript image in a file
4064with that name. If FILENAME is t, prompts for a file name."
4065 (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
9f7a9918
VJL
4066 (if (pr-auto-mode-p)
4067 (pr-ps-mode-preview n-up filename)
4068 (pr-ps-preview (pr-region-active-symbol) n-up filename
4069 (pr-region-active-string "PS preview"))))
2c840b90
KS
4070
4071
4072;;;###autoload
4073(defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
4074 "Print buffer using PostScript through ghostscript.
4075
4076Interactively, the command prompts for N-UP printing number and, when you use a
4077prefix argument (C-u), the command prompts the user for a file name, and saves
4078the PostScript image in that file instead of sending it to the printer.
4079
4080Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4081argument FILENAME is treated as follows: if it's nil, send the image to the
4082printer. If FILENAME is a string, save the PostScript image in a file with
4083that name. If FILENAME is t, prompts for a file name."
4084 (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
9f7a9918
VJL
4085 (if (pr-auto-mode-p)
4086 (pr-ps-mode-using-ghostscript n-up filename)
4087 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4088 (pr-region-active-string "PS print GS"))))
2c840b90
KS
4089
4090
4091;;;###autoload
4092(defun pr-ps-buffer-print (n-up &optional filename)
4093 "Print buffer using PostScript printer.
4094
4095Interactively, the command prompts for N-UP printing number and, when you use a
4096prefix argument (C-u), the command prompts the user for a file name, and saves
4097the PostScript image in that file instead of sending it to the printer.
4098
4099Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4100argument FILENAME is treated as follows: if it's nil, send the image to the
4101printer. If FILENAME is a string, save the PostScript image in a file with
4102that name. If FILENAME is t, prompts for a file name."
4103 (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
9f7a9918
VJL
4104 (if (pr-auto-mode-p)
4105 (pr-ps-mode-print n-up filename)
4106 (pr-ps-print (pr-region-active-symbol) n-up filename
4107 (pr-region-active-string "PS print"))))
2c840b90
KS
4108
4109
4110;;;###autoload
4111(defun pr-ps-buffer-ps-print (n-up &optional filename)
4112 "Print buffer using PostScript printer or through ghostscript.
4113
4114It depends on `pr-print-using-ghostscript'.
4115
4116Interactively, the command prompts for N-UP printing number and, when you use a
4117prefix argument (C-u), the command prompts the user for a file name, and saves
4118the PostScript image in that file instead of sending it to the printer.
4119
4120Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4121argument FILENAME is treated as follows: if it's nil, send the image to the
4122printer. If FILENAME is a string, save the PostScript image in a file with
4123that name. If FILENAME is t, prompts for a file name."
4124 (interactive (pr-interactive-n-up-file
4125 (pr-prompt (pr-prompt-gs "PS print"))))
9f7a9918
VJL
4126 (cond ((pr-auto-mode-p)
4127 (pr-ps-mode-ps-print n-up filename))
4128 ((pr-using-ghostscript-p)
4129 (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
4130 (pr-region-active-string "PS print GS")))
4131 (t
4132 (pr-ps-print (pr-region-active-symbol) n-up filename
4133 (pr-region-active-string "PS print")))))
2c840b90
KS
4134
4135
4136;;;###autoload
4137(defun pr-ps-region-preview (n-up &optional filename)
4138 "Preview region using ghostview.
4139
4140See also `pr-ps-buffer-preview'."
4141 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
9f7a9918
VJL
4142 (if (pr-auto-mode-p)
4143 (let ((pr-auto-region t))
4144 (pr-ps-mode-preview n-up filename))
4145 (pr-ps-preview 'region n-up filename "PS preview region")))
2c840b90
KS
4146
4147
4148;;;###autoload
4149(defun pr-ps-region-using-ghostscript (n-up &optional filename)
4150 "Print region using PostScript through ghostscript.
4151
4152See also `pr-ps-buffer-using-ghostscript'."
4153 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
9f7a9918
VJL
4154 (if (pr-auto-mode-p)
4155 (let ((pr-auto-region t))
4156 (pr-ps-mode-using-ghostscript n-up filename))
4157 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
2c840b90
KS
4158
4159
4160;;;###autoload
4161(defun pr-ps-region-print (n-up &optional filename)
4162 "Print region using PostScript printer.
4163
4164See also `pr-ps-buffer-print'."
4165 (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
9f7a9918
VJL
4166 (if (pr-auto-mode-p)
4167 (let ((pr-auto-region t))
4168 (pr-ps-mode-print n-up filename))
4169 (pr-ps-print 'region n-up filename "PS print region")))
2c840b90
KS
4170
4171
4172;;;###autoload
4173(defun pr-ps-region-ps-print (n-up &optional filename)
4174 "Print region using PostScript printer or through ghostscript.
4175
4176See also `pr-ps-buffer-ps-print'."
4177 (interactive (pr-interactive-n-up-file
4178 (pr-prompt-region (pr-prompt-gs "PS print"))))
9f7a9918
VJL
4179 (cond ((pr-auto-mode-p)
4180 (let ((pr-auto-region t))
4181 (pr-ps-mode-ps-print n-up filename)))
4182 ((pr-using-ghostscript-p)
4183 (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
4184 (t
4185 (pr-ps-print 'region n-up filename "PS print region"))))
2c840b90
KS
4186
4187
4188;;;###autoload
4189(defun pr-ps-mode-preview (n-up &optional filename)
4190 "Preview major mode using ghostview.
4191
4192See also `pr-ps-buffer-preview'."
4193 (interactive (pr-interactive-n-up-file "PS preview mode"))
9f7a9918
VJL
4194 (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
4195 (let ((file (pr-ps-file filename)))
4196 (and (pr-ps-mode n-up file)
4197 (not pr-spool-p)
4198 (pr-ps-file-preview file))))
2c840b90
KS
4199
4200
4201;;;###autoload
4202(defun pr-ps-mode-using-ghostscript (n-up &optional filename)
4203 "Print major mode using PostScript through ghostscript.
4204
4205See also `pr-ps-buffer-using-ghostscript'."
4206 (interactive (pr-interactive-n-up-file "PS print GS mode"))
9f7a9918
VJL
4207 (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
4208 (let ((file (pr-ps-file filename)))
4209 (when (and (pr-ps-mode n-up file)
4210 (not pr-spool-p))
4211 (pr-ps-file-using-ghostscript file)
4212 (or filename (pr-delete-file file)))))
2c840b90
KS
4213
4214
4215;;;###autoload
4216(defun pr-ps-mode-print (n-up &optional filename)
4217 "Print major mode using PostScript printer.
4218
4219See also `pr-ps-buffer-print'."
4220 (interactive (pr-interactive-n-up-file "PS print mode"))
9f7a9918
VJL
4221 (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
4222 (pr-ps-mode n-up filename))
2c840b90
KS
4223
4224
4225;;;###autoload
4226(defun pr-ps-mode-ps-print (n-up &optional filename)
4227 "Print major mode using PostScript or through ghostscript.
4228
4229See also `pr-ps-buffer-ps-print'."
4230 (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
9f7a9918
VJL
4231 (if (pr-using-ghostscript-p)
4232 (pr-ps-mode-using-ghostscript n-up filename)
4233 (pr-ps-mode-print n-up filename)))
2c840b90
KS
4234
4235
4236;;;###autoload
4237(defun pr-printify-directory (&optional dir file-regexp)
4238 "Replace nonprinting characters in directory with printable representations.
4239The printable representations use ^ (for ASCII control characters) or hex.
4240The characters tab, linefeed, space, return and formfeed are not affected.
4241
4242Interactively, the command prompts for a directory and a file name regexp for
4243matching.
4244
4245Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4246prompts for FILE(name)-REGEXP.
4247
4248See also documentation for `pr-list-directory'."
4249 (interactive (pr-interactive-dir-args "Printify dir"))
9f7a9918
VJL
4250 (pr-set-dir-args 'dir 'file-regexp "Printify dir")
4251 (pr-file-list dir file-regexp 'pr-printify-buffer))
2c840b90
KS
4252
4253
4254;;;###autoload
4255(defun pr-printify-buffer ()
4256 "Replace nonprinting characters in buffer with printable representations.
4257The printable representations use ^ (for ASCII control characters) or hex.
4258The characters tab, linefeed, space, return and formfeed are not affected."
4259 (interactive "*")
4260 (if (pr-region-active-p)
4261 (pr-printify-region)
4262 (printify-region (point-min) (point-max))))
4263
4264
4265;;;###autoload
4266(defun pr-printify-region ()
4267 "Replace nonprinting characters in region with printable representations.
4268The printable representations use ^ (for ASCII control characters) or hex.
4269The characters tab, linefeed, space, return and formfeed are not affected."
4270 (interactive "*")
4271 (printify-region (point) (mark)))
4272
4273
4274;;;###autoload
4275(defun pr-txt-directory (&optional dir file-regexp)
4276 "Print directory using text printer.
4277
4278Interactively, the command prompts for a directory and a file name regexp for
4279matching.
4280
4281Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
4282prompts for FILE(name)-REGEXP.
4283
4284See also documentation for `pr-list-directory'."
4285 (interactive (pr-interactive-dir-args "Print dir"))
9f7a9918
VJL
4286 (pr-set-dir-args 'dir 'file-regexp "Print dir")
4287 (pr-file-list dir file-regexp 'pr-txt-buffer))
2c840b90
KS
4288
4289
4290;;;###autoload
4291(defun pr-txt-buffer ()
4292 "Print buffer using text printer."
4293 (interactive)
4294 (cond ((pr-auto-mode-p)
4295 (pr-txt-mode))
4296 ((pr-region-active-p)
4297 (pr-txt-region))
4298 (t
4299 (pr-txt-print (point-min) (point-max)))))
4300
4301
4302;;;###autoload
4303(defun pr-txt-region ()
4304 "Print region using text printer."
4305 (interactive)
4306 (if (pr-auto-mode-p)
4307 (let ((pr-auto-region t))
4308 (pr-txt-mode))
4309 (pr-txt-print (point) (mark))))
4310
4311
4312;;;###autoload
4313(defun pr-txt-mode ()
4314 "Print major mode using text printer."
4315 (interactive)
4316 (let ((args (pr-mode-alist-p)))
4317 (if args
4318 (funcall (car args) (nthcdr 2 args))
4319 (ding)
4320 (message "`%s' major mode not declared." major-mode))))
4321
4322
4323;;;###autoload
4324(defun pr-despool-preview (&optional filename)
4325 "Preview spooled PostScript.
4326
4327Interactively, when you use a prefix argument (C-u), the command prompts the
4328user for a file name, and saves the spooled PostScript image in that file
4329instead of saving it in a temporary file.
4330
4331Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4332save the image in a temporary file. If FILENAME is a string, save the
4333PostScript image in a file with that name."
4334 (interactive (list (ps-print-preprint current-prefix-arg)))
9f7a9918
VJL
4335 (let ((file (pr-ps-file filename)))
4336 (when (stringp file)
4337 (pr-despool-print file)
4338 (pr-ps-file-preview file))))
2c840b90
KS
4339
4340
4341;;;###autoload
4342(defun pr-despool-using-ghostscript (&optional filename)
4343 "Print spooled PostScript using ghostscript.
4344
4345Interactively, when you use a prefix argument (C-u), the command prompts the
4346user for a file name, and saves the spooled PostScript image in that file
4347instead of sending it to the printer.
4348
4349Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4350send the image to the printer. If FILENAME is a string, save the PostScript
4351image in a file with that name."
4352 (interactive (list (ps-print-preprint current-prefix-arg)))
9f7a9918
VJL
4353 (let ((file (pr-ps-file filename)))
4354 (when (stringp file)
4355 (pr-despool-print file)
4356 (pr-ps-file-using-ghostscript file)
4357 (or filename (pr-delete-file file)))))
2c840b90
KS
4358
4359
4360;;;###autoload
4361(defun pr-despool-print (&optional filename)
4362 "Send the spooled PostScript to the printer.
4363
4364Interactively, when you use a prefix argument (C-u), the command prompts the
4365user for a file name, and saves the spooled PostScript image in that file
4366instead of sending it to the printer.
4367
4368Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4369send the image to the printer. If FILENAME is a string, save the PostScript
4370image in a file with that name."
4371 (interactive (list (ps-print-preprint current-prefix-arg)))
d63d883a
GM
4372 (with-file-modes pr-file-modes
4373 (let ((ps-lpr-command (pr-command pr-ps-command))
4374 (ps-lpr-switches pr-ps-switches)
4375 (ps-printer-name-option pr-ps-printer-switch)
4376 (ps-printer-name pr-ps-printer))
4377 (ps-despool filename))))
2c840b90
KS
4378
4379
4380;;;###autoload
4381(defun pr-despool-ps-print (&optional filename)
4382 "Send the spooled PostScript to the printer or use ghostscript to print it.
4383
4384Interactively, when you use a prefix argument (C-u), the command prompts the
4385user for a file name, and saves the spooled PostScript image in that file
4386instead of sending it to the printer.
4387
4388Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4389send the image to the printer. If FILENAME is a string, save the PostScript
4390image in a file with that name."
4391 (interactive (list (ps-print-preprint current-prefix-arg)))
9f7a9918
VJL
4392 (if pr-print-using-ghostscript
4393 (pr-despool-using-ghostscript filename)
4394 (pr-despool-print filename)))
2c840b90
KS
4395
4396
4397;;;###autoload
4398(defun pr-ps-file-preview (filename)
4399 "Preview PostScript file FILENAME."
4400 (interactive (list (pr-ps-infile-preprint "Preview ")))
4401 (and (stringp filename) (file-exists-p filename)
45f17557 4402 (pr-call-process pr-gv-command filename)))
2c840b90
KS
4403
4404
4405;;;###autoload
4406(defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
4407 "Preview PostScript file FILENAME."
4408 (interactive (pr-interactive-n-up-inout "PS preview"))
9f7a9918
VJL
4409 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4410 "PS preview ")))
4411 (pr-ps-utility-process n-up ifilename outfile)
4412 (pr-ps-file-preview outfile)))
2c840b90
KS
4413
4414
4415;;;###autoload
4416(defun pr-ps-file-using-ghostscript (filename)
4417 "Print PostScript file FILENAME using ghostscript."
4418 (interactive (list (pr-ps-infile-preprint "Print preview ")))
4419 (and (stringp filename) (file-exists-p filename)
9f7a9918
VJL
4420 (let* ((file (pr-expand-file-name filename))
4421 (tempfile (pr-dosify-file-name (make-temp-file file))))
4422 ;; gs use
4423 (pr-call-process pr-gs-command
4424 (format "-sDEVICE=%s" pr-gs-device)
4425 (format "-r%d" pr-gs-resolution)
4426 (pr-switches-string pr-gs-switches "pr-gs-switches")
4427 (format "-sOutputFile=\"%s\"" tempfile)
4428 file
4429 "-c quit")
4430 ;; printing
4431 (pr-ps-file-print tempfile)
4432 ;; deleting
4433 (pr-delete-file tempfile))))
2c840b90
KS
4434
4435
4436;;;###autoload
4437(defun pr-ps-file-print (filename)
4438 "Print PostScript file FILENAME."
4439 (interactive (list (pr-ps-infile-preprint "Print ")))
4440 (and (stringp filename) (file-exists-p filename)
4441 ;; printing
4442 (let ((file (pr-expand-file-name filename)))
449cba44 4443 (if (string= pr-ps-command "")
6367b616 4444 ;; default action
2c840b90 4445 (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
7fdbcd83 4446 (with-current-buffer ps-spool-buffer
2c840b90
KS
4447 (erase-buffer)
4448 (insert-file-contents-literally file))
4449 (pr-despool-print))
6367b616 4450 ;; use `pr-ps-command' to print
45f17557
VJL
4451 (apply 'pr-call-process
4452 pr-ps-command
14b84c94 4453 (pr-switches-string pr-ps-switches "pr-ps-switches")
45f17557
VJL
4454 (if (string-match "cp" pr-ps-command)
4455 ;; for "cp" (cmd in out)
4456 (list file
4457 (concat pr-ps-printer-switch pr-ps-printer))
4458 ;; else, for others (cmd out in)
4459 (list (concat pr-ps-printer-switch pr-ps-printer)
4460 file)))))))
2c840b90
KS
4461
4462
4463;;;###autoload
4464(defun pr-ps-file-ps-print (filename)
4465 "Send PostScript file FILENAME to printer or use ghostscript to print it."
4466 (interactive (list (pr-ps-infile-preprint
4467 (if pr-print-using-ghostscript
4468 "Print preview "
4469 "Print "))))
4470 (if pr-print-using-ghostscript
4471 (pr-ps-file-using-ghostscript filename)
4472 (pr-ps-file-print filename)))
4473
4474
4475;;;###autoload
4476(defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
4477 "Process a PostScript file IFILENAME and send it to printer.
4478
4479Interactively, the command prompts for N-UP printing number, for an input
4480PostScript file IFILENAME and, when you use a prefix argument (C-u), the
4481command prompts the user for an output PostScript file name OFILENAME, and
4482saves the PostScript image in that file instead of sending it to the printer.
4483
4484Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
4485argument IFILENAME is treated as follows: if it's t, prompts for an input
4486PostScript file name; otherwise, it *must* be a string that it's an input
4487PostScript file name. The argument OFILENAME is treated as follows: if it's
4488nil, send the image to the printer. If OFILENAME is a string, save the
4489PostScript image in a file with that name. If OFILENAME is t, prompts for a
4490file name."
4491 (interactive (pr-interactive-n-up-inout
4492 (if pr-print-using-ghostscript
4493 "PS print GS"
4494 "PS print")))
9f7a9918
VJL
4495 (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
4496 (if pr-print-using-ghostscript
4497 "PS print GS "
4498 "PS print "))))
4499 (pr-ps-utility-process n-up ifilename outfile)
4500 (unless ofilename
4501 (pr-ps-file-ps-print outfile)
4502 (pr-delete-file outfile))))
2c840b90
KS
4503
4504
4505;;;###autoload
4506(defun pr-toggle-file-duplex ()
4507 "Toggle duplex for PostScript file."
4508 (interactive)
9f7a9918 4509 (pr-toggle-file-duplex-menu t))
2c840b90
KS
4510
4511
4512;;;###autoload
4513(defun pr-toggle-file-tumble ()
4514 "Toggle tumble for PostScript file.
4515
4516If tumble is off, produces a printing suitable for binding on the left or
4517right.
4518If tumble is on, produces a printing suitable for binding at the top or
4519bottom."
4520 (interactive)
9f7a9918 4521 (pr-toggle-file-tumble-menu t))
2c840b90
KS
4522
4523
4524;;;###autoload
4525(defun pr-toggle-file-landscape ()
4526 "Toggle landscape for PostScript file."
4527 (interactive)
9f7a9918 4528 (pr-toggle-file-landscape-menu t))
2c840b90
KS
4529
4530
4531;;;###autoload
4532(defun pr-toggle-ghostscript ()
4533 "Toggle printing using ghostscript."
4534 (interactive)
9f7a9918 4535 (pr-toggle-ghostscript-menu t))
2c840b90
KS
4536
4537
4538;;;###autoload
4539(defun pr-toggle-faces ()
4540 "Toggle printing with faces."
4541 (interactive)
9f7a9918 4542 (pr-toggle-faces-menu t))
2c840b90
KS
4543
4544
4545;;;###autoload
4546(defun pr-toggle-spool ()
4547 "Toggle spooling."
4548 (interactive)
9f7a9918 4549 (pr-toggle-spool-menu t))
2c840b90
KS
4550
4551
4552;;;###autoload
4553(defun pr-toggle-duplex ()
4554 "Toggle duplex."
4555 (interactive)
9f7a9918 4556 (pr-toggle-duplex-menu t))
2c840b90
KS
4557
4558
4559;;;###autoload
4560(defun pr-toggle-tumble ()
4561 "Toggle tumble.
4562
4563If tumble is off, produces a printing suitable for binding on the left or
4564right.
4565If tumble is on, produces a printing suitable for binding at the top or
4566bottom."
4567 (interactive)
9f7a9918 4568 (pr-toggle-tumble-menu t))
2c840b90
KS
4569
4570
4571;;;###autoload
4572(defun pr-toggle-landscape ()
4573 "Toggle landscape."
4574 (interactive)
9f7a9918 4575 (pr-toggle-landscape-menu t))
2c840b90
KS
4576
4577
4578;;;###autoload
4579(defun pr-toggle-upside-down ()
4580 "Toggle upside-down."
4581 (interactive)
9f7a9918 4582 (pr-toggle-upside-down-menu t))
2c840b90
KS
4583
4584
4585;;;###autoload
4586(defun pr-toggle-line ()
4587 "Toggle line number."
4588 (interactive)
9f7a9918 4589 (pr-toggle-line-menu t))
2c840b90
KS
4590
4591
4592;;;###autoload
4593(defun pr-toggle-zebra ()
4594 "Toggle zebra stripes."
4595 (interactive)
9f7a9918 4596 (pr-toggle-zebra-menu t))
2c840b90
KS
4597
4598
4599;;;###autoload
4600(defun pr-toggle-header ()
4601 "Toggle printing header."
4602 (interactive)
9f7a9918 4603 (pr-toggle-header-menu t))
2c840b90
KS
4604
4605
4606;;;###autoload
4607(defun pr-toggle-header-frame ()
4608 "Toggle printing header frame."
4609 (interactive)
9f7a9918 4610 (pr-toggle-header-frame-menu t))
2c840b90
KS
4611
4612
4613;;;###autoload
4614(defun pr-toggle-lock ()
4615 "Toggle menu lock."
4616 (interactive)
9f7a9918 4617 (pr-toggle-lock-menu t))
2c840b90
KS
4618
4619
4620;;;###autoload
4621(defun pr-toggle-region ()
4fe74b19 4622 "Toggle whether the region is automagically detected."
2c840b90 4623 (interactive)
9f7a9918 4624 (pr-toggle-region-menu t))
2c840b90
KS
4625
4626
4627;;;###autoload
4628(defun pr-toggle-mode ()
4629 "Toggle auto mode."
4630 (interactive)
9f7a9918 4631 (pr-toggle-mode-menu t))
2c840b90
KS
4632
4633
4634;;;###autoload
6c42fc3e 4635(defun pr-customize (&rest _ignore)
449cba44 4636 "Customization of the `printing' group."
2c840b90
KS
4637 (interactive)
4638 (customize-group 'printing))
4639
4640
4641;;;###autoload
6c42fc3e 4642(defun lpr-customize (&rest _ignore)
449cba44 4643 "Customization of the `lpr' group."
2c840b90
KS
4644 (interactive)
4645 (customize-group 'lpr))
4646
4647
4648;;;###autoload
6c42fc3e 4649(defun pr-help (&rest _ignore)
449cba44 4650 "Help for the printing package."
2c840b90
KS
4651 (interactive)
4652 (pr-show-setup pr-help-message "*Printing Help*"))
4653
4654
4655;;;###autoload
4656(defun pr-ps-name ()
449cba44 4657 "Interactively select a PostScript printer."
2c840b90 4658 (interactive)
9f7a9918
VJL
4659 (pr-menu-set-ps-title
4660 (pr-complete-alist "PostScript printer"
4661 pr-ps-printer-alist pr-ps-name)))
2c840b90
KS
4662
4663
4664;;;###autoload
4665(defun pr-txt-name ()
449cba44 4666 "Interactively select a text printer."
2c840b90 4667 (interactive)
9f7a9918
VJL
4668 (pr-menu-set-txt-title
4669 (pr-complete-alist "Text printer"
4670 pr-txt-printer-alist pr-txt-name)))
2c840b90
KS
4671
4672
4673;;;###autoload
4674(defun pr-ps-utility ()
449cba44 4675 "Interactively select a PostScript utility."
2c840b90 4676 (interactive)
9f7a9918 4677 (pr-menu-set-utility-title
7877f373 4678 (pr-complete-alist "PostScript utility"
9f7a9918 4679 pr-ps-utility-alist pr-ps-utility)))
2c840b90
KS
4680
4681
4682;;;###autoload
6c42fc3e 4683(defun pr-show-ps-setup (&rest _ignore)
2c840b90
KS
4684 "Show current ps-print settings."
4685 (interactive)
4686 (pr-show-setup (ps-setup) "*PS Setup*"))
4687
4688
4689;;;###autoload
6c42fc3e 4690(defun pr-show-pr-setup (&rest _ignore)
2c840b90
KS
4691 "Show current printing settings."
4692 (interactive)
4693 (pr-show-setup (pr-setup) "*PR Setup*"))
4694
4695
4696;;;###autoload
6c42fc3e 4697(defun pr-show-lpr-setup (&rest _ignore)
2c840b90
KS
4698 "Show current lpr settings."
4699 (interactive)
4700 (pr-show-setup (lpr-setup) "*LPR Setup*"))
4701
4702
4703;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4704;; Fast Commands
4705
4706
4707;;;###autoload
4708(defun pr-ps-fast-fire (n-up &optional select)
4709 "Fast fire function for PostScript printing.
4710
4711If a region is active, the region will be printed instead of the whole buffer.
4712Also if the current major-mode is defined in `pr-mode-alist', the settings in
4713`pr-mode-alist' will be used, that is, the current buffer or region will be
4714printed using `pr-ps-mode-ps-print'.
4715
4716
4717Interactively, you have the following situations:
4718
4719 M-x pr-ps-fast-fire RET
4720 The command prompts the user for a N-UP value and printing will
bbd240ce 4721 immediately be done using the current active printer.
2c840b90
KS
4722
4723 C-u M-x pr-ps-fast-fire RET
4724 C-u 0 M-x pr-ps-fast-fire RET
4725 The command prompts the user for a N-UP value and also for a current
bbd240ce 4726 PostScript printer, then printing will immediately be done using the new
2c840b90
KS
4727 current active printer.
4728
4729 C-u 1 M-x pr-ps-fast-fire RET
4730 The command prompts the user for a N-UP value and also for a file name,
4731 and saves the PostScript image in that file instead of sending it to the
4732 printer.
4733
4734 C-u 2 M-x pr-ps-fast-fire RET
4735 The command prompts the user for a N-UP value, then for a current
4736 PostScript printer and, finally, for a file name. Then change the active
3f79ccad 4737 printer to that chosen by user and saves the PostScript image in
2c840b90
KS
4738 that file instead of sending it to the printer.
4739
4740
4741Noninteractively, the argument N-UP should be a positive integer greater than
4742zero and the argument SELECT is treated as follows:
4743
4744 If it's nil, send the image to the printer.
4745
4746 If it's a list or an integer lesser or equal to zero, the command prompts
bbd240ce 4747 the user for a current PostScript printer, then printing will immediately
2c840b90
KS
4748 be done using the new current active printer.
4749
4750 If it's an integer equal to 1, the command prompts the user for a file name
4751 and saves the PostScript image in that file instead of sending it to the
4752 printer.
4753
4754 If it's an integer greater or equal to 2, the command prompts the user for a
4755 current PostScript printer and for a file name. Then change the active
3f79ccad 4756 printer to that chosen by user and saves the PostScript image in that file
2c840b90
KS
4757 instead of sending it to the printer.
4758
4759 If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
bbd240ce 4760 active printer and printing will immediately be done using the new active
2c840b90
KS
4761 printer.
4762
4763 Otherwise, send the image to the printer.
4764
4765
4766Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4767are both set to t."
4768 (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
4769 current-prefix-arg))
9f7a9918
VJL
4770 (let ((pr-auto-region t)
4771 (pr-auto-mode t)
4772 filename)
4773 (cond ((null select))
4774 ((listp select)
4775 (pr-ps-name))
4776 ((and (symbolp select)
4777 (assq select pr-ps-printer-alist))
4778 (pr-menu-set-ps-title select))
4779 ((integerp select)
4780 (and (/= select 1)
4781 (pr-ps-name))
4782 (and (>= select 1) (not pr-spool-p)
4783 (setq filename (pr-ps-outfile-preprint
4784 (if pr-print-using-ghostscript
4785 "Fast GS "
4786 "Fast "))))))
4787 (pr-ps-buffer-ps-print
4788 (if (integerp n-up)
4789 (min (max n-up 1) 100)
4790 (error "n-up must be an integer greater than zero"))
4791 filename)))
2c840b90
KS
4792
4793
4794;;;###autoload
4795(defun pr-txt-fast-fire (&optional select-printer)
4796 "Fast fire function for text printing.
4797
4798If a region is active, the region will be printed instead of the whole buffer.
4799Also if the current major-mode is defined in `pr-mode-alist', the settings in
4800`pr-mode-alist' will be used, that is, the current buffer or region will be
4801printed using `pr-txt-mode'.
4802
4803Interactively, when you use a prefix argument (C-u), the command prompts the
4804user for a new active text printer.
4805
4806Noninteractively, the argument SELECT-PRINTER is treated as follows:
4807
4808 If it's nil, the printing is sent to the current active text printer.
4809
4810 If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
bbd240ce 4811 active printer and printing will immediately be done using the new active
2c840b90
KS
4812 printer.
4813
4814 If it's non-nil, the command prompts the user for a new active text printer.
4815
4816Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
4817are both set to t."
4818 (interactive (list current-prefix-arg))
9f7a9918
VJL
4819 (cond ((null select-printer))
4820 ((and (symbolp select-printer)
4821 (assq select-printer pr-txt-printer-alist))
4822 (pr-menu-set-txt-title select-printer))
4823 (t
4824 (pr-txt-name)))
4825 (let ((pr-auto-region t)
4826 (pr-auto-mode t))
4827 (pr-txt-buffer)))
2c840b90
KS
4828
4829
4830;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4831;; Utilities
4832
4833
4834(defun pr-setup ()
4835 "Return the current `printing' setup.
4836
4837This is *not* an interactive command.
4838One way to see `printing' setup is to switch to a *Scratch* buffer and type:
4839
4840 M-: (insert (pr-setup)) RET
4841
4842Or choose the menu option Printing/Show Settings/printing."
4843 (let (ps-prefix-quote)
4844 (mapconcat
4845 #'ps-print-quote
4846 (list
4847 (concat "\n;;; printing.el version " pr-version "\n")
45f17557 4848 ";; internal vars"
83aebfe6 4849 (ps-comment-string "emacs-version " emacs-version)
45f17557
VJL
4850 (ps-comment-string "pr-txt-command " pr-txt-command)
4851 (ps-comment-string "pr-txt-switches "
4852 (pr-switches-string pr-txt-switches "pr-txt-switches"))
4853 (ps-comment-string "pr-txt-printer " pr-txt-printer)
4854 (ps-comment-string "pr-ps-command " pr-ps-command)
4855 (ps-comment-string "pr-ps-switches "
4856 (pr-switches-string pr-ps-switches "pr-ps-switches"))
4857 (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
4858 (ps-comment-string "pr-ps-printer " pr-ps-printer)
4859 (ps-comment-string "pr-cygwin-system " pr-cygwin-system)
d100084b
GM
4860 (ps-comment-string "lpr-windows-system " lpr-windows-system)
4861 (ps-comment-string "lpr-lp-system " lpr-lp-system)
45f17557
VJL
4862 nil
4863 '(14 . pr-path-style)
4864 '(14 . pr-path-alist)
2c840b90
KS
4865 nil
4866 '(21 . pr-txt-name)
4867 '(21 . pr-txt-printer-alist)
4868 nil
4869 '(20 . pr-ps-name)
4870 '(20 . pr-ps-printer-alist)
4871 nil
4872 '(20 . pr-temp-dir)
4873 '(20 . pr-ps-temp-file)
6367b616 4874 '(20 . pr-file-modes)
2c840b90
KS
4875 '(20 . pr-delete-temp-file)
4876 '(20 . pr-list-directory)
4877 nil
4878 '(17 . pr-gv-command)
4879 '(17 . pr-gs-command)
4880 '(17 . pr-gs-switches)
4881 '(17 . pr-gs-device)
4882 '(17 . pr-gs-resolution)
4883 nil
4884 '(27 . pr-print-using-ghostscript)
4885 '(27 . pr-faces-p)
4886 '(27 . pr-spool-p)
4887 '(27 . pr-file-landscape)
4888 '(27 . pr-file-duplex)
4889 '(27 . pr-file-tumble)
4890 '(27 . pr-auto-region)
4891 '(27 . pr-auto-mode)
4892 nil
4893 '(20 . pr-ps-utility)
4894 '(20 . pr-ps-utility-alist)
4895 nil
4896 '(14 . pr-mode-alist)
4897 nil
4898 '(20 . pr-menu-lock)
4899 '(20 . pr-menu-char-height)
4900 '(20 . pr-menu-char-width)
4901 nil
4902 '(20 . pr-setting-database)
4903 nil
4904 '(22 . pr-visible-entry-list)
4905 nil
4906 '(22 . pr-buffer-verbose)
4907 '(22 . pr-buffer-name)
4908 '(22 . pr-buffer-name-ignore)
4909 ")\n\n;;; printing.el - end of settings\n")
4910 "\n")))
4911
4912
4913(defun lpr-setup ()
4914 "Return the current `lpr' setup.
4915
4916This is *not* an interactive command.
4917One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
4918
4919 M-: (insert (lpr-setup)) RET
4920
4921Or choose the menu option Printing/Show Settings/lpr."
4922 (let (ps-prefix-quote)
4923 (mapconcat
4924 #'ps-print-quote
83aebfe6
VJL
4925 (list
4926 "\n;;; lpr.el settings\n"
4927 (ps-comment-string "emacs-version" emacs-version)
4928 nil
4929 '(25 . printer-name)
4930 '(25 . lpr-switches)
4931 '(25 . lpr-add-switches)
4932 '(25 . lpr-command)
4933 '(25 . lpr-headers-switches)
4934 '(25 . print-region-function)
4935 '(25 . lpr-page-header-program)
4936 '(25 . lpr-page-header-switches)
4937 ")\n\n;;; lpr.el - end of settings\n")
2c840b90
KS
4938 "\n")))
4939
4940
4941;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4942;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
4943
fdd8417e
GM
4944(declare-function mh-get-msg-num "mh-utils" (error-if-no-message))
4945(declare-function mh-show "mh-show" (&optional message redisplay-flag))
4946(declare-function mh-start-of-uncleaned-message "mh-show" ())
4947(defvar mh-show-buffer)
2c840b90
KS
4948
4949
4950(defun pr-article-date ()
4951 "Find the date of an article or mail message in current buffer.
4952Return only the dayname, if present, weekday, month, and year."
4953 (save-excursion
4954 (goto-char (point-min))
4955 (if (re-search-forward
4956 "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
4957 (buffer-substring (match-beginning 1) (match-end 1))
4958 (format-time-string "%Y/%m/%d"))))
4959
4960
4961(defun pr-mh-current-message ()
4962 "Go to mh-inbox current message."
fdd8417e
GM
4963 (let ((msg (or (mh-get-msg-num nil) 0)))
4964 (mh-show)
2c840b90
KS
4965 (set-buffer mh-show-buffer)
4966 (goto-char (point-min))
fdd8417e 4967 (mh-start-of-uncleaned-message)
2c840b90
KS
4968 (message "Printing message %d" msg)))
4969
4970
4971(defun pr-mh-print-1 (n-up filename header-list)
4972 "Print mh-inbox current message in PostScript."
4973 (save-excursion
4974 (save-window-excursion
4975 (pr-mh-current-message)
4976 (pr-mode-print n-up filename header-list (point)))))
4977
4978
4979(defun pr-mh-lpr-1 (header-list)
4980 "Print mh-inbox current message in text printer."
4981 (save-excursion
4982 (save-window-excursion
4983 (pr-mh-current-message)
4984 (pr-mode-lpr header-list (point)))))
4985
4986
4987(defalias 'pr-mh-print-2 'pr-mode-print)
4988
4989
4990(defalias 'pr-mh-lpr-2 'pr-mode-lpr)
4991
4992
4993;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4994;; rmail (hacked from ps-print.el)
4995
4996
4997(defun pr-rmail-lpr (header-list)
4998 "Print RMAIL current message in text printer."
4999 (pr-lpr-message-from-summary header-list
5000 'rmail-buffer 'rmail-summary-buffer))
5001
5002
5003(defun pr-rmail-print (n-up filename header-list)
5004 "Print RMAIL current message in PostScript."
5005 (pr-ps-message-from-summary n-up filename header-list
5006 'rmail-buffer 'rmail-summary-buffer))
5007
5008
5009(defun pr-ps-message-from-summary (n-up filename header-list
5010 summary-buffer summary-default)
5011 "Print current message in PostScript."
5012 (let ((buf (or (and (boundp summary-buffer)
5013 (symbol-value summary-buffer))
5014 (symbol-value summary-default))))
5015 (and (get-buffer buf)
7fdbcd83 5016 (with-current-buffer buf
2c840b90
KS
5017 (pr-mode-print n-up filename header-list)))))
5018
5019
5020(defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
5021 "Print current message in text printer."
5022 (let ((buf (or (and (boundp summary-buffer)
5023 (symbol-value summary-buffer))
5024 (symbol-value summary-default))))
5025 (and (get-buffer buf)
7fdbcd83 5026 (with-current-buffer buf
2c840b90
KS
5027 (pr-mode-lpr header-list)))))
5028
5029
5030;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5031;; gnus (hacked from ps-print.el)
5032
5033
5034(defvar pr-gnus-article "*Article*")
5035
5036
5037(defun pr-gnus-print (n-up filename header-list)
5038 "Print *Article* current message in PostScript."
5039 (pr-ps-message-from-summary n-up filename header-list
5040 'gnus-article-buffer 'pr-gnus-article))
5041
5042
5043(defun pr-gnus-lpr (header-list)
5044 "Print *Article* current message in text printer."
5045 (pr-lpr-message-from-summary header-list
5046 'gnus-article-buffer 'pr-gnus-article))
5047
5048
5049;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5050;; vm (hacked from ps-print.el)
5051
5052
5053(defvar pr-vm-summary "")
5054
5055
5056(defun pr-vm-print (n-up filename header-list)
5057 "Print current vm message in PostScript."
5058 (pr-ps-message-from-summary n-up filename header-list
5059 'vm-mail-buffer 'pr-vm-summary))
5060
5061
5062(defun pr-vm-lpr (header-list)
5063 "Print current vm message in text printer."
5064 (pr-lpr-message-from-summary header-list
5065 'vm-mail-buffer 'pr-vm-summary))
5066
5067
5068;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5069;; Mode Functions
5070
5071
5072(defun pr-ps-mode (n-up filename)
5073 "If current major mode is declared, print it in PostScript."
5074 (let ((args (pr-mode-alist-p)))
5075 (if args
5076 (let ((fun (cdr args)))
5077 (funcall (car fun) n-up filename (cdr fun))
5078 t)
5079 (ding)
5080 (message "`%s' major mode not declared." major-mode)
5081 nil)))
5082
5083
5084(defmacro pr-local-variable (header-list &rest body)
5085 `(save-excursion
5086 (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
5087 (ps-left-header (or (nth 1 ,header-list) ps-left-header))
5088 (ps-right-header (or (nth 2 ,header-list) ps-right-header))
5089 ps-razzle-dazzle)
5090 (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
5091 ,@body
5092 (and (nth 3 ,header-list)
5093 (pr-kill-local-variable local-var-list))))))
5094
5095
5096(defun pr-mode-print (n-up filename header-list &optional from to)
5097 "Print current major mode in PostScript."
5098 (pr-local-variable
5099 header-list
5100 (let ((file (pr-ps-file filename))
5101 (start (cond (from)
5102 ((pr-region-active-p) (region-beginning))
5103 (t nil)
5104 )))
5105 (pr-text2ps (pr-region-active-symbol start) n-up file start
5106 (cond (to)
5107 ((pr-region-active-p) (region-end))
5108 (from (point-max))
5109 ))
5110 (unless (or pr-spool-p filename)
5111 (pr-ps-file-print file)
5112 (pr-delete-file file)))))
5113
5114
5115(defun pr-mode-lpr (header-list &optional from to)
5116 "Print current major mode in text printer."
5117 (pr-local-variable
5118 header-list
5119 (pr-txt-print (cond (from)
5120 ((pr-region-active-p) (region-beginning))
5121 (t (point-min)))
5122 (cond (to)
5123 ((pr-region-active-p) (region-end))
5124 (t (point-max))))))
5125
5126
5127;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5128;; Menu Lock
5129
5130
5131(defconst pr-menu-entry-alist
5132 '((postscript . 3)
5133 (text . 3)
5134 (postscript-options . 9)
5135 (postscript-process . 3)
5136 (printing . 3)
5137 (help . 3)
5138 )
5139 "Alist that associates menu part with number of items per part.
5140
5141It's used by `pr-menu-index'.
5142
5143Each element has the form:
5144
5145 (MENU-PART . NUMBER-OF-ITEMS)
5146
bafb1102
VJL
5147See `pr-visible-entry-alist'.")
5148
5149
5150(defun pr-menu-index (entry index)
5151 (let ((base-list
5152 (cond ((eq entry 'text)
5153 '(postscript))
5154 ((eq entry 'postscript-options)
5155 '(postscript text))
5156 ((eq entry 'postscript-process)
5157 '(postscript text postscript-options))
5158 ((eq entry 'printing)
5159 '(postscript text postscript-options postscript-process))
5160 (t
5161 nil)
5162 ))
5163 key)
5164 (while base-list
5165 (setq key (car base-list)
5166 base-list (cdr base-list))
5167 (and (pr-visible-p key)
5168 (setq index (+ index
5169 (cdr (assq key pr-menu-entry-alist)))))))
5170 (+ index 2))
2c840b90
KS
5171
5172
5173;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5174;; Printer & Utility Selection
5175
5176
5177(defun pr-update-var (var-sym alist)
5178 (or (assq (symbol-value var-sym) alist)
5179 (set var-sym (car (car alist)))))
5180
5181
5182(defun pr-update-menus (&optional force)
5183 "Update utility, PostScript and text printer menus.
5184
5185If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
5186`pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
bd65bc6c
VJL
5187otherwise, update PostScript printer menu if `pr-ps-printer-menu-modified' is
5188non-nil, update text printer menu if `pr-txt-printer-menu-modified' is
5189non-nil, and update PostScript File menus if `pr-ps-utility-menu-modified' is
b2c9cbd3
VJL
5190non-nil.
5191
5192If menu binding was not done, calls `pr-menu-bind'."
757caf1c 5193 (interactive "P")
b2c9cbd3
VJL
5194 (if pr-menu-print-item ; since v6.8.4
5195 ;; There was no menu binding yet, so do it now!
5196 ;; This is a hack to be compatible with old versions of printing.
5197 ;; So, user does not need to change printing calling in init files.
5198 (pr-menu-bind)
5199 ;; Here menu binding is ok.
5200 (pr-update-var 'pr-ps-name pr-ps-printer-alist)
5201 (pr-update-var 'pr-txt-name pr-txt-printer-alist)
5202 (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
5203 (pr-do-update-menus force)))
2c840b90
KS
5204
5205
2c840b90
KS
5206(defun pr-menu-create (name alist var-sym fun entry index)
5207 (cons name
5208 (mapcar
5209 #'(lambda (elt)
5210 (let ((sym (car elt)))
5211 (vector
5212 (symbol-name sym)
5213 (list fun (list 'quote sym) nil (list 'quote entry) index)
5214 :style 'radio
5215 :selected (list 'eq var-sym (list 'quote sym)))))
5216 alist)))
5217
5218
2c840b90
KS
5219(defun pr-ps-set-utility (value)
5220 (let ((item (cdr (assq value pr-ps-utility-alist))))
5221 (or item
5222 (error
747aa4cf 5223 "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
2c840b90
KS
5224 value))
5225 (setq pr-ps-utility value)
5226 (pr-eval-alist (nthcdr 9 item)))
5227 (pr-update-mode-line))
5228
5229
5230(defun pr-ps-set-printer (value)
5231 (let ((ps (cdr (assq value pr-ps-printer-alist))))
5232 (or ps
5233 (error
747aa4cf 5234 "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
2c840b90
KS
5235 value))
5236 (setq pr-ps-name value
0117451d 5237 pr-ps-command (pr-dosify-file-name (nth 0 ps))
2c840b90
KS
5238 pr-ps-switches (nth 1 ps)
5239 pr-ps-printer-switch (nth 2 ps)
45f17557 5240 pr-ps-printer (nth 3 ps))
2c840b90
KS
5241 (or (stringp pr-ps-command)
5242 (setq pr-ps-command
d100084b
GM
5243 (cond (lpr-windows-system "print")
5244 (lpr-lp-system "lp")
2c840b90
KS
5245 (t "lpr")
5246 )))
5247 (or (stringp pr-ps-printer-switch)
5248 (setq pr-ps-printer-switch
d100084b
GM
5249 (cond (lpr-windows-system "/D:")
5250 (lpr-lp-system "-d")
2c840b90
KS
5251 (t "-P")
5252 )))
5253 (pr-eval-alist (nthcdr 4 ps)))
5254 (pr-update-mode-line))
5255
5256
5257(defun pr-txt-set-printer (value)
5258 (let ((txt (cdr (assq value pr-txt-printer-alist))))
5259 (or txt
747aa4cf 5260 (error "Invalid text printer name `%s' for variable `pr-txt-name'"
2c840b90
KS
5261 value))
5262 (setq pr-txt-name value
0117451d 5263 pr-txt-command (pr-dosify-file-name (nth 0 txt))
2c840b90 5264 pr-txt-switches (nth 1 txt)
45f17557 5265 pr-txt-printer (nth 2 txt)))
2c840b90
KS
5266 (or (stringp pr-txt-command)
5267 (setq pr-txt-command
d100084b
GM
5268 (cond (lpr-windows-system "print")
5269 (lpr-lp-system "lp")
2c840b90
KS
5270 (t "lpr")
5271 )))
5272 (pr-update-mode-line))
5273
5274
5275(defun pr-eval-alist (alist)
5276 (mapcar #'(lambda (option)
5277 (let ((var-sym (car option))
5278 (value (cdr option)))
5279 (if (eq var-sym 'inherits-from:)
5280 (pr-eval-setting-alist value 'global)
5281 (set var-sym (eval value)))))
5282 alist))
5283
5284
5285(defun pr-eval-local-alist (alist)
5286 (let (local-list)
021c7d97
JB
5287 (mapc #'(lambda (option)
5288 (let ((var-sym (car option))
5289 (value (cdr option)))
5290 (setq local-list
5291 (if (eq var-sym 'inherits-from:)
5292 (nconc (pr-eval-setting-alist value) local-list)
5293 (set (make-local-variable var-sym) (eval value))
5294 (cons var-sym local-list)))))
5295 alist)
2c840b90
KS
5296 local-list))
5297
5298
5299(defun pr-eval-setting-alist (key &optional global old)
5300 (let ((setting (cdr (assq key pr-setting-database))))
5301 (and setting
5302 (let ((inherits (nth 0 setting))
5303 (local (nth 1 setting))
5304 (kill (nth 2 setting))
5305 local-list)
5306 (and local global
5307 (progn
5308 (ding)
5309 (message "There are local buffer settings for `%S'." key)
5310 (setq global nil)))
5311 (and inherits
5312 (if (memq inherits old)
747aa4cf 5313 (error "Circular inheritance for `%S'" inherits)
2c840b90
KS
5314 (setq local-list
5315 (pr-eval-setting-alist inherits global
5316 (cons inherits old)))))
021c7d97 5317 (mapc
2c840b90
KS
5318 (cond ((not local) ; global settings
5319 #'(lambda (option)
5320 (let ((var-sym (car option)))
5321 (or (eq var-sym 'inherits-from:)
5322 (set var-sym (eval (cdr option)))))))
5323 (kill ; local settings with killing
5324 #'(lambda (option)
5325 (let ((var-sym (car option)))
5326 (unless (eq var-sym 'inherits-from:)
5327 (setq local-list (cons var-sym local-list))
5328 (set (make-local-variable var-sym)
5329 (eval (cdr option)))))))
5330 (t ; local settings without killing
5331 #'(lambda (option)
5332 (let ((var-sym (car option)))
5333 (or (eq var-sym 'inherits-from:)
5334 (set (make-local-variable var-sym)
5335 (eval (cdr option))))))))
5336 (nthcdr 3 setting))
5337 local-list))))
5338
5339
5340(defun pr-kill-local-variable (local-var-list)
5341 (mapcar 'kill-local-variable local-var-list))
5342
5343
5344;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5345;; Internal Functions (II)
5346
5347
9f7a9918
VJL
5348(defun pr-toggle (var-sym mess entry index horizontal state
5349 &optional path no-menu)
5350 (set var-sym (not (symbol-value var-sym)))
5351 (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
5352 (or no-menu
5353 (pr-menu-lock entry index horizontal state path)))
5354
5355
5356(defun pr-toggle-file-duplex-menu (&optional no-menu)
1d52da10 5357 "Toggle whether to print PostScript files in duplex mode."
9f7a9918
VJL
5358 (interactive)
5359 (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
5360 '("PostScript Print" "File") no-menu))
5361
5362
5363(defun pr-toggle-file-tumble-menu (&optional no-menu)
1d52da10 5364 "Toggle whether to print PostScript files in tumble mode."
9f7a9918
VJL
5365 (interactive)
5366 (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
5367 '("PostScript Print" "File") no-menu))
5368
5369
5370(defun pr-toggle-file-landscape-menu (&optional no-menu)
1d52da10 5371 "Toggle whether to print PostScript files in landscape orientation."
9f7a9918
VJL
5372 (interactive)
5373 (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
5374 '("PostScript Print" "File") no-menu))
5375
5376
5377(defun pr-toggle-ghostscript-menu (&optional no-menu)
1d52da10 5378 "Toggle whether to print using ghostscript."
9f7a9918
VJL
5379 (interactive)
5380 (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
5381 'postscript-process 2 12 'toggle nil no-menu))
5382
5383
5384(defun pr-toggle-faces-menu (&optional no-menu)
1d52da10 5385 "Toggle whether to print with face attributes."
9f7a9918
VJL
5386 (interactive)
5387 (pr-toggle 'pr-faces-p "Printing with faces"
5388 'postscript-process 1 12 'toggle nil no-menu))
5389
5390
5391(defun pr-toggle-spool-menu (&optional no-menu)
1d52da10 5392 "Toggle whether to spool printing in a buffer."
9f7a9918
VJL
5393 (interactive)
5394 (pr-toggle 'pr-spool-p "Spooling printing"
5395 'postscript-process 0 12 'toggle nil no-menu))
5396
5397
5398(defun pr-toggle-duplex-menu (&optional no-menu)
1d52da10 5399 "Toggle whether to generate PostScript for a two-sided printer."
9f7a9918
VJL
5400 (interactive)
5401 (pr-toggle 'ps-spool-duplex "Printing duplex"
5402 'postscript-options 5 12 'toggle nil no-menu))
5403
5404
5405(defun pr-toggle-tumble-menu (&optional no-menu)
1d52da10 5406 "Toggle how pages on opposite sides of a sheet are oriented."
9f7a9918
VJL
5407 (interactive)
5408 (pr-toggle 'ps-spool-tumble "Tumble"
5409 'postscript-options 6 12 'toggle nil no-menu))
5410
5411
5412(defun pr-toggle-landscape-menu (&optional no-menu)
1d52da10 5413 "Toggle whether to print in landscape mode."
9f7a9918
VJL
5414 (interactive)
5415 (pr-toggle 'ps-landscape-mode "Landscape"
5416 'postscript-options 0 12 'toggle nil no-menu))
5417
5418
5419(defun pr-toggle-upside-down-menu (&optional no-menu)
1d52da10 5420 "Toggle whether to print upside-down (that is, rotated by 180 degrees)."
9f7a9918
VJL
5421 (interactive)
5422 (pr-toggle 'ps-print-upside-down "Upside-Down"
5423 'postscript-options 7 12 'toggle nil no-menu))
5424
5425
5426(defun pr-toggle-line-menu (&optional no-menu)
1d52da10 5427 "Toggle whether to means print line numbers."
9f7a9918
VJL
5428 (interactive)
5429 (pr-toggle 'ps-line-number "Line number"
5430 'postscript-options 3 12 'toggle nil no-menu))
5431
5432
5433(defun pr-toggle-zebra-menu (&optional no-menu)
1d52da10 5434 "Toggle whether to print zebra stripes."
9f7a9918
VJL
5435 (interactive)
5436 (pr-toggle 'ps-zebra-stripes "Zebra stripe"
5437 'postscript-options 4 12 'toggle nil no-menu))
5438
5439
5440(defun pr-toggle-header-menu (&optional no-menu)
1d52da10 5441 "Toggle whether to print a header at the top of each page."
9f7a9918
VJL
5442 (interactive)
5443 (pr-toggle 'ps-print-header "Print header"
5444 'postscript-options 1 12 'toggle nil no-menu))
5445
5446
5447(defun pr-toggle-header-frame-menu (&optional no-menu)
1d52da10 5448 "Toggle whether to draw a gaudy frame around the header."
9f7a9918
VJL
5449 (interactive)
5450 (pr-toggle 'ps-print-header-frame "Print header frame"
5451 'postscript-options 2 12 'toggle nil no-menu))
5452
5453
5454(defun pr-toggle-lock-menu (&optional no-menu)
1d52da10 5455 "Toggle whether the menu is locked while selecting toggle options."
9f7a9918
VJL
5456 (interactive)
5457 (pr-toggle 'pr-menu-lock "Menu lock"
5458 'printing 2 12 'toggle nil no-menu))
5459
5460
5461(defun pr-toggle-region-menu (&optional no-menu)
1d52da10 5462 "Toggle whether the region is automagically detected."
9f7a9918
VJL
5463 (interactive)
5464 (pr-toggle 'pr-auto-region "Auto region"
5465 'printing 0 12 'toggle nil no-menu))
5466
5467
5468(defun pr-toggle-mode-menu (&optional no-menu)
e4920bc9 5469 "Toggle whether major-mode specific printing is preferred over normal printing."
9f7a9918
VJL
5470 (interactive)
5471 (pr-toggle 'pr-auto-mode "Auto mode"
5472 'printing 1 12 'toggle nil no-menu))
5473
5474
2c840b90
KS
5475(defun pr-prompt (str)
5476 (if (pr-auto-mode-p)
5477 (concat str " mode")
5478 (pr-region-active-string str)))
5479
5480
5481(defun pr-prompt-region (str)
5482 (concat str (if (pr-auto-mode-p)
5483 " mode"
5484 " region")))
5485
5486
5487(defun pr-prompt-gs (str)
5488 (if (pr-using-ghostscript-p)
5489 (concat str " GS")
5490 str))
5491
5492
5493(defun pr-region-active-symbol (&optional region-p)
5494 (if (or region-p (pr-region-active-p))
5495 'region
5496 'buffer))
5497
5498
5499(defun pr-region-active-string (prefix)
5500 (concat prefix
5501 (if (pr-region-active-p)
5502 " region"
5503 " buffer")))
5504
5505
5506(defun pr-show-setup (settings buffer-name)
5507 (with-output-to-temp-buffer buffer-name
5508 (princ settings)
d5d105e8 5509 (help-print-return-message)))
2c840b90
KS
5510
5511
5512(defun pr-complete-alist (prompt alist default)
5513 (let ((collection (mapcar #'(lambda (elt)
5514 (setq elt (car elt))
5515 (cons (symbol-name elt) elt))
5516 alist)))
5517 (cdr (assoc (completing-read (concat prompt ": ")
5518 collection nil t
5519 (symbol-name default) nil
5520 (symbol-name default))
5521 collection))))
5522
5523
5524(defun pr-delete-file (file)
b1f6fa86
VJL
5525 (and pr-delete-temp-file (file-exists-p file)
5526 (delete-file file)))
2c840b90
KS
5527
5528
5529(defun pr-expand-file-name (filename)
0117451d 5530 (pr-dosify-file-name (expand-file-name filename)))
2c840b90
KS
5531
5532
5533(defun pr-ps-outfile-preprint (&optional mess)
5534 (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
5535 (res (read-file-name prompt default-directory "" nil)))
5536 (while (cond ((not (file-writable-p res))
5537 (ding)
5538 (setq prompt "is unwritable"))
5539 ((file-directory-p res)
5540 (ding)
5541 (setq prompt "is a directory"))
5542 ((file-exists-p res)
5543 (ding)
5544 (setq prompt "exists")
5545 (not (y-or-n-p (format "File `%s' exists; overwrite? "
5546 res))))
5547 (t nil))
5548 (setq res (read-file-name
5549 (format "File %s; PostScript file: " prompt)
5550 (file-name-directory res) nil nil
5551 (file-name-nondirectory res))))
5552 (pr-expand-file-name res)))
5553
5554
5555(defun pr-ps-infile-preprint (&optional mess)
5556 (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
5557 (res (read-file-name prompt default-directory "" nil)))
5558 (while (cond ((not (file-exists-p res))
5559 (ding)
5560 (setq prompt "doesn't exist"))
5561 ((not (file-readable-p res))
5562 (ding)
5563 (setq prompt "is unreadable"))
5564 ((file-directory-p res)
5565 (ding)
5566 (setq prompt "is a directory"))
5567 (t nil))
5568 (setq res (read-file-name
5569 (format "File %s; PostScript file: " prompt)
5570 (file-name-directory res) nil nil
5571 (file-name-nondirectory res))))
5572 (pr-expand-file-name res)))
5573
5574
2c840b90 5575(defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
9f7a9918 5576 ;; check arguments for PostScript file processing.
2c840b90
KS
5577 ;; n-up
5578 (or (symbol-value n-up-sym)
5579 (set n-up-sym (pr-interactive-n-up prompt)))
2c840b90 5580 ;; input file
9f7a9918
VJL
5581 (and (eq (symbol-value infile-sym) t)
5582 (set infile-sym (pr-ps-infile-preprint prompt)))
2c840b90
KS
5583 (or (symbol-value infile-sym)
5584 (error "%s: input PostScript file name is missing" prompt))
0117451d 5585 (set infile-sym (pr-dosify-file-name (symbol-value infile-sym)))
2c840b90
KS
5586 ;; output file
5587 (and (eq (symbol-value outfile-sym) t)
9f7a9918 5588 (set outfile-sym (and current-prefix-arg
2c840b90
KS
5589 (pr-ps-outfile-preprint prompt))))
5590 (and (symbol-value outfile-sym)
0117451d 5591 (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym))))
2c840b90
KS
5592 (pr-ps-file (symbol-value outfile-sym)))
5593
5594
5595(defun pr-ps-utility-process (n-up infile outfile)
9f7a9918 5596 ;; activate utility to process a PostScript file.
2c840b90
KS
5597 (let (item)
5598 (and (stringp infile) (file-exists-p infile)
5599 (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
45f17557
VJL
5600 (pr-call-process (nth 0 item)
5601 (pr-switches-string (nth 1 item)
5602 "pr-ps-utility-alist entry")
5603 (pr-switches-string (nth 8 item)
5604 "pr-ps-utility-alist entry")
5605 (and (nth 2 item)
5606 (format (nth 2 item) ps-paper-type))
5607 (format (nth 3 item) n-up)
5608 (and pr-file-landscape (nth 4 item))
5609 (and pr-file-duplex (nth 5 item))
5610 (and pr-file-tumble (nth 6 item))
5611 (pr-expand-file-name infile)
5612 (nth 7 item)
5613 (pr-expand-file-name outfile)))))
5614
5615
5616(defun pr-remove-nil-from-list (lst)
5617 (while (and lst (null (car lst)))
5618 (setq lst (cdr lst)))
5619 (let ((b lst)
5620 (l (cdr lst)))
5621 (while l
5622 (if (car l)
5623 (setq b l
5624 l (cdr l))
5625 (setq l (cdr l))
5626 (setcdr b l))))
5627 lst)
5628
5629
5630(defun pr-call-process (command &rest args)
14b84c94
VJL
5631 (let ((buffer (get-buffer-create "*Printing Command Output*"))
5632 (cmd (pr-command command))
5633 status)
5634 (setq args (pr-remove-nil-from-list args))
5635 ;; *Printing Command Output* == show command & args
7fdbcd83 5636 (with-current-buffer buffer
14b84c94
VJL
5637 (goto-char (point-max))
5638 (insert (format "%s %S\n" cmd args)))
5639 ;; *Printing Command Output* == show any return message from command
d63d883a
GM
5640 (with-file-modes pr-file-modes
5641 (setq status
5642 (condition-case data
5643 (apply 'call-process cmd nil buffer nil args)
5644 ((quit error)
5645 (error-message-string data)))))
14b84c94 5646 ;; *Printing Command Output* == show exit status
7fdbcd83 5647 (with-current-buffer buffer
14b84c94
VJL
5648 (goto-char (point-max))
5649 (insert (format "Exit status: %s\n\n" status)))
5650 ;; message if error status
5651 (if (or (stringp status)
5652 (and (integerp status) (/= status 0)))
5653 (message
5654 "Printing error status: %s (see *Printing Command Output* buffer)"
5655 status))))
2c840b90
KS
5656
5657
5658(defun pr-txt-print (from to)
0117451d 5659 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command)))
2c840b90
KS
5660 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
5661 (printer-name pr-txt-printer))
5662 (lpr-region from to)))
5663
5664
5665(defun pr-switches-string (switches mess)
14b84c94
VJL
5666 ;; If SWITCHES is nil, return nil.
5667 ;; Otherwise, return the list of string in a string.
5668 (and switches
5669 (mapconcat 'identity (pr-switches switches mess) " ")))
2c840b90
KS
5670
5671
5672(defun pr-switches (switches mess)
5673 (or (listp switches)
747aa4cf 5674 (error "%S should have a list of strings" mess))
ff65ca0d 5675 (lpr-flatten-list ; dynamic evaluation
2c840b90
KS
5676 (mapcar 'ps-eval-switch switches)))
5677
5678
5679(defun pr-ps-preview (kind n-up filename mess)
5680 (pr-set-n-up-and-filename 'n-up 'filename mess)
5681 (let ((file (pr-ps-file filename)))
5682 (pr-text2ps kind n-up file)
5683 (or pr-spool-p (pr-ps-file-preview file))))
5684
5685
5686(defun pr-ps-using-ghostscript (kind n-up filename mess)
5687 (pr-set-n-up-and-filename 'n-up 'filename mess)
5688 (let ((file (pr-ps-file filename)))
5689 (pr-text2ps kind n-up file)
5690 (unless (or pr-spool-p filename)
5691 (pr-ps-file-using-ghostscript file)
5692 (pr-delete-file file))))
5693
5694
5695(defun pr-ps-print (kind n-up filename mess)
5696 (pr-set-n-up-and-filename 'n-up 'filename mess)
5697 (let ((file (pr-ps-file filename)))
5698 (pr-text2ps kind n-up file)
5699 (unless (or pr-spool-p filename)
5700 (pr-ps-file-print file)
5701 (pr-delete-file file))))
5702
5703
5704(defun pr-ps-file (&optional filename)
0117451d 5705 (pr-dosify-file-name (or filename
9f7a9918
VJL
5706 (make-temp-file
5707 (convert-standard-filename
5708 (expand-file-name pr-ps-temp-file pr-temp-dir))
5709 nil ".ps"))))
2c840b90
KS
5710
5711
5712(defun pr-interactive-n-up (mess)
5713 (or (stringp mess) (setq mess "*"))
5714 (save-match-data
5b76833f 5715 (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
2c840b90 5716 (prompt "")
06005961 5717 (str (pr-read-string (format fmt-prompt prompt mess) "1" nil "1"))
2c840b90
KS
5718 int)
5719 (while (if (string-match "^\\s *[0-9]+$" str)
ff4ed9e5 5720 (setq int (string-to-number str)
2c840b90
KS
5721 prompt (cond ((< int 1) "Integer below 1; ")
5722 ((> int 100) "Integer above 100; ")
5723 (t nil)))
5724 (setq prompt "Invalid integer syntax; "))
5725 (ding)
5726 (setq str
06005961 5727 (pr-read-string (format fmt-prompt prompt mess) str nil "1")))
2c840b90
KS
5728 int)))
5729
5730
5731(defun pr-interactive-dir (mess)
5732 (let* ((dir-name (file-name-directory (or (buffer-file-name)
5733 default-directory)))
5734 (fmt-prompt (concat "%s[" mess "] Directory to print: "))
7e27ce9c
AL
5735 (dir (read-directory-name (format fmt-prompt "")
5736 "" dir-name nil dir-name))
2c840b90
KS
5737 prompt)
5738 (while (cond ((not (file-directory-p dir))
5739 (ding)
5740 (setq prompt "It's not a directory! "))
5741 ((not (file-readable-p dir))
5742 (ding)
5743 (setq prompt "Directory is unreadable! "))
5744 (t nil))
5745 (setq dir-name (file-name-directory dir)
7e27ce9c
AL
5746 dir (read-directory-name (format fmt-prompt prompt)
5747 "" dir-name nil dir-name)))
2c840b90
KS
5748 (file-name-as-directory dir)))
5749
5750
5751(defun pr-interactive-regexp (mess)
06005961 5752 (pr-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
2c840b90
KS
5753
5754
5755(defun pr-interactive-dir-args (mess)
5756 (list
5757 ;; get directory argument
5758 (pr-interactive-dir mess)
5759 ;; get file name regexp
5760 (pr-interactive-regexp mess)))
5761
5762
5763(defun pr-interactive-ps-dir-args (mess)
5764 (list
5765 ;; get n-up argument
5766 (pr-interactive-n-up mess)
5767 ;; get directory argument
5768 (pr-interactive-dir mess)
5769 ;; get file name regexp
5770 (pr-interactive-regexp mess)
5771 ;; get output file name
5772 (and (not pr-spool-p)
5773 (ps-print-preprint current-prefix-arg))))
5774
5775
5776(defun pr-interactive-n-up-file (mess)
5777 (list
5778 ;; get n-up argument
5779 (pr-interactive-n-up mess)
5780 ;; get output file name
5781 (and (not pr-spool-p)
5782 (ps-print-preprint current-prefix-arg))))
5783
5784
5785(defun pr-interactive-n-up-inout (mess)
5786 (list
5787 ;; get n-up argument
5788 (pr-interactive-n-up mess)
5789 ;; get input file name
5790 (pr-ps-infile-preprint (concat mess " "))
5791 ;; get output file name
5792 (ps-print-preprint current-prefix-arg)))
5793
5794
5795(defun pr-set-outfilename (filename-sym)
5796 (and (not pr-spool-p)
5797 (eq (symbol-value filename-sym) t)
9f7a9918 5798 (set filename-sym (and current-prefix-arg
2c840b90
KS
5799 (ps-print-preprint current-prefix-arg))))
5800 (and (symbol-value filename-sym)
0117451d 5801 (set filename-sym (pr-dosify-file-name (symbol-value filename-sym)))))
2c840b90
KS
5802
5803
5804(defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
5805 ;; n-up
5806 (or (symbol-value n-up-sym)
5807 (set n-up-sym (pr-interactive-n-up mess)))
5808 ;; output file
5809 (pr-set-outfilename filename-sym))
5810
5811
5812(defun pr-set-dir-args (dir-sym regexp-sym mess)
5813 ;; directory
5814 (or (symbol-value dir-sym)
5815 (set dir-sym (pr-interactive-dir mess)))
5816 ;; file name regexp
5817 (or (symbol-value regexp-sym)
5818 (set regexp-sym (pr-interactive-regexp mess))))
5819
5820
5821(defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
5822 ;; n-up
5823 (or (symbol-value n-up-sym)
5824 (set n-up-sym (pr-interactive-n-up mess)))
5825 ;; directory & file name regexp
5826 (pr-set-dir-args dir-sym regexp-sym mess)
5827 ;; output file
5828 (pr-set-outfilename filename-sym))
5829
5830
5831(defun pr-find-buffer-visiting (file)
5832 (if (not (file-directory-p file))
d100084b 5833 (find-buffer-visiting (if lpr-windows-system
2c840b90
KS
5834 (downcase file)
5835 file))
5836 (let ((truename (file-truename file))
5837 (blist (buffer-list))
5838 found)
5839 (while (and (not found) blist)
7fdbcd83 5840 (with-current-buffer (car blist)
2c840b90
KS
5841 (and (eq major-mode 'dired-mode)
5842 (save-excursion
5843 (goto-char (point-min))
5844 (string= (buffer-substring-no-properties
5845 (+ (point-min) 2)
5846 (progn
5847 (end-of-line)
5848 (1- (point))))
5849 truename))
5850 (setq found (car blist))))
5851 (setq blist (cdr blist)))
5852 found)))
5853
5854
5855(defun pr-file-list (dir file-regexp fun)
5856 (mapcar #'(lambda (file)
5857 (and (or pr-list-directory
5858 (not (file-directory-p file)))
5859 (let ((buffer (pr-find-buffer-visiting file))
5860 pop-up-windows
5861 pop-up-frames)
5862 (and (or buffer
5863 (file-readable-p file))
7fdbcd83
SM
5864 (with-current-buffer (or buffer
5865 (find-file-noselect file))
2c840b90
KS
5866 (funcall fun)
5867 (or buffer
5868 (kill-buffer (current-buffer))))))))
5869 (directory-files dir t file-regexp)))
5870
5871
5872(defun pr-delete-file-if-exists (filename)
5873 (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
5874 (delete-file filename)))
5875
5876
5877(defun pr-ps-file-list (n-up dir file-regexp filename)
5878 (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
5879 (let ((pr-spool-p t))
5880 (pr-file-list dir file-regexp
5881 #'(lambda ()
5882 (if (pr-auto-mode-p)
5883 (pr-ps-mode n-up filename)
5884 (pr-text2ps 'buffer n-up filename)))))
5885 (or pr-spool-p
5886 (pr-despool-print filename)))
5887
5888
5889(defun pr-text2ps (kind n-up filename &optional from to)
d63d883a
GM
5890 (with-file-modes pr-file-modes
5891 (let ((ps-n-up-printing n-up)
5892 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5893 'setpagedevice)))
5894 (pr-delete-file-if-exists filename)
5895 (cond (pr-faces-p
5896 (cond (pr-spool-p
5897 ;; pr-faces-p and pr-spool-p
5898 ;; here FILENAME arg is ignored
5899 (cond ((eq kind 'buffer)
5900 (ps-spool-buffer-with-faces))
5901 ((eq kind 'region)
5902 (ps-spool-region-with-faces (or from (point))
5903 (or to (mark))))
5904 ))
5905 ;; pr-faces-p and not pr-spool-p
5906 ((eq kind 'buffer)
5907 (ps-print-buffer-with-faces filename))
5908 ((eq kind 'region)
5909 (ps-print-region-with-faces (or from (point))
5910 (or to (mark)) filename))
5911 ))
5912 (pr-spool-p
5913 ;; not pr-faces-p and pr-spool-p
5914 ;; here FILENAME arg is ignored
5915 (cond ((eq kind 'buffer)
5916 (ps-spool-buffer))
5917 ((eq kind 'region)
5918 (ps-spool-region (or from (point)) (or to (mark))))
5919 ))
5920 ;; not pr-faces-p and not pr-spool-p
5921 ((eq kind 'buffer)
5922 (ps-print-buffer filename))
5923 ((eq kind 'region)
5924 (ps-print-region (or from (point)) (or to (mark)) filename))
5925 ))))
2c840b90
KS
5926
5927
5928(defun pr-command (command)
5929 "Return absolute file name specification for COMMAND.
5930
449cba44
VJL
5931If COMMAND is an empty string, return it.
5932
2c840b90
KS
5933If COMMAND is already an absolute file name specification, return it.
5934Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
5935otherwise, gives an error.
5936
5937When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
5938`unix' are used (see `pr-path-alist' for documentation).
5939
5940If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
5941COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
449cba44
VJL
5942 (if (string= command "")
5943 command
0117451d 5944 (pr-dosify-file-name
449cba44
VJL
5945 (or (pr-find-command command)
5946 (pr-path-command (cond (pr-cygwin-system 'cygwin)
d100084b 5947 (lpr-windows-system 'windows)
449cba44
VJL
5948 (t 'unix))
5949 (file-name-nondirectory command)
5950 nil)
5951 (error "Command not found: %s"
5952 (file-name-nondirectory command))))))
2c840b90
KS
5953
5954
5955(defun pr-path-command (symbol command sym-list)
5956 (let ((lpath (cdr (assq symbol pr-path-alist)))
5957 cmd)
5958 ;; PATH expansion
5959 (and (eq symbol 'PATH) (null lpath)
5960 (setq lpath (parse-colon-path (getenv "PATH"))))
5961 (while (and lpath
5962 (not
5963 (setq cmd
5964 (let ((path (car lpath)))
5965 (cond
5966 ;; symbol expansion
5967 ((symbolp path)
5968 (and (not (memq path sym-list))
5969 (pr-path-command path command
5970 (cons path sym-list))))
5971 ;; normal path
5972 ((stringp path)
5973 (pr-find-command
5974 (expand-file-name
5975 (substitute-in-file-name
5976 (concat (file-name-as-directory path)
5977 command)))))
5978 )))))
5979 (setq lpath (cdr lpath)))
5980 cmd))
5981
5982
5983(defun pr-find-command (cmd)
d100084b 5984 (if lpr-windows-system
2c840b90
KS
5985 ;; windows system
5986 (let ((ext (cons (file-name-extension cmd t)
5987 (list ".exe" ".bat" ".com")))
5988 found)
5989 (setq cmd (file-name-sans-extension cmd))
5990 (while (and ext
5991 (setq found (concat cmd (car ext)))
5992 (not (and (file-regular-p found)
5993 (file-executable-p found))))
5994 (setq ext (cdr ext)
5995 found nil))
5996 found)
5997 ;; non-windows systems
5998 (and (file-regular-p cmd)
5999 (file-executable-p cmd)
6000 cmd)))
6001
6002
6003;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
316be4e8 6004;; Printing Interface (inspired by ps-print-interface.el)
2c840b90
KS
6005
6006
a7e2b28d
VJL
6007(eval-when-compile
6008 (require 'cus-edit)
6009 (require 'wid-edit)
6010 (require 'widget))
2c840b90
KS
6011
6012
6013(defvar pr-i-window-configuration nil)
6014
6015(defvar pr-i-buffer nil)
6016(defvar pr-i-region nil)
6017(defvar pr-i-mode nil)
6018(defvar pr-i-despool nil)
6019(defvar pr-i-ps-as-is t)
6020(defvar pr-i-n-up 1)
6021(defvar pr-i-directory "./")
6022(defvar pr-i-regexp "")
6023(defvar pr-i-ps-file "")
6024(defvar pr-i-out-file "")
6025(defvar pr-i-answer-yes nil)
6026(defvar pr-i-process 'buffer)
6027(defvar pr-i-ps-send 'printer)
6028
6029
6030(defvar pr-interface-map nil
6031 "Keymap for pr-interface.")
6032
9f7a9918 6033(unless pr-interface-map
06005961
VJL
6034 (let ((map (make-sparse-keymap)))
6035 (cond ((featurep 'xemacs) ; XEmacs
6036 (pr-set-keymap-parents map (list widget-keymap))
6037 (pr-set-keymap-name map 'pr-interface-map))
6038 (t ; GNU Emacs
6039 (pr-set-keymap-parents map widget-keymap)))
6040 (define-key map "q" 'pr-interface-quit)
6041 (define-key map "?" 'pr-interface-help)
6042 (setq pr-interface-map map)))
2c840b90
KS
6043
6044
6045(defmacro pr-interface-save (&rest body)
7fdbcd83 6046 `(with-current-buffer pr-i-buffer
2c840b90
KS
6047 ,@body))
6048
6049
6050(defun pr-create-interface ()
6051 "Create the front end for printing package."
6052 (setq pr-i-buffer (buffer-name (current-buffer))
6053 pr-i-region (ps-mark-active-p)
6054 pr-i-mode (pr-mode-alist-p)
6055 pr-i-window-configuration (current-window-configuration))
6056
6057 (put 'pr-i-process 'pr-widget-list nil)
6058 (put 'pr-i-ps-send 'pr-widget-list nil)
6059
6060 (delete-other-windows)
6061 (kill-buffer (get-buffer-create pr-buffer-name))
6062 (switch-to-buffer (get-buffer-create pr-buffer-name))
6063
6064 ;; header
6065 (let ((versions (concat "printing v" pr-version
6066 " ps-print v" ps-print-version)))
0695be6f
VJL
6067 ;; to keep compatibility with Emacs 20 & 21:
6068 ;; DO NOT REPLACE `?\ ' BY `?\s'
6069 (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
2c840b90
KS
6070 (pr-insert-italic "\nCurrent Directory : " 1)
6071 (pr-insert-italic default-directory)
6072
6073 (pr-insert-section-1) ; 1. Print
6074 (pr-insert-section-2) ; 2. PostScript Printer
6075 (pr-insert-section-3) ; 3. Text Printer
6076
6077 ;; separator
6078 (widget-insert "\n\n " (make-string 77 ?-))
6079
6080 (pr-insert-section-4) ; 4. Settings
6081 (pr-insert-section-5) ; 5. Customize
6082 (pr-insert-section-6) ; 6. Show Settings
6083 (pr-insert-section-7) ; 7. Help
6084
6085 (use-local-map pr-interface-map)
6086 (widget-setup)
6087 (goto-char (point-min))
6088
6089 (and pr-i-region ; let region activated
6090 (pr-keep-region-active)))
6091
d7fe6352
JB
6092(declare-function widget-field-action "wid-edit" (widget &optional _event))
6093(declare-function widget-value-set "wid-edit" (widget value))
2c840b90
KS
6094
6095(defun pr-insert-section-1 ()
6096 ;; 1. Print:
6097 (pr-insert-italic "\nPrint :" 1)
6098
6099 ;; 1a. Buffer:
6100 ;; 1a. Buffer: Buffer List
6101 (pr-insert-radio-button 'pr-i-process 'buffer)
6102 (pr-insert-menu "Buffer List" 'pr-i-buffer
6103 (let ((blist (buffer-list))
6104 case-fold-search choices)
6105 (while blist
6106 (let ((name (buffer-name (car blist)))
6107 (ignore pr-buffer-name-ignore)
6108 found)
6109 (setq blist (cdr blist))
6110 (while (and ignore (not found))
6111 (setq found (string-match (car ignore) name)
6112 ignore (cdr ignore)))
6113 (or found
6114 (setq choices
6115 (cons (list 'quote
6116 (list 'choice-item
6117 :format "%[%t%]"
6118 name))
6119 choices)))))
6120 (nreverse choices))
6121 " Buffer : " nil
6122 '(progn
6123 (pr-interface-save
6124 (setq pr-i-region (ps-mark-active-p)
6125 pr-i-mode (pr-mode-alist-p)))
6126 (pr-update-checkbox 'pr-i-region)
6127 (pr-update-checkbox 'pr-i-mode)))
6128 ;; 1a. Buffer: Region
6129 (put 'pr-i-region 'pr-widget
6130 (pr-insert-checkbox
6131 "\n "
6132 'pr-i-region
6c42fc3e 6133 #'(lambda (widget &rest _ignore)
2c840b90
KS
6134 (let ((region-p (pr-interface-save
6135 (ps-mark-active-p))))
6136 (cond ((null (widget-value widget)) ; widget is nil
6137 (setq pr-i-region nil))
6138 (region-p ; widget is true and there is a region
6139 (setq pr-i-region t)
6140 (widget-value-set widget t)
6141 (widget-setup)) ; MUST be called after widget-value-set
6142 (t ; widget is true and there is no region
6143 (ding)
6144 (message "There is no region active")
6145 (setq pr-i-region nil)
6146 (widget-value-set widget nil)
6147 (widget-setup))))) ; MUST be called after widget-value-set
6148 " Region"))
6149 ;; 1a. Buffer: Mode
6150 (put 'pr-i-mode 'pr-widget
6151 (pr-insert-checkbox
6152 " "
6153 'pr-i-mode
6c42fc3e 6154 #'(lambda (widget &rest _ignore)
2c840b90
KS
6155 (let ((mode-p (pr-interface-save
6156 (pr-mode-alist-p))))
6157 (cond
6158 ((null (widget-value widget)) ; widget is nil
6159 (setq pr-i-mode nil))
6160 (mode-p ; widget is true and there is a `mode'
6161 (setq pr-i-mode t)
6162 (widget-value-set widget t)
6163 (widget-setup)) ; MUST be called after widget-value-set
6164 (t ; widget is true and there is no `mode'
6165 (ding)
6166 (message
6167 "This buffer isn't in a mode that printing treats specially.")
6168 (setq pr-i-mode nil)
6169 (widget-value-set widget nil)
6170 (widget-setup))))) ; MUST be called after widget-value-set
6171 " Mode\n"))
6172
6173 ;; 1b. Directory:
6174 (pr-insert-radio-button 'pr-i-process 'directory)
6175 (widget-create
6176 'directory
6177 :size 58
6178 :format " Directory : %v"
6179 :notify 'pr-interface-directory
6180 :action (lambda (widget &optional event)
6181 (if (pr-interface-directory widget)
6182 (pr-widget-field-action widget event)
6183 (ding)
449cba44 6184 (message "Please specify a readable directory")))
2c840b90
KS
6185 pr-i-directory)
6186 ;; 1b. Directory: File Regexp
6187 (widget-create 'regexp
6188 :size 58
6189 :format "\n File Regexp : %v\n"
6c42fc3e 6190 :notify (lambda (widget &rest _ignore)
2c840b90
KS
6191 (setq pr-i-regexp (widget-value widget)))
6192 pr-i-regexp)
6193 ;; 1b. Directory: List Directory Entry
6194 (widget-insert " ")
6195 (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
6196
6197 ;; 1c. PostScript File:
6198 (pr-insert-radio-button 'pr-i-process 'file)
6199 (widget-create
6200 'file
6201 :size 51
6202 :format " PostScript File : %v"
6203 :notify 'pr-interface-infile
6204 :action (lambda (widget &rest event)
6205 (if (pr-interface-infile widget)
6206 (pr-widget-field-action widget event)
6207 (ding)
449cba44 6208 (message "Please specify a readable PostScript file")))
2c840b90
KS
6209 pr-i-ps-file)
6210 ;; 1c. PostScript File: PostScript Utility
6211 (pr-insert-menu "PostScript Utility" 'pr-ps-utility
6212 (pr-choice-alist pr-ps-utility-alist)
6213 "\n PostScript Utility : "
6214 " ")
b8d955f4
VJL
6215 ;; 1c. PostScript File: No Preprocessing
6216 (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
2c840b90
KS
6217
6218
6219(defun pr-insert-section-2 ()
6220 ;; 2. PostScript Printer:
6221 ;; 2. PostScript Printer: PostScript Printer List
6222 (pr-insert-italic "\n\nPostScript Printer : " 2 20)
6223 (pr-insert-menu "PostScript Printer" 'pr-ps-name
6224 (pr-choice-alist pr-ps-printer-alist))
6225 ;; 2. PostScript Printer: Despool
6226 (put 'pr-i-despool 'pr-widget
6227 (pr-insert-checkbox
6228 " "
6229 'pr-i-despool
6c42fc3e 6230 #'(lambda (widget &rest _ignore)
2c840b90
KS
6231 (if pr-spool-p
6232 (setq pr-i-despool (not pr-i-despool))
6233 (ding)
449cba44 6234 (message "Can despool only when spooling is actually selected")
2c840b90
KS
6235 (setq pr-i-despool nil))
6236 (widget-value-set widget pr-i-despool)
6237 (widget-setup)) ; MUST be called after widget-value-set
6238 " Despool "))
6239 ;; 2. PostScript Printer: Preview Print Quit
6240 (pr-insert-button 'pr-interface-preview "Preview" " ")
6241 (pr-insert-button 'pr-interface-ps-print "Print" " ")
6242 (pr-insert-button 'pr-interface-quit "Quit")
6243 ;; 2. PostScript Printer: Send to Printer/Temporary File
6244 (pr-insert-radio-button 'pr-i-ps-send 'printer)
6245 (widget-insert " Send to Printer/Temporary File")
6246 ;; 2. PostScript Printer: Send to File
6247 (pr-insert-radio-button 'pr-i-ps-send 'file)
6248 (widget-create
6249 'file
6250 :size 57
6251 :format " Send to File : %v"
6252 :notify 'pr-interface-outfile
6253 :action (lambda (widget &rest event)
6254 (if (and (pr-interface-outfile widget)
6255 (or (not (file-exists-p pr-i-out-file))
6256 (setq pr-i-answer-yes
6257 (y-or-n-p "File exists; overwrite? "))))
6258 (pr-widget-field-action widget event)
6259 (ding)
449cba44 6260 (message "Please specify a writable PostScript file")))
2c840b90
KS
6261 pr-i-out-file)
6262 ;; 2. PostScript Printer: N-Up
6263 (widget-create
6264 'integer
6265 :size 3
6266 :format "\n N-Up : %v"
6c42fc3e 6267 :notify (lambda (widget &rest _ignore)
2c840b90
KS
6268 (let ((value (if (string= (widget-apply widget :value-get) "")
6269 0
6270 (widget-value widget))))
6271 (if (and (integerp value)
6272 (<= 1 value) (<= value 100))
6273 (progn
6274 (message " ")
6275 (setq pr-i-n-up value))
6276 (ding)
449cba44 6277 (message "Please specify an integer between 1 and 100"))))
2c840b90
KS
6278 pr-i-n-up))
6279
6280
6281(defun pr-insert-section-3 ()
6282 ;; 3. Text Printer:
6283 (pr-insert-italic "\n\nText Printer : " 2 14)
6284 (pr-insert-menu "Text Printer" 'pr-txt-name
6285 (pr-choice-alist pr-txt-printer-alist)
6286 nil " ")
6287 (pr-insert-button 'pr-interface-printify "Printify" " ")
6288 (pr-insert-button 'pr-interface-txt-print "Print" " ")
6289 (pr-insert-button 'pr-interface-quit "Quit"))
6290
6291
6292(defun pr-insert-section-4 ()
6293 ;; 4. Settings:
6294 ;; 4. Settings: Landscape Auto Region Verbose
6295 (pr-insert-checkbox "\n\n " 'ps-landscape-mode
6c42fc3e 6296 #'(lambda (&rest _ignore)
2c840b90
KS
6297 (setq ps-landscape-mode (not ps-landscape-mode)
6298 pr-file-landscape ps-landscape-mode))
6299 " Landscape ")
6300 (pr-insert-toggle 'pr-auto-region " Auto Region ")
6301 (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
6302
6303 ;; 4. Settings: Print Header Auto Mode
6304 (pr-insert-toggle 'ps-print-header " Print Header ")
6305 (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
6306
6307 ;; 4. Settings: Print Header Frame Menu Lock
6308 (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
6309 (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
6310
6311 ;; 4. Settings: Line Number
6312 (pr-insert-toggle 'ps-line-number " Line Number\n ")
6313
6314 ;; 4. Settings: Zebra Stripes Spool Buffer
6315 (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
6316 (pr-insert-checkbox " "
6317 'pr-spool-p
6c42fc3e 6318 #'(lambda (&rest _ignore)
2c840b90
KS
6319 (setq pr-spool-p (not pr-spool-p))
6320 (unless pr-spool-p
6321 (setq pr-i-despool nil)
6322 (pr-update-checkbox 'pr-i-despool)))
6323 " Spool Buffer")
6324
449cba44 6325 ;; 4. Settings: Duplex Print with faces
2c840b90
KS
6326 (pr-insert-checkbox "\n "
6327 'ps-spool-duplex
6c42fc3e 6328 #'(lambda (&rest _ignore)
2c840b90
KS
6329 (setq ps-spool-duplex (not ps-spool-duplex)
6330 pr-file-duplex ps-spool-duplex))
6331 " Duplex ")
449cba44 6332 (pr-insert-toggle 'pr-faces-p " Print with faces")
2c840b90 6333
449cba44 6334 ;; 4. Settings: Tumble Print via Ghostscript
2c840b90
KS
6335 (pr-insert-checkbox "\n "
6336 'ps-spool-tumble
6c42fc3e 6337 #'(lambda (&rest _ignore)
2c840b90
KS
6338 (setq ps-spool-tumble (not ps-spool-tumble)
6339 pr-file-tumble ps-spool-tumble))
6340 " Tumble ")
449cba44 6341 (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
2c840b90
KS
6342
6343 ;; 4. Settings: Upside-Down Page Parity
acc037ba
VJL
6344 (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
6345 (pr-insert-italic "\n\nSelect Pages : " 2 14)
2c840b90
KS
6346 (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
6347 (mapcar #'(lambda (alist)
6348 (list 'quote
6349 (list 'choice-item
6350 :format "%[%t%]"
6351 :tag (cdr alist)
6352 :value (car alist))))
6353 pr-even-or-odd-alist)))
6354
6355
6356(defun pr-insert-section-5 ()
6357 ;; 5. Customize:
6358 (pr-insert-italic "\n\nCustomize : " 2 11)
6359 (pr-insert-button 'pr-customize "printing" " ")
6c42fc3e 6360 (pr-insert-button #'(lambda (&rest _ignore) (ps-print-customize))
2c840b90
KS
6361 "ps-print" " ")
6362 (pr-insert-button 'lpr-customize "lpr"))
6363
6364
6365(defun pr-insert-section-6 ()
6366 ;; 6. Show Settings:
6367 (pr-insert-italic "\nShow Settings : " 1 14)
6368 (pr-insert-button 'pr-show-pr-setup "printing" " ")
6369 (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
6370 (pr-insert-button 'pr-show-lpr-setup "lpr"))
6371
6372
6373(defun pr-insert-section-7 ()
6374 ;; 7. Help:
6375 (pr-insert-italic "\nHelp : " 1 5)
6376 (pr-insert-button 'pr-interface-help "Interface Help" " ")
6377 (pr-insert-button 'pr-help "Menu Help" " ")
6378 (pr-insert-button 'pr-interface-quit "Quit" "\n ")
6379 (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
6380
6381
6c42fc3e 6382(defun pr-kill-help (&rest _ignore)
2c840b90
KS
6383 "Kill all printing help buffer."
6384 (interactive)
6385 (let ((help '("*Printing Interface Help*" "*Printing Help*"
6386 "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
6387 (while help
6388 (let ((buffer (get-buffer (car help))))
6389 (setq help (cdr help))
6390 (when buffer
6391 (delete-windows-on buffer)
6392 (kill-buffer buffer)))))
6393 (recenter (- (window-height) 2)))
6394
6395
6c42fc3e 6396(defun pr-interface-quit (&rest _ignore)
2c840b90
KS
6397 "Kill the printing buffer interface and quit."
6398 (interactive)
6399 (kill-buffer pr-buffer-name)
6400 (set-window-configuration pr-i-window-configuration))
6401
6402
6c42fc3e 6403(defun pr-interface-help (&rest _ignore)
2c840b90
KS
6404 "printing buffer interface help."
6405 (interactive)
6406 (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
6407
6408
6c42fc3e 6409(defun pr-interface-txt-print (&rest _ignore)
2c840b90
KS
6410 "Print using lpr package."
6411 (interactive)
6412 (condition-case data
6413 (cond
6414 ((eq pr-i-process 'directory)
6415 (pr-i-directory)
6416 (pr-interface-save
6417 (pr-txt-directory pr-i-directory pr-i-regexp)))
6418 ((eq pr-i-process 'buffer)
6419 (pr-interface-save
6420 (cond (pr-i-region
6421 (let ((pr-auto-mode pr-i-mode))
6422 (pr-txt-region)))
6423 (pr-i-mode
6424 (let (pr-auto-region)
6425 (pr-txt-mode)))
6426 (t
6427 (let (pr-auto-mode pr-auto-region)
6428 (pr-txt-buffer)))
6429 )))
6430 ((eq pr-i-process 'file)
449cba44 6431 (error "Please specify a text file"))
2c840b90
KS
6432 (t
6433 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6434 )
6435 ;; handlers
6436 ((quit error)
6437 (ding)
8a26c165 6438 (message "%s" (error-message-string data)))))
2c840b90
KS
6439
6440
6c42fc3e 6441(defun pr-interface-printify (&rest _ignore)
2c840b90
KS
6442 "Printify a buffer."
6443 (interactive)
6444 (condition-case data
6445 (cond
6446 ((eq pr-i-process 'directory)
6447 (pr-i-directory)
6448 (pr-interface-save
6449 (pr-printify-directory pr-i-directory pr-i-regexp)))
6450 ((eq pr-i-process 'buffer)
6451 (pr-interface-save
6452 (if pr-i-region
6453 (pr-printify-region)
6454 (pr-printify-buffer))))
6455 ((eq pr-i-process 'file)
449cba44 6456 (error "Cannot printify a PostScript file"))
2c840b90
KS
6457 (t
6458 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6459 )
6460 ;; handlers
6461 ((quit error)
6462 (ding)
8a26c165 6463 (message "%s" (error-message-string data)))))
2c840b90
KS
6464
6465
6c42fc3e 6466(defun pr-interface-ps-print (&rest _ignore)
2c840b90
KS
6467 "Print using ps-print package."
6468 (interactive)
9f7a9918
VJL
6469 (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
6470 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
6471 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
6472 'pr-ps-buffer-ps-print))
2c840b90
KS
6473
6474
6c42fc3e 6475(defun pr-interface-preview (&rest _ignore)
2c840b90
KS
6476 "Preview a PostScript file."
6477 (interactive)
9f7a9918
VJL
6478 (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
6479 'pr-ps-file-preview 'pr-ps-file-up-preview
6480 'pr-ps-region-preview 'pr-ps-mode-preview
6481 'pr-ps-buffer-preview))
2c840b90
KS
6482
6483
6484(defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
6485 ps-mode ps-buffer)
6486 (condition-case data
6487 (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
6488 (pr-i-ps-send))))
6489 (cond
6490 ((and pr-i-despool pr-spool-p)
6491 (pr-interface-save
6492 (funcall ps-despool outfile))
6493 (setq pr-i-despool nil)
6494 (pr-update-checkbox 'pr-i-despool))
6495 ((eq pr-i-process 'directory)
6496 (pr-i-directory)
6497 (pr-interface-save
6498 (funcall ps-directory
6499 pr-i-n-up pr-i-directory pr-i-regexp outfile)))
6500 ((eq pr-i-process 'file)
6501 (cond ((or (file-directory-p pr-i-ps-file)
6502 (not (file-readable-p pr-i-ps-file)))
449cba44 6503 (error "Please specify a readable PostScript file"))
2c840b90
KS
6504 (pr-i-ps-as-is
6505 (pr-interface-save
6506 (funcall ps-file pr-i-ps-file)))
6507 (t
6508 (pr-interface-save
6509 (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
6510 ))
6511 ((eq pr-i-process 'buffer)
6512 (pr-interface-save
6513 (cond (pr-i-region
6514 (let ((pr-auto-mode pr-i-mode))
6515 (funcall ps-region pr-i-n-up outfile)))
6516 (pr-i-mode
6517 (let (pr-auto-region)
6518 (funcall ps-mode pr-i-n-up outfile)))
6519 (t
6520 (let (pr-auto-mode pr-auto-region)
6521 (funcall ps-buffer pr-i-n-up outfile)))
6522 )))
6523 (t
6524 (error "Internal error: `pr-i-process' = %S" pr-i-process))
6525 ))
6526 ;; handlers
6527 ((quit error)
6528 (ding)
8a26c165 6529 (message "%s" (error-message-string data)))))
2c840b90
KS
6530
6531
6532(defun pr-i-ps-send ()
6533 (cond ((eq pr-i-ps-send 'printer)
6534 nil)
6535 ((not (eq pr-i-ps-send 'file))
6536 (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
6537 ((or (file-directory-p pr-i-out-file)
6538 (not (file-writable-p pr-i-out-file)))
449cba44 6539 (error "Please specify a writable PostScript file"))
2c840b90
KS
6540 ((or (not (file-exists-p pr-i-out-file))
6541 pr-i-answer-yes
6542 (setq pr-i-answer-yes
6543 (y-or-n-p (format "File `%s' exists; overwrite? "
6544 pr-i-out-file))))
6545 pr-i-out-file)
6546 (t
6547 (error "File already exists"))))
6548
6549
6550(defun pr-i-directory ()
1d75432d 6551 (or (file-accessible-directory-p pr-i-directory)
449cba44 6552 (error "Please specify be a readable directory")))
2c840b90
KS
6553
6554
6c42fc3e 6555(defun pr-interface-directory (widget &rest _ignore)
2c840b90 6556 (and pr-buffer-verbose
449cba44 6557 (message "You can use M-TAB or ESC TAB for file completion"))
2c840b90 6558 (let ((dir (widget-value widget)))
1d75432d 6559 (and (file-accessible-directory-p dir)
2c840b90
KS
6560 (setq pr-i-directory dir))))
6561
6562
6c42fc3e 6563(defun pr-interface-infile (widget &rest _ignore)
2c840b90 6564 (and pr-buffer-verbose
449cba44 6565 (message "You can use M-TAB or ESC TAB for file completion"))
2c840b90
KS
6566 (let ((file (widget-value widget)))
6567 (and (not (file-directory-p file))
6568 (file-readable-p file)
6569 (setq pr-i-ps-file file))))
6570
6571
6c42fc3e 6572(defun pr-interface-outfile (widget &rest _ignore)
2c840b90
KS
6573 (setq pr-i-answer-yes nil)
6574 (and pr-buffer-verbose
449cba44 6575 (message "You can use M-TAB or ESC TAB for file completion"))
2c840b90
KS
6576 (let ((file (widget-value widget)))
6577 (and (not (file-directory-p file))
6578 (file-writable-p file)
6579 (setq pr-i-out-file file))))
6580
6581
6582(defun pr-widget-field-action (widget event)
6583 (and (get-buffer "*Completions*") ; clean frame window
6584 (delete-windows-on "*Completions*"))
6585 (message " ") ; clean echo area
6586 (widget-field-action widget event))
6587
6588
6589(defun pr-insert-italic (str &optional from to)
6590 (let ((len (length str)))
6591 (put-text-property (if from (max from 0) 0)
6592 (if to (max to len) len)
6593 'face 'italic str)
6594 (widget-insert str)))
6595
6596
6597(defun pr-insert-checkbox (before var-sym fun label)
6598 (widget-insert before)
6599 (prog1
6600 (widget-create 'checkbox
6601 :notify fun
6602 (symbol-value var-sym))
6603 (widget-insert label)))
6604
6605
6606(defun pr-insert-toggle (var-sym label)
6607 (widget-create 'checkbox
6c42fc3e 6608 :notify `(lambda (&rest _ignore)
2c840b90
KS
6609 (setq ,var-sym (not ,var-sym)))
6610 (symbol-value var-sym))
6611 (widget-insert label))
6612
6613
6614(defun pr-insert-button (fun label &optional separator)
6615 (widget-create 'push-button
6616 :notify fun
6617 label)
6618 (and separator
6619 (widget-insert separator)))
6620
6621
6622(defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
6623 (and before (widget-insert before))
6624 (eval `(widget-create 'menu-choice
6625 :tag ,tag
6626 :format "%v"
6627 :inline t
6628 :value ,var-sym
6c42fc3e 6629 :notify (lambda (widget &rest _ignore)
2c840b90
KS
6630 (setq ,var-sym (widget-value widget))
6631 ,@body)
6632 :void '(choice-item :format "%[%t%]"
6633 :tag "Can not display value!")
6634 ,@choices))
6635 (and after (widget-insert after)))
6636
6637
6638(defun pr-insert-radio-button (var-sym sym)
6639 (widget-insert "\n")
6640 (let ((wid-list (get var-sym 'pr-widget-list))
6641 (wid (eval `(widget-create
6642 'radio-button
6643 :format " %[%v%]"
6644 :value (eq ,var-sym (quote ,sym))
6c42fc3e 6645 :notify (lambda (&rest _ignore)
2c840b90
KS
6646 (setq ,var-sym (quote ,sym))
6647 (pr-update-radio-button (quote ,var-sym)))))))
6648 (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
6649
6650
6651(defun pr-update-radio-button (var-sym)
6652 (let ((wid-list (get var-sym 'pr-widget-list)))
6653 (while wid-list
6654 (let ((wid (car (car wid-list)))
6655 (value (cdr (car wid-list))))
6656 (setq wid-list (cdr wid-list))
6657 (widget-value-set wid (eq (symbol-value var-sym) value))))
6658 (widget-setup)))
6659
6660
6661(defun pr-update-checkbox (var-sym)
6662 (let ((wid (get var-sym 'pr-widget)))
6663 (when wid
6664 (widget-value-set wid (symbol-value var-sym))
6665 (widget-setup))))
6666
6667
6668(defun pr-choice-alist (alist)
6669 (let ((max (apply 'max (mapcar #'(lambda (alist)
6670 (length (symbol-name (car alist))))
6671 alist))))
6672 (mapcar #'(lambda (alist)
6673 (let* ((sym (car alist))
6674 (name (symbol-name sym)))
6675 (list
6676 'quote
6677 (list
6678 'choice-item
6679 :format "%[%t%]"
6680 :tag (concat name
6681 (make-string (- max (length name)) ?_))
6682 :value sym))))
6683 alist)))
6684
6685
6686;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6687
6688
2c840b90
KS
6689(provide 'printing)
6690
6691
6692;;; printing.el ends here