Sublime Forum

Full smart-indent?

#1

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 or more than once (or maybe once per level of detent I want.

Specifically:

There needs to be a way, with a single keystroke (ideally , and I think I can map 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 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?

-Chris

0 Likes

#2

Hey Chris.

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

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:

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)

0 Likes