first push
This commit is contained in:
commit
58358f96c8
|
@ -0,0 +1,31 @@
|
|||
# with-user-abort
|
||||
### _ava fox_
|
||||
|
||||
provides a portable way to capture control-c in your lisp programs
|
||||
|
||||
## Exports
|
||||
|
||||
*Macro* `with-user-abort` &body body
|
||||
|
||||
executes BODY and captures a user-interrupt (control-c) and signals user-abort condition
|
||||
|
||||
*Condition* `user-abort`
|
||||
|
||||
a simple condition that inherits from your implementation's user-interrupt.
|
||||
|
||||
## Example
|
||||
|
||||
```lisp
|
||||
(handler-case
|
||||
(with-user-abort (long-running-call))
|
||||
(user-abort ()
|
||||
(print "Quitting gracefully")
|
||||
(uiop:quit 1)))
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
BSD 3-Clause
|
|
@ -0,0 +1,26 @@
|
|||
(in-package :cl-user)
|
||||
(defpackage with-user-abort
|
||||
(:use :cl)
|
||||
(:export :user-abort
|
||||
:with-user-abort))
|
||||
(in-package :with-user-abort)
|
||||
|
||||
(define-condition user-abort (#+sbcl sb-sys:interactive-interrupt
|
||||
#+ccl ccl:interrupt-signal-condition
|
||||
#+clisp system::simple-interrupt-condition
|
||||
#+ecl ext:interactive-interrupt
|
||||
#+allergo excl:interrupt-signal)
|
||||
())
|
||||
|
||||
(defmacro with-user-abort (&body body)
|
||||
"execute BODY, signalling user-abort if the interrupt signal is recieved"
|
||||
`(handler-bind ((#+sbcl sb-sys:interactive-interrupt
|
||||
#+ccl ccl:interrupt-signal-condition
|
||||
#+clisp system::simple-interrupt-condition
|
||||
#+ecl ext:interactive-interrupt
|
||||
#+allergo excl:interrupt-signal
|
||||
#'(lambda (c)
|
||||
(declare (ignore c))
|
||||
(signal 'user-abort))))
|
||||
,@body))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(asdf:defsystem #:with-user-abort
|
||||
:description "provides an easy way to catch ctrl+c. useful for making binaries."
|
||||
:author "ava fox"
|
||||
:license "BSD 3-Clause"
|
||||
:version "0.1"
|
||||
:components ((:file "package")))
|
Loading…
Reference in New Issue