-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
Implementing the idea @lewis6991 proposed for handling multiple loads on the same command/keymap/event added by separate calls to `add`. Changes the loaders to keep a table of plugins associated with a given load trigger and only create new events/keymaps/commands for new triggers, otherwise simply appending to the set of plugins to be loaded on the given trigger. One note: we may need to make loaders delete plugins from these lists after load, to handle cases like: - add(event, plugins_1) - event happens, plugins_1 loaded - add(event, plugins_2) - event happens, without deleting plugins_1 gets loaded again I don't believe that this is a potential bug introduced by this change---it could've happened with the more naive handlers as well
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
local util = require 'packer.handlers.util' | ||
local event_plugins: {string:{Plugin}} = {} | ||
|
||
return function(plugins: {string:Plugin}, loader: function({Plugin})) | ||
local events: {string:{Plugin}} = {} | ||
|
||
local new_events: {string} = {} | ||
for _, plugin in pairs(plugins) do | ||
if plugin.event then | ||
for _, event in ipairs(plugin.event) do | ||
events[event] = events[event] or {} | ||
table.insert(events[event], plugin) | ||
if not event_plugins[event] then | ||
event_plugins[event] = {} | ||
new_events[#new_events + 1] = event | ||
end | ||
|
||
table.insert(event_plugins[event], plugin) | ||
end | ||
end | ||
end | ||
|
||
for event, eplugins in pairs(events) do | ||
for _, event in ipairs(new_events) do | ||
-- Handle 'User Foo' events | ||
local ev, pattern = unpack(vim.split(event, '%s+')) | ||
|
||
local id = vim.api.nvim_create_autocmd(ev, { | ||
vim.api.nvim_create_autocmd(ev, { | ||
pattern = pattern, | ||
once = true, | ||
callback = function() | ||
loader(eplugins) | ||
loader(event_plugins[event]) | ||
vim.api.nvim_exec_autocmds(event, { modeline = false }) | ||
end | ||
}) | ||
|
||
util.register_destructor(eplugins, function() | ||
pcall(vim.api.nvim_del_autocmd, id) | ||
end) | ||
|
||
end | ||
end |
c89092c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wbthomason This commit broke my packer config using
event
. I got the following error:Revert to older commit and my config's working as expected
c89092c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinging @lewis6991 also, thanks for the report @bangedorrunt. Can you share your config in a new issue?
c89092c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think this change is due to the removal of the destructor for
event
. We trigger the event again during its callback (c89092c#diff-e962cfb497bd4284996e1127113aec6b759f6a3b5290668922a9e3e96d747c3eR26) but before deleting the current event. Theonce
property apparently doesn't delete the autocommand before calling the callback. I replicated this with the following snippet:This might even be an upstream bug?
c89092c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wbthomason and @lewis6991, I'm not sure if it's OK to create new issue on experimental commit. My config is written in Fennel lang but I hope it doesn't look strange to you
packer.fnl
plugin declaration example
packer output