Discussion:
[TxMt] Re: Question about indentation
kruemelkeksfan
2018-09-19 14:34:13 UTC
Permalink
Hello and sorry for digging up this old thread. I have the same problem like
the original author (want to use Whitesmith and don't get the hang of those
regex(es?).

I therefore wanted to ask whether:

a)
This style can’t be expressed with the current classification patterns.
this has changed by now?

and/or

b) Whitesmith-style can't be (roughly) expressed by just increasing indent
after a line finishes with ')' instead of '{', '}' or ';' and decreasing it
after a line with a lone '}'? It doesn't need to be 100% accurate, a crude
approximation for not having to type every single indent would be good
enough for me...



--
Sent from: http://textmate.1073791.n5.nabble.com/textmate-users-f3.html
Allan Odgaard
2018-10-21 07:15:11 UTC
Permalink
Post by kruemelkeksfan
a)
This style can’t be expressed with the current classification
patterns.
this has changed by now?
No, I don’t recall there having been made any changes to support
https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_style
Post by kruemelkeksfan
b) Whitesmith-style can't be (roughly) expressed by just increasing indent
after a line finishes with ')' instead of '{', '}' or ';' and
decreasing it
after a line with a lone '}'? It doesn't need to be 100% accurate, a crude
approximation for not having to type every single indent would be good
enough for me...
You can make it increase indent after `)` (or maybe just lines not
ending with `;` or braces), but the decrease indent pattern includes
current line, so that would fail.

There would also be an issue with single line `if`, `for`, and `while`
statements.

With the above, you end up with patterns like this:

{ increaseIndentPattern = '(?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
';
decreaseIndentPattern = '(?x)
(?=not)possible
';
indentNextLinePattern = '(?x)^
(?=not)possible
';
unIndentedLinePattern =
'^\s*((/\*|\*/|//|template\b.*?>(?!\(.*\))|@protocol|@optional|@interface(?!.*\{)|@implementation|@end).*)?$';
zeroIndentPattern = '^\s*#';
}

I just disabled `decreaseIndentPattern` and `indentNextLinePattern`,
plus made `increaseIndentPattern` use the pattern from the previous
`indentNextLinePattern` pattern.

Additionally you would have to edit the _Return Inside Empty Item_
snippet in the source bundle. This triggers when you press return with
insertion point between two braces, i.e. `{‾}` — adding `- source.c`
to the scope selector should disable that for C.

Still, you may see TextMate’s indent corrector sometimes changing the
indent of the current line, because the patterns does not correctly
express how source should be indented.

The latter can be disabled by setting `disableIndentCorrections =
:true;` for `source.c`.

Loading...