From 3267c9087d2ffc0ec82f9a4eef5fc057bdc14887 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 15 Feb 2025 14:44:19 +0800 Subject: [PATCH] feat(nvim-plug): add `fetch` option --- bundle/nvim-plug/README.md | 72 ++++++++++++++++++++-------- bundle/nvim-plug/lua/plug/loader.lua | 4 +- bundle/nvim-plug/test/init.lua | 4 ++ 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/bundle/nvim-plug/README.md b/bundle/nvim-plug/README.md index ec749a944..7c94ee657 100644 --- a/bundle/nvim-plug/README.md +++ b/bundle/nvim-plug/README.md @@ -13,6 +13,7 @@ - [Installation](#installation) - [Setup nvim-plug](#setup-nvim-plug) - [Add plugins](#add-plugins) + - [Self upgrade](#self-upgrade) - [Plugin Spec](#plugin-spec) - [Commands](#commands) - [Default UI](#default-ui) @@ -129,31 +130,60 @@ require('plug').add({ }) ``` +### Self upgrade + +you can use nvim-plug to manager nvim-plug: + +```lua +if vim.fn.isdirectory('D:/bundle_dir/wsdjeg/nvim-plug') == 0 then + vim.fn.system({ + 'git', + 'clone', + '--depth', + '1', + 'https://github.com/wsdjeg/nvim-plug.git', + 'D:/bundle_dir/wsdjeg/nvim-plug', + }) +end +vim.opt.runtimepath:append('D:/bundle_dir/wsdjeg/nvim-plug') +require('plug').setup({ + -- set the bundle dir + bundle_dir = 'D:/bundle_dir', +}) +require('plug').add({ + { + 'wsdjeg/nvim-plug', + fetch = true, + }, +}) +``` + ## Plugin Spec The plugin spec is inspired by [dein.nvim](https://github.com/Shougo/dein.vim). -| name | description | -| --------------- | ------------------------------------------------------------------------------------------------------------- | -| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` | -| `cmds` | `string` or `table`, commands lazy loading | -| `events` | `string` or `table`, events lazy loading | -| `config` | `function`, function called after adding plugin path to nvim rtp, before loading files in `plugin/` directory | -| `config_after` | `function`, function called after loading files in `plugin/` directory | -| `config_before` | `function`, function called when `plug.add()` function is called | -| `on_ft` | `string` or `table`, filetypes lazy loading | -| `on_map` | `string` or `table`, key bindings lazy loading | -| `on_func` | `string` or `table`, vim function lazy loading | -| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. | -| `build` | `string` or `table`, executed by [job](https://spacevim.org/api/job/) api | -| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped | -| `frozen` | update only when specific with `PlugUpdate name` | -| `depends` | `table` a list of plugins | -| `branch` | `string` specific git branch | -| `tag` | `string` specific git tag | -| `type` | `string` specific plugin type, this can be git, raw or none, if it is raw, `script_type` must be set | -| `autoload` | `boolean`, load plugin after git clone | -| `priority` | `number`, default is 50, set the order in which plugins are loaded | +| name | description | +| --------------- | ---------------------------------------------------------------------------------------------------------------- | +| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` | +| `cmds` | `string` or `table`, commands lazy loading | +| `events` | `string` or `table`, events lazy loading | +| `config` | `function`, function called after adding plugin path to nvim rtp, before loading files in `plugin/` directory | +| `config_after` | `function`, function called after loading files in `plugin/` directory | +| `config_before` | `function`, function called when `plug.add()` function is called | +| `on_ft` | `string` or `table`, filetypes lazy loading | +| `on_map` | `string` or `table`, key bindings lazy loading | +| `on_func` | `string` or `table`, vim function lazy loading | +| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. | +| `build` | `string` or `table`, executed by [job](https://spacevim.org/api/job/) api | +| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped | +| `frozen` | update only when specific with `PlugUpdate name` | +| `depends` | `table` a list of plugins | +| `branch` | `string` specific git branch | +| `tag` | `string` specific git tag | +| `type` | `string` specific plugin type, this can be git, raw or none, if it is raw, `script_type` must be set | +| `autoload` | `boolean`, load plugin after git clone | +| `priority` | `number`, default is 50, set the order in which plugins are loaded | +| `fetch` | If set to true, nvim-plug doesn't add the path to user runtimepath. It is useful to manager no-plugin repository | - `config` and `config_after` function will be not be called if the plugin has not been installed. - `priority` does not work for lazy plugins. diff --git a/bundle/nvim-plug/lua/plug/loader.lua b/bundle/nvim-plug/lua/plug/loader.lua index c5997723b..43e765f92 100644 --- a/bundle/nvim-plug/lua/plug/loader.lua +++ b/bundle/nvim-plug/lua/plug/loader.lua @@ -32,6 +32,7 @@ local loaded_plugins = {} --- @field config_after function function called after update rtp --- @field hook_install_done? function --- @field autoload? boolean +--- @field fetch? boolean If set to true, nvim-plug doesn't add the path to user runtimepath, and doesn't load the bundle --- @param plugSpec PluginSpec --- @return boolean @@ -95,7 +96,7 @@ function M.parser(plugSpec) plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/plugin' plugSpec.url = config.base_url .. '/' .. plugSpec[1] end - if type(plugSpec.autoload) == 'nil' and plugSpec.type ~= 'raw' then + if type(plugSpec.autoload) == 'nil' and plugSpec.type ~= 'raw' and not plugSpec.fetch then plugSpec.autoload = true end @@ -111,6 +112,7 @@ function M.load(plugSpec) plugSpec.rtp and vim.fn.isdirectory(plugSpec.rtp) == 1 and not loaded_plugins[plugSpec.name] + and not plugSpec.fetch then vim.opt.runtimepath:append(plugSpec.rtp) loaded_plugins[plugSpec.name] = true diff --git a/bundle/nvim-plug/test/init.lua b/bundle/nvim-plug/test/init.lua index e131404f5..1adadbbbb 100644 --- a/bundle/nvim-plug/test/init.lua +++ b/bundle/nvim-plug/test/init.lua @@ -42,6 +42,10 @@ require('plug').add({ 'wsdjeg/git.vim', cmds = { 'Git' }, }, + { + 'wsdjeg/nvim-plug', + fetch = true, + }, { 'wsdjeg/JavaUnit.vim', cmds = { 'JavaUnit' },