From 7757fc171927a4189901ba56bad167688a145b0e Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Tue, 10 Feb 2026 22:42:50 -0800 Subject: [PATCH] emacs: retangle org config when any generated file is stale --- dotfiles/emacs.d/README.org | 25 ++++++++++++++++++++----- dotfiles/emacs.d/org-config.org | 5 ++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 9c0b45c3..a4df355d 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -2950,11 +2950,26 @@ My org-mode configuration now lives in its own file org-config.org. #+BEGIN_SRC emacs-lisp (let* ((org-config (expand-file-name "org-config.org" user-emacs-directory)) (org-config-el (expand-file-name "org-config.el" user-emacs-directory))) - (when (file-newer-than-file-p org-config org-config-el) - ;; Tangle all outputs so org-config-bind.el/org-config-config.el are fresh. - (org-babel-tangle-file org-config) - (when (file-exists-p org-config-el) - (set-file-times org-config-el))) + (let* ((outputs (mapcar (lambda (f) (expand-file-name f user-emacs-directory)) + '("org-config.el" + "org-config-preface.el" + "org-config-custom.el" + "org-config-bind.el" + "org-config-config.el"))) + (needs-tangle nil)) + ;; Tangle if any output is missing or stale. This is more robust than only + ;; checking org-config.el, since tangling can update some outputs without + ;; touching org-config.el's contents. + (dolist (f outputs) + (when (or (not (file-exists-p f)) + (file-newer-than-file-p org-config f)) + (setq needs-tangle t))) + (when needs-tangle + (org-babel-tangle-file org-config) + ;; Prevent re-tangling on every startup when files are unchanged. + (dolist (f outputs) + (when (file-exists-p f) + (set-file-times f))))) (load-file org-config-el)) #+END_SRC *** TeX diff --git a/dotfiles/emacs.d/org-config.org b/dotfiles/emacs.d/org-config.org index 54b2fe63..f5fca237 100644 --- a/dotfiles/emacs.d/org-config.org +++ b/dotfiles/emacs.d/org-config.org @@ -1,3 +1,5 @@ +#+PROPERTY: header-args:emacs-lisp :tangle org-config-config.el + * include-file-as-forms We're going to use this to write separate parts of our config to different sections that will then be provided to our use package statment #+begin_src emacs-lisp :tangle org-config.el @@ -775,7 +777,8 @@ SCHEDULED: %^t 'org-babel-load-languages '((mermaid . t)))) #+end_src ** frame-mode handling -Note that this does not go into org-config-config.el. This is on purpose +This block is part of the runtime config. It is tangled via the default +`header-args:emacs-lisp` for this file (see the `#+PROPERTY` near the top). #+begin_src emacs-lisp (use-package org :ensure nil