Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting update to C/C++ indentation rules for more common switch statement formatting #78

Open
theosib opened this issue Oct 25, 2023 · 0 comments

Comments

@theosib
Copy link

theosib commented Oct 25, 2023

TextMate auto-indents C and C++ in an unexpected way. To be specific, I would like to get:

This (1):

switch (x) {
    case 3:
        sdrhit;
    case 4:
        dfsdkfsd;
}

Or this (2):

switch (x) {
case 3:
    sdrhit;
case 4:
    dfsdkfsd;
}

Unfortunately, instead, I get this:

switch (x) {
    case 3:
    sdrhit;
    case 4:
    dfsdkfsd;
}

I figured out how to do this, and here are the necessary edits to the C indent rules:

{   increaseIndentPattern = '(?x)
        ^ .* \{ [^}"'']* $
    |   ^ \s* (public|private|protected): \s* $
    |   ^ \s* @(public|private|protected) \s* $
    |   ^ \s* \{ \} $
    |   ^ \s* (case\b .+ |default):     # NEW!
    ';
    decreaseIndentPattern = '(?x)
        ^ \s* ( (?! \S.* /[*] ) .* [*]/ \s* )? \}
    |   ^ \s* (public|private|protected): \s* $
    |   ^ \s* @(public|private|protected) \s* $
    |   (case\b .+ |default): \s* (/[/*] .*)? $     # NEW!
    ';
    indentNextLinePattern = '(?x)^
        (?! .* [;:{},] \s*                  # do not indent when line ends with ;, :, {, }, or comma
            ( // .* | /[*] .* [*]/ \s* )? $ #  …account for potential trailing comment
        |   @(public|private|protected)     # do not indent after obj-c data access keywords
        )
        .                                  # the negative look-ahead above means we don’t care about what we match here
    ';
    unIndentedLinePattern = '^\s*((/\*|\*/|//|template\b.*?>(?!\(.*\))|@protocol|@optional|@interface(?!.*\{)|@implementation|@end).*)?$';
    zeroIndentPattern = '^\s*#';
}

Even if the devs don't want to make this the default, anyone else encountering this problem could refer to this bug report if they want to change it themselves.

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

No branches or pull requests

1 participant