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