From: Raymond Toy
Subject: The pretty-printer, *print-lines* and per-line prefixes
Date: 
Message-ID: <4n66zauxzw.fsf@rtp.ericsson.se>
Let's say I do something like

(let ((*print-lines* 2))
  (format t "~S" '(defun func (x) "Some long
multiline
description
of the function")))

(DEFUN FUNC (X)
    "Some long ..)

This is fine, but what I really want is a per-line prefix so that the
output is something like

; (DEFUN FUNC (X)
;    "Some long ..)

I tried various uses of "~<; ·@;~S~:>", but this seems to only print
out just one line:

(let ((*print-lines* 3))
  (format t "~<; ·@;~S~:>" '(defun func (x) "Some long
multiline
description
of the function")))

produces 

; DEFUN

Is this possible using format or will I have to dig deeper into the
pretty printer?

Thanks,

Ray

From: Pierpaolo Bernardi
Subject: Re: The pretty-printer, *print-lines* and per-line prefixes
Date: 
Message-ID: <942422315.186729@fire-int>
Raymond Toy (···@rtp.ericsson.se) wrote:

...
: This is fine, but what I really want is a per-line prefix so that the
: output is something like

: ; (DEFUN FUNC (X)
: ;    "Some long ..)
...
: Is this possible using format or will I have to dig deeper into the
: pretty printer?


PPRINT-LOGICAL-BLOCK can do what you want:

(pprint-logical-block (*terminal-io* nil :per-line-prefix "with R's prefix: ")
  (format *terminal-io* "~S" '(defun func (x) "Some long
multiline
description
of the function")))

with R's prefix: (DEFUN FUNC (X)
with R's prefix:   "Some long
with R's prefix: multiline
with R's prefix: description
with R's prefix: of the function")
NIL

P.
From: Pekka P. Pirinen
Subject: Re: The pretty-printer, *print-lines* and per-line prefixes
Date: 
Message-ID: <ixogcza7kk.fsf@gaspode.cam.harlequin.co.uk>
Raymond Toy <···@rtp.ericsson.se> writes:
> what I really want is a per-line prefix [...]
> I tried various uses of "~<; ·@;~S~:>", but this seems to only print
> out just one line:
> 
> (let ((*print-lines* 3))
>   (format t "~<; ·@;~S~:>" '(defun func (x) "Some long
> multiline
> description
> of the function")))
> 
> produces 
> 
> ; DEFUN

The format arguments for the body section of ~<...~:> are the
_elements_ of the list that is the argument of the whole ~<...~:>.  So
you were only consuming the first element, DEFUN.

I'm not sure what you're trying to do here, but you could try
something like:

CL-USER 26> (let ((*print-lines* 3))
  (format t "~<; ·@;~S~:>" (list '(defun func (x) "Some long
multiline
description
of the function"))))
; (defun func (x) "Some long
; multiline
; description ..
nil
-- 
Pekka P. Pirinen   Adaptive Memory Management Group, Harlequin Limited
    I have yet to see any problem, however complicated, which,
when you looked at it in the right way, did not become still
more complicated.	- Poul Anderson
From: Raymond Toy
Subject: Re: The pretty-printer, *print-lines* and per-line prefixes
Date: 
Message-ID: <4nemdr1w9g.fsf@rtp.ericsson.se>
>>>>> "Pekka" == Pekka P Pirinen <·····@harlequin.co.uk> writes:

    Pekka> The format arguments for the body section of ~<...~:> are the
    Pekka> _elements_ of the list that is the argument of the whole ~<...~:>.  So
    Pekka> you were only consuming the first element, DEFUN.

Sorry!  My fault!

    Pekka> I'm not sure what you're trying to do here, but you could try
    Pekka> something like:

Actually, I was trying to make my copy of CMUCL print ";" for all
messages from the compiler.  Why?  I run CMUCL inside XEmacs via ilisp
with font-locking on, so defun's with long descriptions don't get a
terminating closing quote, which confuses XEmacs font-locking.

Besides, I like the way Allegro and Lispworks (?) always puts ; before
compiler output.


Your solution and Pierpaolo Benardi's solution both work for me,
except for an apparent minor bug in CMUCL's pretty printer:

(let ((*print-lines* 3))
  (format t "~<; ·@;~S~:>" (list '(defun func (x) "Some long
multiline
description
of the function"))))

results in 

; (defun func (x) "Some long
  ; multiline
  ; description ..

Thanks!

Ray
From: Pekka P. Pirinen
Subject: Re: The pretty-printer, *print-lines* and per-line prefixes
Date: 
Message-ID: <ixn1sja7kf.fsf@gaspode.cam.harlequin.co.uk>
Raymond Toy <···@rtp.ericsson.se> writes:
> what I really want is a per-line prefix [...]
> I tried various uses of "~<; ·@;~S~:>", but this seems to only print
> out just one line:
> 
> (let ((*print-lines* 3))
>   (format t "~<; ·@;~S~:>" '(defun func (x) "Some long
> multiline
> description
> of the function")))
> 
> produces 
> 
> ; DEFUN

The format arguments for the body section of ~<...~:> are the
_elements_ of the list that is the argument of the whole ~<...~:>.  So
you were only consuming the first element, DEFUN.

I'm not sure what you're trying to do here, but you could try
something like:

CL-USER 26> (let ((*print-lines* 3))
  (format t "~<; ·@;~S~:>" (list '(defun func (x) "Some long
multiline
description
of the function"))))
; (defun func (x) "Some long
; multiline
; description ..
nil
-- 
Pekka P. Pirinen   Adaptive Memory Management Group, Harlequin Limited
    I have yet to see any problem, however complicated, which,
when you looked at it in the right way, did not become still
more complicated.	- Poul Anderson