Skip to content

Balance spaces in braces#147

Merged
nmoroze merged 4 commits intonmoroze:mainfrom
vries:balance-spaces-in-braces-2
Feb 11, 2026
Merged

Balance spaces in braces#147
nmoroze merged 4 commits intonmoroze:mainfrom
vries:balance-spaces-in-braces-2

Conversation

@vries
Copy link
Contributor

@vries vries commented Feb 5, 2026

Currently this piece of code:

if {0} { }

is formatted by tclfmt as either (--spaces-in-braces=yes):

if { 0 } { }

or (--spaces-in-braces=no):

if {0} {}

Add a new 'balanced' mode in which the code is kept as is.

However, in this mode we still want to correct unbalanced space, for instance:

if { 0} {}

Since there are two possible ways to correct this, we introduce
--spaces-in-braces=balanced-yes and --spaces-in-braces=balanced-no.

With --spaces-in-braces=balanced-yes we get:

if { 0 } {}

and with --spaces-in-braces=balanced-no instead:

if {0} {}

Fixes issue:

@vries
vries committed

Copy link
Owner

@nmoroze nmoroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for converting this to a PR. I left a few comments after a closer look!

config_group.add_argument(
"--spaces-in-braces",
type=_argparsify(_validate_style_spaces_in_braces),
metavar="<yes|no|balanced-yes|balanced-no>",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing to nitpick on naming, what do you think of a set of names like: always|never|balanced-yes|balanced-no? I'm thinking "always" and "never" perhaps make the distinction between those two options and the "balanced" options more self-explanatory.

Copy link
Contributor Author

@vries vries Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it a bit better than the current scheme.

I'm proposing though to hash out the code parts first, and at the point that there are no more comments on the code, do the rename.

Copy link
Owner

@nmoroze nmoroze Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me! Happy to do the rename now, and then we can merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've done the rename.

Also I noticed that --no-spaces-in-braces still used store_false after the enum transition, so I've used store_const there now instead.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@vries vries force-pushed the balance-spaces-in-braces-2 branch 2 times, most recently from 8c1afb7 to ff25f2f Compare February 10, 2026 08:25
Introduce a new CLI syntax --spaces-in-braces=always/never, replacing
--spaces-in-braces/--no-spaces-in-braces.

At the CLI level, --no-spaces-in-braces is kept as alias of
--spaces-in-braces=never.

At the config file level, spaces-in-braces = true/false is also kept as alias
of spaces-in-braces = "always"/"never".

Consequently, no test-case update is required.
Change style_spaces_in_braces from bool to enum, in preparation of it having
more than two values.
Add --spaces-in-braces=balanced-yes/balanced-no, in addition to
--spaces-in-braces=always/never.

The options are used to set existing variable spaces_in_braces and new
variable balanced_spaces_in_braces like so:
```
-------------------------------------------------------------------
name		| spaces_in_braces	| balanced_spaces_in_braces
-------------------------------------------------------------------
never		| 0			| 0
always		| 1			| 0
balanced-no	| 0			| 1
balanced-yes	| 1			| 1
-------------------------------------------------------------------
```

Variable balanced_spaces_in_braces is unused in this commit, but will be used
in the following commmit.
Currently this piece of code:
```
if {0} { }
```
is formatted by tclfmt as either (--spaces-in-braces=always):
```
if { 0 } { }
```
or (--spaces-in-braces=never):
```
if {0} {}
```

Add a new 'balanced' mode in which the code is kept as is.

However, in this mode we still want to correct unbalanced space, for instance:
```
if { 0} {}
```

Since there are two possible ways to correct this, we introduce
--spaces-in-braces=balanced-yes and --spaces-in-braces=balanced-no.

With --spaces-in-braces=balanced-yes we get:
```
if { 0 } {}
```
and with --spaces-in-braces=balanced-no instead:
```
if {0} {}
```

Fixes issue:
- nmoroze#138
@vries vries force-pushed the balance-spaces-in-braces-2 branch from ff25f2f to 43f8685 Compare February 10, 2026 08:33
@nmoroze nmoroze merged commit 9ca8199 into nmoroze:main Feb 11, 2026
7 checks passed
@nmoroze
Copy link
Owner

nmoroze commented Feb 11, 2026

Thanks for getting this one over the finish line through a bunch of iterations!

I have a few local changes from a while back I want to dust off, and then I'm thinking of cutting another release (hopefully within the next ~week).

@vries vries deleted the balance-spaces-in-braces-2 branch February 11, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants