Repository navigation
Align the whole region in clojure-ts-indent-region - #159
Merged
bbatsov merged 1 commit intoOct 29, 2026
Merged
Conversation
This was referenced Oct 25, 2026
jasonjckn
force-pushed
the
fix-indent-region-align-to-region-end
branch
from
October 25, 2026 03:13
5aab3be to
62fa2a4
Compare
3 of 4 tasks
clojure-ts-indent-region indents the region, then aligns it up to the END it was given. Indenting adds whitespace, so the region's real end moves, but the align step still stopped at the old position, leaving forms at the end of the region unaligned. A second indent-region then aligned them, which is why formatting a file twice changed it. Keep END as a marker so the align step uses where the region ends after indenting.
bbatsov
force-pushed
the
fix-indent-region-align-to-region-end
branch
from
October 29, 2026 06:13
62fa2a4 to
5d18ce8
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.
clojure-ts-indent-regionfirst indents the region, then aligns forms in it up to the region's original END. But indenting usually adds whitespace, so by the time the align step runs, the region really ends further on. Forms in that last stretch don't get aligned. Runningindent-region(or a formatter built on it) a second time aligns them, which is why formatting a file twice could change it again.This PR keeps END as a marker, so the align step uses the region's end after indenting. One pass now gives what two passes gave before.
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.Several aligned forms; only the last one is left unaligned
One pass with clojure-mode or clojure-ts-mode
main:A second pass with clojure-mode or clojure-ts-mode
main, or one pass with this PR:A deeply nested function followed by a short case
One pass with clojure-mode or clojure-ts-mode
main:A second pass with clojure-mode or clojure-ts-mode
main, or one pass with this PR:A test namespace ending with a short cond->
One pass with clojure-mode or clojure-ts-mode
main:A second pass with clojure-mode or clojure-ts-mode
main, or one pass with this PR:clojure-mode's
indent-regionhas the same one-pass behaviour, as the first and second outputs show. This PR fixes it for clojure-ts-mode only.Tests
This PR adds a new spec,
should align the forms at the end of the region after reindenting. It fails onmainand passes 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
mainand then formatting again changes 23 of 146 inputs (73 real-world files as-is, plus the same files with indentation stripped). With this PR, none change.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 unaligned (this PR)About 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.