|
|
|
@ -8,22 +8,20 @@
|
|
|
|
|
(define (indent-jsonic tbox [posn 0])
|
|
|
|
|
(define prev-line (previous-line tbox posn))
|
|
|
|
|
(define current-line (line tbox posn))
|
|
|
|
|
(define prev-indent (or (line-indent tbox prev-line) 0))
|
|
|
|
|
(define current-indent
|
|
|
|
|
(cond
|
|
|
|
|
[(left-bracket?
|
|
|
|
|
(line-first-visible-char tbox prev-line))
|
|
|
|
|
(+ prev-indent indent-width)]
|
|
|
|
|
[(right-bracket?
|
|
|
|
|
(line-first-visible-char tbox current-line))
|
|
|
|
|
(- prev-indent indent-width)]
|
|
|
|
|
[else prev-indent]))
|
|
|
|
|
(and (exact-positive-integer? current-indent) current-indent))
|
|
|
|
|
(define prev-indent (line-indent tbox prev-line))
|
|
|
|
|
(cond
|
|
|
|
|
[(left-bracket?
|
|
|
|
|
(line-first-visible-char tbox prev-line))
|
|
|
|
|
(+ prev-indent indent-width)]
|
|
|
|
|
[(right-bracket?
|
|
|
|
|
(line-first-visible-char tbox current-line))
|
|
|
|
|
(- prev-indent indent-width)]
|
|
|
|
|
[else prev-indent]))
|
|
|
|
|
(provide
|
|
|
|
|
(contract-out
|
|
|
|
|
[indent-jsonic (((is-a?/c text%))
|
|
|
|
|
(exact-nonnegative-integer?) . ->* .
|
|
|
|
|
(or/c exact-nonnegative-integer? #f))]))
|
|
|
|
|
exact-nonnegative-integer?)]))
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
|
(require rackunit)
|
|
|
|
@ -44,5 +42,4 @@ HERE
|
|
|
|
|
)
|
|
|
|
|
(check-equal?
|
|
|
|
|
(string-indents (apply-indenter indent-jsonic test-str))
|
|
|
|
|
'(#f #f 2 2 2 4 6 6 4 2 2 #f)))
|
|
|
|
|
|
|
|
|
|
'(0 0 2 2 2 4 6 6 4 2 2 0)))
|