--=-=-=
Content-Transfer-Encoding: quoted-printable
michael graffam <[EMAIL PROTECTED]> writes:
> I want to use *debugger-hook* to insulate my users
> from trouble.
>
> (invoke-restart (car (last (compute-restarts))))
> brings me back to the toplevel Lisp without complaint,
> but how can I restart the entire eval? On error, I'd
> like to simply inform the user that there is a
> problem, print the condition, clear the textbox, and
> allow the user to re-enter their code and continue.=20
Well I'm not familiar with LTK, but if you just want to disable
the debugger, I imagine you could do something like:
(prog (condition)
(let ((*debugger-hook* #'(lambda (c)
(setq condition c)
(go hooked))))
(return (eval (read-from-string (ltk:textbox my.textbox)))))
hooked
;; By this point, any dynamic bindings made by the form have
;; already been erased. If you change the code to print the
;; condition before unwinding, you should probably wrap the output
;; in a WITH-STANDARD-IO-SYNTAX form.
(print condition *error-output*)) ; or wherever
Alternatively, handle the condition so that Lisp won't have to
invoke the debugger:
(handler-case (eval (read-from-string (ltk:textbox my.textbox)))
;; Unlike IGNORE-ERRORS, this also handles e.g. STORAGE-CONDITION.
(serious-condition (condition)
(print condition *error-output*)))
This won't help if the user calls INVOKE-DEBUGGER directly, but
he can also call BREAK which ignores *DEBUGGER-HOOK*, so I guess
that isn't very important.
This handler assumes that SERIOUS-CONDITIONs are signalled with
ERROR and other CONDITIONs are signalled with SIGNAL. If someone
signals a plain CONDITION with ERROR, then the handler won't see
it and the Lisp may invoke the debugger. This should not be
fixed by making the handler handle all CONDITIONs, because then
it would also abort evaluation on the first WARN. Thus, if
you're only interested in disabling the debugger, I guess
*DEBUGGER-HOOK* is a better solution.
You could also define your own restart that COMPUTE-RESTARTS
would then see; this would be more flexible than HANDLER-CASE
but only if the user gets to choose the restart, which I assume
you're trying to avoid. Well, the user could then call the
restart programmatically as well; but I don't think that's the
kind of code one would want to type in an automatically cleared
text box.
--=-=-=
Content-Type: application/pgp-signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQBDvZ2aHm9IGt60eMgRAl5wAKDBSQ8sU0/w7o0wlycBwOOHMhDQFwCdGEX9
TTkOyLPiIkOoWQ63VjoMMLM=
=/fvp
-----END PGP SIGNATURE-----
--=-=-=--