[TxMt] Re: Question about indentation

Allan Odgaard mailinglist at textmate.org
Sun Oct 21 07:15:11 UTC 2018


On 19 Sep 2018, at 21:34, kruemelkeksfan wrote:

> a)
>
> Allan Odgaard wrote
>> 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

> 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`.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20181021/7310a028/attachment.html>


More information about the textmate mailing list