-
Notifications
You must be signed in to change notification settings - Fork 166
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
Always strip trailing spaces in TabularizeStrings #21
Conversation
Currently, trailing spaces are only stripped from the first element in a line if it contains non-whitespace characters, however this causes padding creep. Given a block like foo => bar beezlebub => debil john => doe `:GTab /=>/` will move the `=>` column to the right by one instead of to the left by one. Similarly, using `:Tab /=>/` twice will first align the column as expected, but then shift the column one to the right every time you repeat the command. This is because the leading whitespace on the `=> debil` line is considered when calculating the max line length. Stripping the trailing whitespace (which is all of the whitespace in this case) ensures the lines are all aligned, only taking into account relevant content.
Hm. The code has this comment:
I'm sure the reason I wrote the
Doing
But with this patch applied it would give
I don't know how I feel about that. I'm inclined to think that this is a feature, not a bug - Tabular won't remove your indentation, no matter what args you give it. If you don't like that, you can always use Thoughts on the tradeoffs, jamessan? |
I wonder how common either case is. I would argue that in your example the pattern being fed to That being said, with my proposed changes the behavior in both scenarios is at least stable. Your snippet gets thrown to the left and stays there. My snippet gets properly aligned. Tabular's current code aligns your example and shifts my example to the right every time you call That's my take. Do what you think makes the most sense, as I doubt I'll run into this very often since I'm not generally a fan of alignment. I just use your plugin when I need to do it and found this behavior very confusing. :) |
I was just revisiting this PR based on a discussion in #vim and noticed that it's not nearly as difficult as I originally thought -- |
I'll grant that Well, anyway - what was the recent conversation in So, then - maybe the best fix is to find the common leading whitespace, strip the common indent from all lines, align the lines (without treating the first field as special), and then add the common whitespace back to all lines? I think that a patch that does that would fix the creeping indent in a mostly backwards compatible way... |
There was just a discussion about alignment plugins and whether the functionality of easy-align is worth its complexity or if the common use cases are covered by the simplicity of Tabular. I brought up that Tabular had been enough for me save the one edge case I ran into here. I'll take a stab at implementing your suggestion "soon". |
Something like dcd43cb (the new |
That looks good. I made some adjustments in jamessan/tabular@a2ad74f which now makes it satisfy both of our scenarios. |
I missed that blank lines need to not break an indent streak - good catch. I'm not sure about the fix to have My current line of thought is that the indent handling should happen after the I'm going to play with that and try to get you a new patch to try out... |
Easier than I thought - try out ca692a7 and see how it works for you. I still want to do some more testing, but this definitely seems cleaner, more consistent, and more correct than my first attempt. |
Gah, actually - that doesn't work right for the truth table example I gave above. Hrm. |
Third time's a charm - try out a6ef92c if you get a chance. |
👍 |
I've merged my proposed fix as cdac1a6 |
Currently, trailing spaces are only stripped from the first element in a line if it contains non-whitespace characters, however this causes padding creep.
Given a block like
:GTab /=>/
will move the=>
column to the right by one instead of to the left by one. Similarly, using:Tab /=>/
twice will first align the column as expected, but then shift the column one to the right every time you repeat the command.This is because the leading whitespace on the
=> debil
line is considered when calculating the max line length.Stripping the trailing whitespace (which is all of the whitespace in this case) ensures the lines are all aligned, only taking into account relevant content.