Commit | Line | Data |
---|---|---|
d6c7e99a RS |
1 | ;; Print Emacs buffer on line printer. |
2 | ;; Copyright (C) 1985, 1988 Free Software Foundation, Inc. | |
3 | ||
4 | ;; This file is part of GNU Emacs. | |
5 | ||
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) | |
9 | ;; any later version. | |
10 | ||
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. | |
15 | ||
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. | |
19 | ||
20 | ||
21 | ;(defconst lpr-switches nil | |
22 | ; "*List of strings to pass as extra switch args to lpr when it is invoked.") | |
23 | ||
24 | (defvar lpr-command (if (eq system-type 'usg-unix-v) | |
25 | "lp" "lpr") | |
26 | "Shell command for printing a file") | |
27 | ||
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.") | |
31 | ||
32 | (defun lpr-buffer () | |
33 | "Print buffer contents as with Unix command `lpr'. | |
34 | `lpr-switches' is a list of extra switches (strings) to pass to lpr." | |
35 | (interactive) | |
36 | (print-region-1 (point-min) (point-max) lpr-switches nil)) | |
37 | ||
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." | |
41 | (interactive) | |
42 | (print-region-1 (point-min) (point-max) lpr-switches t)) | |
43 | ||
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." | |
47 | (interactive "r") | |
48 | (print-region-1 start end lpr-switches nil)) | |
49 | ||
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." | |
53 | (interactive "r") | |
54 | (print-region-1 start end lpr-switches t)) | |
55 | ||
56 | (defun print-region-1 (start end switches page-headers) | |
57 | (let ((name (concat (buffer-name) " Emacs buffer")) | |
58 | (width tab-width)) | |
59 | (save-excursion | |
60 | (message "Spooling...") | |
61 | (if (/= tab-width 8) | |
62 | (progn | |
63 | (print-region-new-buffer start end) | |
64 | (setq tab-width width) | |
65 | (untabify (point-min) (point-max)))) | |
66 | (if page-headers | |
67 | (if (eq system-type 'usg-unix-v) | |
68 | (progn | |
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 | |
75 | nil nil nil) | |
76 | (nconc (and (eq system-type 'berkeley-unix) | |
77 | (list "-J" name "-T" name)) | |
78 | switches))) | |
79 | (message "Spooling...done")))) | |
80 | ||
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))))) |