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