[comp.emacs] print-buffer usage?

steveh@moosehead.mips.com (Stephen C. Hill) (12/15/90)

I have been having problems getting any output from
[lpr|print]-[buffer|region].  I have tried to change the variable
"lpr-switches" in Edit-Options to ("-PiD") [our printer's id is iD].

The first question is, how does one specify a list when using the "s"
command within Edit-Option?  If I type ("-PiD") in the mini-buffer, it
responds with "Invalid function: "-PiD"".  So, I just went in and
editted the line to read as it should (as I understand it, at least.) 
When I ran the print-buffer, it comes back with "Spooling ..." and
finally "Spooling Done" ... but no output appears.  I'd love to be able
to print out messages from within rmail.  Does anyone know what kind of
arcanity I must do?

I am using version 18.52 of Emacs.

Steve

-- 
Stephen C. Hill, CDP
{ames,prls,pyramid,decwrl}!mips!steveh  or  steveh@mips.com 
Integration Products Group
MIPS Computer Systems, Stop 6-03
950 Deguigne Avenue
Sunnyvale, CA 94086, (408) 524-7436

Time is Nature's method of keeping us from bumping into ourselves.

jbg@sei.cmu.edu (John Goodenough) (12/17/90)

In article print-buffer usage? of 14 Dec 90 22:01:39 GMT steveh@moosehead.mips.com (Stephen C. Hill) writes:

>The first question is, how does one specify a list when using the "s"
>command within Edit-Option?  If I type ("-PiD") in the mini-buffer, it
>responds with "Invalid function: "-PiD"".  So, I just went in and

To prevent evaluation, type

	'("-PiD")

I put the following into my .emacs file

   (set-variable 'lpr-switches (cons (concat "-h -B -P" (getenv "PRINTER")) nil))

-- 
John B. Goodenough					Goodenough@sei.cmu.edu
Software Engineering Institute				412-268-6391

hollen@megatek (Dion Hollenbeck) (12/18/90)

In article <44099@mips.mips.COM> steveh@moosehead.mips.com (Stephen C. Hill) writes:
> 
> I have been having problems getting any output from
> [lpr|print]-[buffer|region].  I have tried to change the variable
> "lpr-switches" in Edit-Options to ("-PiD") [our printer's id is iD].
> 
> The first question is, how does one specify a list when using the "s"
> command within Edit-Option?  If I type ("-PiD") in the mini-buffer, it
> responds with "Invalid function: "-PiD"".  So, I just went in and
> editted the line to read as it should (as I understand it, at least.) 
> When I ran the print-buffer, it comes back with "Spooling ..." and
> finally "Spooling Done" ... but no output appears.  I'd love to be able
> to print out messages from within rmail.  Does anyone know what kind of
> arcanity I must do?
> 

I ran into a similar problem when I wanted to use our laser printer,
only more complex.  The laser printer must have text turned into
PostScript before sending to lpr, so the following was necessary
to implement in emacs:

cat file | lwf | lpr -Pz

I made a kludgy attempt that utilized an external shell script
since 'call-process-region cannot handle "|".  This worked for a
while, but I was not happy with it.  After writing a memo 
generation utility in Elisp, I figured I could tackle the laser
printer problem and do it right.  Not only did I fix the ability
to use a different printer (-Pza), but in the process, I cured
the problem of not being able to print buffers or regions of
rmail and shell buffers.  The secret to this was to ALWAYS use
the spool buffer, not just when needing to untabify.  Evidently
the 'call-process-region on certain kinds of buffers was failing.

The long and short of it is, that here is the source code for
accessing a laser printer which has to have two 'call-process-region
calls made and has all the fixes you mentioned.  I originally got
the source from lpr.el, so you should be able to re-integrate
my changes back in with little trouble.  You will notice that there
are some kludges for our "lwf" PostScript converter since it was
parsing command line arguments in a fashion which would not
allow a list to be passed, but needed an array of strings. I
hope this solves the problem you are experiencing.  By the way,
you are an Elisp programmer, aren't you (or didn't they mention that
by using Emacs you have implicitly agreed to learn Elisp at sometime
in the future).  B^)

-----------------------------  cut here --------------------------
;; Print Emacs buffer on lazer printer.
;; Copyright (C) 1985, 1988 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

;; Modified from "lpr.el" by Dion Hollenbeck
;;                           May 2, 1989
;;
;;

(defvar lwf-prog "lwf"
  "For laser printing - program name to use.")
;;  for debug purposes only
;;(defvar lwf-prog "showinp")
;;(setq lwf-prog "showinp")

;;  Flags for lwf
;;
;;     NOTE:  you can (setq flag "blah") in your .emacs after loading
;;            zpr, but NEVER have one of these flags be a null string
;;            or contain multiple flags, or lwf will barf and most
;;            likely lose all your other flags too.
;;
(defvar lwf-indent "-i0.5"
  "For laser printing - lwf indentation flag.")
(defvar lwf-size "-s11"
  "For laser printing - lwf point size flag.")
(defvar lwf-spool-buf " *lwf spool*"
  "For laser printing - lwf spool buffer name.")

(defun zpr-buffer ()
  "Print buffer contents, un-paginated."
  (interactive)
  (zprint-region-1 (point-min) (point-max) nil )
)

(defun zpr-region (start end)
  "Print region contents, un-paginated."
  (interactive "r")
  (setq lwf-page "")
  (zprint-region-1 start end nil )
)

(defun zprint-buffer ()
  "Print buffer contents paginated."
  (interactive)
  (zprint-region-1 (point-min) (point-max) t )
)

(defun zprint-region (start end)
  "Print region contents paginated."
  (interactive "r")
  (zprint-region-1 (mark) (point) t )
)

(defun zprint-region-1 (start end lwf-page)
  "Lazer print region by pasing through lwf and lpr, optionally paginated.
Will either use environment variable value of ROFFPRINTER, or if
not defined, will use z as the default laser printer.
lwf-page parameter should be either t or nil only."

  (let ((name (concat (buffer-name) ""))
	(width tab-width))
    (save-excursion
      (message "Spooling...")
      (let ((oldbuf (current-buffer))
	    (lwfbuf (get-buffer-create lwf-spool-buf) )
	    (roffprinter (getenv "ROFFPRINTER"))
	    )
	(if (not roffprinter)
	    (setq roffprinter "z"))
	(set-buffer lwfbuf)
	(widen) 
	(erase-buffer)
	;;  replace spaces and -'s in name
	(insert name)
	(goto-char (point-min))
	(subst-char-in-region (point-min) (point-max) 32 ?_)
	(goto-char (point-min))
	(subst-char-in-region (point-min) (point-max) ?- ?_)
	(setq name (buffer-substring (point-min) (point-max)))
	(erase-buffer)

	(insert-buffer-substring oldbuf start end)
	(setq tab-width width)
	(if (/= tab-width 8)
	    (untabify (point-min) (point-max)))
	(setq start (point-min))
	(setq end (point-max))
	(goto-char (point-min))

	;;  process through lwf
	(if lwf-page 
	    ;;  pass a pagination parameter
	    (call-process-region start end 
				 lwf-prog
				 t                   ; delete region
				 lwfbuf              ; send output to
				 nil                 ; no redisplay
				 (concat "-h" name) 
				 lwf-size
				 lwf-indent
				 "-p")
	  ;;  don't pass a pagination parameter
	  (call-process-region start end 
			       lwf-prog
			       t                   ; delete region
			       lwfbuf              ; send output to
			       nil                 ; no redisplay
			       (concat "-h" name) 
			       lwf-size
			       lwf-indent)
	)

	;;  process through lpr
	(if (not (string= lwf-prog "showinp" ))
	(call-process-region (point-min) (point-max)
			     "lpr"
			     t                    ; delete region
			     lwfbuf               ; send output to
			     nil                  ; no redisplay
			     "-l"                 ; suppress burst page
			     (concat "-P" roffprinter)))
	)
      (message "Spooling...done")
      )
    )
  )

-----------------------------  cut here --------------------------
--
	Dion Hollenbeck             (619) 455-5590 x2814
	Megatek Corporation, 9645 Scranton Road, San Diego, CA  92121
        uunet!megatek!hollen       or  hollen@megatek.uucp