joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.26k stars 142 forks source link

Pretty printer indentation issue #228

Open goose121 opened 5 years ago

goose121 commented 5 years ago

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
joaotavora commented 5 years ago

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.

Gleefre commented 1 year ago

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