clipboard: support separate '+' and '*' clipboards

This commit is contained in:
Björn Linse
2014-11-22 16:01:14 +01:00
parent 8fc710110f
commit c1854d2433
3 changed files with 46 additions and 15 deletions

View File

@@ -1,8 +1,8 @@
" The clipboard provider uses shell commands to communicate with the clipboard.
" The provider function will only be registered if one of the supported
" commands are available.
let s:copy = ''
let s:paste = ''
let s:copy = {}
let s:paste = {}
function! s:try_cmd(cmd, ...)
let out = a:0 ? systemlist(a:cmd, a:1) : systemlist(a:cmd)
@@ -14,14 +14,20 @@ function! s:try_cmd(cmd, ...)
endfunction
if executable('pbcopy')
let s:copy = 'pbcopy'
let s:paste = 'pbpaste'
elseif executable('xsel')
let s:copy = 'xsel -i -b'
let s:paste = 'xsel -o -b'
let s:copy['+'] = 'pbcopy'
let s:paste['+'] = 'pbpaste'
let s:copy['*'] = s:copy['+']
let s:paste['*'] = s:paste['+']
elseif executable('xclip')
let s:copy = 'xclip -i -selection clipboard'
let s:paste = 'xclip -o -selection clipboard'
let s:copy['+'] = 'xclip -i -selection clipboard'
let s:paste['+'] = 'xclip -o -selection clipboard'
let s:copy['*'] = 'xclip -i -selection primary'
let s:paste['*'] = 'xclip -o -selection primary'
elseif executable('xsel')
let s:copy['+'] = 'xsel -i -b'
let s:paste['+'] = 'xsel -o -b'
let s:copy['*'] = 'xsel -i -p'
let s:paste['*'] = 'xsel -o -p'
else
echom 'clipboard: No shell command for communicating with the clipboard found.'
finish
@@ -29,14 +35,14 @@ endif
let s:clipboard = {}
function! s:clipboard.get(...)
return s:try_cmd(s:paste)
function! s:clipboard.get(reg)
return s:try_cmd(s:paste[a:reg])
endfunction
function! s:clipboard.set(...)
call s:try_cmd(s:copy, a:1)
function! s:clipboard.set(lines, reg)
call s:try_cmd(s:copy[a:reg], a:lines)
endfunction
function! provider#clipboard#Call(method, args)
return s:clipboard[a:method](a:args)
return call(s:clipboard[a:method],a:args,s:clipboard)
endfunction