Home Download Buy Blog Forum Support

BUG: One-line ifs indentation

BUG: One-line ifs indentation

Postby eduardische on Tue Jun 26, 2012 5:01 pm

When I have only one command for if to execute, I often write it on the same line as the condition and without any { } brackets.

The problem is, Sublime Text indents the next line, as if I'm now writing the block of commands for the if. It's not a deal-breaker for this wonderful software, but it's sometimes can become very annoying to delete these indents manually. Any chance that it might be fixed in the near future?

The video showing the bug: http://www.youtube.com/watch?v=VJdQxaIHLbk

Thanks in advance!
eduardische
 
Posts: 1
Joined: Tue Jun 26, 2012 4:46 pm

Re: BUG: One-line ifs indentation

Postby Chortos-2 on Mon Jul 09, 2012 4:04 pm

The unexpected indentation only occurs with for as shown in the video, not with if. Anyway, here is a way to correct it on your own:

From the Sublime Text 2 menu, select ‘[Sublime Text 2 →] Preferences → Browse Packages…’. Then open for editing ‘C++/Indentaion Rules.tmPreferences’. Find:
Code: Select all
^ \s* \b(if|while|else)\b [^;]* $
| ^ \s* \b(for)\b .* $
Replace with:
Code: Select all
^ \s* \b(if|while|else|for)\b [^;]* $

For an even better experience, replace with this instead:
Code: Select all
^ \s* \b(if|while|else|for)\b [^{;]* $
This will prevent the unexpected indentation from occurring after single-line conditions and loops with empty block bodies (e. g. ‘for (;;) {}’) in addition to those with single- or multi-statement bodies.
Chortos-2
 
Posts: 16
Joined: Thu May 27, 2010 5:13 pm
Location: Riga, Latvia, the EU, Europe, Eurasia, the Earth, the Solar System, the Milky Way, the Universe


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 19 guests