From: Taylor R Campbell Date: Sun, 10 Feb 2019 22:40:10 +0000 (+0000) Subject: Convert multi-LETREC to internal definitions in edwin/undo.scm. X-Git-Tag: mit-scheme-pucked-10.1.10~6^2~7^2 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=4a1d2dcb544c444cb98ce65ff7b67a46e1d78ded;p=mit-scheme.git Convert multi-LETREC to internal definitions in edwin/undo.scm. --- diff --git a/src/edwin/undo.scm b/src/edwin/undo.scm index 68655a8d3..2811220a6 100644 --- a/src/edwin/undo.scm +++ b/src/edwin/undo.scm @@ -195,34 +195,31 @@ which includes both the saved text and other data." (add-event-receiver! event:after-restore truncate-buffer-undo-lists!) (define (truncate-undo-data! items min-size max-size) + (define (loop items prev size boundary) + (if (and boundary (fix:> size max-size)) + ;; If we've exceeded MAX-SIZE, truncate at the + ;; previous boundary. + (set-cdr! boundary '()) + (if (pair? items) + (if (eq? #f (car items)) + ;; If this is the first boundary, continue + ;; regardless of size, otherwise continue + ;; only if we haven't yet reached MIN-SIZE. + (if (and boundary (fix:> size min-size)) + (set-cdr! prev '()) + (continue items size prev)) + (continue items size boundary))))) + (define (continue items size boundary) + (loop (cdr items) + items + (fix:+ size (undo-item-size (car items))) + boundary)) (if (pair? items) - (letrec - ((loop - (lambda (items prev size boundary) - (if (and boundary (fix:> size max-size)) - ;; If we've exceeded MAX-SIZE, truncate at the - ;; previous boundary. - (set-cdr! boundary '()) - (if (pair? items) - (if (eq? #f (car items)) - ;; If this is the first boundary, continue - ;; regardless of size, otherwise continue - ;; only if we haven't yet reached MIN-SIZE. - (if (and boundary (fix:> size min-size)) - (set-cdr! prev '()) - (continue items size prev)) - (continue items size boundary)))))) - (continue - (lambda (items size boundary) - (loop (cdr items) - items - (fix:+ size (undo-item-size (car items))) - boundary)))) - (if (eq? #f (car items)) - ;; If list starts with a boundary, skip over it. We want - ;; to include the first undo operation in the result. - (continue items 0 #f) - (loop items #f 0 #f))))) + (if (eq? #f (car items)) + ;; If list starts with a boundary, skip over it. We want + ;; to include the first undo operation in the result. + (continue items 0 #f) + (loop items #f 0 #f)))) (define (undo-item-size item) (if (pair? item)