aboutsummaryrefslogtreecommitdiff
path: root/runtime/plugin
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-03-10 22:01:34 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-03-11 12:26:22 +0100
commitd1afd434f30202410b217e7137c4a2a4fe055dbe (patch)
treecd83e1b66c2885975cc1c296d96cc47369251b6b /runtime/plugin
parent1743df82f9003514c384ff99779d82179e6cb999 (diff)
downloadrneovim-d1afd434f30202410b217e7137c4a2a4fe055dbe.tar.gz
rneovim-d1afd434f30202410b217e7137c4a2a4fe055dbe.tar.bz2
rneovim-d1afd434f30202410b217e7137c4a2a4fe055dbe.zip
rplugin: Call s:LoadRemotePlugins() on startup.
Dispense with the FuncUndefined/CmdUndefined quasi-optimization. If there are no rplugins, plugin/rplugin.vim takes less than 1ms. Closes #5821 Closes #6250 Helped-by: Qiming zhao <chemzqm@gmail.com>
Diffstat (limited to 'runtime/plugin')
-rw-r--r--runtime/plugin/rplugin.vim63
1 files changed, 53 insertions, 10 deletions
diff --git a/runtime/plugin/rplugin.vim b/runtime/plugin/rplugin.vim
index b4b03032b3..7d83668a30 100644
--- a/runtime/plugin/rplugin.vim
+++ b/runtime/plugin/rplugin.vim
@@ -1,16 +1,59 @@
if exists('g:loaded_remote_plugins')
finish
endif
-let g:loaded_remote_plugins = 1
+let g:loaded_remote_plugins = '/path/to/manifest'
+
+" Get the path to the rplugin manifest file.
+function! s:GetManifestPath() abort
+ let manifest_base = ''
+
+ if exists('$NVIM_RPLUGIN_MANIFEST')
+ return fnamemodify($NVIM_RPLUGIN_MANIFEST, ':p')
+ endif
+
+ let dest = has('win32') ? '$LOCALAPPDATA' : '$XDG_DATA_HOME'
+ if !exists(dest)
+ let dest = has('win32') ? '~/AppData/Local' : '~/.local/share'
+ endif
+
+ let dest = fnamemodify(expand(dest), ':p')
+ if !empty(dest) && !filereadable(dest)
+ let dest .= ('/' ==# dest[-1:] ? '' : '/') . 'nvim'
+ call mkdir(dest, 'p', 0700)
+ let manifest_base = dest
+ endif
+
+ return manifest_base.'/rplugin.vim'
+endfunction
+
+" Old manifest file based on known script locations.
+function! s:GetOldManifestPath() abort
+ let prefix = exists('$MYVIMRC')
+ \ ? $MYVIMRC
+ \ : matchstr(get(split(execute('scriptnames'), '\n'), 0, ''), '\f\+$')
+ return fnamemodify(expand(prefix, 1), ':h')
+ \.'/.'.fnamemodify(prefix, ':t').'-rplugin~'
+endfunction
+
+function! s:GetManifest() abort
+ let manifest = s:GetManifestPath()
+ if !filereadable(manifest)
+ " Check if an old manifest file exists and move it to the new location.
+ let old_manifest = s:GetOldManifestPath()
+ if filereadable(old_manifest)
+ call rename(old_manifest, manifest)
+ endif
+ endif
+ return manifest
+endfunction
+
+function! s:LoadRemotePlugins() abort
+ let g:loaded_remote_plugins = s:GetManifest()
+ if filereadable(g:loaded_remote_plugins)
+ execute 'source' fnameescape(g:loaded_remote_plugins)
+ endif
+endfunction
command! UpdateRemotePlugins call remote#host#UpdateRemotePlugins()
-augroup nvim-rplugin
- autocmd!
- autocmd FuncUndefined *
- \ call remote#host#LoadRemotePluginsEvent(
- \ 'FuncUndefined', expand('<amatch>'))
- autocmd CmdUndefined *
- \ call remote#host#LoadRemotePluginsEvent(
- \ 'CmdUndefined', expand('<amatch>'))
-augroup END
+call s:LoadRemotePlugins()