3bddd30
To: vim-dev@vim.org
3bddd30
Subject: Patch 7.1.211
3bddd30
Fcc: outbox
3bddd30
From: Bram Moolenaar <Bram@moolenaar.net>
3bddd30
Mime-Version: 1.0
3bddd30
Content-Type: text/plain; charset=ISO-8859-1
3bddd30
Content-Transfer-Encoding: 8bit
3bddd30
------------
3bddd30
3bddd30
Patch 7.1.211
3bddd30
Problem:    The matchparen plugin may take an unexpected amount of time, so
3bddd30
	    that it looks like Vim hangs.
3bddd30
Solution:   Add a timeout to searchpair(), searchpairpos(), search() and
3bddd30
	    searchpos().  Use half a second timeout in the plugin.
3bddd30
Files:	    runtime/doc/eval.txt, runtime/plugin/matchparen.vim, src/edit.c,
3bddd30
	    src/eval.c, src/ex_cmds2.c, src/ex_docmd.c, src/normal.c,
3bddd30
	    src/proto/eval.pro, src/proto/ex_cmds2.pro, src/proto/search.pro,
3bddd30
	    src/search.c
3bddd30
3bddd30
3bddd30
*** ../vim-7.1.210/runtime/doc/eval.txt	Sat Jan  5 13:34:01 2008
3bddd30
--- runtime/doc/eval.txt	Sun Jan  6 16:27:33 2008
3bddd30
***************
3bddd30
*** 1,4 ****
3bddd30
! *eval.txt*      For Vim version 7.1.  Last change: 2008 Jan 04
3bddd30
  
3bddd30
  
3bddd30
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
3bddd30
--- 1,4 ----
3bddd30
! *eval.txt*      For Vim version 7.1.  Last change: 2008 Jan 06
3bddd30
  
3bddd30
  
3bddd30
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
3bddd30
***************
3bddd30
*** 1733,1746 ****
3bddd30
  repeat( {expr}, {count})	String	repeat {expr} {count} times
3bddd30
  resolve( {filename})		String	get filename a shortcut points to
3bddd30
  reverse( {list})		List	reverse {list} in-place
3bddd30
! search( {pattern} [, {flags}])	Number	search for {pattern}
3bddd30
  searchdecl({name} [, {global} [, {thisblock}]])
3bddd30
  				Number  search for variable declaration
3bddd30
! searchpair( {start}, {middle}, {end} [, {flags} [, {skip} [, {stopline}]]])
3bddd30
  				Number	search for other end of start/end pair
3bddd30
! searchpairpos( {start}, {middle}, {end} [, {flags} [, {skip} [, {stopline}]]])
3bddd30
  				List	search for other end of start/end pair
3bddd30
! searchpos( {pattern} [, {flags} [, {stopline}]])
3bddd30
  				List	search for {pattern}
3bddd30
  server2client( {clientid}, {string})
3bddd30
  				Number	send reply string
3bddd30
--- 1733,1747 ----
3bddd30
  repeat( {expr}, {count})	String	repeat {expr} {count} times
3bddd30
  resolve( {filename})		String	get filename a shortcut points to
3bddd30
  reverse( {list})		List	reverse {list} in-place
3bddd30
! search( {pattern} [, {flags} [, {stopline} [, {timeout}]]])
3bddd30
! 				Number	search for {pattern}
3bddd30
  searchdecl({name} [, {global} [, {thisblock}]])
3bddd30
  				Number  search for variable declaration
3bddd30
! searchpair( {start}, {middle}, {end} [, {flags} [, {skip} [...]]])
3bddd30
  				Number	search for other end of start/end pair
3bddd30
! searchpairpos( {start}, {middle}, {end} [, {flags} [, {skip} [...]]])
3bddd30
  				List	search for other end of start/end pair
3bddd30
! searchpos( {pattern} [, {flags} [, {stopline} [, {timeout}]]])
3bddd30
  				List	search for {pattern}
3bddd30
  server2client( {clientid}, {string})
3bddd30
  				Number	send reply string
3bddd30
***************
3bddd30
*** 4212,4218 ****
3bddd30
  		If you want a list to remain unmodified make a copy first: >
3bddd30
  			:let revlist = reverse(copy(mylist))
3bddd30
  
3bddd30
! search({pattern} [, {flags} [, {stopline}]])			*search()*
3bddd30
  		Search for regexp pattern {pattern}.  The search starts at the
3bddd30
  		cursor position (you can use |cursor()| to set it).
3bddd30
  
3bddd30
--- 4216,4222 ----
3bddd30
  		If you want a list to remain unmodified make a copy first: >
3bddd30
  			:let revlist = reverse(copy(mylist))
3bddd30
  
3bddd30
! search({pattern} [, {flags} [, {stopline} [, {timeout}]]])	*search()*
3bddd30
  		Search for regexp pattern {pattern}.  The search starts at the
3bddd30
  		cursor position (you can use |cursor()| to set it).
3bddd30
  
3bddd30
***************
3bddd30
*** 4240,4245 ****
3bddd30
--- 4244,4257 ----
3bddd30
  			let end = search('END', '', line("w$"))
3bddd30
  <		When {stopline} is used and it is not zero this also implies
3bddd30
  		that the search does not wrap around the end of the file.
3bddd30
+ 		A zero value is equal to not giving the argument.
3bddd30
+ 
3bddd30
+ 		When the {timeout} argument is given the search stops when
3bddd30
+ 		more than this many milli seconds have passed.  Thus when
3bddd30
+ 		{timeout} is 500 the search stops after half a second.
3bddd30
+ 		The value must not be negative.  A zero value is like not
3bddd30
+ 		giving the argument.
3bddd30
+ 		{only available when compiled with the +reltime feature}
3bddd30
  
3bddd30
  		If there is no match a 0 is returned and the cursor doesn't
3bddd30
  		move.  No error message is given.
3bddd30
***************
3bddd30
*** 4302,4308 ****
3bddd30
  			endif
3bddd30
  <
3bddd30
  							*searchpair()*
3bddd30
! searchpair({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline}]]])
3bddd30
  		Search for the match of a nested start-end pair.  This can be
3bddd30
  		used to find the "endif" that matches an "if", while other
3bddd30
  		if/endif pairs in between are ignored.
3bddd30
--- 4314,4321 ----
3bddd30
  			endif
3bddd30
  <
3bddd30
  							*searchpair()*
3bddd30
! searchpair({start}, {middle}, {end} [, {flags} [, {skip}
3bddd30
! 				[, {stopline} [, {timeout}]]]])
3bddd30
  		Search for the match of a nested start-end pair.  This can be
3bddd30
  		used to find the "endif" that matches an "if", while other
3bddd30
  		if/endif pairs in between are ignored.
3bddd30
***************
3bddd30
*** 4337,4343 ****
3bddd30
  		When evaluating {skip} causes an error the search is aborted
3bddd30
  		and -1 returned.
3bddd30
  
3bddd30
! 		For {stopline} see |search()|.
3bddd30
  
3bddd30
  		The value of 'ignorecase' is used.  'magic' is ignored, the
3bddd30
  		patterns are used like it's on.
3bddd30
--- 4350,4356 ----
3bddd30
  		When evaluating {skip} causes an error the search is aborted
3bddd30
  		and -1 returned.
3bddd30
  
3bddd30
! 		For {stopline} and {timeout} see |search()|.
3bddd30
  
3bddd30
  		The value of 'ignorecase' is used.  'magic' is ignored, the
3bddd30
  		patterns are used like it's on.
3bddd30
***************
3bddd30
*** 4383,4389 ****
3bddd30
  	     \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
3bddd30
  <
3bddd30
  							*searchpairpos()*
3bddd30
! searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [, {stopline}]]])
3bddd30
  		Same as searchpair(), but returns a |List| with the line and
3bddd30
  		column position of the match. The first element of the |List|
3bddd30
  		is the line number and the second element is the byte index of
3bddd30
--- 4396,4403 ----
3bddd30
  	     \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
3bddd30
  <
3bddd30
  							*searchpairpos()*
3bddd30
! searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
3bddd30
! 				[, {stopline} [, {timeout}]]]])
3bddd30
  		Same as searchpair(), but returns a |List| with the line and
3bddd30
  		column position of the match. The first element of the |List|
3bddd30
  		is the line number and the second element is the byte index of
3bddd30
***************
3bddd30
*** 4394,4400 ****
3bddd30
  <
3bddd30
  		See |match-parens| for a bigger and more useful example.
3bddd30
  
3bddd30
! searchpos({pattern} [, {flags} [, {stopline}]])		*searchpos()*
3bddd30
  		Same as |search()|, but returns a |List| with the line and
3bddd30
  		column position of the match. The first element of the |List|
3bddd30
  		is the line number and the second element is the byte index of
3bddd30
--- 4408,4414 ----
3bddd30
  <
3bddd30
  		See |match-parens| for a bigger and more useful example.
3bddd30
  
3bddd30
! searchpos({pattern} [, {flags} [, {stopline} [, {timeout}]]])	*searchpos()*
3bddd30
  		Same as |search()|, but returns a |List| with the line and
3bddd30
  		column position of the match. The first element of the |List|
3bddd30
  		is the line number and the second element is the byte index of
3bddd30
*** ../vim-7.1.210/runtime/plugin/matchparen.vim	Sat Aug 18 18:20:57 2007
3bddd30
--- runtime/plugin/matchparen.vim	Sun Jan  6 16:22:39 2008
3bddd30
***************
3bddd30
*** 1,6 ****
3bddd30
  " Vim plugin for showing matching parens
3bddd30
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
3bddd30
! " Last Change: 2007 Aug 8
3bddd30
  
3bddd30
  " Exit quickly when:
3bddd30
  " - this plugin was already loaded (or disabled)
3bddd30
--- 1,6 ----
3bddd30
  " Vim plugin for showing matching parens
3bddd30
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
3bddd30
! " Last Change: 2008 Jan 06
3bddd30
  
3bddd30
  " Exit quickly when:
3bddd30
  " - this plugin was already loaded (or disabled)
3bddd30
***************
3bddd30
*** 111,117 ****
3bddd30
  	\ '=~?  "string\\|character\\|singlequote\\|comment"'
3bddd30
    execute 'if' s_skip '| let s_skip = 0 | endif'
3bddd30
  
3bddd30
!   let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
3bddd30
  
3bddd30
    if before > 0
3bddd30
      call winrestview(save_cursor)
3bddd30
--- 111,122 ----
3bddd30
  	\ '=~?  "string\\|character\\|singlequote\\|comment"'
3bddd30
    execute 'if' s_skip '| let s_skip = 0 | endif'
3bddd30
  
3bddd30
!   try
3bddd30
!     " Limit the search time to 500 msec to avoid a hang on very long lines.
3bddd30
!     let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, 500)
3bddd30
!   catch /E118/
3bddd30
!     let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
3bddd30
!   endtry
3bddd30
  
3bddd30
    if before > 0
3bddd30
      call winrestview(save_cursor)
3bddd30
*** ../vim-7.1.210/src/edit.c	Wed Jan  2 22:08:43 2008
3bddd30
--- src/edit.c	Sun Jan  6 16:08:00 2008
3bddd30
***************
3bddd30
*** 4062,4068 ****
3bddd30
  		    found_new_match = searchit(NULL, ins_buf, pos,
3bddd30
  							      compl_direction,
3bddd30
  				 compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
3bddd30
! 							RE_LAST, (linenr_T)0);
3bddd30
  		--msg_silent;
3bddd30
  		if (!compl_started)
3bddd30
  		{
3bddd30
--- 4062,4068 ----
3bddd30
  		    found_new_match = searchit(NULL, ins_buf, pos,
3bddd30
  							      compl_direction,
3bddd30
  				 compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
3bddd30
! 						  RE_LAST, (linenr_T)0, NULL);
3bddd30
  		--msg_silent;
3bddd30
  		if (!compl_started)
3bddd30
  		{
3bddd30
*** ../vim-7.1.210/src/eval.c	Sat Jan  5 22:15:21 2008
3bddd30
--- src/eval.c	Sun Jan  6 16:37:42 2008
3bddd30
***************
3bddd30
*** 7213,7223 ****
3bddd30
      {"repeat",		2, 2, f_repeat},
3bddd30
      {"resolve",		1, 1, f_resolve},
3bddd30
      {"reverse",		1, 1, f_reverse},
3bddd30
!     {"search",		1, 3, f_search},
3bddd30
      {"searchdecl",	1, 3, f_searchdecl},
3bddd30
!     {"searchpair",	3, 6, f_searchpair},
3bddd30
!     {"searchpairpos",	3, 6, f_searchpairpos},
3bddd30
!     {"searchpos",	1, 3, f_searchpos},
3bddd30
      {"server2client",	2, 2, f_server2client},
3bddd30
      {"serverlist",	0, 0, f_serverlist},
3bddd30
      {"setbufvar",	3, 3, f_setbufvar},
3bddd30
--- 7213,7223 ----
3bddd30
      {"repeat",		2, 2, f_repeat},
3bddd30
      {"resolve",		1, 1, f_resolve},
3bddd30
      {"reverse",		1, 1, f_reverse},
3bddd30
!     {"search",		1, 4, f_search},
3bddd30
      {"searchdecl",	1, 3, f_searchdecl},
3bddd30
!     {"searchpair",	3, 7, f_searchpair},
3bddd30
!     {"searchpairpos",	3, 7, f_searchpairpos},
3bddd30
!     {"searchpos",	1, 4, f_searchpos},
3bddd30
      {"server2client",	2, 2, f_server2client},
3bddd30
      {"serverlist",	0, 0, f_serverlist},
3bddd30
      {"setbufvar",	3, 3, f_setbufvar},
3bddd30
***************
3bddd30
*** 14020,14025 ****
3bddd30
--- 14020,14029 ----
3bddd30
      int		dir;
3bddd30
      int		retval = 0;	/* default: FAIL */
3bddd30
      long	lnum_stop = 0;
3bddd30
+     proftime_T	tm;
3bddd30
+ #ifdef FEAT_RELTIME
3bddd30
+     long	time_limit = 0;
3bddd30
+ #endif
3bddd30
      int		options = SEARCH_KEEP;
3bddd30
      int		subpatnum;
3bddd30
  
3bddd30
***************
3bddd30
*** 14033,14047 ****
3bddd30
      if (flags & SP_END)
3bddd30
  	options |= SEARCH_END;
3bddd30
  
3bddd30
!     /* Optional extra argument: line number to stop searching. */
3bddd30
!     if (argvars[1].v_type != VAR_UNKNOWN
3bddd30
! 	    && argvars[2].v_type != VAR_UNKNOWN)
3bddd30
      {
3bddd30
  	lnum_stop = get_tv_number_chk(&argvars[2], NULL);
3bddd30
  	if (lnum_stop < 0)
3bddd30
  	    goto theend;
3bddd30
      }
3bddd30
  
3bddd30
      /*
3bddd30
       * This function does not accept SP_REPEAT and SP_RETCOUNT flags.
3bddd30
       * Check to make sure only those flags are set.
3bddd30
--- 14037,14063 ----
3bddd30
      if (flags & SP_END)
3bddd30
  	options |= SEARCH_END;
3bddd30
  
3bddd30
!     /* Optional arguments: line number to stop searching and timeout. */
3bddd30
!     if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN)
3bddd30
      {
3bddd30
  	lnum_stop = get_tv_number_chk(&argvars[2], NULL);
3bddd30
  	if (lnum_stop < 0)
3bddd30
  	    goto theend;
3bddd30
+ #ifdef FEAT_RELTIME
3bddd30
+ 	if (argvars[3].v_type != VAR_UNKNOWN)
3bddd30
+ 	{
3bddd30
+ 	    time_limit = get_tv_number_chk(&argvars[3], NULL);
3bddd30
+ 	    if (time_limit < 0)
3bddd30
+ 		goto theend;
3bddd30
+ 	}
3bddd30
+ #endif
3bddd30
      }
3bddd30
  
3bddd30
+ #ifdef FEAT_RELTIME
3bddd30
+     /* Set the time limit, if there is one. */
3bddd30
+     profile_setlimit(time_limit, &tm;;
3bddd30
+ #endif
3bddd30
+ 
3bddd30
      /*
3bddd30
       * This function does not accept SP_REPEAT and SP_RETCOUNT flags.
3bddd30
       * Check to make sure only those flags are set.
3bddd30
***************
3bddd30
*** 14057,14063 ****
3bddd30
  
3bddd30
      pos = save_cursor = curwin->w_cursor;
3bddd30
      subpatnum = searchit(curwin, curbuf, &pos, dir, pat, 1L,
3bddd30
! 				     options, RE_SEARCH, (linenr_T)lnum_stop);
3bddd30
      if (subpatnum != FAIL)
3bddd30
      {
3bddd30
  	if (flags & SP_SUBPAT)
3bddd30
--- 14073,14079 ----
3bddd30
  
3bddd30
      pos = save_cursor = curwin->w_cursor;
3bddd30
      subpatnum = searchit(curwin, curbuf, &pos, dir, pat, 1L,
3bddd30
! 				options, RE_SEARCH, (linenr_T)lnum_stop, &tm;;
3bddd30
      if (subpatnum != FAIL)
3bddd30
      {
3bddd30
  	if (flags & SP_SUBPAT)
3bddd30
***************
3bddd30
*** 14147,14152 ****
3bddd30
--- 14163,14169 ----
3bddd30
      char_u	nbuf3[NUMBUFLEN];
3bddd30
      int		retval = 0;		/* default: FAIL */
3bddd30
      long	lnum_stop = 0;
3bddd30
+     long	time_limit = 0;
3bddd30
  
3bddd30
      /* Get the three pattern arguments: start, middle, end. */
3bddd30
      spat = get_tv_string_chk(&argvars[0]);
3bddd30
***************
3bddd30
*** 14182,14194 ****
3bddd30
  	    lnum_stop = get_tv_number_chk(&argvars[5], NULL);
3bddd30
  	    if (lnum_stop < 0)
3bddd30
  		goto theend;
3bddd30
  	}
3bddd30
      }
3bddd30
      if (skip == NULL)
3bddd30
  	goto theend;	    /* type error */
3bddd30
  
3bddd30
      retval = do_searchpair(spat, mpat, epat, dir, skip, flags,
3bddd30
! 							match_pos, lnum_stop);
3bddd30
  
3bddd30
  theend:
3bddd30
      p_ws = save_p_ws;
3bddd30
--- 14199,14219 ----
3bddd30
  	    lnum_stop = get_tv_number_chk(&argvars[5], NULL);
3bddd30
  	    if (lnum_stop < 0)
3bddd30
  		goto theend;
3bddd30
+ #ifdef FEAT_RELTIME
3bddd30
+ 	    if (argvars[6].v_type != VAR_UNKNOWN)
3bddd30
+ 	    {
3bddd30
+ 		time_limit = get_tv_number_chk(&argvars[6], NULL);
3bddd30
+ 		if (time_limit < 0)
3bddd30
+ 		    goto theend;
3bddd30
+ 	    }
3bddd30
+ #endif
3bddd30
  	}
3bddd30
      }
3bddd30
      if (skip == NULL)
3bddd30
  	goto theend;	    /* type error */
3bddd30
  
3bddd30
      retval = do_searchpair(spat, mpat, epat, dir, skip, flags,
3bddd30
! 					    match_pos, lnum_stop, time_limit);
3bddd30
  
3bddd30
  theend:
3bddd30
      p_ws = save_p_ws;
3bddd30
***************
3bddd30
*** 14240,14246 ****
3bddd30
   * Returns 0 or -1 for no match,
3bddd30
   */
3bddd30
      long
3bddd30
! do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, lnum_stop)
3bddd30
      char_u	*spat;	    /* start pattern */
3bddd30
      char_u	*mpat;	    /* middle pattern */
3bddd30
      char_u	*epat;	    /* end pattern */
3bddd30
--- 14265,14272 ----
3bddd30
   * Returns 0 or -1 for no match,
3bddd30
   */
3bddd30
      long
3bddd30
! do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos,
3bddd30
! 							lnum_stop, time_limit)
3bddd30
      char_u	*spat;	    /* start pattern */
3bddd30
      char_u	*mpat;	    /* middle pattern */
3bddd30
      char_u	*epat;	    /* end pattern */
3bddd30
***************
3bddd30
*** 14249,14254 ****
3bddd30
--- 14275,14281 ----
3bddd30
      int		flags;	    /* SP_SETPCMARK and other SP_ values */
3bddd30
      pos_T	*match_pos;
3bddd30
      linenr_T	lnum_stop;  /* stop at this line if not zero */
3bddd30
+     long	time_limit; /* stop after this many msec */
3bddd30
  {
3bddd30
      char_u	*save_cpo;
3bddd30
      char_u	*pat, *pat2 = NULL, *pat3 = NULL;
3bddd30
***************
3bddd30
*** 14263,14273 ****
3bddd30
--- 14290,14306 ----
3bddd30
      int		nest = 1;
3bddd30
      int		err;
3bddd30
      int		options = SEARCH_KEEP;
3bddd30
+     proftime_T	tm;
3bddd30
  
3bddd30
      /* Make 'cpoptions' empty, the 'l' flag should not be used here. */
3bddd30
      save_cpo = p_cpo;
3bddd30
      p_cpo = (char_u *)"";
3bddd30
  
3bddd30
+ #ifdef FEAT_RELTIME
3bddd30
+     /* Set the time limit, if there is one. */
3bddd30
+     profile_setlimit(time_limit, &tm;;
3bddd30
+ #endif
3bddd30
+ 
3bddd30
      /* Make two search patterns: start/end (pat2, for in nested pairs) and
3bddd30
       * start/middle/end (pat3, for the top pair). */
3bddd30
      pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15));
3bddd30
***************
3bddd30
*** 14291,14297 ****
3bddd30
      for (;;)
3bddd30
      {
3bddd30
  	n = searchit(curwin, curbuf, &pos, dir, pat, 1L,
3bddd30
! 					       options, RE_SEARCH, lnum_stop);
3bddd30
  	if (n == FAIL || (firstpos.lnum != 0 && equalpos(pos, firstpos)))
3bddd30
  	    /* didn't find it or found the first match again: FAIL */
3bddd30
  	    break;
3bddd30
--- 14324,14330 ----
3bddd30
      for (;;)
3bddd30
      {
3bddd30
  	n = searchit(curwin, curbuf, &pos, dir, pat, 1L,
3bddd30
! 					   options, RE_SEARCH, lnum_stop, &tm;;
3bddd30
  	if (n == FAIL || (firstpos.lnum != 0 && equalpos(pos, firstpos)))
3bddd30
  	    /* didn't find it or found the first match again: FAIL */
3bddd30
  	    break;
3bddd30
*** ../vim-7.1.210/src/ex_cmds2.c	Fri Jan  4 16:00:10 2008
3bddd30
--- src/ex_cmds2.c	Sun Jan  6 18:22:28 2008
3bddd30
***************
3bddd30
*** 895,913 ****
3bddd30
      sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart);
3bddd30
  # else
3bddd30
      sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec);
3bddd30
! #endif
3bddd30
      return buf;
3bddd30
  }
3bddd30
  
3bddd30
! # endif  /* FEAT_PROFILE || FEAT_RELTIME */
3bddd30
  
3bddd30
- # if defined(FEAT_PROFILE) || defined(PROTO)
3bddd30
  /*
3bddd30
!  * Functions for profiling.
3bddd30
   */
3bddd30
! static void script_do_profile __ARGS((scriptitem_T *si));
3bddd30
! static void script_dump_profile __ARGS((FILE *fd));
3bddd30
! static proftime_T prof_wait_time;
3bddd30
  
3bddd30
  /*
3bddd30
   * Set the time in "tm" to zero.
3bddd30
--- 895,955 ----
3bddd30
      sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart);
3bddd30
  # else
3bddd30
      sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec);
3bddd30
! # endif
3bddd30
      return buf;
3bddd30
  }
3bddd30
  
3bddd30
! /*
3bddd30
!  * Put the time "msec" past now in "tm".
3bddd30
!  */
3bddd30
!     void
3bddd30
! profile_setlimit(msec, tm)
3bddd30
!     long	msec;
3bddd30
!     proftime_T	*tm;
3bddd30
! {
3bddd30
!     if (msec <= 0)   /* no limit */
3bddd30
! 	profile_zero(tm);
3bddd30
!     else
3bddd30
!     {
3bddd30
! # ifdef WIN3264
3bddd30
! 	LARGE_INTEGER   fr;
3bddd30
! 
3bddd30
! 	QueryPerformanceCounter(tm);
3bddd30
! 	QueryPerformanceFrequency(&fr);
3bddd30
! 	tm->QuadPart +=  (double)msec / 1000.0 * (double)fr.QuadPart;
3bddd30
! # else
3bddd30
! 	long	    usec;
3bddd30
! 
3bddd30
! 	gettimeofday(tm, NULL);
3bddd30
! 	usec = (long)tm->tv_usec + (long)msec * 1000;
3bddd30
! 	tm->tv_usec = usec % 1000000L;
3bddd30
! 	tm->tv_sec += usec / 1000000L;
3bddd30
! # endif
3bddd30
!     }
3bddd30
! }
3bddd30
  
3bddd30
  /*
3bddd30
!  * Return TRUE if the current time is past "tm".
3bddd30
   */
3bddd30
!     int
3bddd30
! profile_passed_limit(tm)
3bddd30
!     proftime_T	*tm;
3bddd30
! {
3bddd30
!     proftime_T	now;
3bddd30
! 
3bddd30
! # ifdef WIN3264
3bddd30
!     if (tm->QuadPart == 0)  /* timer was not set */
3bddd30
! 	return FALSE;
3bddd30
!     QueryPerformanceCounter(&now;;
3bddd30
!     return (now.QuadPart > tm->QuadPart);
3bddd30
! # else
3bddd30
!     if (tm->tv_sec == 0)    /* timer was not set */
3bddd30
! 	return FALSE;
3bddd30
!     gettimeofday(&now, NULL);
3bddd30
!     return (now.tv_sec > tm->tv_sec
3bddd30
! 	    || (now.tv_sec == tm->tv_sec && now.tv_usec > tm->tv_usec));
3bddd30
! # endif
3bddd30
! }
3bddd30
  
3bddd30
  /*
3bddd30
   * Set the time in "tm" to zero.
3bddd30
***************
3bddd30
*** 923,928 ****
3bddd30
--- 965,980 ----
3bddd30
      tm->tv_sec = 0;
3bddd30
  # endif
3bddd30
  }
3bddd30
+ 
3bddd30
+ # endif  /* FEAT_PROFILE || FEAT_RELTIME */
3bddd30
+ 
3bddd30
+ # if defined(FEAT_PROFILE) || defined(PROTO)
3bddd30
+ /*
3bddd30
+  * Functions for profiling.
3bddd30
+  */
3bddd30
+ static void script_do_profile __ARGS((scriptitem_T *si));
3bddd30
+ static void script_dump_profile __ARGS((FILE *fd));
3bddd30
+ static proftime_T prof_wait_time;
3bddd30
  
3bddd30
  /*
3bddd30
   * Add the time "tm2" to "tm".
3bddd30
*** ../vim-7.1.210/src/ex_docmd.c	Fri Jan  4 16:00:10 2008
3bddd30
--- src/ex_docmd.c	Sun Jan  6 16:08:29 2008
3bddd30
***************
3bddd30
*** 3979,3985 ****
3bddd30
  					*cmd == '?' ? BACKWARD : FORWARD,
3bddd30
  					(char_u *)"", 1L,
3bddd30
  					SEARCH_MSG + SEARCH_START,
3bddd30
! 						      i, (linenr_T)0) != FAIL)
3bddd30
  				lnum = pos.lnum;
3bddd30
  			    else
3bddd30
  			    {
3bddd30
--- 3980,3986 ----
3bddd30
  					*cmd == '?' ? BACKWARD : FORWARD,
3bddd30
  					(char_u *)"", 1L,
3bddd30
  					SEARCH_MSG + SEARCH_START,
3bddd30
! 						i, (linenr_T)0, NULL) != FAIL)
3bddd30
  				lnum = pos.lnum;
3bddd30
  			    else
3bddd30
  			    {
3bddd30
*** ../vim-7.1.210/src/normal.c	Sat Jan  5 13:34:01 2008
3bddd30
--- src/normal.c	Sun Jan  6 16:08:54 2008
3bddd30
***************
3bddd30
*** 4194,4200 ****
3bddd30
      for (;;)
3bddd30
      {
3bddd30
  	t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD,
3bddd30
! 				  pat, 1L, searchflags, RE_LAST, (linenr_T)0);
3bddd30
  	if (curwin->w_cursor.lnum >= old_pos.lnum)
3bddd30
  	    t = FAIL;	/* match after start is failure too */
3bddd30
  
3bddd30
--- 4194,4200 ----
3bddd30
      for (;;)
3bddd30
      {
3bddd30
  	t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD,
3bddd30
! 			    pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL);
3bddd30
  	if (curwin->w_cursor.lnum >= old_pos.lnum)
3bddd30
  	    t = FAIL;	/* match after start is failure too */
3bddd30
  
3bddd30
*** ../vim-7.1.210/src/proto/eval.pro	Sun May  6 15:18:09 2007
3bddd30
--- src/proto/eval.pro	Sun Jan  6 15:55:47 2008
3bddd30
***************
3bddd30
*** 54,60 ****
3bddd30
  long get_dict_number __ARGS((dict_T *d, char_u *key));
3bddd30
  char_u *get_function_name __ARGS((expand_T *xp, int idx));
3bddd30
  char_u *get_expr_name __ARGS((expand_T *xp, int idx));
3bddd30
! long do_searchpair __ARGS((char_u *spat, char_u *mpat, char_u *epat, int dir, char_u *skip, int flags, pos_T *match_pos, linenr_T lnum_stop));
3bddd30
  void set_vim_var_nr __ARGS((int idx, long val));
3bddd30
  long get_vim_var_nr __ARGS((int idx));
3bddd30
  char_u *get_vim_var_str __ARGS((int idx));
3bddd30
--- 54,60 ----
3bddd30
  long get_dict_number __ARGS((dict_T *d, char_u *key));
3bddd30
  char_u *get_function_name __ARGS((expand_T *xp, int idx));
3bddd30
  char_u *get_expr_name __ARGS((expand_T *xp, int idx));
3bddd30
! long do_searchpair __ARGS((char_u *spat, char_u *mpat, char_u *epat, int dir, char_u *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit));
3bddd30
  void set_vim_var_nr __ARGS((int idx, long val));
3bddd30
  long get_vim_var_nr __ARGS((int idx));
3bddd30
  char_u *get_vim_var_str __ARGS((int idx));
3bddd30
*** ../vim-7.1.210/src/proto/ex_cmds2.pro	Sat May  5 20:21:13 2007
3bddd30
--- src/proto/ex_cmds2.pro	Sun Jan  6 16:42:24 2008
3bddd30
***************
3bddd30
*** 14,19 ****
3bddd30
--- 14,21 ----
3bddd30
  void profile_end __ARGS((proftime_T *tm));
3bddd30
  void profile_sub __ARGS((proftime_T *tm, proftime_T *tm2));
3bddd30
  char *profile_msg __ARGS((proftime_T *tm));
3bddd30
+ void profile_setlimit __ARGS((long msec, proftime_T *tm));
3bddd30
+ int profile_passed_limit __ARGS((proftime_T *tm));
3bddd30
  void profile_zero __ARGS((proftime_T *tm));
3bddd30
  void profile_add __ARGS((proftime_T *tm, proftime_T *tm2));
3bddd30
  void profile_self __ARGS((proftime_T *self, proftime_T *total, proftime_T *children));
3bddd30
*** ../vim-7.1.210/src/proto/search.pro	Wed Aug  8 22:48:16 2007
3bddd30
--- src/proto/search.pro	Sun Jan  6 16:11:53 2008
3bddd30
***************
3bddd30
*** 10,16 ****
3bddd30
  void reset_search_dir __ARGS((void));
3bddd30
  void set_last_search_pat __ARGS((char_u *s, int idx, int magic, int setlast));
3bddd30
  void last_pat_prog __ARGS((regmmatch_T *regmatch));
3bddd30
! int searchit __ARGS((win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum));
3bddd30
  int do_search __ARGS((oparg_T *oap, int dirc, char_u *pat, long count, int options));
3bddd30
  int search_for_exact_line __ARGS((buf_T *buf, pos_T *pos, int dir, char_u *pat));
3bddd30
  int searchc __ARGS((cmdarg_T *cap, int t_cmd));
3bddd30
--- 10,16 ----
3bddd30
  void reset_search_dir __ARGS((void));
3bddd30
  void set_last_search_pat __ARGS((char_u *s, int idx, int magic, int setlast));
3bddd30
  void last_pat_prog __ARGS((regmmatch_T *regmatch));
3bddd30
! int searchit __ARGS((win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum, proftime_T *tm));
3bddd30
  int do_search __ARGS((oparg_T *oap, int dirc, char_u *pat, long count, int options));
3bddd30
  int search_for_exact_line __ARGS((buf_T *buf, pos_T *pos, int dir, char_u *pat));
3bddd30
  int searchc __ARGS((cmdarg_T *cap, int t_cmd));
3bddd30
*** ../vim-7.1.210/src/search.c	Tue Jan  1 15:42:45 2008
3bddd30
--- src/search.c	Sun Jan  6 18:23:37 2008
3bddd30
***************
3bddd30
*** 494,501 ****
3bddd30
   * When FEAT_EVAL is defined, returns the index of the first matching
3bddd30
   * subpattern plus one; one if there was none.
3bddd30
   */
3bddd30
      int
3bddd30
! searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum)
3bddd30
      win_T	*win;		/* window to search in; can be NULL for a
3bddd30
  				   buffer without a window! */
3bddd30
      buf_T	*buf;
3bddd30
--- 494,502 ----
3bddd30
   * When FEAT_EVAL is defined, returns the index of the first matching
3bddd30
   * subpattern plus one; one if there was none.
3bddd30
   */
3bddd30
+ /*ARGSUSED*/
3bddd30
      int
3bddd30
! searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
3bddd30
      win_T	*win;		/* window to search in; can be NULL for a
3bddd30
  				   buffer without a window! */
3bddd30
      buf_T	*buf;
3bddd30
***************
3bddd30
*** 506,511 ****
3bddd30
--- 507,513 ----
3bddd30
      int		options;
3bddd30
      int		pat_use;	/* which pattern to use when "pat" is empty */
3bddd30
      linenr_T	stop_lnum;	/* stop after this line number when != 0 */
3bddd30
+     proftime_T	*tm;		/* timeout limit or NULL */
3bddd30
  {
3bddd30
      int		found;
3bddd30
      linenr_T	lnum;		/* no init to shut up Apollo cc */
3bddd30
***************
3bddd30
*** 594,599 ****
3bddd30
--- 596,606 ----
3bddd30
  		if (stop_lnum != 0 && (dir == FORWARD
3bddd30
  				       ? lnum > stop_lnum : lnum < stop_lnum))
3bddd30
  		    break;
3bddd30
+ #ifdef FEAT_RELTIME
3bddd30
+ 		/* Stop after passing the "tm" time limit. */
3bddd30
+ 		if (tm != NULL && profile_passed_limit(tm))
3bddd30
+ 		    break;
3bddd30
+ #endif
3bddd30
  
3bddd30
  		/*
3bddd30
  		 * Look for a match somewhere in line "lnum".
3bddd30
***************
3bddd30
*** 1249,1255 ****
3bddd30
  		       (SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS
3bddd30
  			+ SEARCH_MSG + SEARCH_START
3bddd30
  			+ ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
3bddd30
! 		RE_LAST, (linenr_T)0);
3bddd30
  
3bddd30
  	if (dircp != NULL)
3bddd30
  	    *dircp = dirc;	/* restore second '/' or '?' for normal_cmd() */
3bddd30
--- 1256,1262 ----
3bddd30
  		       (SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS
3bddd30
  			+ SEARCH_MSG + SEARCH_START
3bddd30
  			+ ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
3bddd30
! 		RE_LAST, (linenr_T)0, NULL);
3bddd30
  
3bddd30
  	if (dircp != NULL)
3bddd30
  	    *dircp = dirc;	/* restore second '/' or '?' for normal_cmd() */
3bddd30
***************
3bddd30
*** 3780,3786 ****
3bddd30
  	if (do_searchpair((char_u *)"<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)",
3bddd30
  		    (char_u *)"",
3bddd30
  		    (char_u *)"</[^>]*>", BACKWARD, (char_u *)"", 0,
3bddd30
! 						      NULL, (linenr_T)0) <= 0)
3bddd30
  	{
3bddd30
  	    curwin->w_cursor = old_pos;
3bddd30
  	    goto theend;
3bddd30
--- 3787,3793 ----
3bddd30
  	if (do_searchpair((char_u *)"<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)",
3bddd30
  		    (char_u *)"",
3bddd30
  		    (char_u *)"</[^>]*>", BACKWARD, (char_u *)"", 0,
3bddd30
! 						  NULL, (linenr_T)0, 0L) <= 0)
3bddd30
  	{
3bddd30
  	    curwin->w_cursor = old_pos;
3bddd30
  	    goto theend;
3bddd30
***************
3bddd30
*** 3814,3820 ****
3bddd30
      sprintf((char *)epat, "</%.*s>\\c", len, p);
3bddd30
  
3bddd30
      r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"",
3bddd30
! 						       0, NULL, (linenr_T)0);
3bddd30
  
3bddd30
      vim_free(spat);
3bddd30
      vim_free(epat);
3bddd30
--- 3821,3827 ----
3bddd30
      sprintf((char *)epat, "</%.*s>\\c", len, p);
3bddd30
  
3bddd30
      r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"",
3bddd30
! 						    0, NULL, (linenr_T)0, 0L);
3bddd30
  
3bddd30
      vim_free(spat);
3bddd30
      vim_free(epat);
3bddd30
*** ../vim-7.1.210/src/version.c	Sun Jan  6 17:18:16 2008
3bddd30
--- src/version.c	Sun Jan  6 20:00:03 2008
3bddd30
***************
3bddd30
*** 668,669 ****
3bddd30
--- 668,671 ----
3bddd30
  {   /* Add new patch number below this line */
3bddd30
+ /**/
3bddd30
+     211,
3bddd30
  /**/
3bddd30
3bddd30
-- 
3bddd30
No letters of the alphabet were harmed in the creation of this message.
3bddd30
3bddd30
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3bddd30
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3bddd30
\\\        download, build and distribute -- http://www.A-A-P.org        ///
3bddd30
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///