1 ;;; lpr.el --- print Emacs buffer on line printer.
3 ;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
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)
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.
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.
23 (defconst lpr-switches nil
"\
24 *List of strings to pass as extra switch args to lpr when it is invoked.")
26 (defvar lpr-command
(if (eq system-type
'usg-unix-v
)
28 "*Shell command for printing a file")
30 (defvar print-region-function nil
31 "Function to call to print the region on a printer.
32 See definition of `print-region-1' for calling conventions.")
36 "Print buffer contents as with Unix command `lpr'.
37 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
39 (print-region-1 (point-min) (point-max) lpr-switches nil
))
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."
46 (print-region-1 (point-min) (point-max) lpr-switches t
))
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."
53 (print-region-1 start end lpr-switches nil
))
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."
60 (print-region-1 start end lpr-switches t
))
62 (defun print-region-1 (start end switches page-headers
)
63 (let ((name (concat (buffer-name) " Emacs buffer"))
66 (message "Spooling...")
69 (print-region-new-buffer start end
)
70 (setq tab-width width
)
71 (untabify (point-min) (point-max))))
73 (if (eq system-type
'usg-unix-v
)
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
82 (nconc (and (eq system-type
'berkeley-unix
)
83 (list "-J" name
"-T" name
))
85 (message "Spooling...done"))))
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)))))