entered into RCS
[bpt/emacs.git] / lisp / lpr.el
CommitLineData
6594deb0
ER
1;;; lpr.el --- print Emacs buffer on line printer.
2
e5167999
ER
3;; Maintainer: FSF
4;; Last-Modified: 19 Apr 1992
fd7fa35a 5;; Keywords: unix
e5167999 6
46947372 7;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc.
d6c7e99a
RS
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
d6c7e99a
RS
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to
23;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
e5167999 25;;; Code:
d6c7e99a 26
6503cec3
JB
27;;;###autoload
28(defconst lpr-switches nil "\
29*List of strings to pass as extra switch args to lpr when it is invoked.")
d6c7e99a
RS
30
31(defvar lpr-command (if (eq system-type 'usg-unix-v)
32 "lp" "lpr")
46947372 33 "*Shell command for printing a file")
d6c7e99a
RS
34
35(defvar print-region-function nil
36 "Function to call to print the region on a printer.
ac5b56bc 37See definition of `print-region-1' for calling conventions.")
d6c7e99a 38
7229064d 39;;;###autoload
d6c7e99a
RS
40(defun lpr-buffer ()
41 "Print buffer contents as with Unix command `lpr'.
42`lpr-switches' is a list of extra switches (strings) to pass to lpr."
43 (interactive)
44 (print-region-1 (point-min) (point-max) lpr-switches nil))
45
7229064d 46;;;###autoload
d6c7e99a
RS
47(defun print-buffer ()
48 "Print buffer contents as with Unix command `lpr -p'.
49`lpr-switches' is a list of extra switches (strings) to pass to lpr."
50 (interactive)
51 (print-region-1 (point-min) (point-max) lpr-switches t))
52
7229064d 53;;;###autoload
d6c7e99a
RS
54(defun lpr-region (start end)
55 "Print region contents as with Unix command `lpr'.
56`lpr-switches' is a list of extra switches (strings) to pass to lpr."
57 (interactive "r")
58 (print-region-1 start end lpr-switches nil))
59
7229064d 60;;;###autoload
d6c7e99a
RS
61(defun print-region (start end)
62 "Print region contents as with Unix command `lpr -p'.
63`lpr-switches' is a list of extra switches (strings) to pass to lpr."
64 (interactive "r")
65 (print-region-1 start end lpr-switches t))
66
67(defun print-region-1 (start end switches page-headers)
68 (let ((name (concat (buffer-name) " Emacs buffer"))
69 (width tab-width))
70 (save-excursion
71 (message "Spooling...")
72 (if (/= tab-width 8)
73 (progn
74 (print-region-new-buffer start end)
75 (setq tab-width width)
76 (untabify (point-min) (point-max))))
77 (if page-headers
78 (if (eq system-type 'usg-unix-v)
79 (progn
80 (print-region-new-buffer)
81 (call-process-region start end "pr" t t nil))
82 ;; On BSD, use an option to get page headers.
83 (setq switches (cons "-p" switches))))
84 (apply (or print-region-function 'call-process-region)
85 (nconc (list start end lpr-command
86 nil nil nil)
87 (nconc (and (eq system-type 'berkeley-unix)
88 (list "-J" name "-T" name))
89 switches)))
90 (message "Spooling...done"))))
91
92;; This function copies the text between start and end
93;; into a new buffer, makes that buffer current,
94;; and sets start and end to the buffer bounds.
95;; start and end are used free.
96(defun print-region-new-buffer ()
97 (or (string= (buffer-name) " *spool temp*")
98 (let ((oldbuf (current-buffer)))
99 (set-buffer (get-buffer-create " *spool temp*"))
100 (widen) (erase-buffer)
101 (insert-buffer-substring oldbuf start end)
102 (setq start (point-min) end (point-max)))))
6594deb0
ER
103
104;;; lpr.el ends here