Closed moteus closed 2 years ago
@moteus, good point, but I'd deem editor.state
to be "safe" enough as long as the plugins can use specific prefixes or sub-tables, so editor.plugin.state
or editor.plugin_state
. editor:get_userdata(key)
would still need to have some information about the caller/plugin. Where would this information come from?
Your original option should work as well, if you make data
a weak table on keys. This should take care of data deletion.
Actually, you already used something like this (local SET = setmetatable({}, {__mode = 'k'})
) in #1124, so this should work ;). Or is this not working for you for some reason?
Currently for plugins that requires several actions from user (such like code snippets or easy motion) plugin code has to store its state like
data[editor] = state
and tracking closing editor to clear one. I know it is possible to just seteditor.state = ...
but its looks like not very safe solution. I think more abouteditor:get_userdata(key)
/editor:set_userdata(key, value)
. So each plugin can have its own namespace