aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/autoload')
-rw-r--r--runtime/autoload/provider/clipboard.vim32
-rw-r--r--runtime/autoload/provider/python.vim6
-rw-r--r--runtime/autoload/remote/define.vim (renamed from runtime/autoload/rpc/define.vim)36
-rw-r--r--runtime/autoload/remote/host.vim (renamed from runtime/autoload/rpc/host.vim)63
4 files changed, 75 insertions, 62 deletions
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index 615a80ca6d..46c05a882c 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -4,6 +4,15 @@
let s:copy = ''
let s:paste = ''
+function! s:try_cmd(cmd, ...)
+ let out = a:0 ? systemlist(a:cmd, a:1) : systemlist(a:cmd)
+ if v:shell_error
+ echo "clipboard: error: ".(len(out) ? out[0] : '')
+ return ''
+ endif
+ return out
+endfunction
+
if executable('pbcopy')
let s:copy = 'pbcopy'
let s:paste = 'pbpaste'
@@ -13,28 +22,21 @@ elseif executable('xsel')
elseif executable('xclip')
let s:copy = 'xclip -i -selection clipboard'
let s:paste = 'xclip -o -selection clipboard'
-endif
-
-if s:copy == ''
- echom 'No shell command for communicating with the clipboard found.'
+else
+ echom 'clipboard: No shell command for communicating with the clipboard found.'
finish
endif
-let s:methods = {}
+let s:clipboard = {}
-function! s:ClipboardGet(...)
- return systemlist(s:paste)
+function! s:clipboard.get(...)
+ return s:try_cmd(s:paste)
endfunction
-function! s:ClipboardSet(...)
- call systemlist(s:copy, a:1)
+function! s:clipboard.set(...)
+ call s:try_cmd(s:copy, a:1)
endfunction
-let s:methods = {
- \ 'get': function('s:ClipboardGet'),
- \ 'set': function('s:ClipboardSet')
- \ }
-
function! provider#clipboard#Call(method, args)
- return s:methods[a:method](a:args)
+ return s:clipboard[a:method](a:args)
endfunction
diff --git a/runtime/autoload/provider/python.vim b/runtime/autoload/provider/python.vim
index 9ca81c35f4..53b984dfe2 100644
--- a/runtime/autoload/provider/python.vim
+++ b/runtime/autoload/provider/python.vim
@@ -11,11 +11,11 @@ let s:loaded_python_provider = 1
let s:plugin_path = expand('<sfile>:p:h').'/script_host.py'
" The python provider plugin will run in a separate instance of the python
" host.
-call rpc#host#RegisterClone('legacy-python-provider', 'python')
-call rpc#host#RegisterPlugin('legacy-python-provider', s:plugin_path, [])
+call remote#host#RegisterClone('legacy-python-provider', 'python')
+call remote#host#RegisterPlugin('legacy-python-provider', s:plugin_path, [])
" Ensure that we can load the python host before bootstrapping
try
- let s:host = rpc#host#Require('legacy-python-provider')
+ let s:host = remote#host#Require('legacy-python-provider')
catch
echomsg v:exception
finish
diff --git a/runtime/autoload/rpc/define.vim b/runtime/autoload/remote/define.vim
index e7817c5fac..dd2482998d 100644
--- a/runtime/autoload/rpc/define.vim
+++ b/runtime/autoload/remote/define.vim
@@ -1,4 +1,4 @@
-function! rpc#define#CommandOnHost(host, method, sync, name, opts)
+function! remote#define#CommandOnHost(host, method, sync, name, opts)
let prefix = ''
if has_key(a:opts, 'range')
@@ -28,7 +28,7 @@ function! rpc#define#CommandOnHost(host, method, sync, name, opts)
endif
exe s:GetCommandPrefix(a:name, a:opts)
- \ .' call rpc#define#CommandBootstrap("'.a:host.'"'
+ \ .' call remote#define#CommandBootstrap("'.a:host.'"'
\ . ', "'.a:method.'"'
\ . ', "'.a:sync.'"'
\ . ', "'.a:name.'"'
@@ -38,11 +38,11 @@ function! rpc#define#CommandOnHost(host, method, sync, name, opts)
endfunction
-function! rpc#define#CommandBootstrap(host, method, sync, name, opts, forward)
- let channel = rpc#host#Require(a:host)
+function! remote#define#CommandBootstrap(host, method, sync, name, opts, forward)
+ let channel = remote#host#Require(a:host)
if channel
- call rpc#define#CommandOnChannel(channel, a:method, a:sync, a:name, a:opts)
+ call remote#define#CommandOnChannel(channel, a:method, a:sync, a:name, a:opts)
exe a:forward
else
exe 'delcommand '.a:name
@@ -51,7 +51,7 @@ function! rpc#define#CommandBootstrap(host, method, sync, name, opts, forward)
endfunction
-function! rpc#define#CommandOnChannel(channel, method, sync, name, opts)
+function! remote#define#CommandOnChannel(channel, method, sync, name, opts)
let rpcargs = [a:channel, '"'.a:method.'"']
if has_key(a:opts, 'nargs')
" -nargs, pass arguments in a list
@@ -87,12 +87,12 @@ function! rpc#define#CommandOnChannel(channel, method, sync, name, opts)
endfunction
-function! rpc#define#AutocmdOnHost(host, method, sync, name, opts)
+function! remote#define#AutocmdOnHost(host, method, sync, name, opts)
let group = s:GetNextAutocmdGroup()
let forward = '"doau '.group.' '.a:name.' ".'.'expand("<amatch>")'
let a:opts.group = group
let bootstrap_def = s:GetAutocmdPrefix(a:name, a:opts)
- \ .' call rpc#define#AutocmdBootstrap("'.a:host.'"'
+ \ .' call remote#define#AutocmdBootstrap("'.a:host.'"'
\ . ', "'.a:method.'"'
\ . ', "'.a:sync.'"'
\ . ', "'.a:name.'"'
@@ -103,12 +103,12 @@ function! rpc#define#AutocmdOnHost(host, method, sync, name, opts)
endfunction
-function! rpc#define#AutocmdBootstrap(host, method, sync, name, opts, forward)
- let channel = rpc#host#Require(a:host)
+function! remote#define#AutocmdBootstrap(host, method, sync, name, opts, forward)
+ let channel = remote#host#Require(a:host)
exe 'autocmd! '.a:opts.group
if channel
- call rpc#define#AutocmdOnChannel(channel, a:method, a:sync, a:name,
+ call remote#define#AutocmdOnChannel(channel, a:method, a:sync, a:name,
\ a:opts)
exe eval(a:forward)
else
@@ -118,7 +118,7 @@ function! rpc#define#AutocmdBootstrap(host, method, sync, name, opts, forward)
endfunction
-function! rpc#define#AutocmdOnChannel(channel, method, sync, name, opts)
+function! remote#define#AutocmdOnChannel(channel, method, sync, name, opts)
let rpcargs = [a:channel, '"'.a:method.'"']
call s:AddEval(rpcargs, a:opts)
@@ -128,10 +128,10 @@ function! rpc#define#AutocmdOnChannel(channel, method, sync, name, opts)
endfunction
-function! rpc#define#FunctionOnHost(host, method, sync, name, opts)
+function! remote#define#FunctionOnHost(host, method, sync, name, opts)
let group = s:GetNextAutocmdGroup()
exe 'autocmd! '.group.' FuncUndefined '.a:name
- \ .' call rpc#define#FunctionBootstrap("'.a:host.'"'
+ \ .' call remote#define#FunctionBootstrap("'.a:host.'"'
\ . ', "'.a:method.'"'
\ . ', "'.a:sync.'"'
\ . ', "'.a:name.'"'
@@ -141,13 +141,13 @@ function! rpc#define#FunctionOnHost(host, method, sync, name, opts)
endfunction
-function! rpc#define#FunctionBootstrap(host, method, sync, name, opts, group)
- let channel = rpc#host#Require(a:host)
+function! remote#define#FunctionBootstrap(host, method, sync, name, opts, group)
+ let channel = remote#host#Require(a:host)
exe 'autocmd! '.a:group
exe 'augroup! '.a:group
if channel
- call rpc#define#FunctionOnChannel(channel, a:method, a:sync, a:name,
+ call remote#define#FunctionOnChannel(channel, a:method, a:sync, a:name,
\ a:opts)
else
echoerr 'Host "'a:host.'" for "'.a:name.'" function is not available'
@@ -155,7 +155,7 @@ function! rpc#define#FunctionBootstrap(host, method, sync, name, opts, group)
endfunction
-function! rpc#define#FunctionOnChannel(channel, method, sync, name, opts)
+function! remote#define#FunctionOnChannel(channel, method, sync, name, opts)
let rpcargs = [a:channel, '"'.a:method.'"', 'a:000']
call s:AddEval(rpcargs, a:opts)
diff --git a/runtime/autoload/rpc/host.vim b/runtime/autoload/remote/host.vim
index 177d816df0..b07593f39b 100644
--- a/runtime/autoload/rpc/host.vim
+++ b/runtime/autoload/remote/host.vim
@@ -2,11 +2,12 @@ let s:hosts = {}
let s:plugin_patterns = {
\ 'python': '*.py'
\ }
-let s:external_plugins = fnamemodify($MYVIMRC, ':p:h').'/.external_plugins~'
+let s:remote_plugins_manifest = fnamemodify($MYVIMRC, ':p:h')
+ \.'/.'.fnamemodify($MYVIMRC, ':t').'-rplugin~'
" Register a host by associating it with a factory(funcref)
-function! rpc#host#Register(name, factory)
+function! remote#host#Register(name, factory)
let s:hosts[a:name] = {'factory': a:factory, 'channel': 0, 'initialized': 0}
if type(a:factory) == type(1) && a:factory
" Passed a channel directly
@@ -19,7 +20,7 @@ endfunction
" as `source`, but it will run as a different process. This can be used by
" plugins that should run isolated from other plugins created for the same host
" type
-function! rpc#host#RegisterClone(name, orig_name)
+function! remote#host#RegisterClone(name, orig_name)
if !has_key(s:hosts, a:orig_name)
throw 'No host named "'.a:orig_name.'" is registered'
endif
@@ -29,7 +30,7 @@ endfunction
" Get a host channel, bootstrapping it if necessary
-function! rpc#host#Require(name)
+function! remote#host#Require(name)
if !has_key(s:hosts, a:name)
throw 'No host named "'.a:name.'" is registered'
endif
@@ -42,7 +43,7 @@ function! rpc#host#Require(name)
endfunction
-function! rpc#host#IsRunning(name)
+function! remote#host#IsRunning(name)
if !has_key(s:hosts, a:name)
throw 'No host named "'.a:name.'" is registered'
endif
@@ -54,7 +55,7 @@ endfunction
" autocmd(async) and one function(sync):
"
" let s:plugin_path = expand('<sfile>:p:h').'/nvim_plugin.py'
-" call rpc#host#RegisterPlugin('python', s:plugin_path, [
+" call remote#host#RegisterPlugin('python', s:plugin_path, [
" \ {'type': 'command', 'name': 'PyCmd', 'sync': 1, 'opts': {}},
" \ {'type': 'command', 'name': 'PyAsyncCmd', 'sync': 0, 'opts': {'eval': 'cursor()'}},
" \ {'type': 'autocmd', 'name': 'BufEnter', 'sync': 0, 'opts': {'eval': 'expand("<afile>")'}},
@@ -63,7 +64,7 @@ endfunction
"
" The third item in a declaration is a boolean: non zero means the command,
" autocommand or function will be executed synchronously with rpcrequest.
-function! rpc#host#RegisterPlugin(host, path, specs)
+function! remote#host#RegisterPlugin(host, path, specs)
let plugins = s:PluginsForHost(a:host)
for plugin in plugins
@@ -72,7 +73,7 @@ function! rpc#host#RegisterPlugin(host, path, specs)
endif
endfor
- if rpc#host#IsRunning(a:host)
+ if remote#host#IsRunning(a:host)
" For now we won't allow registration of plugins when the host is already
" running.
throw 'Host "'.a:host.'" is already running'
@@ -86,7 +87,7 @@ function! rpc#host#RegisterPlugin(host, path, specs)
let rpc_method = a:path
if type == 'command'
let rpc_method .= ':command:'.name
- call rpc#define#CommandOnHost(a:host, rpc_method, sync, name, opts)
+ call remote#define#CommandOnHost(a:host, rpc_method, sync, name, opts)
elseif type == 'autocmd'
" Since multiple handlers can be attached to the same autocmd event by a
" single plugin, we need a way to uniquely identify the rpc method to
@@ -94,10 +95,10 @@ function! rpc#host#RegisterPlugin(host, path, specs)
" name(This still has a limit: one handler per event/pattern combo, but
" there's no need to allow plugins define multiple handlers in that case)
let rpc_method .= ':autocmd:'.name.':'.get(opts, 'pattern', '*')
- call rpc#define#AutocmdOnHost(a:host, rpc_method, sync, name, opts)
+ call remote#define#AutocmdOnHost(a:host, rpc_method, sync, name, opts)
elseif type == 'function'
let rpc_method .= ':function:'.name
- call rpc#define#FunctionOnHost(a:host, rpc_method, sync, name, opts)
+ call remote#define#FunctionOnHost(a:host, rpc_method, sync, name, opts)
else
echoerr 'Invalid declaration type: '.type
endif
@@ -107,9 +108,9 @@ function! rpc#host#RegisterPlugin(host, path, specs)
endfunction
-function! rpc#host#LoadExternalPlugins()
- if filereadable(s:external_plugins)
- exe 'source '.s:external_plugins
+function! remote#host#LoadRemotePlugins()
+ if filereadable(s:remote_plugins_manifest)
+ exe 'source '.s:remote_plugins_manifest
endif
endfunction
@@ -117,17 +118,22 @@ endfunction
function! s:RegistrationCommands(host)
" Register a temporary host clone for discovering specs
let host_id = a:host.'-registration-clone'
- call rpc#host#RegisterClone(host_id, a:host)
+ call remote#host#RegisterClone(host_id, a:host)
let pattern = s:plugin_patterns[a:host]
- let paths = globpath(&rtp, 'plugin/external/'.a:host.'/'.pattern, 0, 1)
+ let paths = globpath(&rtp, 'rplugin/'.a:host.'/'.pattern, 0, 1)
+ if len(paths) < 1
+ echom "Could not find any plugins when attempting to register plugin "
+ \ ."commands. See :he remote-plugin"
+ return []
+ endif
for path in paths
- call rpc#host#RegisterPlugin(host_id, path, [])
+ call remote#host#RegisterPlugin(host_id, path, [])
endfor
- let channel = rpc#host#Require(host_id)
+ let channel = remote#host#Require(host_id)
let lines = []
for path in paths
let specs = rpcrequest(channel, 'specs', path)
- call add(lines, "call rpc#host#RegisterPlugin('".a:host
+ call add(lines, "call remote#host#RegisterPlugin('".a:host
\ ."', '".path."', [")
for spec in specs
call add(lines, " \\ ".string(spec).",")
@@ -142,7 +148,7 @@ function! s:RegistrationCommands(host)
endfunction
-function! s:UpdateExternalPlugins()
+function! s:UpdateRemotePlugins()
let commands = []
let hosts = keys(s:hosts)
for host in hosts
@@ -153,11 +159,11 @@ function! s:UpdateExternalPlugins()
\ + ['', '']
endif
endfor
- call writefile(commands, s:external_plugins)
+ call writefile(commands, s:remote_plugins_manifest)
endfunction
-command! UpdateExternalPlugins call s:UpdateExternalPlugins()
+command! UpdateRemotePlugins call s:UpdateRemotePlugins()
let s:plugins_for_host = {}
@@ -213,7 +219,9 @@ function! s:RequirePythonHost(name)
" In some distros, python3 is the default python
let python_host_prog = 'python2'
else
- throw 'No python interpreter found'
+ throw 'No python interpreter found.' .
+ \ " Try setting 'let g:python_host_prog=/path/to/python' in your '.nvimrc'" .
+ \ " or see ':help nvim-python'."
endif
" Make sure we pick correct python version on path.
@@ -225,7 +233,8 @@ function! s:RequirePythonHost(name)
let import_result = system(python_host_prog .
\ ' -c "import neovim, sys; sys.stdout.write(\"ok\")"')
if import_result != 'ok'
- throw 'No neovim module found for ' . python_version
+ throw 'No neovim module found for ' . python_version . '.' .
+ \ " Try installing it with 'pip install neovim' or see ':help nvim-python'."
endif
try
@@ -235,8 +244,10 @@ function! s:RequirePythonHost(name)
endif
catch
endtry
- throw 'Failed to load python host'
+ throw 'Failed to load python host.' .
+ \ " Try upgrading the Neovim python module with 'pip install --upgrade neovim'" .
+ \ " or see ':help nvim-python'."
endfunction
-call rpc#host#Register('python', function('s:RequirePythonHost'))
+call remote#host#Register('python', function('s:RequirePythonHost'))
" }}}