diff src/search.c @ 7358:6fbeef3b65e6 v7.4.984

commit https://github.com/vim/vim/commit/ad4d8a192abf44b89371af87d70b971cd654b799 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 28 19:20:36 2015 +0100 patch 7.4.984 Problem: searchpos() always starts searching in the first column, which is not what some people expect. (Brett Stahlman) Solution: Add the 'z' flag: start at the specified column.
author Christian Brabandt <cb@256bit.org>
date Mon, 28 Dec 2015 19:30:04 +0100
parents d92910c0c415
children 0b6c37dd858d
line wrap: on
line diff
--- a/src/search.c
+++ b/src/search.c
@@ -578,6 +578,7 @@ last_pat_prog(regmatch)
  * if (options & SEARCH_KEEP) keep previous search pattern
  * if (options & SEARCH_FOLD) match only once in a closed fold
  * if (options & SEARCH_PEEK) check for typed char, cancel search
+ * if (options & SEARCH_COL) start at pos->col instead of zero
  *
  * Return FAIL (zero) for failure, non-zero for success.
  * When FEAT_EVAL is defined, returns the index of the first matching
@@ -599,6 +600,7 @@ searchit(win, buf, pos, dir, pat, count,
 {
     int		found;
     linenr_T	lnum;		/* no init to shut up Apollo cc */
+    colnr_T	col;
     regmmatch_T	regmatch;
     char_u	*ptr;
     colnr_T	matchcol;
@@ -711,12 +713,14 @@ searchit(win, buf, pos, dir, pat, count,
 		/*
 		 * Look for a match somewhere in line "lnum".
 		 */
+		col = at_first_line && (options & SEARCH_COL) ? pos->col
+								 : (colnr_T)0;
 		nmatched = vim_regexec_multi(&regmatch, win, buf,
-						      lnum, (colnr_T)0,
+					     lnum, col,
 #ifdef FEAT_RELTIME
-						      tm
+					     tm
 #else
-						      NULL
+					     NULL
 #endif
 						      );
 		/* Abort searching on an error (e.g., out of stack). */
@@ -1098,6 +1102,7 @@ set_vv_searchforward()
 
 /*
  * Return the number of the first subpat that matched.
+ * Return zero if none of them matched.
  */
     static int
 first_submatch(rp)