-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow for partially formatting a file e.g. from line 20 to 25 #511
Comments
Try |
@khvn26 But then I have to do pick my hunks manually, and keep in mind which lines I actually changed. It's not the same thing. |
This is not going to happen, sorry. It's not generally safe to reformat part of a python source code. See #134 for a full explanation. |
Also FYI, I wrote darker to apply Black formatting only to lines which have changed in the Git working tree since the last commit. |
one hack:
|
I understand hesitancy to introduce partial formatting to prevent inconsistent style within files. However, many text editors simply assume partial formatting is a feature of the formatter, so this stance significantly decreases the usability. My specific use case is a desire is to use Vim to format my code. In many situation, simply calling using the formatter on a paragraph is the simplest way to ident a group of lines, but I'm prevented from doing that when using black. Furthermore, you format an entire file in Vim by selecting the entire file and formatting the selection, so even that isn't possible without support for partial formatting. Is this still seen as out of the question to consider implementing? I can't help but feel the provided justification isn't satisfactory. |
The docs mention a way to use Black from vim without relying on selecting lines. That should get your workflow unblocked immediately |
@zsol Thank you very much for the response and the link. However, I'd like to be able to use the Vim keybinding (e.g. |
@mkarrmann you may want to try this instead: https://github.com/smbl64/vim-black-macchiato partial formatting is a dirty hack and should be avoided if possible. |
@wbolster Thanks! I overlooked your above comment. That's unfortunate to hear (although of course expected, I wasn't expecting my single comment to change a decision made years ago lol). Glad to know I wasn't the only one frustrated by this limitation. And that's a neat "dirty hack" :) Thanks for sharing! |
Hello,
I just stumbled upon black and I immediately integrated it into my workflow in PyCharm. it's really great tool.
Unfortunately I cannot reformat all of our code at once and make everything consistent, because I would be clobbering our git history and every subsequent git blame would blame me!
So I would like to have a command line switch to only reformat a part of a file, say a range of lines, e.g.
so I can only reformat the code that I'm touching anyway and transform our codebase over time.
The text was updated successfully, but these errors were encountered: