diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-09-20 02:14:01 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-09-22 14:50:42 +0100 |
commit | dcf91d8e1b1d618e124dd55a158d6e8709160986 (patch) | |
tree | 84ac2d6a20cec9b449f7bfd247350d804fd693d4 /Emacs | |
parent | d5c8694db2d143b32376e5fdef2ef6be0ff34ed4 (diff) | |
download | dotfiles-dcf91d8e1b1d618e124dd55a158d6e8709160986.tar.gz dotfiles-dcf91d8e1b1d618e124dd55a158d6e8709160986.tar.bz2 dotfiles-dcf91d8e1b1d618e124dd55a158d6e8709160986.zip |
(Emacs)~literate now actually checks if compilation is necessary
Just realised how easy a fix this is to the 2 second wait time for
Emacs to stop. Checking if the org files are newer than the compiled
files, and the same for byte compilation, ensures I only compile when
necessary.
This actually makes Emacs kinda appealing for quick work: I kinda
cringed every time I launched Emacs without a server because I knew it
would take *so long* to stop it. Now that isn't as big a concern!
Diffstat (limited to 'Emacs')
-rw-r--r-- | Emacs/.config/emacs/elisp/literate.el | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/Emacs/.config/emacs/elisp/literate.el b/Emacs/.config/emacs/elisp/literate.el index 0a53bdd..67ee88e 100644 --- a/Emacs/.config/emacs/elisp/literate.el +++ b/Emacs/.config/emacs/elisp/literate.el @@ -48,10 +48,6 @@ (lambda (name) (string= "el" (file-name-extension name))) (cddr (directory-files (concat user-emacs-directory "elisp/"))))))) -(defconst +literate/elisp-byte-compiled - `(,@(mapcar #'(lambda (x) (replace-regexp-in-string ".el" ".elc" x)) +literate/output-files) - ,@(mapcar #'(lambda (x) (replace-regexp-in-string ".el" ".elc" x)) +literate/elisp-files))) - ;; Setup predicates and loading (defun +literate/--reduce-bool (bools init) @@ -62,7 +58,7 @@ (defun +literate/output-files-exist () "Checks if output files exist, for compilation purposes." (if (< 1 (length +literate/output-files)) - (+literate/--reduce-bool (mapc #'file-exists-p +literate/output-files) t) + (+literate/--reduce-bool (mapcar #'file-exists-p +literate/output-files) t) (file-exists-p (car +literate/output-files)))) (defun +literate/load-config () @@ -72,30 +68,29 @@ (autoload #'org-babel-tangle-file "ob-tangle") +(defun +literate/tangle-if-old (org-file) + (let ((output-file (replace-regexp-in-string ".org" ".el" org-file))) + (if (or (not (file-exists-p output-file)) (file-newer-than-file-p org-file output-file)) + (org-babel-tangle-file org-file)))) + +(defun +literate/byte-compile-if-old (el-file) + (let ((output-file (replace-regexp-in-string ".el" ".elc" el-file))) + (if (file-newer-than-file-p el-file output-file) + (byte-compile-file el-file)))) + (defun +literate/compile-config () "Compile all files in +literate/org-files via org-babel-tangle." (interactive) (message "Compiling files...") - (mapcar #'org-babel-tangle-file +literate/org-files) + (mapc #'+literate/tangle-if-old +literate/org-files) (message "Files compiled") (message "Byte-compiling literate files...") - (mapcar #'(lambda (file) (byte-compile-file file)) +literate/output-files) + (mapc #'+literate/byte-compile-if-old +literate/output-files) (message "Literate files byte-compiled") (message "Byte compiling init.el, early-init.el, elisp/*") - (mapcar #'(lambda (file) (byte-compile-file file)) +literate/elisp-files) + (mapc #'+literate/byte-compile-if-old +literate/elisp-files) (message "Finished byte-compiling")) -(defun +literate/--async-compile () - "WIP Attempting to make an asynchronous compilation function." - (interactive) - (start-process-shell-command - "async-compile" - "*literate/async-compile*" - (format - "emacs --batch --eval \"(progn (load %s\") (+literate/compile-config))\"" - (concat user-emacs-directory "elisp/literate.el")))) - - (provide 'literate) ;;; literate.el ends here |