diff options
author | Daniel Colascione <dancol@dancol.org> | 2025-03-07 21:47:56 -0800 |
---|---|---|
committer | Daniel Colascione <dancol@dancol.org> | 2025-03-07 22:22:30 -0800 |
commit | 0972a54a5ac52f731c0ea7c8538c8f3b7b6b36b4 (patch) | |
tree | 189479d5628caa179b4889e8b9a45211fc4b0357 /lisp/subr.el | |
parent | 1c313f8dce0ac9e0520f885420cd696703736baf (diff) | |
download | emacs-0972a54a5ac52f731c0ea7c8538c8f3b7b6b36b4.tar.gz emacs-0972a54a5ac52f731c0ea7c8538c8f3b7b6b36b4.tar.bz2 emacs-0972a54a5ac52f731c0ea7c8538c8f3b7b6b36b4.zip |
Add static-when, static-unless like static-if
* lisp/subr.el (static-when, static-unless): define
* doc/lispref/control.texi (Conditional Compilation): document
* etc/NEWS: mention
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 8f0366824d9..110bebed789 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -301,6 +301,19 @@ value of last one, or nil if there are none." (macroexp-warn-and-return (format-message "`when' with empty body") (list 'progn cond nil) '(empty-body when) t))) +(defmacro static-when (condition &rest body) + "A conditional compilation macro. +Evaluate CONDITION at macro-expansion time. If it is non-nil, +expand the macro to evaluate all BODY forms sequentially and return +the value of the last one, or nil if there are none." + (declare (indent 1) (debug t)) + (if body + (if (eval condition lexical-binding) + (cons 'progn body) + nil) + (macroexp-warn-and-return (format-message "`static-when' with empty body") + (list 'progn nil nil) '(empty-body static-when) t))) + (defmacro unless (cond &rest body) "If COND yields nil, do BODY, else return nil. When COND yields nil, eval BODY forms sequentially and return @@ -311,6 +324,19 @@ value of last one, or nil if there are none." (macroexp-warn-and-return (format-message "`unless' with empty body") (list 'progn cond nil) '(empty-body unless) t))) +(defmacro static-unless (condition &rest body) + "A conditional compilation macro. +Evaluate CONDITION at macro-expansion time. If it is nil, +expand the macro to evaluate all BODY forms sequentially and return +the value of the last one, or nil if there are none." + (declare (indent 1) (debug t)) + (if body + (if (eval condition lexical-binding) + nil + (cons 'progn body)) + (macroexp-warn-and-return (format-message "`static-unless' with empty body") + (list 'progn nil nil) '(empty-body static-unless) t))) + (defsubst subr-primitive-p (object) "Return t if OBJECT is a built-in primitive written in C. Such objects can be functions or special forms." |