mirror of https://github.com/folke/lazy.nvim.git
fix(ft): only trigger filetypepluing and filetypeindent for ft handler. Fixes #228
This commit is contained in:
parent
db043da829
commit
7de662d037
|
@ -11,7 +11,6 @@ M.trigger_events = {
|
||||||
BufRead = { "BufReadPre", "BufRead" },
|
BufRead = { "BufReadPre", "BufRead" },
|
||||||
BufReadPost = { "BufReadPre", "BufRead", "BufReadPost" },
|
BufReadPost = { "BufReadPre", "BufRead", "BufReadPost" },
|
||||||
}
|
}
|
||||||
M.trigger_always = { "FileType" }
|
|
||||||
M.group = vim.api.nvim_create_augroup("lazy_handler_event", { clear = true })
|
M.group = vim.api.nvim_create_augroup("lazy_handler_event", { clear = true })
|
||||||
|
|
||||||
---@param value string
|
---@param value string
|
||||||
|
@ -32,12 +31,8 @@ function M:_add(value)
|
||||||
local groups = M.get_augroups(event, pattern)
|
local groups = M.get_augroups(event, pattern)
|
||||||
-- load the plugins
|
-- load the plugins
|
||||||
Loader.load(self.active[value], { [self.type] = value })
|
Loader.load(self.active[value], { [self.type] = value })
|
||||||
if vim.tbl_contains(M.trigger_always, event) then
|
-- check if any plugin created an event handler for this event and fire the group
|
||||||
vim.cmd("do " .. event)
|
self:trigger(event, pattern, groups)
|
||||||
else
|
|
||||||
-- check if any plugin created an event handler for this event and fire the group
|
|
||||||
M.trigger(event, pattern, groups)
|
|
||||||
end
|
|
||||||
Util.track()
|
Util.track()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -66,7 +61,7 @@ end
|
||||||
---@param event string|string[]
|
---@param event string|string[]
|
||||||
---@param pattern? string
|
---@param pattern? string
|
||||||
---@param groups table<string,true>
|
---@param groups table<string,true>
|
||||||
function M.trigger(event, pattern, groups)
|
function M:trigger(event, pattern, groups)
|
||||||
local events = M.trigger_events[event] or { event }
|
local events = M.trigger_events[event] or { event }
|
||||||
---@cast events string[]
|
---@cast events string[]
|
||||||
for _, e in ipairs(events) do
|
for _, e in ipairs(events) do
|
||||||
|
@ -77,7 +72,7 @@ function M.trigger(event, pattern, groups)
|
||||||
"# Firing Events",
|
"# Firing Events",
|
||||||
" - **group:** `" .. autocmd.group_name .. "`",
|
" - **group:** `" .. autocmd.group_name .. "`",
|
||||||
" - **event:** " .. autocmd.event,
|
" - **event:** " .. autocmd.event,
|
||||||
pattern and "- **pattern:** ",
|
pattern and (" - **pattern:** " .. pattern),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
Util.try(function()
|
Util.try(function()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
local Event = require("lazy.core.handler.event")
|
local Event = require("lazy.core.handler.event")
|
||||||
|
local Util = require("lazy.core.util")
|
||||||
local Loader = require("lazy.core.loader")
|
local Loader = require("lazy.core.loader")
|
||||||
|
|
||||||
---@class LazyFiletypeHandler:LazyEventHandler
|
---@class LazyFiletypeHandler:LazyEventHandler
|
||||||
|
@ -18,4 +19,19 @@ function M:add(plugin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param pattern? string
|
||||||
|
function M:trigger(_, pattern, _)
|
||||||
|
for _, group in ipairs({ "filetypeplugin", "filetypeindent" }) do
|
||||||
|
Util.try(function()
|
||||||
|
Util.info({
|
||||||
|
"# Firing Events",
|
||||||
|
" - **group:** `" .. group .. "`",
|
||||||
|
" - **event:** FileType",
|
||||||
|
pattern and (" - **pattern:** " .. pattern),
|
||||||
|
})
|
||||||
|
vim.api.nvim_exec_autocmds("FileType", { group = group, modeline = false, pattern = pattern })
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue