From 0a1b852cd10aafc35a12fbfd9f756c5465c6c50c Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 29 Oct 2016 02:48:49 +0200 Subject: [PATCH 1/3] provider/clipboard.vim: refactor --- runtime/autoload/provider/clipboard.vim | 66 +++++++++++++++---------- 1 file changed, 39 insertions(+), 27 deletions(-) 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 From 797d72a9973b4c9978dae48ca677b26d6fe36c83 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 29 Oct 2016 03:39:29 +0200 Subject: [PATCH 2/3] health/provider.vim: add clipboard check --- runtime/autoload/health/provider.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim index d4b2f07a17..3c40e48b2e 100644 --- a/runtime/autoload/health/provider.vim +++ b/runtime/autoload/health/provider.vim @@ -45,6 +45,19 @@ function! s:download(url) abort return 'missing `curl` and `python`, cannot make pypi request' endfunction +" Check for clipboard tools. +function! s:check_clipboard() abort + call health#report_start('Clipboard') + + let clipboard_tool = provider#clipboard#Executable() + if empty(clipboard_tool) + call health#report_warn( + \ "No clipboard tool found. Using the system clipboard won't work.", + \ ['See ":help clipboard"']) + else + call health#report_ok('Clipboard tool found: '. clipboard_tool) + endif +endfunction " Get the latest Neovim Python client version from PyPI. function! s:latest_pypi_version() abort @@ -371,6 +384,7 @@ function! s:check_ruby() abort endfunction function! health#provider#check() abort + call s:check_clipboard() call s:check_python(2) call s:check_python(3) call s:check_ruby() From 3a802e3c16d2a06f455fb45901ffa6954098f853 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 29 Oct 2016 14:35:15 +0200 Subject: [PATCH 3/3] 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(-) 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