Sublime Forum

smart_indent bug?

#1

Hi,

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

Like this:

function foo($bar)
    {
    <code>
    }

Instead of this:

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.

0 Likes

[ST2/3] Smart Indent setting broken
#2

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

[quote] 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.
[/quote]

here 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?

0 Likes

#3

smart_indent will still indent after braces by design. There isn’t any direct support for your desired indentation style.

0 Likes

#4

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 :wink:.

0 Likes

#5

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.

0 Likes

Disable syntax-based indentation
#6

[quote=“shanebdavis”]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.
[/quote]

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

if (test)
    {|

the auto match feature inserts

if (test)
    {|}

and when you press enter, the modified macro does this

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 :smile:

0 Likes

#7

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:


    {"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.

0 Likes

#8

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.

0 Likes

Build 3009
Build 3012
#9

I second this. This is actually the only feature that bugs me in ST2. Otherwise, it’s just great.

0 Likes