sakapoko / vscode-emacs-indent

2 stars 1 forks source link

tab on a blank line preceded by another blank line doesn't indent to the right position #1

Open joeshaw opened 3 years ago

joeshaw commented 3 years ago

If I have two blank lines in a row and hit tab on the second blank line, the cursor is taken back to column 1. This isn't what I expect: I want to jump to the appropriate indentation for the document, ignoring any blank lines above it. The built-in VSCode behavior of hitting enter on a blank line does jump me to the appropriate indent.

For example, take a JSON document:

1 {
2     "hello": "world",
3
4
5     "goodbye": "for now"
6 }

On row 3, hitting tab correctly indents inline with the other JSON keys.

On row 4, hitting tab takes the cursor back to column 1. I would expect the behavior to be the same between rows 3 and 4. (Note that row 3 has to be completely blank for this to be the case: if row 3 has indentation in it, row 4 will indent to that level.)

This isn't limited to JSON documents.

joeshaw commented 3 years ago

Poking at this a little bit more, this seems to be the result of editor.action.reindentselectedlines not doing the right thing in this case.

sakapoko commented 3 years ago

That is the reason for this behavior. I was hoping that the document formatter of language support would improve over time. To solve this, I tried to reindent using range selection when the previous line is blank.

sakapoko commented 3 years ago

https://github.com/sakapoko/vscode-emacs-indent/tree/feature/indent_after_empty_line

sakapoko commented 3 years ago

Note that the document formatter inserts unnecessary whitespace in blank lines. You need to set the trailing whitespace.

joeshaw commented 3 years ago

As an alternative, could you delete the previous line and then insert a new line in the manner that pressing "enter" does, thereby indenting to the right place? Maybe that only works for a single line and not a selection -- I almost never hit "tab" with a selection.

sakapoko commented 3 years ago

It's best to use Insert Line Below(editor.action.insertLineAfter), considering only when lines are added and indented. However, the problem is that the end of the block is also indented. If it is possible to switch to distinguish these cases, we can use that method.