dev-srcloc
Matthew Butterick 8 years ago
parent 5e4ed4a89e
commit 5daa221ea4

@ -53,7 +53,7 @@
(check-equal? (next-line t 11) #f))
(define (valid-line? text line)
(<= 0 line (send text last-line)))
(and line (<= 0 line (send text last-line))))
(define (line-start text line)
(and (valid-line? text line)

@ -3,19 +3,28 @@
(provide indenter)
(define indent-width 2)
(define (indenter text start-pos)
(define (indenter text this-pos)
;; if line begins with }:
;; outdent to the matching {
;; indent to match the previous line
(define the-line (line text start-pos))
(define line-last-pos (line-end text the-line))
(define this-line (line text this-pos))
(define this-line-end (line-end text this-line))
(define open-braces
(- (count-char text #\{ 0 line-last-pos)
(count-char text #\} 0 line-last-pos)))
(define line-first-pos (line-start text the-line))
(define first-char (char text line-first-pos))
(- (count-char text #\{ 0 this-line-end)
(count-char text #\} 0 this-line-end)))
(and (positive? open-braces)
(* indent-width
(if (first-char . char=? . #\{)
(if ((char text (line-start text this-line)) . char=? . #\{)
(sub1 open-braces)
open-braces))))
#|
(define prev-line (previous-line text this-line))
(define prev-indent (line-indent text prev-line))
(cond
[((char text (line-start text this-line)) . char=? . #\})
(and prev-indent (- prev-indent indent-width))]
[((char text (line-start text prev-line)) . char=? . #\{)
(+ (or prev-indent 0) indent-width)]
[else prev-indent]))
|#
Loading…
Cancel
Save