Skip to content

Commit

Permalink
Break fill newlines when previous section contains a break
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Jul 4, 2023
1 parent f5e389f commit 98a82fb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
26 changes: 22 additions & 4 deletions code/pretty-stream.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
(section-end :accessor section-end
:initarg :section-end
:initform nil
:type (or null newline block-end))))
:type (or null newline block-end))
(simplep :accessor simplep
:initarg :simplep
:initform nil
:type boolean)))

(defclass text (instruction)
((value :accessor value
Expand Down Expand Up @@ -75,7 +79,10 @@
(prin1 (width obj) stream)))

(defclass newline (section-start)
())
((break-before-p :accessor break-before-p
:initarg :break-before-P
:initform nil
:type boolean)))

(defclass fresh-newline (newline)
())
Expand Down Expand Up @@ -248,7 +255,7 @@
finally (terpri stream)
if (eq sub instruction)
do (write-char #\[ stream)
(setf ch #\-)
(setf ch (if (simplep instruction) #\- #\=))
else if (eq sub (section-end instruction))
do (write-char #\] stream)
(setf ch #\Space)
Expand Down Expand Up @@ -331,6 +338,10 @@
instruction (next instruction)))
(otherwise
(cond (last-maybe-break
(unless (or (eq t section)
(simplep section)
(null (section-end section)))
(setf (break-before-p (section-end section)) t))
(setf instruction last-maybe-break
(fill-pointer (fragments stream)) (fragment-index last-maybe-break)
section last-maybe-break
Expand Down Expand Up @@ -531,6 +542,8 @@
(not allow-break-p))
t)
((and (not mode)
(or (not (break-before-p instruction))
(not (section-end instruction)))
(not (miser-p stream instruction)))
:maybe-break)
(t
Expand Down Expand Up @@ -642,7 +655,12 @@
(eq s parent)
(and (typep s 'newline)
(> (depth s) depth)))
(setf (section-end s) newline)
(setf (section-end s) newline
(simplep s) (loop for i = (next s) then (next i)
finally (return t)
while (and i (not (eq i newline)))
when (typep i 'newline)
return nil))
t))
sections)
(section newline) (car (sections stream)))
Expand Down
1 change: 0 additions & 1 deletion code/shim/test/expected-failures/abcl.sexp
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
PPRINT-NEWLINE.FILL.7
PPRINT-LOGICAL-BLOCK.17 ; ABCL's circle detection has some limits
2 changes: 0 additions & 2 deletions code/shim/test/expected-failures/clasp.sexp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
:ALLOW-NIL-ARRAYS
:MAKE-CONDITION-WITH-COMPOUND-NAME
:NO-FLOATING-POINT-UNDERFLOW-BY-DEFAULT

PPRINT-NEWLINE.FILL.7
2 changes: 0 additions & 2 deletions code/shim/test/expected-failures/cmucl.sexp
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
:NIL-VECTORS-ARE-STRINGS

PPRINT-NEWLINE.FILL.7
1 change: 0 additions & 1 deletion code/shim/test/expected-failures/default.sexp
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
PPRINT-NEWLINE.FILL.7
2 changes: 0 additions & 2 deletions code/shim/test/expected-failures/ecl.sexp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
:ALLOW-NIL-ARRAYS
:MAKE-CONDITION-WITH-COMPOUND-NAME
:NO-FLOATING-POINT-UNDERFLOW-BY-DEFAULT

PPRINT-NEWLINE.FILL.7

0 comments on commit 98a82fb

Please sign in to comment.