branch: externals/compat commit c110db282978ccd65416d0afc987b4987245a115 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Ensure that Compat works both interpreted and compiled See https://github.com/magit/magit/issues/4858 --- .github/workflows/makefile.yml | 4 +++- Makefile | 2 +- compat-27.el | 6 +++--- compat-macs.el | 19 ++++++++++--------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index db67eaaf01..0764e3452e 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -38,11 +38,13 @@ jobs: - uses: purcell/setup-emacs@master with: version: ${{ matrix.emacs-version }} + - name: Run interpreted tests + run: make test - name: Compile run: | sed -i "s/ no-byte-compile: t;//" compat-macs.el compat-tests.el make compile - - name: Run tests + - name: Run compiled tests run: make test - name: Make info run: make compat.info diff --git a/Makefile b/Makefile index f56bfa4eee..85907f6c5a 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ all: compile compile: $(BYTEC) -test: compile +test: $(EMACS) --version $(EMACS) -Q --batch -L . -l compat-tests.el -f ert-run-tests-batch-and-exit diff --git a/compat-27.el b/compat-27.el index 793c98e095..5d23529baf 100644 --- a/compat-27.el +++ b/compat-27.el @@ -412,9 +412,9 @@ the minibuffer was activated, and execute the forms." ;; override the gv expander until Emacs 27.1. (compat-guard (or (= emacs-major-version 26) (not (get 'image-property 'gv-expander))) :feature image - (if (eval-when-compile (< emacs-major-version 26)) - (gv-define-simple-setter image-property image--set-property) ;; <compat-tests:image-property> - (gv-define-simple-setter image-property compat--image--set-property))) + (gv-define-setter image-property (value image prop) ;; <compat-tests:image-property> + `(,(if (< emacs-major-version 26) 'image--set-property 'compat--image--set-property) + ,image ,prop ,value))) ;;;; Defined in files.el diff --git a/compat-macs.el b/compat-macs.el index 0e81eab110..2e07399fb1 100644 --- a/compat-macs.el +++ b/compat-macs.el @@ -30,14 +30,14 @@ (defvar compat-macs--version nil "Version of the currently defined compatibility definitions.") -(defmacro compat-macs--strict (cond &rest error) +(defun compat-macs--strict (cond &rest error) "Assert strict COND, otherwise fail with ERROR." (when (bound-and-true-p compat-strict) - `(compat-macs--assert ,cond ,@error))) + (apply #'compat-macs--assert cond error))) -(defmacro compat-macs--assert (cond &rest error) +(defun compat-macs--assert (cond &rest error) "Assert COND, otherwise fail with ERROR." - `(unless ,cond (error ,@error))) + (unless cond (apply #'error error))) (defun compat-macs--docstring (type name docstring) "Format DOCSTRING for NAME of TYPE. @@ -102,7 +102,7 @@ REST are attributes and the function BODY." "Invalid :extended version %s for %s %s" extended type name) (setq extended (version<= extended emacs-version))) (compat-macs--strict (eq extended (fboundp name)) - "Wrong :extended flag for %s %s" type name) + "Wrong :extended flag for %s %s" type name) ;; Remove unsupported declares. It might be possible to set these ;; properties otherwise. That should be looked into and implemented ;; if it is the case. @@ -247,10 +247,11 @@ definition is generated. (defmacro compat-declare-version (version) "Set the Emacs version that is currently being handled to VERSION." - (setq compat-macs--version version) - (let ((before (1- (car (version-to-list version))))) - (when (and (< 24 before) (< emacs-major-version before)) - `(require ',(intern (format "compat-%d" before)))))) + (prog1 + (let ((before (1- (car (version-to-list version))))) + (when (and (< 24 before) (< emacs-major-version before)) + `(require ',(require (intern (format "compat-%d" before)))))) + (setq compat-macs--version version))) (provide 'compat-macs) ;;; compat-macs.el ends here