1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-13 01:43:50 +03:00

Add define-error on 24.3

This commit is contained in:
Vasilij Schneidermann 2016-03-01 23:40:16 +01:00
parent fde9d804c2
commit a2f5087f02

View File

@ -77,6 +77,27 @@
;;; errors
(when (not (fboundp 'define-error))
(defun define-error (name message &optional parent)
"Define NAME as a new error signal.
MESSAGE is a string that will be output to the echo area if such an error
is signaled without being caught by a `condition-case'.
PARENT is either a signal or a list of signals from which it inherits.
Defaults to `error'."
(unless parent (setq parent 'error))
(let ((conditions
(if (consp parent)
(apply #'nconc
(mapcar (lambda (parent)
(cons parent
(or (get parent 'error-conditions)
(error "Unknown signal `%s'" parent))))
parent))
(cons parent (get parent 'error-conditions)))))
(put name 'error-conditions
(delete-dups (copy-sequence (cons name conditions))))
(when message (put name 'error-message message)))))
(define-error 'mal "MAL error")
(define-error 'unterminated-sequence "Unterminated token sequence" 'mal)
(define-error 'end-of-token-stream "End of token stream" 'mal)