printing.el 218 KB
Newer Older
Kim F. Storm's avatar
Kim F. Storm committed
1 2
;;; printing.el --- printing utilities

3
;; Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
Kim F. Storm's avatar
Kim F. Storm committed
4

5 6
;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
Deepak Goel's avatar
Deepak Goel committed
7
;; Time-stamp: <2005-09-18 05:57:14 deego>
Kim F. Storm's avatar
Kim F. Storm committed
8
;; Keywords: wp, print, PostScript
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
9
;; Version: 6.8.4
Kim F. Storm's avatar
Kim F. Storm committed
10 11
;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
12 13
(defconst pr-version "6.8.4"
  "printing.el, v 6.8.4 <2005/06/11 vinicius>
Kim F. Storm's avatar
Kim F. Storm committed
14 15

Please send all bug fixes and enhancements to
16
	Vinicius Jose Latorre <viniciusjl@ig.com.br>
Kim F. Storm's avatar
Kim F. Storm committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
")

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.

;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY
;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
;; details.

;; You should have received a copy of the GNU General Public License along with
;; GNU Emacs; see the file COPYING.  If not, write to the Free Software
Lute Kamstra's avatar
Lute Kamstra committed
33
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Kim F. Storm's avatar
Kim F. Storm committed
34 35 36 37 38 39 40 41

;;; Commentary:

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Introduction
;; ------------
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
42 43 44 45 46
;; With `printing' you can preview or print a PostScript file.  You can also
;; print a text file using PostScript, and preview or print buffers that use
;; certain special modes like mh-folder-mode, rmail-summary-mode,
;; gnus-summary-mode, etc.  This package also includes a PostScript/text
;; printer database.
47
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
48
;; There are two user interfaces:
49
;;
50
;;    * Menu interface:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
51
;;      The `printing' menu replaces the usual print options in the menu bar.
52 53
;;      This is the default user interface.
;;
54
;;    * Buffer interface:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
55 56 57
;;      You can use a buffer interface instead of menus.  It looks like a
;;      customization buffer.  Basically, it has the same options found in the
;;      menu and some extra options, all this on a buffer.
Kim F. Storm's avatar
Kim F. Storm committed
58 59 60 61 62 63 64
;;
;; `printing' is prepared to run on GNU, Unix and NT systems.
;; On GNU or Unix system, `printing' depends on gs and gv utilities.
;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe).
;; To obtain ghostscript, ghostview and GSview see the URL
;; `http://www.gnu.org/software/ghostscript/ghostscript.html'.
;;
65 66 67 68
;; `printing' depends on ps-print package to generate PostScript files, to
;; spool and to despool PostScript buffer.  So, `printing' provides an
;; interface to ps-print package and it also provides some extra stuff.
;;
Kim F. Storm's avatar
Kim F. Storm committed
69 70 71 72
;; To download the latest ps-print package see
;; `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'.
;; Please, see README file for ps-print installation instructions.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86
;; `printing' was inspired on:
;;
;;    print-nt.el	      Frederic Corne <frederic.corne@erli.fr>
;;	 Special printing functions for Windows NT
;;
;;    mh-e-init.el	      Tom Vogels <tov@ece.cmu.edu>
;;	 PS-print for mail messages
;;
;;    win32-ps-print.el	      Matthew O. Persico <mpersico@erols.com>
;;	 PostScript printing with ghostscript
;;
;;    ps-print-interface.el   Volker Franz <volker.franz@tuebingen.mpg.de>
;;	 Graphical front end for ps-print and previewing
;;
Kim F. Storm's avatar
Kim F. Storm committed
87
;;
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
;; Log Messages
;; ------------
;;
;; The buffer *Printing Command Output* is where the `printing' log messages
;; are inserted.  All program called by `printing' has a log entry in the
;; buffer *Printing Command Output*.  A log entry has the following form:
;;
;;    PROGRAM (ARG...)
;;    MESSAGE
;;    Exit status: CODE
;;
;; Where
;; PROGRAM is the program activated by `printing',
;; ARG is an argument passed to PROGRAM (it can have more than one argument),
;; MESSAGE is an error message returned by PROGRAM (it can have no message, if
;; PROGRAM is successful),
;; and CODE is a numeric exit status or a signal description string.
;;
;; For example, after previewing a PostScript file, *Printing Command Output*
;; will have the following entry:
;;
;;    /usr/X11R6/bin/gv ("/home/user/example/file.ps")
;;    Exit status: 0
;;
;; In the example above, the previewing was successful.  If during previewing,
;; you quit gv execution (by typing C-g during Emacs session), the log entry
;; would be:
;;
;;    /usr/X11R6/bin/gv ("/home/user/example/file.ps")
;;    Exit status: Quit
;;
;; So, if something goes wrong, a good place to take a look is the buffer
;; *Printing Command Output*.  Don't forget to see also the buffer *Messages*,
;; it can help.
;;
;;
Kim F. Storm's avatar
Kim F. Storm committed
124 125 126
;; Novices (First Users)
;; ---------------------
;;
127 128
;; First of all, see printing documentation only to get an idea of what
;; `printing' is capable.
Kim F. Storm's avatar
Kim F. Storm committed
129 130 131 132 133
;;
;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'.  These variables
;; are the main variables for printing processing.
;;
134 135 136
;; Now, please, see these variables documentation deeper.  You can do this by
;; typing C-h v pr-ps-name RET (for example) if you already loaded printing
;; package, or by browsing printing.el source file.
Kim F. Storm's avatar
Kim F. Storm committed
137 138 139 140 141 142 143 144
;;
;; If the documentation isn't clear or if you find a way to improve the
;; documentation, please, send an email to maintainer.  All printing users
;; will thank you.
;;
;; One way to set variables is by calling `pr-customize', customize all
;; variables and save the customization by future sessions (see Options
;; section).  Other way is by coding your settings on Emacs init file (that is,
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
145
;; ~/.emacs file), see below for a first setting template that it should be
Kim F. Storm's avatar
Kim F. Storm committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
;; inserted on your ~/.emacs file (or c:/_emacs, if you're using Windows 9x/NT
;; or MS-DOS):
;;
;; * Example of setting for Windows system:
;;
;;    (require 'printing)		; load printing package
;;    (setq pr-path-alist
;;	    '((windows   "c:/applications/executables" PATH ghostview mpage)
;;	      (ghostview "c:/gs/gsview-dir")
;;	      (mpage     "c:/mpage-dir")
;;	      ))
;;    (setq pr-txt-name      'prt_06a)
;;    (setq pr-txt-printer-alist
;;          '((prt_06a  "print"     nil "/D:\\\\printers\\prt_06a")
;;            (prt_07c  nil         nil "/D:\\\\printers\\prt_07c")
;;            (PRN      ""          nil "PRN")
;;            (standard "redpr.exe" nil "")
;;            ))
;;    (setq pr-ps-name       'lps_06b)
;;    (setq pr-ps-printer-alist
;;          '((lps_06a  "print"     nil "/D:" "\\\\printers\\lps_06a")
;;            (lps_06b  "print"     nil nil   "\\\\printers\\lps_06b")
;;            (lps_07c  "print"     nil ""    "/D:\\\\printers\\lps_07c")
;;            (lps_08c  nil         nil nil   "\\\\printers\\lps_08c")
;;            (LPT1     ""          nil ""    "LPT1:")
;;            (PRN      ""          nil ""    "PRN")
;;            (standard "redpr.exe" nil ""    "")
;;            ))
;;    (pr-update-menus t)		; update now printer and utility menus
;;
;; * Example of setting for GNU or Unix system:
;;
;;    (require 'printing)		; load printing package
;;    (setq pr-path-alist
;;	    '((unix      "." "~/bin" ghostview mpage PATH)
;;	      (ghostview "$HOME/bin/gsview-dir")
;;	      (mpage     "$HOME/bin/mpage-dir")
;;	      ))
;;    (setq pr-txt-name      'prt_06a)
;;    (setq pr-txt-printer-alist
;;          '((prt_06a "lpr" nil "prt_06a")
;;            (prt_07c nil   nil "prt_07c")
;;            ))
;;    (setq pr-ps-name       'lps_06b)
;;    (setq pr-ps-printer-alist
;;          '((lps_06b "lpr" nil "-P" "lps_06b")
;;            (lps_07c "lpr" nil nil  "lps_07c")
;;            (lps_08c nil   nil nil  "lps_08c")
;;            ))
;;    (pr-update-menus t)		; update now printer and utility menus
;;
;;
;; NOTE 1: Don't forget to download and install ghostscript utilities (see
;;         Utilities section).
;;
;; NOTE 2: The `printer-name' and `ps-printer-name' variables don't need to be
;;         set, as they are implicit set by `pr-ps-printer-alist' and
;;         `pr-txt-printer-alist'.
;;
;; NOTE 3: The duplex feature will only work on PostScript printers that
;;         support this feature.
;;         You can check if your PostScript printer supports duplex feature
;;         by checking the printer manual.  Or you can try these steps:
;;         1. Open a buffer (or use the *scratch* buffer).
;;         2. Type:
;;            First line (on first page)
;;            ^L
;;            Second line (on second page)
;;         3. Print this buffer with duplex turned on.
;;         If it's printed 2 (two) sheets of paper, then your PostScript
;;         printer doesn't have duplex feature; otherwise, it's ok, your
;;         printer does have duplex feature.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
219 220 221 222 223 224
;; NOTE 4: See Tips section.
;;
;;
;; Tips
;; ----
;;
225
;; 1. If you have a local printer, that is, a printer which is connected
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
226 227 228
;;    directly to your computer, don't forget to connect the printer to your
;;    computer before printing.
;;
229 230 231 232 233 234 235 236 237 238 239
;; 2. If you try to print a file and it seems that the file was printed, but
;;    there is no paper in the printer, then try to set `pr-delete-temp-file'
;;    to nil.  Probably `printing' is deleting the temporary file before your
;;    local system can get it to send to the printer.
;;
;; 3. Don't try to print a dynamic buffer, that is, a buffer which is
;;    modifying while `printing' tries to print.  Eventually you got an error
;;    message.  Instead, save the dynamic buffer to a file or copy it in
;;    another buffer and, then, print the file or the new static buffer.
;;    An example of dynamic buffer is the *Messages* buffer.
;;
240 241 242 243 244
;; 4. When running Emacs on Windows (with or without cygwin), check if your
;;    printer is a text printer or not by typing in a DOS window:
;;
;;       print /D:\\host\printer somefile.txt
;;
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.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
247
;;
248 249
;;    If the printer `\\host\printer' doesn't print the content of
;;    `somefile.txt' or, instead, it returns the following message:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
250
;;
251 252 253 254 255 256 257 258 259
;;       PostScript Error Handler
;;       Offending Command = CCC
;;       Stack =
;;
;;    Where `CCC' is whatever is at the beginning of the text to be printed.
;;
;;    Therefore, the printer `\\host\printer' is not a text printer, but a
;;    PostScript printer.  So, please, don't include this printer in
;;    `pr-txt-printer-alist' (which see).
260
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
261 262 263
;; 5. You can use gsprint instead of ghostscript to print monochrome PostScript
;;    files in Windows.  The gsprint utility documentation says that it is more
;;    efficient than ghostscript to print monochrome PostScript.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
264
;;
265 266
;;    To print non-monochrome PostScript file, the efficiency of ghostscript
;;    is similar to gsprint.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
267 268 269 270 271 272
;;
;;    Also the gsprint utility comes together with gsview distribution.
;;
;;    For more information about gsprint see
;;    `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
;;    As an example of gsprint declaration:
;;
;;    (setq pr-ps-printer-alist
;;          '((A "gsprint" ("-all" "-twoup") "-printer " "my-b/w-printer-name")
;;            (B "gsprint" ("-all" "-twoup") nil "-printer my-b/w-printer-name")
;;            ;; some other printer declaration
;;            ))
;;
;;    The example above declares that printer A prints all pages (-all) and two
;;    pages per sheet (-twoup).  The printer B declaration does the same as the
;;    printer A declaration, the only difference is the printer name selection.
;;
;;    There are other command line options like:
;;
;;    -mono	Render in monochrome as 1bit/pixel (only black and white).
;;    -grey	Render in greyscale as 8bits/pixel.
;;    -color	Render in color as 24bits/pixel.
;;
;;    The default is `-mono'.  So, printer A and B in the example above are
;;    using implicitly the `-mono' option.  Note that in `-mono' no gray tone
;;    or color is printed, this includes the zebra stripes, that is, in `-mono'
;;    the zebra stripes are not printed.
;;
;;    See also documentation for `pr-ps-printer-alist'.
;;
Kim F. Storm's avatar
Kim F. Storm committed
298 299 300 301 302 303 304 305
;;
;; Using `printing'
;; ----------------
;;
;; To use `printing' insert in your ~/.emacs file (or c:/_emacs, if you're
;; using Windows 9x/NT or MS-DOS):
;;
;;    (require 'printing)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
306 307
;;    ;; ...some user settings...
;;    (pr-update-menus t)
Kim F. Storm's avatar
Kim F. Storm committed
308
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
309
;; During `pr-update-menus' evaluation:
Kim F. Storm's avatar
Kim F. Storm committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
;;   * On Emacs 20:
;;      it replaces the Tools/Print menu by Tools/Printing menu.
;;   * On Emacs 21:
;;      it replaces the File/Print* menu entries by File/Print menu.
;; Please, see section Menu Layout below for menu explanation.
;;
;; To use `printing' utilities you can use the Printing menu options, type M-x
;; followed by one of the commands below, or type a key associated with the
;; command you want (if there is a key binding).
;;
;; `printing' has the following commands:
;;
;;    pr-interface
;;    pr-ps-directory-preview
;;    pr-ps-directory-using-ghostscript
;;    pr-ps-directory-print
;;    pr-ps-directory-ps-print
;;    pr-ps-buffer-preview
;;    pr-ps-buffer-using-ghostscript
;;    pr-ps-buffer-print
;;    pr-ps-buffer-ps-print
;;    pr-ps-region-preview
;;    pr-ps-region-using-ghostscript
;;    pr-ps-region-print
;;    pr-ps-region-ps-print
;;    pr-ps-mode-preview
;;    pr-ps-mode-using-ghostscript
;;    pr-ps-mode-print
;;    pr-ps-mode-ps-print
;;    pr-ps-file-preview
;;    pr-ps-file-up-preview
;;    pr-ps-file-using-ghostscript
;;    pr-ps-file-print
;;    pr-ps-file-ps-print
;;    pr-ps-file-up-ps-print
;;    pr-ps-fast-fire
;;    pr-despool-preview
;;    pr-despool-using-ghostscript
;;    pr-despool-print
;;    pr-despool-ps-print
;;    pr-printify-directory
;;    pr-printify-buffer
;;    pr-printify-region
;;    pr-txt-directory
;;    pr-txt-buffer
;;    pr-txt-region
;;    pr-txt-mode
;;    pr-txt-fast-fire
;;    pr-toggle-file-duplex
;;    pr-toggle-file-tumble
;;    pr-toggle-file-landscape
;;    pr-toggle-ghostscript
;;    pr-toggle-faces
;;    pr-toggle-spool
;;    pr-toggle-duplex
;;    pr-toggle-tumble
;;    pr-toggle-landscape
;;    pr-toggle-upside-down
;;    pr-toggle-line
;;    pr-toggle-zebra
;;    pr-toggle-header
;;    pr-toggle-lock
;;    pr-toggle-region
;;    pr-toggle-mode
;;    pr-customize
;;    lpr-customize
;;    pr-help
;;    pr-ps-name
;;    pr-txt-name
;;    pr-ps-utility
;;    pr-show-ps-setup
;;    pr-show-pr-setup
;;    pr-show-lpr-setup
;;
;; The general meanings of above commands are:
;;
;;    PREFIX:
;;    `pr-interface'	buffer interface for printing package.
;;    `pr-help'		help for printing package.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
389 390 391
;;    `pr-ps-name'	interactively select a PostScript printer.
;;    `pr-txt-name'	interactively select a text printer.
;;    `pr-ps-utility'	interactively select a PostScript utility.
Kim F. Storm's avatar
Kim F. Storm committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
;;    `pr-show-*-setup'	show current settings.
;;    `pr-ps-*'		deal with PostScript code generation.
;;    `pr-txt-*'	deal with text generation.
;;    `pr-toggle-*'	toggle on/off some boolean variable.
;;    `pr-despool-*'	despool the PostScript spooling buffer.
;;    `pr-printify-*'	replace nonprintable ASCII by printable ASCII
;;			representation.
;;
;;    SUFFIX:
;;    `*-customize'		customization.
;;    `*-preview'		preview a PostScript file.
;;    `*-using-ghostscript'	use ghostscript to print.
;;    `*-fast-fire'		fast fire command (see it for documentation).
;;    `*-print'			send PostScript directly to printer.
;;    `*-ps-print'		send PostScript directly to printer or use
;;				ghostscript to print.  It depends on
;;				`pr-print-using-ghostscript' option.
;;
;;    INFIX/SUFFIX:
;;    `*-directory*'	process a directory.
;;    `*-buffer*'	process a buffer.
;;    `*-region*'	process a region.
;;    `*-mode*'		process a major mode (see explanation below).
;;    `*-file-*'	process a PostScript file.
;;    `*-file-up-*'	process a PostScript file using a filter utility.
;;
;; Here are some examples:
;;
;;    `pr-ps-buffer-using-ghostscript'
;;	 Use ghostscript to print a buffer.
;;
;;    `pr-ps-file-print'
;;	 Print a PostScript file.
;;
;;    `pr-toggle-spool'
;;	 Toggle spooling buffer.
;;
;; So you can preview through ghostview, use ghostscript to print (if you don't
;; have a PostScript printer) or send directly to printer a PostScript code
;; generated by `ps-print' package.
;;
;; Besides operating one buffer or region each time, you also can postpone
;; previewing or printing by saving the PostScript code generated in a
;; temporary Emacs buffer.  This way you can save banner pages between
;; successive printing.  You can toggle on/off spooling by invoking
;; `pr-toggle-spool' interactively or through menu bar.
;;
;; If you type, for example:
;;
;;    C-u M-x pr-ps-buffer-print RET
;;
;; The `pr-ps-buffer-print' command prompts you for a n-up printing number and
;; a file name, and save the PostScript code generated to the file name instead
;; of sending to printer.
;;
;; This behavior is similar with the commands that deal with PostScript code
;; generation, that is, with `pr-ps-*' and `pr-despool-*' commands.  If
;; spooling is on, only `pr-despool-*' commands prompt for a file name and save
;; the PostScript code spooled in this file.
;;
;; Besides the behavior described above, the `*-directory*' commands also
;; prompt for a directory and a file name regexp.  So, it's possible to process
;; all or certain files on a directory at once (see also documentation for
;; `pr-list-directory').
;;
;; `printing' has also a special way to handle some major mode through
;; `*-mode*' commands.  So it's possible to customize a major mode printing,
;; it's only needed to declare the customization in `pr-mode-alist' (see
;; section Options) and invoke some of `*-mode*' commands.  An example for
;; major mode usage is when you're using gnus (or mh, or rmail, etc.) and
;; you're in the *Summary* buffer, if you forget to switch to the *Article*
;; buffer before printing, you'll get a nicely formatted list of article
;; subjects shows up at the printer.  With major mode printing you don't need
;; to switch from gnus *Summary* buffer first.
;;
;; Current global keyboard mapping for GNU Emacs is:
;;
469 470 471 472 473
;;    (global-set-key [print]     'pr-ps-fast-fire)
;;    (global-set-key [M-print]   'pr-ps-mode-using-ghostscript)
;;    (global-set-key [S-print]   'pr-ps-mode-using-ghostscript)
;;    (global-set-key [C-print]   'pr-txt-fast-fire)
;;    (global-set-key [C-M-print] 'pr-txt-fast-fire)
Kim F. Storm's avatar
Kim F. Storm committed
474 475 476
;;
;; And for XEmacs is:
;;
477 478 479 480 481
;;    (global-set-key 'f22                'pr-ps-fast-fire)
;;    (global-set-key '(meta f22)         'pr-ps-mode-using-ghostscript)
;;    (global-set-key '(shift f22)        'pr-ps-mode-using-ghostscript)
;;    (global-set-key '(control f22)      'pr-txt-fast-fire)
;;    (global-set-key '(control meta f22) 'pr-txt-fast-fire)
Kim F. Storm's avatar
Kim F. Storm committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
;;
;; As a suggestion of global keyboard mapping for some `printing' commands:
;;
;;    (global-set-key "\C-ci"  'pr-interface)
;;    (global-set-key "\C-cbp" 'pr-ps-buffer-print)
;;    (global-set-key "\C-cbx" 'pr-ps-buffer-preview)
;;    (global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
;;    (global-set-key "\C-crp" 'pr-ps-region-print)
;;    (global-set-key "\C-crx" 'pr-ps-region-preview)
;;    (global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
;;
;;
;; Options
;; -------
;;
;; Below it's shown a brief description of `printing' options, please, see the
;; options declaration in the code for a long documentation.
;;
;; `pr-path-style'		Specify which path style to use for external
;;				commands.
;;
;; `pr-path-alist'		Specify an alist for command paths.
;;
;; `pr-txt-name'		Specify a printer for printing a text file.
;;
;; `pr-txt-printer-alist'	Specify an alist of all text printers.
;;
;; `pr-ps-name'			Specify a printer for printing a PostScript
;;				file.
;;
;; `pr-ps-printer-alist'	Specify an alist for all PostScript printers.
;;
;; `pr-temp-dir'		Specify a directory for temporary files during
;;				printing.
;;
517
;; `pr-ps-temp-file'		Specify PostScript temporary file name prefix.
Kim F. Storm's avatar
Kim F. Storm committed
518
;;
519 520 521
;; `pr-file-modes'		Specify the file permission bits for newly
;;				created files.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
522 523
;; `pr-gv-command'		Specify path and name of the gsview/gv
;;				utility.
Kim F. Storm's avatar
Kim F. Storm committed
524
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
525 526
;; `pr-gs-command'		Specify path and name of the ghostscript
;;				utility.
Kim F. Storm's avatar
Kim F. Storm committed
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
;;
;; `pr-gs-switches'		Specify ghostscript switches.
;;
;; `pr-gs-device'		Specify ghostscript device switch value.
;;
;; `pr-gs-resolution'		Specify ghostscript resolution switch value.
;;
;; `pr-print-using-ghostscript'	Non-nil means print using ghostscript.
;;
;; `pr-faces-p'			Non-nil means print with face attributes.
;;
;; `pr-spool-p'			Non-nil means spool printing in a buffer.
;;
;; `pr-file-landscape'		Non-nil means print PostScript file in
;;				landscape orientation.
;;
;; `pr-file-duplex'		Non-nil means print PostScript file in duplex
;;				mode.
;;
;; `pr-file-tumble'		Non-nil means print PostScript file in tumble
;;				mode.
;;
;; `pr-auto-region'		Non-nil means region is automagically detected.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
551 552
;; `pr-auto-mode'		Non-nil means major-mode specific printing is
;;				prefered over normal printing.
Kim F. Storm's avatar
Kim F. Storm committed
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
;;
;; `pr-mode-alist'		Specify an alist for a major-mode and printing
;;				function.
;;
;; `pr-ps-utility'		Specify PostScript utility processing.
;;
;; `pr-ps-utility-alist'	Specify an alist for PostScript utility
;;				processing.
;;
;; `pr-menu-lock'		Non-nil means menu is locked while selecting
;;				toggle options.
;;
;; `pr-menu-char-height'	Specify menu char height in pixels.
;;
;; `pr-menu-char-width'		Specify menu char width in pixels.
;;
;; `pr-setting-database'	Specify an alist for settings in general.
;;
;; `pr-visible-entry-list'	Specify a list of Printing menu visible
;;				entries.
;;
;; `pr-delete-temp-file'	Non-nil means delete temporary files.
;;
;; `pr-list-directory'		Non-nil means list directory when processing a
;;				directory.
;;
;; `pr-buffer-name'		Specify the name of the buffer interface for
;;				printing package.
;;
;; `pr-buffer-name-ignore'	Specify a regexp list for buffer names to be
;;				ignored in interface buffer.
;;
;; `pr-buffer-verbose'		Non-nil means to be verbose when editing a
;;				field in interface buffer.
;;
;; To set the above options you may:
;;
;; a) insert the code in your ~/.emacs, like:
;;
;;	 (setq pr-faces-p t)
;;
;;    This way always keep your default settings when you enter a new Emacs
;;    session.
;;
;; b) or use `set-variable' in your Emacs session, like:
;;
;;	 M-x set-variable RET pr-faces-p RET t RET
;;
;;    This way keep your settings only during the current Emacs session.
;;
;; c) or use customization, for example:
;;	 click on menu-bar *Help* option,
;;	 then click on *Customize*,
;;	 then click on *Browse Customization Groups*,
;;	 expand *PostScript* group,
;;	 expand *Printing* group
;;	 and then customize `printing' options.
;;    Through this way, you may choose if the settings are kept or not when
;;    you leave out the current Emacs session.
;;
;; d) or see the option value:
;;
;;	 C-h v pr-faces-p RET
;;
;;    and click the *customize* hypertext button.
;;    Through this way, you may choose if the settings are kept or not when
;;    you leave out the current Emacs session.
;;
;; e) or invoke:
;;
;;	 M-x pr-customize RET
;;
;;    and then customize `printing' options.
;;    Through this way, you may choose if the settings are kept or not when
;;    you leave out the current Emacs session.
;;
;; f) or use menu bar, for example:
;;	 click on menu-bar *File* option,
;;	 then click on *Printing*,
;;	 then click on *Customize*,
;;	 then click on *printing*
;;	 and then customize `printing' options.
;;    Through this way, you may choose if the settings are kept or not when
;;    you leave out the current Emacs session.
;;
;;
;; Menu Layout
;; -----------
;;
;; The `printing' menu (Tools/Printing or File/Print) has the following layout:
;;
;;        +-----------------------------+
;; A   0  |   Printing Interface        |
;;        +-----------------------------+       +-A---------+     +-B------+
;; I   1  |   PostScript Preview       >|-------|Directory >|-----|1-up    |
;;     2  |   PostScript Print         >|---- A |Buffer    >|-- B |2-up    |
;;     3  |   PostScript Printer: name >|---- C |Region    >|-- B |4-up    |
;;        +-----------------------------+       |Mode      >|-- B |Other...|
;; II  4  |   Printify                 >|-----\ |File      >|--\  +--------+
;;     5  |   Print                    >|---\ | |Despool... |  |
;;     6  |   Text Printer: name       >|-\ | | +-----------+  |
;;        +-----------------------------+ | | | +---------+   +------------+
655
;; III 7  |[ ]Landscape                 | | | \-|Directory|   | No Prep... | Ia
Kim F. Storm's avatar
Kim F. Storm committed
656 657 658 659 660 661 662 663 664 665
;;     8  |[ ]Print Header              | | |   |Buffer   |   +------------+ Ib
;;     9  |[ ]Print Header Frame        | | |   |Region   |   |   name    >|- C
;;     10 |[ ]Line Number               | | |   +---------+   +------------+
;;     11 |[ ]Zebra Stripes             | | |   +---------+   |   1-up...  | Ic
;;     12 |[ ]Duplex                    | | \---|Directory|   |   2-up...  |
;;     13 |[ ]Tumble                    | \--\  |Buffer   |   |   4-up...  |
;;     14 |[ ]Upside-Down               |    |  |Region   |   |   Other... |
;;     15 |   Print All Pages          >|--\ |  |Mode     |   +------------+
;;        +-----------------------------+  | |  +---------+   |[ ]Landscape| Id
;; IV  16 |[ ]Spool Buffer              |  | |  +-C-------+   |[ ]Duplex   | Ie
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
666 667
;;     17 |[ ]Print with faces          |  | \--|( )name A|   |[ ]Tumble   | If
;;     18 |[ ]Print via Ghostscript     |  |    |( )name B|   +------------+
Kim F. Storm's avatar
Kim F. Storm committed
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
;;        +-----------------------------+  |    |...      |
;; V   19 |[ ]Auto Region               |  |    |(*)name  |
;;     20 |[ ]Auto Mode                 |  |    |...      |
;;     21 |[ ]Menu Lock                 |  |    +---------+   +--------------+
;;        +-----------------------------+  \------------------|(*)All Pages  |
;; VI  22 |   Customize                >|--- D  +-D------+    |( )Even Pages |
;;     23 |   Show Settings            >|-------|printing|    |( )Odd Pages  |
;;     24 |   Help                      |       |ps-print|    |( )Even Sheets|
;;        +-----------------------------+       |lpr     |    |( )Odd Sheets |
;;                                              +--------+    +--------------+
;;
;; See `pr-visible-entry-list' for hiding some parts of the menu.
;;
;; The menu has the following sections:
;;
;; A. Interface:
;;
;;    0. You can use a buffer interface instead of menus.  It looks like the
;;	 customization buffer.  Basically, it has the same options found in the
;;	 menu and some extra options, all this on a buffer.
;;
;; I. PostScript printing:
;;
;;    1. You can generate a PostScript file (if you type C-u before activating
;;	 menu) or PostScript temporary file for a directory, a buffer, a region
;;	 or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
;;	 after file generation, ghostview is activated using the file generated
;;	 as argument.  This option is disabled if spooling is on (option 16).
;;	 Also, if you already have a PostScript file you can preview it.
;;	 Instead of previewing each buffer, region or major mode at once, you
;;	 can save temporarily the PostScript code generated in a buffer and
;;	 preview it later.  The option `Despool...' despools the PostScript
;;	 spooling buffer in a temporary file and uses ghostview to preview it.
;;	 If you type C-u before choosing this option, the PostScript code
;;	 generated is saved in a file instead of saving in a temporary file.
;;	 To spool the PostScript code generated you need to turn on the option
;;	 16.  The option `Despool...' is enabled if spooling is on (option
;;	 16).
;;
;;	 NOTE 1: It's possible to customize a major mode printing, just declare
;;		 the customization in `pr-mode-alist' and invoke some of
;;		 `*-mode*' commands or select Mode option in Printing menu.  An
;;		 example for major mode usage is when you're using gnus (or mh,
;;		 or rmail, etc.) and you're in the *Summary* buffer, if you
;;		 forget to switch to the *Article* buffer before printing,
;;		 you'll get a nicely formatted list of article subjects shows
;;		 up at the printer.  With major mode printing you don't need to
;;		 switch from gnus *Summary* buffer first.
;;
;;	 NOTE 2: There are the following options for PostScript file
;;		 processing:
719 720
;;		 Ia. Print the file *No Preprocessing*, that is, send it
;;		     directly to PostScript printer.
Kim F. Storm's avatar
Kim F. Storm committed
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
;;		 Ib. PostScript utility processing selection.
;;		     See `pr-ps-utility-alist' and `pr-setting-database' for
;;		     documentation.
;;		 Ic. Do n-up processing before printing.
;;		 Id. Toggle on/off landscape for PostScript file processing.
;;		 Ie. Toggle on/off duplex for PostScript file processing.
;;		 If. Toggle on/off tumble for PostScript file processing.
;;
;;	 NOTE 3: Don't forget to download and install the utilities declared on
;;		 `pr-ps-utility-alist'.
;;
;;    2. Operate the same way as option 1, but it sends directly the PostScript
;;	 code (or put in a file, if you've typed C-u) or it uses ghostscript to
;;	 print the PostScript file generated.  It depends on option 18, if it's
;;	 turned on, it uses ghostscript; otherwise, it sends directly to
;;	 printer.  If spooling is on (option 16), the PostScript code is saved
;;	 temporarily in a buffer instead of printing it or saving it in a file.
;;	 Also, if you already have a PostScript file you can print it.  Instead
;;	 of printing each buffer, region or major mode at once, you can save
;;	 temporarily the PostScript code generated in a buffer and print it
;;	 later.  The option `Despool...' despools the PostScript spooling
;;	 buffer directly on a printer.  If you type C-u before choosing this
;;	 option, the PostScript code generated is saved in a file instead of
;;	 sending to printer.  To spool the PostScript code generated you need
;;	 to turn on the option 16.  This option is enabled if spooling is on
;;	 (option 16).  See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
;;
;;    3. You can select a new PostScript printer to send PostScript code
;;	 generated.  For selection it's used all PostScript printers defined
;;	 in `pr-ps-printer-alist' variable (see it for documentation).
;;	 See also `pr-setting-database'.
;;
;; II. Text printing:
;;
;;    4. If you have control characters (character code from \000 to \037) in a
;;	 buffer and you want to print them in a text printer, select this
;;	 option.  All control characters in your buffer or region will be
;;	 replaced by a printable representation.  The printable representations
;;	 use ^ (for ASCII control characters) or hex.  The characters tab,
;;	 linefeed, space, return and formfeed are not affected.  You don't need
;;	 to select this option if you use any option of section I, the
;;	 PostScript engine treats control characters properly.
;;
;;    5. If you want to print a directory, buffer, region or major mode in a
;;	 text printer, select this option.  See also the NOTE 1 on option 1.
;;
;;    6. You can select a new text printer to send text generated.  For
;;	 selection it's used all text printers defined in
;;	 `pr-txt-printer-alist' variable (see it for documentation).
;;	 See also `pr-setting-database'.
;;
;; III. PostScript page toggle options:
;;
;;    7. If you want a PostScript landscape printing, turn on this option.
;;
;;    8. If you want to have a header in each page in your PostScript code,
;;	 turn on this option.
;;
;;    9. If you want to draw a gaudy frame around the header, turn on this
;;	 option.  This option is enabled if print header is on (option 8).
;;
;;    10. If you want that the line number is printed in your PostScript code,
;;	  turn on this option.
;;
;;    11. If you want background zebra stripes in your PostScript code, turn on
;;	  this option.
;;
;;    12. If you want a duplex printing and your PostScript printer has this
;;	  feature, turn on this option.
;;
;;    13. If you turned on duplex printing, you can choose if you want to have
;;	  a printing suitable for binding on the left or right (tumble off), or
;;	  to have a printing suitable for binding at top or bottom (tumble on).
;;	  This option is enabled if duplex is on (option 12).
;;
;;    14. If you want a PostScript upside-down printing, turn on this option.
;;
;;    15. With this option, you can choose if you want to print all pages, odd
;;	  pages, even pages, odd sheets or even sheets.
;;	  See also `ps-even-or-odd-pages'.
;;
;; IV. PostScript processing toggle options:
;;
;;    16. If you want to spool the PostScript code generated, turn on this
;;	  option.  To spool the PostScript code generated use option 2.  You
;;	  can despool later by choosing option 1 or 2, sub-option `Despool...'.
;;
;;    17. If you use colors in your buffers and want to see these colors on
;;	  your PostScript code generated, turn on this option.  If you have a
;;	  black/white PostScript printer, these colors are displayed in gray
;;	  scale by PostScript printer interpreter.
;;
;;    18. If you don't have a PostScript printer to send PostScript files, turn
;;	  on this option.  When this option is on, the ghostscript is used to
;;	  print PostScript files.  In GNU or Unix system, if ghostscript is set
;;	  as a PostScript filter, you don't need to turn on this option.
;;
;; V. Printing customization:
;;
;;    19. If you want that region is automagically detected, turn on this
;;	  option.  Note that this will only work if you're using transient mark
;;	  mode.  When this option is on, the `*-buffer*' commands will behave
;;	  like `*-region*' commands, that is, `*-buffer*' commands will print
;;	  only the region marked instead of all buffer.
;;
;;    20. Turn this option on if you want that when current major-mode is
;;	  declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
;;	  behave like `*-mode*' commands.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
830
;;    21. If you want that Printing menu stays open while you are setting
Kim F. Storm's avatar
Kim F. Storm committed
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
;;	  toggle options, turn on this option.  The variables
;;	  `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
;;	  menu position, so don't forget to adjust these variables if menu
;;	  position is not ok.
;;
;; VI. Customization:
;;
;;    22. Besides all options in section III, IV and V, you can customize much
;;	  more PostScript options in `ps-print' option.  Or you can customize
;;	  some `lpr' options for text printing.  Or customize `printing'
;;	  options.
;;
;;    23. Show current settings for `printing', `ps-print' or `lpr'.
;;
;;    24. Quick help for printing menu layout.
;;
;;
;; Option Settings
;; ---------------
;;
;; Below it's shown only the main options that affect all `printing' package.
;; Check all the settings below *BEFORE* running `printing' commands.
;;
;; * Example of setting for GNU or Unix system:
;;
;;    (require 'printing)
;;    (setq pr-path-alist
;;	    '((unix      "." "~/bin" ghostview mpage PATH)
;;	      (ghostview "$HOME/bin/gsview-dir")
;;	      (mpage     "$HOME/bin/mpage-dir")
;;	      ))
;;    (setq pr-txt-name      'prt_06a)
;;    (setq pr-txt-printer-alist
;;          '((prt_06a "lpr" nil "prt_06a")
;;            (prt_07c nil   nil "prt_07c")
;;            ))
;;    (setq pr-ps-name       'lps_06b)
;;    (setq pr-ps-printer-alist
;;          '((lps_06b "lpr" nil "-P" "lps_06b")
;;            (lps_07c "lpr" nil nil  "lps_07c")
;;            (lps_08c nil   nil nil  "lps_08c")
;;            ))
;;    (setq pr-temp-dir      "/tmp/")
;;    (setq pr-gv-command    "gv")
;;    (setq pr-gs-command    "gs")
;;    (setq pr-gs-switches '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
;;    (setq pr-gs-device     "uniprint")
;;    (setq pr-gs-resolution 300)
;;    (setq pr-ps-utility    'mpage)
;;    (setq pr-ps-utility-alist
;;	    '((mpage "mpage" nil    "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
;;	      (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil  nil  " " nil
;;		     (inherits-from: . no-duplex))
;;	      ))
;;    (setq pr-setting-database
;;	    '((no-duplex
;;	       nil nil nil
;;	       (pr-file-duplex . nil)
;;	       (pr-file-tumble . nil))
;;	      ))
;;    (pr-update-menus t)		; update now printer and utility menus
;;
;; * Example of setting for Windows system:
;;
;;    (require 'printing)
;;    (setq pr-path-alist
;;	    '((windows   "c:/applications/executables" PATH ghostview mpage)
;;	      (ghostview "c:/gs/gsview-dir")
;;	      (mpage     "c:/mpage-dir")
;;	      ))
;;    (setq pr-txt-name      'prt_06a)
;;    (setq pr-txt-printer-alist
;;          '((prt_06a  "print"     nil "/D:\\\\printers\\prt_06a")
;;            (prt_07c  nil         nil "/D:\\\\printers\\prt_07c")
;;            (PRN      ""          nil "PRN")
;;            (standard "redpr.exe" nil "")
;;            ))
;;    (setq pr-ps-name       'lps_06b)
;;    (setq pr-ps-printer-alist
;;          '((lps_06a  "print"     nil "/D:" "\\\\printers\\lps_06a")
;;            (lps_06b  "print"     nil nil   "\\\\printers\\lps_06b")
;;            (lps_07c  "print"     nil ""    "/D:\\\\printers\\lps_07c")
;;            (lps_08c  nil         nil nil   "\\\\printers\\lps_08c")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
914
;;            (b/w      "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
Kim F. Storm's avatar
Kim F. Storm committed
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
;;            (LPT1     ""          nil ""    "LPT1:")
;;            (PRN      ""          nil ""    "PRN")
;;            (standard "redpr.exe" nil ""    "")
;;            ))
;;    (setq pr-temp-dir      "C:/WINDOWS/TEMP/")
;;    (setq pr-gv-command    "c:/gs/gsview/gsview32.exe")
;;    (setq pr-gs-command    "c:/gs/gswin32.exe")
;;    (setq pr-gs-switches '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts"))
;;    (setq pr-gs-device     "mswinpr2")
;;    (setq pr-gs-resolution 300)
;;    (setq pr-ps-utility    'psnup)
;;    (setq pr-ps-utility-alist
;;	    '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " "
;;		     nil (inherits-from: . no-duplex))
;;	      ))
;;    (setq pr-setting-database
;;	    '((no-duplex
;;	       nil nil nil
;;	       (pr-file-duplex . nil)
;;	       (pr-file-tumble . nil))
;;	      ))
;;    (pr-update-menus t)		; update now printer and utility menus
;;
;; NOTE: Don't forget to download and install the utilities declared on
;;	 `pr-ps-utility-alist'.
;;
;;
;; Utilities
;; ---------
;;
;; `printing' package has the following utilities:
;;
;;    `pr-setup'	Return the current `printing' setup.
;;
;;    `lpr-setup'	Return the current `lpr' setup.
;;
;;    `pr-update-menus'	Update utility, PostScript and text printer menus.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
953 954 955
;;    `pr-menu-bind'	Install `printing' menu in the menubar.
;;
;;
Kim F. Storm's avatar
Kim F. Storm committed
956 957 958 959 960 961 962 963 964 965 966
;; Below are some URL where you can find good utilities.
;;
;; * For `printing' package:
;;
;;    printing	`http://www.cpqd.com.br/~vinicius/emacs/printing.el.gz'
;;    ps-print	`http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'
;;
;; * For GNU or Unix system:
;;
;;    gs, gv         `http://www.gnu.org/software/ghostscript/ghostscript.html'
;;    enscript       `http://people.ssh.fi/mtr/genscript/'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
967
;;    psnup          `http://www.knackered.org/angus/psutils/'
Kim F. Storm's avatar
Kim F. Storm committed
968 969 970 971 972 973
;;    mpage          `http://www.mesa.nl/pub/mpage/'
;;
;; * For Windows system:
;;
;;    gswin32, gsview32
;;                   `http://www.gnu.org/software/ghostscript/ghostscript.html'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
974
;;    gsprint        `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
Kim F. Storm's avatar
Kim F. Storm committed
975
;;    enscript       `http://people.ssh.fi/mtr/genscript/'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
976
;;    psnup          `http://gnuwin32.sourceforge.net/packages/psutils.htm'
Kim F. Storm's avatar
Kim F. Storm committed
977 978 979 980 981 982
;;    redmon         `http://www.cs.wisc.edu/~ghost/redmon/'
;;
;;
;; Acknowledgments
;; ---------------
;;
983 984 985
;; Thanks to Stefan Monnier <monnier@iro.umontreal.ca> for GNU Emacs and XEmacs
;; printing menu (in `pr-menu-spec') merging suggestion.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
986 987 988
;; Thanks to Lennart Borgman <lennart.borgman.073@student.lu.se> for gsprint
;; suggestion (see tip 5 in section Tips).
;;
989 990 991 992 993
;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions:
;;    - directory processing.
;;    - `pr-path-alist' variable.
;;    - doc fix.
;;    - a lot of tests on Windows.
Kim F. Storm's avatar
Kim F. Storm committed
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
;;
;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests.
;;
;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging
;; and for suggestions:
;;    - even/odd pages printing.
;;    - ghostscript parameters for `pr-ps-printer-alist'.
;;    - default printer name.
;;    - completion functions.
;;    - automagic region detection.
;;    - menu entry hiding.
;;    - fast fire PostScript printing command.
;;    - `pr-path-style' variable.
;;
;; Thanks to Kim F. Storm <storm@filanet.dk> for beta-test and for suggestions:
;;    - PostScript Print and PostScript Print Preview merge.
;;    - Tools/Printing menu.
;;    - replace *-using-preview by *-using-ghostscript.
;;    - printer selection.
;;    - extra parameters for `pr-ps-printer-alist'.
;;
;; Thanks to:
;;    Frederic Corne <frederic.corne@erli.fr>		print-nt.el
;;    Tom Vogels <tov@ece.cmu.edu>			mh-e-init.el
;;    Matthew O. Persico <mpersico@erols.com>		win32-ps-print.el
;;    Volker Franz <volker.franz@tuebingen.mpg.de>	ps-print-interface.el
;; And to all people who contributed with them.
;;
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; Code:


(require 'lpr)
(require 'ps-print)


1032
(and (string< ps-print-version "6.6.4")
1033
     (error "`printing' requires `ps-print' package version 6.6.4 or later"))
Kim F. Storm's avatar
Kim F. Storm committed
1034 1035


1036 1037 1038
(defconst pr-cygwin-system
  (and ps-windows-system (getenv "OSTYPE")
       (string-match "cygwin" (getenv "OSTYPE"))))
Kim F. Storm's avatar
Kim F. Storm committed
1039 1040 1041 1042 1043 1044


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; To avoid compilation gripes


1045 1046 1047
(or (fboundp 'easy-menu-intern)		; hacked from easymenu.el
    (defsubst easy-menu-intern (s)
      (if (stringp s) (intern s) s)))
Kim F. Storm's avatar
Kim F. Storm committed
1048

1049 1050 1051 1052 1053


(or (fboundp 'subst-char-in-string)	; hacked from subr.el
    (defun subst-char-in-string (fromchar tochar string &optional inplace)
      "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
Kim F. Storm's avatar
Kim F. Storm committed
1054
Unless optional argument INPLACE is non-nil, return a new string."
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
      (let ((i (length string))
	    (newstr (if inplace string (copy-sequence string))))
	(while (> (setq i (1- i)) 0)
	  (if (eq (aref newstr i) fromchar)
	      (aset newstr i tochar)))
	newstr)))


(or (fboundp 'make-temp-file)		; hacked from subr.el
    (defun make-temp-file (prefix &optional dir-flag suffix)
      "Create a temporary file.
The returned file name (created by appending some random characters at the end
of PREFIX, and expanding against `temporary-file-directory' if necessary),
is guaranteed to point to a newly created empty file.
You can then use `write-region' to write new data into the file.

If DIR-FLAG is non-nil, create a new empty directory instead of a file.

If SUFFIX is non-nil, add that at the end of the file name."
      (let ((umask (default-file-modes))
	    file)
	(unwind-protect
	    (progn
	      ;; Create temp files with strict access rights.  It's easy to
	      ;; loosen them later, whereas it's impossible to close the
	      ;; time-window of loose permissions otherwise.
	      (set-default-file-modes ?\700)
	      (while (condition-case ()
			 (progn
			   (setq file
				 (make-temp-name
				  (expand-file-name prefix temporary-file-directory)))
			   (if suffix
			       (setq file (concat file suffix)))
			   (if dir-flag
			       (make-directory file)
			     (write-region "" nil file nil 'silent nil 'excl))
			   nil)
		       (file-already-exists t))
		;; the file was somehow created by someone else between
		;; `make-temp-name' and `write-region', let's try again.
		nil)
	      file)
	  ;; Reset the umask.
	  (set-default-file-modes umask)))))
Kim F. Storm's avatar
Kim F. Storm committed
1100 1101


1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
;; GNU Emacs
(defalias 'pr-e-frame-char-height    'frame-char-height)
(defalias 'pr-e-frame-char-width     'frame-char-width)
(defalias 'pr-e-mouse-pixel-position 'mouse-pixel-position)
;; XEmacs
(defalias 'pr-x-add-submenu             'add-submenu)
(defalias 'pr-x-event-function          'event-function)
(defalias 'pr-x-event-object            'event-object)
(defalias 'pr-x-find-menu-item          'find-menu-item)
(defalias 'pr-x-font-height             'font-height)
(defalias 'pr-x-font-width              'font-width)
(defalias 'pr-x-get-popup-menu-response 'get-popup-menu-response)
(defalias 'pr-x-make-event              'make-event)
(defalias 'pr-x-misc-user-event-p       'misc-user-event-p)
(defalias 'pr-x-relabel-menu-item       'relabel-menu-item)
(defalias 'pr-x-event-x-pixel           'event-x-pixel)
(defalias 'pr-x-event-y-pixel           'event-y-pixel)

(cond
 ((featurep 'xemacs)			; XEmacs
  (defvar current-menubar     nil)
  (defvar current-mouse-event nil)
  (defvar zmacs-region-stays  nil)
  (defalias 'pr-f-set-keymap-parents 'set-keymap-parents)
  (defalias 'pr-f-set-keymap-name    'set-keymap-name)
  (defun pr-f-read-string (prompt initial history default)
    (let ((str (read-string prompt initial)))
      (if (and str (not (string= str "")))
	  str
	default)))
  (defun pr-keep-region-active ()
    (setq zmacs-region-stays t)))

 (t					; GNU Emacs
  (defvar deactivate-mark nil)
  (defalias 'pr-f-set-keymap-parents 'set-keymap-parent)
  (defalias 'pr-f-set-keymap-name    'ignore)
  (defalias 'pr-f-read-string        'read-string)
  (defun pr-keep-region-active ()
    (setq deactivate-mark nil))))
Kim F. Storm's avatar
Kim F. Storm committed
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customization Functions


(defun pr-alist-custom-set (symbol value)
  "Set the value of custom variables for printer & utility selection."
  (set symbol value)
  (and (featurep 'printing)		; update only after printing is loaded
       (pr-update-menus t)))


(defun pr-ps-utility-custom-set (symbol value)
  "Update utility menu entry."
  (set symbol value)
  (and (featurep 'printing)		; update only after printing is loaded
       (pr-menu-set-utility-title value)))


(defun pr-ps-name-custom-set (symbol value)
  "Update `PostScript Printer:' menu entry."
  (set symbol value)
  (and (featurep 'printing)		; update only after printing is loaded
       (pr-menu-set-ps-title value)))


(defun pr-txt-name-custom-set (symbol value)
  "Update `Text Printer:' menu entry."
  (set symbol value)
  (and (featurep 'printing)		; update only after printing is loaded
       (pr-menu-set-txt-title value)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; User Interface (I)


(defgroup printing nil
1181
  "Printing Utilities group."
Kim F. Storm's avatar
Kim F. Storm committed
1182 1183 1184
  :tag "Printing Utilities"
  :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
  :prefix "pr-"
1185
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
  :group 'wp
  :group 'postscript)


(defcustom pr-path-style
  (if (and (not pr-cygwin-system)
	   ps-windows-system)
      'windows
    'unix)
  "*Specify which path style to use for external commands.

Valid values are:

   windows	Windows 9x/NT style (\\)

   unix		Unix style (/)"
  :type '(choice :tag "Path style"
		 (const :tag "Windows 9x/NT Style (\\)" :value windows)
		 (const :tag "Unix Style (/)" :value unix))
1205
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1206 1207 1208 1209 1210 1211 1212
  :group 'printing)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal Functions (I)


1213
(defun pr-dosify-file-name (path)
Kim F. Storm's avatar
Kim F. Storm committed
1214 1215 1216 1217 1218 1219 1220
  "Replace unix-style directory separator character with dos/windows one."
  (interactive "sPath: ")
  (if (eq pr-path-style 'windows)
      (subst-char-in-string ?/ ?\\ path)
    path))


1221
(defun pr-unixify-file-name (path)
Kim F. Storm's avatar
Kim F. Storm committed
1222 1223 1224 1225 1226 1227 1228
  "Replace dos/windows-style directory separator character with unix one."
  (interactive "sPath: ")
  (if (eq pr-path-style 'windows)
      (subst-char-in-string ?\\ ?/ path)
    path))


1229
(defun pr-standard-file-name (path)
1230 1231 1232 1233 1234 1235 1236 1237
  "Ensure the proper directory separator depending on the OS.
That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
separator; otherwise, ensure unix-style directory separator."
  (if (or pr-cygwin-system ps-windows-system)
      (subst-char-in-string ?/ ?\\ path)
    (subst-char-in-string ?\\ ?/ path)))


Kim F. Storm's avatar
Kim F. Storm committed
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; User Interface (II)


(defcustom pr-path-alist
  '((unix    PATH)
    (cygwin  PATH)
    (windows PATH))
  "*Specify an alist for command paths.

It's used to find commands used for printing package, like gv, gs, gsview.exe,
mpage, print.exe, etc.  See also `pr-command' function.

Each element has the form:

   (ENTRY DIRECTORY...)

Where:

ENTRY		It's a symbol, used to identify this entry.
		There must exist at least one of the following entries:

		unix	this entry is used when Emacs is running on GNU or
			Unix system.

		cygwin	this entry is used when Emacs is running on Windows
			95/98/NT/2000 with Cygwin.

		windows	this entry is used when Emacs is running on Windows
			95/98/NT/2000.

DIRECTORY	It should be a string or a symbol.  If it's a symbol, it should
		exist an equal entry in `pr-path-alist'.  If it's a string,
		it's considered a directory specification.

		The directory specification may contain:
		$var	environment variable expansion
		~/	tilde expansion
		./	current directory
		../	previous directory

		For example, let's say the home directory is /home/my and the
		current directory is /home/my/dir, so:

		THE ENTRY			IS EXPANDED TO
		~/entry				/home/my/entry
		./entry				/home/my/dir/entry
		../entry			/home/my/entry
		$HOME/entry			/home/my/entry
		$HOME/~/other/../my/entry	/home/my/entry

		SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
		list and there isn't a `PATH' entry in `pr-path-alist' or the
		`PATH' entry has a null directory list, the PATH environment
		variable is used.

Examples:

* On GNU or Unix system:

   '((unix      \".\" \"~/bin\" ghostview mpage PATH)
     (ghostview \"$HOME/bin/gsview-dir\")
     (mpage     \"$HOME/bin/mpage-dir\")
     )

* On Windows system:

   '((windows   \"c:/applications/executables\" PATH ghostview mpage)
     (ghostview \"c:/gs/gsview-dir\")
     (mpage     \"c:/mpage-dir\")
     )"
  :type '(repeat
	  (cons :tag ""
		(symbol :tag "Identifier    ")
		(repeat :tag "Directory List"
			(choice :menu-tag "Directory"
				:tag "Directory"
				(string :value "")
				(symbol :value symbol)))))
1317
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
  :group 'printing)


(defcustom pr-txt-name 'default
  "*Specify a printer for printing a text file.

The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
documentation).

This variable should be modified by customization engine.  If this variable is
modified by other means (for example, a lisp function), use `pr-update-menus'
function (see it for documentation) to update text printer menu."
  :type 'symbol
  :set 'pr-txt-name-custom-set
1332
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
  :group 'printing)


(defcustom pr-txt-printer-alist
  (list (list 'default lpr-command nil
	      (cond ((boundp 'printer-name) printer-name)
		    (ps-windows-system "PRN")
		    (t nil)
		    )))
  ;; Examples:
  ;; * On GNU or Unix system:
  ;;    '((prt_06a "lpr" nil "prt_06a")
  ;;      (prt_07c nil   nil "prt_07c")
  ;;      )
  ;; * On Windows system:
  ;;    '((prt_06a  "print"     nil "/D:\\\\printers\\prt_06a")
  ;;      (prt_07c  nil         nil "/D:\\\\printers\\prt_07c")
  ;;      (PRN      ""          nil "PRN")
  ;;      (standard "redpr.exe" nil "")
  ;;      )
  "*Specify an alist of all text printers (text printer database).

The alist element has the form:

   (SYMBOL COMMAND SWITCHES NAME)

Where:

SYMBOL		It's a symbol to identify a text printer.  It's for
		`pr-txt-name' variable setting and for menu selection.
		Examples:
			'prt_06a
			'my_printer

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1367 1368 1369
COMMAND		Name of the program for printing a text file.  On MS-DOS and
		MS-Windows systems, if the value is an empty string, then Emacs
		will write directly to the printer port given by NAME (see text
Kim F. Storm's avatar
Kim F. Storm committed
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432
		below), that is, the NAME should be something like \"PRN\" or
		\"LPT1:\".
		If NAME is something like \"\\\\\\\\host\\\\share-name\" then
		COMMAND shouldn't be an empty string.
		The programs `print' and `nprint' (the standard print programs
		on Windows NT and Novell Netware respectively) are handled
		specially, using NAME as the destination for output; any other
		program is treated like `lpr' except that an explicit filename
		is given as the last argument.
		If COMMAND is nil, it's used the default printing program:
		`print' for Windows system, `lp' for lp system and `lpr' for
		all other systems.  See also `pr-path-alist'.
		Examples:
			\"print\"
			\"lpr\"
			\"lp\"

SWITCHES	List of sexp's to pass as extra options for text printer
		program.  It is recommended to set NAME (see text below)
		instead of including an explicit switch on this list.
		Example:
		   . for lpr
			'(\"-#3\" \"-l\")
			nil

NAME		A string that specifies a text printer name.
		On Unix-like systems, a string value should be a name
		understood by lpr's -P option (or lp's -d option).
		On MS-DOS and MS-Windows systems, it is the name of a printer
		device or port.  Typical non-default settings would be \"LPT1:\"
		to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
		\"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
		(or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
		printer.  You can also set it to a name of a file, in which
		case the output gets appended to that file.  If you want to
		discard the printed output, set this to \"NUL\".
		Examples:
		   . for print.exe
			\"/D:\\\\\\\\host\\\\share-name\"
			\"LPT1:\"
			\"PRN\"

		   . for lpr or lp
			\"share-name\"

This variable should be modified by customization engine.  If this variable is
modified by other means (for example, a lisp function), use `pr-update-menus'
function (see it for documentation) to update text printer menu.

Examples:

* On GNU or Unix system:

   '((prt_06a \"lpr\" nil \"prt_06a\")
     (prt_07c nil   nil \"prt_07c\")
     )

* On Windows system:

   '((prt_06a  \"print\"     nil \"/D:\\\\\\\\printers\\\\prt_06a\")
     (prt_07c  nil         nil \"/D:\\\\\\\\printers\\\\prt_07c\")
     (PRN      \"\"          nil \"PRN\")
     (standard \"redpr.exe\" nil \"\")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
     )

Useful links:

* Information about the print command (print.exe)
  `http://www.computerhope.com/printhlp.htm'

* RedMon - Redirection Port Monitor (redpr.exe)
  `http://www.cs.wisc.edu/~ghost/redmon/index.htm'

* Redirection Port Monitor (redpr.exe on-line help)
  `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'

* UNIX man pages: lpr (or type `man lpr')
  `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
  `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'

* UNIX man pages: lp (or type `man lp')
  `http://bama.ua.edu/cgi-bin/man-cgi?lp'
  `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
"
Kim F. Storm's avatar
Kim F. Storm committed
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
  :type '(repeat
	  (list :tag "Text Printer"
		(symbol :tag "Printer Symbol Name")
		(string :tag "Printer Command")
		(repeat :tag "Printer Switches"
			(sexp :tag "Switch" :value ""))
		(choice :menu-tag "Printer Name"
			:tag "Printer Name"
			(const :tag "None" nil)
			string)))
  :set 'pr-alist-custom-set
1465
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
  :group 'printing)


(defcustom pr-ps-name 'default
  "*Specify a printer for printing a PostScript file.

This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
documentation).

This variable should be modified by customization engine.  If this variable is
modified by other means (for example, a lisp function), use `pr-update-menus'
function (see it for documentation) to update PostScript printer menu."
  :type 'symbol
  :set 'pr-ps-name-custom-set
1480
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
  :group 'printing)


(defcustom pr-ps-printer-alist
  (list (list 'default lpr-command nil
	      (cond (ps-windows-system  nil)
		    (ps-lp-system       "-d")
		    (t                  "-P"))
	      (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
  ;; Examples:
  ;; * On GNU or Unix system:
  ;;    '((lps_06b "lpr" nil "-P" "lps_06b")
  ;;      (lps_07c "lpr" nil nil  "lps_07c")
  ;;      (lps_08c nil   nil nil  "lps_08c")
  ;;      )
  ;; * On Windows system:
  ;;    '((lps_06a  "print"     nil "/D:" "\\\\printers\\lps_06a")
  ;;      (lps_06b  "print"     nil nil   "\\\\printers\\lps_06b")
  ;;      (lps_07c  "print"     nil ""    "/D:\\\\printers\\lps_07c")
  ;;      (lps_08c  nil         nil nil   "\\\\printers\\lps_08c")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1501
  ;;      (b/w      "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
Kim F. Storm's avatar
Kim F. Storm committed
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
  ;;      (LPT1     ""          nil ""    "LPT1:")
  ;;      (PRN      ""          nil ""    "PRN")
  ;;      (standard "redpr.exe" nil ""    "")
  ;;      )
  "*Specify an alist for all PostScript printers (PostScript printer database).

The alist element has the form:

   (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)

Where:

SYMBOL		It's a symbol to identify a PostScript printer.  It's for
		`pr-ps-name' variable setting and for menu selection.
		Examples:
			'prt_06a
			'my_printer

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1520 1521 1522 1523 1524
COMMAND		Name of the program for printing a PostScript file.  On MS-DOS
		and MS-Windows systems, if the value is an empty string then
		Emacs will write directly to the printer port given by NAME
		(see text below), that is, the NAME should be something like
		\"PRN\" or \"LPT1:\".
Kim F. Storm's avatar
Kim F. Storm committed
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
		If NAME is something like \"\\\\\\\\host\\\\share-name\" then
		COMMAND shouldn't be an empty string.
		The programs `print' and `nprint' (the standard print programs
		on Windows NT and Novell Netware respectively) are handled
		specially, using NAME as the destination for output; any other
		program is treated like `lpr' except that an explicit filename
		is given as the last argument.
		If COMMAND is nil, it's used the default printing program:
		`print' for Windows system, `lp' for lp system and `lpr' for
		all other systems.  See also `pr-path-alist'.
		Examples:
			\"print\"
			\"lpr\"
			\"lp\"
			\"cp\"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1540
			\"gsprint\"
Kim F. Storm's avatar
Kim F. Storm committed
1541 1542 1543 1544 1545 1546 1547 1548 1549

SWITCHES	List of sexp's to pass as extra options for PostScript printer
		program.  It is recommended to set NAME (see text below)
		instead of including an explicit switch on this list.
		Example:
		   . for lpr
			'(\"-#3\" \"-l\")
			nil

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1550 1551 1552
		   . for gsprint.exe
			'(\"-all\" \"-twoup\")

Kim F. Storm's avatar
Kim F. Storm committed
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568
PRINTER-SWITCH	A string that specifies PostScript printer name switch.  If
		it's necessary to have a space between PRINTER-SWITCH and NAME,
		it should be inserted at the end of PRINTER-SWITCH string.
		If PRINTER-SWITCH is nil, it's used the default printer name
		switch: `/D:' for Windows system, `-d' for lp system and `-P'
		for all other systems.
		Examples:
		   . for lpr
			\"-P \"

		   . for lp
			\"-d \"

		   . for print.exe
			\"/D:\"

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1569 1570 1571
		   . for gsprint.exe
			\"-printer \"

Kim F. Storm's avatar
Kim F. Storm committed
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
NAME		A string that specifies a PostScript printer name.
		On Unix-like systems, a string value should be a name
		understood by lpr's -P option (or lp's -d option).
		On MS-DOS and MS-Windows systems, it is the name of a printer
		device or port.  Typical non-default settings would be \"LPT1:\"
		to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
		\"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
		(or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
		printer.  You can also set it to a name of a file, in which
		case the output gets appended to that file.  If you want to
		discard the printed output, set this to \"NUL\".
		Examples:
		   . for cp.exe
			\"\\\\\\\\host\\\\share-name\"

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1587
		   . for print.exe or gsprint.exe
Kim F. Storm's avatar
Kim F. Storm committed
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
			\"/D:\\\\\\\\host\\\\share-name\"
			\"\\\\\\\\host\\\\share-name\"
			\"LPT1:\"
			\"PRN\"

		   . for lpr or lp
			\"share-name\"

DEFAULT		It's a way to set default values when this entry is selected.
		It's a cons like:

		   (VARIABLE . VALUE)

		That associates VARIABLE with VALUE.  when this entry is
		selected, it's executed the following command:

		   (set VARIABLE (eval VALUE))

		Note that VALUE can be any valid lisp expression.  So, don't
		forget to quote symbols and constant lists.
		If VARIABLE is the special keyword `inherits-from:', VALUE must
		be a symbol name setting defined in `pr-setting-database' from
		which the current setting inherits the context.  Take care with
		circular inheritance.
		Examples:
			'(ps-landscape-mode . nil)
			'(ps-spool-duplex . t)
			'(pr-gs-device . (my-gs-device t))

This variable should be modified by customization engine.  If this variable is
modified by other means (for example, a lisp function), use `pr-update-menus'
function (see it for documentation) to update PostScript printer menu.

Examples:

* On GNU or Unix system:

   '((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
     (lps_07c \"lpr\" nil nil  \"lps_07c\")
     (lps_08c nil   nil nil  \"lps_08c\")
     )

* On Windows system:

   '((lps_06a  \"print\"     nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
     (lps_06b  \"print\"     nil nil   \"\\\\\\\\printers\\\\lps_06b\")
     (lps_07c  \"print\"     nil \"\"    \"/D:\\\\\\\\printers\\\\lps_07c\")
     (lps_08c  nil         nil nil   \"\\\\\\\\printers\\\\lps_08c\")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1636 1637
     (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
     (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
Kim F. Storm's avatar
Kim F. Storm committed
1638 1639 1640
     (LPT1     \"\"          nil \"\"    \"LPT1:\")
     (PRN      \"\"          nil \"\"    \"PRN\")
     (standard \"redpr.exe\" nil \"\"    \"\")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
     )


gsprint:

You can use gsprint instead of ghostscript to print monochrome PostScript files
in Windows.  The gsprint utility documentation says that it is more efficient
than ghostscript to print monochrome PostScript.

To print non-monochrome PostScript file, the efficiency of ghostscript is
similar to gsprint.

Also the gsprint utility comes together with gsview distribution.

As an example of gsprint declaration:

   (setq pr-ps-printer-alist
	 '((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
	   (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
	   ;; some other printer declaration
	   ))

The example above declares that printer A prints all pages (-all) and two pages
per sheet (-twoup).  The printer B declaration does the same as the printer A
declaration, the only difference is the printer name selection.

There are other command line options like:

   -mono	Render in monochrome as 1bit/pixel (only black and white).
   -grey	Render in greyscale as 8bits/pixel.
   -color	Render in color as 24bits/pixel.

The default is `-mono'.  So, printer A and B in the example above are using
implicitly the `-mono' option.  Note that in `-mono' no gray tone or color is
printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
are not printed.


Useful links:

* GSPRINT - Ghostscript print to Windows printer
  `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'

* Introduction to Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/intro.htm'

* How to use Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'

* Information about the print command (print.exe)
  `http://www.computerhope.com/printhlp.htm'

* RedMon - Redirection Port Monitor (redpr.exe)
  `http://www.cs.wisc.edu/~ghost/redmon/index.htm'

* Redirection Port Monitor (redpr.exe on-line help)
  `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'

* UNIX man pages: lpr (or type `man lpr')
  `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
  `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'

* UNIX man pages: lp (or type `man lp')
  `http://bama.ua.edu/cgi-bin/man-cgi?lp'
  `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'

* GNU utilities for Win32 (cp.exe)
  `http://unxutils.sourceforge.net/'
"
Kim F. Storm's avatar
Kim F. Storm committed
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752
  :type '(repeat
	  (list
	   :tag "PostScript Printer"
	   (symbol :tag "Printer Symbol Name")
	   (string :tag "Printer Command")
	   (repeat :tag "Printer Switches"
		   (sexp :tag "Switch" :value ""))
	   (choice :menu-tag "Printer Name Switch"
		   :tag "Printer Name Switch"
		   (const :tag "None" nil)
		   string)
	   (choice :menu-tag "Printer Name"
		   :tag "Printer Name"
		   (const :tag "None" nil)
		   string)
	   (repeat
	    :tag "Default Value List"
	    :inline t
	    (cons
	     :tag ""
	     (choice
	      :menu-tag "Variable"
	      :tag "Variable"
	      (const :tag "Landscape"              ps-landscape-mode)
	      (const :tag "Print Header"           ps-print-header)
	      (const :tag "Print Header Frame"     ps-print-header-frame)
	      (const :tag "Line Number"            ps-line-number)
	      (const :tag "Zebra Stripes"          ps-zebra-stripes)
	      (const :tag "Duplex"                 ps-spool-duplex)
	      (const :tag "Tumble"                 ps-spool-tumble)
	      (const :tag "Upside-Down"            ps-print-upside-down)
	      (const :tag "PS File Landscape"      pr-file-landscape)
	      (const :tag "PS File Duplex"         pr-file-duplex)
	      (const :tag "PS File Tumble"         pr-file-tumble)
	      (const :tag "Auto Region"            pr-auto-region)
	      (const :tag "Auto Mode"              pr-auto-mode)
	      (const :tag "Ghostscript Device"     pr-gs-device)
	      (const :tag "Ghostscript Resolution" pr-gs-resolution)
	      (const :tag "inherits-from:"         inherits-from:)
	      (variable :tag "Other"))
	     (sexp :tag "Value")))
	   ))
  :set 'pr-alist-custom-set
1753
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1754 1755 1756 1757
  :group 'printing)


(defcustom pr-temp-dir
1758
  (pr-dosify-file-name
Kim F. Storm's avatar
Kim F. Storm committed
1759 1760 1761 1762 1763 1764 1765 1766 1767
   (if (boundp 'temporary-file-directory)
       (symbol-value 'temporary-file-directory)
     ;; hacked from `temporary-file-directory' variable in files.el
     (file-name-as-directory
      (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
	  (cond (ps-windows-system "c:/temp")
		((memq system-type '(vax-vms axp-vms)) "SYS$SCRATCH:")
		(t "/tmp")
		)))))
1768 1769 1770
  "*Specify a directory for temporary files during printing.

See also `pr-ps-temp-file' and `pr-file-modes'."
Kim F. Storm's avatar
Kim F. Storm committed
1771
  :type '(directory :tag "Temporary Directory")
1772
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1773 1774 1775
  :group 'printing)


1776 1777
(defcustom pr-ps-temp-file "prspool-"
  "*Specify PostScript temporary file name prefix.
1778 1779

See also `pr-temp-dir' and `pr-file-modes'."
Kim F. Storm's avatar
Kim F. Storm committed
1780
  :type '(file :tag "PostScript Temporary File Name")
1781
  :version "21"
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795
  :group 'printing)


;; It uses 0600 as default instead of (default-file-modes).
;; So, by default, only the session owner have permission to deal with files
;; generated by `printing'.
(defcustom pr-file-modes ?\600
  "*Specify the file permission bits for newly created files.

It should be an integer; only the low 9 bits are used.

See also `pr-temp-dir' and `pr-ps-temp-file'."
  :type '(integer :tag "File Permission Bits")
  :version "21.3"
Kim F. Storm's avatar
Kim F. Storm committed
1796 1797 1798 1799 1800 1801 1802
  :group 'printing)


(defcustom pr-gv-command
  (if ps-windows-system
      "gsview32.exe"
    "gv")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1803
  "*Specify path and name of the gsview/gv utility.
Kim F. Storm's avatar
Kim F. Storm committed
1804

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835
See also `pr-path-alist'.

Useful links:

* GNU gv manual
  `http://www.gnu.org/software/gv/manual/gv.html'

* GSview Help
  `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'

* GSview Help - Common Problems
  `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'

* GSview Readme (compilation & installation)
  `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'

* GSview (main site)
  `http://www.cs.wisc.edu/~ghost/gsview/index.htm'

* Ghostscript, Ghostview and GSview
  `http://www.cs.wisc.edu/~ghost/'

* Ghostview
  `http://www.cs.wisc.edu/~ghost/gv/index.htm'

* gv 3.5, June 1997
  `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'

* MacGSView (MacOS)
  `http://www.cs.wisc.edu/~ghost/macos/index.htm'
"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1836
  :type '(string :tag "Ghostview Utility")
1837
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1838 1839 1840 1841 1842 1843 1844
  :group 'printing)


(defcustom pr-gs-command
  (if ps-windows-system
      "gswin32.exe"
    "gs")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1845
  "*Specify path and name of the ghostscript utility.
Kim F. Storm's avatar
Kim F. Storm committed
1846

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
See also `pr-path-alist'.

Useful links:

* Ghostscript, Ghostview and GSview
  `http://www.cs.wisc.edu/~ghost/'

* Introduction to Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/intro.htm'

* How to use Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'

* Printer compatibility
  `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1863
  :type '(string :tag "Ghostscript Utility")
1864
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
  :group 'printing)


(defcustom pr-gs-switches
  (if ps-windows-system
      '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
    '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
  "*Specify ghostscript switches.  See the documentation on GS for more info.

It's a list of strings, where each string is one or more ghostscript switches.

A note on the gs switches:

-q					quiet
-dNOPAUSE				don't wait for user intervention
-Ic:/gs/gs5.50;c:/gs/gs5.50/fonts	the directories needed for gs
-c quit					it's added at the end to terminate gs

To see ghostscript documentation for more information:

* On GNU or Unix system:
   - for full documentation, type: man gs
   - for brief documentation, type: gs -h

* On Windows system:
   - for full documentation, see in a browser the file
     c:/gstools/gs5.50/index.html, that is, the file index.html which is
     located in the same directory as gswin32.exe.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905
   - for brief documentation, type: gswin32.exe -h

Useful links:

* Introduction to Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/intro.htm'

* How to use Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'

* Printer compatibility
  `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
"
Kim F. Storm's avatar
Kim F. Storm committed
1906
  :type '(repeat (string :tag "Ghostscript Switch"))
1907
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1908 1909 1910 1911 1912 1913 1914
  :group 'printing)


(defcustom pr-gs-device
  (if ps-windows-system
      "mswinpr2"
    "uniprint")
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1915
  "*Specify the ghostscript device switch value (-sDEVICE=).
Kim F. Storm's avatar
Kim F. Storm committed
1916 1917 1918 1919 1920 1921 1922 1923

A note on the gs switches:

-sDEVICE=djet500	the printer - works with HP DeskJet 540

See `pr-gs-switches' for documentation.
See also `pr-ps-printer-alist'."
  :type '(string :tag "Ghostscript Device")
1924
  :version "20"
Kim F. Storm's avatar
Kim F. Storm committed
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
  :group 'printing)


(defcustom pr-gs-resolution 300
  "*Specify ghostscript resolution switch value (-r).

A note on the gs switches:

-r300	resolution 300x300

See `pr-gs-switches' for documentation.
See also `pr-ps-printer-alist'."
  :type '(integer :tag "Ghostscript Resolution")