emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 8f33aaf181 2/3: Add compat-guard dynamic conditi


From: ELPA Syncer
Subject: [elpa] externals/compat 8f33aaf181 2/3: Add compat-guard dynamic condition
Date: Tue, 17 Jan 2023 04:57:26 -0500 (EST)

branch: externals/compat
commit 8f33aaf1813bbf56cdad0701953f2bdd86ec00b3
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add compat-guard dynamic condition
    
    We have to make sure that no definitions are overriden at runtime, when the
    compiled library is loaded in a newer or patched Emacs version.
---
 compat-26.el   |  2 +-
 compat-27.el   |  8 +++++---
 compat-macs.el | 35 ++++++++++++++++++++---------------
 3 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/compat-26.el b/compat-26.el
index 9833698c9c..f1d49d540c 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -88,7 +88,7 @@ SEQUENCE may be a list, a vector, a boolean vector, or a 
string."
         (if entry (cdr entry) default))
     (alist-get key alist default remove)))
 
-(compat-guard
+(compat-guard t
   (gv-define-expander compat--alist-get ;; <compat-tests:alist-get-gv>
     (lambda (do key alist &optional default remove testfn)
       (macroexp-let2 macroexp-copyable-p k key
diff --git a/compat-27.el b/compat-27.el
index 3a67e6ca2d..b891fb2311 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -282,7 +282,7 @@ return nil."
 
 ;;;; Defined in simple.el
 
-(compat-guard
+(compat-guard (not (fboundp 'decoded-time-second))
   (cl-defstruct (decoded-time ;; <compat-tests:decoded-time>
                  (:constructor nil)
                  (:copier nil)
@@ -334,7 +334,7 @@ Internal use only."
     (setcdr image (plist-put (cdr image) property value)))
   value)
 
-(compat-guard
+(compat-guard t
   :feature image
   ;; HACK: image--set-property was broken with an off-by-one error on Emacs 26.
   ;; The bug was fixed in a4ad7bed187493c1c230f223b52c71f5c34f7c89. Therefore 
we
@@ -522,7 +522,9 @@ January 1st being 1."
 
 ;;;; Defined in text-property-search.el
 
-(compat-guard (cl-defstruct (prop-match) beginning end value)) ;; 
<compat-tests:prop-match>
+(declare-function make-prop-match nil)
+(compat-guard (not (fboundp 'make-prop-match))
+  (cl-defstruct (prop-match) beginning end value)) ;; <compat-tests:prop-match>
 
 (compat-defun text-property-search-forward ;; 
<compat-tests:text-property-search-forward>
     (property &optional value predicate not-current)
diff --git a/compat-macs.el b/compat-macs.el
index a4de82dbe4..83eec3f57d 100644
--- a/compat-macs.el
+++ b/compat-macs.el
@@ -37,21 +37,6 @@
     (when (and (< 24 before) (< emacs-major-version before))
       `(require ',(intern (format "compat-%d" before))))))
 
-(defmacro compat-guard (&rest rest)
-  "Guard definition with a version check.
-REST is an attribute plist followed by the definition body.  The
-attributes specify the conditions under which the definition is
-generated.
-
-- :feature :: Wrap the definition with `with-eval-after-load'.
-
-- :when :: Do not install the definition depending on the
-  version.  Instead install the definition if :when evaluates to
-  non-nil."
-  (declare (debug ([&rest keywordp sexp] def-body))
-           (indent 0))
-  (compat--guard rest '(:body) #'identity))
-
 (defun compat--format-docstring (type name docstring)
   "Format DOCSTRING for NAME of TYPE.
 Prepend compatibility notice to the actual documentation string."
@@ -138,6 +123,26 @@ REST are attributes and the function BODY."
               (unless (fboundp ',name) ,def))
           (list def))))))
 
+(defmacro compat-guard (cond &rest rest)
+  "Guard definition with a runtime COND and a version check.
+The runtime condition must make sure that no definition is
+overriden.  REST is an attribute plist followed by the definition
+body.  The attributes specify the conditions under which the
+definition is generated.
+
+- :feature :: Wrap the definition with `with-eval-after-load'.
+
+- :when :: Do not install the definition depending on the
+  version.  Instead install the definition if :when evaluates to
+  non-nil."
+  (declare (debug ([&rest keywordp sexp] def-body))
+           (indent 0))
+  (compat--guard rest '(:body)
+    (lambda (body)
+      (if (eq cond t)
+          body
+        `((when ,cond ,@body))))))
+
 (defmacro compat-defalias (name def &rest attrs)
   "Define compatibility alias NAME as DEF.
 ATTRS is a plist of attributes, which specify the conditions



reply via email to

[Prev in Thread] Current Thread [Next in Thread]