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