comparison src/evalfunc.c @ 14407:631344964949 v8.1.0218

patch 8.1.0218: cannot add matches to another window commit https://github.com/vim/vim/commit/95e51470f10e1ddcc4b2ce53e4f7ff7aa2e58417 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 28 16:55:56 2018 +0200 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 #3260)
author Christian Brabandt <cb@256bit.org>
date Sat, 28 Jul 2018 17:00:05 +0200
parents e7d1bc5ee3b8
children 06316dbd66bc
comparison
equal deleted inserted replaced
14406:9b4fa7ed95a0 14407:631344964949
7986 f_match(typval_T *argvars, typval_T *rettv) 7986 f_match(typval_T *argvars, typval_T *rettv)
7987 { 7987 {
7988 find_some_match(argvars, rettv, MATCH_MATCH); 7988 find_some_match(argvars, rettv, MATCH_MATCH);
7989 } 7989 }
7990 7990
7991 #ifdef FEAT_SEARCH_EXTRA
7992 static int
7993 matchadd_dict_arg(typval_T *tv, char_u **conceal_char, win_T **win)
7994 {
7995 dictitem_T *di;
7996
7997 if (tv->v_type != VAR_DICT)
7998 {
7999 EMSG(_(e_dictreq));
8000 return FAIL;
8001 }
8002
8003 if (dict_find(tv->vval.v_dict, (char_u *)"conceal", -1) != NULL)
8004 *conceal_char = get_dict_string(tv->vval.v_dict,
8005 (char_u *)"conceal", FALSE);
8006
8007 if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) != NULL)
8008 {
8009 *win = find_win_by_nr(&di->di_tv, NULL);
8010 if (*win == NULL)
8011 {
8012 EMSG(_("E957: Invalid window number"));
8013 return FAIL;
8014 }
8015 }
8016
8017 return OK;
8018 }
8019 #endif
8020
7991 /* 8021 /*
7992 * "matchadd()" function 8022 * "matchadd()" function
7993 */ 8023 */
7994 static void 8024 static void
7995 f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED) 8025 f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
8000 char_u *pat = get_tv_string_buf_chk(&argvars[1], buf); /* pattern */ 8030 char_u *pat = get_tv_string_buf_chk(&argvars[1], buf); /* pattern */
8001 int prio = 10; /* default priority */ 8031 int prio = 10; /* default priority */
8002 int id = -1; 8032 int id = -1;
8003 int error = FALSE; 8033 int error = FALSE;
8004 char_u *conceal_char = NULL; 8034 char_u *conceal_char = NULL;
8035 win_T *win = curwin;
8005 8036
8006 rettv->vval.v_number = -1; 8037 rettv->vval.v_number = -1;
8007 8038
8008 if (grp == NULL || pat == NULL) 8039 if (grp == NULL || pat == NULL)
8009 return; 8040 return;
8011 { 8042 {
8012 prio = (int)get_tv_number_chk(&argvars[2], &error); 8043 prio = (int)get_tv_number_chk(&argvars[2], &error);
8013 if (argvars[3].v_type != VAR_UNKNOWN) 8044 if (argvars[3].v_type != VAR_UNKNOWN)
8014 { 8045 {
8015 id = (int)get_tv_number_chk(&argvars[3], &error); 8046 id = (int)get_tv_number_chk(&argvars[3], &error);
8016 if (argvars[4].v_type != VAR_UNKNOWN) 8047 if (argvars[4].v_type != VAR_UNKNOWN
8017 { 8048 && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
8018 if (argvars[4].v_type != VAR_DICT) 8049 return;
8019 {
8020 EMSG(_(e_dictreq));
8021 return;
8022 }
8023 if (dict_find(argvars[4].vval.v_dict,
8024 (char_u *)"conceal", -1) != NULL)
8025 conceal_char = get_dict_string(argvars[4].vval.v_dict,
8026 (char_u *)"conceal", FALSE);
8027 }
8028 } 8050 }
8029 } 8051 }
8030 if (error == TRUE) 8052 if (error == TRUE)
8031 return; 8053 return;
8032 if (id >= 1 && id <= 3) 8054 if (id >= 1 && id <= 3)
8033 { 8055 {
8034 EMSGN(_("E798: ID is reserved for \":match\": %ld"), id); 8056 EMSGN(_("E798: ID is reserved for \":match\": %ld"), id);
8035 return; 8057 return;
8036 } 8058 }
8037 8059
8038 rettv->vval.v_number = match_add(curwin, grp, pat, prio, id, NULL, 8060 rettv->vval.v_number = match_add(win, grp, pat, prio, id, NULL,
8039 conceal_char); 8061 conceal_char);
8040 #endif 8062 #endif
8041 } 8063 }
8042 8064
8043 /* 8065 /*
8052 int prio = 10; 8074 int prio = 10;
8053 int id = -1; 8075 int id = -1;
8054 int error = FALSE; 8076 int error = FALSE;
8055 list_T *l; 8077 list_T *l;
8056 char_u *conceal_char = NULL; 8078 char_u *conceal_char = NULL;
8079 win_T *win = curwin;
8057 8080
8058 rettv->vval.v_number = -1; 8081 rettv->vval.v_number = -1;
8059 8082
8060 group = get_tv_string_buf_chk(&argvars[0], buf); 8083 group = get_tv_string_buf_chk(&argvars[0], buf);
8061 if (group == NULL) 8084 if (group == NULL)
8074 { 8097 {
8075 prio = (int)get_tv_number_chk(&argvars[2], &error); 8098 prio = (int)get_tv_number_chk(&argvars[2], &error);
8076 if (argvars[3].v_type != VAR_UNKNOWN) 8099 if (argvars[3].v_type != VAR_UNKNOWN)
8077 { 8100 {
8078 id = (int)get_tv_number_chk(&argvars[3], &error); 8101 id = (int)get_tv_number_chk(&argvars[3], &error);
8079 if (argvars[4].v_type != VAR_UNKNOWN) 8102
8080 { 8103 if (argvars[4].v_type != VAR_UNKNOWN
8081 if (argvars[4].v_type != VAR_DICT) 8104 && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
8082 { 8105 return;
8083 EMSG(_(e_dictreq));
8084 return;
8085 }
8086 if (dict_find(argvars[4].vval.v_dict,
8087 (char_u *)"conceal", -1) != NULL)
8088 conceal_char = get_dict_string(argvars[4].vval.v_dict,
8089 (char_u *)"conceal", FALSE);
8090 }
8091 } 8106 }
8092 } 8107 }
8093 if (error == TRUE) 8108 if (error == TRUE)
8094 return; 8109 return;
8095 8110
8098 { 8113 {
8099 EMSGN(_("E798: ID is reserved for \":match\": %ld"), id); 8114 EMSGN(_("E798: ID is reserved for \":match\": %ld"), id);
8100 return; 8115 return;
8101 } 8116 }
8102 8117
8103 rettv->vval.v_number = match_add(curwin, group, NULL, prio, id, l, 8118 rettv->vval.v_number = match_add(win, group, NULL, prio, id, l,
8104 conceal_char); 8119 conceal_char);
8105 #endif 8120 #endif
8106 } 8121 }
8107 8122
8108 /* 8123 /*