annotate lisp/packages/lpr.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; lpr.el --- print Emacs buffer on line printer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: unix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Commands to send the region or a buffer your printer. Entry points
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; are `lpr-buffer', `print-buffer', lpr-region', or `print-region'; option
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; variables include `lpr-switches' and `lpr-command'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defvar lpr-switches nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "*List of strings to pass as extra switch args to `lpr' when it is invoked.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defvar lpr-add-switches (eq system-type 'berkeley-unix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 "*Non-nil means construct -T and -J options for the `lpr'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defvar lpr-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (if (memq system-type '(usg-unix-v dgux hpux irix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 "lp" "lpr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "*Name of program for printing a file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; Default is nil, because that enables us to use pr -f
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; which is more reliable than pr with no args, which is what lpr -p does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defvar lpr-headers-switches nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "*List of strings to use as options for `lpr' to request page headings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 If nil, we run `lpr-page-header-program' to make page headings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 and print the result.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defvar print-region-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "Function to call to print the region on a printer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 See definition of `print-region-1' for calling conventions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defvar lpr-page-header-program "pr"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "*Name of program for adding page headers to a file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar lpr-page-header-switches '("-f")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "*List of strings to use as options for `lpr-page-header-program'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun lpr-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Print buffer contents as with Unix command `lpr'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (print-region-1 (point-min) (point-max) lpr-switches nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defun print-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Print buffer contents as with Unix command `lpr -p'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (print-region-1 (point-min) (point-max) lpr-switches t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defun lpr-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 "Print region contents as with Unix command `lpr'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (print-region-1 start end lpr-switches nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun print-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "Print region contents as with Unix command `lpr -p'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (print-region-1 start end lpr-switches t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun print-region-1 (start end switches page-headers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; On some MIPS system, having a space in the job name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; crashes the printer demon. But using dashes looks ugly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; and it seems to annoying to do for that MIPS system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (let ((name (concat (buffer-name) " Emacs buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (title (concat (buffer-name) " Emacs buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (width tab-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 switch-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (if page-headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if lpr-headers-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; It is possible to use an lpr option
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; to get page headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq switches (append (if (stringp lpr-headers-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (list lpr-headers-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 lpr-headers-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (setq switch-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (if switches (concat " with options "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (mapconcat 'identity switches " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (message "Spooling%s..." switch-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (/= tab-width 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (let ((new-coords (print-region-new-buffer start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq start (car new-coords) end (cdr new-coords))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq tab-width width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq end (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (untabify (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if page-headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (if lpr-headers-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; We handled this above by modifying SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; Run a separate program to get page headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (let ((new-coords (print-region-new-buffer start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq start (car new-coords) end (cdr new-coords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (apply 'call-process-region start end lpr-page-header-program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 t t nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (nconc (and lpr-add-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (list "-h" title))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 lpr-page-header-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (setq start (point-min) end (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (apply (or print-region-function 'call-process-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (nconc (list start end lpr-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 nil nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (nconc (and lpr-add-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (list "-J" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; These belong in pr if we are using that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (and lpr-add-switches lpr-headers-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (list "-T" title))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (markerp end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (set-marker end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (message "Spooling%s...done" switch-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; This function copies the text between start and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; into a new buffer, makes that buffer current.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; It returns the new range to print from the new current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; as (START . END).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (defun print-region-new-buffer (ostart oend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (if (string= (buffer-name) " *spool temp*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (cons ostart oend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let ((oldbuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (set-buffer (get-buffer-create " *spool temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (widen) (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (insert-buffer-substring oldbuf ostart oend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (cons (point-min) (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defun printify-region (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 in the current buffer into printable representations as control or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 hexadecimal escapes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (let (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq c (preceding-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (delete-backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (if (< c ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (format "\\^%c" (+ c ?@))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (format "\\%02x" c)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (provide 'lpr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;; lpr.el ends here