rplugin.vim 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. if exists('g:loaded_remote_plugins')
  2. finish
  3. endif
  4. let g:loaded_remote_plugins = '/path/to/manifest'
  5. " Get the path to the rplugin manifest file.
  6. function! s:GetManifestPath() abort
  7. let manifest_base = ''
  8. if exists('$NVIM_RPLUGIN_MANIFEST')
  9. return fnamemodify($NVIM_RPLUGIN_MANIFEST, ':p')
  10. endif
  11. let dest = stdpath('data')
  12. if !empty(dest)
  13. if !isdirectory(dest)
  14. if getftype(dest) != "link"
  15. call mkdir(dest, 'p', 0700)
  16. endif
  17. endif
  18. let manifest_base = dest
  19. endif
  20. return manifest_base.'/rplugin.vim'
  21. endfunction
  22. " Old manifest file based on known script locations.
  23. function! s:GetOldManifestPaths() abort
  24. let prefix = exists('$MYVIMRC')
  25. \ ? $MYVIMRC
  26. \ : matchstr(get(split(execute('scriptnames'), '\n'), 0, ''), '\f\+$')
  27. let origpath = fnamemodify(expand(prefix, 1), ':h')
  28. \.'/.'.fnamemodify(prefix, ':t').'-rplugin~'
  29. if !has('win32')
  30. return [origpath]
  31. endif
  32. " Windows used to use $APPLOCALDATA/nvim but stdpath('data') is
  33. " $XDG_DATA_DIR/nvim-data
  34. let pseudostdpath = exists('$LOCALAPPDATA') ? '$LOCALAPPDATA' : '~/AppData/Local'
  35. let pseudostdpath = fnamemodify(expand(pseudostdpath), ':p')
  36. return [substitute(pseudostdpath, '[/\\]\=$', '/', '') . 'nvim/rplugin.vim', origpath]
  37. endfunction
  38. function! s:GetManifest() abort
  39. let manifest = s:GetManifestPath()
  40. if !filereadable(manifest)
  41. " Check if an old manifest file exists and move it to the new location.
  42. for old_manifest in s:GetOldManifestPaths()
  43. if filereadable(old_manifest)
  44. call rename(old_manifest, manifest)
  45. break
  46. endif
  47. endfor
  48. endif
  49. return manifest
  50. endfunction
  51. function! s:LoadRemotePlugins() abort
  52. let g:loaded_remote_plugins = s:GetManifest()
  53. if filereadable(g:loaded_remote_plugins)
  54. execute 'source' fnameescape(g:loaded_remote_plugins)
  55. endif
  56. endfunction
  57. command! -bar UpdateRemotePlugins call remote#host#UpdateRemotePlugins()
  58. if index(v:argv, "--clean") < 0
  59. call s:LoadRemotePlugins()
  60. endif