wbolster / emacs-python-black

Emacs package to reformat Python using black-macchiato
BSD 3-Clause "New" or "Revised" License
95 stars 11 forks source link

add python-black-statement: reformat the current statement #1

Closed wbolster closed 5 years ago

wbolster commented 5 years ago

This adds a python-black-statement interactive command to reformat the Python statement at point. Python statement boundary detection uses the built-in python.el navigation functions (python-nav-*).

rjprins commented 5 years ago

On some lines I get this error: error: cannot format /tmp/tmp_n05tpf2.py: Cannot parse: 3:0: <line number missing in source> Didn't go into the cause yet, maybe python-nav-beginning/end-of-statement doesn't always return a line number?

wbolster commented 5 years ago

@rjprins can you provide me with an example of such a line/statement?

wbolster commented 5 years ago

minimal example:

if True:
    pass

the if True: line is not a full python program, so black cannot parse it, resulting in a message like

error: cannot format /run/user/1000/tmpjf9a9ssn.py: Cannot parse: 2:0: <line number missing in source>

pretty sure this is a https://github.com/wbolster/black-macchiato limitation, not a problem in the python-black-statement command.

wbolster commented 5 years ago

been using this for a bit today, and it seems to work just fine for the majority of cases.