From 711dcf5e2d592271e0939c205ba33dbd93a4d547 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 24 Apr 2024 04:00:41 +0530 Subject: (Emacs/literate)~reworked literate to only compile if necessary Speeds up boot and kill. Actually checks for timestamps and logical errors are removed. --- Emacs/.config/emacs/elisp/literate.el | 144 +++++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 44 deletions(-) (limited to 'Emacs/.config/emacs/elisp/literate.el') diff --git a/Emacs/.config/emacs/elisp/literate.el b/Emacs/.config/emacs/elisp/literate.el index 114c3bb..077de93 100644 --- a/Emacs/.config/emacs/elisp/literate.el +++ b/Emacs/.config/emacs/elisp/literate.el @@ -24,6 +24,16 @@ ;;; 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) (if (null list) nil @@ -39,70 +49,116 @@ (defun +literate/el-p (filename) (string= "el" (file-name-extension filename))) +(defun +literate/--reduce-bool (bools init) + (if (= (length bools) 0) + init + (+literate/--reduce-bool (cdr bools) (and (car bools) init)))) + +;; Files (defconst +literate/org-files (+literate/filter #'+literate/org-p (mapcar #'(lambda (file) (concat user-emacs-directory file)) - (cddr (directory-files user-emacs-directory))))) + (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 +(defconst +literate/el-init-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/"))))))) + ,(concat user-emacs-directory "init.el"))) -;; Setup predicates and loading +(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/")))))) -(defun +literate/--reduce-bool (bools init) - (if (= (length bools) 0) - init - (+literate/--reduce-bool (cdr bools) (and (car bools) init)))) +(defconst +literate/el-org-files + (mapcar #'+literate/org-to-el +literate/org-files)) -(defun +literate/output-files-exist () - "Checks if output files exist, for compilation purposes." - (if (< 1 (length +literate/output-files)) - (+literate/--reduce-bool (mapcar #'file-exists-p +literate/output-files) t) - (file-exists-p (car +literate/output-files)))) +(defconst +literate/el-files + (cl-concatenate + 'list + +literate/el-init-files + +literate/el-lib-files + +literate/el-org-files)) -(defun +literate/load-config () - "Load the first file in +literate/output-files." - (interactive) - (load-file (concat user-emacs-directory "config.el"))) +(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") (defun +literate/tangle-if-old (org-file) - (let ((output-file (replace-regexp-in-string ".org" ".el" org-file))) - (message "Tangle(%s)->%s" org-file output-file) - (if (or (not (file-exists-p output-file)) (file-newer-than-file-p org-file output-file)) - (org-babel-tangle-file org-file)))) + (let ((output-file (+literate/org-to-el org-file))) + (when (file-newer-than-file-p org-file output-file) + (message "[Literate]:\tTangle(%s)->%s" 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)))) + (let ((output-file (+literate/el-to-elc el-file))) + (when (file-newer-than-file-p el-file output-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 () "Compile all files in +literate/org-files via org-babel-tangle." (interactive) - (message "Compiling files...") - (mapc #'+literate/tangle-if-old +literate/org-files) - (message "Files compiled") - - (message "Byte-compiling literate files...") - (mapc #'+literate/byte-compile-if-old +literate/output-files) - (message "Literate files byte-compiled") - (message "Byte compiling init.el, early-init.el, *.org~>*.el elisp/*") - (mapc #'+literate/byte-compile-if-old +literate/elisp-files) - (message "Finished byte-compiling")) + (message "[Literate]: Starting compilation...") + (+literate/compile-init-files) + (+literate/compile-lib-files) + (+literate/compile-org-files) + (message "[Literate]: Finished compilation!")) + +;; Cleaning config +(defun +literate/clean-config () + "Removes all .el files generated by literate org files and .elc +files by byte compilation" + (interactive) + (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) ;;; literate.el ends here -- cgit v1.2.3-13-gbd6f From 89cc78f476ada3f3cf1f125c5c9b4e9b3e215d59 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 7 May 2024 00:14:32 +0530 Subject: (Emacs/elisp)+bytecompile? option to literate So if you don't want to, say while debugging, it won't. --- Emacs/.config/emacs/elisp/literate.el | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'Emacs/.config/emacs/elisp/literate.el') diff --git a/Emacs/.config/emacs/elisp/literate.el b/Emacs/.config/emacs/elisp/literate.el index 077de93..ffd4963 100644 --- a/Emacs/.config/emacs/elisp/literate.el +++ b/Emacs/.config/emacs/elisp/literate.el @@ -92,6 +92,9 @@ (defconst +literate/elc-org-files (mapcar #'+literate/org-to-elc +literate/org-files)) +(defvar +literate/bytecompile? t + "Bytecompile all files?") + ;; Basic compilation and loading files (autoload #'org-babel-tangle-file "ob-tangle") @@ -119,22 +122,25 @@ ;; 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) + (when +literate/bytecompile? + (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) + (when +literate/bytecompile? + (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!")) + (when +literate/bytecompile? + (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 () "Compile all files in +literate/org-files via org-babel-tangle." -- cgit v1.2.3-13-gbd6f From 6aa3c170e93ea9a88b16816a3396778def524a01 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sat, 11 May 2024 13:05:41 +0530 Subject: (Emacs/*)~clean up text, change license of elisp packages to GPLv2 strictly --- Emacs/.config/emacs/elisp/literate.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Emacs/.config/emacs/elisp/literate.el') diff --git a/Emacs/.config/emacs/elisp/literate.el b/Emacs/.config/emacs/elisp/literate.el index ffd4963..5039446 100644 --- a/Emacs/.config/emacs/elisp/literate.el +++ b/Emacs/.config/emacs/elisp/literate.el @@ -5,10 +5,9 @@ ;; Author: Aryadev Chavali ;; Keywords: -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License version +;; 2 as published by the Free Software Foundation. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit v1.2.3-13-gbd6f From 8fcdfac6614e1ea84f2bfd100b5713ce7dce2db0 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 13 May 2024 16:58:28 +0530 Subject: (Emacs)~Merged app.org, lang.org and core.org back into config.org Just makes it easier to profile and deal with compilation --- Emacs/.config/emacs/elisp/literate.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Emacs/.config/emacs/elisp/literate.el') diff --git a/Emacs/.config/emacs/elisp/literate.el b/Emacs/.config/emacs/elisp/literate.el index 5039446..43c39d8 100644 --- a/Emacs/.config/emacs/elisp/literate.el +++ b/Emacs/.config/emacs/elisp/literate.el @@ -55,10 +55,8 @@ ;; Files (defconst +literate/org-files - (+literate/filter - #'+literate/org-p - (mapcar #'(lambda (file) (concat user-emacs-directory file)) - (cddr (directory-files user-emacs-directory))))) + (mapcar #'(lambda (x) (expand-file-name (concat user-emacs-directory x))) + (list "config.org"))) (defconst +literate/el-init-files `(,(concat user-emacs-directory "early-init.el") -- cgit v1.2.3-13-gbd6f