+ Factor out exit hooks into a separate package.
+ Let exit call the exit hooks.
This commit is contained in:
parent
949b6df8df
commit
8b451fe673
|
@ -595,6 +595,10 @@
|
||||||
scsh-version-string
|
scsh-version-string
|
||||||
scsh-release-name))
|
scsh-release-name))
|
||||||
|
|
||||||
|
(define-interface exit-hooks-interface
|
||||||
|
(export call-exit-hooks-and-narrow
|
||||||
|
add-narrowed-exit-hook!
|
||||||
|
add-exit-hook!))
|
||||||
|
|
||||||
;;; This is probably bogus.
|
;;; This is probably bogus.
|
||||||
(define-interface string-ports-interface
|
(define-interface string-ports-interface
|
||||||
|
|
|
@ -241,6 +241,7 @@
|
||||||
features
|
features
|
||||||
general-tables
|
general-tables
|
||||||
simple-syntax
|
simple-syntax
|
||||||
|
exit-hooks
|
||||||
|
|
||||||
scsh-errors
|
scsh-errors
|
||||||
scsh-endian)
|
scsh-endian)
|
||||||
|
@ -335,8 +336,6 @@
|
||||||
|
|
||||||
(define-structure scsh-top-package (export parse-switches-and-execute
|
(define-structure scsh-top-package (export parse-switches-and-execute
|
||||||
with-scsh-initialized
|
with-scsh-initialized
|
||||||
add-exit-hook!
|
|
||||||
add-narrowed-exit-hook!
|
|
||||||
repl)
|
repl)
|
||||||
(open command-processor
|
(open command-processor
|
||||||
command-levels ; with-new-session
|
command-levels ; with-new-session
|
||||||
|
@ -370,9 +369,33 @@
|
||||||
char-set-contains?
|
char-set-contains?
|
||||||
string->char-set))
|
string->char-set))
|
||||||
root-scheduler ; scheme-exit-now
|
root-scheduler ; scheme-exit-now
|
||||||
|
exit-hooks
|
||||||
scheme)
|
scheme)
|
||||||
(files top meta-arg))
|
(files top meta-arg))
|
||||||
|
|
||||||
|
(define-structure exit-hooks exit-hooks-interface
|
||||||
|
(open scheme
|
||||||
|
threads)
|
||||||
|
(begin
|
||||||
|
(define *exit-hooks* '())
|
||||||
|
(define (add-exit-hook! thunk)
|
||||||
|
(set! *exit-hooks* (cons thunk *exit-hooks*)))
|
||||||
|
(define (call-exit-hooks!)
|
||||||
|
(for-each (lambda (thunk) (thunk)) *exit-hooks*))
|
||||||
|
|
||||||
|
(define *narrowed-exit-hooks* '())
|
||||||
|
(define (add-narrowed-exit-hook! thunk)
|
||||||
|
(set! *narrowed-exit-hooks* (cons thunk *narrowed-exit-hooks*)))
|
||||||
|
(define (call-narrowed-exit-hooks!)
|
||||||
|
(for-each (lambda (thunk) (thunk)) *narrowed-exit-hooks*))
|
||||||
|
|
||||||
|
(define (call-exit-hooks-and-narrow thunk)
|
||||||
|
(call-exit-hooks!)
|
||||||
|
(narrow
|
||||||
|
(lambda ()
|
||||||
|
(call-narrowed-exit-hooks!)
|
||||||
|
(thunk))))))
|
||||||
|
|
||||||
|
|
||||||
(define-structure field-reader-package scsh-field-reader-interface
|
(define-structure field-reader-package scsh-field-reader-interface
|
||||||
(open receiving ; receive
|
(open receiving ; receive
|
||||||
|
|
|
@ -1135,10 +1135,11 @@
|
||||||
proc))
|
proc))
|
||||||
|
|
||||||
(define (exit . maybe-status)
|
(define (exit . maybe-status)
|
||||||
(flush-all-ports)
|
(call-exit-hooks-and-narrow
|
||||||
|
(lambda ()
|
||||||
(exit/errno (:optional maybe-status 0))
|
(exit/errno (:optional maybe-status 0))
|
||||||
(display "The evil undead walk the earth." 2)
|
(display "The evil undead walk the earth." 2)
|
||||||
(if #t (error "(exit) returned.")))
|
(if #t (error "(exit) returned.")))))
|
||||||
|
|
||||||
|
|
||||||
;;; The classic T 2.0 primitive.
|
;;; The classic T 2.0 primitive.
|
||||||
|
|
22
scsh/top.scm
22
scsh/top.scm
|
@ -327,9 +327,7 @@
|
||||||
(lambda (c m)
|
(lambda (c m)
|
||||||
(scheme-exit-now 1))
|
(scheme-exit-now 1))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(call-exit-hooks)
|
(call-exit-hooks-and-narrow (lambda () #t))
|
||||||
(narrow (lambda ()
|
|
||||||
(call-narrowed-exit-hooks)))
|
|
||||||
(more)))))
|
(more)))))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(with-scsh-initialized
|
(with-scsh-initialized
|
||||||
|
@ -352,7 +350,7 @@
|
||||||
(interaction-environment)))
|
(interaction-environment)))
|
||||||
|
|
||||||
(cond ((not term-switch) ; -- interactive
|
(cond ((not term-switch) ; -- interactive
|
||||||
(scsh-exit-now
|
(scsh-exit-now ;; TODO: ,exit will bypass this
|
||||||
(restart-command-processor
|
(restart-command-processor
|
||||||
args
|
args
|
||||||
context
|
context
|
||||||
|
@ -389,23 +387,9 @@
|
||||||
(if (eof-object? (read)) val
|
(if (eof-object? (read)) val
|
||||||
(error "More than one value read from string" s)))))
|
(error "More than one value read from string" s)))))
|
||||||
|
|
||||||
(define *exit-hooks* '())
|
|
||||||
(define (add-exit-hook! thunk)
|
|
||||||
(set! *exit-hooks* (cons thunk *exit-hooks*)))
|
|
||||||
(define (call-exit-hooks)
|
|
||||||
(for-each (lambda (thunk) (thunk)) *exit-hooks*))
|
|
||||||
|
|
||||||
(define *narrowed-exit-hooks* '())
|
|
||||||
(define (add-narrowed-exit-hook! thunk)
|
|
||||||
(set! *narrowed-exit-hooks* (cons thunk *narrowed-exit-hooks*)))
|
|
||||||
(define (call-narrowed-exit-hooks)
|
|
||||||
(for-each (lambda (thunk) (thunk)) *narrowed-exit-hooks*))
|
|
||||||
|
|
||||||
(define (scsh-exit-now status)
|
(define (scsh-exit-now status)
|
||||||
(call-exit-hooks)
|
(call-exit-hooks-and-narrow
|
||||||
(narrow
|
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(call-narrowed-exit-hooks)
|
|
||||||
(scheme-exit-now status))))
|
(scheme-exit-now status))))
|
||||||
|
|
||||||
(add-narrowed-exit-hook! flush-all-ports-no-threads)
|
(add-narrowed-exit-hook! flush-all-ports-no-threads)
|
||||||
|
|
Loading…
Reference in New Issue