feat(literate): indent output config with +pretty

This adds auto indenting of the generated config file, from the user's
literate config, when the +pretty flag is added to the literate module.
This commit is contained in:
Peter Farr 2025-08-14 11:37:56 -04:00
parent 751ac6134b
commit 4b3ef167aa
2 changed files with 18 additions and 2 deletions

View file

@ -13,7 +13,8 @@ tangled =$DOOMDIR/config.el=, by default, when ~$ doom sync~ is executed.
/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]]
** Module flags
/This module has no flags./
- +pretty ::
Applies auto indenting to output files after tangling
** Packages
/This module doesn't install any packages./

View file

@ -61,6 +61,8 @@
(and (+literate-tangle +literate-config-file
doom-module-config-file
doom-user-dir)
(when (modulep! +pretty)
(+literate-auto-indent))
(or (not noninteractive)
(exit! "__NOTANGLE=1 $@")))))
@ -101,7 +103,9 @@
(= 0 (process-exit-status process)))
(message "Tangled config.org sucessfully (took %.1fs)"
(- (float-time) +literate-tangle--async-proc-start-time))
(setq +literate-tangle--async-proc nil))
(setq +literate-tangle--async-proc nil)
(when (modulep! +pretty)
(+literate-auto-indent)))
((memq (process-status process) '(exit signal))
(pop-to-buffer (get-buffer " *tangle config*"))
(message "Failed to tangle config.org (after %.1fs)"
@ -150,6 +154,17 @@
(unless result
(set-window-configuration c))))))))
;;;###autoload
(defun +literate-auto-indent ()
"Indent the tangled config.el file according to lisp indenting rules."
(let ((dest-file (concat (file-name-sans-extension +literate-config-file) ".el")))
(when (file-exists-p dest-file)
(with-current-buffer (find-file-noselect dest-file)
(widen)
;; Set explicitly so indenting rules are correctly applied.
(emacs-lisp-mode)
(indent-region (point-min) (point-max))
(save-buffer)))))
;;
;;; Hooks