aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compat-26.el2
-rw-r--r--compat-27.el8
-rw-r--r--compat-macs.el35
3 files changed, 26 insertions, 19 deletions
diff --git a/compat-26.el b/compat-26.el
index 9833698..f1d49d5 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 3a67e6c..b891fb2 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 a4de82d..83eec3f 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