Repository navigation
Indent a form on the line after its reader prefix - #155
Merged
bbatsov merged 1 commit intoOct 29, 2026
Merged
Conversation
This was referenced Oct 25, 2026
jasonjckn
force-pushed
the
fix-indent-after-reader-prefix
branch
from
October 25, 2026 03:13
67a8e51 to
0cf4eae
Compare
No indentation rule matched a form that starts on the line after its
reader prefix, as in
(swap! state assoc :n @
(:counter state))
so `indent-region' left such lines wherever they were. Indent the
form the way the prefixed form would be indented if it started the
line, in both the semantic and the fixed style. This is what
clojure-mode does.
bbatsov
force-pushed
the
fix-indent-after-reader-prefix
branch
from
October 29, 2026 06:09
0cf4eae to
4c32370
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a reader prefix (
@,',`,~,~@,#',#=) is at the end of a line and the form it applies to starts on the next line, no indentation rule matches that line.indent-regionthen leaves the line exactly where it was typed. Themainoutputs below are just the input, untouched.This PR adds a rule for that case, in both the semantic and the fixed style. The line is indented as if the prefixed form started there, which is what clojure-mode does.
Examples
Each example shows the result of
indent-regionwith default settings and alignment turned on (clojure-ts-align-forms-automatically/clojure-align-forms-automatically). Identical outputs are grouped under one heading.Deref of a form on the next line
clojure-mode, clojure-ts-mode with this PR:
clojure-ts-mode
main:A quoted vector on the next line
clojure-mode, clojure-ts-mode with this PR:
clojure-ts-mode
main:Unquote inside syntax-quote
clojure-mode, clojure-ts-mode with this PR:
`(let [y# ~ x] y#)clojure-ts-mode
main:`(let [y# ~ x] y#)Var quote as a map value
clojure-mode, clojure-ts-mode with this PR:
clojure-ts-mode
main:Tests
This PR adds two new specs,
should indent a form on the line after its reader prefix(semantic) and... in fixed style. They start from unindented text, becausewhen-indenting-itstarts from correctly indented text and so can't catch a line that is left alone. Both fail onmainand pass with this PR.How it was checked locally:
make all(Eldev: compile with warnings as errors, lint, indent check, tests) passes on Emacs 30.1 (the nix-emacs-ci build CI uses) and on 31.1.50, the closest local build to CI's snapshot.Notes
treesit-simple-indenton the prefix node to find the anchor and offset, so it gives the same result as any other rule would for that node. A function offset like this works in Emacs 30.1 (checked in itstreesit.el).#_is left out on purpose: clojure-ts-mode already treats it the way cljfmt does.Part of a series
This is one of 7 small, independent PRs, each fixing one problem found while making clojure-ts-mode format like clojure-mode. Each one is based on
mainand none depends on another. Some touch neighbouring lines inCHANGELOG.mdand the indentation tests, so once one is merged the others may need a quick rebase, which we're happy to do::blockformsclojure.test/arealignmentindent-regionleaving the last forms unalignedAbout this PR
The code, tests and this description were generated by an AI (Claude, by Anthropic), at @jasonjckn's request. Sorry for the PR spam: the fixes are split up so that each one can be accepted or rejected on its own instead of in one big change. If AI-generated contributions are a problem for this project, please feel free to close these PRs right away.
M-x checkdocand fixed any warnings in the code you've written.