Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It does, you'd just have to install a python plugin that registers the autocommand-- or leave out the plugin and register the autocommand yourself. The (n)vim/emacs communities aren't fond of integrating the hot new thing for each language directly into the editor-- I think this is a lesson that comes from being 50 years old!

As for whether it would be buggy, I'd doubt it? Unless Black's principle of operation is different from most formatters, it should just write the formatted contents to the file, right? The autocommand you'd use would just run Black on your current file on each save. So where % is Vim's symbol for the name of the currently open file, :silent! suppresses stdout/stderr from the formatter, and :! runs a command:

autocmd BufWritePost *.py silent! !<format_cmd> %

(Don't quote me on that, but it should be essentially correct. I'm not at a computer right now.)

Actually, it looks like you can install an (n)vim plugin from the official Black repo here:

https://github.com/psf/black/blob/main/plugin/black.vim

And then the autocmd would be

autocmd BufWritePost *.py silent! Black

This stuff is documented here: https://black.readthedocs.io/en/stable/integrations/editors....

Anyway, I think it's actually a really cool effect of doing this that you realize a lot of the scaffolding underneath most editors _isn't_ that complicated! It's totally understandable :)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: