diff options
Diffstat (limited to 'lua/user/vimplug.lua')
-rw-r--r-- | lua/user/vimplug.lua | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lua/user/vimplug.lua b/lua/user/vimplug.lua new file mode 100644 index 0000000..f182a4b --- /dev/null +++ b/lua/user/vimplug.lua @@ -0,0 +1,65 @@ +local configs = { + lazy = {}, + start = {} +} + +local Plug = { + begin = vim.fn['plug#begin'], + + -- "end" is a keyword, need something else + ends = function() + vim.fn['plug#end']() + + for i, config in pairs(configs.start) do + config() + end + end +} + +-- Not a fan of global functions, but it'll work better +-- for the people that will copy/paste this +_G.VimPlugApplyConfig = function(plugin_name) + local fn = configs.lazy[plugin_name] + if type(fn) == 'function' then fn() end +end + +local plug_name = function(repo) + return repo:match("^[%w-]+/([%w-_.]+)$") +end + +-- "Meta-functions" +local meta = { + + -- Function call "operation" + __call = function(self, repo, opts) + opts = opts or vim.empty_dict() + + -- we declare some aliases for `do` and `for` + opts['do'] = opts.run + opts.run = nil + + opts['for'] = opts.ft + opts.ft = nil + + vim.call('plug#', repo, opts) + + -- Add basic support to colocate plugin config + if type(opts.config) == 'function' then + local plugin = opts.as or plug_name(repo) + + if opts['for'] == nil and opts.on == nil then + configs.start[plugin] = opts.config + else + configs.lazy[plugin] = opts.config + + local user_cmd = [[ autocmd! User %s ++once lua VimPlugApplyConfig('%s') ]] + vim.cmd(user_cmd:format(plugin, plugin)) + end + + end + end +} + +-- Meta-tables are awesome +return setmetatable(Plug, meta) + |