Karsten Hopp 9f44d6
To: vim_dev@googlegroups.com
Karsten Hopp 9f44d6
Subject: Patch 7.4.813
Karsten Hopp 9f44d6
Fcc: outbox
Karsten Hopp 9f44d6
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 9f44d6
Mime-Version: 1.0
Karsten Hopp 9f44d6
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 9f44d6
Content-Transfer-Encoding: 8bit
Karsten Hopp 9f44d6
------------
Karsten Hopp 9f44d6
Karsten Hopp 9f44d6
Patch 7.4.813
Karsten Hopp 9f44d6
Problem:    It is not possible to save and restore character search state.
Karsten Hopp 9f44d6
Solution:   Add getcharsearch() and setcharsearch().  (James McCoy)
Karsten Hopp 9f44d6
Files:      runtime/doc/eval.txt, src/eval.c, src/proto/search.pro,
Karsten Hopp 9f44d6
            src/search.c, src/testdir/test_charsearch.in,
Karsten Hopp 9f44d6
            src/testdir/test_charsearch.ok, src/testdir/Makefile,
Karsten Hopp 9f44d6
            src/testdir/Make_amiga.mak, src/testdir/Make_dos.mak,
Karsten Hopp 9f44d6
            src/testdir/Make_ming.mak, src/testdir/Make_os2.mak,
Karsten Hopp 9f44d6
            src/testdir/Make_vms.mms
Karsten Hopp 9f44d6
Karsten Hopp 9f44d6
Karsten Hopp 9f44d6
*** ../vim-7.4.812/runtime/doc/eval.txt	2015-07-21 15:48:13.581518028 +0200
Karsten Hopp 9f44d6
--- runtime/doc/eval.txt	2015-08-11 13:32:31.643435417 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 1820,1828 ****
Karsten Hopp 9f44d6
  				any	variable {varname} in buffer {expr}
Karsten Hopp 9f44d6
  getchar( [expr])		Number	get one character from the user
Karsten Hopp 9f44d6
  getcharmod( )			Number	modifiers for the last typed character
Karsten Hopp 9f44d6
  getcmdline()			String	return the current command-line
Karsten Hopp 9f44d6
  getcmdpos()			Number	return cursor position in command-line
Karsten Hopp 9f44d6
! getcmdtype()			String	return the current command-line type
Karsten Hopp 9f44d6
  getcurpos()			List	position of the cursor
Karsten Hopp 9f44d6
  getcwd()			String	the current working directory
Karsten Hopp 9f44d6
  getfontname( [{name}])		String	name of font being used
Karsten Hopp 9f44d6
--- 1822,1832 ----
Karsten Hopp 9f44d6
  				any	variable {varname} in buffer {expr}
Karsten Hopp 9f44d6
  getchar( [expr])		Number	get one character from the user
Karsten Hopp 9f44d6
  getcharmod( )			Number	modifiers for the last typed character
Karsten Hopp 9f44d6
+ getcharsearch()			Dict	last character search
Karsten Hopp 9f44d6
  getcmdline()			String	return the current command-line
Karsten Hopp 9f44d6
  getcmdpos()			Number	return cursor position in command-line
Karsten Hopp 9f44d6
! getcmdtype()			String	return current command-line type
Karsten Hopp 9f44d6
! getcmdwintype()			String	return current command-line window type
Karsten Hopp 9f44d6
  getcurpos()			List	position of the cursor
Karsten Hopp 9f44d6
  getcwd()			String	the current working directory
Karsten Hopp 9f44d6
  getfontname( [{name}])		String	name of font being used
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 1968,1973 ****
Karsten Hopp 9f44d6
--- 1972,1978 ----
Karsten Hopp 9f44d6
  				Number	send reply string
Karsten Hopp 9f44d6
  serverlist()			String	get a list of available servers
Karsten Hopp 9f44d6
  setbufvar( {expr}, {varname}, {val})	set {varname} in buffer {expr} to {val}
Karsten Hopp 9f44d6
+ setcharsearch( {dict})		Dict	set character search from {dict}
Karsten Hopp 9f44d6
  setcmdpos( {pos})		Number	set cursor position in command-line
Karsten Hopp 9f44d6
  setline( {lnum}, {line})	Number	set line {lnum} to {line}
Karsten Hopp 9f44d6
  setloclist( {nr}, {list}[, {action}])
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 3334,3339 ****
Karsten Hopp 9f44d6
--- 3363,3388 ----
Karsten Hopp 9f44d6
  		character itself are obtained.	Thus Shift-a results in "A"
Karsten Hopp 9f44d6
  		without a modifier.
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
+ getcharsearch()						*getcharsearch()*
Karsten Hopp 9f44d6
+ 		Return the current character search information as a {dict}
Karsten Hopp 9f44d6
+ 		with the following entries:
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ 		    char	character previously used for a character
Karsten Hopp 9f44d6
+ 				search (|t|, |f|, |T|, or |F|); empty string
Karsten Hopp 9f44d6
+ 				if no character search has been performed
Karsten Hopp 9f44d6
+ 		    forward	direction of character search; 1 for forward,
Karsten Hopp 9f44d6
+ 				0 for backward
Karsten Hopp 9f44d6
+ 		    until	type of character search; 1 for a |t| or |T|
Karsten Hopp 9f44d6
+ 				character search, 0 for an |f| or |F|
Karsten Hopp 9f44d6
+ 				character search
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ 		This can be useful to always have |;| and |,| search
Karsten Hopp 9f44d6
+ 		forward/backward regardless of the direction of the previous
Karsten Hopp 9f44d6
+ 		character search: >
Karsten Hopp 9f44d6
+ 			:nnoremap <expr> ; getcharsearch().forward ? ';' : ','
Karsten Hopp 9f44d6
+ 			:nnoremap <expr> , getcharsearch().forward ? ',' : ';'
Karsten Hopp 9f44d6
+ <		Also see |setcharsearch()|.
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
  getcmdline()						*getcmdline()*
Karsten Hopp 9f44d6
  		Return the current command-line.  Only works when the command
Karsten Hopp 9f44d6
  		line is being edited, thus requires use of |c_CTRL-\_e| or
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 5356,5361 ****
Karsten Hopp 9f44d6
--- 5419,5444 ----
Karsten Hopp 9f44d6
  			:call setbufvar("todo", "myvar", "foobar")
Karsten Hopp 9f44d6
  <		This function is not available in the |sandbox|.
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
+ setcharsearch()						*setcharsearch()*
Karsten Hopp 9f44d6
+ 		Set the current character search information to {dict},
Karsten Hopp 9f44d6
+ 		which contains one or more of the following entries:
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ 		    char	character which will be used for a subsequent
Karsten Hopp 9f44d6
+ 				|,| or |;| command; an empty string clears the
Karsten Hopp 9f44d6
+ 				character search
Karsten Hopp 9f44d6
+ 		    forward	direction of character search; 1 for forward,
Karsten Hopp 9f44d6
+ 				0 for backward
Karsten Hopp 9f44d6
+ 		    until	type of character search; 1 for a |t| or |T|
Karsten Hopp 9f44d6
+ 				character search, 0 for an |f| or |F|
Karsten Hopp 9f44d6
+ 				character search
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ 		This can be useful to save/restore a user's character search
Karsten Hopp 9f44d6
+ 		from a script: >
Karsten Hopp 9f44d6
+ 			:let prevsearch = getcharsearch()
Karsten Hopp 9f44d6
+ 			:" Perform a command which clobbers user's search
Karsten Hopp 9f44d6
+ 			:call setcharsearch(prevsearch)
Karsten Hopp 9f44d6
+ <		Also see |getcharsearch()|.
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
  setcmdpos({pos})					*setcmdpos()*
Karsten Hopp 9f44d6
  		Set the cursor position in the command line to byte position
Karsten Hopp 9f44d6
  		{pos}.	The first position is 1.
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/eval.c	2015-07-21 15:48:13.585517990 +0200
Karsten Hopp 9f44d6
--- src/eval.c	2015-08-11 13:34:03.374392656 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 555,560 ****
Karsten Hopp 9f44d6
--- 555,561 ----
Karsten Hopp 9f44d6
  static void f_getbufvar __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_getchar __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_getcharmod __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
+ static void f_getcharsearch __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_getcmdline __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_getcmdpos __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_getcmdtype __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 688,693 ****
Karsten Hopp 9f44d6
--- 689,695 ----
Karsten Hopp 9f44d6
  static void f_server2client __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_serverlist __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_setbufvar __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
+ static void f_setcharsearch __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_setcmdpos __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_setline __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
  static void f_setloclist __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 8149,8154 ****
Karsten Hopp 9f44d6
--- 8151,8157 ----
Karsten Hopp 9f44d6
      {"getbufvar",	2, 3, f_getbufvar},
Karsten Hopp 9f44d6
      {"getchar",		0, 1, f_getchar},
Karsten Hopp 9f44d6
      {"getcharmod",	0, 0, f_getcharmod},
Karsten Hopp 9f44d6
+     {"getcharsearch",	0, 0, f_getcharsearch},
Karsten Hopp 9f44d6
      {"getcmdline",	0, 0, f_getcmdline},
Karsten Hopp 9f44d6
      {"getcmdpos",	0, 0, f_getcmdpos},
Karsten Hopp 9f44d6
      {"getcmdtype",	0, 0, f_getcmdtype},
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 8285,8290 ****
Karsten Hopp 9f44d6
--- 8288,8294 ----
Karsten Hopp 9f44d6
      {"server2client",	2, 2, f_server2client},
Karsten Hopp 9f44d6
      {"serverlist",	0, 0, f_serverlist},
Karsten Hopp 9f44d6
      {"setbufvar",	3, 3, f_setbufvar},
Karsten Hopp 9f44d6
+     {"setcharsearch",	1, 1, f_setcharsearch},
Karsten Hopp 9f44d6
      {"setcmdpos",	1, 1, f_setcmdpos},
Karsten Hopp 9f44d6
      {"setline",		2, 2, f_setline},
Karsten Hopp 9f44d6
      {"setloclist",	2, 3, f_setloclist},
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 11664,11669 ****
Karsten Hopp 9f44d6
--- 11668,11691 ----
Karsten Hopp 9f44d6
  }
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
  /*
Karsten Hopp 9f44d6
+  * "getcharsearch()" function
Karsten Hopp 9f44d6
+  */
Karsten Hopp 9f44d6
+     static void
Karsten Hopp 9f44d6
+ f_getcharsearch(argvars, rettv)
Karsten Hopp 9f44d6
+     typval_T	*argvars UNUSED;
Karsten Hopp 9f44d6
+     typval_T	*rettv;
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+     if (rettv_dict_alloc(rettv) != FAIL)
Karsten Hopp 9f44d6
+     {
Karsten Hopp 9f44d6
+ 	dict_T *dict = rettv->vval.v_dict;
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ 	dict_add_nr_str(dict, "char", 0L, last_csearch());
Karsten Hopp 9f44d6
+ 	dict_add_nr_str(dict, "forward", last_csearch_forward(), NULL);
Karsten Hopp 9f44d6
+ 	dict_add_nr_str(dict, "until", last_csearch_until(), NULL);
Karsten Hopp 9f44d6
+     }
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ /*
Karsten Hopp 9f44d6
   * "getcmdline()" function
Karsten Hopp 9f44d6
   */
Karsten Hopp 9f44d6
      static void
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 17004,17009 ****
Karsten Hopp 9f44d6
--- 17026,17073 ----
Karsten Hopp 9f44d6
      }
Karsten Hopp 9f44d6
  }
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
+     static void
Karsten Hopp 9f44d6
+ f_setcharsearch(argvars, rettv)
Karsten Hopp 9f44d6
+     typval_T	*argvars;
Karsten Hopp 9f44d6
+     typval_T	*rettv UNUSED;
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+     dict_T	*d;
Karsten Hopp 9f44d6
+     dictitem_T	*di;
Karsten Hopp 9f44d6
+     char_u	*csearch;
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     if (argvars[0].v_type != VAR_DICT)
Karsten Hopp 9f44d6
+     {
Karsten Hopp 9f44d6
+ 	EMSG(_(e_dictreq));
Karsten Hopp 9f44d6
+ 	return;
Karsten Hopp 9f44d6
+     }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     if ((d = argvars[0].vval.v_dict) != NULL)
Karsten Hopp 9f44d6
+     {
Karsten Hopp 9f44d6
+ 	csearch = get_dict_string(d, (char_u *)"char", FALSE);
Karsten Hopp 9f44d6
+ 	if (csearch != NULL)
Karsten Hopp 9f44d6
+ 	{
Karsten Hopp 9f44d6
+ 	    if (enc_utf8)
Karsten Hopp 9f44d6
+ 	    {
Karsten Hopp 9f44d6
+ 		int pcc[MAX_MCO];
Karsten Hopp 9f44d6
+ 		int c = utfc_ptr2char(csearch, pcc);
Karsten Hopp 9f44d6
+ 		set_last_csearch(c, csearch, utfc_ptr2len(csearch));
Karsten Hopp 9f44d6
+ 	    }
Karsten Hopp 9f44d6
+ 	    else
Karsten Hopp 9f44d6
+ 		set_last_csearch(mb_ptr2char(csearch),
Karsten Hopp 9f44d6
+ 						csearch, mb_ptr2len(csearch));
Karsten Hopp 9f44d6
+ 	}
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ 	di = dict_find(d, (char_u *)"forward", -1);
Karsten Hopp 9f44d6
+ 	if (di != NULL)
Karsten Hopp 9f44d6
+ 	    set_csearch_direction(get_tv_number(&di->di_tv)
Karsten Hopp 9f44d6
+ 							? FORWARD : BACKWARD);
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ 	di = dict_find(d, (char_u *)"until", -1);
Karsten Hopp 9f44d6
+ 	if (di != NULL)
Karsten Hopp 9f44d6
+ 	    set_csearch_until(!!get_tv_number(&di->di_tv));
Karsten Hopp 9f44d6
+     }
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
  /*
Karsten Hopp 9f44d6
   * "setcmdpos()" function
Karsten Hopp 9f44d6
   */
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/proto/search.pro	2014-12-13 03:17:07.465046539 +0100
Karsten Hopp 9f44d6
--- src/proto/search.pro	2015-08-11 13:32:31.651435327 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 8,13 ****
Karsten Hopp 9f44d6
--- 8,19 ----
Karsten Hopp 9f44d6
  void free_search_patterns __ARGS((void));
Karsten Hopp 9f44d6
  int ignorecase __ARGS((char_u *pat));
Karsten Hopp 9f44d6
  int pat_has_uppercase __ARGS((char_u *pat));
Karsten Hopp 9f44d6
+ char_u *last_csearch __ARGS((void));
Karsten Hopp 9f44d6
+ int last_csearch_forward __ARGS((void));
Karsten Hopp 9f44d6
+ int last_csearch_until __ARGS((void));
Karsten Hopp 9f44d6
+ void set_last_csearch __ARGS((int c, char_u *s, int len));
Karsten Hopp 9f44d6
+ void set_csearch_direction __ARGS((int cdir));
Karsten Hopp 9f44d6
+ void set_csearch_until __ARGS((int t_cmd));
Karsten Hopp 9f44d6
  char_u *last_search_pat __ARGS((void));
Karsten Hopp 9f44d6
  void reset_search_dir __ARGS((void));
Karsten Hopp 9f44d6
  void set_last_search_pat __ARGS((char_u *s, int idx, int magic, int setlast));
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/search.c	2015-07-28 21:17:31.518069428 +0200
Karsten Hopp 9f44d6
--- src/search.c	2015-08-11 14:05:25.425003350 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 89,94 ****
Karsten Hopp 9f44d6
--- 89,102 ----
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
  static int last_idx = 0;	/* index in spats[] for RE_LAST */
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
+ static char_u lastc[2] = {NUL, NUL};	/* last character searched for */
Karsten Hopp 9f44d6
+ static int lastcdir = FORWARD;		/* last direction of character search */
Karsten Hopp 9f44d6
+ static int last_t_cmd = TRUE;		/* last search t_cmd */
Karsten Hopp 9f44d6
+ #ifdef FEAT_MBYTE
Karsten Hopp 9f44d6
+ static char_u	lastc_bytes[MB_MAXBYTES + 1];
Karsten Hopp 9f44d6
+ static int	lastc_bytelen = 1;	/* >1 for multi-byte char */
Karsten Hopp 9f44d6
+ #endif
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
  #if defined(FEAT_AUTOCMD) || defined(FEAT_EVAL) || defined(PROTO)
Karsten Hopp 9f44d6
  /* copy of spats[], for keeping the search patterns while executing autocmds */
Karsten Hopp 9f44d6
  static struct spat  saved_spats[2];
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 378,384 ****
Karsten Hopp 9f44d6
  }
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
  /*
Karsten Hopp 9f44d6
!  * Return TRUE if patter "pat" has an uppercase character.
Karsten Hopp 9f44d6
   */
Karsten Hopp 9f44d6
      int
Karsten Hopp 9f44d6
  pat_has_uppercase(pat)
Karsten Hopp 9f44d6
--- 386,392 ----
Karsten Hopp 9f44d6
  }
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
  /*
Karsten Hopp 9f44d6
!  * Return TRUE if pattern "pat" has an uppercase character.
Karsten Hopp 9f44d6
   */
Karsten Hopp 9f44d6
      int
Karsten Hopp 9f44d6
  pat_has_uppercase(pat)
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 419,424 ****
Karsten Hopp 9f44d6
--- 427,484 ----
Karsten Hopp 9f44d6
  }
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
      char_u *
Karsten Hopp 9f44d6
+ last_csearch()
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+ #ifdef FEAT_MBYTE
Karsten Hopp 9f44d6
+     return lastc_bytes;
Karsten Hopp 9f44d6
+ #else
Karsten Hopp 9f44d6
+     return lastc;
Karsten Hopp 9f44d6
+ #endif
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     int
Karsten Hopp 9f44d6
+ last_csearch_forward()
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+     return lastcdir == FORWARD;
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     int
Karsten Hopp 9f44d6
+ last_csearch_until()
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+     return last_t_cmd == TRUE;
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     void
Karsten Hopp 9f44d6
+ set_last_csearch(c, s, len)
Karsten Hopp 9f44d6
+     int		c;
Karsten Hopp 9f44d6
+     char_u	*s;
Karsten Hopp 9f44d6
+     int		len;
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+     *lastc = c;
Karsten Hopp 9f44d6
+ #ifdef FEAT_MBYTE
Karsten Hopp 9f44d6
+     lastc_bytelen = len;
Karsten Hopp 9f44d6
+     if (len)
Karsten Hopp 9f44d6
+ 	memcpy(lastc_bytes, s, len);
Karsten Hopp 9f44d6
+     else
Karsten Hopp 9f44d6
+ 	vim_memset(lastc_bytes, 0, sizeof(lastc_bytes));
Karsten Hopp 9f44d6
+ #endif
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     void
Karsten Hopp 9f44d6
+ set_csearch_direction(cdir)
Karsten Hopp 9f44d6
+     int cdir;
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+     lastcdir = cdir;
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     void
Karsten Hopp 9f44d6
+ set_csearch_until(t_cmd)
Karsten Hopp 9f44d6
+     int t_cmd;
Karsten Hopp 9f44d6
+ {
Karsten Hopp 9f44d6
+     last_t_cmd = t_cmd;
Karsten Hopp 9f44d6
+ }
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+     char_u *
Karsten Hopp 9f44d6
  last_search_pat()
Karsten Hopp 9f44d6
  {
Karsten Hopp 9f44d6
      return spats[last_idx].pat;
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 1559,1605 ****
Karsten Hopp 9f44d6
      int			c = cap->nchar;	/* char to search for */
Karsten Hopp 9f44d6
      int			dir = cap->arg;	/* TRUE for searching forward */
Karsten Hopp 9f44d6
      long		count = cap->count1;	/* repeat count */
Karsten Hopp 9f44d6
-     static int		lastc = NUL;	/* last character searched for */
Karsten Hopp 9f44d6
-     static int		lastcdir;	/* last direction of character search */
Karsten Hopp 9f44d6
-     static int		last_t_cmd;	/* last search t_cmd */
Karsten Hopp 9f44d6
      int			col;
Karsten Hopp 9f44d6
      char_u		*p;
Karsten Hopp 9f44d6
      int			len;
Karsten Hopp 9f44d6
      int			stop = TRUE;
Karsten Hopp 9f44d6
- #ifdef FEAT_MBYTE
Karsten Hopp 9f44d6
-     static char_u	bytes[MB_MAXBYTES + 1];
Karsten Hopp 9f44d6
-     static int		bytelen = 1;	/* >1 for multi-byte char */
Karsten Hopp 9f44d6
- #endif
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
      if (c != NUL)	/* normal search: remember args for repeat */
Karsten Hopp 9f44d6
      {
Karsten Hopp 9f44d6
  	if (!KeyStuffed)    /* don't remember when redoing */
Karsten Hopp 9f44d6
  	{
Karsten Hopp 9f44d6
! 	    lastc = c;
Karsten Hopp 9f44d6
! 	    lastcdir = dir;
Karsten Hopp 9f44d6
! 	    last_t_cmd = t_cmd;
Karsten Hopp 9f44d6
  #ifdef FEAT_MBYTE
Karsten Hopp 9f44d6
! 	    bytelen = (*mb_char2bytes)(c, bytes);
Karsten Hopp 9f44d6
  	    if (cap->ncharC1 != 0)
Karsten Hopp 9f44d6
  	    {
Karsten Hopp 9f44d6
! 		bytelen += (*mb_char2bytes)(cap->ncharC1, bytes + bytelen);
Karsten Hopp 9f44d6
  		if (cap->ncharC2 != 0)
Karsten Hopp 9f44d6
! 		    bytelen += (*mb_char2bytes)(cap->ncharC2, bytes + bytelen);
Karsten Hopp 9f44d6
  	    }
Karsten Hopp 9f44d6
  #endif
Karsten Hopp 9f44d6
  	}
Karsten Hopp 9f44d6
      }
Karsten Hopp 9f44d6
      else		/* repeat previous search */
Karsten Hopp 9f44d6
      {
Karsten Hopp 9f44d6
! 	if (lastc == NUL)
Karsten Hopp 9f44d6
  	    return FAIL;
Karsten Hopp 9f44d6
  	if (dir)	/* repeat in opposite direction */
Karsten Hopp 9f44d6
  	    dir = -lastcdir;
Karsten Hopp 9f44d6
  	else
Karsten Hopp 9f44d6
  	    dir = lastcdir;
Karsten Hopp 9f44d6
  	t_cmd = last_t_cmd;
Karsten Hopp 9f44d6
! 	c = lastc;
Karsten Hopp 9f44d6
! 	/* For multi-byte re-use last bytes[] and bytelen. */
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
  	/* Force a move of at least one char, so ";" and "," will move the
Karsten Hopp 9f44d6
  	 * cursor, even if the cursor is right in front of char we are looking
Karsten Hopp 9f44d6
--- 1619,1660 ----
Karsten Hopp 9f44d6
      int			c = cap->nchar;	/* char to search for */
Karsten Hopp 9f44d6
      int			dir = cap->arg;	/* TRUE for searching forward */
Karsten Hopp 9f44d6
      long		count = cap->count1;	/* repeat count */
Karsten Hopp 9f44d6
      int			col;
Karsten Hopp 9f44d6
      char_u		*p;
Karsten Hopp 9f44d6
      int			len;
Karsten Hopp 9f44d6
      int			stop = TRUE;
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
      if (c != NUL)	/* normal search: remember args for repeat */
Karsten Hopp 9f44d6
      {
Karsten Hopp 9f44d6
  	if (!KeyStuffed)    /* don't remember when redoing */
Karsten Hopp 9f44d6
  	{
Karsten Hopp 9f44d6
! 	    *lastc = c;
Karsten Hopp 9f44d6
! 	    set_csearch_direction(dir);
Karsten Hopp 9f44d6
! 	    set_csearch_until(t_cmd);
Karsten Hopp 9f44d6
  #ifdef FEAT_MBYTE
Karsten Hopp 9f44d6
! 	    lastc_bytelen = (*mb_char2bytes)(c, lastc_bytes);
Karsten Hopp 9f44d6
  	    if (cap->ncharC1 != 0)
Karsten Hopp 9f44d6
  	    {
Karsten Hopp 9f44d6
! 		lastc_bytelen += (*mb_char2bytes)(cap->ncharC1,
Karsten Hopp 9f44d6
! 			lastc_bytes + lastc_bytelen);
Karsten Hopp 9f44d6
  		if (cap->ncharC2 != 0)
Karsten Hopp 9f44d6
! 		    lastc_bytelen += (*mb_char2bytes)(cap->ncharC2,
Karsten Hopp 9f44d6
! 			    lastc_bytes + lastc_bytelen);
Karsten Hopp 9f44d6
  	    }
Karsten Hopp 9f44d6
  #endif
Karsten Hopp 9f44d6
  	}
Karsten Hopp 9f44d6
      }
Karsten Hopp 9f44d6
      else		/* repeat previous search */
Karsten Hopp 9f44d6
      {
Karsten Hopp 9f44d6
! 	if (*lastc == NUL)
Karsten Hopp 9f44d6
  	    return FAIL;
Karsten Hopp 9f44d6
  	if (dir)	/* repeat in opposite direction */
Karsten Hopp 9f44d6
  	    dir = -lastcdir;
Karsten Hopp 9f44d6
  	else
Karsten Hopp 9f44d6
  	    dir = lastcdir;
Karsten Hopp 9f44d6
  	t_cmd = last_t_cmd;
Karsten Hopp 9f44d6
! 	c = *lastc;
Karsten Hopp 9f44d6
! 	/* For multi-byte re-use last lastc_bytes[] and lastc_bytelen. */
Karsten Hopp 9f44d6
  
Karsten Hopp 9f44d6
  	/* Force a move of at least one char, so ";" and "," will move the
Karsten Hopp 9f44d6
  	 * cursor, even if the cursor is right in front of char we are looking
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 1636,1649 ****
Karsten Hopp 9f44d6
  			return FAIL;
Karsten Hopp 9f44d6
  		    col -= (*mb_head_off)(p, p + col - 1) + 1;
Karsten Hopp 9f44d6
  		}
Karsten Hopp 9f44d6
! 		if (bytelen == 1)
Karsten Hopp 9f44d6
  		{
Karsten Hopp 9f44d6
  		    if (p[col] == c && stop)
Karsten Hopp 9f44d6
  			break;
Karsten Hopp 9f44d6
  		}
Karsten Hopp 9f44d6
  		else
Karsten Hopp 9f44d6
  		{
Karsten Hopp 9f44d6
! 		    if (vim_memcmp(p + col, bytes, bytelen) == 0 && stop)
Karsten Hopp 9f44d6
  			break;
Karsten Hopp 9f44d6
  		}
Karsten Hopp 9f44d6
  		stop = TRUE;
Karsten Hopp 9f44d6
--- 1691,1704 ----
Karsten Hopp 9f44d6
  			return FAIL;
Karsten Hopp 9f44d6
  		    col -= (*mb_head_off)(p, p + col - 1) + 1;
Karsten Hopp 9f44d6
  		}
Karsten Hopp 9f44d6
! 		if (lastc_bytelen == 1)
Karsten Hopp 9f44d6
  		{
Karsten Hopp 9f44d6
  		    if (p[col] == c && stop)
Karsten Hopp 9f44d6
  			break;
Karsten Hopp 9f44d6
  		}
Karsten Hopp 9f44d6
  		else
Karsten Hopp 9f44d6
  		{
Karsten Hopp 9f44d6
! 		    if (vim_memcmp(p + col, lastc_bytes, lastc_bytelen) == 0 && stop)
Karsten Hopp 9f44d6
  			break;
Karsten Hopp 9f44d6
  		}
Karsten Hopp 9f44d6
  		stop = TRUE;
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 1671,1678 ****
Karsten Hopp 9f44d6
  	if (has_mbyte)
Karsten Hopp 9f44d6
  	{
Karsten Hopp 9f44d6
  	    if (dir < 0)
Karsten Hopp 9f44d6
! 		/* Landed on the search char which is bytelen long */
Karsten Hopp 9f44d6
! 		col += bytelen - 1;
Karsten Hopp 9f44d6
  	    else
Karsten Hopp 9f44d6
  		/* To previous char, which may be multi-byte. */
Karsten Hopp 9f44d6
  		col -= (*mb_head_off)(p, p + col);
Karsten Hopp 9f44d6
--- 1726,1733 ----
Karsten Hopp 9f44d6
  	if (has_mbyte)
Karsten Hopp 9f44d6
  	{
Karsten Hopp 9f44d6
  	    if (dir < 0)
Karsten Hopp 9f44d6
! 		/* Landed on the search char which is lastc_bytelen long */
Karsten Hopp 9f44d6
! 		col += lastc_bytelen - 1;
Karsten Hopp 9f44d6
  	    else
Karsten Hopp 9f44d6
  		/* To previous char, which may be multi-byte. */
Karsten Hopp 9f44d6
  		col -= (*mb_head_off)(p, p + col);
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/test_charsearch.in	2015-08-11 14:22:29.713361737 +0200
Karsten Hopp 9f44d6
--- src/testdir/test_charsearch.in	2015-08-11 14:12:34.048131520 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 0 ****
Karsten Hopp 9f44d6
--- 1,25 ----
Karsten Hopp 9f44d6
+ Test for character searches
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ STARTTEST
Karsten Hopp 9f44d6
+ :so small.vim
Karsten Hopp 9f44d6
+ :" check that "fe" and ";" work
Karsten Hopp 9f44d6
+ /^X
Karsten Hopp 9f44d6
+ ylfep;;p,,p:
Karsten Hopp 9f44d6
+ :" check that save/restore works
Karsten Hopp 9f44d6
+ /^Y
Karsten Hopp 9f44d6
+ ylfep:let csave = getcharsearch()
Karsten Hopp 9f44d6
+ fip:call setcharsearch(csave)
Karsten Hopp 9f44d6
+ ;p;p:
Karsten Hopp 9f44d6
+ :" check that setcharsearch() changes the settins.
Karsten Hopp 9f44d6
+ /^Z
Karsten Hopp 9f44d6
+ ylfep:call setcharsearch({'char': 'k'})
Karsten Hopp 9f44d6
+ ;p:call setcharsearch({'forward': 0})
Karsten Hopp 9f44d6
+ $;p:call setcharseearch({'until'}: 1})
Karsten Hopp 9f44d6
+ ;;p:
Karsten Hopp 9f44d6
+ :/^X/,$w! test.out
Karsten Hopp 9f44d6
+ :qa!
Karsten Hopp 9f44d6
+ ENDTEST
Karsten Hopp 9f44d6
+ 
Karsten Hopp 9f44d6
+ Xabcdefghijkemnopqretuvwxyz
Karsten Hopp 9f44d6
+ Yabcdefghijkemnopqretuvwxyz
Karsten Hopp 9f44d6
+ Zabcdefghijkemnokqretkvwxyz
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/test_charsearch.ok	2015-08-11 14:22:29.717361691 +0200
Karsten Hopp 9f44d6
--- src/testdir/test_charsearch.ok	2015-08-11 13:59:20.253153843 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 0 ****
Karsten Hopp 9f44d6
--- 1,3 ----
Karsten Hopp 9f44d6
+ XabcdeXfghijkeXmnopqreXtuvwxyz
Karsten Hopp 9f44d6
+ YabcdeYfghiYjkeYmnopqreYtuvwxyz
Karsten Hopp 9f44d6
+ ZabcdeZfghijkZemnokZqretkZvwxyz
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/Makefile	2015-07-21 15:48:13.593517912 +0200
Karsten Hopp 9f44d6
--- src/testdir/Makefile	2015-08-11 13:46:04.386197622 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 39,44 ****
Karsten Hopp 9f44d6
--- 39,45 ----
Karsten Hopp 9f44d6
  		test_autoformat_join.out \
Karsten Hopp 9f44d6
  		test_breakindent.out \
Karsten Hopp 9f44d6
  		test_changelist.out \
Karsten Hopp 9f44d6
+ 		test_charsearch.out \
Karsten Hopp 9f44d6
  		test_close_count.out \
Karsten Hopp 9f44d6
  		test_command_count.out \
Karsten Hopp 9f44d6
  		test_erasebackword.out \
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/Make_amiga.mak	2015-07-21 15:48:13.589517950 +0200
Karsten Hopp 9f44d6
--- src/testdir/Make_amiga.mak	2015-08-11 13:45:21.702682710 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 42,47 ****
Karsten Hopp 9f44d6
--- 42,48 ----
Karsten Hopp 9f44d6
  		test_autoformat_join.out \
Karsten Hopp 9f44d6
  		test_breakindent.out \
Karsten Hopp 9f44d6
  		test_changelist.out \
Karsten Hopp 9f44d6
+ 		test_charsearch.out \
Karsten Hopp 9f44d6
  		test_close_count.out \
Karsten Hopp 9f44d6
  		test_command_count.out \
Karsten Hopp 9f44d6
  		test_erasebackword.out \
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 194,199 ****
Karsten Hopp 9f44d6
--- 195,201 ----
Karsten Hopp 9f44d6
  test_autoformat_join.out: test_autoformat_join.in
Karsten Hopp 9f44d6
  test_breakindent.out: test_breakindent.in
Karsten Hopp 9f44d6
  test_changelist.out: test_changelist.in
Karsten Hopp 9f44d6
+ test_charsearch.out: test_charsearch.in
Karsten Hopp 9f44d6
  test_close_count.out: test_close_count.in
Karsten Hopp 9f44d6
  test_command_count.out: test_command_count.in
Karsten Hopp 9f44d6
  test_erasebackword.out: test_erasebackword.in
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/Make_dos.mak	2015-07-21 15:48:13.589517950 +0200
Karsten Hopp 9f44d6
--- src/testdir/Make_dos.mak	2015-08-11 13:45:29.306596293 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 41,46 ****
Karsten Hopp 9f44d6
--- 41,47 ----
Karsten Hopp 9f44d6
  		test_autoformat_join.out \
Karsten Hopp 9f44d6
  		test_breakindent.out \
Karsten Hopp 9f44d6
  		test_changelist.out \
Karsten Hopp 9f44d6
+ 		test_charsearch.out \
Karsten Hopp 9f44d6
  		test_close_count.out \
Karsten Hopp 9f44d6
  		test_command_count.out \
Karsten Hopp 9f44d6
  		test_erasebackword.out \
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/Make_ming.mak	2015-07-21 15:48:13.589517950 +0200
Karsten Hopp 9f44d6
--- src/testdir/Make_ming.mak	2015-08-11 13:45:35.742523150 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 63,68 ****
Karsten Hopp 9f44d6
--- 63,69 ----
Karsten Hopp 9f44d6
  		test_autoformat_join.out \
Karsten Hopp 9f44d6
  		test_breakindent.out \
Karsten Hopp 9f44d6
  		test_changelist.out \
Karsten Hopp 9f44d6
+ 		test_charsearch.out \
Karsten Hopp 9f44d6
  		test_close_count.out \
Karsten Hopp 9f44d6
  		test_command_count.out \
Karsten Hopp 9f44d6
  		test_erasebackword.out \
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/Make_os2.mak	2015-07-21 15:48:13.593517912 +0200
Karsten Hopp 9f44d6
--- src/testdir/Make_os2.mak	2015-08-11 14:23:59.096345955 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 43,48 ****
Karsten Hopp 9f44d6
--- 43,49 ----
Karsten Hopp 9f44d6
  		test_autoformat_join.out \
Karsten Hopp 9f44d6
  		test_breakindent.out \
Karsten Hopp 9f44d6
  		test_changelist.out \
Karsten Hopp 9f44d6
+ 		test_charsearch.out \
Karsten Hopp 9f44d6
  		test_close_count.out \
Karsten Hopp 9f44d6
  		test_command_count.out \
Karsten Hopp 9f44d6
  		test_erasebackword.out \
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/testdir/Make_vms.mms	2015-07-21 15:48:13.593517912 +0200
Karsten Hopp 9f44d6
--- src/testdir/Make_vms.mms	2015-08-11 14:24:20.772099626 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 4,10 ****
Karsten Hopp 9f44d6
  # Authors:	Zoltan Arpadffy, <arpadffy@polarhome.com>
Karsten Hopp 9f44d6
  #		Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
Karsten Hopp 9f44d6
  #
Karsten Hopp 9f44d6
! # Last change:  2015 Jul 17
Karsten Hopp 9f44d6
  #
Karsten Hopp 9f44d6
  # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
Karsten Hopp 9f44d6
  # Edit the lines in the Configuration section below to select.
Karsten Hopp 9f44d6
--- 4,10 ----
Karsten Hopp 9f44d6
  # Authors:	Zoltan Arpadffy, <arpadffy@polarhome.com>
Karsten Hopp 9f44d6
  #		Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
Karsten Hopp 9f44d6
  #
Karsten Hopp 9f44d6
! # Last change:  2015 Aug 11
Karsten Hopp 9f44d6
  #
Karsten Hopp 9f44d6
  # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
Karsten Hopp 9f44d6
  # Edit the lines in the Configuration section below to select.
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 102,107 ****
Karsten Hopp 9f44d6
--- 102,108 ----
Karsten Hopp 9f44d6
  	 test_autoformat_join.out \
Karsten Hopp 9f44d6
  	 test_breakindent.out \
Karsten Hopp 9f44d6
  	 test_changelist.out \
Karsten Hopp 9f44d6
+ 	 test_charsearch.out \
Karsten Hopp 9f44d6
  	 test_close_count.out \
Karsten Hopp 9f44d6
  	 test_command_count.out \
Karsten Hopp 9f44d6
  	 test_erasebackword.out \
Karsten Hopp 9f44d6
*** ../vim-7.4.812/src/version.c	2015-08-08 18:23:41.219566256 +0200
Karsten Hopp 9f44d6
--- src/version.c	2015-08-11 13:22:49.398054460 +0200
Karsten Hopp 9f44d6
***************
Karsten Hopp 9f44d6
*** 743,744 ****
Karsten Hopp 9f44d6
--- 743,746 ----
Karsten Hopp 9f44d6
  {   /* Add new patch number below this line */
Karsten Hopp 9f44d6
+ /**/
Karsten Hopp 9f44d6
+     813,
Karsten Hopp 9f44d6
  /**/
Karsten Hopp 9f44d6
Karsten Hopp 9f44d6
-- 
Karsten Hopp 9f44d6
`When any government, or any church for that matter, undertakes to say to
Karsten Hopp 9f44d6
 its subjects, "This you may not read, this you must not see, this you are
Karsten Hopp 9f44d6
 forbidden to know," the end result is tyranny and oppression no matter how
Karsten Hopp 9f44d6
 holy the motives' -- Robert A Heinlein, "If this goes on --"
Karsten Hopp 9f44d6
Karsten Hopp 9f44d6
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 9f44d6
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 9f44d6
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 9f44d6
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///