From f20a79207c4b6f243e6de029f5f0fffd81dc0c1c Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 15 Aug 2022 00:28:52 +0530 Subject: Track variables provided by certain features. We track the value of variables provided by certain features. This is so that we rebuild correctly when the user sets a configuration variable. * ennum.el: Require loadhist. (ennum-track-features, ennum-feature-hash): New variables. (ennum--feature-environment): New function. (ennum-exp): Include ennum-feature-hash in hash computation. (ennum-publish): Recompute ennum-feature-hash. --- ennum.el | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'ennum.el') diff --git a/ennum.el b/ennum.el index 31e5e5f..7161eeb 100644 --- a/ennum.el +++ b/ennum.el @@ -5,6 +5,7 @@ (require 'ox) (require 'seq) (require 'cl) +(require 'loadhist) (require 'map) (require 'memoize) (require 'simple-httpd) @@ -15,6 +16,14 @@ (defvar ennum-blog nil "Property list specifying ennum publish settings") +(defvar ennum-track-features + '(ennum ennum-html ennum-image ob-tangle org ox ox-html) + "List of features to track on expression evaluation.") + +(defvar ennum-feature-hash + nil + "List of hashes tracking current state of features.") + ;; TODO: Should the store have an absolute path to deal with directory ;; changes? Yes, since we ask for an absolute working directory, we ;; should. @@ -57,6 +66,28 @@ respectively by - and _, and the pad character = is optional." (insert file) (ennum--hash))) +(defun ennum--feature-environment (feature) + "Return hash of the current state of FEATURE. + +The returned hash is the hash of the file providing FEATURE, and +the current state of all its variables." + (pcase (feature-symbols feature) + (`(,file . ,entries) + (with-temp-buffer + ;; Print hash of file. + (print (ennum-file-hash file) (current-buffer)) + ;; Print variables and their values. + (dolist (variable entries) + (print (if (and (atom variable) + (boundp variable) + ;; Exclude `ennum-feature-hash' since it + ;; is meant to be changed on each run. + (not (eq variable 'ennum-feature-hash))) + (cons variable (symbol-value variable)) + variable) + (current-buffer))) + (ennum--hash))))) + (defun ennum--set-file-modes-recursively (directory directory-mode file-mode executable-file-mode) (chmod directory directory-mode) (seq-do (lambda (file) @@ -75,6 +106,7 @@ respectively by - and _, and the pad character = is optional." (with-temp-buffer (let ((print-length nil) (print-level nil)) + (print ennum-feature-hash (current-buffer)) (print closure (current-buffer))) (ennum--hash)) (ennum-setting :store)))) @@ -648,6 +680,9 @@ as keys. Keys are compared using `equal'." (defun ennum-publish () (interactive) + ;; Recompute feature hash. + (setq ennum-feature-hash + (seq-map 'ennum--feature-environment ennum-track-features)) (ennum-with-current-directory (ennum-setting :working-directory) (let* ((blog-title (ennum-setting :blog-title)) (posts (ennum-posts (ennum-setting :posts-directory))) -- cgit v1.2.3