branch: externals/compat commit 8ea6272c3b09be5a3e0f860e7026bfe6c312e5ff Author: Philip Kaludercic <phil...@posteo.net> Commit: Philip Kaludercic <phil...@posteo.net>
Add define-error compatibility function --- compat-24.4.el | 20 ++++++++++++++++++++ compat-tests.el | 1 + 2 files changed, 21 insertions(+) diff --git a/compat-24.4.el b/compat-24.4.el index dcc61d2..9ee75d8 100644 --- a/compat-24.4.el +++ b/compat-24.4.el @@ -149,5 +149,25 @@ non-nil." (setcdr last nil))) list) +(compat-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 #'append + (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)))) + (provide 'compat-24.4) ;;; compat-24.4.el ends here diff --git a/compat-tests.el b/compat-tests.el index 6adeac6..bfa8005 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -29,6 +29,7 @@ ;; ;; - buffer-local-boundp (`buffer-local-boundp') ;; - count-windows (`compat--count-windows') +;; - define-error (`compat--define-error') ;; - directory-empty-p (`compat--directory-empty-p') ;; - directory-files (`compat--directory-files') ;; - dlet (`compat--dlet')