0
|
1 ;;; lpr.el --- print Emacs buffer on line printer.
|
|
2
|
|
3 ;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6 ;; Keywords: unix
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
23 ;; 02111-1307, USA.
|
0
|
24
|
2
|
25 ;;; Synched up with: FSF 19.34.
|
0
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; Commands to send the region or a buffer your printer. Entry points
|
|
30 ;; are `lpr-buffer', `print-buffer', lpr-region', or `print-region'; option
|
|
31 ;; variables include `lpr-switches' and `lpr-command'.
|
|
32
|
|
33 ;;; Code:
|
|
34
|
134
|
35 (defgroup lpr nil
|
|
36 "Print Emacs buffer on line printer"
|
|
37 :group 'wp)
|
|
38
|
|
39
|
0
|
40 ;;;###autoload
|
134
|
41 (defcustom lpr-switches nil
|
2
|
42 "*List of strings to pass as extra options for the printer program.
|
134
|
43 See `lpr-command'."
|
|
44 :type '(repeat (string :tag "Argument"))
|
|
45 :group 'lpr)
|
0
|
46
|
134
|
47 (defcustom lpr-add-switches (eq system-type 'berkeley-unix)
|
2
|
48 "*Non-nil means construct -T and -J options for the printer program.
|
|
49 These are made assuming that the program is `lpr';
|
|
50 if you are using some other incompatible printer program,
|
134
|
51 this variable should be nil."
|
|
52 :type 'boolean
|
|
53 :group 'lpr)
|
0
|
54
|
|
55 ;;;###autoload
|
134
|
56 (defcustom lpr-command
|
0
|
57 (if (memq system-type '(usg-unix-v dgux hpux irix))
|
|
58 "lp" "lpr")
|
134
|
59 "*Name of program for printing a file."
|
|
60 :type 'string
|
|
61 :group 'lpr)
|
0
|
62
|
|
63 ;; Default is nil, because that enables us to use pr -f
|
|
64 ;; which is more reliable than pr with no args, which is what lpr -p does.
|
134
|
65 (defcustom lpr-headers-switches nil
|
2
|
66 "*List of strings of options to request page headings in the printer program.
|
0
|
67 If nil, we run `lpr-page-header-program' to make page headings
|
134
|
68 and print the result."
|
|
69 :type '(repeat (string :tag "Argument"))
|
|
70 :group 'lpr)
|
0
|
71
|
134
|
72 (defcustom print-region-function nil
|
0
|
73 "Function to call to print the region on a printer.
|
134
|
74 See definition of `print-region-1' for calling conventions."
|
|
75 :type 'function
|
|
76 :group 'lpr)
|
0
|
77
|
134
|
78 (defcustom lpr-page-header-program "pr"
|
|
79 "*Name of program for adding page headers to a file."
|
|
80 :type 'string
|
|
81 :group 'lpr)
|
0
|
82
|
134
|
83 (defcustom lpr-page-header-switches '("-f")
|
2
|
84 "*List of strings to use as options for the page-header-generating program.
|
134
|
85 The variable `lpr-page-header-program' specifies the program to use."
|
|
86 :type '(repeat string)
|
|
87 :group 'lpr)
|
0
|
88
|
|
89 ;;;###autoload
|
|
90 (defun lpr-buffer ()
|
|
91 "Print buffer contents as with Unix command `lpr'.
|
|
92 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
|
|
93 (interactive)
|
|
94 (print-region-1 (point-min) (point-max) lpr-switches nil))
|
|
95
|
|
96 ;;;###autoload
|
|
97 (defun print-buffer ()
|
|
98 "Print buffer contents as with Unix command `lpr -p'.
|
|
99 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
|
|
100 (interactive)
|
|
101 (print-region-1 (point-min) (point-max) lpr-switches t))
|
|
102
|
|
103 ;;;###autoload
|
|
104 (defun lpr-region (start end)
|
|
105 "Print region contents as with Unix command `lpr'.
|
|
106 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
|
|
107 (interactive "r")
|
|
108 (print-region-1 start end lpr-switches nil))
|
|
109
|
|
110 ;;;###autoload
|
|
111 (defun print-region (start end)
|
|
112 "Print region contents as with Unix command `lpr -p'.
|
|
113 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
|
|
114 (interactive "r")
|
|
115 (print-region-1 start end lpr-switches t))
|
|
116
|
74
|
117 ;; XEmacs change
|
|
118 (require 'message) ; Until We can get some sensible autoloads, or
|
|
119 ; message-flatten-list gets put somewhere decent.
|
0
|
120 (defun print-region-1 (start end switches page-headers)
|
|
121 ;; On some MIPS system, having a space in the job name
|
|
122 ;; crashes the printer demon. But using dashes looks ugly
|
|
123 ;; and it seems to annoying to do for that MIPS system.
|
|
124 (let ((name (concat (buffer-name) " Emacs buffer"))
|
|
125 (title (concat (buffer-name) " Emacs buffer"))
|
2
|
126 ;; On MS-DOS systems, make pipes use binary mode if the
|
|
127 ;; original file is binary.
|
|
128 (binary-process-input buffer-file-type)
|
|
129 (binary-process-output buffer-file-type)
|
0
|
130 (width tab-width)
|
74
|
131 nswitches
|
0
|
132 switch-string)
|
|
133 (save-excursion
|
|
134 (if page-headers
|
|
135 (if lpr-headers-switches
|
|
136 ;; It is possible to use an lpr option
|
|
137 ;; to get page headers.
|
|
138 (setq switches (append (if (stringp lpr-headers-switches)
|
|
139 (list lpr-headers-switches)
|
|
140 lpr-headers-switches)
|
|
141 switches))))
|
74
|
142 (setq nswitches (message-flatten-list ; XEmacs
|
|
143 (mapcar '(lambda (arg) ; Dynamic evaluation
|
|
144 (cond ((stringp arg) arg)
|
|
145 ((functionp arg) (apply arg nil))
|
|
146 ((symbolp arg) (eval arg))
|
|
147 ((consp arg) (apply (car arg)
|
|
148 (cdr arg)))
|
|
149 (t nil)))
|
|
150 switches)))
|
0
|
151 (setq switch-string
|
74
|
152 (if nswitches (concat " with options "
|
|
153 (mapconcat 'identity nswitches " "))
|
0
|
154 ""))
|
|
155 (message "Spooling%s..." switch-string)
|
|
156 (if (/= tab-width 8)
|
|
157 (let ((new-coords (print-region-new-buffer start end)))
|
|
158 (setq start (car new-coords) end (cdr new-coords))
|
|
159 (setq tab-width width)
|
|
160 (save-excursion
|
|
161 (goto-char end)
|
|
162 (setq end (point-marker)))
|
|
163 (untabify (point-min) (point-max))))
|
|
164 (if page-headers
|
|
165 (if lpr-headers-switches
|
|
166 ;; We handled this above by modifying SWITCHES.
|
|
167 nil
|
|
168 ;; Run a separate program to get page headers.
|
|
169 (let ((new-coords (print-region-new-buffer start end)))
|
|
170 (setq start (car new-coords) end (cdr new-coords)))
|
|
171 (apply 'call-process-region start end lpr-page-header-program
|
|
172 t t nil
|
|
173 (nconc (and lpr-add-switches
|
|
174 (list "-h" title))
|
|
175 lpr-page-header-switches))
|
|
176 (setq start (point-min) end (point-max))))
|
|
177 (apply (or print-region-function 'call-process-region)
|
|
178 (nconc (list start end lpr-command
|
|
179 nil nil nil)
|
|
180 (nconc (and lpr-add-switches
|
|
181 (list "-J" name))
|
|
182 ;; These belong in pr if we are using that.
|
|
183 (and lpr-add-switches lpr-headers-switches
|
|
184 (list "-T" title))
|
74
|
185 nswitches)))
|
0
|
186 (if (markerp end)
|
|
187 (set-marker end nil))
|
|
188 (message "Spooling%s...done" switch-string))))
|
|
189
|
|
190 ;; This function copies the text between start and end
|
|
191 ;; into a new buffer, makes that buffer current.
|
|
192 ;; It returns the new range to print from the new current buffer
|
|
193 ;; as (START . END).
|
|
194
|
|
195 (defun print-region-new-buffer (ostart oend)
|
|
196 (if (string= (buffer-name) " *spool temp*")
|
|
197 (cons ostart oend)
|
|
198 (let ((oldbuf (current-buffer)))
|
|
199 (set-buffer (get-buffer-create " *spool temp*"))
|
|
200 (widen) (erase-buffer)
|
|
201 (insert-buffer-substring oldbuf ostart oend)
|
|
202 (cons (point-min) (point-max)))))
|
|
203
|
|
204 (defun printify-region (begin end)
|
|
205 "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
|
|
206 in the current buffer into printable representations as control or
|
|
207 hexadecimal escapes."
|
|
208 (interactive "r")
|
|
209 (save-excursion
|
|
210 (goto-char begin)
|
|
211 (let (c)
|
|
212 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
|
|
213 (setq c (preceding-char))
|
|
214 (delete-backward-char 1)
|
|
215 (insert
|
|
216 (if (< c ?\ )
|
|
217 (format "\\^%c" (+ c ?@))
|
|
218 (format "\\%02x" c)))))))
|
|
219
|
|
220 (provide 'lpr)
|
|
221
|
|
222 ;;; lpr.el ends here
|