Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #22.
Adds the config option
trim_changed_only
(defaultfalse
).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 tofileformat
(otherwise diff may falsely report the entire file is changed).For this to work,
diff
must be on thePATH
, 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.