(module checkpoint mzscheme
(require (lib "class.ss")
(lib "struct.ss")
(lib "list.ss")
(lib "mred.ss" "mred"))
(provide (struct checkpoint (name position))
make-checkpoints)
(define *proof-tree-start* "\n<< Starting proof tree logging >>\n")
(define-struct/properties checkpoint (name position)
([prop:custom-write (lambda (x port write?)
(fprintf port "#checkpoint(~a ~a)"
(checkpoint-name x)
(checkpoint-position x)))]))
(define (find-position-of-goal goal-name editor)
(let loop ([start (send editor find-string
*proof-tree-start* 'backward (send editor last-position) 'eof)])
(if start
(send editor find-string goal-name 'forward start 'eof)
(begin (yield)
(let ([last-posn (send editor last-position)])
(loop (send editor find-string
*proof-tree-start*
'backward last-posn 'eof))))
)))
(define (make-checkpoints goal-names editor)
(let ([answer
(reverse (foldl (lambda (goal checkpoints)
(cond [(find-position-of-goal goal editor)
=> (lambda (posn)
(cons (make-checkpoint goal posn)
checkpoints))]
[else checkpoints]))
'()
goal-names))])
answer))
)