aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-11-23 17:53:12 -0500
committerJustin M. Keyes <justinkz@gmail.com>2014-11-23 17:53:12 -0500
commit1c25f1d9475ad763138c67f538aee37ef9ab5aee (patch)
tree81f807824db31d8a4b471689969c18d5d2fcb2ed
parentf4e125de2dd92e149510e300c139568fc5e83f9d (diff)
parentc10f7e1c624f2e1b2b1aced74ab782b588e49672 (diff)
downloadrneovim-1c25f1d9475ad763138c67f538aee37ef9ab5aee.tar.gz
rneovim-1c25f1d9475ad763138c67f538aee37ef9ab5aee.tar.bz2
rneovim-1c25f1d9475ad763138c67f538aee37ef9ab5aee.zip
Merge pull request #1525 from justinmk/clipboardX
clipboard: check for X on every invocation
-rw-r--r--runtime/autoload/provider/clipboard.vim32
1 files changed, 17 insertions, 15 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