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