aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/funcs.c
diff options
context:
space:
mode:
authorShougo <Shougo.Matsu@gmail.com>2020-05-16 22:25:51 +0900
committerGitHub <noreply@github.com>2020-05-16 15:25:51 +0200
commitd7d69fed18c2cd59d28ff12ef72f6fb2a98a7b66 (patch)
treec854446549f57498c8e07481a721c37c6a2e2d32 /src/nvim/eval/funcs.c
parentf3d0a1741ef69222ab7893ce4f801d26b6b3fb00 (diff)
downloadrneovim-d7d69fed18c2cd59d28ff12ef72f6fb2a98a7b66.tar.gz
rneovim-d7d69fed18c2cd59d28ff12ef72f6fb2a98a7b66.tar.bz2
rneovim-d7d69fed18c2cd59d28ff12ef72f6fb2a98a7b66.zip
vim-patch:8.1.1084: cannot delete a match from another window (#12325)
Problem: Cannot delete a match from another window. (Paul Jolly) Solution: Add window ID argument to matchdelete(), clearmatches(), getmatches() and setmatches(). (Andy Massimino, closes vim/vim#4178) https://github.com/vim/vim/commit/aff749145e23c0f20b5158d1d3a942948ed138e3
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r--src/nvim/eval/funcs.c53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index c7df1d6753..8289f9515c 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -93,6 +93,7 @@ PRAGMA_DIAG_POP
static char *e_listarg = N_("E686: Argument of %s must be a List");
static char *e_stringreq = N_("E928: String required");
+static char *e_invalwindow = N_("E957: Invalid window number");
/// Dummy va_list for passing to vim_snprintf
///
@@ -952,12 +953,30 @@ static void f_cindent(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = -1;
}
+static win_T * get_optional_window(typval_T *argvars, int idx)
+{
+ win_T *win = curwin;
+
+ if (argvars[idx].v_type != VAR_UNKNOWN) {
+ win = find_win_by_nr_or_id(&argvars[idx]);
+ if (win == NULL) {
+ EMSG(_(e_invalwindow));
+ return NULL;
+ }
+ }
+ return win;
+}
+
/*
* "clearmatches()" function
*/
static void f_clearmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- clear_matches(curwin);
+ win_T *win = get_optional_window(argvars, 0);
+
+ if (win != NULL) {
+ clear_matches(win);
+ }
}
/*
@@ -3452,10 +3471,16 @@ static void f_getloclist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/
static void f_getmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- matchitem_T *cur = curwin->w_match_head;
+ matchitem_T *cur;
int i;
+ win_T *win = get_optional_window(argvars, 0);
+
+ if (win == NULL) {
+ return;
+ }
tv_list_alloc_ret(rettv, kListLenMayKnow);
+ cur = win->w_match_head;
while (cur != NULL) {
dict_T *dict = tv_dict_alloc();
if (cur->match.regprog == NULL) {
@@ -5771,8 +5796,13 @@ static void f_matcharg(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/
static void f_matchdelete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- rettv->vval.v_number = match_delete(curwin,
- (int)tv_get_number(&argvars[0]), true);
+ win_T *win = get_optional_window(argvars, 1);
+ if (win == NULL) {
+ rettv->vval.v_number = -1;
+ } else {
+ rettv->vval.v_number = match_delete(curwin,
+ (int)tv_get_number(&argvars[0]), true);
+ }
}
/*
@@ -8136,14 +8166,19 @@ static void f_setloclist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/
static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- dict_T *d;
- list_T *s = NULL;
+ dict_T *d;
+ list_T *s = NULL;
+ win_T *win = get_optional_window(argvars, 1);
rettv->vval.v_number = -1;
if (argvars[0].v_type != VAR_LIST) {
EMSG(_(e_listreq));
return;
}
+ if (win == NULL) {
+ return;
+ }
+
list_T *const l = argvars[0].vval.v_list;
// To some extent make sure that we are dealing with a list from
// "getmatches()".
@@ -8167,7 +8202,7 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
li_idx++;
});
- clear_matches(curwin);
+ clear_matches(win);
bool match_add_failed = false;
TV_LIST_ITER_CONST(l, li, {
int i = 0;
@@ -8213,13 +8248,13 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
? tv_get_string(&conceal_di->di_tv)
: NULL);
if (i == 0) {
- if (match_add(curwin, group,
+ if (match_add(win, group,
tv_dict_get_string(d, "pattern", false),
priority, id, NULL, conceal) != id) {
match_add_failed = true;
}
} else {
- if (match_add(curwin, group, NULL, priority, id, s, conceal) != id) {
+ if (match_add(win, group, NULL, priority, id, s, conceal) != id) {
match_add_failed = true;
}
tv_list_unref(s);