Commit | Line | Data |
---|---|---|
6594deb0 ER |
1 | ;;; lpr.el --- print Emacs buffer on line printer. |
2 | ||
3a801d0c ER |
3 | ;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc. |
4 | ||
e5167999 | 5 | ;; Maintainer: FSF |
fd7fa35a | 6 | ;; Keywords: unix |
e5167999 | 7 | |
d6c7e99a RS |
8 | ;; This file is part of GNU Emacs. |
9 | ||
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 | |
e5167999 | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
d6c7e99a RS |
13 | ;; any later version. |
14 | ||
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. | |
19 | ||
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. | |
23 | ||
e41b2db1 ER |
24 | ;;; Commentary: |
25 | ||
26 | ;; Commands to send the region or a buffer your printer. Entry points | |
27 | ;; are `lpr-buffer', `print-buffer', lpr-region', or `print-region'; option | |
28 | ;; variables include `lpr-switches' and `lpr-command'. | |
29 | ||
e5167999 | 30 | ;;; Code: |
d6c7e99a | 31 | |
6503cec3 | 32 | ;;;###autoload |
7114f404 | 33 | (defvar lpr-switches nil |
9f0a6471 | 34 | "*List of strings to pass as extra switch args to lpr when it is invoked.") |
d6c7e99a | 35 | |
910476ef | 36 | ;;;###autoload |
7114f404 | 37 | (defvar lpr-command |
f48872fc | 38 | (if (memq system-type '(usg-unix-v dgux-unix hpux irix)) |
9f0a6471 JB |
39 | "lp" "lpr") |
40 | "*Shell command for printing a file") | |
d6c7e99a RS |
41 | |
42 | (defvar print-region-function nil | |
43 | "Function to call to print the region on a printer. | |
ac5b56bc | 44 | See definition of `print-region-1' for calling conventions.") |
d6c7e99a | 45 | |
7229064d | 46 | ;;;###autoload |
d6c7e99a RS |
47 | (defun lpr-buffer () |
48 | "Print buffer contents as with Unix command `lpr'. | |
49 | `lpr-switches' is a list of extra switches (strings) to pass to lpr." | |
50 | (interactive) | |
51 | (print-region-1 (point-min) (point-max) lpr-switches nil)) | |
52 | ||
7229064d | 53 | ;;;###autoload |
d6c7e99a RS |
54 | (defun print-buffer () |
55 | "Print buffer contents as with Unix command `lpr -p'. | |
56 | `lpr-switches' is a list of extra switches (strings) to pass to lpr." | |
57 | (interactive) | |
58 | (print-region-1 (point-min) (point-max) lpr-switches t)) | |
59 | ||
7229064d | 60 | ;;;###autoload |
d6c7e99a RS |
61 | (defun lpr-region (start end) |
62 | "Print region contents as with Unix command `lpr'. | |
63 | `lpr-switches' is a list of extra switches (strings) to pass to lpr." | |
64 | (interactive "r") | |
65 | (print-region-1 start end lpr-switches nil)) | |
66 | ||
7229064d | 67 | ;;;###autoload |
d6c7e99a RS |
68 | (defun print-region (start end) |
69 | "Print region contents as with Unix command `lpr -p'. | |
70 | `lpr-switches' is a list of extra switches (strings) to pass to lpr." | |
71 | (interactive "r") | |
72 | (print-region-1 start end lpr-switches t)) | |
73 | ||
74 | (defun print-region-1 (start end switches page-headers) | |
75 | (let ((name (concat (buffer-name) " Emacs buffer")) | |
76 | (width tab-width)) | |
77 | (save-excursion | |
78 | (message "Spooling...") | |
79 | (if (/= tab-width 8) | |
80 | (progn | |
81 | (print-region-new-buffer start end) | |
82 | (setq tab-width width) | |
2adf4f61 RS |
83 | (save-excursion |
84 | (goto-char end) | |
85 | (setq end (point-marker))) | |
d6c7e99a RS |
86 | (untabify (point-min) (point-max)))) |
87 | (if page-headers | |
88 | (if (eq system-type 'usg-unix-v) | |
89 | (progn | |
0b030df7 | 90 | (print-region-new-buffer start end) |
d6c7e99a RS |
91 | (call-process-region start end "pr" t t nil)) |
92 | ;; On BSD, use an option to get page headers. | |
93 | (setq switches (cons "-p" switches)))) | |
94 | (apply (or print-region-function 'call-process-region) | |
95 | (nconc (list start end lpr-command | |
96 | nil nil nil) | |
97 | (nconc (and (eq system-type 'berkeley-unix) | |
98 | (list "-J" name "-T" name)) | |
99 | switches))) | |
2adf4f61 RS |
100 | (if (markerp end) |
101 | (set-marker end nil)) | |
d6c7e99a RS |
102 | (message "Spooling...done")))) |
103 | ||
104 | ;; This function copies the text between start and end | |
105 | ;; into a new buffer, makes that buffer current, | |
106 | ;; and sets start and end to the buffer bounds. | |
107 | ;; start and end are used free. | |
0b030df7 | 108 | (defun print-region-new-buffer (start end) |
d6c7e99a RS |
109 | (or (string= (buffer-name) " *spool temp*") |
110 | (let ((oldbuf (current-buffer))) | |
111 | (set-buffer (get-buffer-create " *spool temp*")) | |
112 | (widen) (erase-buffer) | |
113 | (insert-buffer-substring oldbuf start end) | |
114 | (setq start (point-min) end (point-max))))) | |
6594deb0 | 115 | |
1c2df063 ER |
116 | (defun printify-region (begin end) |
117 | "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF) | |
118 | in the current buffer into printable representations as control or | |
119 | hexadecimal escapes." | |
120 | (interactive "r") | |
121 | (save-excursion | |
122 | (goto-char begin) | |
123 | (let (c) | |
124 | (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t) | |
125 | (setq c (preceding-char)) | |
126 | (delete-backward-char 1) | |
127 | (insert | |
128 | (if (< c ?\ ) | |
129 | (format "\\^%c" (+ c ?@)) | |
130 | (format "\\%02x" c))))))) | |
131 | ||
6594deb0 | 132 | ;;; lpr.el ends here |