annotate lisp/lpr.el @ 210:01cbfdd59f82

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Wed, 06 Mar 1991 21:14:11 +0000
parents 5dfb6532c1b1
children 2c663336acaf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; Print Emacs buffer on line printer.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1985, 1988 Free Software Foundation, Inc.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; any later version.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU General Public License for more details.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;(defconst lpr-switches nil
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ; "*List of strings to pass as extra switch args to lpr when it is invoked.")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 (defvar lpr-command (if (eq system-type 'usg-unix-v)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 "lp" "lpr")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 "Shell command for printing a file")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 (defvar print-region-function nil
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 "Function to call to print the region on a printer.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 See definition of print-region-1 for calling conventions.")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (defun lpr-buffer ()
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 "Print buffer contents as with Unix command `lpr'.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (interactive)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (print-region-1 (point-min) (point-max) lpr-switches nil))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (defun print-buffer ()
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 "Print buffer contents as with Unix command `lpr -p'.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (interactive)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (print-region-1 (point-min) (point-max) lpr-switches t))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (defun lpr-region (start end)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 "Print region contents as with Unix command `lpr'.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (interactive "r")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (print-region-1 start end lpr-switches nil))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defun print-region (start end)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 "Print region contents as with Unix command `lpr -p'.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 `lpr-switches' is a list of extra switches (strings) to pass to lpr."
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (interactive "r")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (print-region-1 start end lpr-switches t))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (defun print-region-1 (start end switches page-headers)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (let ((name (concat (buffer-name) " Emacs buffer"))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (width tab-width))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (save-excursion
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (message "Spooling...")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (if (/= tab-width 8)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (progn
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (print-region-new-buffer start end)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (setq tab-width width)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (untabify (point-min) (point-max))))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (if page-headers
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (if (eq system-type 'usg-unix-v)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (progn
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (print-region-new-buffer)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (call-process-region start end "pr" t t nil))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; On BSD, use an option to get page headers.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (setq switches (cons "-p" switches))))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (apply (or print-region-function 'call-process-region)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (nconc (list start end lpr-command
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 nil nil nil)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (nconc (and (eq system-type 'berkeley-unix)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (list "-J" name "-T" name))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 switches)))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (message "Spooling...done"))))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; This function copies the text between start and end
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; into a new buffer, makes that buffer current,
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; and sets start and end to the buffer bounds.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; start and end are used free.
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (defun print-region-new-buffer ()
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (or (string= (buffer-name) " *spool temp*")
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (let ((oldbuf (current-buffer)))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (set-buffer (get-buffer-create " *spool temp*"))
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (widen) (erase-buffer)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (insert-buffer-substring oldbuf start end)
5dfb6532c1b1 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (setq start (point-min) end (point-max)))))