howl-editor / howl

The Howl Editor
http://howl.io
Other
712 stars 68 forks source link

Smart indentation, not being smart #413

Open italomaia opened 6 years ago

italomaia commented 6 years ago
with open(filename) as fs:
  data = fs.read()
| <= cursor here

Given my cursor is in the above line, if I hit "enter", indentation expands back to 2chars. I believe that should not be the expected behavior. It should keep the indentation of the line it was.

refi64 commented 6 years ago

I'm confused: are you referring to the indentation of the third line? If so, it doesn't really matter: Howl strips away trailing indentation anyway.

Here's an example: say you have:

if something:
    print('something')
|

where | again represents the cursor. You want to add some text two lines beneath, like this:

if something:
    print('something')

print('Some text here')

Instead of:

Just do:

Does that sort of make sense?

italomaia commented 6 years ago

@kirbyfan64 this is what I mean https://youtu.be/ZRraFwlAfXA

This described behavior is particularly problematic if I want to write multiple functions in a file, one after the other. I would have to remove indentation multiple times, in redundance.

italomaia commented 6 years ago

Confirmed?

nilnor commented 6 years ago

@italomaia I see what you mean, but I would not "confirm" it in the sense of confirming a bug. Your intention in this case is clearly not to have it indented since you explicitly dedented the previous line just before. Indentation is however not dependent on what, if any, editor actions have been performed, but is concerned solely with the buffer contents.

Currently, empty preceding lines are not considered when determining the indentation, so the question here ends up being whether they should be. This might not actually be a bad idea, and could work out well. I for one would have to experiment with actually using that for a while to see how it behaves, but that will require first doing the work. I'm personally doing other Howl stuff now, so if it's dependent on me then it will have to wait for a while.

Finally, I don't see why you have to remove indentation multiple times when writing multiple functions - you can press enter until you're at the line where you want to be and dedent once.