aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2001-01-30 12:04:05 +0000
committerEli Zaretskii2001-01-30 12:04:05 +0000
commit4ad25e4311961dd134b167fd51a3d968f58bd728 (patch)
tree5a675aeedba23af85d080d9b75b2d72c82478787
parent47a96555b3ecadebb082a8deb0ebb42d935413b7 (diff)
downloademacs-4ad25e4311961dd134b167fd51a3d968f58bd728.tar.gz
emacs-4ad25e4311961dd134b167fd51a3d968f58bd728.zip
XEmacs compatibility and doc fixes from Vinicius Jose Latorre
<vinicius@cpqd.com.br>: (lpr-windows-system, lpr-lp-system): New vars. (lpr-printer-switch): New defcustom. (printer-name, lpr-command): Customization fix. (print-region-1): Code fix. (print-region-new-buffer, printify-region): Indentation fix. (lpr-eval-switch, lpr-flatten-list, lpr-flatten-list-1): New funcsions.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/lpr.el159
2 files changed, 116 insertions, 54 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a6b085cd5cd..7317481ce82 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12001-01-30 Vinicius Jose Latorre <vinicius@cpqd.com.br>
2
3 * lpr.el: Compatibility with XEmacs and doc fixes.
4 (lpr-windows-system, lpr-lp-system): New vars.
5 (lpr-printer-switch): New defcustom.
6 (printer-name, lpr-command): Customization fix.
7 (print-region-1): Code fix.
8 (print-region-new-buffer, printify-region): Indentation fix.
9 (lpr-eval-switch, lpr-flatten-list, lpr-flatten-list-1): New
10 functions.
11
12001-01-29 Gerd Moellmann <gerd@gnu.org> 122001-01-29 Gerd Moellmann <gerd@gnu.org>
2 13
3 * msb.el (toplevel): Fix the eval-after-load. 14 * msb.el (toplevel): Fix the eval-after-load.
diff --git a/lisp/lpr.el b/lisp/lpr.el
index 21a1ed24f81..6f6f3d53b25 100644
--- a/lisp/lpr.el
+++ b/lisp/lpr.el
@@ -1,9 +1,9 @@
1;;; lpr.el --- print Emacs buffer on line printer. 1;;; lpr.el --- print Emacs buffer on line printer.
2 2
3;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc. 3;; Copyright (C) 1985, 1988, 1992, 1994, 2001 Free Software Foundation, Inc.
4 4
5;; Maintainer: FSF 5;; Maintainer: FSF
6;; Keywords: unix 6;; Keywords: unix
7 7
8;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
9 9
@@ -30,13 +30,21 @@
30 30
31;;; Code: 31;;; Code:
32 32
33(defvar lpr-windows-system
34 (memq system-type '(emx win32 w32 mswindows ms-dos windows-nt)))
35
36(defvar lpr-lp-system
37 (memq system-type '(usg-unix-v dgux hpux irix)))
38
39
33(defgroup lpr nil 40(defgroup lpr nil
34 "Print Emacs buffer on line printer" 41 "Print Emacs buffer on line printer"
35 :group 'wp) 42 :group 'wp)
36 43
44
37;;;###autoload 45;;;###autoload
38(defcustom printer-name 46(defcustom printer-name
39 (if (memq system-type '(ms-dos windows-nt)) "PRN") 47 (and lpr-windows-system "PRN")
40 "*The name of a local printer to which data is sent for printing. 48 "*The name of a local printer to which data is sent for printing.
41\(Note that PostScript files are sent to `ps-printer-name', which see.\) 49\(Note that PostScript files are sent to `ps-printer-name', which see.\)
42 50
@@ -50,13 +58,15 @@ printers, or \"COM1\" to \"COM4\" or \"AUX\" for serial printers, or
50\"//hostname/printer\" for a shared network printer. You can also set 58\"//hostname/printer\" for a shared network printer. You can also set
51it to the name of a file, in which case the output gets appended to that 59it to the name of a file, in which case the output gets appended to that
52file. If you want to discard the printed output, set this to \"NUL\"." 60file. If you want to discard the printed output, set this to \"NUL\"."
53 :type '(choice ; could use string but then we lose completion for files. 61 :type '(choice :menu-tag "Printer Name"
54 (file :tag "Name") 62 :tag "Printer Name"
55 (const :tag "Default" nil)) 63 (const :tag "Default" nil)
64 ;; could use string but then we lose completion for files.
65 (file :tag "Name"))
56 :group 'lpr) 66 :group 'lpr)
57 67
58;;;###autoload 68;;;###autoload
59(defcustom lpr-switches nil 69(defcustom lpr-switches nil
60 "*List of strings to pass as extra options for the printer program. 70 "*List of strings to pass as extra options for the printer program.
61It is recommended to set `printer-name' instead of including an explicit 71It is recommended to set `printer-name' instead of including an explicit
62switch on this list. 72switch on this list.
@@ -72,12 +82,24 @@ this variable should be nil."
72 :type 'boolean 82 :type 'boolean
73 :group 'lpr) 83 :group 'lpr)
74 84
85(defcustom lpr-printer-switch
86 (if lpr-lp-system
87 "-d "
88 "-P")
89 "*Printer switch, that is, something like \"-P\", \"-d \", \"/D:\", etc.
90This switch is used in conjunction with `printer-name'."
91 :type '(choice :menu-tag "Printer Name Switch"
92 :tag "Printer Name Switch"
93 (const :tag "None" nil)
94 (string :tag "Printer Switch"))
95 :group 'lpr)
96
75;;;###autoload 97;;;###autoload
76(defcustom lpr-command 98(defcustom lpr-command
77 (cond 99 (cond
78 ((memq system-type '(ms-dos windows-nt)) 100 (lpr-windows-system
79 "") 101 "")
80 ((memq system-type '(usg-unix-v dgux hpux irix)) 102 (lpr-lp-system
81 "lp") 103 "lp")
82 (t 104 (t
83 "lpr")) 105 "lpr"))
@@ -175,34 +197,37 @@ for further customization of the printer command."
175 ;; On some MIPS system, having a space in the job name 197 ;; On some MIPS system, having a space in the job name
176 ;; crashes the printer demon. But using dashes looks ugly 198 ;; crashes the printer demon. But using dashes looks ugly
177 ;; and it seems to annoying to do for that MIPS system. 199 ;; and it seems to annoying to do for that MIPS system.
178 (let ((name (concat (buffer-name) " Emacs buffer")) 200 (let ((name (concat (buffer-name) " Emacs buffer"))
179 (title (concat (buffer-name) " Emacs buffer")) 201 (title (concat (buffer-name) " Emacs buffer"))
180 ;; Make pipes use the same coding system as 202 ;; Make pipes use the same coding system as
181 ;; writing the buffer to a file would. 203 ;; writing the buffer to a file would.
182 (coding-system-for-write 204 (coding-system-for-write (or coding-system-for-write
183 (or coding-system-for-write buffer-file-coding-system)) 205 buffer-file-coding-system))
184 (coding-system-for-read 206 (coding-system-for-read (or coding-system-for-read
185 (or coding-system-for-read buffer-file-coding-system)) 207 buffer-file-coding-system))
186 (width tab-width) 208 (width tab-width)
209 nswitches
187 switch-string) 210 switch-string)
188 (save-excursion 211 (save-excursion
189 (if page-headers 212 (and page-headers lpr-headers-switches
190 (if lpr-headers-switches 213 ;; It's possible to use an lpr option to get page headers.
191 ;; It is possible to use an lpr option 214 (setq switches (append (if (stringp lpr-headers-switches)
192 ;; to get page headers. 215 (list lpr-headers-switches)
193 (setq switches (append (if (stringp lpr-headers-switches) 216 lpr-headers-switches)
194 (list lpr-headers-switches) 217 switches)))
195 lpr-headers-switches) 218 (setq nswitches (lpr-flatten-list
196 switches)))) 219 (mapcar 'lpr-eval-switch ; Dynamic evaluation
197 (setq switch-string 220 switches))
198 (if switches (concat " with options " 221 switch-string (if switches
199 (mapconcat 'identity switches " ")) 222 (concat " with options "
200 "")) 223 (mapconcat 'identity switches " "))
224 ""))
201 (message "Spooling%s..." switch-string) 225 (message "Spooling%s..." switch-string)
202 (if (/= tab-width 8) 226 (if (/= tab-width 8)
203 (let ((new-coords (print-region-new-buffer start end))) 227 (let ((new-coords (print-region-new-buffer start end)))
204 (setq start (car new-coords) end (cdr new-coords)) 228 (setq start (car new-coords)
205 (setq tab-width width) 229 end (cdr new-coords)
230 tab-width width)
206 (save-excursion 231 (save-excursion
207 (goto-char end) 232 (goto-char end)
208 (setq end (point-marker))) 233 (setq end (point-marker)))
@@ -213,26 +238,23 @@ for further customization of the printer command."
213 nil 238 nil
214 ;; Run a separate program to get page headers. 239 ;; Run a separate program to get page headers.
215 (let ((new-coords (print-region-new-buffer start end))) 240 (let ((new-coords (print-region-new-buffer start end)))
216 (setq start (car new-coords) end (cdr new-coords))) 241 (apply 'call-process-region (car new-coords) (cdr new-coords)
217 (apply 'call-process-region start end lpr-page-header-program 242 lpr-page-header-program t t nil
218 t t nil 243 lpr-page-header-switches))
219 lpr-page-header-switches) 244 (setq start (point-min)
220 (setq start (point-min) end (point-max)))) 245 end (point-max))))
221 (let ((printer-name-switch (if (memq system-type 246 (apply (or print-region-function 'call-process-region)
222 '(usg-unix-v dgux hpux irix)) 247 (nconc (list start end lpr-command
223 "-d" "-P"))) 248 nil nil nil)
224 (apply (or print-region-function 'call-process-region) 249 (and lpr-add-switches
225 (nconc (list start end lpr-command 250 (list "-J" name))
226 nil nil nil) 251 ;; These belong in pr if we are using that.
227 (nconc (and lpr-add-switches 252 (and lpr-add-switches lpr-headers-switches
228 (list "-J" name)) 253 (list "-T" title))
229 ;; These belong in pr if we are using that. 254 (and (stringp printer-name)
230 (and lpr-add-switches lpr-headers-switches 255 (list (concat lpr-printer-switch
231 (list "-T" title)) 256 printer-name)))
232 (and (stringp printer-name) 257 nswitches))
233 (list (concat printer-name-switch
234 printer-name)))
235 switches))))
236 (if (markerp end) 258 (if (markerp end)
237 (set-marker end nil)) 259 (set-marker end nil))
238 (message "Spooling%s...done" switch-string)))) 260 (message "Spooling%s...done" switch-string))))
@@ -247,7 +269,8 @@ for further customization of the printer command."
247 (cons ostart oend) 269 (cons ostart oend)
248 (let ((oldbuf (current-buffer))) 270 (let ((oldbuf (current-buffer)))
249 (set-buffer (get-buffer-create " *spool temp*")) 271 (set-buffer (get-buffer-create " *spool temp*"))
250 (widen) (erase-buffer) 272 (widen)
273 (erase-buffer)
251 (insert-buffer-substring oldbuf ostart oend) 274 (insert-buffer-substring oldbuf ostart oend)
252 (cons (point-min) (point-max))))) 275 (cons (point-min) (point-max)))))
253 276
@@ -262,10 +285,38 @@ The characters tab, linefeed, space, return and formfeed are not affected."
262 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t) 285 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
263 (setq c (preceding-char)) 286 (setq c (preceding-char))
264 (delete-backward-char 1) 287 (delete-backward-char 1)
265 (insert 288 (insert (if (< c ?\ )
266 (if (< c ?\ ) 289 (format "\\^%c" (+ c ?@))
267 (format "\\^%c" (+ c ?@)) 290 (format "\\%02x" c)))))))
268 (format "\\%02x" c))))))) 291
292;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
293;; Functions hacked from `ps-print' package.
294
295;; Dynamic evaluation
296(defun lpr-eval-switch (arg)
297 (cond ((stringp arg) arg)
298 ((functionp arg) (apply arg nil))
299 ((symbolp arg) (symbol-value arg))
300 ((consp arg) (apply (car arg) (cdr arg)))
301 (t nil)))
302
303;; `lpr-flatten-list' is defined here (copied from "message.el" and
304;; enhanced to handle dotted pairs as well) until we can get some
305;; sensible autoloads, or `flatten-list' gets put somewhere decent.
306
307;; (lpr-flatten-list '((a . b) c (d . e) (f g h) i . j))
308;; => (a b c d e f g h i j)
309
310(defun lpr-flatten-list (&rest list)
311 (lpr-flatten-list-1 list))
312
313(defun lpr-flatten-list-1 (list)
314 (cond
315 ((null list) (list))
316 ((consp list)
317 (append (lpr-flatten-list-1 (car list))
318 (lpr-flatten-list-1 (cdr list))))
319 (t (list list))))
269 320
270(provide 'lpr) 321(provide 'lpr)
271 322