aboutsummaryrefslogtreecommitdiff
path: root/modules/config-utilities.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/config-utilities.el')
-rw-r--r--modules/config-utilities.el40
1 files changed, 27 insertions, 13 deletions
diff --git a/modules/config-utilities.el b/modules/config-utilities.el
index 72427ef9..62fc29d0 100644
--- a/modules/config-utilities.el
+++ b/modules/config-utilities.el
@@ -131,12 +131,18 @@ Signals `user-error' if METHOD-SYMBOL is nil or not fboundp."
;;; ----------------------------- Config Compilation ----------------------------
+(defun cj/--native-comp-p ()
+ "Return non-nil when native compilation is available on this build.
+Detected with `native-comp-available-p', not `boundp' of the async function:
+`native-compile-async' is a function, so `boundp' is always nil."
+ (and (fboundp 'native-comp-available-p) (native-comp-available-p)))
+
(defun cj/--recompile-emacs-home (dir &optional native-p)
"Delete all .elc/.eln files under DIR, then recompile.
NATIVE-P chooses native compilation when non-nil, byte otherwise.
-Also removes the eln (native) or elc (byte) cache directory.
+Also removes the eln-cache (native) or elc (byte) cache directory.
Returns the compilation method used: \\='native or \\='byte."
- (let ((elt-dir (expand-file-name (if native-p "eln" "elc") dir)))
+ (let ((elt-dir (expand-file-name (if native-p "eln-cache" "elc") dir)))
(message "Deleting all compiled files in %s" dir)
(dolist (file (directory-files-recursively dir "\\(\\.elc\\|\\.eln\\)$"))
(delete-file file))
@@ -157,7 +163,7 @@ Returns the compilation method used: \\='native or \\='byte."
"Delete all compiled files in the Emacs home before recompiling.
Recompile natively when supported, otherwise fall back to byte compilation."
(interactive)
- (let* ((native (boundp 'native-compile-async))
+ (let* ((native (cj/--native-comp-p))
(mode-word (if native "native" "byte")))
(if (yes-or-no-p
(format "Please confirm recursive %s recompilation of %s: "
@@ -190,27 +196,27 @@ Returns the count of files deleted."
count user-emacs-directory)))
(keymap-set cj/debug-config-keymap "c d" 'cj/delete-emacs-home-compiled-files)
-(defun cj/compile-this-elisp-buffer ()
- "Compile the current .el: prefer native (.eln), else .elc. Message if neither."
- (interactive)
- (unless (and buffer-file-name (string-match-p "\\.el\\'" buffer-file-name))
- (user-error "Not visiting a .el file"))
- (save-buffer)
- (let ((file buffer-file-name))
+(defun cj/--compile-elisp-file (file &optional available-p)
+ "Compile FILE: prefer async native, then sync native, then byte-compile.
+AVAILABLE-P decides which compilers exist; it defaults to `fboundp'. It is
+a parameter so tests can force each branch without redefining `fboundp':
+an `fset' on that subr pulls in comp-run and bytecomp, whose own `defun'
+of `byte-compile-file' then lands on top of any test double."
+ (let ((available-p (or available-p #'fboundp)))
(cond
;; Native compilation (async preferred)
- ((fboundp 'native-compile-async)
+ ((funcall available-p 'native-compile-async)
(native-compile-async file)
(message "Queued native compilation for %s" file))
;; Native compilation (sync, if async not available)
- ((fboundp 'native-compile)
+ ((funcall available-p 'native-compile)
(condition-case err
(progn
(native-compile file)
(message "Native-compiled %s" file))
(error (message "Native compile failed: %s" (error-message-string err)))))
;; Byte-compile fallback
- ((fboundp 'byte-compile-file)
+ ((funcall available-p 'byte-compile-file)
(let ((out (byte-compile-file file)))
(if out
(message "Byte-compiled -> %s" out)
@@ -218,6 +224,14 @@ Returns the count of files deleted."
;; Neither facility available
(t
(message "No compilation available (no native-compile, no byte-compile)")))))
+
+(defun cj/compile-this-elisp-buffer ()
+ "Compile the current .el: prefer native (.eln), else .elc. Message if neither."
+ (interactive)
+ (unless (and buffer-file-name (string-match-p "\\.el\\'" buffer-file-name))
+ (user-error "Not visiting a .el file"))
+ (save-buffer)
+ (cj/--compile-elisp-file buffer-file-name))
(keymap-set cj/debug-config-keymap "c ." 'cj/compile-this-elisp-buffer)
;; --------------------------- Information Reporting ---------------------------