summaryrefslogtreecommitdiffstats
path: root/after/ftplugin/python.lua
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
commitf1f1b7458c1829c0aeabd0bf400c10725be28b2a (patch)
treebb3dbc4f91d43873eae2a81015f9c013ed666328 /after/ftplugin/python.lua
parent756455810875217b3e826bd6438ee40e936e5c1d (diff)
downloadnvim-config-f1f1b7458c1829c0aeabd0bf400c10725be28b2a.tar.gz
nvim-config-f1f1b7458c1829c0aeabd0bf400c10725be28b2a.zip
misc(nvim): add python formatter (black)
Diffstat (limited to 'after/ftplugin/python.lua')
-rw-r--r--after/ftplugin/python.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/after/ftplugin/python.lua b/after/ftplugin/python.lua
new file mode 100644
index 0000000..fa39ee8
--- /dev/null
+++ b/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