aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2024-04-16 21:17:47 -0400
committerStefan Monnier2024-04-16 21:17:47 -0400
commit484b0979099d91e286c248e32b2f693111fac2ad (patch)
treee49d353db50f7e0b1aad43c0cce686e7dd0212db
parent2141caca30860ee04cad44ae2ad32744c1c11987 (diff)
downloademacs-484b0979099d91e286c248e32b2f693111fac2ad.tar.gz
emacs-484b0979099d91e286c248e32b2f693111fac2ad.zip
(cl-defstruct): Improve handling of unknown options
Until now `cl-defstruct` signaled an error when encountering an unknown option. It's easy to code and it does the job, but it doesn't give good location info in the compiler's output, and it makes it more painful to use not-yet-supported options. So just signal a warning instead. * lisp/emacs-lisp/cl-macs.el (cl-defstruct): Warn about unknown options, instead of signaling an error.
-rw-r--r--lisp/emacs-lisp/cl-macs.el7
1 files changed, 6 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 1350e474d6a..2e501005bf7 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -3010,6 +3010,7 @@ To see the documentation for a defined struct type, use
3010 ;; All the above is for the following def-form. 3010 ;; All the above is for the following def-form.
3011 &rest &or symbolp (symbolp &optional def-form &rest sexp)))) 3011 &rest &or symbolp (symbolp &optional def-form &rest sexp))))
3012 (let* ((name (if (consp struct) (car struct) struct)) 3012 (let* ((name (if (consp struct) (car struct) struct))
3013 (warning nil)
3013 (opts (cdr-safe struct)) 3014 (opts (cdr-safe struct))
3014 (slots nil) 3015 (slots nil)
3015 (defaults nil) 3016 (defaults nil)
@@ -3094,7 +3095,10 @@ To see the documentation for a defined struct type, use
3094 (setq descs (nconc (make-list (car args) '(cl-skip-slot)) 3095 (setq descs (nconc (make-list (car args) '(cl-skip-slot))
3095 descs))) 3096 descs)))
3096 (t 3097 (t
3097 (error "Structure option %s unrecognized" opt))))) 3098 (setq warning
3099 (macroexp-warn-and-return
3100 (format "Structure option %S unrecognized" opt)
3101 warning nil nil (list opt struct)))))))
3098 (unless (or include-name type 3102 (unless (or include-name type
3099 ;; Don't create a bogus parent to `cl-structure-object' 3103 ;; Don't create a bogus parent to `cl-structure-object'
3100 ;; while compiling the (cl-defstruct cl-structure-object ..) 3104 ;; while compiling the (cl-defstruct cl-structure-object ..)
@@ -3333,6 +3337,7 @@ To see the documentation for a defined struct type, use
3333 (cl-struct-define ',name ,docstring ',include-name 3337 (cl-struct-define ',name ,docstring ',include-name
3334 ',(or type 'record) ,(eq named t) ',descs 3338 ',(or type 'record) ,(eq named t) ',descs
3335 ',tag-symbol ',tag ',print-auto)) 3339 ',tag-symbol ',tag ',print-auto))
3340 ,warning
3336 ',name))) 3341 ',name)))
3337 3342
3338;;; Add cl-struct support to pcase 3343;;; Add cl-struct support to pcase