sly icon indicating copy to clipboard operation
sly copied to clipboard

Pretty printer indentation issue

Open goose121 opened this issue 6 years ago • 2 comments

There appears to be some odd behaviour with the ~I format command in SLY; it appears that somehow the indentation doesn't get reset between calls or something, so indented text drifts rightward. Here's an example (taken from the original XP paper, page 16):

CL-USER> (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM MAIN MAPLE
       CENTER)
NIL
CL-USER> (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM
                     MAIN
                     MAPLE
                     CENTER)
NIL
CL-USER> (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM
                                   MAIN
                                   MAPLE
                                   CENTER)
NIL
CL-USER> (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM
                                                 MAIN
                                                 MAPLE
                                                 CENTER)
NIL

whereas in an sbcl REPL at the terminal, the same thing gives me

* (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM MAIN MAPLE
       CENTER)
NIL
* (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM MAIN MAPLE
       CENTER)
NIL
* (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM MAIN MAPLE
       CENTER)
NIL
* (let ((*print-right-margin* 25))
           (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center)))
(Roads ELM MAIN MAPLE
       CENTER)
NIL

goose121 avatar May 05 '19 04:05 goose121

Thanks for the detailed report. I'm kinda tied up right now, but I will get to these and other issues eventually, possibly in June/July. There was some other issue connected to the pretty printer and org mode that is connected to this one, I think, but I don't even have time to search for that.

joaotavora avatar May 05 '19 17:05 joaotavora

Hello, Not sure if this is fixed already, as I was able to test only on an older version 1.0.0-beta-3 (from portacle).

The problem seems to be that CL side doesn't see the newline that is printed before the next repl prompt (and values of the previous expression).

For example in sbcl:

* (loop repeat 4
        do (let ((*print-right-margin* 25))
             (format t "~:<Roads ~:I~@_~@{~W~^~8:T~:_~}~:>" '(elm main maple center))))
(Roads ELM MAIN MAPLE
       CENTER)(Roads ELM
                     MAIN
                     MAPLE
                     CENTER)(Roads ELM
                                   MAIN
                                   MAPLE
                                   CENTER)(Roads ELM
                                                 MAIN
                                                 MAPLE
                                                 CENTER)
NIL

The output is exactly concatenation of 4 outputs from above.

Also, a bit simpler test case might be something like this

(let ((*print-pretty* t)
      (*print-right-margin* 10))
  (format t "~A" '(1 2 3 4)))

In REPL:

; SLY 1.0.0-beta-3 (#<MREPL mrepl-1-1>)
CL-USER> (let ((*print-pretty* t)
               (*print-right-margin* 10))
           (format t "~A" '(1 2 3 4)))
(1 2 3 4)
NIL
CL-USER> (let ((*print-pretty* t)
               (*print-right-margin* 10))
           (format t "~A" '(1 2 3 4)))
(1
          2
          3
          4)
NIL

Gleefre avatar Sep 06 '23 09:09 Gleefre