[TxMt] Indentation of switch/case blocks
Trevor Harmon
trevor at vocaro.com
Wed Apr 19 03:38:21 UTC 2006
On Apr 18, 2006, at 6:15 PM, Allan Odgaard wrote:
>> [ switch/case ] I believe this is a pretty standard formatting
>> convention.
>
> Yes, along with putting brackets around the code,
I don't see why that should be a problem. In Xcode, for instance, if
you open a C file and start typing a switch/case block, it will
indent after you type the case clause and hit Return. Then, if you
type an open brace, it will automatically *unindent* for you.
Couldn't TextMate do the same thing?
> keeping the break at same indent as the case,
Hmm, I've never seen that one. Do people actually do that? (Xcode
doesn't handle it, either.)
> putting the break inside the brackets, etc. :)
This is handled correctly by Xcode. It automatically unindents the
closing brace when you type it.
>> [...] I was hoping it could be smart about indenting switch/case
>> blocks, too. Is that possible? Perhaps there is something I could
>> add to the language definition?
>
> While the indenting rules can be controlled [1], it does not have
> enough flexibility to work with switch/case statements.
>
> [1] http://macromates.com/textmate/manual/appendix#indentation_rules
Hmm, maybe increaseIndentPattern isn't powerful enough to give Xcode-
like behavior to switch/case blocks, but I think it can be hacked
enough to make me happy. I went to the C bundle's Indentation Rules
and appended this to increaseIndentPattern:
|case.*:
That seems to give exactly the behavior I want. (I never need to put
braces in my case blocks.) I also added source.java to the Scope
Selector so that this would work in Java files.
Trevor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2363 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20060418/2f2697fc/attachment.p7s>
More information about the textmate
mailing list