|
391 | 391 | (define (format-reader-vector-multiline datum indent) |
392 | 392 | (let* ((prefix (reader-vector-prefix datum)) |
393 | 393 | (item-indent (+ indent (string-length prefix))) |
| 394 | + (close-marker (string-append "\n" (spaces indent) ") ;#")) |
394 | 395 | ) ; |
395 | 396 | (let loop |
396 | 397 | ((items (reader-vector->list datum)) (pieces (list prefix)) (prefix-ready? #t)) |
397 | 398 | (if (null? items) |
398 | | - (apply string-append (reverse (cons ")" pieces))) |
| 399 | + (apply string-append (reverse (cons close-marker pieces))) |
399 | 400 | (let ((item (car items))) |
400 | 401 | (if (newline-marker-datum? item) |
401 | 402 | (loop (cdr items) |
402 | 403 | (cons (spaces item-indent) (cons (reader-newlines (cadr item)) pieces)) |
403 | 404 | #t |
404 | 405 | ) ;loop |
405 | | - (loop (cdr items) |
406 | | - (cons (format-reader-datum-at item item-indent) |
407 | | - (if prefix-ready? |
408 | | - pieces |
409 | | - (cons (string-append "\n" (spaces item-indent)) pieces) |
410 | | - ) ;if |
411 | | - ) ;cons |
412 | | - #f |
413 | | - ) ;loop |
| 406 | + (let ((item-text (string-trim (format-reader-datum-at item item-indent)))) |
| 407 | + (loop (cdr items) |
| 408 | + (cons item-text |
| 409 | + (if prefix-ready? |
| 410 | + pieces |
| 411 | + (cons (string-append "\n" (spaces item-indent)) pieces) |
| 412 | + ) ;if |
| 413 | + ) ;cons |
| 414 | + #f |
| 415 | + ) ;loop |
| 416 | + ) ;let |
414 | 417 | ) ;if |
415 | 418 | ) ;let |
416 | 419 | ) ;if |
|
462 | 465 | ) ;let |
463 | 466 | ) ;define |
464 | 467 |
|
465 | | - (define (reader-append-rest current result rest-indent prefix-ready?) |
| 468 | + (define (last-line-column text) |
| 469 | + (let loop |
| 470 | + ((i 0) (column 0)) |
| 471 | + (if (>= i (string-length text)) |
| 472 | + column |
| 473 | + (loop (+ i 1) |
| 474 | + (if (char=? (string-ref text i) #\newline) 0 (+ column 1)) |
| 475 | + ) ;loop |
| 476 | + ) ;if |
| 477 | + ) ;let |
| 478 | + ) ;define |
| 479 | + |
| 480 | + (define (reader-append-close result close-indent) |
| 481 | + (if (string-suffix? ";#" result) |
| 482 | + (string-append result "\n" (spaces close-indent) ")") |
| 483 | + (string-append result ")") |
| 484 | + ) ;if |
| 485 | + ) ;define |
| 486 | + |
| 487 | + (define (reader-append-rest current result rest-indent prefix-ready? close-indent) |
466 | 488 | (cond ((pair? current) |
467 | 489 | (let ((item (car current))) |
468 | 490 | (if (newline-marker-datum? item) |
469 | 491 | (reader-append-rest (cdr current) |
470 | 492 | (string-append result (reader-newlines (cadr item)) (spaces rest-indent)) |
471 | 493 | rest-indent |
472 | 494 | #t |
| 495 | + close-indent |
473 | 496 | ) ;reader-append-rest |
474 | 497 | (reader-append-rest (cdr current) |
475 | 498 | (string-append result |
476 | 499 | (if prefix-ready? "" (string-append "\n" (spaces rest-indent))) |
477 | | - (format-reader-datum-at item rest-indent) |
| 500 | + (format-reader-datum-at item |
| 501 | + (if prefix-ready? (last-line-column result) rest-indent) |
| 502 | + ) ;format-reader-datum-at |
478 | 503 | ) ;string-append |
479 | 504 | rest-indent |
480 | 505 | #f |
| 506 | + close-indent |
481 | 507 | ) ;reader-append-rest |
482 | 508 | ) ;if |
483 | 509 | ) ;let |
484 | 510 | ) ; |
485 | | - ((null? current) (string-append result ")")) |
486 | | - (else (string-append result |
487 | | - (if prefix-ready? "" (string-append "\n" (spaces rest-indent))) |
488 | | - ". " |
489 | | - (format-reader-datum-at current (+ rest-indent 2)) |
490 | | - ")" |
491 | | - ) ;string-append |
| 511 | + ((null? current) (reader-append-close result close-indent)) |
| 512 | + (else (reader-append-close |
| 513 | + (let* ((prefix (if prefix-ready? "" (string-append "\n" (spaces rest-indent))) |
| 514 | + ) ;prefix |
| 515 | + (before-tail (string-append result prefix ". ")) |
| 516 | + ) ; |
| 517 | + (string-append before-tail |
| 518 | + (format-reader-datum-at current (last-line-column before-tail)) |
| 519 | + ) ;string-append |
| 520 | + ) ;let* |
| 521 | + close-indent |
| 522 | + ) ;reader-append-close |
492 | 523 | ) ;else |
493 | 524 | ) ;cond |
494 | 525 | ) ;define |
|
520 | 551 | ) ;if |
521 | 552 | ) ;body-indent |
522 | 553 | ) ; |
523 | | - (reader-append-rest after-selected with-selected body-indent #f) |
| 554 | + (reader-append-rest after-selected with-selected body-indent #f indent) |
524 | 555 | ) ;let* |
525 | 556 | ) ;if |
526 | 557 | ) ;define |
|
0 commit comments