aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2014-11-22 16:01:14 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2014-12-08 21:38:35 +0100
commitc1854d2433a10122ae2933e2dcbc970b53e9438b (patch)
treec047061b557a445669ca4f596d01428b326ab2a5
parent8fc710110f445850f50dab5f58a42ed0d8a9c7e6 (diff)
downloadrneovim-c1854d2433a10122ae2933e2dcbc970b53e9438b.tar.gz
rneovim-c1854d2433a10122ae2933e2dcbc970b53e9438b.tar.bz2
rneovim-c1854d2433a10122ae2933e2dcbc970b53e9438b.zip
clipboard: support separate '+' and '*' clipboards
-rw-r--r--runtime/autoload/provider/clipboard.vim34
-rw-r--r--src/nvim/eval.c14
-rw-r--r--src/nvim/ops.c13
3 files changed, 46 insertions, 15 deletions
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index 46c05a882c..04a3068360 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -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
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index be69bdbe61..c2156c5d58 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5119,6 +5119,20 @@ void list_append_tv(list_T *l, typval_T *tv)
}
/*
+ * Add a list to a list.
+ */
+void list_append_list(list_T *list, list_T *itemlist)
+{
+ listitem_T *li = listitem_alloc();
+
+ li->li_tv.v_type = VAR_LIST;
+ li->li_tv.v_lock = 0;
+ li->li_tv.vval.v_list = itemlist;
+ list_append(list, li);
+ ++list->lv_refcount;
+}
+
+/*
* Add a dictionary to a list. Used by getqflist().
*/
void list_append_dict(list_T *list, dict_T *dict)
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 6bf3f6036f..8dfb986714 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -5244,7 +5244,11 @@ static void get_clipboard(int name)
struct yankreg *reg = &y_regs[CLIP_REGISTER];
free_register(reg);
+
list_T *args = list_alloc();
+ char_u regname = (char_u)name;
+ list_append_string(args, &regname, 1);
+
typval_T result = eval_call_provider("clipboard", "get", args);
if (result.v_type != VAR_LIST) {
@@ -5294,6 +5298,7 @@ static void set_clipboard(int name)
if (!name && p_unc) {
// copy from the unnamed register
copy_register(reg, &y_regs[0]);
+ name = '+';
}
list_T *lines = list_alloc();
@@ -5302,5 +5307,11 @@ static void set_clipboard(int name)
list_append_string(lines, reg->y_array[i], -1);
}
- (void)eval_call_provider("clipboard", "set", lines);
+ list_T *args = list_alloc();
+ list_append_list(args, lines);
+
+ char_u regname = (char_u)name;
+ list_append_string(args, &regname, 1);
+
+ (void)eval_call_provider("clipboard", "set", args);
}