To: vim_dev@googlegroups.com Subject: Patch 8.1.0218 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.0218 Problem: Cannot add matches to another window. (Qiming Zhao) Solution: Add the "window" argument to matchadd() and matchaddpos(). (closes #3260) Files: src/evalfunc.c, runtime/doc/eval.txt, src/testdir/test_match.vim *** ../vim-8.1.0217/src/evalfunc.c 2018-07-27 22:08:54.084115114 +0200 --- src/evalfunc.c 2018-07-28 16:38:54.045497084 +0200 *************** *** 7988,7993 **** --- 7988,8023 ---- find_some_match(argvars, rettv, MATCH_MATCH); } + #ifdef FEAT_SEARCH_EXTRA + static int + matchadd_dict_arg(typval_T *tv, char_u **conceal_char, win_T **win) + { + dictitem_T *di; + + if (tv->v_type != VAR_DICT) + { + EMSG(_(e_dictreq)); + return FAIL; + } + + if (dict_find(tv->vval.v_dict, (char_u *)"conceal", -1) != NULL) + *conceal_char = get_dict_string(tv->vval.v_dict, + (char_u *)"conceal", FALSE); + + if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) != NULL) + { + *win = find_win_by_nr(&di->di_tv, NULL); + if (*win == NULL) + { + EMSG(_("E957: Invalid window number")); + return FAIL; + } + } + + return OK; + } + #endif + /* * "matchadd()" function */ *************** *** 8002,8007 **** --- 8032,8038 ---- int id = -1; int error = FALSE; char_u *conceal_char = NULL; + win_T *win = curwin; rettv->vval.v_number = -1; *************** *** 8013,8030 **** if (argvars[3].v_type != VAR_UNKNOWN) { id = (int)get_tv_number_chk(&argvars[3], &error); ! if (argvars[4].v_type != VAR_UNKNOWN) ! { ! if (argvars[4].v_type != VAR_DICT) ! { ! EMSG(_(e_dictreq)); ! return; ! } ! if (dict_find(argvars[4].vval.v_dict, ! (char_u *)"conceal", -1) != NULL) ! conceal_char = get_dict_string(argvars[4].vval.v_dict, ! (char_u *)"conceal", FALSE); ! } } } if (error == TRUE) --- 8044,8052 ---- if (argvars[3].v_type != VAR_UNKNOWN) { id = (int)get_tv_number_chk(&argvars[3], &error); ! if (argvars[4].v_type != VAR_UNKNOWN ! && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL) ! return; } } if (error == TRUE) *************** *** 8035,8041 **** return; } ! rettv->vval.v_number = match_add(curwin, grp, pat, prio, id, NULL, conceal_char); #endif } --- 8057,8063 ---- return; } ! rettv->vval.v_number = match_add(win, grp, pat, prio, id, NULL, conceal_char); #endif } *************** *** 8054,8059 **** --- 8076,8082 ---- int error = FALSE; list_T *l; char_u *conceal_char = NULL; + win_T *win = curwin; rettv->vval.v_number = -1; *************** *** 8076,8093 **** if (argvars[3].v_type != VAR_UNKNOWN) { id = (int)get_tv_number_chk(&argvars[3], &error); ! if (argvars[4].v_type != VAR_UNKNOWN) ! { ! if (argvars[4].v_type != VAR_DICT) ! { ! EMSG(_(e_dictreq)); ! return; ! } ! if (dict_find(argvars[4].vval.v_dict, ! (char_u *)"conceal", -1) != NULL) ! conceal_char = get_dict_string(argvars[4].vval.v_dict, ! (char_u *)"conceal", FALSE); ! } } } if (error == TRUE) --- 8099,8108 ---- if (argvars[3].v_type != VAR_UNKNOWN) { id = (int)get_tv_number_chk(&argvars[3], &error); ! ! if (argvars[4].v_type != VAR_UNKNOWN ! && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL) ! return; } } if (error == TRUE) *************** *** 8100,8106 **** return; } ! rettv->vval.v_number = match_add(curwin, group, NULL, prio, id, l, conceal_char); #endif } --- 8115,8121 ---- return; } ! rettv->vval.v_number = match_add(win, group, NULL, prio, id, l, conceal_char); #endif } *** ../vim-8.1.0217/runtime/doc/eval.txt 2018-07-15 17:01:06.361425488 +0200 --- runtime/doc/eval.txt 2018-07-28 16:54:21.839764726 +0200 *************** *** 6015,6021 **** the pattern. 'smartcase' is NOT used. The matching is always done like 'magic' is set and 'cpoptions' is empty. ! *matchadd()* *E798* *E799* *E801* 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 --- 6016,6022 ---- the pattern. 'smartcase' is NOT used. The matching is always done like 'magic' is set and 'cpoptions' is empty. ! *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 *************** *** 6054,6059 **** --- 6055,6062 ---- conceal Special character to show instead of the match (only for |hl-Conceal| highlighted 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. *** ../vim-8.1.0217/src/testdir/test_match.vim 2017-09-14 14:16:37.000000000 +0200 --- src/testdir/test_match.vim 2018-07-28 16:51:59.280637174 +0200 *************** *** 192,197 **** --- 192,219 ---- 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 *** ../vim-8.1.0217/src/version.c 2018-07-28 16:14:26.131040141 +0200 --- src/version.c 2018-07-28 16:40:26.416917394 +0200 *************** *** 800,801 **** --- 800,803 ---- { /* Add new patch number below this line */ + /**/ + 218, /**/ -- 'I generally avoid temptation unless I can't resist it." -- Mae West /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///