Commits

evhan committed 7854a81

Queue indentation levels for special-case keywords (such as "do")

  • Participants
  • Parent commits 064ab3f

Comments (0)

Files changed (1)

File schematic-format.scm

 ;;;
 ;;; Still TODO:
 ;;;
-;;;   * `do`'s third subexpression (should indent by one, not three).
 ;;;   * `=>` in `cond` forms (should not set a new indentation level).
+;;;   * User-defined indentation rules.
 ;;;
 ;;; See this project's README for more information.
 ;;;
 ;;
 (define (keyword-indentation-offset sym eol?)
   (case sym
-    ((begin cond do) (and eol? 1))
+    ((begin cond) (and eol? 1))
     ((call-with-port) 0)
     ((case) 1)
     ((cond-expand) 1)
     ((define-library) 1)
     ((define-record-type) 1)
     ((define-syntax syntax-rules) 1)
+    ((do) '(0 3 1))
     ((guard) 1)
     ((lambda case-lambda) 1)
     ((let let*) 1)
        (let ((line (read-line input)))
          (unless (eof-object? line)
            (let ((form (car forms)))
-             (let-values (((indent line)
+             (let-values (((line indent)
                            (if (symbol? form)
-                               (values 0 line)
-                               (values form (string-trim line)))))
+                               (values line 0)
+                               (values (string-trim line)
+                                       (if (number? form)
+                                           form
+                                           (car form))))))
                (unless (zero? indent)
                  (display (make-string indent #\space) output))
                (display line output)
                            ((#\)) (scan (cdr f) (+ i 1)))
                            ((#\() (let* ((i (+ i 1))
                                          (a (guard/value #f (string-read line i)))
-                                         (k (string-nth-read-index line 1 i)))
+                                         (k (string-nth-read-index line 1 i))
+                                         (f (cond ((number? (car f)) f)        ; No queue.
+                                                  ((null? (cdar f)) f)         ; Exhausted.
+                                                  ((cons (cdar f) (cdr f)))))) ; Shift.
                                     (cond
                                       ((constant? a)
                                        (scan (cons (+ i indent) f) i))
                                       ((keyword-indentation-offset a (not k))
-                                       => (lambda (n)
-                                            (scan (cons (+ i n indent) f)
+                                       => (lambda (offset)
+                                            (scan (if (number? offset)
+                                                      (cons (+ i offset indent) f)
+                                                      (cons (map (lambda (o) (+ i o indent)) offset) f))
                                                   (or k len))))
                                       ((not k)
                                        (scan (cons (+ i indent) f) i))
                                       (else
-                                       (scan (cons (+ k indent) f)
-                                             (or k len))))))
+                                       (scan (cons (+ k indent) f) k)))))
                            ((#\#) (case (string-ref line (+ i 1) #f)
                                     ((#\|) (scan (cons 'comment f) (+ i 2)))
                                     ((#\;) (scan f (+ i 2)))