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 #68

Open
theosib opened this issue Jan 13, 2016 · 2 comments

Comments

@theosib
Copy link

theosib commented Jan 13, 2016

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 looked into this, and I understand that the Swift indent rules would behave as I expect. I'm told that I can edit the indentation rules, but for C, I don't see the word "select" mentioned anywhere in the indentation rules, so this is confusing to me. My opinion is that (1) or (2) should be default, but at the very least, documentation somewhere about how to change them to fix this specific case would be really nice.

@theosib
Copy link
Author

theosib commented Jan 13, 2016

Ok, I figured out that the C indentation rules just don't mention switch/case or anything. I compared to Swift, and I edited C rules to be this:

{   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.

@carpii
Copy link

carpii commented May 29, 2016

@theosib You posted this as an issue for Textmates PHP bundle.

You might have more luck if you post it to their C bundle repo.. https://github.com/textmate/c.tmbundle/issues

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

2 participants