(gnus-inews-domain-name): Once again test gnus-your-domain.
[bpt/emacs.git] / lisp / lpr.el
CommitLineData
6594deb0
ER
1;;; lpr.el --- print Emacs buffer on line printer.
2
8f1204db 3;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc.
3a801d0c 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
3a621cfe
RS
34 "*List of strings to pass as extra switch args to `lpr' when it is invoked.")
35
36(defvar lpr-add-options (eq system-type 'berkeley-unix)
37 "*Non-nil means construct -T and -J options for the `lpr'.")
d6c7e99a 38
910476ef 39;;;###autoload
7114f404 40(defvar lpr-command
3a621cfe 41 (if (memq system-type '(usg-unix-v dgux hpux irix))
9f0a6471
JB
42 "lp" "lpr")
43 "*Shell command for printing a file")
d6c7e99a 44
9897e2d5
RS
45(defvar lpr-headers-switches
46 (if (memq system-type '(usg-unix-v hpux)) nil "-p")
3a621cfe
RS
47 "*List of strings to use as options for `lpr' to request page headings.")
48
d6c7e99a
RS
49(defvar print-region-function nil
50 "Function to call to print the region on a printer.
ac5b56bc 51See definition of `print-region-1' for calling conventions.")
d6c7e99a 52
7229064d 53;;;###autoload
d6c7e99a
RS
54(defun lpr-buffer ()
55 "Print buffer contents as with Unix command `lpr'.
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 nil))
59
7229064d 60;;;###autoload
d6c7e99a
RS
61(defun print-buffer ()
62 "Print buffer contents as with Unix command `lpr -p'.
63`lpr-switches' is a list of extra switches (strings) to pass to lpr."
64 (interactive)
65 (print-region-1 (point-min) (point-max) lpr-switches t))
66
7229064d 67;;;###autoload
d6c7e99a
RS
68(defun lpr-region (start end)
69 "Print region contents as with Unix command `lpr'.
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 nil))
73
7229064d 74;;;###autoload
d6c7e99a
RS
75(defun print-region (start end)
76 "Print region contents as with Unix command `lpr -p'.
77`lpr-switches' is a list of extra switches (strings) to pass to lpr."
78 (interactive "r")
79 (print-region-1 start end lpr-switches t))
80
81(defun print-region-1 (start end switches page-headers)
fc60327e
RS
82 ;; Avoid having a space in the job name
83 ;; because on some MIPS system that crashes the printer demon.
a8037455
RS
84 (let ((name (concat (buffer-name) "-Emacs-buffer"))
85 (title (concat (buffer-name) " Emacs buffer"))
d6c7e99a
RS
86 (width tab-width))
87 (save-excursion
88 (message "Spooling...")
89 (if (/= tab-width 8)
90 (progn
91 (print-region-new-buffer start end)
92 (setq tab-width width)
2adf4f61
RS
93 (save-excursion
94 (goto-char end)
95 (setq end (point-marker)))
d6c7e99a
RS
96 (untabify (point-min) (point-max))))
97 (if page-headers
3a621cfe
RS
98 (if lpr-headers-switches
99 ;; On BSD, use an option to get page headers.
b41f6027
RS
100 (setq switches (append (if (stringp lpr-headers-switches)
101 (list lpr-headers-switches)
102 lpr-headers-switches)
103 switches))
3a621cfe
RS
104 (print-region-new-buffer start end)
105 (call-process-region start end "pr" t t nil)
106 (setq start (point-min) end (point-max))))
d6c7e99a
RS
107 (apply (or print-region-function 'call-process-region)
108 (nconc (list start end lpr-command
109 nil nil nil)
3a621cfe 110 (nconc (and lpr-add-options
a8037455 111 (list "-J" name "-T" title))
d6c7e99a 112 switches)))
2adf4f61
RS
113 (if (markerp end)
114 (set-marker end nil))
d6c7e99a
RS
115 (message "Spooling...done"))))
116
117;; This function copies the text between start and end
118;; into a new buffer, makes that buffer current,
119;; and sets start and end to the buffer bounds.
120;; start and end are used free.
3a621cfe 121(defun print-region-new-buffer (ostart oend)
d6c7e99a
RS
122 (or (string= (buffer-name) " *spool temp*")
123 (let ((oldbuf (current-buffer)))
124 (set-buffer (get-buffer-create " *spool temp*"))
125 (widen) (erase-buffer)
3a621cfe 126 (insert-buffer-substring oldbuf ostart oend)
d6c7e99a 127 (setq start (point-min) end (point-max)))))
6594deb0 128
1c2df063
ER
129(defun printify-region (begin end)
130 "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
131in the current buffer into printable representations as control or
132hexadecimal escapes."
133 (interactive "r")
134 (save-excursion
135 (goto-char begin)
136 (let (c)
137 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
138 (setq c (preceding-char))
139 (delete-backward-char 1)
140 (insert
141 (if (< c ?\ )
142 (format "\\^%c" (+ c ?@))
143 (format "\\%02x" c)))))))
144
6594deb0 145;;; lpr.el ends here