From 28661770fbaf1e98dd7f40add0c58146c16f391a Mon Sep 17 00:00:00 2001 From: siduck Date: Sun, 28 Jan 2024 21:40:04 +0530 Subject: [PATCH] fix editorConfig indent opts not applying on certain fts #2633 --- lua/core/init.lua | 23 +++++++++++++++++++++++ lua/plugins/init.lua | 38 +++++--------------------------------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/lua/core/init.lua b/lua/core/init.lua index 19804e1..8d19174 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -107,6 +107,29 @@ autocmd("BufWritePost", { end, }) +-- user event that loads after UIEnter + only if file buf is there +vim.api.nvim_create_autocmd({ "UIEnter", "BufReadPost", "BufNewFile" }, { + group = vim.api.nvim_create_augroup("NvFilePost", { clear = true }), + callback = function(args) + local file = vim.api.nvim_buf_get_name(args.buf) + local buftype = vim.api.nvim_buf_get_option(args.buf, "buftype") + + if not vim.g.ui_entered and args.event == "UIEnter" then + vim.g.ui_entered = true + end + + if file ~= "" and buftype ~= "nofile" and vim.g.ui_entered then + vim.api.nvim_exec_autocmds("User", { pattern = "FilePost", modeline = false }) + vim.api.nvim_del_augroup_by_name "NvFilePost" + + vim.schedule(function() + vim.api.nvim_exec_autocmds("FileType", {}) + require("editorconfig").config(args.buf) + end, 0) + end + end, +}) + -------------------------------------- commands ------------------------------------------ local new_cmd = vim.api.nvim_create_user_command diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 638051e..065040f 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -31,9 +31,7 @@ local default_plugins = { { "NvChad/nvim-colorizer.lua", - init = function() - require("core.utils").lazy_load "nvim-colorizer.lua" - end, + event = "User FilePost", config = function(_, opts) require("colorizer").setup(opts) @@ -58,9 +56,7 @@ local default_plugins = { { "lukas-reineke/indent-blankline.nvim", version = "2.20.7", - init = function() - require("core.utils").lazy_load "indent-blankline.nvim" - end, + event = "User FilePost", opts = function() return require("plugins.configs.others").blankline end, @@ -73,10 +69,8 @@ local default_plugins = { { "nvim-treesitter/nvim-treesitter", + event = { "BufReadPost", "BufNewFile" }, tag = "v0.9.2", - init = function() - require("core.utils").lazy_load "nvim-treesitter" - end, cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, build = ":TSUpdate", opts = function() @@ -91,27 +85,7 @@ local default_plugins = { -- git stuff { "lewis6991/gitsigns.nvim", - ft = { "gitcommit", "diff" }, - init = function() - -- load gitsigns only when a git file is opened - vim.api.nvim_create_autocmd({ "BufRead" }, { - group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }), - callback = function() - vim.fn.jobstart({"git", "-C", vim.loop.cwd(), "rev-parse"}, - { - on_exit = function(_, return_code) - if return_code == 0 then - vim.api.nvim_del_augroup_by_name "GitSignsLazyLoad" - vim.schedule(function() - require("lazy").load { plugins = { "gitsigns.nvim" } } - end) - end - end - } - ) - end, - }) - end, + event = "User FilePost", opts = function() return require("plugins.configs.others").gitsigns end, @@ -143,9 +117,7 @@ local default_plugins = { { "neovim/nvim-lspconfig", - init = function() - require("core.utils").lazy_load "nvim-lspconfig" - end, + event = "User FilePost", config = function() require "plugins.configs.lspconfig" end,