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.
TextMate auto-indents C and C++ in an unexpected way. To be specific, I would like to get:
This (1):
Or this (2):
Unfortunately, instead, I get this:
I figured out how to do this, and here are the necessary edits to the C indent rules:
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.