(Emacs)~init.el literate functions

To remove the ~(require 'cl)~ dependency, I wrote my own reduce for
boolean values, recursive, which should do the trick.  Mostly just to
remove the annoying "haha no cl library anymore".
This commit is contained in:
2022-09-14 00:35:37 +01:00
parent 4767422b39
commit 61f06ef0c8

View File

@@ -53,19 +53,24 @@
(defconst +literate/output-files (defconst +literate/output-files
(mapcar #'(lambda (x) (replace-regexp-in-string ".org" ".el" x)) +literate/org-files)) (mapcar #'(lambda (x) (replace-regexp-in-string ".org" ".el" x)) +literate/org-files))
;; Setup predicates and loading
(defun +literate/--reduce-bool (bools init)
(if (= (length bools) 0)
init
(+literate/--reduce-bool (cdr bools) (and (car bools) init))))
(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)
(file-exists-p (car +literate/output-files))))
(defun +literate/load-config () (defun +literate/load-config ()
"Load all files in +literate/output-files." "Load all files in +literate/output-files."
(interactive) (interactive)
(mapc #'(lambda (x) (load-file x)) +literate/output-files)) (mapc #'(lambda (x) (load-file x)) +literate/output-files))
(defun +literate/org-files-exist ()
"Checks if output files exist, for compilation purposes."
(require 'cl-lib)
(if (< 1 (length +literate/output-files))
(cl-reduce #'(lambda (x y) (and x y)) (mapc #'file-exists-p +literate/output-files)
:initial-value t)
(file-exists-p (car +literate/output-files))))
(autoload #'org-babel-tangle-file "ob-tangle") (autoload #'org-babel-tangle-file "ob-tangle")
(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."
@@ -83,7 +88,7 @@
'kill-emacs-hook 'kill-emacs-hook
#'+literate/compile-config) #'+literate/compile-config)
(unless (+literate/org-files-exist) (unless (+literate/output-files-exist)
(+literate/compile-config)) (+literate/compile-config))
(+literate/load-config) (+literate/load-config)