summaryrefslogtreecommitdiffstats
path: root/after/ftplugin/lua.lua
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-11 19:53:59 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-11 20:08:37 +0200
commit94087c1bda9dc3f64710174c3e1da264a821d438 (patch)
tree1bf484139b0aa0ad53afcaadb7e77465cbb6d0f3 /after/ftplugin/lua.lua
parentf8c324b806a1b69d79633ea8bc4cf851b8c9bbeb (diff)
downloadnvim-config-94087c1bda9dc3f64710174c3e1da264a821d438.tar.gz
nvim-config-94087c1bda9dc3f64710174c3e1da264a821d438.zip
refactor(nvim): rewrite the buffer formatting flow
Diffstat (limited to 'after/ftplugin/lua.lua')
-rw-r--r--after/ftplugin/lua.lua29
1 files changed, 1 insertions, 28 deletions
diff --git a/after/ftplugin/lua.lua b/after/ftplugin/lua.lua
index b7d29c1..2b2f2c5 100644
--- a/after/ftplugin/lua.lua
+++ b/after/ftplugin/lua.lua
@@ -1,29 +1,3 @@
-local function format()
- local view = vim.fn.winsaveview()
- local buf_str = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), "\n") .. "\n"
- local tempname = vim.fn.tempname()
- local tempfile = assert(io.open(tempname, "w"), "Could not open temporary file")
- tempfile:write(buf_str)
- tempfile:close()
- local r_check = vim.system({ "stylua", "--check", tempname }):wait()
- if r_check.code == 0 then
- return
- elseif r_check.code ~= 1 then
- vim.notify("stylua failed (" .. r_check.code .. "):\n" .. r_check.stderr)
- end
- local r_format = vim.system({ "stylua", tempname }):wait()
- if r_format.code ~= 0 then
- vim.notify("stylua failed (" .. r_format.code .. "):\n" .. r_format.stderr)
- end
- local formatted_lines = {}
- for line in io.lines(tempname) do
- formatted_lines[#formatted_lines + 1] = line
- end
- os.remove(tempname)
- vim.api.nvim_buf_set_lines(0, 0, -1, false, formatted_lines)
- vim.fn.winrestview(view)
-end
-
vim.opt_local.textwidth = vim.g.dotfiles.textwidth.lua -- gw wraps at this value
vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth'
vim.opt_local.complete = {
@@ -31,8 +5,7 @@ vim.opt_local.complete = {
"F", -- 'completefunc' (snippet source, see plugin/50-completion.lua)
}
-vim.b.autoformat = true
-vim.b.format_func = format
+vim.b.format = true -- See plugin/50-format.lua
------------------------------------------------------------------------------------------------------------------------
-- Snippets