*** empty log message ***
[emacs.git] / lisp / lpr.el
blob52f5abc5220755022613cf089fecd2e821da1bea
1 ;;; lpr.el --- print Emacs buffer on line printer.
3 ;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: unix
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)
13 ;; any later version.
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.
24 ;;; Code:
26 ;;;###autoload
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)
31 "lp" "lpr")
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.")
38 ;;;###autoload
39 (defun lpr-buffer ()
40 "Print buffer contents as with Unix command `lpr'.
41 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
42 (interactive)
43 (print-region-1 (point-min) (point-max) lpr-switches nil))
45 ;;;###autoload
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."
49 (interactive)
50 (print-region-1 (point-min) (point-max) lpr-switches t))
52 ;;;###autoload
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."
56 (interactive "r")
57 (print-region-1 start end lpr-switches nil))
59 ;;;###autoload
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."
63 (interactive "r")
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"))
68 (width tab-width))
69 (save-excursion
70 (message "Spooling...")
71 (if (/= tab-width 8)
72 (progn
73 (print-region-new-buffer start end)
74 (setq tab-width width)
75 (untabify (point-min) (point-max))))
76 (if page-headers
77 (if (eq system-type 'usg-unix-v)
78 (progn
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
85 nil nil nil)
86 (nconc (and (eq system-type 'berkeley-unix)
87 (list "-J" name "-T" name))
88 switches)))
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)))))
103 ;;; lpr.el ends here