1 ;; Print Emacs buffer on line printer.
2 ;; Copyright (C) 1985, 1988 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
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)
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.
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.
21 ;(defconst lpr-switches nil
22 ; "*List of strings to pass as extra switch args to lpr when it is invoked.")
24 (defvar lpr-command
(if (eq system-type
'usg-unix-v
)
26 "Shell command for printing a file")
28 (defvar print-region-function nil
29 "Function to call to print the region on a printer.
30 See definition of print-region-1 for calling conventions.")
33 "Print buffer contents as with Unix command `lpr'.
34 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
36 (print-region-1 (point-min) (point-max) lpr-switches nil
))
38 (defun print-buffer ()
39 "Print buffer contents as with Unix command `lpr -p'.
40 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
42 (print-region-1 (point-min) (point-max) lpr-switches t
))
44 (defun lpr-region (start end
)
45 "Print region contents as with Unix command `lpr'.
46 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
48 (print-region-1 start end lpr-switches nil
))
50 (defun print-region (start end
)
51 "Print region contents as with Unix command `lpr -p'.
52 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
54 (print-region-1 start end lpr-switches t
))
56 (defun print-region-1 (start end switches page-headers
)
57 (let ((name (concat (buffer-name) " Emacs buffer"))
60 (message "Spooling...")
63 (print-region-new-buffer start end
)
64 (setq tab-width width
)
65 (untabify (point-min) (point-max))))
67 (if (eq system-type
'usg-unix-v
)
69 (print-region-new-buffer)
70 (call-process-region start end
"pr" t t nil
))
71 ;; On BSD, use an option to get page headers.
72 (setq switches
(cons "-p" switches
))))
73 (apply (or print-region-function
'call-process-region
)
74 (nconc (list start end lpr-command
76 (nconc (and (eq system-type
'berkeley-unix
)
77 (list "-J" name
"-T" name
))
79 (message "Spooling...done"))))
81 ;; This function copies the text between start and end
82 ;; into a new buffer, makes that buffer current,
83 ;; and sets start and end to the buffer bounds.
84 ;; start and end are used free.
85 (defun print-region-new-buffer ()
86 (or (string= (buffer-name) " *spool temp*")
87 (let ((oldbuf (current-buffer)))
88 (set-buffer (get-buffer-create " *spool temp*"))
89 (widen) (erase-buffer)
90 (insert-buffer-substring oldbuf start end
)
91 (setq start
(point-min) end
(point-max)))))