Commits

evhan committed 6734149

Shift from indent queue on any datum, not just open parenthesis

Comments (0)

Files changed (1)

src/schematic/format.scm

     ((with-output-to-file call-with-output-file) 0)
     (else #f)))
 
+;; Keywords may push a queue of indentation offsets onto the form
+;; stack, which is repeatedly shifted to obtain the next indent level
+;; (until it's exhausted, at which point the final value of the queue
+;; applies as usual).
+(define (shift-indent forms)
+  (cond ((number? (car forms)) forms)       ; No queue.
+        ((null? (cdar forms)) forms)        ; Exhausted.
+        ((cons (cdar forms) (cdr forms))))) ; Shift.
+
 ;; Reformat the Scheme code on `input` into `output`.
 (define format-scheme
   (case-lambda
                            ((#\() (let* ((i (+ i 1))
                                          (a (guard/value #f (string-read line i len)))
                                          (k (string-nth-read-index line 1 i len))
-                                         (f (cond ((number? (car f)) f)        ; No queue.
-                                                  ((null? (cdar f)) f)         ; Exhausted.
-                                                  ((cons (cdar f) (cdr f)))))) ; Shift.
+                                         (f (shift-indent f)))
                                     (cond
                                       ((constant? a)
                                        (scan (cons (+ i indent) f) i))
                                        (scan (cons (+ k indent) f) k)))))
                            ((#\#) (case (string-ref line (+ i 1) #f)
                                     ((#\|) (scan (cons 'comment f) (+ i 2)))
-                                    ((#\;) (scan f (+ i 2)))
-                                    (else  (scan f (or (string-nth-read-index line 1 i len)
-                                                       (+ i 1))))))
-                           (else  (scan f (or (string-nth-read-index line 1 i len)
-                                              (+ i 1)))))))))))))))))))
+                                    ((#\;) (scan (shift-indent f) (+ i 2)))
+                                    (else  (scan (shift-indent f)
+                                                 (or (string-nth-read-index line 1 i len)
+                                                     (+ i 1))))))
+                           (else  (scan (shift-indent f)
+                                        (or (string-nth-read-index line 1 i len)
+                                            (+ i 1)))))))))))))))))))