Mercurial > emacs
comparison lisp/printing.el @ 56405:10b68aa88abe
Doc fix. Change name of some funs.
author | Vinicius Jose Latorre <viniciusjl@ig.com.br> |
---|---|
date | Tue, 13 Jul 2004 01:32:18 +0000 |
parents | e97dd6ea9f71 |
children | 13ab9b29575b 97905c4f1a42 |
comparison
equal
deleted
inserted
replaced
56404:ab69405dae2e | 56405:10b68aa88abe |
---|---|
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004 | 3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004 |
4 ;; Free Software Foundation, Inc. | 4 ;; Free Software Foundation, Inc. |
5 | 5 |
6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> | 6 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> | 7 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
8 ;; Time-stamp: <2004/07/10 18:48:24 vinicius> | 8 ;; Time-stamp: <2004/07/12 21:10:35 vinicius> |
9 ;; Keywords: wp, print, PostScript | 9 ;; Keywords: wp, print, PostScript |
10 ;; Version: 6.8 | 10 ;; Version: 6.8 |
11 ;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/ | 11 ;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/ |
12 | 12 |
13 (defconst pr-version "6.8" | 13 (defconst pr-version "6.8" |
14 "printing.el, v 6.8 <2004/07/10 vinicius> | 14 "printing.el, v 6.8 <2004/07/12 vinicius> |
15 | 15 |
16 Please send all bug fixes and enhancements to | 16 Please send all bug fixes and enhancements to |
17 Vinicius Jose Latorre <viniciusjl@ig.com.br> | 17 Vinicius Jose Latorre <viniciusjl@ig.com.br> |
18 ") | 18 ") |
19 | 19 |
46 ;; rmail-summary-mode, gnus-summary-mode, etc). It also includes a | 46 ;; rmail-summary-mode, gnus-summary-mode, etc). It also includes a |
47 ;; PostScript/text printer database. | 47 ;; PostScript/text printer database. |
48 ;; | 48 ;; |
49 ;; Indeed, there are two user interfaces: | 49 ;; Indeed, there are two user interfaces: |
50 ;; | 50 ;; |
51 ;; * one is via menubar: | 51 ;; * Menu interface: |
52 ;; When `printing' is loaded, the menubar is modified to use `printing' | 52 ;; When `printing' is loaded, the menubar is modified to use `printing' |
53 ;; menu instead of the print options in menubar. | 53 ;; menu instead of the print options in menubar. |
54 ;; This is the default user interface. | 54 ;; This is the default user interface. |
55 ;; | 55 ;; |
56 ;; * other is via buffer interface: | 56 ;; * Buffer interface: |
57 ;; It is an option of `printing' menu, but it can be binded into another | 57 ;; It is an option of `printing' menu, but it can be binded into another |
58 ;; key, so user can activate the buffer interface directly without using | 58 ;; key, so user can activate the buffer interface directly without using |
59 ;; a menu. See `pr-interface' command. | 59 ;; a menu. See `pr-interface' command. |
60 ;; | 60 ;; |
61 ;; `printing' was inspired on: | 61 ;; `printing' was inspired on: |
76 ;; On GNU or Unix system, `printing' depends on gs and gv utilities. | 76 ;; On GNU or Unix system, `printing' depends on gs and gv utilities. |
77 ;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe). | 77 ;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe). |
78 ;; To obtain ghostscript, ghostview and GSview see the URL | 78 ;; To obtain ghostscript, ghostview and GSview see the URL |
79 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'. | 79 ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'. |
80 ;; | 80 ;; |
81 ;; `printing' also depends on ps-print and lpr GNU Emacs packages. | 81 ;; `printing' depends on ps-print package to generate PostScript files, to |
82 ;; spool and to despool PostScript buffer. So, `printing' provides an | |
83 ;; interface to ps-print package and it also provides some extra stuff. | |
84 ;; | |
82 ;; To download the latest ps-print package see | 85 ;; To download the latest ps-print package see |
83 ;; `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'. | 86 ;; `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'. |
84 ;; Please, see README file for ps-print installation instructions. | 87 ;; Please, see README file for ps-print installation instructions. |
88 ;; | |
89 ;; | |
90 ;; Log Messages | |
91 ;; ------------ | |
92 ;; | |
93 ;; The buffer *Printing Command Output* is where the `printing' log messages | |
94 ;; are inserted. All program called by `printing' has a log entry in the | |
95 ;; buffer *Printing Command Output*. A log entry has the following form: | |
96 ;; | |
97 ;; PROGRAM (ARG...) | |
98 ;; MESSAGE | |
99 ;; Exit status: CODE | |
100 ;; | |
101 ;; Where | |
102 ;; PROGRAM is the program activated by `printing', | |
103 ;; ARG is an argument passed to PROGRAM (it can have more than one argument), | |
104 ;; MESSAGE is an error message returned by PROGRAM (it can have no message, if | |
105 ;; PROGRAM is successful), | |
106 ;; and CODE is a numeric exit status or a signal description string. | |
107 ;; | |
108 ;; For example, after previewing a PostScript file, *Printing Command Output* | |
109 ;; will have the following entry: | |
110 ;; | |
111 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps") | |
112 ;; Exit status: 0 | |
113 ;; | |
114 ;; In the example above, the previewing was successful. If during previewing, | |
115 ;; you quit gv execution (by typing C-g during Emacs session), the log entry | |
116 ;; would be: | |
117 ;; | |
118 ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps") | |
119 ;; Exit status: Quit | |
120 ;; | |
121 ;; So, if something goes wrong, a good place to take a look is the buffer | |
122 ;; *Printing Command Output*. Don't forget to see also the buffer *Messages*, | |
123 ;; it can help. | |
85 ;; | 124 ;; |
86 ;; | 125 ;; |
87 ;; Novices (First Users) | 126 ;; Novices (First Users) |
88 ;; --------------------- | 127 ;; --------------------- |
89 ;; | 128 ;; |
203 ;; 4. When running Emacs on Windows (with or without cygwin), check if your | 242 ;; 4. When running Emacs on Windows (with or without cygwin), check if your |
204 ;; printer is a text printer or not by typing in a DOS window: | 243 ;; printer is a text printer or not by typing in a DOS window: |
205 ;; | 244 ;; |
206 ;; print /D:\\host\printer somefile.txt | 245 ;; print /D:\\host\printer somefile.txt |
207 ;; | 246 ;; |
208 ;; Where, `host' is the machine where your printer is directly connected, | 247 ;; Where, `host' is the machine where the printer is directly connected, |
209 ;; `printer' is the printer name and `somefile.txt' is a text file. | 248 ;; `printer' is the printer name and `somefile.txt' is a text file. |
210 ;; | 249 ;; |
211 ;; If the printer `\\host\printer' doesn't print the content of | 250 ;; If the printer `\\host\printer' doesn't print the content of |
212 ;; `somefile.txt' or, instead, it returns the following message: | 251 ;; `somefile.txt' or, instead, it returns the following message: |
213 ;; | 252 ;; |
890 ;; | 929 ;; |
891 ;; | 930 ;; |
892 ;; Acknowledgments | 931 ;; Acknowledgments |
893 ;; --------------- | 932 ;; --------------- |
894 ;; | 933 ;; |
895 ;; Thanks to Drew Adams <drew.adams@oracle.com> for directory processing and | 934 ;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions: |
896 ;; `pr-path-alist' suggestions. | 935 ;; - directory processing. |
936 ;; - `pr-path-alist' variable. | |
937 ;; - doc fix. | |
938 ;; - a lot of tests on Windows. | |
897 ;; | 939 ;; |
898 ;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests. | 940 ;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests. |
899 ;; | 941 ;; |
900 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging | 942 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging |
901 ;; and for suggestions: | 943 ;; and for suggestions: |
1066 | 1108 |
1067 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1068 ;; Internal Functions (I) | 1110 ;; Internal Functions (I) |
1069 | 1111 |
1070 | 1112 |
1071 (defun pr-dosify-path (path) | 1113 (defun pr-dosify-file-name (path) |
1072 "Replace unix-style directory separator character with dos/windows one." | 1114 "Replace unix-style directory separator character with dos/windows one." |
1073 (interactive "sPath: ") | 1115 (interactive "sPath: ") |
1074 (if (eq pr-path-style 'windows) | 1116 (if (eq pr-path-style 'windows) |
1075 (subst-char-in-string ?/ ?\\ path) | 1117 (subst-char-in-string ?/ ?\\ path) |
1076 path)) | 1118 path)) |
1077 | 1119 |
1078 | 1120 |
1079 (defun pr-unixify-path (path) | 1121 (defun pr-unixify-file-name (path) |
1080 "Replace dos/windows-style directory separator character with unix one." | 1122 "Replace dos/windows-style directory separator character with unix one." |
1081 (interactive "sPath: ") | 1123 (interactive "sPath: ") |
1082 (if (eq pr-path-style 'windows) | 1124 (if (eq pr-path-style 'windows) |
1083 (subst-char-in-string ?\\ ?/ path) | 1125 (subst-char-in-string ?\\ ?/ path) |
1084 path)) | 1126 path)) |
1085 | 1127 |
1086 | 1128 |
1087 (defun pr-standard-path (path) | 1129 (defun pr-standard-file-name (path) |
1088 "Ensure the proper directory separator depending on the OS. | 1130 "Ensure the proper directory separator depending on the OS. |
1089 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory | 1131 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory |
1090 separator; otherwise, ensure unix-style directory separator." | 1132 separator; otherwise, ensure unix-style directory separator." |
1091 (if (or pr-cygwin-system ps-windows-system) | 1133 (if (or pr-cygwin-system ps-windows-system) |
1092 (subst-char-in-string ?/ ?\\ path) | 1134 (subst-char-in-string ?/ ?\\ path) |
1508 :set 'pr-alist-custom-set | 1550 :set 'pr-alist-custom-set |
1509 :group 'printing) | 1551 :group 'printing) |
1510 | 1552 |
1511 | 1553 |
1512 (defcustom pr-temp-dir | 1554 (defcustom pr-temp-dir |
1513 (pr-dosify-path | 1555 (pr-dosify-file-name |
1514 (if (boundp 'temporary-file-directory) | 1556 (if (boundp 'temporary-file-directory) |
1515 (symbol-value 'temporary-file-directory) | 1557 (symbol-value 'temporary-file-directory) |
1516 ;; hacked from `temporary-file-directory' variable in files.el | 1558 ;; hacked from `temporary-file-directory' variable in files.el |
1517 (file-name-as-directory | 1559 (file-name-as-directory |
1518 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") | 1560 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") |
3829 (defun pr-ps-file-using-ghostscript (filename) | 3871 (defun pr-ps-file-using-ghostscript (filename) |
3830 "Print PostScript file FILENAME using ghostscript." | 3872 "Print PostScript file FILENAME using ghostscript." |
3831 (interactive (list (pr-ps-infile-preprint "Print preview "))) | 3873 (interactive (list (pr-ps-infile-preprint "Print preview "))) |
3832 (and (stringp filename) (file-exists-p filename) | 3874 (and (stringp filename) (file-exists-p filename) |
3833 (let* ((file (pr-expand-file-name filename)) | 3875 (let* ((file (pr-expand-file-name filename)) |
3834 (tempfile (pr-dosify-path (make-temp-name file)))) | 3876 (tempfile (pr-dosify-file-name (make-temp-name file)))) |
3835 ;; gs use | 3877 ;; gs use |
3836 (pr-call-process pr-gs-command | 3878 (pr-call-process pr-gs-command |
3837 (format "-sDEVICE=%s" pr-gs-device) | 3879 (format "-sDEVICE=%s" pr-gs-device) |
3838 (format "-r%d" pr-gs-resolution) | 3880 (format "-r%d" pr-gs-resolution) |
3839 (pr-switches-string pr-gs-switches "pr-gs-switches") | 3881 (pr-switches-string pr-gs-switches "pr-gs-switches") |
5002 (or ps | 5044 (or ps |
5003 (error | 5045 (error |
5004 "Invalid PostScript printer name `%s' for variable `pr-ps-name'." | 5046 "Invalid PostScript printer name `%s' for variable `pr-ps-name'." |
5005 value)) | 5047 value)) |
5006 (setq pr-ps-name value | 5048 (setq pr-ps-name value |
5007 pr-ps-command (pr-dosify-path (nth 0 ps)) | 5049 pr-ps-command (pr-dosify-file-name (nth 0 ps)) |
5008 pr-ps-switches (nth 1 ps) | 5050 pr-ps-switches (nth 1 ps) |
5009 pr-ps-printer-switch (nth 2 ps) | 5051 pr-ps-printer-switch (nth 2 ps) |
5010 pr-ps-printer (nth 3 ps)) | 5052 pr-ps-printer (nth 3 ps)) |
5011 (or (stringp pr-ps-command) | 5053 (or (stringp pr-ps-command) |
5012 (setq pr-ps-command | 5054 (setq pr-ps-command |
5028 (let ((txt (cdr (assq value pr-txt-printer-alist)))) | 5070 (let ((txt (cdr (assq value pr-txt-printer-alist)))) |
5029 (or txt | 5071 (or txt |
5030 (error "Invalid text printer name `%s' for variable `pr-txt-name'." | 5072 (error "Invalid text printer name `%s' for variable `pr-txt-name'." |
5031 value)) | 5073 value)) |
5032 (setq pr-txt-name value | 5074 (setq pr-txt-name value |
5033 pr-txt-command (pr-dosify-path (nth 0 txt)) | 5075 pr-txt-command (pr-dosify-file-name (nth 0 txt)) |
5034 pr-txt-switches (nth 1 txt) | 5076 pr-txt-switches (nth 1 txt) |
5035 pr-txt-printer (nth 2 txt))) | 5077 pr-txt-printer (nth 2 txt))) |
5036 (or (stringp pr-txt-command) | 5078 (or (stringp pr-txt-command) |
5037 (setq pr-txt-command | 5079 (setq pr-txt-command |
5038 (cond (ps-windows-system "print") | 5080 (cond (ps-windows-system "print") |
5167 (defun pr-delete-file (file) | 5209 (defun pr-delete-file (file) |
5168 (and pr-delete-temp-file (delete-file file))) | 5210 (and pr-delete-temp-file (delete-file file))) |
5169 | 5211 |
5170 | 5212 |
5171 (defun pr-expand-file-name (filename) | 5213 (defun pr-expand-file-name (filename) |
5172 (pr-dosify-path (expand-file-name filename))) | 5214 (pr-dosify-file-name (expand-file-name filename))) |
5173 | 5215 |
5174 | 5216 |
5175 (defun pr-ps-outfile-preprint (&optional mess) | 5217 (defun pr-ps-outfile-preprint (&optional mess) |
5176 (let* ((prompt (format "%soutput PostScript file name: " (or mess ""))) | 5218 (let* ((prompt (format "%soutput PostScript file name: " (or mess ""))) |
5177 (res (read-file-name prompt default-directory "" nil))) | 5219 (res (read-file-name prompt default-directory "" nil))) |
5228 (set infile-sym (and (not (interactive-p)) | 5270 (set infile-sym (and (not (interactive-p)) |
5229 (pr-ps-infile-preprint prompt)))) | 5271 (pr-ps-infile-preprint prompt)))) |
5230 ;; input file | 5272 ;; input file |
5231 (or (symbol-value infile-sym) | 5273 (or (symbol-value infile-sym) |
5232 (error "%s: input PostScript file name is missing" prompt)) | 5274 (error "%s: input PostScript file name is missing" prompt)) |
5233 (set infile-sym (pr-dosify-path (symbol-value infile-sym))) | 5275 (set infile-sym (pr-dosify-file-name (symbol-value infile-sym))) |
5234 ;; output file | 5276 ;; output file |
5235 (and (eq (symbol-value outfile-sym) t) | 5277 (and (eq (symbol-value outfile-sym) t) |
5236 (set outfile-sym (and (not (interactive-p)) | 5278 (set outfile-sym (and (not (interactive-p)) |
5237 current-prefix-arg | 5279 current-prefix-arg |
5238 (pr-ps-outfile-preprint prompt)))) | 5280 (pr-ps-outfile-preprint prompt)))) |
5239 (and (symbol-value outfile-sym) | 5281 (and (symbol-value outfile-sym) |
5240 (set outfile-sym (pr-dosify-path (symbol-value outfile-sym)))) | 5282 (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym)))) |
5241 (pr-ps-file (symbol-value outfile-sym))) | 5283 (pr-ps-file (symbol-value outfile-sym))) |
5242 | 5284 |
5243 | 5285 |
5244 (defun pr-ps-utility-process (n-up infile outfile) | 5286 (defun pr-ps-utility-process (n-up infile outfile) |
5245 (let (item) | 5287 (let (item) |
5282 (setq args (pr-remove-nil-from-list args)) | 5324 (setq args (pr-remove-nil-from-list args)) |
5283 (save-excursion | 5325 (save-excursion |
5284 (set-buffer buffer) | 5326 (set-buffer buffer) |
5285 (goto-char (point-max)) | 5327 (goto-char (point-max)) |
5286 (insert (format "%s %S\n" cmd args))) | 5328 (insert (format "%s %S\n" cmd args))) |
5287 (setq status (apply 'call-process cmd nil buffer nil args)) | 5329 (setq status |
5330 (condition-case data | |
5331 (apply 'call-process cmd nil buffer nil args) | |
5332 ((quit error) | |
5333 (error-message-string data)))) | |
5288 (save-excursion | 5334 (save-excursion |
5289 (set-buffer buffer) | 5335 (set-buffer buffer) |
5290 (goto-char (point-max)) | 5336 (goto-char (point-max)) |
5291 (insert (format "Exit status: %s\n" status))))) | 5337 (insert (format "Exit status: %s\n" status))))) |
5292 | 5338 |
5293 | 5339 |
5294 (defun pr-txt-print (from to) | 5340 (defun pr-txt-print (from to) |
5295 (let ((lpr-command (pr-standard-path (pr-command pr-txt-command))) | 5341 (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command))) |
5296 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches")) | 5342 (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches")) |
5297 (printer-name pr-txt-printer)) | 5343 (printer-name pr-txt-printer)) |
5298 (lpr-region from to))) | 5344 (lpr-region from to))) |
5299 | 5345 |
5300 | 5346 |
5333 (pr-ps-file-print file) | 5379 (pr-ps-file-print file) |
5334 (pr-delete-file file)))) | 5380 (pr-delete-file file)))) |
5335 | 5381 |
5336 | 5382 |
5337 (defun pr-ps-file (&optional filename) | 5383 (defun pr-ps-file (&optional filename) |
5338 (pr-dosify-path (or filename | 5384 (pr-dosify-file-name (or filename |
5339 (convert-standard-filename | 5385 (convert-standard-filename |
5340 (expand-file-name pr-ps-temp-file pr-temp-dir))))) | 5386 (expand-file-name pr-ps-temp-file pr-temp-dir))))) |
5341 | 5387 |
5342 | 5388 |
5343 (defun pr-interactive-n-up (mess) | 5389 (defun pr-interactive-n-up (mess) |
5344 (or (stringp mess) (setq mess "*")) | 5390 (or (stringp mess) (setq mess "*")) |
5345 (save-match-data | 5391 (save-match-data |
5428 (eq (symbol-value filename-sym) t) | 5474 (eq (symbol-value filename-sym) t) |
5429 (set filename-sym (and (not (interactive-p)) | 5475 (set filename-sym (and (not (interactive-p)) |
5430 current-prefix-arg | 5476 current-prefix-arg |
5431 (ps-print-preprint current-prefix-arg)))) | 5477 (ps-print-preprint current-prefix-arg)))) |
5432 (and (symbol-value filename-sym) | 5478 (and (symbol-value filename-sym) |
5433 (set filename-sym (pr-dosify-path (symbol-value filename-sym))))) | 5479 (set filename-sym (pr-dosify-file-name (symbol-value filename-sym))))) |
5434 | 5480 |
5435 | 5481 |
5436 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess) | 5482 (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess) |
5437 ;; n-up | 5483 ;; n-up |
5438 (or (symbol-value n-up-sym) | 5484 (or (symbol-value n-up-sym) |
5572 | 5618 |
5573 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND, | 5619 If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND, |
5574 COMMAND.exe, COMMAND.bat and COMMAND.com in this order." | 5620 COMMAND.exe, COMMAND.bat and COMMAND.com in this order." |
5575 (if (string= command "") | 5621 (if (string= command "") |
5576 command | 5622 command |
5577 (pr-dosify-path | 5623 (pr-dosify-file-name |
5578 (or (pr-find-command command) | 5624 (or (pr-find-command command) |
5579 (pr-path-command (cond (pr-cygwin-system 'cygwin) | 5625 (pr-path-command (cond (pr-cygwin-system 'cygwin) |
5580 (ps-windows-system 'windows) | 5626 (ps-windows-system 'windows) |
5581 (t 'unix)) | 5627 (t 'unix)) |
5582 (file-name-nondirectory command) | 5628 (file-name-nondirectory command) |