3 |
;; Copyright (C) 2000, 2001, 2002, 2003, 2004 |
;; Copyright (C) 2000, 2001, 2002, 2003, 2004 |
4 |
;; Free Software Foundation, Inc. |
;; Free Software Foundation, Inc. |
5 |
|
|
6 |
;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br> |
;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
7 |
;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br> |
;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
8 |
;; Time-stamp: <2004/04/05 23:41:49 vinicius> |
;; Time-stamp: <2004/07/10 18:48:24 vinicius> |
9 |
;; Keywords: wp, print, PostScript |
;; Keywords: wp, print, PostScript |
10 |
;; Version: 6.7.4 |
;; 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.7.4" |
(defconst pr-version "6.8" |
14 |
"printing.el, v 6.7.4 <2004/03/31 vinicius> |
"printing.el, v 6.8 <2004/07/10 vinicius> |
15 |
|
|
16 |
Please send all bug fixes and enhancements to |
Please send all bug fixes and enhancements to |
17 |
Vinicius Jose Latorre <vinicius@cpqd.com.br> |
Vinicius Jose Latorre <viniciusjl@ig.com.br> |
18 |
") |
") |
19 |
|
|
20 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
40 |
;; Introduction |
;; Introduction |
41 |
;; ------------ |
;; ------------ |
42 |
;; |
;; |
43 |
;; This package provides some printing utilities that includes |
;; This package provides an user interface to some printing utilities that |
44 |
;; previewing/printing a PostScript file, printing a text file and |
;; includes previewing/printing a PostScript file, printing a text file and |
45 |
;; previewing/printing some major modes (like mh-folder-mode, |
;; previewing/printing some major modes (like mh-folder-mode, |
46 |
;; rmail-summary-mode, gnus-summary-mode, etc). |
;; rmail-summary-mode, gnus-summary-mode, etc). It also includes a |
47 |
|
;; PostScript/text printer database. |
48 |
|
;; |
49 |
|
;; Indeed, there are two user interfaces: |
50 |
|
;; |
51 |
|
;; * one is via menubar: |
52 |
|
;; When `printing' is loaded, the menubar is modified to use `printing' |
53 |
|
;; menu instead of the print options in menubar. |
54 |
|
;; This is the default user interface. |
55 |
|
;; |
56 |
|
;; * other is via buffer interface: |
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 |
59 |
|
;; a menu. See `pr-interface' command. |
60 |
;; |
;; |
61 |
;; `printing' was inspired on: |
;; `printing' was inspired on: |
62 |
;; |
;; |
185 |
;; Tips |
;; Tips |
186 |
;; ---- |
;; ---- |
187 |
;; |
;; |
188 |
;; 1. If your have a local printer, that is, a printer which is connected |
;; 1. If you have a local printer, that is, a printer which is connected |
189 |
;; directly to your computer, don't forget to connect the printer to your |
;; directly to your computer, don't forget to connect the printer to your |
190 |
;; computer before printing. |
;; computer before printing. |
191 |
;; |
;; |
200 |
;; another buffer and, then, print the file or the new static buffer. |
;; another buffer and, then, print the file or the new static buffer. |
201 |
;; An example of dynamic buffer is the *Messages* buffer. |
;; An example of dynamic buffer is the *Messages* buffer. |
202 |
;; |
;; |
203 |
;; 4. When running Emacs on Windows with cygwin, check if the |
;; 4. When running Emacs on Windows (with or without cygwin), check if your |
204 |
;; `pr-shell-file-name' variable is set to the proper shell. This shell |
;; printer is a text printer or not by typing in a DOS window: |
205 |
;; will execute the commands to preview/print the buffer, file or directory. |
;; |
206 |
;; Also check the setting of `pr-path-style' variable. |
;; print /D:\\host\printer somefile.txt |
207 |
;; Probably, you should use: |
;; |
208 |
|
;; Where, `host' is the machine where your printer is directly connected, |
209 |
|
;; `printer' is the printer name and `somefile.txt' is a text file. |
210 |
|
;; |
211 |
|
;; If the printer `\\host\printer' doesn't print the content of |
212 |
|
;; `somefile.txt' or, instead, it returns the following message: |
213 |
;; |
;; |
214 |
;; (setq pr-shell-file-name "bash") |
;; PostScript Error Handler |
215 |
;; (setq pr-path-style 'unix) |
;; Offending Command = CCC |
216 |
|
;; Stack = |
217 |
;; |
;; |
218 |
;; And use / instead of \ when specifying a directory. |
;; Where `CCC' is whatever is at the beginning of the text to be printed. |
219 |
|
;; |
220 |
|
;; Therefore, the printer `\\host\printer' is not a text printer, but a |
221 |
|
;; PostScript printer. So, please, don't include this printer in |
222 |
|
;; `pr-txt-printer-alist' (which see). |
223 |
;; |
;; |
224 |
;; |
;; |
225 |
;; Using `printing' |
;; Using `printing' |
502 |
;; `pr-buffer-verbose' Non-nil means to be verbose when editing a |
;; `pr-buffer-verbose' Non-nil means to be verbose when editing a |
503 |
;; field in interface buffer. |
;; field in interface buffer. |
504 |
;; |
;; |
|
;; `pr-shell-file-name' Specify file name to load inferior shells |
|
|
;; from. |
|
|
;; |
|
505 |
;; To set the above options you may: |
;; To set the above options you may: |
506 |
;; |
;; |
507 |
;; a) insert the code in your ~/.emacs, like: |
;; a) insert the code in your ~/.emacs, like: |
932 |
(require 'ps-print) |
(require 'ps-print) |
933 |
|
|
934 |
|
|
935 |
(and (string< ps-print-version "6.5.7") |
(and (string< ps-print-version "6.6.4") |
936 |
(error "`printing' requires `ps-print' package version 6.5.7 or later.")) |
(error "`printing' requires `ps-print' package version 6.6.4 or later.")) |
937 |
|
|
938 |
|
|
939 |
(eval-and-compile |
(eval-and-compile |
1084 |
path)) |
path)) |
1085 |
|
|
1086 |
|
|
1087 |
|
(defun pr-standard-path (path) |
1088 |
|
"Ensure the proper directory separator depending on the OS. |
1089 |
|
That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory |
1090 |
|
separator; otherwise, ensure unix-style directory separator." |
1091 |
|
(if (or pr-cygwin-system ps-windows-system) |
1092 |
|
(subst-char-in-string ?/ ?\\ path) |
1093 |
|
(subst-char-in-string ?\\ ?/ path))) |
1094 |
|
|
1095 |
|
|
1096 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1097 |
;; User Interface (II) |
;; User Interface (II) |
1098 |
|
|
2343 |
:group 'printing) |
:group 'printing) |
2344 |
|
|
2345 |
|
|
|
(defcustom pr-shell-file-name |
|
|
(if (and (not pr-cygwin-system) |
|
|
ps-windows-system) |
|
|
"cmdproxy.exe" |
|
|
shell-file-name) |
|
|
"*Specify file name to load inferior shells from." |
|
|
:type 'string |
|
|
:group 'printing) |
|
|
|
|
|
|
|
2346 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2347 |
;; Internal Variables |
;; Internal Variables |
2348 |
|
|
2429 |
(and pr-auto-region transient-mark-mode mark-active))) |
(and pr-auto-region transient-mark-mode mark-active))) |
2430 |
|
|
2431 |
((eq ps-print-emacs-type 'xemacs) ; XEmacs |
((eq ps-print-emacs-type 'xemacs) ; XEmacs |
2432 |
|
(defvar zmacs-region-stays nil) ; to avoid compilation gripes |
2433 |
(defsubst pr-region-active-p () |
(defsubst pr-region-active-p () |
2434 |
(and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p))))) |
(and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p))))) |
2435 |
|
|
3812 |
"Preview PostScript file FILENAME." |
"Preview PostScript file FILENAME." |
3813 |
(interactive (list (pr-ps-infile-preprint "Preview "))) |
(interactive (list (pr-ps-infile-preprint "Preview "))) |
3814 |
(and (stringp filename) (file-exists-p filename) |
(and (stringp filename) (file-exists-p filename) |
3815 |
(let ((shell-file-name pr-shell-file-name)) |
(pr-call-process pr-gv-command filename))) |
|
(start-process-shell-command "PREVIEW" "*Messages*" |
|
|
(pr-command pr-gv-command) filename)))) |
|
3816 |
|
|
3817 |
|
|
3818 |
;;;###autoload |
;;;###autoload |
3833 |
(let* ((file (pr-expand-file-name filename)) |
(let* ((file (pr-expand-file-name filename)) |
3834 |
(tempfile (pr-dosify-path (make-temp-name file)))) |
(tempfile (pr-dosify-path (make-temp-name file)))) |
3835 |
;; gs use |
;; gs use |
3836 |
(pr-shell-command |
(pr-call-process pr-gs-command |
3837 |
(concat (pr-command pr-gs-command) |
(format "-sDEVICE=%s" pr-gs-device) |
3838 |
" -sDEVICE=" pr-gs-device |
(format "-r%d" pr-gs-resolution) |
3839 |
" -r" (int-to-string pr-gs-resolution) |
(pr-switches-string pr-gs-switches "pr-gs-switches") |
3840 |
" " (pr-switches-string pr-gs-switches "pr-gs-switches") |
(format "-sOutputFile=\"%s\"" tempfile) |
3841 |
" -sOutputFile=" tempfile " " file " -c quit")) |
file |
3842 |
|
"-c quit") |
3843 |
;; printing |
;; printing |
3844 |
(pr-ps-file-print tempfile) |
(pr-ps-file-print tempfile) |
3845 |
;; deleting |
;; deleting |
3860 |
(erase-buffer) |
(erase-buffer) |
3861 |
(insert-file-contents-literally file)) |
(insert-file-contents-literally file)) |
3862 |
(pr-despool-print)) |
(pr-despool-print)) |
3863 |
(pr-shell-command |
(apply 'pr-call-process |
3864 |
(concat (pr-command pr-ps-command) " " |
pr-ps-command |
3865 |
(pr-switches-string pr-ps-switches "pr-gs-switches") " " |
(pr-switches-string pr-ps-switches "pr-gs-switches") |
3866 |
(if (string-match "cp" pr-ps-command) |
(if (string-match "cp" pr-ps-command) |
3867 |
;; for "cp" (cmd in out) |
;; for "cp" (cmd in out) |
3868 |
(concat "\"" file "\" " |
(list file |
3869 |
pr-ps-printer-switch pr-ps-printer) |
(concat pr-ps-printer-switch pr-ps-printer)) |
3870 |
;; else, for others (cmd out in) |
;; else, for others (cmd out in) |
3871 |
(concat pr-ps-printer-switch pr-ps-printer |
(list (concat pr-ps-printer-switch pr-ps-printer) |
3872 |
" \"" file "\"")))))))) |
file))))))) |
3873 |
|
|
3874 |
|
|
3875 |
;;;###autoload |
;;;###autoload |
4271 |
#'ps-print-quote |
#'ps-print-quote |
4272 |
(list |
(list |
4273 |
(concat "\n;;; printing.el version " pr-version "\n") |
(concat "\n;;; printing.el version " pr-version "\n") |
4274 |
'(19 . pr-shell-file-name) |
";; internal vars" |
4275 |
'(19 . pr-path-style) |
(ps-comment-string "pr-txt-command " pr-txt-command) |
4276 |
'(19 . pr-path-alist) |
(ps-comment-string "pr-txt-switches " |
4277 |
|
(pr-switches-string pr-txt-switches "pr-txt-switches")) |
4278 |
|
(ps-comment-string "pr-txt-printer " pr-txt-printer) |
4279 |
|
(ps-comment-string "pr-ps-command " pr-ps-command) |
4280 |
|
(ps-comment-string "pr-ps-switches " |
4281 |
|
(pr-switches-string pr-ps-switches "pr-ps-switches")) |
4282 |
|
(ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch) |
4283 |
|
(ps-comment-string "pr-ps-printer " pr-ps-printer) |
4284 |
|
(ps-comment-string "pr-cygwin-system " pr-cygwin-system) |
4285 |
|
(ps-comment-string "ps-windows-system " ps-windows-system) |
4286 |
|
(ps-comment-string "ps-lp-system " ps-lp-system) |
4287 |
|
nil |
4288 |
|
'(14 . pr-path-style) |
4289 |
|
'(14 . pr-path-alist) |
4290 |
nil |
nil |
4291 |
'(21 . pr-txt-name) |
'(21 . pr-txt-name) |
4292 |
'(21 . pr-txt-printer-alist) |
'(21 . pr-txt-printer-alist) |
4602 |
(cond |
(cond |
4603 |
((eq ps-print-emacs-type 'xemacs) |
((eq ps-print-emacs-type 'xemacs) |
4604 |
;; XEmacs |
;; XEmacs |
4605 |
|
(defvar current-mouse-event nil) ; to avoid compilation gripes |
4606 |
(defun pr-menu-position (entry index horizontal) |
(defun pr-menu-position (entry index horizontal) |
4607 |
(pr-x-make-event |
(pr-x-make-event |
4608 |
'button-release |
'button-release |
4666 |
|
|
4667 |
((eq ps-print-emacs-type 'xemacs) |
((eq ps-print-emacs-type 'xemacs) |
4668 |
;; XEmacs |
;; XEmacs |
4669 |
|
(defvar current-menubar nil) ; to avoid compilation gripes |
4670 |
(defun pr-menu-lookup (path) |
(defun pr-menu-lookup (path) |
4671 |
(car (pr-x-find-menu-item current-menubar (cons "Printing" path)))) |
(car (pr-x-find-menu-item current-menubar (cons "Printing" path)))) |
4672 |
|
|
5007 |
pr-ps-command (pr-dosify-path (nth 0 ps)) |
pr-ps-command (pr-dosify-path (nth 0 ps)) |
5008 |
pr-ps-switches (nth 1 ps) |
pr-ps-switches (nth 1 ps) |
5009 |
pr-ps-printer-switch (nth 2 ps) |
pr-ps-printer-switch (nth 2 ps) |
5010 |
pr-ps-printer (pr-dosify-path (nth 3 ps))) |
pr-ps-printer (nth 3 ps)) |
5011 |
(or (stringp pr-ps-command) |
(or (stringp pr-ps-command) |
5012 |
(setq pr-ps-command |
(setq pr-ps-command |
5013 |
(cond (ps-windows-system "print") |
(cond (ps-windows-system "print") |
5032 |
(setq pr-txt-name value |
(setq pr-txt-name value |
5033 |
pr-txt-command (pr-dosify-path (nth 0 txt)) |
pr-txt-command (pr-dosify-path (nth 0 txt)) |
5034 |
pr-txt-switches (nth 1 txt) |
pr-txt-switches (nth 1 txt) |
5035 |
pr-txt-printer (pr-dosify-path (nth 2 txt)))) |
pr-txt-printer (nth 2 txt))) |
5036 |
(or (stringp pr-txt-command) |
(or (stringp pr-txt-command) |
5037 |
(setq pr-txt-command |
(setq pr-txt-command |
5038 |
(cond (ps-windows-system "print") |
(cond (ps-windows-system "print") |
5245 |
(let (item) |
(let (item) |
5246 |
(and (stringp infile) (file-exists-p infile) |
(and (stringp infile) (file-exists-p infile) |
5247 |
(setq item (cdr (assq pr-ps-utility pr-ps-utility-alist))) |
(setq item (cdr (assq pr-ps-utility pr-ps-utility-alist))) |
5248 |
(pr-shell-command |
(pr-call-process (nth 0 item) |
5249 |
(concat (pr-command (nth 0 item)) " " |
(pr-switches-string (nth 1 item) |
5250 |
(pr-switches-string (nth 1 item) |
"pr-ps-utility-alist entry") |
5251 |
"pr-ps-utility-alist entry") |
(pr-switches-string (nth 8 item) |
5252 |
" " |
"pr-ps-utility-alist entry") |
5253 |
(pr-switches-string (nth 8 item) |
(and (nth 2 item) |
5254 |
"pr-ps-utility-alist entry") |
(format (nth 2 item) ps-paper-type)) |
5255 |
" " |
(format (nth 3 item) n-up) |
5256 |
(and (nth 2 item) |
(and pr-file-landscape (nth 4 item)) |
5257 |
(format (nth 2 item) ps-paper-type)) |
(and pr-file-duplex (nth 5 item)) |
5258 |
" " (format (nth 3 item) n-up) " " |
(and pr-file-tumble (nth 6 item)) |
5259 |
(and pr-file-landscape (nth 4 item)) " " |
(pr-expand-file-name infile) |
5260 |
(and pr-file-duplex (nth 5 item)) " " |
(nth 7 item) |
5261 |
(and pr-file-tumble (nth 6 item)) |
(pr-expand-file-name outfile))))) |
5262 |
" \"" (pr-expand-file-name infile) "\" " |
|
5263 |
(nth 7 item) |
|
5264 |
" \"" (pr-expand-file-name outfile) "\""))))) |
(defun pr-remove-nil-from-list (lst) |
5265 |
|
(while (and lst (null (car lst))) |
5266 |
|
(setq lst (cdr lst))) |
5267 |
(defun pr-shell-command (command) |
(let ((b lst) |
5268 |
(let ((shell-file-name pr-shell-file-name)) |
(l (cdr lst))) |
5269 |
(shell-command command))) |
(while l |
5270 |
|
(if (car l) |
5271 |
|
(setq b l |
5272 |
|
l (cdr l)) |
5273 |
|
(setq l (cdr l)) |
5274 |
|
(setcdr b l)))) |
5275 |
|
lst) |
5276 |
|
|
5277 |
|
|
5278 |
|
(defun pr-call-process (command &rest args) |
5279 |
|
(let ((buffer (get-buffer-create "*Printing Command Output*")) |
5280 |
|
(cmd (pr-command command)) |
5281 |
|
status) |
5282 |
|
(setq args (pr-remove-nil-from-list args)) |
5283 |
|
(save-excursion |
5284 |
|
(set-buffer buffer) |
5285 |
|
(goto-char (point-max)) |
5286 |
|
(insert (format "%s %S\n" cmd args))) |
5287 |
|
(setq status (apply 'call-process cmd nil buffer nil args)) |
5288 |
|
(save-excursion |
5289 |
|
(set-buffer buffer) |
5290 |
|
(goto-char (point-max)) |
5291 |
|
(insert (format "Exit status: %s\n" status))))) |
5292 |
|
|
5293 |
|
|
5294 |
(defun pr-txt-print (from to) |
(defun pr-txt-print (from to) |
5295 |
(let ((lpr-command (pr-command pr-txt-command)) |
(let ((lpr-command (pr-standard-path (pr-command pr-txt-command))) |
5296 |
(lpr-switches (pr-switches pr-txt-switches "pr-txt-switches")) |
(lpr-switches (pr-switches pr-txt-switches "pr-txt-switches")) |
5297 |
(printer-name pr-txt-printer)) |
(printer-name pr-txt-printer)) |
5298 |
(lpr-region from to))) |
(lpr-region from to))) |