home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / packages / lpr.el < prev    next >
Encoding:
Text File  |  1992-11-12  |  3.3 KB  |  91 lines

  1. ;; Print Emacs buffer on line printer.
  2. ;; Copyright (C) 1985, 1988, 1992 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 2, 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 (memq system-type
  25.                    '(usg-unix-v hpux silicon-graphics-unix))
  26.             "lp" "lpr")
  27.   "Shell command for printing a file")
  28.  
  29. (defun lpr-buffer ()
  30.   "Print buffer contents as with Unix command `lpr'.
  31. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  32.   (interactive)
  33.   (print-region-1 (point-min) (point-max) lpr-switches nil))
  34.  
  35. (defun print-buffer ()
  36.   "Print buffer contents as with Unix command `lpr -p'.
  37. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  38.   (interactive)
  39.   (print-region-1 (point-min) (point-max) lpr-switches t))
  40.  
  41. (defun lpr-region (start end)
  42.   "Print region contents as with Unix command `lpr'.
  43. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  44.   (interactive "r")
  45.   (print-region-1 start end lpr-switches nil))
  46.  
  47. (defun print-region (start end)
  48.   "Print region contents as with Unix command `lpr -p'.
  49. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  50.   (interactive "r")
  51.   (print-region-1 start end lpr-switches t))
  52.  
  53. (defun print-region-1 (start end switches page-headers)
  54.   (let ((name (concat (buffer-name) " Emacs buffer"))
  55.     (width tab-width))
  56.     (save-excursion
  57.       (message "Spooling...")
  58.       (if (/= tab-width 8)
  59.       (progn
  60.         (print-region-new-buffer) ; dynaimcally accesses start and end
  61.         (setq tab-width width)
  62.         (untabify (point-min) (point-max))))
  63.       (if page-headers
  64.       (if (eq system-type 'usg-unix-v)
  65.           (progn
  66.         (print-region-new-buffer)
  67.         (call-process-region start end "pr" t t nil))
  68.         ;; On BSD, use an option to get page headers.
  69.         (setq switches (and (equal lpr-command "lpr")
  70.                 (cons "-p" switches)))))
  71.       (apply 'call-process-region
  72.          (nconc (list start end lpr-command
  73.               nil nil nil)
  74.             (nconc (and (eq system-type 'berkeley-unix)
  75.                 (eq lpr-command "lpr")
  76.                 (list "-J" name "-T" name))
  77.                switches)))
  78.       (message "Spooling...done"))))
  79.  
  80. ;; This function copies the text between start and end
  81. ;; into a new buffer, makes that buffer current,
  82. ;; and sets start and end to the buffer bounds.
  83. ;; start and end are used free.
  84. (defun print-region-new-buffer ()
  85.   (or (string= (buffer-name) " *spool temp*")
  86.       (let ((oldbuf (current-buffer)))
  87.     (set-buffer (get-buffer-create " *spool temp*"))
  88.     (widen) (erase-buffer)
  89.     (insert-buffer-substring oldbuf start end)
  90.     (setq start (point-min) end (point-max)))))
  91.