annotate lisp/packages/lpr.el @ 155:43dd3413c7c7 r20-3b4

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