Format Python code according to the
First, install Python yapf package with pip:
pip install -U yapf
python-yapf.el to your load-path and add to your
Three commands are supplied to format python code:
python-yapf-region: Format the code of the region or the buffer if no region selected.
python-yapf-file: Format a file(by default the one opened in current buffer).
python-yapf-directory: Search and format .py files in a directory.
Run them interactively:
M-x python-yapf-* RET
Or set any key bindings you like.
Currently, YAPF is in alpha stage(buggy) and may change often in the released version, many features are required to enhance the code formatting. When you format code files, please remember to make backups.
Bugfix or suggestions/improvements welcome!