lpr.el 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ;; Print Emacs buffer on line printer.
  2. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  3. ;; This file is part of GNU Emacs.
  4. ;; GNU Emacs is distributed in the hope that it will be useful,
  5. ;; but WITHOUT ANY WARRANTY. No author or distributor
  6. ;; accepts responsibility to anyone for the consequences of using it
  7. ;; or for whether it serves any particular purpose or works at all,
  8. ;; unless he says so in writing. Refer to the GNU Emacs General Public
  9. ;; License for full details.
  10. ;; Everyone is granted permission to copy, modify and redistribute
  11. ;; GNU Emacs, but only under the conditions described in the
  12. ;; GNU Emacs General Public License. A copy of this license is
  13. ;; supposed to have been given to you along with GNU Emacs so you
  14. ;; can know your rights and responsibilities. It should be in a
  15. ;; file named COPYING. Among other things, the copyright notice
  16. ;; and this notice must be preserved on all copies.
  17. ;(defconst lpr-switches nil
  18. ; "*List of strings to pass as extra switch args to lpr when it is invoked.")
  19. (defun lpr-buffer ()
  20. "Print buffer contents as with Unix command `lpr'.
  21. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  22. (interactive)
  23. (print-region-1 (point-min) (point-max) lpr-switches))
  24. (defun print-buffer ()
  25. "Print buffer contents as with Unix command `lpr -p'.
  26. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  27. (interactive)
  28. (print-region-1 (point-min) (point-max) (cons "-p" lpr-switches)))
  29. (defun lpr-region (start end)
  30. "Print region contents as with Unix command `lpr'.
  31. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  32. (interactive "r")
  33. (print-region-1 start end lpr-switches))
  34. (defun print-region (start end)
  35. "Print region contents as with Unix command `lpr -p'.
  36. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  37. (interactive "r")
  38. (print-region-1 start end (cons "-p" lpr-switches)))
  39. (defun print-region-1 (start end switches)
  40. (save-excursion
  41. (message "Spooling...")
  42. (if (/= tab-width 8)
  43. (let ((oldbuf (current-buffer)))
  44. (set-buffer (get-buffer-create " *spool temp*"))
  45. (widen) (erase-buffer)
  46. (insert-buffer-substring oldbuf)
  47. (call-process-region start end "expand"
  48. t t nil
  49. (format "-%d" tab-width))))
  50. (apply 'call-process-region
  51. (nconc (list start end "lpr"
  52. nil nil nil
  53. "-J" (concat (buffer-name) " Emacs buffer")
  54. "-T" (concat (buffer-name) " Emacs buffer"))
  55. switches))
  56. (message "Spooling...done")))