From 0a1b852cd10aafc35a12fbfd9f756c5465c6c50c Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 29 Oct 2016 02:48:49 +0200 Subject: provider/clipboard.vim: refactor --- runtime/autoload/provider/clipboard.vim | 66 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'runtime/autoload/provider') diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index 0f4aa78ddd..7a977c391e 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -31,33 +31,45 @@ function! s:try_cmd(cmd, ...) endfunction let s:cache_enabled = 1 -if executable('pbcopy') - let s:copy['+'] = 'pbcopy' - let s:paste['+'] = 'pbpaste' - let s:copy['*'] = s:copy['+'] - let s:paste['*'] = s:paste['+'] - let s:cache_enabled = 0 -elseif exists('$DISPLAY') && executable('xsel') - let s:copy['+'] = 'xsel --nodetach -i -b' - let s:paste['+'] = 'xsel -o -b' - let s:copy['*'] = 'xsel --nodetach -i -p' - let s:paste['*'] = 'xsel -o -p' -elseif exists('$DISPLAY') && executable('xclip') - let s:copy['+'] = 'xclip -quiet -i -selection clipboard' - let s:paste['+'] = 'xclip -o -selection clipboard' - let s:copy['*'] = 'xclip -quiet -i -selection primary' - let s:paste['*'] = 'xclip -o -selection primary' -elseif executable('lemonade') - let s:copy['+'] = 'lemonade copy' - let s:paste['+'] = 'lemonade paste' - let s:copy['*'] = 'lemonade copy' - let s:paste['*'] = 'lemonade paste' -elseif executable('doitclient') - let s:copy['+'] = 'doitclient wclip' - let s:paste['+'] = 'doitclient wclip -r' - let s:copy['*'] = s:copy['+'] - let s:paste['*'] = s:paste['+'] -else + +function! provider#clipboard#Executable() abort + if executable('pbcopy') + let s:copy['+'] = 'pbcopy' + let s:paste['+'] = 'pbpaste' + let s:copy['*'] = s:copy['+'] + let s:paste['*'] = s:paste['+'] + let s:cache_enabled = 0 + return 'pbcopy' + elseif exists('$DISPLAY') && executable('xsel') + let s:copy['+'] = 'xsel --nodetach -i -b' + let s:paste['+'] = 'xsel -o -b' + let s:copy['*'] = 'xsel --nodetach -i -p' + let s:paste['*'] = 'xsel -o -p' + return 'xsel' + elseif exists('$DISPLAY') && executable('xclip') + let s:copy['+'] = 'xclip -quiet -i -selection clipboard' + let s:paste['+'] = 'xclip -o -selection clipboard' + let s:copy['*'] = 'xclip -quiet -i -selection primary' + let s:paste['*'] = 'xclip -o -selection primary' + return 'xclip' + elseif executable('lemonade') + let s:copy['+'] = 'lemonade copy' + let s:paste['+'] = 'lemonade paste' + let s:copy['*'] = 'lemonade copy' + let s:paste['*'] = 'lemonade paste' + return 'lemonade' + elseif executable('doitclient') + let s:copy['+'] = 'doitclient wclip' + let s:paste['+'] = 'doitclient wclip -r' + let s:copy['*'] = s:copy['+'] + let s:paste['*'] = s:paste['+'] + return 'doitclient' + endif + + return '' +endfunction + +if empty(provider#clipboard#Executable()) echom 'clipboard: No clipboard tool available. See :help clipboard' finish endif -- cgit From 3a802e3c16d2a06f455fb45901ffa6954098f853 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 29 Oct 2016 14:35:15 +0200 Subject: provider/clipboard.vim: never show a warning on sourcing Never throw an error when provider/clipboard.vim is sourced for the first time. Save the error instead and expose it via `provider#clipboard#Error()`, mimicking provider/python.vim. --- runtime/autoload/provider/clipboard.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'runtime/autoload/provider') diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index 7a977c391e..f63ad5730b 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -31,6 +31,11 @@ function! s:try_cmd(cmd, ...) endfunction let s:cache_enabled = 1 +let s:err = '' + +function! provider#clipboard#Error() abort + return s:err +endfunction function! provider#clipboard#Executable() abort if executable('pbcopy') @@ -66,11 +71,11 @@ function! provider#clipboard#Executable() abort return 'doitclient' endif + let s:err = 'clipboard: No clipboard tool available. See :help clipboard' return '' endfunction if empty(provider#clipboard#Executable()) - echom 'clipboard: No clipboard tool available. See :help clipboard' finish endif -- cgit