5 |
|
|
6 |
;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
7 |
;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
8 |
;; Time-stamp: <2004/07/10 18:48:24 vinicius> |
;; Time-stamp: <2004/07/12 21:10:35 vinicius> |
9 |
;; Keywords: wp, print, PostScript |
;; Keywords: wp, print, PostScript |
10 |
;; Version: 6.8 |
;; Version: 6.8 |
11 |
;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/ |
;; X-URL: http://www.cpqd.com.br/~vinicius/emacs/ |
12 |
|
|
13 |
(defconst pr-version "6.8" |
(defconst pr-version "6.8" |
14 |
"printing.el, v 6.8 <2004/07/10 vinicius> |
"printing.el, v 6.8 <2004/07/12 vinicius> |
15 |
|
|
16 |
Please send all bug fixes and enhancements to |
Please send all bug fixes and enhancements to |
17 |
Vinicius Jose Latorre <viniciusjl@ig.com.br> |
Vinicius Jose Latorre <viniciusjl@ig.com.br> |
48 |
;; |
;; |
49 |
;; Indeed, there are two user interfaces: |
;; Indeed, there are two user interfaces: |
50 |
;; |
;; |
51 |
;; * one is via menubar: |
;; * Menu interface: |
52 |
;; When `printing' is loaded, the menubar is modified to use `printing' |
;; When `printing' is loaded, the menubar is modified to use `printing' |
53 |
;; menu instead of the print options in menubar. |
;; menu instead of the print options in menubar. |
54 |
;; This is the default user interface. |
;; This is the default user interface. |
55 |
;; |
;; |
56 |
;; * other is via buffer interface: |
;; * Buffer interface: |
57 |
;; It is an option of `printing' menu, but it can be binded into another |
;; 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 |
;; key, so user can activate the buffer interface directly without using |
59 |
;; a menu. See `pr-interface' command. |
;; a menu. See `pr-interface' command. |
78 |
;; To obtain ghostscript, ghostview and GSview see the URL |
;; To obtain ghostscript, ghostview and GSview see the URL |
79 |
;; `http://www.gnu.org/software/ghostscript/ghostscript.html'. |
;; `http://www.gnu.org/software/ghostscript/ghostscript.html'. |
80 |
;; |
;; |
81 |
;; `printing' also depends on ps-print and lpr GNU Emacs packages. |
;; `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 |
|
;; |
85 |
;; To download the latest ps-print package see |
;; To download the latest ps-print package see |
86 |
;; `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'. |
;; `http://www.cpqd.com.br/~vinicius/emacs/ps-print.tar.gz'. |
87 |
;; Please, see README file for ps-print installation instructions. |
;; 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. |
124 |
|
;; |
125 |
|
;; |
126 |
;; Novices (First Users) |
;; Novices (First Users) |
127 |
;; --------------------- |
;; --------------------- |
128 |
;; |
;; |
244 |
;; |
;; |
245 |
;; print /D:\\host\printer somefile.txt |
;; print /D:\\host\printer somefile.txt |
246 |
;; |
;; |
247 |
;; Where, `host' is the machine where your printer is directly connected, |
;; Where, `host' is the machine where the printer is directly connected, |
248 |
;; `printer' is the printer name and `somefile.txt' is a text file. |
;; `printer' is the printer name and `somefile.txt' is a text file. |
249 |
;; |
;; |
250 |
;; If the printer `\\host\printer' doesn't print the content of |
;; If the printer `\\host\printer' doesn't print the content of |
931 |
;; Acknowledgments |
;; Acknowledgments |
932 |
;; --------------- |
;; --------------- |
933 |
;; |
;; |
934 |
;; Thanks to Drew Adams <drew.adams@oracle.com> for directory processing and |
;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions: |
935 |
;; `pr-path-alist' suggestions. |
;; - directory processing. |
936 |
|
;; - `pr-path-alist' variable. |
937 |
|
;; - doc fix. |
938 |
|
;; - a lot of tests on Windows. |
939 |
;; |
;; |
940 |
;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests. |
;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests. |
941 |
;; |
;; |
1110 |
;; Internal Functions (I) |
;; Internal Functions (I) |
1111 |
|
|
1112 |
|
|
1113 |
(defun pr-dosify-path (path) |
(defun pr-dosify-file-name (path) |
1114 |
"Replace unix-style directory separator character with dos/windows one." |
"Replace unix-style directory separator character with dos/windows one." |
1115 |
(interactive "sPath: ") |
(interactive "sPath: ") |
1116 |
(if (eq pr-path-style 'windows) |
(if (eq pr-path-style 'windows) |
1118 |
path)) |
path)) |
1119 |
|
|
1120 |
|
|
1121 |
(defun pr-unixify-path (path) |
(defun pr-unixify-file-name (path) |
1122 |
"Replace dos/windows-style directory separator character with unix one." |
"Replace dos/windows-style directory separator character with unix one." |
1123 |
(interactive "sPath: ") |
(interactive "sPath: ") |
1124 |
(if (eq pr-path-style 'windows) |
(if (eq pr-path-style 'windows) |
1126 |
path)) |
path)) |
1127 |
|
|
1128 |
|
|
1129 |
(defun pr-standard-path (path) |
(defun pr-standard-file-name (path) |
1130 |
"Ensure the proper directory separator depending on the OS. |
"Ensure the proper directory separator depending on the OS. |
1131 |
That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory |
That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory |
1132 |
separator; otherwise, ensure unix-style directory separator." |
separator; otherwise, ensure unix-style directory separator." |
1552 |
|
|
1553 |
|
|
1554 |
(defcustom pr-temp-dir |
(defcustom pr-temp-dir |
1555 |
(pr-dosify-path |
(pr-dosify-file-name |
1556 |
(if (boundp 'temporary-file-directory) |
(if (boundp 'temporary-file-directory) |
1557 |
(symbol-value 'temporary-file-directory) |
(symbol-value 'temporary-file-directory) |
1558 |
;; hacked from `temporary-file-directory' variable in files.el |
;; hacked from `temporary-file-directory' variable in files.el |
3873 |
(interactive (list (pr-ps-infile-preprint "Print preview "))) |
(interactive (list (pr-ps-infile-preprint "Print preview "))) |
3874 |
(and (stringp filename) (file-exists-p filename) |
(and (stringp filename) (file-exists-p filename) |
3875 |
(let* ((file (pr-expand-file-name filename)) |
(let* ((file (pr-expand-file-name filename)) |
3876 |
(tempfile (pr-dosify-path (make-temp-name file)))) |
(tempfile (pr-dosify-file-name (make-temp-name file)))) |
3877 |
;; gs use |
;; gs use |
3878 |
(pr-call-process pr-gs-command |
(pr-call-process pr-gs-command |
3879 |
(format "-sDEVICE=%s" pr-gs-device) |
(format "-sDEVICE=%s" pr-gs-device) |
5046 |
"Invalid PostScript printer name `%s' for variable `pr-ps-name'." |
"Invalid PostScript printer name `%s' for variable `pr-ps-name'." |
5047 |
value)) |
value)) |
5048 |
(setq pr-ps-name value |
(setq pr-ps-name value |
5049 |
pr-ps-command (pr-dosify-path (nth 0 ps)) |
pr-ps-command (pr-dosify-file-name (nth 0 ps)) |
5050 |
pr-ps-switches (nth 1 ps) |
pr-ps-switches (nth 1 ps) |
5051 |
pr-ps-printer-switch (nth 2 ps) |
pr-ps-printer-switch (nth 2 ps) |
5052 |
pr-ps-printer (nth 3 ps)) |
pr-ps-printer (nth 3 ps)) |
5072 |
(error "Invalid text printer name `%s' for variable `pr-txt-name'." |
(error "Invalid text printer name `%s' for variable `pr-txt-name'." |
5073 |
value)) |
value)) |
5074 |
(setq pr-txt-name value |
(setq pr-txt-name value |
5075 |
pr-txt-command (pr-dosify-path (nth 0 txt)) |
pr-txt-command (pr-dosify-file-name (nth 0 txt)) |
5076 |
pr-txt-switches (nth 1 txt) |
pr-txt-switches (nth 1 txt) |
5077 |
pr-txt-printer (nth 2 txt))) |
pr-txt-printer (nth 2 txt))) |
5078 |
(or (stringp pr-txt-command) |
(or (stringp pr-txt-command) |
5211 |
|
|
5212 |
|
|
5213 |
(defun pr-expand-file-name (filename) |
(defun pr-expand-file-name (filename) |
5214 |
(pr-dosify-path (expand-file-name filename))) |
(pr-dosify-file-name (expand-file-name filename))) |
5215 |
|
|
5216 |
|
|
5217 |
(defun pr-ps-outfile-preprint (&optional mess) |
(defun pr-ps-outfile-preprint (&optional mess) |
5272 |
;; input file |
;; input file |
5273 |
(or (symbol-value infile-sym) |
(or (symbol-value infile-sym) |
5274 |
(error "%s: input PostScript file name is missing" prompt)) |
(error "%s: input PostScript file name is missing" prompt)) |
5275 |
(set infile-sym (pr-dosify-path (symbol-value infile-sym))) |
(set infile-sym (pr-dosify-file-name (symbol-value infile-sym))) |
5276 |
;; output file |
;; output file |
5277 |
(and (eq (symbol-value outfile-sym) t) |
(and (eq (symbol-value outfile-sym) t) |
5278 |
(set outfile-sym (and (not (interactive-p)) |
(set outfile-sym (and (not (interactive-p)) |
5279 |
current-prefix-arg |
current-prefix-arg |
5280 |
(pr-ps-outfile-preprint prompt)))) |
(pr-ps-outfile-preprint prompt)))) |
5281 |
(and (symbol-value outfile-sym) |
(and (symbol-value outfile-sym) |
5282 |
(set outfile-sym (pr-dosify-path (symbol-value outfile-sym)))) |
(set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym)))) |
5283 |
(pr-ps-file (symbol-value outfile-sym))) |
(pr-ps-file (symbol-value outfile-sym))) |
5284 |
|
|
5285 |
|
|
5326 |
(set-buffer buffer) |
(set-buffer buffer) |
5327 |
(goto-char (point-max)) |
(goto-char (point-max)) |
5328 |
(insert (format "%s %S\n" cmd args))) |
(insert (format "%s %S\n" cmd args))) |
5329 |
(setq status (apply 'call-process cmd nil buffer nil args)) |
(setq status |
5330 |
|
(condition-case data |
5331 |
|
(apply 'call-process cmd nil buffer nil args) |
5332 |
|
((quit error) |
5333 |
|
(error-message-string data)))) |
5334 |
(save-excursion |
(save-excursion |
5335 |
(set-buffer buffer) |
(set-buffer buffer) |
5336 |
(goto-char (point-max)) |
(goto-char (point-max)) |
5338 |
|
|
5339 |
|
|
5340 |
(defun pr-txt-print (from to) |
(defun pr-txt-print (from to) |
5341 |
(let ((lpr-command (pr-standard-path (pr-command pr-txt-command))) |
(let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command))) |
5342 |
(lpr-switches (pr-switches pr-txt-switches "pr-txt-switches")) |
(lpr-switches (pr-switches pr-txt-switches "pr-txt-switches")) |
5343 |
(printer-name pr-txt-printer)) |
(printer-name pr-txt-printer)) |
5344 |
(lpr-region from to))) |
(lpr-region from to))) |
5381 |
|
|
5382 |
|
|
5383 |
(defun pr-ps-file (&optional filename) |
(defun pr-ps-file (&optional filename) |
5384 |
(pr-dosify-path (or filename |
(pr-dosify-file-name (or filename |
5385 |
(convert-standard-filename |
(convert-standard-filename |
5386 |
(expand-file-name pr-ps-temp-file pr-temp-dir))))) |
(expand-file-name pr-ps-temp-file pr-temp-dir))))) |
5387 |
|
|
5388 |
|
|
5389 |
(defun pr-interactive-n-up (mess) |
(defun pr-interactive-n-up (mess) |
5476 |
current-prefix-arg |
current-prefix-arg |
5477 |
(ps-print-preprint current-prefix-arg)))) |
(ps-print-preprint current-prefix-arg)))) |
5478 |
(and (symbol-value filename-sym) |
(and (symbol-value filename-sym) |
5479 |
(set filename-sym (pr-dosify-path (symbol-value filename-sym))))) |
(set filename-sym (pr-dosify-file-name (symbol-value filename-sym))))) |
5480 |
|
|
5481 |
|
|
5482 |
(defun pr-set-n-up-and-filename (n-up-sym filename-sym mess) |
(defun pr-set-n-up-and-filename (n-up-sym filename-sym mess) |
5620 |
COMMAND.exe, COMMAND.bat and COMMAND.com in this order." |
COMMAND.exe, COMMAND.bat and COMMAND.com in this order." |
5621 |
(if (string= command "") |
(if (string= command "") |
5622 |
command |
command |
5623 |
(pr-dosify-path |
(pr-dosify-file-name |
5624 |
(or (pr-find-command command) |
(or (pr-find-command command) |
5625 |
(pr-path-command (cond (pr-cygwin-system 'cygwin) |
(pr-path-command (cond (pr-cygwin-system 'cygwin) |
5626 |
(ps-windows-system 'windows) |
(ps-windows-system 'windows) |