aboutsummaryrefslogtreecommitdiff
path: root/compat.el
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2022-07-11 11:49:18 +0200
committerPhilip Kaludercic <philipk@posteo.net>2022-07-14 22:16:34 +0200
commit9e40cf3c3a4d36c39fb9145776e21d2f6be69de6 (patch)
treedbdf694fb7e83807ce1d9e4cc3bf72b50b18e259 /compat.el
parent08a673a8eb713374d18bae1b52e34fecd5b6733f (diff)
Simplify loading and compiling of Compat
To avoid the issue like having to find the source of the other files in the project during byte compilation, we will stop embedding (or "entwining") the compiled results of compat-*.el into compat.elc. While this may make loading slightly slower -- in my own tests it was unnoticeable -- it makes loading Compat a lot easier to manage and decreases the risk of running into peculiar edge cases, as documented here[0]. To accommodate for Compat's unusual approach, we still need to do something unusual, namely rebind the `features' variable, that is used by `require' to check if a feature is already bound or not. This is done so that while loading compat-NM.el, the bound version of `features' is updated but the updated version is reverted back as soon as the scope of the let-block is left. This allows `compat-NM' to be loaded again later on, without `compat--inhibit-prefixed' being bound, as is the case in compat.el. This variable, if bound, suppresses the evaluation of prefixed definitions, as had previously been done by the generator function `compat--generate-minimal-no-prefix'. Another marginal advantage of this approach is that if someone loads `compat-NM' before `compat' (for whatever reason), `compat-NM' will not be reloaded, as it is represented in both the actual as well as the copied value of `features'. [0] https://todo.sr.ht/~pkal/compat/4#event-180270
Diffstat (limited to 'compat.el')
-rw-r--r--compat.el78
1 files changed, 15 insertions, 63 deletions
diff --git a/compat.el b/compat.el
index 9484211..b8e5e93 100644
--- a/compat.el
+++ b/compat.el
@@ -41,69 +41,21 @@
(eval-when-compile (require 'compat-macs))
-;;;; Core functionality
-
-;; To accelerate the loading process, we insert the contents of
-;; compat-N.M.el directly into the compat.elc. Note that by default
-;; this will not include prefix functions. These have to be required
-;; separately, by explicitly requiring the feature that defines them.
-(eval-when-compile
- (defvar compat--generate-function)
- (defvar compat--entwine-version)
- (defmacro compat-entwine (version)
- (cond
- ((or (not (eq compat--generate-function 'compat--generate-minimal))
- (bound-and-true-p compat-testing))
- `(load ,(format "compat-%d.el" version)))
- ((let* ((compat--generate-function 'compat--generate-minimal-no-prefix)
- (file (expand-file-name
- (format "compat-%d.el" version)
- (file-name-directory
- (or
- ;; Some third-party library, which requires
- ;; compat.el, is being compiled, loaded or
- ;; evaluated, and compat.el hasn't been compiled
- ;; yet.
- ;; cd compat && make clean && cd ../other && \
- ;; make clean all
- ;;
- ;; Or compat.el is being evaluated.
- ;; cd compat && make clean && emacs -Q -L . compat.el
- ;; M-x eval-buffer
- ;;
- ;; (Like `macroexp-file-name' from Emacs 28.1.)
- (let ((file (car (last current-load-list))))
- (and (stringp file) file))
- ;; compat.el is being compiled.
- ;; cd compat && make clean all
- (bound-and-true-p byte-compile-current-file)))))
- (compat--entwine-version (number-to-string version))
- defs)
- (with-temp-buffer
- (insert-file-contents file)
- (emacs-lisp-mode)
- (while (progn
- (forward-comment 1)
- (not (eobp)))
- (let ((form (read (current-buffer))))
- (cond
- ((memq (car-safe form)
- '(compat-defun
- compat-defmacro
- compat-advise
- compat-defvar))
- (push (macroexpand-all form) defs))
- ((memq (car-safe form)
- '(declare-function
- defvar))
- (push form defs))))))
- (macroexp-progn (nreverse defs)))))))
-
-(compat-entwine 24)
-(compat-entwine 25)
-(compat-entwine 26)
-(compat-entwine 27)
-(compat-entwine 28)
+;; We load all the components of Compat with a copied value of
+;; `features' list, that will prevent the list being modified, and all
+;; the files can be loaded again. This is done so that
+;; `compat--inhibit-prefixed' can take effect when loading `compat',
+;; and do nothing when loading each sub-feature manually.
+
+(defvar compat--inhibit-prefixed)
+(let* ((features (copy-sequence features))
+ (compat--inhibit-prefixed t))
+ (ignore features) ;for the byte compiler
+ (load "compat-24")
+ (load "compat-25")
+ (load "compat-26")
+ (load "compat-27")
+ (load "compat-28"))
(provide 'compat)
;;; compat.el ends here