andreikop / enki

A text editor for programmers
http://enki-editor.org
GNU General Public License v2.0
161 stars 38 forks source link

Autoformat Python code #468

Open abitrolly opened 4 years ago

abitrolly commented 4 years ago

After writing Go and Terraform code in vim which automatically runs go fmt and terraform fmt it is very painful to fix Flake8 errors by hand. Is it possible to implement an autoformat mode for Enki?

andreikop commented 4 years ago

Ctrl+I does this in some extent. Select more than one line or even whole file. It will not produce correct indentation for whole Python file, because only the programmer knows when the code must be unindented after if, for, etc.

abitrolly commented 4 years ago

@andreikop while counting lines when opening file, it might be possbile to gather statistics on indentation and use the most popular one. This indentation detection could actually improve user experience with Enki.

abitrolly commented 4 years ago

Looks like Enki already detects indentation, and I got your message wrong.

There are a couple of tools that do autoformatting for Python - https://github.com/pausan/cblack#similar-projects which probably could be reused for the task.