aboutsummaryrefslogtreecommitdiff
path: root/format.el
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2026-04-18 05:59:07 +0100
committerGene Pasquet <dev@etenil.net>2026-04-18 05:59:07 +0100
commit84f251ee6e829d33a4f29aa4043924023a378724 (patch)
treeab03d18fa192303bf2e1758743ac16c11d9da87f /format.el
parentc2085be2dd2a0cb3da05991847e35080915e547e (diff)
Re-format
Diffstat (limited to 'format.el')
-rw-r--r--format.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/format.el b/format.el
new file mode 100644
index 0000000..48c2df6
--- /dev/null
+++ b/format.el
@@ -0,0 +1,50 @@
+;;; format.el — batch scheme formatter for downstroke.
+;;;
+;;; Reformats every tracked .scm file using `indent-region` under
+;;; `scheme-mode`, with the user's full Emacs init loaded so the indent
+;;; rules match exactly what interactive Emacs does (notably the
+;;; geiser-chicken / scheme-mode `module` indent).
+;;;
+;;; Usage (from the Makefile):
+;;; make format
+;;;
+;;; Or directly:
+;;; emacs --batch \
+;;; --init-directory=$HOME/.emacs-perso \
+;;; --eval "(add-to-list 'load-path (expand-file-name \"emacs-substrate/\" \"~/.emacs-perso\"))" \
+;;; -l ~/.emacs-perso/init.el \
+;;; -l format.el \
+;;; --eval "(downstroke-format-tracked-scm-files)"
+
+(require 'subr-x)
+
+(defun downstroke--project-root ()
+ "Directory containing this script — the downstroke project root."
+ (file-name-directory (or load-file-name buffer-file-name default-directory)))
+
+(defun downstroke--tracked-scm-files ()
+ "Return a list of all .scm files tracked by git in the project."
+ (let ((default-directory (downstroke--project-root)))
+ (split-string
+ (string-trim
+ (shell-command-to-string "git ls-files -- '*.scm'"))
+ "\n" t)))
+
+(defun downstroke-format-file (path)
+ "Reformat a single .scm file with `indent-region'."
+ (let ((inhibit-message t))
+ (find-file path)
+ (scheme-mode)
+ (indent-region (point-min) (point-max))
+ (save-buffer)
+ (kill-buffer)))
+
+(defun downstroke-format-tracked-scm-files ()
+ "Reformat every tracked .scm file in the project."
+ (let ((default-directory (downstroke--project-root))
+ (files (downstroke--tracked-scm-files)))
+ (message "downstroke-format: reindenting %d files" (length files))
+ (dolist (p files)
+ (message "indent: %s" p)
+ (downstroke-format-file p))
+ (message "downstroke-format: done")))