(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!
This commit is contained in:
@@ -48,10 +48,6 @@
|
|||||||
(lambda (name) (string= "el" (file-name-extension name)))
|
(lambda (name) (string= "el" (file-name-extension name)))
|
||||||
(cddr (directory-files (concat user-emacs-directory "elisp/")))))))
|
(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
|
;; Setup predicates and loading
|
||||||
|
|
||||||
(defun +literate/--reduce-bool (bools init)
|
(defun +literate/--reduce-bool (bools init)
|
||||||
@@ -62,7 +58,7 @@
|
|||||||
(defun +literate/output-files-exist ()
|
(defun +literate/output-files-exist ()
|
||||||
"Checks if output files exist, for compilation purposes."
|
"Checks if output files exist, for compilation purposes."
|
||||||
(if (< 1 (length +literate/output-files))
|
(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))))
|
(file-exists-p (car +literate/output-files))))
|
||||||
|
|
||||||
(defun +literate/load-config ()
|
(defun +literate/load-config ()
|
||||||
@@ -72,30 +68,29 @@
|
|||||||
|
|
||||||
(autoload #'org-babel-tangle-file "ob-tangle")
|
(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 ()
|
(defun +literate/compile-config ()
|
||||||
"Compile all files in +literate/org-files via org-babel-tangle."
|
"Compile all files in +literate/org-files via org-babel-tangle."
|
||||||
(interactive)
|
(interactive)
|
||||||
(message "Compiling files...")
|
(message "Compiling files...")
|
||||||
(mapcar #'org-babel-tangle-file +literate/org-files)
|
(mapc #'+literate/tangle-if-old +literate/org-files)
|
||||||
(message "Files compiled")
|
(message "Files compiled")
|
||||||
|
|
||||||
(message "Byte-compiling literate files...")
|
(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 "Literate files byte-compiled")
|
||||||
(message "Byte compiling init.el, early-init.el, elisp/*")
|
(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"))
|
(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)
|
(provide 'literate)
|
||||||
;;; literate.el ends here
|
;;; literate.el ends here
|
||||||
|
|||||||
Reference in New Issue
Block a user