[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 438d683afd 4/4: Add compat--with-feature helper
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 438d683afd 4/4: Add compat--with-feature helper |
Date: |
Tue, 3 Jan 2023 12:57:27 -0500 (EST) |
branch: externals/compat
commit 438d683afd6f92c77acbb91763520ee80d68ac12
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add compat--with-feature helper
---
compat-macs.el | 28 +++++++++++++---------------
compat-tests.el | 7 +------
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/compat-macs.el b/compat-macs.el
index 9a8703202d..c45fd7671a 100644
--- a/compat-macs.el
+++ b/compat-macs.el
@@ -29,6 +29,14 @@
(setq compat--current-version version)
nil)
+(defun compat--with-feature (feature body)
+ "Protect BODY with `eval-after-load' if FEATURE is non-nil."
+ (declare (indent 1))
+ (if feature
+ ;; See https://nullprogram.com/blog/2018/02/22/:
+ `(eval-after-load ,feature `(funcall ',(lambda () ,body)))
+ body))
+
(defvar compat--generate-function #'compat--generate-default
"Function used to generate compatibility code.
The function must take six arguments: NAME, DEF-FN, INSTALL-FN,
@@ -100,27 +108,17 @@ DEF-FN, INSTALL-FN, CHECK-FN and ATTR."
(when (and (version<= version emacs-version)
(fboundp actual-name)
check)
- `(,@check
- ,(if feature
- ;; See https://nullprogram.com/blog/2018/02/22/:
- `(eval-after-load ,feature `(funcall ',(lambda ()
,body)))
- body))))))
+ `(,@check ,(compat--with-feature feature body))))))
((plist-get attr :realname)
`(progn
,(funcall def-fn realname version)
,(and check
`(,@check
- ,(let ((body (funcall install-fn realname version)))
- (if feature
- ;; See https://nullprogram.com/blog/2018/02/22/:
- `(eval-after-load ,feature `(funcall ',(lambda ()
,body)))
- body))))))
+ ,(compat--with-feature feature
+ (funcall install-fn realname version))))))
(check
- (let ((body `(,@check ,(funcall def-fn name version))))
- (if feature
- ;; See https://nullprogram.com/blog/2018/02/22/:
- `(eval-after-load ,feature `(funcall ',(lambda () ,body)))
- body))))))
+ (compat--with-feature feature
+ `(,@check ,(funcall def-fn name version)))))))
(defun compat--define-function (type name arglist docstring rest)
"Generate compatibility code for a function NAME.
diff --git a/compat-tests.el b/compat-tests.el
index ad2611d9b9..9555d2bb19 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -70,12 +70,7 @@ DEF-FN, INSTALL-FN, CHECK-FN and ATTR."
(put ',realname 'compat-min-version ,min-version)
(put ',realname 'compat-max-version ,max-version)
,(funcall def-fn realname version)
- ,(and check
- `(,@check
- ,(if feature
- ;; See https://nullprogram.com/blog/2018/02/22/:
- `(eval-after-load ,feature `(funcall ',(lambda () ,body)))
- body))))))
+ ,(and check `(,@check ,(compat--with-feature feature body))))))
(setq compat--generate-function #'compat--generate-testable)