dev (#1)
* dev * Improve sync design * Support buffer local mapping * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * stylua * tmp * tmp * tmp * tmp * tmp * tmp * tmp * integration * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * update * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp * tmp
This commit is contained in:
34
lua/cmp/autocmd.lua
Normal file
34
lua/cmp/autocmd.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
local debug = require('cmp.utils.debug')
|
||||
|
||||
local autocmd = {}
|
||||
|
||||
autocmd.events = {}
|
||||
|
||||
---Subscribe autocmd
|
||||
---@param event string
|
||||
---@param callback function
|
||||
---@return function
|
||||
autocmd.subscribe = function(event, callback)
|
||||
autocmd.events[event] = autocmd.events[event] or {}
|
||||
table.insert(autocmd.events[event], callback)
|
||||
return function()
|
||||
for i, callback_ in ipairs(autocmd.events[event]) do
|
||||
if callback_ == callback then
|
||||
table.remove(autocmd.events[event], i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Emit autocmd
|
||||
---@param event string
|
||||
autocmd.emit = function(event)
|
||||
debug.log(string.format('>>> %s', event))
|
||||
autocmd.events[event] = autocmd.events[event] or {}
|
||||
for _, callback in ipairs(autocmd.events[event]) do
|
||||
callback()
|
||||
end
|
||||
end
|
||||
|
||||
return autocmd
|
||||
Reference in New Issue
Block a user