jkunstle / rpms / vim

Forked from rpms/vim 3 years ago
Clone

Blame SOURCES/7.4.330

3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.330
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.330
3ef2ca
Problem:    Using a regexp pattern to highlight a specific position can be
3ef2ca
	    slow.
3ef2ca
Solution:   Add matchaddpos() to highlight specific positions efficiently.
3ef2ca
	    (Alexey Radkov)
3ef2ca
Files:	    runtime/doc/eval.txt, runtime/doc/usr_41.txt,
3ef2ca
	    runtime/plugin/matchparen.vim, src/eval.c, src/ex_docmd.c,
3ef2ca
	    src/proto/window.pro, src/screen.c, src/structs.h,
3ef2ca
	    src/testdir/test63.in, src/testdir/test63.ok, src/window.c
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.329/runtime/doc/eval.txt	2014-05-28 20:31:37.500292805 +0200
3ef2ca
--- runtime/doc/eval.txt	2014-06-17 16:31:35.572453748 +0200
3ef2ca
***************
3ef2ca
*** 1887,1892 ****
3ef2ca
--- 1887,1894 ----
3ef2ca
  				Number	position where {pat} matches in {expr}
3ef2ca
  matchadd( {group}, {pattern}[, {priority}[, {id}]])
3ef2ca
  				Number	highlight {pattern} with {group}
3ef2ca
+ matchaddpos( {group}, {list}[, {priority}[, {id}]])
3ef2ca
+ 				Number	highlight positions with {group}
3ef2ca
  matcharg( {nr})			List	arguments of |:match|
3ef2ca
  matchdelete( {id})		Number	delete match identified by {id}
3ef2ca
  matchend( {expr}, {pat}[, {start}[, {count}]])
3ef2ca
***************
3ef2ca
*** 4342,4347 ****
3ef2ca
--- 4382,4422 ----
3ef2ca
  		available from |getmatches()|.	All matches can be deleted in
3ef2ca
  		one operation by |clearmatches()|.
3ef2ca
  
3ef2ca
+ matchaddpos({group}, {pos}[, {priority}[, {id}]])		*matchaddpos()*
3ef2ca
+ 		Same as |matchadd()|, but requires a list of positions {pos}
3ef2ca
+ 		instead of a pattern. This command is faster than |matchadd()|
3ef2ca
+ 		because it does not require to handle regular expressions and
3ef2ca
+ 		sets buffer line boundaries to redraw screen. It is supposed
3ef2ca
+ 		to be used when fast match additions and deletions are
3ef2ca
+ 		required, for example to highlight matching parentheses.
3ef2ca
+ 
3ef2ca
+ 		The list {pos} can contain one of these items:
3ef2ca
+ 		- A number.  This while line will be highlighted.  The first
3ef2ca
+ 		  line has number 1.
3ef2ca
+ 		- A list with one number, e.g., [23]. The whole line with this
3ef2ca
+ 		  number will be highlighted.
3ef2ca
+ 		- A list with two numbers, e.g., [23, 11]. The first number is
3ef2ca
+ 		  the line number, the second one the column number (first
3ef2ca
+ 		  column is 1).  The character at this position will be
3ef2ca
+ 		  highlighted.
3ef2ca
+ 		- A list with three numbers, e.g., [23, 11, 3]. As above, but
3ef2ca
+ 		  the third number gives the length of the highlight in screen
3ef2ca
+ 		  cells.
3ef2ca
+ 		
3ef2ca
+ 		The maximum number of positions is 8.
3ef2ca
+ 
3ef2ca
+ 		Example: >
3ef2ca
+ 			:highlight MyGroup ctermbg=green guibg=green
3ef2ca
+ 			:let m = matchaddpos("MyGroup", [[23, 24], 34])
3ef2ca
+ <		Deletion of the pattern: >
3ef2ca
+ 			:call matchdelete(m)
3ef2ca
+ 
3ef2ca
+ <		Matches added by |matchaddpos()| are returned by
3ef2ca
+ 		|getmatches()| with an entry "pos1", "pos2", etc., with the
3ef2ca
+ 		value a list like the {pos} item.
3ef2ca
+ 		These matches cannot be set via |setmatches()|, however they
3ef2ca
+ 		can still be deleted by |clearmatches()|.
3ef2ca
+ 
3ef2ca
  matcharg({nr})							*matcharg()*
3ef2ca
  		Selects the {nr} match item, as set with a |:match|,
3ef2ca
  		|:2match| or |:3match| command.
3ef2ca
*** ../vim-7.4.329/runtime/doc/usr_41.txt	2014-05-28 18:22:37.872225054 +0200
3ef2ca
--- runtime/doc/usr_41.txt	2014-06-17 14:06:44.836124965 +0200
3ef2ca
***************
3ef2ca
*** 824,829 ****
3ef2ca
--- 827,833 ----
3ef2ca
  	synconcealed()		get info about concealing
3ef2ca
  	diff_hlID()		get highlight ID for diff mode at a position
3ef2ca
  	matchadd()		define a pattern to highlight (a "match")
3ef2ca
+ 	matchaddpos()		define a list of positions to highlight
3ef2ca
  	matcharg()		get info about |:match| arguments
3ef2ca
  	matchdelete()		delete a match defined by |matchadd()| or a
3ef2ca
  				|:match| command
3ef2ca
*** ../vim-7.4.329/runtime/plugin/matchparen.vim	2013-05-08 05:15:53.000000000 +0200
3ef2ca
--- runtime/plugin/matchparen.vim	2014-06-17 14:14:45.712143158 +0200
3ef2ca
***************
3ef2ca
*** 1,6 ****
3ef2ca
  " Vim plugin for showing matching parens
3ef2ca
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
3ef2ca
! " Last Change: 2013 May 08
3ef2ca
  
3ef2ca
  " Exit quickly when:
3ef2ca
  " - this plugin was already loaded (or disabled)
3ef2ca
--- 1,6 ----
3ef2ca
  " Vim plugin for showing matching parens
3ef2ca
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
3ef2ca
! " Last Change: 2014 Jun 17
3ef2ca
  
3ef2ca
  " Exit quickly when:
3ef2ca
  " - this plugin was already loaded (or disabled)
3ef2ca
***************
3ef2ca
*** 39,45 ****
3ef2ca
  function! s:Highlight_Matching_Pair()
3ef2ca
    " Remove any previous match.
3ef2ca
    if exists('w:paren_hl_on') && w:paren_hl_on
3ef2ca
!     3match none
3ef2ca
      let w:paren_hl_on = 0
3ef2ca
    endif
3ef2ca
  
3ef2ca
--- 39,45 ----
3ef2ca
  function! s:Highlight_Matching_Pair()
3ef2ca
    " Remove any previous match.
3ef2ca
    if exists('w:paren_hl_on') && w:paren_hl_on
3ef2ca
!     silent! call matchdelete(3)
3ef2ca
      let w:paren_hl_on = 0
3ef2ca
    endif
3ef2ca
  
3ef2ca
***************
3ef2ca
*** 152,165 ****
3ef2ca
  
3ef2ca
    " If a match is found setup match highlighting.
3ef2ca
    if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom 
3ef2ca
!     exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) .
3ef2ca
! 	  \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
3ef2ca
      let w:paren_hl_on = 1
3ef2ca
    endif
3ef2ca
  endfunction
3ef2ca
  
3ef2ca
  " Define commands that will disable and enable the plugin.
3ef2ca
! command! NoMatchParen windo 3match none | unlet! g:loaded_matchparen |
3ef2ca
  	  \ au! matchparen
3ef2ca
  command! DoMatchParen runtime plugin/matchparen.vim | windo doau CursorMoved
3ef2ca
  
3ef2ca
--- 152,169 ----
3ef2ca
  
3ef2ca
    " If a match is found setup match highlighting.
3ef2ca
    if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom 
3ef2ca
!     if exists('*matchaddpos')
3ef2ca
!       call matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10, 3)
3ef2ca
!     else
3ef2ca
!       exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) .
3ef2ca
! 	    \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
3ef2ca
!     endif
3ef2ca
      let w:paren_hl_on = 1
3ef2ca
    endif
3ef2ca
  endfunction
3ef2ca
  
3ef2ca
  " Define commands that will disable and enable the plugin.
3ef2ca
! command! NoMatchParen windo silent! call matchdelete(3) | unlet! g:loaded_matchparen |
3ef2ca
  	  \ au! matchparen
3ef2ca
  command! DoMatchParen runtime plugin/matchparen.vim | windo doau CursorMoved
3ef2ca
  
3ef2ca
*** ../vim-7.4.329/src/eval.c	2014-06-17 12:51:13.207953527 +0200
3ef2ca
--- src/eval.c	2014-06-17 17:02:25.388523729 +0200
3ef2ca
***************
3ef2ca
*** 622,627 ****
3ef2ca
--- 622,628 ----
3ef2ca
  static void f_mapcheck __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_match __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_matchadd __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
+ static void f_matchaddpos __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_matcharg __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_matchdelete __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_matchend __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
***************
3ef2ca
*** 8054,8059 ****
3ef2ca
--- 8055,8061 ----
3ef2ca
      {"mapcheck",	1, 3, f_mapcheck},
3ef2ca
      {"match",		2, 4, f_match},
3ef2ca
      {"matchadd",	2, 4, f_matchadd},
3ef2ca
+     {"matchaddpos",	2, 4, f_matchaddpos},
3ef2ca
      {"matcharg",	1, 1, f_matcharg},
3ef2ca
      {"matchdelete",	1, 1, f_matchdelete},
3ef2ca
      {"matchend",	2, 4, f_matchend},
3ef2ca
***************
3ef2ca
*** 11767,11772 ****
3ef2ca
--- 11769,11775 ----
3ef2ca
  #ifdef FEAT_SEARCH_EXTRA
3ef2ca
      dict_T	*dict;
3ef2ca
      matchitem_T	*cur = curwin->w_match_head;
3ef2ca
+     int		i;
3ef2ca
  
3ef2ca
      if (rettv_list_alloc(rettv) == OK)
3ef2ca
      {
3ef2ca
***************
3ef2ca
*** 11775,11782 ****
3ef2ca
  	    dict = dict_alloc();
3ef2ca
  	    if (dict == NULL)
3ef2ca
  		return;
3ef2ca
  	    dict_add_nr_str(dict, "group", 0L, syn_id2name(cur->hlg_id));
3ef2ca
- 	    dict_add_nr_str(dict, "pattern", 0L, cur->pattern);
3ef2ca
  	    dict_add_nr_str(dict, "priority", (long)cur->priority, NULL);
3ef2ca
  	    dict_add_nr_str(dict, "id", (long)cur->id, NULL);
3ef2ca
  	    list_append_dict(rettv->vval.v_list, dict);
3ef2ca
--- 11778,11813 ----
3ef2ca
  	    dict = dict_alloc();
3ef2ca
  	    if (dict == NULL)
3ef2ca
  		return;
3ef2ca
+ 	    if (cur->match.regprog == NULL)
3ef2ca
+ 	    {
3ef2ca
+ 		/* match added with matchaddpos() */
3ef2ca
+ 		for (i = 0; i < MAXPOSMATCH; ++i)
3ef2ca
+ 		{
3ef2ca
+ 		    llpos_T	*llpos;
3ef2ca
+ 		    char	buf[6];
3ef2ca
+ 		    list_T	*l;
3ef2ca
+ 
3ef2ca
+ 		    llpos = &cur->pos.pos[i];
3ef2ca
+ 		    if (llpos->lnum == 0)
3ef2ca
+ 			break;
3ef2ca
+ 		    l = list_alloc();
3ef2ca
+ 		    if (l == NULL)
3ef2ca
+ 			break;
3ef2ca
+ 		    list_append_number(l, (varnumber_T)llpos->lnum);
3ef2ca
+ 		    if (llpos->col > 0)
3ef2ca
+ 		    {
3ef2ca
+ 			list_append_number(l, (varnumber_T)llpos->col);
3ef2ca
+ 			list_append_number(l, (varnumber_T)llpos->len);
3ef2ca
+ 		    }
3ef2ca
+ 		    sprintf(buf, "pos%d", i + 1);
3ef2ca
+ 		    dict_add_list(dict, buf, l);
3ef2ca
+ 		}
3ef2ca
+ 	    }
3ef2ca
+ 	    else
3ef2ca
+ 	    {
3ef2ca
+ 		dict_add_nr_str(dict, "pattern", 0L, cur->pattern);
3ef2ca
+ 	    }
3ef2ca
  	    dict_add_nr_str(dict, "group", 0L, syn_id2name(cur->hlg_id));
3ef2ca
  	    dict_add_nr_str(dict, "priority", (long)cur->priority, NULL);
3ef2ca
  	    dict_add_nr_str(dict, "id", (long)cur->id, NULL);
3ef2ca
  	    list_append_dict(rettv->vval.v_list, dict);
3ef2ca
***************
3ef2ca
*** 14313,14319 ****
3ef2ca
  	return;
3ef2ca
      }
3ef2ca
  
3ef2ca
!     rettv->vval.v_number = match_add(curwin, grp, pat, prio, id);
3ef2ca
  #endif
3ef2ca
  }
3ef2ca
  
3ef2ca
--- 14344,14401 ----
3ef2ca
  	return;
3ef2ca
      }
3ef2ca
  
3ef2ca
!     rettv->vval.v_number = match_add(curwin, grp, pat, prio, id, NULL);
3ef2ca
! #endif
3ef2ca
! }
3ef2ca
! 
3ef2ca
! /*
3ef2ca
!  * "matchaddpos()" function
3ef2ca
!  */
3ef2ca
!     static void
3ef2ca
! f_matchaddpos(argvars, rettv)
3ef2ca
!     typval_T	*argvars UNUSED;
3ef2ca
!     typval_T	*rettv UNUSED;
3ef2ca
! {
3ef2ca
! #ifdef FEAT_SEARCH_EXTRA
3ef2ca
!     char_u	buf[NUMBUFLEN];
3ef2ca
!     char_u	*group;
3ef2ca
!     int		prio = 10;
3ef2ca
!     int		id = -1;
3ef2ca
!     int		error = FALSE;
3ef2ca
!     list_T	*l;
3ef2ca
! 
3ef2ca
!     rettv->vval.v_number = -1;
3ef2ca
! 
3ef2ca
!     group = get_tv_string_buf_chk(&argvars[0], buf);
3ef2ca
!     if (group == NULL)
3ef2ca
! 	return;
3ef2ca
! 
3ef2ca
!     if (argvars[1].v_type != VAR_LIST)
3ef2ca
!     {
3ef2ca
! 	EMSG2(_(e_listarg), "matchaddpos()");
3ef2ca
! 	return;
3ef2ca
!     }
3ef2ca
!     l = argvars[1].vval.v_list;
3ef2ca
!     if (l == NULL)
3ef2ca
! 	return;
3ef2ca
! 
3ef2ca
!     if (argvars[2].v_type != VAR_UNKNOWN)
3ef2ca
!     {
3ef2ca
! 	prio = get_tv_number_chk(&argvars[2], &error);
3ef2ca
! 	if (argvars[3].v_type != VAR_UNKNOWN)
3ef2ca
! 	    id = get_tv_number_chk(&argvars[3], &error);
3ef2ca
!     }
3ef2ca
!     if (error == TRUE)
3ef2ca
! 	return;
3ef2ca
! 
3ef2ca
!     /* id == 3 is ok because matchaddpos() is supposed to substitute :3match */
3ef2ca
!     if (id == 1 || id == 2)
3ef2ca
!     {
3ef2ca
! 	EMSGN("E798: ID is reserved for \":match\": %ld", id);
3ef2ca
! 	return;
3ef2ca
!     }
3ef2ca
! 
3ef2ca
!     rettv->vval.v_number = match_add(curwin, group, NULL, prio, id, l);
3ef2ca
  #endif
3ef2ca
  }
3ef2ca
  
3ef2ca
***************
3ef2ca
*** 16816,16822 ****
3ef2ca
  	    match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
3ef2ca
  		    get_dict_string(d, (char_u *)"pattern", FALSE),
3ef2ca
  		    (int)get_dict_number(d, (char_u *)"priority"),
3ef2ca
! 		    (int)get_dict_number(d, (char_u *)"id"));
3ef2ca
  	    li = li->li_next;
3ef2ca
  	}
3ef2ca
  	rettv->vval.v_number = 0;
3ef2ca
--- 16898,16904 ----
3ef2ca
  	    match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
3ef2ca
  		    get_dict_string(d, (char_u *)"pattern", FALSE),
3ef2ca
  		    (int)get_dict_number(d, (char_u *)"priority"),
3ef2ca
! 		    (int)get_dict_number(d, (char_u *)"id"), NULL);
3ef2ca
  	    li = li->li_next;
3ef2ca
  	}
3ef2ca
  	rettv->vval.v_number = 0;
3ef2ca
*** ../vim-7.4.329/src/ex_docmd.c	2014-05-28 18:22:37.876225054 +0200
3ef2ca
--- src/ex_docmd.c	2014-06-17 14:06:44.844124966 +0200
3ef2ca
***************
3ef2ca
*** 11489,11495 ****
3ef2ca
  
3ef2ca
  	    c = *end;
3ef2ca
  	    *end = NUL;
3ef2ca
! 	    match_add(curwin, g, p + 1, 10, id);
3ef2ca
  	    vim_free(g);
3ef2ca
  	    *end = c;
3ef2ca
  	}
3ef2ca
--- 11489,11495 ----
3ef2ca
  
3ef2ca
  	    c = *end;
3ef2ca
  	    *end = NUL;
3ef2ca
! 	    match_add(curwin, g, p + 1, 10, id, NULL);
3ef2ca
  	    vim_free(g);
3ef2ca
  	    *end = c;
3ef2ca
  	}
3ef2ca
*** ../vim-7.4.329/src/proto/window.pro	2013-08-14 17:11:14.000000000 +0200
3ef2ca
--- src/proto/window.pro	2014-06-17 14:06:44.844124966 +0200
3ef2ca
***************
3ef2ca
*** 75,81 ****
3ef2ca
  void switch_buffer __ARGS((buf_T **save_curbuf, buf_T *buf));
3ef2ca
  void restore_buffer __ARGS((buf_T *save_curbuf));
3ef2ca
  int win_hasvertsplit __ARGS((void));
3ef2ca
! int match_add __ARGS((win_T *wp, char_u *grp, char_u *pat, int prio, int id));
3ef2ca
  int match_delete __ARGS((win_T *wp, int id, int perr));
3ef2ca
  void clear_matches __ARGS((win_T *wp));
3ef2ca
  matchitem_T *get_match __ARGS((win_T *wp, int id));
3ef2ca
--- 75,81 ----
3ef2ca
  void switch_buffer __ARGS((buf_T **save_curbuf, buf_T *buf));
3ef2ca
  void restore_buffer __ARGS((buf_T *save_curbuf));
3ef2ca
  int win_hasvertsplit __ARGS((void));
3ef2ca
! int match_add __ARGS((win_T *wp, char_u *grp, char_u *pat, int prio, int id, list_T *pos));
3ef2ca
  int match_delete __ARGS((win_T *wp, int id, int perr));
3ef2ca
  void clear_matches __ARGS((win_T *wp));
3ef2ca
  matchitem_T *get_match __ARGS((win_T *wp, int id));
3ef2ca
*** ../vim-7.4.329/src/screen.c	2014-05-28 21:40:47.092329130 +0200
3ef2ca
--- src/screen.c	2014-06-17 17:04:08.064527614 +0200
3ef2ca
***************
3ef2ca
*** 144,150 ****
3ef2ca
  static void end_search_hl __ARGS((void));
3ef2ca
  static void init_search_hl __ARGS((win_T *wp));
3ef2ca
  static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum));
3ef2ca
! static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol));
3ef2ca
  #endif
3ef2ca
  static void screen_start_highlight __ARGS((int attr));
3ef2ca
  static void screen_char __ARGS((unsigned off, int row, int col));
3ef2ca
--- 144,151 ----
3ef2ca
  static void end_search_hl __ARGS((void));
3ef2ca
  static void init_search_hl __ARGS((win_T *wp));
3ef2ca
  static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum));
3ef2ca
! static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur));
3ef2ca
! static int next_search_hl_pos __ARGS((match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol));
3ef2ca
  #endif
3ef2ca
  static void screen_start_highlight __ARGS((int attr));
3ef2ca
  static void screen_char __ARGS((unsigned off, int row, int col));
3ef2ca
***************
3ef2ca
*** 2929,2934 ****
3ef2ca
--- 2930,2937 ----
3ef2ca
      match_T	*shl;			/* points to search_hl or a match */
3ef2ca
      int		shl_flag;		/* flag to indicate whether search_hl
3ef2ca
  					   has been processed or not */
3ef2ca
+     int		pos_inprogress;		/* marks that position match search is
3ef2ca
+ 					   in progress */
3ef2ca
      int		prevcol_hl_flag;	/* flag to indicate whether prevcol
3ef2ca
  					   equals startcol of search_hl or one
3ef2ca
  					   of the matches */
3ef2ca
***************
3ef2ca
*** 3439,3482 ****
3ef2ca
  	shl->startcol = MAXCOL;
3ef2ca
  	shl->endcol = MAXCOL;
3ef2ca
  	shl->attr_cur = 0;
3ef2ca
! 	if (shl->rm.regprog != NULL)
3ef2ca
! 	{
3ef2ca
! 	    v = (long)(ptr - line);
3ef2ca
! 	    next_search_hl(wp, shl, lnum, (colnr_T)v);
3ef2ca
! 
3ef2ca
! 	    /* Need to get the line again, a multi-line regexp may have made it
3ef2ca
! 	     * invalid. */
3ef2ca
! 	    line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3ef2ca
! 	    ptr = line + v;
3ef2ca
  
3ef2ca
! 	    if (shl->lnum != 0 && shl->lnum <= lnum)
3ef2ca
  	    {
3ef2ca
- 		if (shl->lnum == lnum)
3ef2ca
- 		    shl->startcol = shl->rm.startpos[0].col;
3ef2ca
- 		else
3ef2ca
- 		    shl->startcol = 0;
3ef2ca
- 		if (lnum == shl->lnum + shl->rm.endpos[0].lnum
3ef2ca
- 						  - shl->rm.startpos[0].lnum)
3ef2ca
- 		    shl->endcol = shl->rm.endpos[0].col;
3ef2ca
- 		else
3ef2ca
- 		    shl->endcol = MAXCOL;
3ef2ca
- 		/* Highlight one character for an empty match. */
3ef2ca
- 		if (shl->startcol == shl->endcol)
3ef2ca
- 		{
3ef2ca
  #ifdef FEAT_MBYTE
3ef2ca
! 		    if (has_mbyte && line[shl->endcol] != NUL)
3ef2ca
! 			shl->endcol += (*mb_ptr2len)(line + shl->endcol);
3ef2ca
! 		    else
3ef2ca
  #endif
3ef2ca
! 			++shl->endcol;
3ef2ca
! 		}
3ef2ca
! 		if ((long)shl->startcol < v)  /* match at leftcol */
3ef2ca
! 		{
3ef2ca
! 		    shl->attr_cur = shl->attr;
3ef2ca
! 		    search_attr = shl->attr;
3ef2ca
! 		}
3ef2ca
! 		area_highlighting = TRUE;
3ef2ca
  	    }
3ef2ca
  	}
3ef2ca
  	if (shl != &search_hl && cur != NULL)
3ef2ca
  	    cur = cur->next;
3ef2ca
--- 3442,3484 ----
3ef2ca
  	shl->startcol = MAXCOL;
3ef2ca
  	shl->endcol = MAXCOL;
3ef2ca
  	shl->attr_cur = 0;
3ef2ca
! 	v = (long)(ptr - line);
3ef2ca
! 	if (cur != NULL)
3ef2ca
! 	    cur->pos.cur = 0;
3ef2ca
! 	next_search_hl(wp, shl, lnum, (colnr_T)v, cur);
3ef2ca
! 
3ef2ca
! 	/* Need to get the line again, a multi-line regexp may have made it
3ef2ca
! 	 * invalid. */
3ef2ca
! 	line = ml_get_buf(wp->w_buffer, lnum, FALSE);
3ef2ca
! 	ptr = line + v;
3ef2ca
  
3ef2ca
! 	if (shl->lnum != 0 && shl->lnum <= lnum)
3ef2ca
! 	{
3ef2ca
! 	    if (shl->lnum == lnum)
3ef2ca
! 		shl->startcol = shl->rm.startpos[0].col;
3ef2ca
! 	    else
3ef2ca
! 		shl->startcol = 0;
3ef2ca
! 	    if (lnum == shl->lnum + shl->rm.endpos[0].lnum
3ef2ca
! 						- shl->rm.startpos[0].lnum)
3ef2ca
! 		shl->endcol = shl->rm.endpos[0].col;
3ef2ca
! 	    else
3ef2ca
! 		shl->endcol = MAXCOL;
3ef2ca
! 	    /* Highlight one character for an empty match. */
3ef2ca
! 	    if (shl->startcol == shl->endcol)
3ef2ca
  	    {
3ef2ca
  #ifdef FEAT_MBYTE
3ef2ca
! 		if (has_mbyte && line[shl->endcol] != NUL)
3ef2ca
! 		    shl->endcol += (*mb_ptr2len)(line + shl->endcol);
3ef2ca
! 		else
3ef2ca
  #endif
3ef2ca
! 		    ++shl->endcol;
3ef2ca
  	    }
3ef2ca
+ 	    if ((long)shl->startcol < v)  /* match at leftcol */
3ef2ca
+ 	    {
3ef2ca
+ 		shl->attr_cur = shl->attr;
3ef2ca
+ 		search_attr = shl->attr;
3ef2ca
+ 	    }
3ef2ca
+ 	    area_highlighting = TRUE;
3ef2ca
  	}
3ef2ca
  	if (shl != &search_hl && cur != NULL)
3ef2ca
  	    cur = cur->next;
3ef2ca
***************
3ef2ca
*** 3488,3494 ****
3ef2ca
       * when Visual mode is active, because it's not clear what is selected
3ef2ca
       * then. */
3ef2ca
      if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3ef2ca
! 					 && !(wp == curwin  && VIsual_active))
3ef2ca
      {
3ef2ca
  	line_attr = hl_attr(HLF_CUL);
3ef2ca
  	area_highlighting = TRUE;
3ef2ca
--- 3490,3496 ----
3ef2ca
       * when Visual mode is active, because it's not clear what is selected
3ef2ca
       * then. */
3ef2ca
      if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3ef2ca
! 					 && !(wp == curwin && VIsual_active))
3ef2ca
      {
3ef2ca
  	line_attr = hl_attr(HLF_CUL);
3ef2ca
  	area_highlighting = TRUE;
3ef2ca
***************
3ef2ca
*** 3792,3798 ****
3ef2ca
  		    }
3ef2ca
  		    else
3ef2ca
  			shl = &cur->hl;
3ef2ca
! 		    while (shl->rm.regprog != NULL)
3ef2ca
  		    {
3ef2ca
  			if (shl->startcol != MAXCOL
3ef2ca
  				&& v >= (long)shl->startcol
3ef2ca
--- 3794,3804 ----
3ef2ca
  		    }
3ef2ca
  		    else
3ef2ca
  			shl = &cur->hl;
3ef2ca
! 		    if (cur != NULL)
3ef2ca
! 			cur->pos.cur = 0;
3ef2ca
! 		    pos_inprogress = TRUE;
3ef2ca
! 		    while (shl->rm.regprog != NULL
3ef2ca
! 					   || (cur != NULL && pos_inprogress))
3ef2ca
  		    {
3ef2ca
  			if (shl->startcol != MAXCOL
3ef2ca
  				&& v >= (long)shl->startcol
3ef2ca
***************
3ef2ca
*** 3803,3810 ****
3ef2ca
  			else if (v == (long)shl->endcol)
3ef2ca
  			{
3ef2ca
  			    shl->attr_cur = 0;
3ef2ca
! 
3ef2ca
! 			    next_search_hl(wp, shl, lnum, (colnr_T)v);
3ef2ca
  
3ef2ca
  			    /* Need to get the line again, a multi-line regexp
3ef2ca
  			     * may have made it invalid. */
3ef2ca
--- 3809,3817 ----
3ef2ca
  			else if (v == (long)shl->endcol)
3ef2ca
  			{
3ef2ca
  			    shl->attr_cur = 0;
3ef2ca
! 			    next_search_hl(wp, shl, lnum, (colnr_T)v, cur);
3ef2ca
! 			    pos_inprogress = cur == NULL || cur->pos.cur == 0
3ef2ca
! 							      ? FALSE : TRUE;
3ef2ca
  
3ef2ca
  			    /* Need to get the line again, a multi-line regexp
3ef2ca
  			     * may have made it invalid. */
3ef2ca
***************
3ef2ca
*** 7277,7282 ****
3ef2ca
--- 7284,7291 ----
3ef2ca
      match_T	*shl;		/* points to search_hl or a match */
3ef2ca
      int		shl_flag;	/* flag to indicate whether search_hl
3ef2ca
  				   has been processed or not */
3ef2ca
+     int		pos_inprogress;	/* marks that position match search is
3ef2ca
+ 				   in progress */
3ef2ca
      int		n;
3ef2ca
  
3ef2ca
      /*
3ef2ca
***************
3ef2ca
*** 7311,7320 ****
3ef2ca
  		shl->first_lnum = wp->w_topline;
3ef2ca
  # endif
3ef2ca
  	    }
3ef2ca
  	    n = 0;
3ef2ca
! 	    while (shl->first_lnum < lnum && shl->rm.regprog != NULL)
3ef2ca
  	    {
3ef2ca
! 		next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n);
3ef2ca
  		if (shl->lnum != 0)
3ef2ca
  		{
3ef2ca
  		    shl->first_lnum = shl->lnum
3ef2ca
--- 7320,7335 ----
3ef2ca
  		shl->first_lnum = wp->w_topline;
3ef2ca
  # endif
3ef2ca
  	    }
3ef2ca
+ 	    if (cur != NULL)
3ef2ca
+ 		cur->pos.cur = 0;
3ef2ca
+ 	    pos_inprogress = TRUE;
3ef2ca
  	    n = 0;
3ef2ca
! 	    while (shl->first_lnum < lnum && (shl->rm.regprog != NULL
3ef2ca
! 					  || (cur != NULL && pos_inprogress)))
3ef2ca
  	    {
3ef2ca
! 		next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, cur);
3ef2ca
! 		pos_inprogress = cur == NULL || cur->pos.cur == 0
3ef2ca
! 							      ? FALSE : TRUE;
3ef2ca
  		if (shl->lnum != 0)
3ef2ca
  		{
3ef2ca
  		    shl->first_lnum = shl->lnum
3ef2ca
***************
3ef2ca
*** 7343,7353 ****
3ef2ca
   * Careful: Any pointers for buffer lines will become invalid.
3ef2ca
   */
3ef2ca
      static void
3ef2ca
! next_search_hl(win, shl, lnum, mincol)
3ef2ca
!     win_T	*win;
3ef2ca
!     match_T	*shl;		/* points to search_hl or a match */
3ef2ca
!     linenr_T	lnum;
3ef2ca
!     colnr_T	mincol;		/* minimal column for a match */
3ef2ca
  {
3ef2ca
      linenr_T	l;
3ef2ca
      colnr_T	matchcol;
3ef2ca
--- 7358,7369 ----
3ef2ca
   * Careful: Any pointers for buffer lines will become invalid.
3ef2ca
   */
3ef2ca
      static void
3ef2ca
! next_search_hl(win, shl, lnum, mincol, cur)
3ef2ca
!     win_T	    *win;
3ef2ca
!     match_T	    *shl;	/* points to search_hl or a match */
3ef2ca
!     linenr_T	    lnum;
3ef2ca
!     colnr_T	    mincol;	/* minimal column for a match */
3ef2ca
!     matchitem_T	    *cur;	/* to retrieve match postions if any */
3ef2ca
  {
3ef2ca
      linenr_T	l;
3ef2ca
      colnr_T	matchcol;
3ef2ca
***************
3ef2ca
*** 7415,7440 ****
3ef2ca
  	    matchcol = shl->rm.endpos[0].col;
3ef2ca
  
3ef2ca
  	shl->lnum = lnum;
3ef2ca
! 	nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol,
3ef2ca
  #ifdef FEAT_RELTIME
3ef2ca
! 		&(shl->tm)
3ef2ca
  #else
3ef2ca
! 		NULL
3ef2ca
  #endif
3ef2ca
! 		);
3ef2ca
! 	if (called_emsg || got_int)
3ef2ca
! 	{
3ef2ca
! 	    /* Error while handling regexp: stop using this regexp. */
3ef2ca
! 	    if (shl == &search_hl)
3ef2ca
  	    {
3ef2ca
! 		/* don't free regprog in the match list, it's a copy */
3ef2ca
! 		vim_regfree(shl->rm.regprog);
3ef2ca
! 		SET_NO_HLSEARCH(TRUE);
3ef2ca
  	    }
3ef2ca
! 	    shl->rm.regprog = NULL;
3ef2ca
! 	    shl->lnum = 0;
3ef2ca
! 	    got_int = FALSE;  /* avoid the "Type :quit to exit Vim" message */
3ef2ca
! 	    break;
3ef2ca
  	}
3ef2ca
  	if (nmatched == 0)
3ef2ca
  	{
3ef2ca
--- 7431,7465 ----
3ef2ca
  	    matchcol = shl->rm.endpos[0].col;
3ef2ca
  
3ef2ca
  	shl->lnum = lnum;
3ef2ca
! 	if (shl->rm.regprog != NULL)
3ef2ca
! 	{
3ef2ca
! 	    nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum,
3ef2ca
! 		    matchcol,
3ef2ca
  #ifdef FEAT_RELTIME
3ef2ca
! 		    &(shl->tm)
3ef2ca
  #else
3ef2ca
! 		    NULL
3ef2ca
  #endif
3ef2ca
! 		    );
3ef2ca
! 	    if (called_emsg || got_int)
3ef2ca
  	    {
3ef2ca
! 		/* Error while handling regexp: stop using this regexp. */
3ef2ca
! 		if (shl == &search_hl)
3ef2ca
! 		{
3ef2ca
! 		    /* don't free regprog in the match list, it's a copy */
3ef2ca
! 		    vim_regfree(shl->rm.regprog);
3ef2ca
! 		    SET_NO_HLSEARCH(TRUE);
3ef2ca
! 		}
3ef2ca
! 		shl->rm.regprog = NULL;
3ef2ca
! 		shl->lnum = 0;
3ef2ca
! 		got_int = FALSE;  /* avoid the "Type :quit to exit Vim"
3ef2ca
! 				     message */
3ef2ca
! 		break;
3ef2ca
  	    }
3ef2ca
! 	}
3ef2ca
! 	else if (cur != NULL)
3ef2ca
! 	{
3ef2ca
! 	    nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol);
3ef2ca
  	}
3ef2ca
  	if (nmatched == 0)
3ef2ca
  	{
3ef2ca
***************
3ef2ca
*** 7453,7458 ****
3ef2ca
--- 7478,7539 ----
3ef2ca
  }
3ef2ca
  #endif
3ef2ca
  
3ef2ca
+     static int
3ef2ca
+ next_search_hl_pos(shl, lnum, posmatch, mincol)
3ef2ca
+     match_T	    *shl;	/* points to a match */
3ef2ca
+     linenr_T	    lnum;
3ef2ca
+     posmatch_T	    *posmatch;	/* match positions */
3ef2ca
+     colnr_T	    mincol;	/* minimal column for a match */
3ef2ca
+ {
3ef2ca
+     int	    i;
3ef2ca
+     int     bot = -1;
3ef2ca
+ 
3ef2ca
+     shl->lnum = 0;
3ef2ca
+     for (i = posmatch->cur; i < MAXPOSMATCH; i++)
3ef2ca
+     {
3ef2ca
+ 	if (posmatch->pos[i].lnum == 0)
3ef2ca
+ 	    break;
3ef2ca
+ 	if (posmatch->pos[i].col < mincol)
3ef2ca
+ 	    continue;
3ef2ca
+ 	if (posmatch->pos[i].lnum == lnum)
3ef2ca
+ 	{
3ef2ca
+ 	    if (shl->lnum == lnum)
3ef2ca
+ 	    {
3ef2ca
+ 		/* partially sort positions by column numbers
3ef2ca
+ 		 * on the same line */
3ef2ca
+ 		if (posmatch->pos[i].col < posmatch->pos[bot].col)
3ef2ca
+ 		{
3ef2ca
+ 		    llpos_T	tmp = posmatch->pos[i];
3ef2ca
+ 
3ef2ca
+ 		    posmatch->pos[i] = posmatch->pos[bot];
3ef2ca
+ 		    posmatch->pos[bot] = tmp;
3ef2ca
+ 		}
3ef2ca
+ 	    }
3ef2ca
+ 	    else
3ef2ca
+ 	    {
3ef2ca
+ 		bot = i;
3ef2ca
+ 		shl->lnum = lnum;
3ef2ca
+ 	    }
3ef2ca
+ 	}
3ef2ca
+     }
3ef2ca
+     posmatch->cur = 0;
3ef2ca
+     if (shl->lnum == lnum)
3ef2ca
+     {
3ef2ca
+ 	colnr_T	start = posmatch->pos[bot].col == 0
3ef2ca
+ 					     ? 0 : posmatch->pos[bot].col - 1;
3ef2ca
+ 	colnr_T	end = posmatch->pos[bot].col == 0
3ef2ca
+ 				    ? MAXCOL : start + posmatch->pos[bot].len;
3ef2ca
+ 
3ef2ca
+ 	shl->rm.startpos[0].lnum = 0;
3ef2ca
+ 	shl->rm.startpos[0].col = start;
3ef2ca
+ 	shl->rm.endpos[0].lnum = 0;
3ef2ca
+ 	shl->rm.endpos[0].col = end;
3ef2ca
+ 	posmatch->cur = bot + 1;
3ef2ca
+ 	return TRUE;
3ef2ca
+     }
3ef2ca
+     return FALSE;
3ef2ca
+ }
3ef2ca
+ 
3ef2ca
        static void
3ef2ca
  screen_start_highlight(attr)
3ef2ca
        int	attr;
3ef2ca
*** ../vim-7.4.329/src/structs.h	2014-05-28 18:22:37.876225054 +0200
3ef2ca
--- src/structs.h	2014-06-17 17:00:55.524520330 +0200
3ef2ca
***************
3ef2ca
*** 1927,1932 ****
3ef2ca
--- 1927,1958 ----
3ef2ca
  #endif
3ef2ca
  } match_T;
3ef2ca
  
3ef2ca
+ /* number of positions supported by matchaddpos() */
3ef2ca
+ #define MAXPOSMATCH 8
3ef2ca
+ 
3ef2ca
+ /*
3ef2ca
+  * Same as lpos_T, but with additional field len.
3ef2ca
+  */
3ef2ca
+ typedef struct
3ef2ca
+ {
3ef2ca
+     linenr_T	lnum;	/* line number */
3ef2ca
+     colnr_T	col;	/* column number */
3ef2ca
+     int		len;	/* length: 0 - to the end of line */
3ef2ca
+ } llpos_T;
3ef2ca
+ 
3ef2ca
+ /*
3ef2ca
+  * posmatch_T provides an array for storing match items for matchaddpos()
3ef2ca
+  * function.
3ef2ca
+  */
3ef2ca
+ typedef struct posmatch posmatch_T;
3ef2ca
+ struct posmatch
3ef2ca
+ {
3ef2ca
+     llpos_T	pos[MAXPOSMATCH];	/* array of positions */
3ef2ca
+     int		cur;			/* internal position counter */
3ef2ca
+     linenr_T	toplnum;		/* top buffer line */
3ef2ca
+     linenr_T	botlnum;		/* bottom buffer line */
3ef2ca
+ };
3ef2ca
+ 
3ef2ca
  /*
3ef2ca
   * matchitem_T provides a linked list for storing match items for ":match" and
3ef2ca
   * the match functions.
3ef2ca
***************
3ef2ca
*** 1940,1945 ****
3ef2ca
--- 1966,1972 ----
3ef2ca
      char_u	*pattern;   /* pattern to highlight */
3ef2ca
      int		hlg_id;	    /* highlight group ID */
3ef2ca
      regmmatch_T	match;	    /* regexp program for pattern */
3ef2ca
+     posmatch_T	pos;	    /* position matches */
3ef2ca
      match_T	hl;	    /* struct for doing the actual highlighting */
3ef2ca
  };
3ef2ca
  
3ef2ca
*** ../vim-7.4.329/src/testdir/test63.in	2010-05-15 13:04:10.000000000 +0200
3ef2ca
--- src/testdir/test63.in	2014-06-17 16:29:36.056449227 +0200
3ef2ca
***************
3ef2ca
*** 1,5 ****
3ef2ca
  Test for ":match", ":2match", ":3match", "clearmatches()", "getmatches()",
3ef2ca
! "matchadd()", "matcharg()", "matchdelete()", and "setmatches()".
3ef2ca
  
3ef2ca
  STARTTEST
3ef2ca
  :so small.vim
3ef2ca
--- 1,5 ----
3ef2ca
  Test for ":match", ":2match", ":3match", "clearmatches()", "getmatches()",
3ef2ca
! "matchadd()", "matchaddpos", "matcharg()", "matchdelete()", and "setmatches()".
3ef2ca
  
3ef2ca
  STARTTEST
3ef2ca
  :so small.vim
3ef2ca
***************
3ef2ca
*** 147,155 ****
3ef2ca
  :unlet rf1
3ef2ca
  :unlet rf2
3ef2ca
  :unlet rf3
3ef2ca
! :highlight clear MyGroup1
3ef2ca
! :highlight clear MyGroup2
3ef2ca
! :highlight clear MyGroup3
3ef2ca
  G"rp
3ef2ca
  :/^Results/,$wq! test.out
3ef2ca
  ENDTEST
3ef2ca
--- 147,172 ----
3ef2ca
  :unlet rf1
3ef2ca
  :unlet rf2
3ef2ca
  :unlet rf3
3ef2ca
! :" --- Check that "matchaddpos()" positions matches correctly
3ef2ca
! :let @r .= "*** Test 11:\n"
3ef2ca
! :set nolazyredraw
3ef2ca
! :call setline(1, 'abcdefghijklmnopq')
3ef2ca
! :call matchaddpos("MyGroup1", [[1, 5], [1, 8, 3]], 10, 3)
3ef2ca
! :1
3ef2ca
! :redraw!
3ef2ca
! :let v1 = screenattr(1, 1)
3ef2ca
! :let v5 = screenattr(1, 5)
3ef2ca
! :let v6 = screenattr(1, 6)
3ef2ca
! :let v8 = screenattr(1, 8)
3ef2ca
! :let v10 = screenattr(1, 10)
3ef2ca
! :let v11 = screenattr(1, 11)
3ef2ca
! :let @r .= string(getmatches())."\n"
3ef2ca
! :if v1 != v5 && v6 == v1 && v8 == v5 && v10 == v5 && v11 == v1
3ef2ca
! :  let @r .= "OK\n"
3ef2ca
! :else
3ef2ca
! :  let @r .= "FAILED\n"
3ef2ca
! :endif
3ef2ca
! :call clearmatches()
3ef2ca
  G"rp
3ef2ca
  :/^Results/,$wq! test.out
3ef2ca
  ENDTEST
3ef2ca
*** ../vim-7.4.329/src/testdir/test63.ok	2010-05-15 13:04:10.000000000 +0200
3ef2ca
--- src/testdir/test63.ok	2014-06-17 17:32:57.036593023 +0200
3ef2ca
***************
3ef2ca
*** 9,11 ****
3ef2ca
--- 9,14 ----
3ef2ca
  *** Test 8: OK
3ef2ca
  *** Test 9: OK
3ef2ca
  *** Test 10: OK
3ef2ca
+ *** Test 11:
3ef2ca
+ [{'group': 'MyGroup1', 'id': 3, 'priority': 10, 'pos1': [1, 5, 1], 'pos2': [1, 8, 3]}]
3ef2ca
+ OK
3ef2ca
*** ../vim-7.4.329/src/window.c	2014-06-17 13:52:35.868092848 +0200
3ef2ca
--- src/window.c	2014-06-17 17:04:51.060529240 +0200
3ef2ca
***************
3ef2ca
*** 6751,6770 ****
3ef2ca
   * Return ID of added match, -1 on failure.
3ef2ca
   */
3ef2ca
      int
3ef2ca
! match_add(wp, grp, pat, prio, id)
3ef2ca
      win_T	*wp;
3ef2ca
      char_u	*grp;
3ef2ca
      char_u	*pat;
3ef2ca
      int		prio;
3ef2ca
      int		id;
3ef2ca
  {
3ef2ca
!     matchitem_T *cur;
3ef2ca
!     matchitem_T *prev;
3ef2ca
!     matchitem_T *m;
3ef2ca
      int		hlg_id;
3ef2ca
!     regprog_T	*regprog;
3ef2ca
  
3ef2ca
!     if (*grp == NUL || *pat == NUL)
3ef2ca
  	return -1;
3ef2ca
      if (id < -1 || id == 0)
3ef2ca
      {
3ef2ca
--- 6751,6772 ----
3ef2ca
   * Return ID of added match, -1 on failure.
3ef2ca
   */
3ef2ca
      int
3ef2ca
! match_add(wp, grp, pat, prio, id, pos_list)
3ef2ca
      win_T	*wp;
3ef2ca
      char_u	*grp;
3ef2ca
      char_u	*pat;
3ef2ca
      int		prio;
3ef2ca
      int		id;
3ef2ca
+     list_T	*pos_list;
3ef2ca
  {
3ef2ca
!     matchitem_T	*cur;
3ef2ca
!     matchitem_T	*prev;
3ef2ca
!     matchitem_T	*m;
3ef2ca
      int		hlg_id;
3ef2ca
!     regprog_T	*regprog = NULL;
3ef2ca
!     int		rtype = SOME_VALID;
3ef2ca
  
3ef2ca
!     if (*grp == NUL || (pat != NULL && *pat == NUL))
3ef2ca
  	return -1;
3ef2ca
      if (id < -1 || id == 0)
3ef2ca
      {
3ef2ca
***************
3ef2ca
*** 6789,6795 ****
3ef2ca
  	EMSG2(_(e_nogroup), grp);
3ef2ca
  	return -1;
3ef2ca
      }
3ef2ca
!     if ((regprog = vim_regcomp(pat, RE_MAGIC)) == NULL)
3ef2ca
      {
3ef2ca
  	EMSG2(_(e_invarg2), pat);
3ef2ca
  	return -1;
3ef2ca
--- 6791,6797 ----
3ef2ca
  	EMSG2(_(e_nogroup), grp);
3ef2ca
  	return -1;
3ef2ca
      }
3ef2ca
!     if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL)
3ef2ca
      {
3ef2ca
  	EMSG2(_(e_invarg2), pat);
3ef2ca
  	return -1;
3ef2ca
***************
3ef2ca
*** 6810,6821 ****
3ef2ca
      m = (matchitem_T *)alloc(sizeof(matchitem_T));
3ef2ca
      m->id = id;
3ef2ca
      m->priority = prio;
3ef2ca
!     m->pattern = vim_strsave(pat);
3ef2ca
      m->hlg_id = hlg_id;
3ef2ca
      m->match.regprog = regprog;
3ef2ca
      m->match.rmm_ic = FALSE;
3ef2ca
      m->match.rmm_maxcol = 0;
3ef2ca
  
3ef2ca
      /* Insert new match.  The match list is in ascending order with regard to
3ef2ca
       * the match priorities. */
3ef2ca
      cur = wp->w_match_head;
3ef2ca
--- 6812,6922 ----
3ef2ca
      m = (matchitem_T *)alloc(sizeof(matchitem_T));
3ef2ca
      m->id = id;
3ef2ca
      m->priority = prio;
3ef2ca
!     m->pattern = pat == NULL ? NULL : vim_strsave(pat);
3ef2ca
!     m->pos.cur = 0;
3ef2ca
      m->hlg_id = hlg_id;
3ef2ca
      m->match.regprog = regprog;
3ef2ca
      m->match.rmm_ic = FALSE;
3ef2ca
      m->match.rmm_maxcol = 0;
3ef2ca
  
3ef2ca
+     /* Set up position matches */
3ef2ca
+     if (pos_list != NULL)
3ef2ca
+     {
3ef2ca
+ 	linenr_T	toplnum = 0;
3ef2ca
+ 	linenr_T	botlnum = 0;
3ef2ca
+ 	listitem_T	*li;
3ef2ca
+ 	int		i;
3ef2ca
+ 
3ef2ca
+ 	for (i = 0, li = pos_list->lv_first; i < MAXPOSMATCH;
3ef2ca
+ 							i++, li = li->li_next)
3ef2ca
+ 	{
3ef2ca
+ 	    linenr_T	lnum = 0;
3ef2ca
+ 	    colnr_T	col = 0;
3ef2ca
+ 	    int		len = 1;
3ef2ca
+ 	    list_T	*subl;
3ef2ca
+ 	    listitem_T	*subli;
3ef2ca
+ 	    int		error;
3ef2ca
+ 
3ef2ca
+ 	    if (li == NULL)
3ef2ca
+ 	    {
3ef2ca
+ 		m->pos.pos[i].lnum = 0;
3ef2ca
+ 		break;
3ef2ca
+ 	    }
3ef2ca
+ 	    if (li->li_tv.v_type == VAR_LIST)
3ef2ca
+ 	    {
3ef2ca
+ 		subl = li->li_tv.vval.v_list;
3ef2ca
+ 		if (subl == NULL)
3ef2ca
+ 		    goto fail;
3ef2ca
+ 		subli = subl->lv_first;
3ef2ca
+ 		if (subli == NULL)
3ef2ca
+ 		    goto fail;
3ef2ca
+ 		lnum = get_tv_number_chk(&subli->li_tv, &error);
3ef2ca
+ 		if (error == TRUE)
3ef2ca
+ 		    goto fail;
3ef2ca
+ 		m->pos.pos[i].lnum = lnum;
3ef2ca
+ 		if (lnum == 0)
3ef2ca
+ 		{
3ef2ca
+ 		    --i;
3ef2ca
+ 		    continue;
3ef2ca
+ 		}
3ef2ca
+ 		subli = subli->li_next;
3ef2ca
+ 		if (subli != NULL)
3ef2ca
+ 		{
3ef2ca
+ 		    col = get_tv_number_chk(&subli->li_tv, &error);
3ef2ca
+ 		    if (error == TRUE)
3ef2ca
+ 			goto fail;
3ef2ca
+ 		    subli = subli->li_next;
3ef2ca
+ 		    if (subli != NULL)
3ef2ca
+ 		    {
3ef2ca
+ 			len = get_tv_number_chk(&subli->li_tv, &error);
3ef2ca
+ 			if (error == TRUE)
3ef2ca
+ 			    goto fail;
3ef2ca
+ 		    }
3ef2ca
+ 		}
3ef2ca
+ 		m->pos.pos[i].col = col;
3ef2ca
+ 		m->pos.pos[i].len = len;
3ef2ca
+ 	    }
3ef2ca
+ 	    else if (li->li_tv.v_type == VAR_NUMBER)
3ef2ca
+ 	    {
3ef2ca
+ 		if (li->li_tv.vval.v_number == 0)
3ef2ca
+ 		    continue;
3ef2ca
+ 		m->pos.pos[i].lnum = li->li_tv.vval.v_number;
3ef2ca
+ 		m->pos.pos[i].col = 0;
3ef2ca
+ 		m->pos.pos[i].len = 0;
3ef2ca
+ 	    }
3ef2ca
+ 	    else
3ef2ca
+ 	    {
3ef2ca
+ 		EMSG(_("List or number required"));
3ef2ca
+ 		goto fail;
3ef2ca
+ 	    }
3ef2ca
+ 	    if (toplnum == 0 || lnum < toplnum)
3ef2ca
+ 		toplnum = lnum;
3ef2ca
+ 	    if (botlnum == 0 || lnum > botlnum)
3ef2ca
+ 		botlnum = lnum;
3ef2ca
+ 	}
3ef2ca
+ 
3ef2ca
+ 	/* Calculate top and bottom lines for redrawing area */
3ef2ca
+ 	if (toplnum != 0)
3ef2ca
+ 	{
3ef2ca
+ 	    if (wp->w_buffer->b_mod_set)
3ef2ca
+ 	    {
3ef2ca
+ 		if (wp->w_buffer->b_mod_top > toplnum)
3ef2ca
+ 		    wp->w_buffer->b_mod_top = toplnum;
3ef2ca
+ 		if (wp->w_buffer->b_mod_bot < botlnum)
3ef2ca
+ 		    wp->w_buffer->b_mod_bot = botlnum;
3ef2ca
+ 	    }
3ef2ca
+ 	    else
3ef2ca
+ 	    {
3ef2ca
+ 		wp->w_buffer->b_mod_top = toplnum;
3ef2ca
+ 		wp->w_buffer->b_mod_bot = botlnum;
3ef2ca
+ 	    }
3ef2ca
+ 	    m->pos.toplnum = toplnum;
3ef2ca
+ 	    m->pos.botlnum = botlnum;
3ef2ca
+ 	    wp->w_buffer->b_mod_set = TRUE;
3ef2ca
+ 	    rtype = VALID;
3ef2ca
+ 	}
3ef2ca
+     }
3ef2ca
+ 
3ef2ca
      /* Insert new match.  The match list is in ascending order with regard to
3ef2ca
       * the match priorities. */
3ef2ca
      cur = wp->w_match_head;
3ef2ca
***************
3ef2ca
*** 6831,6838 ****
3ef2ca
  	prev->next = m;
3ef2ca
      m->next = cur;
3ef2ca
  
3ef2ca
!     redraw_later(SOME_VALID);
3ef2ca
      return id;
3ef2ca
  }
3ef2ca
  
3ef2ca
  /*
3ef2ca
--- 6932,6943 ----
3ef2ca
  	prev->next = m;
3ef2ca
      m->next = cur;
3ef2ca
  
3ef2ca
!     redraw_later(rtype);
3ef2ca
      return id;
3ef2ca
+ 
3ef2ca
+ fail:
3ef2ca
+     vim_free(m);
3ef2ca
+     return -1;
3ef2ca
  }
3ef2ca
  
3ef2ca
  /*
3ef2ca
***************
3ef2ca
*** 6845,6852 ****
3ef2ca
      int		id;
3ef2ca
      int		perr;
3ef2ca
  {
3ef2ca
!     matchitem_T *cur = wp->w_match_head;
3ef2ca
!     matchitem_T *prev = cur;
3ef2ca
  
3ef2ca
      if (id < 1)
3ef2ca
      {
3ef2ca
--- 6950,6958 ----
3ef2ca
      int		id;
3ef2ca
      int		perr;
3ef2ca
  {
3ef2ca
!     matchitem_T	*cur = wp->w_match_head;
3ef2ca
!     matchitem_T	*prev = cur;
3ef2ca
!     int		rtype = SOME_VALID;
3ef2ca
  
3ef2ca
      if (id < 1)
3ef2ca
      {
3ef2ca
***************
3ef2ca
*** 6872,6879 ****
3ef2ca
  	prev->next = cur->next;
3ef2ca
      vim_regfree(cur->match.regprog);
3ef2ca
      vim_free(cur->pattern);
3ef2ca
      vim_free(cur);
3ef2ca
!     redraw_later(SOME_VALID);
3ef2ca
      return 0;
3ef2ca
  }
3ef2ca
  
3ef2ca
--- 6978,7002 ----
3ef2ca
  	prev->next = cur->next;
3ef2ca
      vim_regfree(cur->match.regprog);
3ef2ca
      vim_free(cur->pattern);
3ef2ca
+     if (cur->pos.toplnum != 0)
3ef2ca
+     {
3ef2ca
+ 	if (wp->w_buffer->b_mod_set)
3ef2ca
+ 	{
3ef2ca
+ 	    if (wp->w_buffer->b_mod_top > cur->pos.toplnum)
3ef2ca
+ 		wp->w_buffer->b_mod_top = cur->pos.toplnum;
3ef2ca
+ 	    if (wp->w_buffer->b_mod_bot < cur->pos.botlnum)
3ef2ca
+ 		wp->w_buffer->b_mod_bot = cur->pos.botlnum;
3ef2ca
+ 	}
3ef2ca
+ 	else
3ef2ca
+ 	{
3ef2ca
+ 	    wp->w_buffer->b_mod_top = cur->pos.toplnum;
3ef2ca
+ 	    wp->w_buffer->b_mod_bot = cur->pos.botlnum;
3ef2ca
+ 	}
3ef2ca
+ 	wp->w_buffer->b_mod_set = TRUE;
3ef2ca
+ 	rtype = VALID;
3ef2ca
+     }
3ef2ca
      vim_free(cur);
3ef2ca
!     redraw_later(rtype);
3ef2ca
      return 0;
3ef2ca
  }
3ef2ca
  
3ef2ca
*** ../vim-7.4.329/src/version.c	2014-06-17 13:52:35.868092848 +0200
3ef2ca
--- src/version.c	2014-06-17 14:11:53.764136653 +0200
3ef2ca
***************
3ef2ca
*** 736,737 ****
3ef2ca
--- 736,739 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     330,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
I'd like to meet the man who invented sex and see what he's working on now.
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///