Skip to content

Conversation

@errmayank
Copy link
Contributor

@errmayank errmayank commented Oct 31, 2025

Closes #41179

Release Notes:

  • Fixed indentation for if/else statements in C/C++ without braces

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 31, 2025
@errmayank errmayank changed the title languages: Fix C indentation for if/else statements without braces languages: Fix indentation for if/else statements in C without braces Oct 31, 2025
@teowelton
Copy link
Contributor

Hey!

I was also working on this today, but forgot to comment on the issue, so no worries at all. I would just like to point out that this applies to C++ as well (as the original example showed).

Also, feel free to let me know if there was an error in what I was doing, but I ended up solving this by just modifying this:

{ pattern = "^\\s*else\\s*$", valid_after = ["if"] }

To be:

{ pattern = "^\\s*else\\b", valid_after = ["if"] }

(for both C & C++), thus not needing to modify indents.scm at all, and passing all tests.

Thoughts?

@errmayank
Copy link
Contributor Author

Hey @teowelton, I tested your way and it works great, thanks!

I've also updated this PR as it requires minimal changes that way.

I would just like to point out that this applies to C++ as well (as the original example showed).

Yeah, I was hoping to create a separate PR for C++ but maybe you can do that?

@teowelton
Copy link
Contributor

teowelton commented Nov 2, 2025

Yeah, I was hoping to create a separate PR for C++ but maybe you can do that?

I think that in this case having both in the same PR is much cleaner, since they fall under the same issue. The solution is the same too, simply modifying the config.toml file for C++ instead of C:

{ pattern = "^\\s*else\\s*$", valid_after = ["if"] }

@errmayank errmayank changed the title languages: Fix indentation for if/else statements in C without braces languages: Fix indentation for if/else statements in C/C++ without braces Nov 2, 2025
@errmayank
Copy link
Contributor Author

@teowelton makes sense

@osiewicz osiewicz merged commit d32934a into zed-industries:main Nov 17, 2025
24 checks passed
osiewicz pushed a commit that referenced this pull request Nov 17, 2025
Related to #41670

Release Notes:

- Cleaned up invalid init calls after recent API changes in
#42238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong indentation for else block in C++.

3 participants