mcauley-penney / tidy.nvim

A small Neovim plugin to remove trailing whitespace and empty lines at end of file on every save
107 stars 15 forks source link

Also delete leading blank lines #9

Open amarakon opened 1 year ago

amarakon commented 1 year ago

It makes sense to also delete leading blank lines, not just trailing blank lines. The only problem with my implementation is this: If the plugin deletes trailing blank lines, it will not correct your cursor position if your cursor was somewhere in the middle of the file (i.e. not on any of the blank lines or the highest line that is not blank). Try it for yourself to see what I mean. Nonetheless, you won't encounter any errors and it's better than nothing.

mcauley-penney commented 1 year ago

Firstly, thanks for the PR! I tested it out and saw what you meant about the problem with the implementation. Before I consider merging this into master, I'd want to have that problem solved. I don't know when or if I'd get around to it, unfortunately.

More importantly, though, I don't know if this is a feature that I want to include in Tidy. I had a branch a while ago that did this and I really didn't find much use for it; typically, once I have a source code file established, I don't have to remove blank lines at the top of the file. I don't think its safe to assume that other people are the same but, for me, it was more source code for little benefit. That being said, I will take some time to consider it.

amarakon commented 1 year ago

For the branch you had that does this, did it have the same problem my pull request has? As for whether it should be included in Tidy, I think it should if it can be efficiently implemented. Since this plugin deletes trailing blank lines, I think it should also delete leading blank lines. I don't see a scenario in which someone would want to write in a file that has leading blank lines. Also, it would be cool if this plugin also deleted leading spaces not used for indentation. Implementing this would not be practical though, so it is probably best to keep this plugin to just deleting trailing whitespace and leading and trailing blank lines.