#!/usr/bin/env bash # Validate emacs.el by loading it in a batch Emacs. # Run this before committing changes to your config. # # PASS = file loads with exit 0 and no errors. # Warnings are shown but do not fail the check. set -uo pipefail REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" INIT="$REPO_DIR/emacs.el" OUTPUT=$(mktemp) trap 'rm -f "$OUTPUT"' EXIT timeout 180 emacs --batch -l "$INIT" >"$OUTPUT" 2>&1 STATUS=$? echo "--- emacs --batch -l emacs.el (exit $STATUS) ---" cat "$OUTPUT" echo "--- end output ---" ERRORS=$(grep -cE "^(Error|error|Cannot open|File mode specification error)" "$OUTPUT") WARNINGS=$(grep -c "^Warning" "$OUTPUT" || true) if [ "$STATUS" -eq 0 ] && [ "$ERRORS" -eq 0 ]; then echo "PASS: config loads cleanly ($WARNINGS warning(s))" exit 0 else echo "FAIL: config has errors (see output above)" exit 1 fi