1 ;;; lpr.el --- print Emacs buffer on line printer.
3 ;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 (defconst lpr-switches nil
"\
28 *List of strings to pass as extra switch args to lpr when it is invoked.")
30 (defvar lpr-command
(if (eq system-type
'usg-unix-v
)
32 "*Shell command for printing a file")
34 (defvar print-region-function nil
35 "Function to call to print the region on a printer.
36 See definition of `print-region-1' for calling conventions.")
40 "Print buffer contents as with Unix command `lpr'.
41 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
43 (print-region-1 (point-min) (point-max) lpr-switches nil
))
46 (defun print-buffer ()
47 "Print buffer contents as with Unix command `lpr -p'.
48 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
50 (print-region-1 (point-min) (point-max) lpr-switches t
))
53 (defun lpr-region (start end
)
54 "Print region contents as with Unix command `lpr'.
55 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
57 (print-region-1 start end lpr-switches nil
))
60 (defun print-region (start end
)
61 "Print region contents as with Unix command `lpr -p'.
62 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
64 (print-region-1 start end lpr-switches t
))
66 (defun print-region-1 (start end switches page-headers
)
67 (let ((name (concat (buffer-name) " Emacs buffer"))
70 (message "Spooling...")
73 (print-region-new-buffer start end
)
74 (setq tab-width width
)
75 (untabify (point-min) (point-max))))
77 (if (eq system-type
'usg-unix-v
)
79 (print-region-new-buffer start end
)
80 (call-process-region start end
"pr" t t nil
))
81 ;; On BSD, use an option to get page headers.
82 (setq switches
(cons "-p" switches
))))
83 (apply (or print-region-function
'call-process-region
)
84 (nconc (list start end lpr-command
86 (nconc (and (eq system-type
'berkeley-unix
)
87 (list "-J" name
"-T" name
))
89 (message "Spooling...done"))))
91 ;; This function copies the text between start and end
92 ;; into a new buffer, makes that buffer current,
93 ;; and sets start and end to the buffer bounds.
94 ;; start and end are used free.
95 (defun print-region-new-buffer (start end
)
96 (or (string= (buffer-name) " *spool temp*")
97 (let ((oldbuf (current-buffer)))
98 (set-buffer (get-buffer-create " *spool temp*"))
99 (widen) (erase-buffer)
100 (insert-buffer-substring oldbuf start end
)
101 (setq start
(point-min) end
(point-max)))))