Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trim of changed lines only #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jan-grimo
Copy link

@jan-grimo jan-grimo commented May 24, 2024

Closes #22.

Adds the config option trim_changed_only (default false).

I think this is a relatively neat fix that even retains leading lines and trailing lines trimming for only changed lines. I have to admit I didn't do much more than translate the general solution approach that vim-better-whitespace uses here to figure out the changed blocks, except that this version even ensures the line breaks conform to fileformat (otherwise diff may falsely report the entire file is changed).

For this to work, diff must be on the PATH, and if it isn't, you get a complaint and trimming deactivates entirely.

Note that in principle the regexes used for trimming should still be updated to work with all the other line endings for true compatibility. It would amount to replacing \n with \(\r\n\|\r\|\n\) in the trailing and leading lines trimming regexes.

Although I've been dogfooding this for a little bit, this is the first time I'm messing with Lua, so please give it some close scrutiny. It's quite possible there are some functionality or perf corner cases with the functions I'm using that I'm not aware of.

@jan-grimo
Copy link
Author

@cappyzawa what do you think?

@cappyzawa
Copy link
Owner

@jan-grimo I'm sorry for not noticing earlier. I'll check it right now.

@jan-grimo
Copy link
Author

No apology needed, and feel free to take all the time you need!

@cappyzawa
Copy link
Owner

@jan-grimo Thanks for your pull request.

I appreciate the effort put into this pull request, but I'm unsure about the necessity of this feature. (#22 (comment))

Until I understand the need for this functionality, I cannot proceed with a code review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] trim only modified lines
2 participants