Add opt-in options for a compact multiline formatting style#7
Open
sw1sh wants to merge 2 commits into
Open
Conversation
Seven options, all defaulting to the current behavior so existing output and
tests are unchanged (best used together, with BreakLinesMethod ->
"LineBreakerV2"):
- "KeepBindingsInline": decide the scoping/control break on the leading-line
width (head + binding list / condition) rather than the max width, so a long
body line does not force a short binding list / condition onto its own line.
- "SpaceAfterControlOpener": `If[ cond,` so the condition aligns with branches.
- "GlueAssignmentRHS": keep an assignment RHS on the operator line
(`f := Block[{`), for top-level and inner Set / SetDelayed / UpSet / ... .
- "TrailingCommas": comma at the end of a single-line element; on its own line
only when an element is multiline.
- "InlineShortControl": a control structure that fits on one line and whose
branches are all single-line stays inline (`If[a, b, c]`).
- "SpaceAfterPrefixNot": `! cond`.
- "SpaceAroundPatternOperators": space Pattern (:), Optional (:), and
PatternTest (?) like ordinary operators; MessageName (::) and Power (^) stay
tight.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
12 tests covering each option (KeepBindingsInline on/off, SpaceAfterControlOpener, GlueAssignmentRHS for Set/SetDelayed and inner assignments, TrailingCommas single-line and multiline-boundary, InlineShortControl, SpaceAfterPrefixNot, SpaceAroundPatternOperators) and a combined case. The existing suite is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
426f163 to
a90524b
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.
Summary
Adds seven opt-in options that together produce a compact, consistent multiline
style (one element per line, never a mid-expression wrap), best used with
BreakLinesMethod -> "LineBreakerV2". All seven default to the currentbehavior, so existing output and the test suite are unchanged.
These came out of formatting a real paclet to a house style that the existing
options could not express.
Options
"KeepBindingsInline"— decide whether a scoping (Module/Block/With/Function) or control (If/Switch/Which/...) construct must explode basedon the width of its leading line (head + binding list / condition, e.g.
Block[{a, b},) rather than the maximum width of the whole construct. A longbody line no longer forces a short binding list / condition onto its own line.
"SpaceAfterControlOpener"— insert a space after the opener of a multilinecontrol structure so the condition lines up with the branches (
If[ cond,)."GlueAssignmentRHS"— keep the RHS of an assignment (Set,SetDelayed,UpSet, ...) on the operator line (f := Block[{) instead of breaking afterthe operator. Applies to top-level and inner assignments.
"TrailingCommas"— when breaking a comma-separated sequence whose elementsare all single-line, keep the comma at the end of the element line; when an
element is multiline, the comma stays on its own line as a boundary marker.
"InlineShortControl"— a control structure that fits withinLineWidthand whose branches are all single-line stays on one line (
If[a, b, c])instead of always breaking.
"SpaceAfterPrefixNot"— insert a space after a prefixNot(! cond)."SpaceAroundPatternOperators"— spacePattern(:),Optional(:),and
PatternTest(?) like ordinary operators (name : pat,x_ ? NumericQ);MessageName(::) andPower(^) stay tight.Example (all options on,
LineWidth -> 60):Tests
Adds
Tests/GuideStyle.mt(12 tests) covering each option and a combined case.The existing suite is unchanged (the new options default off).
Notes
Implementation is localized to the scoping/control indenters, the prefix and
operator/comma renderers, and the pattern-operator spacing rule in
Indent.wl,plus option plumbing in
CodeFormatter.wl. Each option is gated, so defaultformatter output is unchanged.
🤖 Generated with Claude Code