mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 02:27:58 +08:00
feat(nvim-plug): add on_ft
support
This commit is contained in:
parent
bbf79d8b4c
commit
e80046552b
6
bundle/nvim-plug/README.md
vendored
6
bundle/nvim-plug/README.md
vendored
@ -5,6 +5,8 @@
|
||||
[![](https://spacevim.org/img/build-with-SpaceVim.svg)](https://spacevim.org)
|
||||
[![GPLv3 License](https://img.spacevim.org/license-GPLv3-blue.svg)](LICENSE)
|
||||
|
||||
**Alpha version. Any changes, including backward incompatible changes, are applied without announcements.**
|
||||
|
||||
## Usage
|
||||
|
||||
```lua
|
||||
@ -32,9 +34,11 @@ require("plug").add({
|
||||
## Plugin Spec
|
||||
|
||||
| name | description |
|
||||
| ------ | ------------------------------------------------------- |
|
||||
| -------- | ------------------------------------------------------- |
|
||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||
| `cmds` | `table<string>`, commands lazy loading |
|
||||
| `events` | `table<string>`, events lazy loading |
|
||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||
|
||||
## Commands
|
||||
|
||||
|
26
bundle/nvim-plug/lua/plug/hooks.lua
vendored
26
bundle/nvim-plug/lua/plug/hooks.lua
vendored
@ -1,18 +1,22 @@
|
||||
local M = {}
|
||||
|
||||
local group = vim.api.nvim_create_augroup("plugin_hooks", { clear = true })
|
||||
local group = vim.api.nvim_create_augroup('plugin_hooks', { clear = true })
|
||||
|
||||
local plugin_loader = require("plug.loader")
|
||||
local plugin_loader = require('plug.loader')
|
||||
|
||||
local event_plugins = {}
|
||||
local cmd_plugins = {}
|
||||
local on_ft_plugins = {}
|
||||
|
||||
function M.on_events(events, plugSpec)
|
||||
event_plugins[plugSpec.name] = vim.api.nvim_create_autocmd(events, {
|
||||
group = group,
|
||||
pattern = { "*" },
|
||||
pattern = { '*' },
|
||||
callback = function(_)
|
||||
vim.api.nvim_del_autocmd(event_plugins[plugSpec.name])
|
||||
if on_ft_plugins[plugSpec.name] then
|
||||
vim.api.nvim_del_autocmd(on_ft_plugins[plugSpec.name])
|
||||
end
|
||||
plugin_loader.load(plugSpec)
|
||||
end,
|
||||
})
|
||||
@ -27,7 +31,7 @@ function M.on_cmds(cmds, plugSpec)
|
||||
plugin_loader.load(cmd_plugins[opt.name])
|
||||
vim.cmd(opt.name .. ' ' .. opt.args)
|
||||
end, {
|
||||
nargs = "*",
|
||||
nargs = '*',
|
||||
complete = function(...)
|
||||
return {}
|
||||
end,
|
||||
@ -35,4 +39,18 @@ function M.on_cmds(cmds, plugSpec)
|
||||
end
|
||||
end
|
||||
|
||||
function M.on_ft(fts, plugSpec)
|
||||
on_ft_plugins[plugSpec.name] = vim.api.nvim_create_autocmd({ 'FileType' }, {
|
||||
group = group,
|
||||
pattern = fts,
|
||||
callback = function(_)
|
||||
vim.api.nvim_del_autocmd(on_ft_plugins[plugSpec.name])
|
||||
if event_plugins[plugSpec.name] then
|
||||
vim.api.nvim_del_autocmd(event_plugins[plugSpec.name])
|
||||
end
|
||||
plugin_loader.load(plugSpec)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
6
bundle/nvim-plug/lua/plug/init.lua
vendored
6
bundle/nvim-plug/lua/plug/init.lua
vendored
@ -29,7 +29,11 @@ function M.add(plugins)
|
||||
hooks.on_events(plug.events, plug)
|
||||
end
|
||||
|
||||
if not plug.events and not plug.cmds then
|
||||
if plug.on_ft then
|
||||
hooks.on_ft(plug.on_ft, plug)
|
||||
end
|
||||
|
||||
if not plug.events and not plug.cmds and not plug.on_ft then
|
||||
loader.load(plug)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user