From 23a4b3004568391ddf69c02f6f75ce760fbf68fb Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Wed, 10 Jun 2026 08:51:17 +0200 Subject: misc(nvim): add python formatter (black) --- .config/nvim/after/ftplugin/python.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .config/nvim/after/ftplugin/python.lua diff --git a/.config/nvim/after/ftplugin/python.lua b/.config/nvim/after/ftplugin/python.lua new file mode 100644 index 0000000..fa39ee8 --- /dev/null +++ b/.config/nvim/after/ftplugin/python.lua @@ -0,0 +1,17 @@ +vim.opt_local.textwidth = vim.g.dotfiles.textwidth.python +vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth' +vim.opt_local.complete = { + "o", -- 'omnifunc' +} + +vim.b.autoformat = true +vim.b.format_func = function() + local ret = vim.system({ "black", "--check", "-" }, { stdin = vim.api.nvim_buf_get_lines(0, 0, -1, false) }):wait() + if ret.code > 1 then + vim.notify("black failed (" .. ret.code .. "):\n" .. ret.stderr, vim.log.levels.WARN) + return + end + local view = vim.fn.winsaveview() + vim.cmd("%!black --quiet -") + vim.fn.winrestview(view) +end -- cgit v1.3.1