diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2019-04-03 19:57:48 +0200 |
---|---|---|
committer | Marco Hinz <mh.codebro@gmail.com> | 2019-04-04 20:24:39 +0200 |
commit | 6b75d9f865b9a1ef56dbf9e4485aaf133efa2f22 (patch) | |
tree | e535cda127dbdcfe36ea2003d4f8247fdabd4719 | |
parent | fb555c6898e8deddf6191144b18b382fa8decf99 (diff) | |
download | rneovim-6b75d9f865b9a1ef56dbf9e4485aaf133efa2f22.tar.gz rneovim-6b75d9f865b9a1ef56dbf9e4485aaf133efa2f22.tar.bz2 rneovim-6b75d9f865b9a1ef56dbf9e4485aaf133efa2f22.zip |
vim-patch:8.1.0218: cannot add matches to another window
Problem: Cannot add matches to another window. (Qiming Zhao)
Solution: Add the "window" argument to matchadd() and matchaddpos().
(closes vim/vim#3260)
https://github.com/vim/vim/commit/95e51470f10e1ddcc4b2ce53e4f7ff7aa2e58417
-rw-r--r-- | runtime/doc/eval.txt | 4 | ||||
-rw-r--r-- | src/nvim/eval.c | 59 | ||||
-rw-r--r-- | src/nvim/testdir/test_match.vim | 22 |
3 files changed, 60 insertions, 25 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 1f83d0de54..db278b2fb0 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5554,7 +5554,7 @@ match({expr}, {pat} [, {start} [, {count}]]) *match()* the pattern. 'smartcase' is NOT used. The matching is always done like 'magic' is set and 'cpoptions' is empty. - *matchadd()* *E798* *E799* *E801* + *matchadd()* *E798* *E799* *E801* *E957* matchadd({group}, {pattern}[, {priority}[, {id} [, {dict}]]]) Defines a pattern to be highlighted in the current window (a "match"). It will be highlighted with {group}. Returns an @@ -5593,6 +5593,8 @@ matchadd({group}, {pattern}[, {priority}[, {id} [, {dict}]]]) conceal Special character to show instead of the match (only for |hl-Conceal| highlighed matches, see |:syn-cchar|) + window Instead of the current window use the + window with this number or window ID. The number of matches is not limited, as it is the case with the |:match| commands. diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 66c46e2478..68a0c86583 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12528,6 +12528,31 @@ static void f_match(typval_T *argvars, typval_T *rettv, FunPtr fptr) find_some_match(argvars, rettv, kSomeMatch); } +static int matchadd_dict_arg(typval_T *tv, const char **conceal_char, + win_T **win) +{ + dictitem_T *di; + + if (tv->v_type != VAR_DICT) { + EMSG(_(e_dictreq)); + return FAIL; + } + + if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("conceal"))) != NULL) { + *conceal_char = tv_get_string(&di->di_tv); + } + + if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("window"))) != NULL) { + *win = find_win_by_nr(&di->di_tv, NULL); + if (*win == NULL) { + EMSG(_("E957: Invalid window number")); + return FAIL; + } + } + + return OK; +} + /* * "matchadd()" function */ @@ -12541,6 +12566,7 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv, FunPtr fptr) int id = -1; bool error = false; const char *conceal_char = NULL; + win_T *win = curwin; rettv->vval.v_number = -1; @@ -12551,16 +12577,9 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv, FunPtr fptr) prio = tv_get_number_chk(&argvars[2], &error); if (argvars[3].v_type != VAR_UNKNOWN) { id = tv_get_number_chk(&argvars[3], &error); - if (argvars[4].v_type != VAR_UNKNOWN) { - if (argvars[4].v_type != VAR_DICT) { - EMSG(_(e_dictreq)); - return; - } - dictitem_T *di; - if ((di = tv_dict_find(argvars[4].vval.v_dict, S_LEN("conceal"))) - != NULL) { - conceal_char = tv_get_string(&di->di_tv); - } + if (argvars[4].v_type != VAR_UNKNOWN + && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL) { + return; } } } @@ -12572,8 +12591,7 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - rettv->vval.v_number = match_add(curwin, grp, pat, prio, id, NULL, - conceal_char); + rettv->vval.v_number = match_add(win, grp, pat, prio, id, NULL, conceal_char); } static void f_matchaddpos(typval_T *argvars, typval_T *rettv, FunPtr fptr) @@ -12601,21 +12619,15 @@ static void f_matchaddpos(typval_T *argvars, typval_T *rettv, FunPtr fptr) int prio = 10; int id = -1; const char *conceal_char = NULL; + win_T *win = curwin; if (argvars[2].v_type != VAR_UNKNOWN) { prio = tv_get_number_chk(&argvars[2], &error); if (argvars[3].v_type != VAR_UNKNOWN) { id = tv_get_number_chk(&argvars[3], &error); - if (argvars[4].v_type != VAR_UNKNOWN) { - if (argvars[4].v_type != VAR_DICT) { - EMSG(_(e_dictreq)); - return; - } - dictitem_T *di; - if ((di = tv_dict_find(argvars[4].vval.v_dict, S_LEN("conceal"))) - != NULL) { - conceal_char = tv_get_string(&di->di_tv); - } + if (argvars[4].v_type != VAR_UNKNOWN + && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL) { + return; } } } @@ -12629,8 +12641,7 @@ static void f_matchaddpos(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - rettv->vval.v_number = match_add(curwin, group, NULL, prio, id, l, - conceal_char); + rettv->vval.v_number = match_add(win, group, NULL, prio, id, l, conceal_char); } /* diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index e608a2e58b..e926b946a9 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -202,6 +202,28 @@ func Test_matchaddpos() set hlsearch& endfunc +func Test_matchaddpos_otherwin() + syntax on + new + call setline(1, ['12345', 'NP']) + let winid = win_getid() + + wincmd w + call matchadd('Search', '4', 10, -1, {'window': winid}) + call matchaddpos('Error', [[1,2], [2,2]], 10, -1, {'window': winid}) + redraw! + call assert_notequal(screenattr(1,2), 0) + call assert_notequal(screenattr(1,4), 0) + call assert_notequal(screenattr(2,2), 0) + call assert_equal(screenattr(1,2), screenattr(2,2)) + call assert_notequal(screenattr(1,2), screenattr(1,4)) + + wincmd w + bwipe! + call clearmatches() + syntax off +endfunc + func Test_matchaddpos_using_negative_priority() set hlsearch |