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

Quick fix for s:clean_slice #36

Closed
wants to merge 1 commit into from

Conversation

NoahTheDuke
Copy link

Decided to do the "hard" work myself! Quick fix for the issue I had in #35.

@tweekmonster
Copy link
Owner

Thanks! I think it might be better if it's done as a pre-check here: format.vim#L97

The pattern could be something like:

[[^\[\]]*:[^\[\]]*\]

but it might need an extra bit for the slice stepping:

[[^\[\]]*:[^\[\]]*\%(:[^\[\]]*\)\?\]

I haven't test it, but I think those would match [:], [x:], [:x], etc.

In reply to:

This removes all surrounding whitespace from the the operators +, -, *, /. Originally, PEP 8 dictated leaving space around arithmetic operators, but that has changed. Post-2012 PEP 8's Other Recommendations says to use spaces when determining priority level (even though I find that unclean), but as it's left up to user discretion, I'd suggest making the default remove extra whitespaces around operators instead:

Yeah, the cleanups are meant for things under PEP8's Pet Peeves, which I consider to be a matter of opinion/taste. The original intention was for cleaning up inherited code that was written by someone trying to impose a different language's coding style (java devs, mostly). My reasoned opinion for wanting to remove whitespace around slice operators has more to do with readability.

If you're quickly scanning through the code to look for something, you might not see the immediate difference between these two lines:

x = [1 + 2, 3 + 4]
x = x[1 + 2 : 3 + 4]

but, it's slightly easier to spot like this:

x = [1 + 2, 3 + 4]
x = x[1+2:3+4]

It also helps that you can use the W motion to select the entire slice expression. If preserving some of the whitespace is wanted, we should probably make it so that they're properly balanced as described in PEP8.

The parts under Other Recommendations are okay, but I'm not willing to tackle parsing out the expressions.

@tweekmonster
Copy link
Owner

@NoahTheDuke Is this abandoned?

@NoahTheDuke
Copy link
Author

Yeah, sorry. I don't remember why cuz I def tried to handle some of your comments, but that was two computers ago.

@NoahTheDuke NoahTheDuke closed this Nov 9, 2018
@NoahTheDuke NoahTheDuke deleted the clean_slice_fix branch November 21, 2019 21:39
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.

2 participants