Home Download Buy Blog Forum Support

smart_indent bug?

smart_indent bug?

Postby acidtv on Wed Feb 29, 2012 12:16 pm

Hi,

I'm looking for a way to have sublime text 2 not add an extra indent level after typing {<enter>.
I would like to stay on the same indent level.

Like this:

Code: Select all
function foo($bar)
    {
    <code>
    }


Instead of this:


Code: Select all
function foo($bar)
    {
        <code>
    }


I'm coding in php.

Does anybody know how to do this?
Smart-indent is already turned off, but that didn't seem to help.
Last edited by acidtv on Mon Mar 05, 2012 8:45 am, edited 1 time in total.
acidtv
 
Posts: 4
Joined: Wed Feb 29, 2012 12:11 pm

Re: PHP auto indent

Postby acidtv on Mon Mar 05, 2012 8:45 am

Reading some more about the smart_indent setting, I saw this:

smart_indent: Boolean, enabled by default. Makes auto indent a little smarter, e.g., by indenting the next line after an if statement in C.


here http://www.sublimetext.com/docs/2/indentation.html.

Which sounds like, if smart_indent if off and auto_indent is on, sublime should just indent the new line at the same level as the previous one, instead of adding an extra indent level.

Is this a bug in smart_indent?
acidtv
 
Posts: 4
Joined: Wed Feb 29, 2012 12:11 pm

Re: smart_indent bug?

Postby jps on Mon Mar 05, 2012 11:14 am

smart_indent will still indent after braces by design. There isn't any direct support for your desired indentation style.
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: smart_indent bug?

Postby acidtv on Mon Mar 05, 2012 2:42 pm

Hmm, I'm not sure I understand what the smart_indent option actually does then.
When writing a function it indents the same way with both smart_indent turned on and turned off.

Do you have any plans to support this kind of indentation in the future?

I would love to use your great editor, but our company coding style prescribes this (admittedly unusual) style.

Please save me from having to go back to macvim ;).
acidtv
 
Posts: 4
Joined: Wed Feb 29, 2012 12:11 pm

Re: smart_indent bug?

Postby shanebdavis on Sat Jul 14, 2012 7:51 pm

I'd like to second this "feature request". It seems to me that "auto_indent" should ONLY maintain the indention level. "Smart_indent" should do any extra special language-specific indentation.

My preferred C++ indention scheme is:

void my_func(int x)
{
return x*x;
}

Auto-indent off results in an excessive amount of tabbing. With it on, I'm always fighting with the editor. It seems like this more basic "auto_indent" is a sane choice for pretty-much all languages at a base level. XCode works this way if you turn off "syntax-aware" indenting.

I am right on the verge of buying SublimeText, but this is a show-stopper for me. It's something that's going to annoy me every few seconds as I use the editor. Thanks! Otherwise, I'm liking SublimeText.
shanebdavis
 
Posts: 5
Joined: Sat Jul 14, 2012 7:40 pm

Re: smart_indent bug?

Postby MisterAnderson42 on Mon Aug 13, 2012 6:34 pm

shanebdavis wrote:I'd like to second this "feature request". It seems to me that "auto_indent" should ONLY maintain the indention level. "Smart_indent" should do any extra special language-specific indentation.


I'll add another vote to the request to fix this bug (smart_indent=false doesn't fully disable smart indent). This is how every other editor I have ever used behaves when you turn on auto indent and turn off their equivalent of smart indent (visual studio, xcode, vim, kate, kdevelop, textwrangler, eclipse, ...).

Like the previous poster, this is a show-stopper for me. So far in my evaluation, ST2 is exactly what I want in a text editor for coding - except for this one annoying auto-indent bug/"feature".

I was able to find an ad-hoc workaround. I enabled "auto_match_enabled". Then I modified Add Line in Braces.sublime-macro to remove the final "reindent" command. Now, when I type
Code: Select all
if (test)
    {|

the auto match feature inserts
Code: Select all
if (test)
    {|}

and when you press enter, the modified macro does this
Code: Select all
if (test)
    {
    |
    }


This is a poor workaround, because auto_match is almost as annoying as the smart indent. At least the auto match is smart enough to allow me to type the matching bracket without duplicate characters. So as long as I don't look at the screen it doesn't bug me :)
MisterAnderson42
 
Posts: 1
Joined: Mon Aug 13, 2012 6:20 pm

Re: smart_indent bug?

Postby shanebdavis on Thu Sep 06, 2012 8:31 pm

To follow up acidtv's post. I took his idea, but had to find a slightly different solution. Here is exactly what I did. I edited: ~/Library/Application Support/Sublime Text 2/Packages/Default/Add Line in Braces.sublime-macro to become:

Code: Select all
[
    {"command": "insert", "args": {"characters": "\n\n"} },
    {"command": "move", "args": {"by": "lines", "forward": false} },
    {"command": "move_to", "args": {"to": "hardeol", "extend": false} },
    {"command": "reindent", "args": {"force_indent": false}},
    {"command": "unindent", "args": {"force_indent": false}}
]


I added the "unindent" to the end. Just removing "reindent" caused the cursor to end up in the left-most column with no indention whatsoever.
shanebdavis
 
Posts: 5
Joined: Sat Jul 14, 2012 7:40 pm

Re: smart_indent bug?

Postby zeuxcg on Fri Feb 01, 2013 7:19 am

jps, seeing as there is some work being done currently on ST3, is it possible to resolve this issue? Maybe with an extra setting if breaking the existing behavior with smart_indent = false is such a big deal.

I'd like to reiterate the points above - most other editors have a mode where indentation of the previous line is preserved, but no extra indentation is added after a brace - moreover, this is what "auto indent" actually means.
This is probably a very simple change in ST codebase, and it would likely make at least several people happy.
zeuxcg
 
Posts: 3
Joined: Fri Feb 01, 2013 7:13 am

Re: smart_indent bug?

Postby JaseMourne on Wed Sep 04, 2013 8:21 am

I second this. This is actually the only feature that bugs me in ST2. Otherwise, it's just great.
JaseMourne
 
Posts: 5
Joined: Wed Sep 04, 2013 8:15 am


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 30 guests