(display-time-file-nonempty-p): Check existence here.
[bpt/emacs.git] / lisp / lpr.el
CommitLineData
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
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)
82 (let ((name (concat (buffer-name) " Emacs buffer"))
83 (width tab-width))
84 (save-excursion
85 (message "Spooling...")
86 (if (/= tab-width 8)
87 (progn
88 (print-region-new-buffer start end)
89 (setq tab-width width)
2adf4f61
RS
90 (save-excursion
91 (goto-char end)
92 (setq end (point-marker)))
d6c7e99a
RS
93 (untabify (point-min) (point-max))))
94 (if page-headers
3a621cfe
RS
95 (if lpr-headers-switches
96 ;; On BSD, use an option to get page headers.
b41f6027
RS
97 (setq switches (append (if (stringp lpr-headers-switches)
98 (list lpr-headers-switches)
99 lpr-headers-switches)
100 switches))
3a621cfe
RS
101 (print-region-new-buffer start end)
102 (call-process-region start end "pr" t t nil)
103 (setq start (point-min) end (point-max))))
d6c7e99a
RS
104 (apply (or print-region-function 'call-process-region)
105 (nconc (list start end lpr-command
106 nil nil nil)
3a621cfe 107 (nconc (and lpr-add-options
d6c7e99a
RS
108 (list "-J" name "-T" name))
109 switches)))
2adf4f61
RS
110 (if (markerp end)
111 (set-marker end nil))
d6c7e99a
RS
112 (message "Spooling...done"))))
113
114;; This function copies the text between start and end
115;; into a new buffer, makes that buffer current,
116;; and sets start and end to the buffer bounds.
117;; start and end are used free.
3a621cfe 118(defun print-region-new-buffer (ostart oend)
d6c7e99a
RS
119 (or (string= (buffer-name) " *spool temp*")
120 (let ((oldbuf (current-buffer)))
121 (set-buffer (get-buffer-create " *spool temp*"))
122 (widen) (erase-buffer)
3a621cfe 123 (insert-buffer-substring oldbuf ostart oend)
d6c7e99a 124 (setq start (point-min) end (point-max)))))
6594deb0 125
1c2df063
ER
126(defun printify-region (begin end)
127 "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
128in the current buffer into printable representations as control or
129hexadecimal escapes."
130 (interactive "r")
131 (save-excursion
132 (goto-char begin)
133 (let (c)
134 (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
135 (setq c (preceding-char))
136 (delete-backward-char 1)
137 (insert
138 (if (< c ?\ )
139 (format "\\^%c" (+ c ?@))
140 (format "\\%02x" c)))))))
141
6594deb0 142;;; lpr.el ends here