summaryrefslogtreecommitdiffstats
path: root/.config/nvim
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-10 08:51:17 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-10 08:51:17 +0200
commit23a4b3004568391ddf69c02f6f75ce760fbf68fb (patch)
tree4413291d8eb478c9b5e0b5ba75aeeeaf4f6c3dca /.config/nvim
parentd58694b966d06e08c364ca6e0f578bcb1ef82bf2 (diff)
downloaddotfiles-23a4b3004568391ddf69c02f6f75ce760fbf68fb.tar.gz
dotfiles-23a4b3004568391ddf69c02f6f75ce760fbf68fb.zip
misc(nvim): add python formatter (black)
Diffstat (limited to '.config/nvim')
-rw-r--r--.config/nvim/after/ftplugin/python.lua17
1 files changed, 17 insertions, 0 deletions
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