diff --git a/lua/core/init.lua b/lua/core/init.lua index c261ef4..984f458 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -2,7 +2,7 @@ require("user.options") require("user.keymaps") require("user.autocommands") -require("user.format") +require("user.format_onsave") -- require("user.colorscheme") -- require("user.snip") -- require("user.bufferline") diff --git a/lua/user/format_onsave.lua b/lua/user/format_onsave.lua index 9d78330..80b9624 100644 --- a/lua/user/format_onsave.lua +++ b/lua/user/format_onsave.lua @@ -1,22 +1,33 @@ -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 - end +local run = 0 +local data_exists, frmt = pcall(require, "custom.format_onsave") +if not data_exists then + run = 1 end -vim.cmd([[ +if frmt.disable == 0 then + run = 1 +end + +if run == 1 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 + 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