Home Download Buy Blog Forum Support

Full smart-indent?

Full smart-indent?

Postby Chris.Barker on Tue Nov 06, 2012 6:00 pm

Hi folks,

I'm checking out Sublime Text 2, as a lot of folks have much good to say about it, and it so far has every key feture I"ve been looking for for years.

Except one:

The smart-indenting is, not to put too fine a point on it, really lame. Perhaps I haven't found the right setting yet, but this is what I would like, and indeed, it's really pretty critical to my productivity -- I use primarily Python, where indenting is key -- but in any language I want clean consistent indenting.

What do I want? in short, I should NEVER have to delete or add a single space to get a line indented right, or hit <tab> or <backspace> more than once (or maybe once per level of detent I want.


There needs to be a way, with a single keystroke (ideally <tab>, and I think I can map <tab> to "reindent"), to say "indent this line correctly". "reindent" professes to do this, but it's really pretty lame. In a delimted language, indenting be very clearly defined, in Python, there is a bit of ambiguity, but only a little.

- the line should indent to be the same as the line above, unless the line above begins a new block (a : in python ), in which case it should increase the indentation level one.

- if the line is a continuation line (the previous line has an unclosed parentheses, etc), the line should be indented (with spaces) to line up with the unclosed paren in the line above.

- the cursor should be placed at the end of the indentation -- at the beginning of the real line

- if <backspace> is hit at the end of the indentation level, the level of indentation is decreased by one.

There are a number of details to doing it right, but I think that's about it for the big things.

(X)emacs does this well
Peppy does this well
I think VIM does this well.

Sublime, at least with the settings I've found, does this horribly.

(Actually, remarkably few editors do this well!)

This is a deal breaker for me, but I can't believe this is an unusual desire, so wondering is someone has already done this.

Am I going to need to write a new plug-in? If so can someone point me to one that would be good to start from?

Posts: 2
Joined: Tue Nov 06, 2012 5:24 pm

Re: Full smart-indent?

Postby tehwilsonat0r on Wed Dec 05, 2012 12:01 am

Hey Chris.

There is an option that supports your continuation case, actually: http://www.sublimetext.com/docs/2/indentation.html

indent_to_bracket Boolean, disabled by default. Adds whitespace up to the first open bracket when indenting.

I am wondering, though, if it'd be possible to add an option that would, rather than indenting up to the bracket, just indent twice. In other words:
Code: Select all
if __name__ == "__main__":
    some_thing = some_method_call(
            parameter1  # indented two levels below the previous line

This is closer to PEP8's recommendation for Python, and it's what we use at my job, but Sublime Text 2 doesn't have an option for it (apparently)
Posts: 1
Joined: Tue Dec 04, 2012 11:56 pm

Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], olivierlacan and 23 guests