annotate lisp/packages/lpr.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 27bc7f280385
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
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Commands to send the region or a buffer your printer. Entry points
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; are `lpr-buffer', `print-buffer', lpr-region', or `print-region'; option
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; variables include `lpr-switches' and `lpr-command'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (defvar lpr-switches nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
37 "*List of strings to pass as extra options for the printer program.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
38 See `lpr-command'.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defvar lpr-add-switches (eq system-type 'berkeley-unix)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
41 "*Non-nil means construct -T and -J options for the printer program.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
42 These are made assuming that the program is `lpr';
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
43 if you are using some other incompatible printer program,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
44 this variable should be nil.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvar lpr-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (if (memq system-type '(usg-unix-v dgux hpux irix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 "lp" "lpr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "*Name of program for printing a file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; Default is nil, because that enables us to use pr -f
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; 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
54 (defvar lpr-headers-switches nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
55 "*List of strings of options to request page headings in the printer program.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 If nil, we run `lpr-page-header-program' to make page headings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 and print the result.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defvar print-region-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "Function to call to print the region on a printer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 See definition of `print-region-1' for calling conventions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defvar lpr-page-header-program "pr"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "*Name of program for adding page headers to a file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defvar lpr-page-header-switches '("-f")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
67 "*List of strings to use as options for the page-header-generating program.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
68 The variable `lpr-page-header-program' specifies the program to use.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defun lpr-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "Print buffer contents as with Unix command `lpr'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (print-region-1 (point-min) (point-max) lpr-switches nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defun print-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "Print buffer contents as with Unix command `lpr -p'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (print-region-1 (point-min) (point-max) lpr-switches t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defun lpr-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "Print region contents as with Unix command `lpr'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (print-region-1 start end lpr-switches nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun print-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "Print region contents as with Unix command `lpr -p'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (print-region-1 start end lpr-switches t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun print-region-1 (start end switches page-headers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; On some MIPS system, having a space in the job name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; crashes the printer demon. But using dashes looks ugly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; and it seems to annoying to do for that MIPS system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (let ((name (concat (buffer-name) " Emacs buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (title (concat (buffer-name) " Emacs buffer"))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
104 ;; On MS-DOS systems, make pipes use binary mode if the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
105 ;; original file is binary.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
106 (binary-process-input buffer-file-type)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
107 (binary-process-output buffer-file-type)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (width tab-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 switch-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if page-headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if lpr-headers-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; It is possible to use an lpr option
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; to get page headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq switches (append (if (stringp lpr-headers-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (list lpr-headers-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 lpr-headers-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (setq switch-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (if switches (concat " with options "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (mapconcat 'identity switches " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (message "Spooling%s..." switch-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (/= tab-width 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (let ((new-coords (print-region-new-buffer start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (setq start (car new-coords) end (cdr new-coords))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq tab-width width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq end (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (untabify (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (if page-headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (if lpr-headers-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; We handled this above by modifying SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; Run a separate program to get page headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (let ((new-coords (print-region-new-buffer start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (setq start (car new-coords) end (cdr new-coords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (apply 'call-process-region start end lpr-page-header-program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 t t nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (nconc (and lpr-add-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (list "-h" title))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 lpr-page-header-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (setq start (point-min) end (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (apply (or print-region-function 'call-process-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (nconc (list start end lpr-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 nil nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (nconc (and lpr-add-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (list "-J" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; These belong in pr if we are using that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (and lpr-add-switches lpr-headers-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (list "-T" title))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (if (markerp end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (set-marker end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (message "Spooling%s...done" switch-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; This function copies the text between start and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; into a new buffer, makes that buffer current.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; It returns the new range to print from the new current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; as (START . END).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defun print-region-new-buffer (ostart oend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (if (string= (buffer-name) " *spool temp*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (cons ostart oend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (let ((oldbuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (set-buffer (get-buffer-create " *spool temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (widen) (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (insert-buffer-substring oldbuf ostart oend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (cons (point-min) (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (defun printify-region (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 in the current buffer into printable representations as control or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 hexadecimal escapes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (let (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq c (preceding-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (delete-backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if (< c ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (format "\\^%c" (+ c ?@))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (format "\\%02x" c)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (provide 'lpr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;;; lpr.el ends here