summaryrefslogtreecommitdiffstats
path: root/.config/nvim/after/ftplugin/python.lua
blob: fa39ee800e38dbd28ccb0af006ec3bbaa9d2e473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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