config/literate: improve tangling algorithm
- Tangling no longer adds temp files to recentf (#3685) - If :tangle yes is used, the result is no longer tangled to /tmp/config.org.*.el - In interactive sessions the org buffer is no longer interfered with when tangling (by scrolling up to the top of the page, or undoing overlays/markers). - Tangling no longer triggers formatters (or any save/write hooks). - Appease byte-compiler sama, complaining about free variables.
This commit is contained in:
parent
aae8203f86
commit
d2bc2ff44b
2 changed files with 52 additions and 26 deletions
|
@ -18,6 +18,9 @@
|
||||||
(require 'core-packages)
|
(require 'core-packages)
|
||||||
(doom-initialize-core-packages)
|
(doom-initialize-core-packages)
|
||||||
|
|
||||||
|
;; Don't generate superfluous files when writing temp buffers
|
||||||
|
(setq make-backup-files nil)
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Variables
|
;;; Variables
|
||||||
|
|
|
@ -9,41 +9,64 @@
|
||||||
"The file path that `+literate-config-file' will be tangled to, then
|
"The file path that `+literate-config-file' will be tangled to, then
|
||||||
byte-compiled from.")
|
byte-compiled from.")
|
||||||
|
|
||||||
|
(defvar org-mode-hook)
|
||||||
|
(defvar org-inhibit-startup)
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +literate-tangle-h ()
|
(defun +literate-tangle-h ()
|
||||||
"Tangles `+literate-config-file' if it has changed."
|
"Tangles `+literate-config-file' if it has changed."
|
||||||
(print! (start "Compiling your literate config..."))
|
(print! (start "Compiling your literate config..."))
|
||||||
(print-group!
|
(print-group!
|
||||||
(let* ((default-directory doom-private-dir)
|
(let* ((default-directory doom-private-dir)
|
||||||
(org (expand-file-name +literate-config-file))
|
(org (expand-file-name +literate-config-file))
|
||||||
(dest (concat (file-name-sans-extension +literate-config-file) ".el"))
|
(dest (concat (file-name-sans-extension +literate-config-file) ".el")))
|
||||||
;; Operate on a copy because `org-babel-tangle' has side-effects we
|
(and (require 'ox)
|
||||||
;; don't want to impose on the User's config permanently.
|
(require 'ob-tangle)
|
||||||
(backup (make-temp-file (concat (file-name-nondirectory org) "."))))
|
(letf! (;; Operate on a copy because `org-babel-tangle' has
|
||||||
(unwind-protect
|
;; side-effects we need to undo immediately as not to
|
||||||
(and (require 'ox)
|
;; overwrite the user's config; it's bad ettiquite.
|
||||||
(require 'ob-tangle)
|
(backup (make-temp-file (concat (file-name-nondirectory org) ".")))
|
||||||
(letf! ((defun message (msg &rest args)
|
;; A hack to prevent ob-tangle from operating relative to the
|
||||||
(when msg
|
;; backup file and thus tangling to the wrong destinations.
|
||||||
(print! (info "%s") (apply #'format msg args))))
|
(defun org-babel-tangle-single-block (&rest args)
|
||||||
;; Prevent infinite recursion due to recompile-on-save
|
(let* ((spec (apply org-babel-tangle-single-block args))
|
||||||
;; hooks later.
|
(file (nth 1 spec))
|
||||||
(org-mode-hook nil))
|
(file (if (file-equal-p file backup) org file))
|
||||||
;; Tangling won't ordinarily expand #+INCLUDE directives, and it
|
(file (if org-babel-tangle-use-relative-file-links
|
||||||
;; modifies the buffer so we must do it in a copy to prevent
|
(file-relative-name file)
|
||||||
;; stepping on the user's toes.
|
file)))
|
||||||
|
(setf (nth 1 spec) file)
|
||||||
|
spec))
|
||||||
|
;; Ensure output conforms to the formatting of all doom CLIs
|
||||||
|
(defun message (msg &rest args)
|
||||||
|
(when msg
|
||||||
|
(print! (info "%s") (apply #'format msg args)))))
|
||||||
|
(unwind-protect
|
||||||
(with-temp-file backup
|
(with-temp-file backup
|
||||||
|
(insert-file-contents org)
|
||||||
(let ((buffer-file-name backup)
|
(let ((buffer-file-name backup)
|
||||||
(org-inhibit-startup t)
|
;; Prevent unwanted entries in recentf, or formatters, or
|
||||||
org-mode-hook)
|
;; anything that could be on these hooks, really. Nothing
|
||||||
(insert-file-contents org)
|
;; else should be touching these files (particularly in
|
||||||
|
;; interactive sessions).
|
||||||
|
(write-file-functions nil)
|
||||||
|
(before-save-hook nil)
|
||||||
|
(after-save-hook nil)
|
||||||
|
;; Prevent infinite recursion due to recompile-on-save
|
||||||
|
;; hooks later, and speed up `org-mode' init.
|
||||||
|
(org-mode-hook nil)
|
||||||
|
(org-inhibit-startup t))
|
||||||
(org-mode)
|
(org-mode)
|
||||||
(org-export-expand-include-keyword)
|
(with-silent-modifications
|
||||||
(org-babel-tangle nil dest)))
|
;; Tangling won't ordinarily expand #+INCLUDE directives,
|
||||||
t)
|
;; so I do it myself.
|
||||||
;; Write an empty file to serve as our mtime cache
|
(org-export-expand-include-keyword)
|
||||||
(with-temp-file +literate-config-cache-file))
|
(org-babel-tangle nil dest))))
|
||||||
(ignore-errors (delete-file backup))))))
|
(ignore-errors (delete-file backup)))
|
||||||
|
;; Write an empty file to serve as our mtime cache
|
||||||
|
(with-temp-file +literate-config-cache-file)
|
||||||
|
t)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(add-hook 'org-mode-hook #'+literate-enable-recompile-h)
|
(add-hook 'org-mode-hook #'+literate-enable-recompile-h)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue