summaryrefslogtreecommitdiff
path: root/tw/home
diff options
context:
space:
mode:
authorTimo Wilken2023-11-04 21:34:47 +0100
committerTimo Wilken2023-11-04 22:09:15 +0100
commit046beafb15037b52d33c8e32830ab53103005228 (patch)
tree34e70a83b42cf55ee6596c34f679f45cc74ab0a4 /tw/home
parentb6faa2b59ffe6a62abf43455ec88efe075b1df1c (diff)
Reduce nesting in `ppscm'
Diffstat (limited to 'tw/home')
-rwxr-xr-xtw/home/files/ppscm34
1 files changed, 16 insertions, 18 deletions
diff --git a/tw/home/files/ppscm b/tw/home/files/ppscm
index 326ebbb6..26edb39f 100755
--- a/tw/home/files/ppscm
+++ b/tw/home/files/ppscm
@@ -4,23 +4,21 @@
(ice-9 popen)
(ice-9 pretty-print))
-(define (main input-file)
- (call-with-input-file input-file
- (lambda (iport)
- (let ((highlighter (open-output-pipe "source-highlight -s scheme -f esc | $PAGER")))
- (with-exception-handler
- (lambda (exn)
- (close-pipe highlighter) ; make sure $PAGER doesn't mess up the terminal
- (raise-exception exn)) ; re-raise exception
- (lambda ()
- (let loop ((thing (read iport)))
- (cond
- ((eof-object? thing)
- (close-pipe highlighter))
- (#t
- (pretty-print thing highlighter)
- (newline highlighter)
- (loop (read iport)))))))))))
+(define (main input-port)
+ (define highlighter
+ (open-output-pipe "source-highlight -s scheme -f esc | $PAGER"))
+ (define (exn-handler exn)
+ (close-pipe highlighter) ; make sure $PAGER doesn't mess up the terminal
+ (raise-exception exn)) ; re-raise exception
+ (define (pretty-printer)
+ (match (read input-port)
+ ((? eof-object? _)
+ (close-pipe highlighter))
+ (thing
+ (pretty-print thing highlighter)
+ (newline highlighter) ; add empty line between top-level forms
+ (pretty-printer))))
+ (with-exception-handler exn-handler pretty-printer))
(define (help-message program-name)
(string-append "\
@@ -43,7 +41,7 @@ arguments:
(display (help-message program-name)))
((_ input-file)
- (main input-file))
+ (call-with-input-file input-file main))
((program-name . _)
(display "error: invalid number of arguments\n\n"