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