diff --git a/lua/core/init.lua b/lua/core/init.lua index de4aad2..984f458 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -1,12 +1,9 @@ -local onsave = true -- require("config.lazy") require("user.options") require("user.keymaps") require("user.autocommands") +require("user.format_onsave") -- require("user.colorscheme") -- require("user.snip") -- require("user.bufferline") -if onsave then - require("user.format_onsave") -end -- require("user.chat_gpt") diff --git a/lua/custom/format_onsave.lua b/lua/custom/format_onsave.lua new file mode 100644 index 0000000..cc63b0c --- /dev/null +++ b/lua/custom/format_onsave.lua @@ -0,0 +1,5 @@ +local M = { + disable = false, +} + +return M diff --git a/lua/user/format_onsave.lua b/lua/user/format_onsave.lua index 511d09c..b836522 100644 --- a/lua/user/format_onsave.lua +++ b/lua/user/format_onsave.lua @@ -1,22 +1,25 @@ -function format_filter(client) - local filetype = vim.bo.filetype - local n = require("null-ls") - local s = require("null-ls.sources") - local method = n.methods.FORMATTING - local available_formatters = s.get_available(filetype, method) +local data_exists, frmt = pcall(require, "custom.format_onsave") +if data_exists and frmt.disable == false then + function format_filter(client) + local filetype = vim.bo.filetype + local n = require("null-ls") + local s = require("null-ls.sources") + local method = n.methods.FORMATTING + local available_formatters = s.get_available(filetype, method) - if #available_formatters > 0 then - return client.name == "null-ls" - elseif client.supports_method("textDocument/formatting") then - return true - else - return false + if #available_formatters > 0 then + return client.name == "null-ls" + elseif client.supports_method("textDocument/formatting") then + return true + else + return false + end end + vim.cmd([[ + augroup _lsp + autocmd! + " autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms =200, filter=format_filter} + autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=1000 ,filter=format_filter} + augroup end + ]]) end -vim.cmd([[ -augroup _lsp - autocmd! - " autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms =200, filter=format_filter} - autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=1000 ,filter=format_filter} - augroup end -]])