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