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