;;; 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")))