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