[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 97652d0e7a5: New conditional compilation macro static-if.
From: |
Alan Mackenzie |
Subject: |
master 97652d0e7a5: New conditional compilation macro static-if. |
Date: |
Sun, 3 Sep 2023 08:56:41 -0400 (EDT) |
branch: master
commit 97652d0e7a53281297010e9f43ec9b5aa7623dc5
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>
New conditional compilation macro static-if.
* etc/NEWS: Record the new macro.
* lisp/subr.el (static-if): New macro.
---
etc/NEWS | 8 +++++++-
lisp/subr.el | 15 +++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 15cc6cc47e0..bbf4b67fe34 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -55,7 +55,7 @@ the signature) the automatically inferred function type as
well.
---
** New user option 'describe-bindings-outline-rules'.
This user option controls outline visibility in the output buffer of
-'describe-bindings' when 'describe-bindings-outline' in non-nil.
+'describe-bindings' when 'describe-bindings-outline' is non-nil.
** X selection requests are now handled much faster and asynchronously.
This means it should be less necessary to disable the likes of
@@ -861,6 +861,12 @@ Use 'define-minor-mode' and 'define-globalized-minor-mode'
instead.
See the "(elisp) Porting Old Advice" node for help converting them
to use 'advice-add' or 'define-advice' instead.
++++
+** New macro 'static-if' for conditional compilation of code.
+This macro hides a form from the compiler based on a compile-time
+condition. This is handy for avoiding byte-compilation warnings about
+code that will never actually run under some conditions.
+
+++
** Desktop notifications are now supported on the Haiku operating system.
The new function 'haiku-notifications-notify' provides a subset of the
diff --git a/lisp/subr.el b/lisp/subr.el
index 0894a644d28..34d87e83310 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -277,6 +277,21 @@ change the list."
(macroexp-let2 macroexp-copyable-p x getter
`(prog1 ,x ,(funcall setter `(cdr ,x))))))))
+;; Note: `static-if' can be copied into a package to enable it to be
+;; used in Emacsen older than Emacs 30.1. If the package is used in
+;; very old Emacsen or XEmacs (in which `eval' takes exactly one
+;; argument) the copy will need amending.
+(defmacro static-if (condition then-form &rest else-forms)
+ "A conditional compilation macro.
+Evaluate CONDITION at macro-expansion time. If it is non-nil,
+expand the macro to THEN-FORM. Otherwise expand it to ELSE-FORMS
+enclosed in a `progn' form. ELSE-FORMS may be empty."
+ (declare (indent 2)
+ (debug (sexp sexp &rest sexp)))
+ (if (eval condition lexical-binding)
+ then-form
+ (cons 'progn else-forms)))
+
(defmacro when (cond &rest body)
"If COND yields non-nil, do BODY, else return nil.
When COND yields non-nil, eval BODY forms sequentially and return
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 97652d0e7a5: New conditional compilation macro static-if.,
Alan Mackenzie <=