entered into RCS
[bpt/emacs.git] / lisp / lpr.el
CommitLineData
6594deb0
ER
1;;; lpr.el --- print Emacs buffer on line printer.
2
3a801d0c
ER
3;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc.
4
e5167999 5;; Maintainer: FSF
fd7fa35a 6;; Keywords: unix
e5167999 7
d6c7e99a
RS
8;; This file is part of GNU Emacs.
9
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
e5167999 12;; the Free Software Foundation; either version 2, or (at your option)
d6c7e99a
RS
13;; any later version.
14
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.
19
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.
23
e5167999 24;;; Code:
d6c7e99a 25
6503cec3
JB
26;;;###autoload
27(defconst lpr-switches nil "\
28*List of strings to pass as extra switch args to lpr when it is invoked.")
d6c7e99a
RS
29
30(defvar lpr-command (if (eq system-type 'usg-unix-v)
31 "lp" "lpr")
46947372 32 "*Shell command for printing a file")
d6c7e99a
RS
33
34(defvar print-region-function nil
35 "Function to call to print the region on a printer.
ac5b56bc 36See definition of `print-region-1' for calling conventions.")
d6c7e99a 37
7229064d 38;;;###autoload
d6c7e99a
RS
39(defun lpr-buffer ()
40 "Print buffer contents as with Unix command `lpr'.
41`lpr-switches' is a list of extra switches (strings) to pass to lpr."
42 (interactive)
43 (print-region-1 (point-min) (point-max) lpr-switches nil))
44
7229064d 45;;;###autoload
d6c7e99a
RS
46(defun print-buffer ()
47 "Print buffer contents as with Unix command `lpr -p'.
48`lpr-switches' is a list of extra switches (strings) to pass to lpr."
49 (interactive)
50 (print-region-1 (point-min) (point-max) lpr-switches t))
51
7229064d 52;;;###autoload
d6c7e99a
RS
53(defun lpr-region (start end)
54 "Print region contents as with Unix command `lpr'.
55`lpr-switches' is a list of extra switches (strings) to pass to lpr."
56 (interactive "r")
57 (print-region-1 start end lpr-switches nil))
58
7229064d 59;;;###autoload
d6c7e99a
RS
60(defun print-region (start end)
61 "Print region contents as with Unix command `lpr -p'.
62`lpr-switches' is a list of extra switches (strings) to pass to lpr."
63 (interactive "r")
64 (print-region-1 start end lpr-switches t))
65
66(defun print-region-1 (start end switches page-headers)
67 (let ((name (concat (buffer-name) " Emacs buffer"))
68 (width tab-width))
69 (save-excursion
70 (message "Spooling...")
71 (if (/= tab-width 8)
72 (progn
73 (print-region-new-buffer start end)
74 (setq tab-width width)
75 (untabify (point-min) (point-max))))
76 (if page-headers
77 (if (eq system-type 'usg-unix-v)
78 (progn
0b030df7 79 (print-region-new-buffer start end)
d6c7e99a
RS
80 (call-process-region start end "pr" t t nil))
81 ;; On BSD, use an option to get page headers.
82 (setq switches (cons "-p" switches))))
83 (apply (or print-region-function 'call-process-region)
84 (nconc (list start end lpr-command
85 nil nil nil)
86 (nconc (and (eq system-type 'berkeley-unix)
87 (list "-J" name "-T" name))
88 switches)))
89 (message "Spooling...done"))))
90
91;; This function copies the text between start and end
92;; into a new buffer, makes that buffer current,
93;; and sets start and end to the buffer bounds.
94;; start and end are used free.
0b030df7 95(defun print-region-new-buffer (start end)
d6c7e99a
RS
96 (or (string= (buffer-name) " *spool temp*")
97 (let ((oldbuf (current-buffer)))
98 (set-buffer (get-buffer-create " *spool temp*"))
99 (widen) (erase-buffer)
100 (insert-buffer-substring oldbuf start end)
101 (setq start (point-min) end (point-max)))))
6594deb0
ER
102
103;;; lpr.el ends here