(Emacs/literate)~reworked literate to only compile if necessary
Speeds up boot and kill. Actually checks for timestamps and logical errors are removed.
This commit is contained in:
@@ -24,6 +24,16 @@
|
|||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
|
;; Predicates
|
||||||
|
(defun +literate/org-to-el (name)
|
||||||
|
(string-replace ".org" ".el" name))
|
||||||
|
|
||||||
|
(defun +literate/org-to-elc (name)
|
||||||
|
(string-replace ".org" ".elc" name))
|
||||||
|
|
||||||
|
(defun +literate/el-to-elc (name)
|
||||||
|
(string-replace ".el" ".elc" name))
|
||||||
|
|
||||||
(defun +literate/filter (predicate list)
|
(defun +literate/filter (predicate list)
|
||||||
(if (null list)
|
(if (null list)
|
||||||
nil
|
nil
|
||||||
@@ -39,70 +49,116 @@
|
|||||||
(defun +literate/el-p (filename)
|
(defun +literate/el-p (filename)
|
||||||
(string= "el" (file-name-extension filename)))
|
(string= "el" (file-name-extension filename)))
|
||||||
|
|
||||||
(defconst +literate/org-files
|
|
||||||
(+literate/filter
|
|
||||||
#'+literate/org-p
|
|
||||||
(mapcar #'(lambda (file) (concat user-emacs-directory file))
|
|
||||||
(cddr (directory-files user-emacs-directory)))))
|
|
||||||
|
|
||||||
(defconst +literate/output-files
|
|
||||||
(mapcar #'(lambda (x) (replace-regexp-in-string ".org" ".el" x)) +literate/org-files))
|
|
||||||
|
|
||||||
(defconst +literate/elisp-files
|
|
||||||
`(,(concat user-emacs-directory "early-init.el")
|
|
||||||
,(concat user-emacs-directory "init.el")
|
|
||||||
,@+literate/output-files
|
|
||||||
,@(mapcar
|
|
||||||
#'(lambda (name) (concat user-emacs-directory "elisp/" name))
|
|
||||||
;; Only take .el files
|
|
||||||
(+literate/filter
|
|
||||||
#'+literate/el-p
|
|
||||||
(cddr (directory-files (concat user-emacs-directory "elisp/")))))))
|
|
||||||
|
|
||||||
;; Setup predicates and loading
|
|
||||||
|
|
||||||
(defun +literate/--reduce-bool (bools init)
|
(defun +literate/--reduce-bool (bools init)
|
||||||
(if (= (length bools) 0)
|
(if (= (length bools) 0)
|
||||||
init
|
init
|
||||||
(+literate/--reduce-bool (cdr bools) (and (car bools) init))))
|
(+literate/--reduce-bool (cdr bools) (and (car bools) init))))
|
||||||
|
|
||||||
(defun +literate/output-files-exist ()
|
;; Files
|
||||||
"Checks if output files exist, for compilation purposes."
|
(defconst +literate/org-files
|
||||||
(if (< 1 (length +literate/output-files))
|
(+literate/filter
|
||||||
(+literate/--reduce-bool (mapcar #'file-exists-p +literate/output-files) t)
|
#'+literate/org-p
|
||||||
(file-exists-p (car +literate/output-files))))
|
(mapcar #'(lambda (file) (concat user-emacs-directory file))
|
||||||
|
(cddr (directory-files user-emacs-directory)))))
|
||||||
|
|
||||||
(defun +literate/load-config ()
|
(defconst +literate/el-init-files
|
||||||
"Load the first file in +literate/output-files."
|
`(,(concat user-emacs-directory "early-init.el")
|
||||||
(interactive)
|
,(concat user-emacs-directory "init.el")))
|
||||||
(load-file (concat user-emacs-directory "config.el")))
|
|
||||||
|
|
||||||
|
(defconst +literate/el-lib-files
|
||||||
|
(mapcar
|
||||||
|
#'(lambda (name) (concat user-emacs-directory "elisp/" name))
|
||||||
|
;; Only take .el files
|
||||||
|
(+literate/filter
|
||||||
|
#'+literate/el-p
|
||||||
|
(cddr (directory-files (concat user-emacs-directory "elisp/"))))))
|
||||||
|
|
||||||
|
(defconst +literate/el-org-files
|
||||||
|
(mapcar #'+literate/org-to-el +literate/org-files))
|
||||||
|
|
||||||
|
(defconst +literate/el-files
|
||||||
|
(cl-concatenate
|
||||||
|
'list
|
||||||
|
+literate/el-init-files
|
||||||
|
+literate/el-lib-files
|
||||||
|
+literate/el-org-files))
|
||||||
|
|
||||||
|
(defconst +literate/elc-init-files
|
||||||
|
(mapcar #'+literate/el-to-elc +literate/el-init-files))
|
||||||
|
|
||||||
|
(defconst +literate/elc-lib-files
|
||||||
|
(mapcar #'+literate/el-to-elc +literate/el-lib-files))
|
||||||
|
|
||||||
|
(defconst +literate/elc-org-files
|
||||||
|
(mapcar #'+literate/org-to-elc +literate/org-files))
|
||||||
|
|
||||||
|
;; Basic compilation and loading files
|
||||||
(autoload #'org-babel-tangle-file "ob-tangle")
|
(autoload #'org-babel-tangle-file "ob-tangle")
|
||||||
|
|
||||||
(defun +literate/tangle-if-old (org-file)
|
(defun +literate/tangle-if-old (org-file)
|
||||||
(let ((output-file (replace-regexp-in-string ".org" ".el" org-file)))
|
(let ((output-file (+literate/org-to-el org-file)))
|
||||||
(message "Tangle(%s)->%s" org-file output-file)
|
(when (file-newer-than-file-p org-file output-file)
|
||||||
(if (or (not (file-exists-p output-file)) (file-newer-than-file-p org-file output-file))
|
(message "[Literate]:\tTangle(%s)->%s" org-file output-file)
|
||||||
(org-babel-tangle-file org-file))))
|
(org-babel-tangle-file org-file))))
|
||||||
|
|
||||||
(defun +literate/byte-compile-if-old (el-file)
|
(defun +literate/byte-compile-if-old (el-file)
|
||||||
(let ((output-file (replace-regexp-in-string ".el" ".elc" el-file)))
|
(let ((output-file (+literate/el-to-elc el-file)))
|
||||||
(if (file-newer-than-file-p el-file output-file)
|
(when (file-newer-than-file-p el-file output-file)
|
||||||
(byte-compile-file el-file))))
|
(message "[Literate]:\tByteCompile(%s)->%s" el-file output-file)
|
||||||
|
(byte-compile-file el-file))))
|
||||||
|
|
||||||
|
(defun +literate/load-org-file (org-file)
|
||||||
|
(+literate/tangle-if-old org-file)
|
||||||
|
(load-file (+literate/org-to-el org-file)))
|
||||||
|
|
||||||
|
(defun +literate/load-config ()
|
||||||
|
"Load the config.el."
|
||||||
|
(interactive)
|
||||||
|
(mapcar #'+literate/tangle-if-old +literate/org-files)
|
||||||
|
(load-file (concat user-emacs-directory "config.el")))
|
||||||
|
|
||||||
|
;; Compiling all files
|
||||||
|
(defun +literate/compile-init-files ()
|
||||||
|
(message "[Literate/init]: Byte compiling init files...")
|
||||||
|
(mapc #'+literate/byte-compile-if-old +literate/el-init-files)
|
||||||
|
(message "[Literate/init]: Init files compiled!"))
|
||||||
|
|
||||||
|
(defun +literate/compile-lib-files ()
|
||||||
|
(message "[Literate/lib]: Byte compiling lib files...")
|
||||||
|
(mapc #'+literate/byte-compile-if-old +literate/el-lib-files)
|
||||||
|
(message "[Literate/lib]: Lib files compiled!"))
|
||||||
|
|
||||||
|
(defun +literate/compile-org-files ()
|
||||||
|
(message "[Literate/org]: Tangling org files...")
|
||||||
|
(mapc #'+literate/tangle-if-old +literate/org-files)
|
||||||
|
(message "[Literate/org]: Tangled org files!")
|
||||||
|
(message "[Literate/org]: Byte compiling org files...")
|
||||||
|
(mapc #'+literate/byte-compile-if-old +literate/el-org-files)
|
||||||
|
(message "[Literate/org]: Byte compiled org files!"))
|
||||||
|
|
||||||
(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 "[Literate]: Starting compilation...")
|
||||||
(mapc #'+literate/tangle-if-old +literate/org-files)
|
(+literate/compile-init-files)
|
||||||
(message "Files compiled")
|
(+literate/compile-lib-files)
|
||||||
|
(+literate/compile-org-files)
|
||||||
|
(message "[Literate]: Finished compilation!"))
|
||||||
|
|
||||||
(message "Byte-compiling literate files...")
|
;; Cleaning config
|
||||||
(mapc #'+literate/byte-compile-if-old +literate/output-files)
|
(defun +literate/clean-config ()
|
||||||
(message "Literate files byte-compiled")
|
"Removes all .el files generated by literate org files and .elc
|
||||||
(message "Byte compiling init.el, early-init.el, *.org~>*.el elisp/*")
|
files by byte compilation"
|
||||||
(mapc #'+literate/byte-compile-if-old +literate/elisp-files)
|
(interactive)
|
||||||
(message "Finished byte-compiling"))
|
(message "[Literate]: Cleaning configuration...")
|
||||||
|
(mapcar #'delete-file
|
||||||
|
(cl-concatenate
|
||||||
|
'list
|
||||||
|
+literate/el-org-files
|
||||||
|
+literate/elc-init-files
|
||||||
|
+literate/elc-lib-files
|
||||||
|
+literate/elc-org-files))
|
||||||
|
(message "[Literate]: Cleaned configuration!"))
|
||||||
|
|
||||||
(provide 'literate)
|
(provide 'literate)
|
||||||
;;; literate.el ends here
|
;;; literate.el ends here
|
||||||
|
|||||||
@@ -70,9 +70,6 @@
|
|||||||
'kill-emacs-hook
|
'kill-emacs-hook
|
||||||
#'+literate/compile-config)
|
#'+literate/compile-config)
|
||||||
|
|
||||||
(if (not (+literate/output-files-exist))
|
|
||||||
(+literate/compile-config))
|
|
||||||
|
|
||||||
(+literate/load-config)
|
(+literate/load-config)
|
||||||
|
|
||||||
(when (daemonp)
|
(when (daemonp)
|
||||||
|
|||||||
Reference in New Issue
Block a user