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