andreikop / enki

A text editor for programmers
http://enki-editor.org
GNU General Public License v2.0
161 stars 38 forks source link

Python editor insists in indenting at ( #230

Closed yajo closed 9 years ago

yajo commented 10 years ago

Let me explain. Imagine that | is the cursor. You have this scenario:

something = this_is_a_very_long_function(|cr,uid, ids, context=context)

Pressing Enter does:

something = this_is_a_very_long_function(
                                         |cr, uid, ids, context=context)

OK, this is usual in Python, so it's understandable. However now imagine I unindent that and come to this:

something = this_is_a_very_long_function(
    cr, |uid, ids, context=context)

The logical behavior if I press Enter is:

something = this_is_a_very_long_function(
    cr, 
    |uid, ids, context=context)

But Enki does:

something = this_is_a_very_long_function(
    cr,
                                         |uid, ids, context=context)

This time it has no sense, since previous line is already in a lesser indentation level.

andreikop commented 10 years ago

Yes, I also discovered this bug. Enki is not going to force your indentation, it just tries to indent properly constructions like this:

call_func(param,
          one_more_param,
          nested_call(a,
                      b,
                      c, | # <-- case 1
                      d),| # <-- case 2
          next_param)

In the case 1 next line shall be indented as b, but in the case 2 next line shall be indented as nested_call

We have to invent more complicated algorithm

yajo commented 10 years ago

And I just imagined an even more complex scenario:

call_func(param,
          one_more_param,
          nested_call(
              a,
              this_is_a_very_long_value
                  if True| #<-- case 3
                  else None,| #<-- case 4
              c,
              d),| #<-- case 5
          next_param)

In that case, after a comma, Enki should be smart enough to put else, c and next_param where they are.

andreikop commented 10 years ago

Any help is welcome! https://github.com/hlamer/qutepart/blob/master/qutepart/indenter/python.py

andreikop commented 9 years ago

I added more logic to the Python indenter. Update to Qutepart master, and notify me if something is indented incorrectly. (case 4 is not supported)

yajo commented 9 years ago

I tested it and looks great! Thanks! :+1: