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