Skip to content

Commit

Permalink
fix(ft): only trigger filetypepluing and filetypeindent for ft handler.
Browse files Browse the repository at this point in the history
Fixes #228
  • Loading branch information
folke committed Dec 29, 2022
1 parent db043da commit 7de662d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lua/lazy/core/handler/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ M.trigger_events = {
BufRead = { "BufReadPre", "BufRead" },
BufReadPost = { "BufReadPre", "BufRead", "BufReadPost" },
}
M.trigger_always = { "FileType" }
M.group = vim.api.nvim_create_augroup("lazy_handler_event", { clear = true })

---@param value string
Expand All @@ -32,12 +31,8 @@ function M:_add(value)
local groups = M.get_augroups(event, pattern)
-- load the plugins
Loader.load(self.active[value], { [self.type] = value })
if vim.tbl_contains(M.trigger_always, event) then
vim.cmd("do " .. event)
else
-- check if any plugin created an event handler for this event and fire the group
M.trigger(event, pattern, groups)
end
-- check if any plugin created an event handler for this event and fire the group
self:trigger(event, pattern, groups)
Util.track()
end,
})
Expand Down Expand Up @@ -66,7 +61,7 @@ end
---@param event string|string[]
---@param pattern? string
---@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 }
---@cast events string[]
for _, e in ipairs(events) do
Expand All @@ -77,7 +72,7 @@ function M.trigger(event, pattern, groups)
"# Firing Events",
" - **group:** `" .. autocmd.group_name .. "`",
" - **event:** " .. autocmd.event,
pattern and "- **pattern:** ",
pattern and (" - **pattern:** " .. pattern),
})
end
Util.try(function()
Expand Down
16 changes: 16 additions & 0 deletions lua/lazy/core/handler/ft.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Event = require("lazy.core.handler.event")
local Util = require("lazy.core.util")
local Loader = require("lazy.core.loader")

---@class LazyFiletypeHandler:LazyEventHandler
Expand All @@ -18,4 +19,19 @@ function M:add(plugin)
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

0 comments on commit 7de662d

Please sign in to comment.