[racket] Pretty printing and extra indentation

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Jan 6 15:56:35 EST 2014

I forget the details, but maybe try to call the default
pretty-print-print-line and add your own output there instead?

Robby



On Mon, Jan 6, 2014 at 2:45 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:

> Hi all,
>
> Does anyone know an easy way to add extra indentation to pretty printed
> output using racket/pretty?
>
> For example, suppose I want to add pretty printed output after part of
> an error message like:
>
>   expected: (<pretty printed value>
>              <should be aligned like this>)
>
> I would want any linebreak-separated portions to align with the first
> line with "expected:".
>
> So far, I've tried using the `pretty-print-print-line` parameter to add
> some extra indentation, but it doesn't work like I expect. For example:
>
>   #lang racket
>
>   ;; how much extra indentation to add
>   (define indent 2)
>
>   ;; to parameterize `pretty-print-print-line`
>   (define (print-line line-num out old-line-length cols)
>     (cond [(and line-num
>                 (not (= line-num 0))
>                 (not (eq? cols 'infinity)))
>            (newline out)
>            ;; these two lines differ from the default
>            (display (make-string indent #\space) out)
>            ;; changing this to `indent` has weird behavior
>            0]
>           [else 0]))
>
>   (parameterize ([pretty-print-print-line print-line])
>     (display "  ")
>     (pretty-display
>      '(λ (x y z)
>         (aaaaaaaa bbbbbbbbbbbbbb cccccccccccccc ddddddddd eeeeeeee
> ffffffff ggggggg hhhhhhh)))
>     (newline)
>     (display "  ")
>     (pretty-display
>      '(some-other-identifier (x y z)
>         (aaaaaaaa bbbbbbbbbbbbbb cccccccccccccc ddddddddd eeeeeeee
> ffffffff ggggggg hhhhhhh)))
>     (newline))
>
> The output I'd like to get is (indentation significant):
>
>   (lambda (x y z)
>     (aaaaaaaa
>      bbbbbbbbbbbbbb
>      cccccccccccccc
>      ddddddddd
>      eeeeeeee
>      ffffffff
>      ggggggg
>      hhhhhhh))
>   (some-other-identifier
>    (x y z)
>    (aaaaaaaa
>     bbbbbbbbbbbbbb
>     cccccccccccccc
>     ddddddddd
>     eeeeeeee
>     ffffffff
>     ggggggg
>     hhhhhhh))
>
> but I get:
>
>   (lambda (x y z)
>     (aaaaaaaa
>        bbbbbbbbbbbbbb
>        cccccccccccccc
>        ddddddddd
>        eeeeeeee
>        ffffffff
>        ggggggg
>        hhhhhhh))
>   (some-other-identifier
>    (x y z)
>    (aaaaaaaa
>       bbbbbbbbbbbbbb
>       cccccccccccccc
>       ddddddddd
>       eeeeeeee
>       ffffffff
>       ggggggg
>       hhhhhhh))
>
> Any idea what I'm doing wrong? There seems to be some extra indentation
> added to the output in the inner expression. Am I missing some obvious
> easy method to do this?
>
> Cheers,
> Asumu
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140106/0a534941/attachment.html>

Posted on the users mailing list.