1 ;;; lpr.el --- print Emacs buffer on line printer.
3 ;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;; Commands to send the region or a buffer your printer. Entry points
27 ;; are `lpr-buffer', `print-buffer', lpr-region', or `print-region'; option
28 ;; variables include `lpr-switches' and `lpr-command'.
33 (defvar lpr-switches nil
34 "*List of strings to pass as extra switch args to lpr when it is invoked.")
38 (if (memq system-type
'(usg-unix-v dgux-unix hpux silicon-graphics-unix
))
40 "*Shell command for printing a file")
42 (defvar print-region-function nil
43 "Function to call to print the region on a printer.
44 See definition of `print-region-1' for calling conventions.")
48 "Print buffer contents as with Unix command `lpr'.
49 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
51 (print-region-1 (point-min) (point-max) lpr-switches nil
))
54 (defun print-buffer ()
55 "Print buffer contents as with Unix command `lpr -p'.
56 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
58 (print-region-1 (point-min) (point-max) lpr-switches t
))
61 (defun lpr-region (start end
)
62 "Print region contents as with Unix command `lpr'.
63 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
65 (print-region-1 start end lpr-switches nil
))
68 (defun print-region (start end
)
69 "Print region contents as with Unix command `lpr -p'.
70 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
72 (print-region-1 start end lpr-switches t
))
74 (defun print-region-1 (start end switches page-headers
)
75 (let ((name (concat (buffer-name) " Emacs buffer"))
78 (message "Spooling...")
81 (print-region-new-buffer start end
)
82 (setq tab-width width
)
83 (untabify (point-min) (point-max))))
85 (if (eq system-type
'usg-unix-v
)
87 (print-region-new-buffer start end
)
88 (call-process-region start end
"pr" t t nil
))
89 ;; On BSD, use an option to get page headers.
90 (setq switches
(cons "-p" switches
))))
91 (apply (or print-region-function
'call-process-region
)
92 (nconc (list start end lpr-command
94 (nconc (and (eq system-type
'berkeley-unix
)
95 (list "-J" name
"-T" name
))
97 (message "Spooling...done"))))
99 ;; This function copies the text between start and end
100 ;; into a new buffer, makes that buffer current,
101 ;; and sets start and end to the buffer bounds.
102 ;; start and end are used free.
103 (defun print-region-new-buffer (start end
)
104 (or (string= (buffer-name) " *spool temp*")
105 (let ((oldbuf (current-buffer)))
106 (set-buffer (get-buffer-create " *spool temp*"))
107 (widen) (erase-buffer)
108 (insert-buffer-substring oldbuf start end
)
109 (setq start
(point-min) end
(point-max)))))
111 (defun printify-region (begin end
)
112 "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
113 in the current buffer into printable representations as control or
114 hexadecimal escapes."
119 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t
)
120 (setq c
(preceding-char))
121 (delete-backward-char 1)
124 (format "\\^%c" (+ c ?
@))
125 (format "\\%02x" c
)))))))