printing.el 210 KB
Newer Older
1
;;; printing.el --- printing utilities  -*- lexical-binding:t -*-
Kim F. Storm's avatar
Kim F. Storm committed
2

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 2000-2001, 2003-2019 Free Software Foundation, Inc.
Kim F. Storm's avatar
Kim F. Storm committed
4

viniciusjl's avatar
viniciusjl committed
5
;; Author: Vinicius Jose Latorre <viniciusjl.gnu@gmail.com>
Kim F. Storm's avatar
Kim F. Storm committed
6
;; Keywords: wp, print, PostScript
7
;; Version: 6.9.3
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
8
;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
Kim F. Storm's avatar
Kim F. Storm committed
9

10 11
(defconst pr-version "6.9.3"
  "printing.el, v 6.9.3 <2007/12/09 vinicius>
Kim F. Storm's avatar
Kim F. Storm committed
12 13

Please send all bug fixes and enhancements to
viniciusjl's avatar
viniciusjl committed
14
	bug-gnu-emacs@gnu.org and Vinicius Jose Latorre <viniciusjl.gnu@gmail.com>
Kim F. Storm's avatar
Kim F. Storm committed
15 16 17 18
")

;; This file is part of GNU Emacs.

19 20 21 22 23 24 25 26 27 28 29
;; 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 3 of the License, 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
30
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
Kim F. Storm's avatar
Kim F. Storm committed
31 32 33 34 35 36 37 38

;;; Commentary:

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Introduction
;; ------------
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
39 40 41 42 43
;; 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.
44
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
45
;; There are two user interfaces:
46
;;
47
;;    * Menu interface:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
48
;;      The `printing' menu replaces the usual print options in the menu bar.
49 50
;;      This is the default user interface.
;;
51
;;    * Buffer interface:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
52 53 54
;;      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
55 56 57 58 59
;;
;; `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
60
;; `https://www.gnu.org/software/ghostscript/ghostscript.html'.
Kim F. Storm's avatar
Kim F. Storm committed
61
;;
62 63 64 65
;; `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
66
;; To download the latest ps-print package see
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
67
;; `http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'.
Kim F. Storm's avatar
Kim F. Storm committed
68 69
;; Please, see README file for ps-print installation instructions.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
70
;; `printing' was inspired by:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
71 72 73 74 75 76 77 78 79 80 81 82 83
;;
;;    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
84
;;
85 86 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
;; 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
121 122 123
;; Novices (First Users)
;; ---------------------
;;
124 125
;; 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
126 127 128 129 130
;;
;; 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.
;;
131 132 133
;; 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
134 135 136 137 138 139 140
;;
;; 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
141 142 143
;; section).  Other way is by adding code to your init file; see below
;; for a first setting template that it should be inserted on your
;; init file:
Kim F. Storm's avatar
Kim F. Storm committed
144 145 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
;;
;; * 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
215 216 217 218 219 220
;; NOTE 4: See Tips section.
;;
;;
;; Tips
;; ----
;;
221
;; 1. If you have a local printer, that is, a printer which is connected
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
222 223 224
;;    directly to your computer, don't forget to connect the printer to your
;;    computer before printing.
;;
225 226 227 228 229 230 231 232 233 234 235
;; 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.
;;
236 237 238 239 240
;; 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
;;
241
;;    Where, `host' is the machine where the printer is directly connected,
242
;;    `printer' is the printer name and `somefile.txt' is a text file.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
243
;;
244 245
;;    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
246
;;
247 248 249 250 251 252 253 254 255
;;       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).
256
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
257 258 259
;; 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
260
;;
261 262
;;    To print non-monochrome PostScript file, the efficiency of ghostscript
;;    is similar to gsprint.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
263 264 265 266 267 268
;;
;;    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
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
;;    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
294 295 296 297
;;
;; Using `printing'
;; ----------------
;;
298
;; To use `printing' insert in your init file:
Kim F. Storm's avatar
Kim F. Storm committed
299 300
;;
;;    (require 'printing)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
301 302
;;    ;; ...some user settings...
;;    (pr-update-menus t)
Kim F. Storm's avatar
Kim F. Storm committed
303
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
304
;; During `pr-update-menus' evaluation:
Kim F. Storm's avatar
Kim F. Storm committed
305 306 307 308 309 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
;;   * 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
384 385 386
;;    `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
387 388 389 390 391 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
;;    `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.
;;
462
;; Current global keyboard mapping is:
Kim F. Storm's avatar
Kim F. Storm committed
463
;;
464 465 466 467 468
;;    (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
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
;;
;; 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.
;;
487
;; `pr-filename-style'		Specify which filename style to use for external
Kim F. Storm's avatar
Kim F. Storm committed
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
;;				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.
;;
504
;; `pr-ps-temp-file'		Specify PostScript temporary file name prefix.
Kim F. Storm's avatar
Kim F. Storm committed
505
;;
506 507 508
;; `pr-file-modes'		Specify the file permission bits for newly
;;				created files.
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
509 510
;; `pr-gv-command'		Specify path and name of the gsview/gv
;;				utility.
Kim F. Storm's avatar
Kim F. Storm committed
511
;;
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
512 513
;; `pr-gs-command'		Specify path and name of the ghostscript
;;				utility.
Kim F. Storm's avatar
Kim F. Storm committed
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
;;
;; `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
538
;; `pr-auto-mode'		Non-nil means major-mode specific printing is
Paul Eggert's avatar
Paul Eggert committed
539
;;				preferred over normal printing.
Kim F. Storm's avatar
Kim F. Storm committed
540 541 542 543 544 545 546 547 548 549 550 551 552 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
;;
;; `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       >|-\ | | +-----------+  |
;;        +-----------------------------+ | | | +---------+   +------------+
642
;; III 7  |[ ]Landscape                 | | | \-|Directory|   | No Prep... | Ia
Kim F. Storm's avatar
Kim F. Storm committed
643 644 645 646 647 648 649 650 651 652
;;     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
653 654
;;     17 |[ ]Print with faces          |  | \--|( )name A|   |[ ]Tumble   | If
;;     18 |[ ]Print via Ghostscript     |  |    |( )name B|   +------------+
Kim F. Storm's avatar
Kim F. Storm committed
655 656 657 658 659 660 661 662 663 664 665 666 667 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
;;        +-----------------------------+  |    |...      |
;; 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:
706 707
;;		 Ia. Print the file *No Preprocessing*, that is, send it
;;		     directly to PostScript printer.
Kim F. Storm's avatar
Kim F. Storm committed
708 709 710 711 712 713 714 715 716 717 718 719 720 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
;;		 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
817
;;    21. If you want that Printing menu stays open while you are setting
Kim F. Storm's avatar
Kim F. Storm committed
818 819 820 821 822 823 824 825 826 827 828 829 830 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
;;	  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
901
;;            (b/w      "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
Kim F. Storm's avatar
Kim F. Storm committed
902 903 904 905 906 907 908 909 910 911 912 913 914 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
;;            (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
940 941 942
;;    `pr-menu-bind'	Install `printing' menu in the menubar.
;;
;;
Kim F. Storm's avatar
Kim F. Storm committed
943 944 945 946
;; Below are some URL where you can find good utilities.
;;
;; * For `printing' package:
;;
947
;;    printing	`http://www.emacswiki.org/cgi-bin/emacs/download/printing.el'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
948
;;    ps-print	`http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'
Kim F. Storm's avatar
Kim F. Storm committed
949 950 951
;;
;; * For GNU or Unix system:
;;
952
;;    gs, gv         `https://www.gnu.org/software/ghostscript/ghostscript.html'
Kim F. Storm's avatar
Kim F. Storm committed
953
;;    enscript       `http://people.ssh.fi/mtr/genscript/'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
954
;;    psnup          `http://www.knackered.org/angus/psutils/'
Kim F. Storm's avatar
Kim F. Storm committed
955 956 957 958 959
;;    mpage          `http://www.mesa.nl/pub/mpage/'
;;
;; * For Windows system:
;;
;;    gswin32, gsview32
960
;;                   `https://www.gnu.org/software/ghostscript/ghostscript.html'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
961
;;    gsprint        `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
Kim F. Storm's avatar
Kim F. Storm committed
962
;;    enscript       `http://people.ssh.fi/mtr/genscript/'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
963
;;    psnup          `http://gnuwin32.sourceforge.net/packages/psutils.htm'
Kim F. Storm's avatar
Kim F. Storm committed
964 965 966 967 968 969
;;    redmon         `http://www.cs.wisc.edu/~ghost/redmon/'
;;
;;
;; Acknowledgments
;; ---------------
;;
970 971 972
;; 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
973 974 975
;; Thanks to Lennart Borgman <lennart.borgman.073@student.lu.se> for gsprint
;; suggestion (see tip 5 in section Tips).
;;
976 977 978 979 980
;; 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
981 982 983 984 985 986 987 988 989 990 991 992
;;
;; 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.
993
;;    - `pr-filename-style' variable.
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
;;
;; 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:


1015 1016
(require 'lpr)
(require 'ps-print)
1017
(require 'easymenu)
Kim F. Storm's avatar
Kim F. Storm committed
1018

1019
(and (string< ps-print-version "6.6.4")
1020
     (error "`printing' requires `ps-print' package version 6.6.4 or later"))
Kim F. Storm's avatar
Kim F. Storm committed
1021 1022


1023
(defconst pr-cygwin-system
1024
  (and lpr-windows-system (getenv "OSTYPE")
1025
       (string-match "cygwin" (getenv "OSTYPE"))))
Kim F. Storm's avatar
Kim F. Storm committed
1026 1027 1028 1029 1030 1031


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


1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
;; User Interface --- declared here to avoid compiler warnings
(define-obsolete-variable-alias 'pr-path-style 'pr-filename-style "27.1")
(defvar pr-filename-style)
(defvar pr-auto-region)
(defvar pr-menu-char-height)
(defvar pr-menu-char-width)
(defvar pr-menu-lock)
(defvar pr-ps-printer-alist)
(defvar pr-txt-printer-alist)
(defvar pr-ps-utility-alist)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1042 1043 1044 1045

;; Internal Vars --- defined here to avoid compiler warnings
(defvar pr-menu-print-item "print"
  "Non-nil means that menu binding was not done.
1046

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1047
Used by `pr-menu-bind' and `pr-update-menus'.")
1048

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1049 1050
(defvar pr-ps-printer-menu-modified  t
  "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
1051

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1052 1053
(defvar pr-txt-printer-menu-modified t
  "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
1054

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1055 1056
(defvar pr-ps-utility-menu-modified t
  "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
1057

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1058 1059 1060 1061 1062 1063
(defconst pr-even-or-odd-alist
  '((nil        . "Print All Pages")
    (even-page  . "Print Even Pages")
    (odd-page   . "Print Odd Pages")
    (even-sheet . "Print Even Sheets")
    (odd-sheet  . "Print Odd Sheets")))
1064

Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1065 1066 1067

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1068
;; GNU Emacs Definitions
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1069

1070 1071
(defun pr-keep-region-active ()
  (setq deactivate-mark nil))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1072

1073 1074
(defun pr-region-active-p ()
  (and pr-auto-region (use-region-p)))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1075

1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
;; Menu binding
;; Replace existing "print" item by "Printing" item.
;; If you're changing this file, you'll load it a second,
;; third... time, but "print" item exists only in the first load.

(defvar pr-menu-bar nil
  "Specify Printing menu-bar entry.")

(defun pr-global-menubar (menu-spec)
  (let ((menu-file '("menu-bar" "file")))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1086
    (cond
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
     (pr-menu-print-item
      (easy-menu-add-item global-map menu-file
                          (easy-menu-create-menu "Print" menu-spec)
                          "print-buffer")
      (dolist (item '("print-buffer"          "print-region"
                      "ps-print-buffer-faces" "ps-print-region-faces"
                      "ps-print-buffer"       "ps-print-region"))
        (easy-menu-remove-item global-map menu-file item))
      (setq pr-menu-print-item nil
            pr-menu-bar (vector 'menu-bar
                                (easy-menu-intern (nth 1 menu-file))
                                (easy-menu-intern "Print"))))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1099
     (t
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 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
      (easy-menu-add-item global-map menu-file
                          (easy-menu-create-menu "Print" menu-spec)))
     )))

(defun pr-menu-position (entry index horizontal)
  (let ((pos (cdr (mouse-pixel-position))))
    (list
     (list (- (or (car pos) 0)	; X
              (if lpr-windows-system
                  0 ;; GNU Emacs for Windows 9x/NT
                (* horizontal pr-menu-char-width)))
           (- (or (cdr pos) 0)	; Y
              (* (pr-menu-index entry index) pr-menu-char-height)))
     (selected-frame))))		; frame

(defvar pr-menu-position nil)
(defvar pr-menu-state    nil)

(defun pr-menu-lookup (path)
  (lookup-key global-map
	      (if path
		  (vconcat pr-menu-bar
			   (mapcar #'easy-menu-intern
				   (if (listp path)
				       path
				     (list path))))
		pr-menu-bar)))

(defun pr-menu-lock (entry index horizontal state path)
  (when pr-menu-lock
    (or (and pr-menu-position (eq state pr-menu-state))
	(setq pr-menu-position (pr-menu-position entry index horizontal)
	      pr-menu-state    state))
    (let* ((menu   (pr-menu-lookup path))
	   (result (x-popup-menu pr-menu-position menu)))
      (and result
	   (let ((command (lookup-key menu (vconcat result))))
	     (if (fboundp command)
		 (funcall command)
	       (eval command)))))
    (setq pr-menu-position nil)))

(defun pr-do-update-menus (&optional force)
  (pr-menu-alist pr-ps-printer-alist
		 'pr-ps-name
		 #'pr-menu-set-ps-title
		 "PostScript Printers"
		 'pr-ps-printer-menu-modified
		 force
		 "PostScript Printers"
		 'postscript 2)
  (pr-menu-alist pr-txt-printer-alist
		 'pr-txt-name
		 #'pr-menu-set-txt-title
		 "Text Printers"
		 'pr-txt-printer-menu-modified
		 force
		 "Text Printers"
		 'text 2)
  (defvar pr--save-var)
  (let ((pr--save-var pr-ps-utility-menu-modified))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1161 1162
    (pr-menu-alist pr-ps-utility-alist
		   'pr-ps-utility
1163 1164 1165
		   #'pr-menu-set-utility-title
		   '("PostScript Print" "File" "PostScript Utility")
		   'pr--save-var
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1166 1167
		   force
		   "PostScript Utility"
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
		   nil 1))
  (pr-menu-alist pr-ps-utility-alist
		 'pr-ps-utility
		 #'pr-menu-set-utility-title
		 '("PostScript Preview" "File" "PostScript Utility")
		 'pr-ps-utility-menu-modified
		 force
		 "PostScript Utility"
		 nil 1)
  (pr-even-or-odd-pages ps-even-or-odd-pages force))

(defun pr-menu-get-item (name-list)
  ;; NAME-LIST is a string or a list of strings.
  (or (listp name-list)
      (setq name-list (list name-list)))
  (and name-list
       (let* ((reversed (reverse name-list))
	      (name (easy-menu-intern (car reversed)))
	      (path (nreverse (cdr reversed)))
	      (menu (lookup-key
		     global-map
		     (vconcat pr-menu-bar
			      (mapcar #'easy-menu-intern path)))))
	 (assq name (nthcdr 2 menu)))))

(defvar pr-temp-menu nil)

(defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
			    entry index)
  (when (and alist (or force (symbol-value modified-sym)))
    (easy-menu-define pr-temp-menu nil ""
      (pr-menu-create name alist var-sym fun entry index))
    (let ((item (pr-menu-get-item menu-path)))
      (and item
           (progn
	     (setf (nth 3 item) pr-temp-menu)
	     (funcall fun (symbol-value var-sym) item))))
    (set modified-sym nil)))

(defun pr-menu-set-item-name (item name)
  (and item
       (setcar (nthcdr 2 item) name))) ; ITEM-NAME

(defun pr-menu-set-ps-title (value &optional item entry index)
  (pr-menu-set-item-name (or item
			     (pr-menu-get-item "PostScript Printers"))
			 (format "PostScript Printer: %s" value))
  (pr-ps-set-printer value)
  (and index
       (pr-menu-lock entry index 12 'toggle nil)))

(defun pr-menu-set-txt-title (value &optional item entry index)
  (pr-menu-set-item-name (or item
			     (pr-menu-get-item "Text Printers"))
			 (format "Text Printer: %s" value))
  (pr-txt-set-printer value)
  (and index
       (pr-menu-lock entry index 12 'toggle nil)))

(defun pr-menu-set-utility-title (value &optional item entry index)
  (let ((name (symbol-name value)))
    (if item
	(pr-menu-set-item-name item name)
      (pr-menu-set-item-name
       (pr-menu-get-item
	'("PostScript Print"   "File" "PostScript Utility"))
       name)
      (pr-menu-set-item-name
       (pr-menu-get-item
	'("PostScript Preview" "File" "PostScript Utility"))
       name)))
  (pr-ps-set-utility value)
  (and index
       (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))

(defun pr-even-or-odd-pages (value &optional no-lock)
  (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
			 (cdr (assq value pr-even-or-odd-alist)))
  (setq ps-even-or-odd-pages value)
  (or no-lock
      (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1249 1250 1251 1252 1253

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


1254
(defun pr-dosify-file-name (filename)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1255
  "Replace unix-style directory separator character with dos/windows one."
1256 1257 1258
  (if (eq pr-filename-style 'windows)
      (subst-char-in-string ?/ ?\\ filename)
    filename))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1259

1260
(defun pr-standard-file-name (filename)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1261 1262 1263
  "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."
1264
  ;; FIXME: Why not use pr-dosify-file-name?
1265
  (if (or pr-cygwin-system lpr-windows-system)
1266 1267
      (subst-char-in-string ?/ ?\\ filename)
    filename))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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


(defgroup printing nil
  "Printing Utilities group."
  :tag "Printing Utilities"
  :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
  :prefix "pr-"
1310
  :version "22.1"
1311
  :group 'text
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1312 1313 1314
  :group 'postscript)


1315
(defcustom pr-filename-style
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1316
  (if (and (not pr-cygwin-system)
1317
	   lpr-windows-system)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1318 1319
      'windows
    'unix)
1320
  "Specify which filename style to use for external commands.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1321 1322 1323 1324 1325 1326

Valid values are:

   windows	Windows 9x/NT style (\\)

   unix		Unix style (/)"
1327
  :type '(choice :tag "Filename style"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1328
		 (const :tag "Windows 9x/NT Style (\\)" :value windows)
1329
		 (const :tag "Unix Style (/)" :value unix)))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1330 1331 1332 1333 1334 1335


(defcustom pr-path-alist
  '((unix    PATH)
    (cygwin  PATH)
    (windows PATH))
Lute Kamstra's avatar
Lute Kamstra committed
1336
  "Specify an alist for command paths.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349

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:

1350
		`unix'	this entry is used when Emacs is running on GNU or
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1351 1352
			Unix system.

1353
		`cygwin'	this entry is used when Emacs is running on Windows
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1354 1355
			95/98/NT/2000 with Cygwin.

1356
		`windows'	this entry is used when Emacs is running on Windows
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
			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:

Paul Eggert's avatar
Paul Eggert committed
1388
    ((unix      \".\" \"~/bin\" ghostview mpage PATH)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1389 1390 1391 1392 1393 1394
     (ghostview \"$HOME/bin/gsview-dir\")
     (mpage     \"$HOME/bin/mpage-dir\")
     )

* On Windows system:

Paul Eggert's avatar
Paul Eggert committed
1395
    ((windows   \"c:/applications/executables\" PATH ghostview mpage)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
     (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 "")
1406
				(symbol :value symbol))))))
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1407 1408 1409


(defcustom pr-txt-name 'default
Lute Kamstra's avatar
Lute Kamstra committed
1410
  "Specify a printer for printing a text file.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1411 1412 1413 1414 1415 1416 1417 1418

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
1419
  :set 'pr-txt-name-custom-set)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1420 1421


1422 1423 1424
(defcustom pr-txt-printer-alist
  (list (list 'default lpr-command nil
	      (cond ((boundp 'printer-name) printer-name)
1425
		    (lpr-windows-system "PRN")
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
		    (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 "")
  ;;      )
Lute Kamstra's avatar
Lute Kamstra committed
1439
  "Specify an alist of all text printers (text printer database).
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1440

1441
The alist element has the form:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1442

1443
   (SYMBOL COMMAND SWITCHES NAME)
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1444

1445
Where:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1446

1447
SYMBOL		It's a symbol to identify a text printer.  It's for
1448
		setting option `pr-txt-name' and for menu selection.
1449
		Examples:
Paul Eggert's avatar
Paul Eggert committed
1450 1451
			prt_06a
			my_printer
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1452

1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
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
		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\"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1472

1473 1474 1475 1476 1477
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
Paul Eggert's avatar
Paul Eggert committed
1478
			(\"-#3\" \"-l\")
1479
			nil
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1480

1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
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\"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1497

1498 1499
		   . for lpr or lp
			\"share-name\"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1500

1501 1502 1503
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.
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1504

1505
Examples:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1506

1507
* On GNU or Unix system:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1508

Paul Eggert's avatar
Paul Eggert committed
1509
    ((prt_06a \"lpr\" nil \"prt_06a\")
1510 1511
     (prt_07c nil   nil \"prt_07c\")
     )
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1512

1513
* On Windows system:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1514

Paul Eggert's avatar
Paul Eggert committed
1515
    ((prt_06a  \"print\"     nil \"/D:\\\\\\\\printers\\\\prt_06a\")
1516 1517 1518 1519
     (prt_07c  nil         nil \"/D:\\\\\\\\printers\\\\prt_07c\")
     (PRN      \"\"          nil \"PRN\")
     (standard \"redpr.exe\" nil \"\")
     )
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1520

1521
Useful links:
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1522

1523 1524
* Information about the print command (print.exe)
  `http://www.computerhope.com/printhlp.htm'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1525

1526 1527
* RedMon - Redirection Port Monitor (redpr.exe)
  `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1528

1529 1530
* Redirection Port Monitor (redpr.exe on-line help)
  `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1531

1532 1533 1534
* 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'
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1535

1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
* 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'
"
  :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)))
1550
  :set 'pr-alist-custom-set)
1551 1552 1553


(defcustom pr-ps-name 'default
Lute Kamstra's avatar
Lute Kamstra committed
1554
  "Specify a printer for printing a PostScript file.
1555 1556 1557 1558 1559 1560 1561 1562

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
1563
  :set 'pr-ps-name-custom-set)
1564 1565 1566 1567


(defcustom pr-ps-printer-alist
  (list (list 'default lpr-command nil
1568 1569
	      (cond (lpr-windows-system  nil)
		    (lpr-lp-system       "-d")
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
		    (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")
  ;;      (b/w      "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
  ;;      (LPT1     ""          nil ""    "LPT1:")
  ;;      (PRN      ""          nil ""    "PRN")
  ;;      (standard "redpr.exe" nil ""    "")
  ;;      )
Lute Kamstra's avatar
Lute Kamstra committed
1588
  "Specify an alist for all PostScript printers (PostScript printer database).
1589 1590 1591 1592 1593 1594 1595 1596

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
1597
		setting option `pr-ps-name' and for menu selection.
1598
		Examples:
Paul Eggert's avatar
Paul Eggert committed
1599 1600
			prt_06a
			my_printer
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

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:\".
		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\"
			\"gsprint\"

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
Paul Eggert's avatar
Paul Eggert committed
1629
			(\"-#3\" \"-l\")
1630 1631 1632
			nil

		   . for gsprint.exe
Paul Eggert's avatar
Paul Eggert committed
1633
			(\"-all\" \"-twoup\")
1634 1635 1636 1637 1638 1639 1640 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

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:\"

		   . for gsprint.exe
			\"-printer \"

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\"

		   . for print.exe or gsprint.exe
			\"/D:\\\\\\\\host\\\\share-name\"
			\"\\\\\\\\host\\\\share-name\"
			\"LPT1:\"
			\"PRN\"
Vinicius Jose Latorre's avatar
Vinicius Jose Latorre committed
1674

1675 1676
		   . for lpr or lp
			\"share-name\"
Kim F. Storm's avatar
Kim F. Storm committed
1677

1678 1679
DEFAULT		It's a way to set default values when this entry is selected.
		It's a cons like:
Kim F. Storm's avatar
Kim F. Storm committed
1680

1681
		   (VARIABLE . VALUE)
Kim F. Storm's avatar
Kim F. Storm committed
1682

1683 1684
		Which associates VARIABLE with VALUE.  When this entry is
		selected, it's executed the following command:
Kim F. Storm's avatar
Kim F. Storm committed
1685

1686
		   (set VARIABLE (eval VALUE))
Kim F. Storm's avatar
Kim F. Storm committed
1687

1688 1689 1690 1691 1692 1693 1694
		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:
Paul Eggert's avatar
Paul Eggert committed
1695 1696 1697
			(ps-landscape-mode . nil)
			(ps-spool-duplex . t)
			(pr-gs-device . (my-gs-device t))
Kim F. Storm's avatar
Kim F. Storm committed
1698

1699 1700 1701
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.
Kim F. Storm's avatar
Kim F. Storm committed
1702

1703
Examples:
Kim F. Storm's avatar
Kim F. Storm committed
1704

1705
* On GNU or Unix system:
Kim F. Storm's avatar
Kim F. Storm committed
1706

Paul Eggert's avatar
Paul Eggert committed
1707
    ((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
1708 1709 1710
     (lps_07c \"lpr\" nil nil  \"lps_07c\")
     (lps_08c nil   nil nil  \"lps_08c\")
     )
Kim F. Storm's avatar
Kim F. Storm committed
1711

1712 1713
* On Windows system:

Paul Eggert's avatar
Paul Eggert committed
1714
    ((lps_06a  \"print\"     nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
1715 1716 1717 1718 1719 1720 1721 1722 1723
     (lps_06b  \"print\"     nil nil   \"\\\\\\\\printers\\\\lps_06b\")
     (lps_07c  \"print\"     nil \"\"    \"/D:\\\\\\\\printers\\\\lps_07c\")
     (lps_08c  nil         nil nil   \"\\\\\\\\printers\\\\lps_08c\")
     (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
     (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
     (LPT1     \"\"          nil \"\"    \"LPT1:\")
     (PRN      \"\"          nil \"\"    \"PRN\")
     (standard \"redpr.exe\" nil \"\"    \"\")
     )
Kim F. Storm's avatar
Kim F. Storm committed
1724 1725


1726
gsprint:
Kim F. Storm's avatar
Kim F. Storm committed
1727

1728 1729 1730
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.
Kim F. Storm's avatar
Kim F. Storm committed
1731

1732 1733
To print non-monochrome PostScript file, the efficiency of ghostscript is
similar to gsprint.
Kim F. Storm's avatar
Kim F. Storm committed
1734

1735
Also the gsprint utility comes together with gsview distribution.
Kim F. Storm's avatar
Kim F. Storm committed
1736

1737
As an example of gsprint declaration:
Kim F. Storm's avatar
Kim F. Storm committed
1738

1739
   (setq pr-ps-printer-alist
Paul Eggert's avatar
Paul Eggert committed
1740
	 \\='((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
1741 1742 1743
	   (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
	   ;; some other printer declaration
	   ))
Kim F. Storm's avatar
Kim F. Storm committed
1744

1745 1746 1747
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.
Kim F. Storm's avatar
Kim F. Storm committed
1748

1749
There are other command line options like:
Kim F. Storm's avatar
Kim F. Storm committed
1750

1751 1752 1753
   -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.
Kim F. Storm's avatar
Kim F. Storm committed
1754

1755 1756 1757 1758
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.
Kim F. Storm's avatar
Kim F. Storm committed
1759 1760


1761
Useful links:
Kim F. Storm's avatar
Kim F. Storm committed
1762

1763 1764
* GSPRINT - Ghostscript print to Windows printer
  `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
Kim F. Storm's avatar
Kim F. Storm committed
1765

1766 1767
* Introduction to Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
Kim F. Storm's avatar
Kim F. Storm committed
1768

1769 1770
* How to use Ghostscript
  `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
Kim F. Storm's avatar
Kim F. Storm committed
1771

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

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

1778 1779
* Redirection Port Monitor (redpr.exe on-line help)
  `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
Kim F. Storm's avatar
Kim F. Storm committed
1780

1781 1782 1783
* 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'
Kim F. Storm's avatar
Kim F. Storm committed
1784

1785 1786 1787
* 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
1788

1789
* GNU utilities for w32 (cp.exe)
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 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
  `http://unxutils.sourceforge.net/'
"
  :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")))
	   ))
1834 1835 1836 1837
  :set 'pr-alist-custom-set)


(defcustom pr-temp-dir temporary-file-directory
Lute Kamstra's avatar
Lute Kamstra committed
1838
  "Specify a directory for temporary files during printing.
Kim F. Storm's avatar
Kim F. Storm committed
1839

1840
See also `pr-ps-temp-file' and `pr-file-modes'."
1841
  :type '(directory :tag "Temporary Directory"))
Kim F. Storm's avatar
Kim F. Storm committed
1842 1843


1844
(defcustom pr-ps-temp-file "prspool-"
Lute Kamstra's avatar
Lute Kamstra committed
1845
  "Specify PostScript temporary file name prefix.
Kim F. Storm's avatar
Kim F. Storm committed
1846

1847
See also `pr-temp-dir' and `pr-file-modes'."
1848
  :type '(file :tag "PostScript Temporary File Name"))
Kim F. Storm's avatar
Kim F. Storm committed
1849 1850


1851 1852 1853 1854
;; 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
Lute Kamstra's avatar
Lute Kamstra committed
1855
  "Specify the file permission bits for newly created files.
Kim F. Storm's avatar
Kim F. Storm committed
1856

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

See also `pr-temp-dir' and `pr-ps-temp-file'."
1860
  :type '(integer :tag "File Permission Bits"))
Kim F. Storm's avatar
Kim F. Storm committed
1861 1862