Skip to content

Commit

Permalink
Add linter for Elisp indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
raxod502 committed Dec 30, 2023
1 parent aa63b06 commit a822072
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
SHELL := bash

VERSION ?=
CMD ?=

longlines_files := $(shell find . -name .git -prune -o -print)
for_checkindent := $(shell find . -name .git -prune -o -name '*.el' -print)

.PHONY: help
help: ## Show this message
Expand Down Expand Up @@ -32,12 +35,32 @@ checkdoc: ## Check docstring style in radian.el
longlines: ## Check for long lines
@scripts/check-line-length.bash

.PHONY: checkindent
checkindent: ## Ensure that indentation is correct
@tmpdir="$$(mktemp -d)"; for file in $(for_checkindent); do \
emacs -Q --batch \
-l scripts/radian-indent.el \
--eval "(setq inhibit-message t)" \
--eval "(progn \
(setq straight-safe-mode t) \
(load (expand-file-name \"init.el\" \
user-emacs-directory) nil t))" \
--eval "(find-file \"$$file\")" \
--eval "(indent-region (point-min) (point-max))" \
--eval "(write-file \"$$tmpdir/indented.el\")"; \
(diff <(cat "$$file" | nl -v1 -ba | \
sed "s/\t/: /" | sed "s|^ *|$$file:|") \
<(cat "$$tmpdir/indented.el" | nl -v1 -ba | \
sed "s/\t/: /" | sed "s|^ *|$$file:|") ) \
| grep -F ">" | grep -o "[a-z].*" | grep . && exit 1 || true; \
done

.PHONY: validate
validate: ## Validate el-patches
@scripts/validate-patches.bash

.PHONY: lint
lint: build compile validate checkdoc longlines ## Run all linters
lint: build compile validate checkdoc longlines checkindent ## Run all linters

.PHONY: clean
clean: ## Remove build artifacts
Expand Down
10 changes: 10 additions & 0 deletions scripts/radian-indent.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; This file has code that is evaluated in CI before the indentation
;; of Radian is checked. This is helpful because it allows us to
;; ensure that various things are indented correctly if they require
;; some setup for Emacs to know how to do the right thing.

;; The indentation of `define-key' has for some reason changed in
;; Emacs 29 when it was deprecated in favor of `keymap-set'. Maybe
;; that is a bug and they will change it, but for now, force the
;; indentation to the backwards-compatible version.
(put #'define-key 'lisp-indent-function 'defun)

0 comments on commit a822072

Please sign in to comment.