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