Hi Bram!

On So, 22 Mai 2011, Bram Moolenaar wrote:

> 
> Christian Brabandt wrote:
> 
> > On So, 22 Mai 2011, Bram Moolenaar wrote:
> > 
> > > It's true that using ";" after a "t" command is currently close to
> > > useless.  Changing this would be backwards incompatible, but I doubt
> > > anyone would notice.  I hardly use ";" anyway.  Would there be any
> > > plugin that breaks?  I can't think of a reason why a plugin would rely on
> > > ";" not moving.
> > > 
> > > So I tend to think I would include such a patch.
> > 
> > Ok, here is the patch. I made it so that only including the ';' in 'cpo' 
> > would change the behaviour. If you don't want to introduce a new 'cpo' 
> > setting, I am fine with simply changing the current implementation. The 
> > comment should explain how it works.
> 
> Thanks.  I think the behavior should be default in 'nocompatible' mode.
> 
> Please add a test for the new behavior, and sticking to the old behavior
> when ';' is in 'cpo'.

Please find attached a new patch.

Funny thing is, it took me longer to create the test case then to write 
the patch ;)

regards,
Christian
-- 

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt
--- a/runtime/doc/motion.txt
+++ b/runtime/doc/motion.txt
@@ -269,11 +269,11 @@
 			{char} can be entered like with the |f| command.
 
 							*;*
-;			Repeat latest f, t, F or T [count] times.
+;			Repeat latest f, t, F or T [count] times. See |cpo-;|
 
 							*,*
 ,			Repeat latest f, t, F or T in opposite direction
-			[count] times.
+			[count] times. See also |cpo-;|
 
 							*gc*
 gc			move forward to next CamelCase char [count] times.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2117,6 +2117,12 @@
 								*cpo->*
 		>	When appending to a register, put a line break before
 			the appended text.
+								*cpo-;*
+		;	When using |,| or |;| to repeat the last |t| search
+			and the cursor is right in front of the searched
+			character, the cursor won't move. When not included,
+			the cursor would skip over it and jump to the
+			following occurence.
 
 	POSIX flags.  These are not included in the Vi default value, except
 	when $VIM_POSIX was set on startup. |posix|
diff --git a/src/option.h b/src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -169,10 +169,11 @@
 #define CPO_SUBPERCENT	'/'	/* % in :s string uses previous one */
 #define CPO_BACKSL	'\\'	/* \ is not special in [] */
 #define CPO_CHDIR	'.'	/* don't chdir if buffer is modified */
+#define CPO_SCOLON	';'	/* using ,/; will skip over char, if last t search landed in front of char */
 /* default values for Vim, Vi and POSIX */
 #define CPO_VIM		"aABceFs"
 #define CPO_VI		"aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>"
-#define CPO_ALL		"aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\\."
+#define CPO_ALL		"aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\\.;"
 
 /* characters for p_ww option: */
 #define WW_ALL		"bshl<>[],~"
diff --git a/src/search.c b/src/search.c
--- a/src/search.c
+++ b/src/search.c
@@ -1546,6 +1546,7 @@
     int			col;
     char_u		*p;
     int			len;
+    int                 stop = TRUE;
 #ifdef FEAT_MBYTE
     static char_u	bytes[MB_MAXBYTES];
     static int		bytelen = 1;	/* >1 for multi-byte char */
@@ -1580,6 +1581,11 @@
 	t_cmd = last_t_cmd;
 	c = lastc;
 	/* For multi-byte re-use last bytes[] and bytelen. */
+
+	/* force a move of at least one char, so ;/, will move the cursor,
+	 * even if the cursor is right in front of char we are looking at */
+	if (vim_strchr(p_cpo, CPO_SCOLON) == NULL && count == 1)
+	  stop = FALSE;
     }
 
     if (dir == BACKWARD)
@@ -1612,14 +1618,16 @@
 		}
 		if (bytelen == 1)
 		{
-		    if (p[col] == c)
+		    if (p[col] == c && stop)
 			break;
 		}
 		else
 		{
-		    if (vim_memcmp(p + col, bytes, bytelen) == 0)
+		    if (vim_memcmp(p + col, bytes, bytelen) == 0 && stop)
 			break;
 		}
+		if (!stop)
+		    stop = TRUE;
 	    }
 	}
 	else
@@ -1629,8 +1637,10 @@
 	    {
 		if ((col += dir) < 0 || col >= len)
 		    return FAIL;
-		if (p[col] == c)
+		if (p[col] == c && stop)
 		    break;
+		if (!stop)
+		    stop = TRUE;
 	    }
 	}
     }
diff --git a/src/testdir/Make_amiga.mak b/src/testdir/Make_amiga.mak
--- a/src/testdir/Make_amiga.mak
+++ b/src/testdir/Make_amiga.mak
@@ -28,7 +28,7 @@
 		test61.out test62.out test63.out test64.out test65.out \
 		test66.out test67.out test68.out test69.out test70.out \
 		test71.out test72.out test73.out test74.out test75.out \
-		test76.out test77.out
+		test76.out test77.out test78.out
 
 .SUFFIXES: .in .out
 
diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak
--- a/src/testdir/Make_dos.mak
+++ b/src/testdir/Make_dos.mak
@@ -28,7 +28,7 @@
 		test37.out test38.out test39.out test40.out test41.out \
 		test42.out test52.out test65.out test66.out test67.out \
 		test68.out test69.out test71.out test72.out test73.out \
-		test74.out test75.out test76.out test77.out
+		test74.out test75.out test76.out test77.out test78.out
 
 SCRIPTS32 =	test50.out test70.out
 
diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak
--- a/src/testdir/Make_ming.mak
+++ b/src/testdir/Make_ming.mak
@@ -48,7 +48,7 @@
 		test37.out test38.out test39.out test40.out test41.out \
 		test42.out test52.out test65.out test66.out test67.out \
 		test68.out test69.out test71.out test72.out test73.out \
-		test74.out test75.out test76.out test77.out
+		test74.out test75.out test76.out test77.out test78.out
 
 SCRIPTS32 =	test50.out test70.out
 
diff --git a/src/testdir/Make_os2.mak b/src/testdir/Make_os2.mak
--- a/src/testdir/Make_os2.mak
+++ b/src/testdir/Make_os2.mak
@@ -28,7 +28,7 @@
 		test61.out test62.out test63.out test64.out test65.out \
 		test66.out test67.out test68.out test69.out test70.out \
 		test71.out test72.out test73.out test74.out test75.out \
-		test76.out test77.out
+		test76.out test77.out test78.out
 
 .SUFFIXES: .in .out
 
diff --git a/src/testdir/Make_vms.mms b/src/testdir/Make_vms.mms
--- a/src/testdir/Make_vms.mms
+++ b/src/testdir/Make_vms.mms
@@ -75,7 +75,7 @@
 	 test61.out test62.out test63.out test64.out test65.out \
 	 test66.out test67.out test68.out test69.out \
 	 test71.out test72.out test74.out test75.out test76.out \
-	 test77.out
+	 test77.out test78.out
 
 # Known problems:
 # Test 30: a problem around mac format - unknown reason
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -25,7 +25,7 @@
 		test59.out test60.out test61.out test62.out test63.out \
 		test64.out test65.out test66.out test67.out test68.out \
 		test69.out test70.out test71.out test72.out test73.out \
-		test74.out test75.out test76.out test77.out
+		test74.out test75.out test76.out test77.out test78.out
 
 SCRIPTS_GUI = test16.out
 
diff --git a/src/testdir/test78.in b/src/testdir/test78.in
new file mode 100644
--- /dev/null
+++ b/src/testdir/test78.in
@@ -0,0 +1,14 @@
+Test for t movement command and 'cpo-;' setting
+
+STARTTEST
+:set nocompatible
+:set cpo-=;
+/firstline/
+j0tt;D:set cpo+=;
+j0;D:?firstline?+1,$w! test.out
+:qa!
+ENDTEST
+
+firstline
+one two three four
+one two three four
diff --git a/src/testdir/test78.ok b/src/testdir/test78.ok
new file mode 100644
--- /dev/null
+++ b/src/testdir/test78.ok
@@ -0,0 +1,2 @@
+one two
+one

Reply via email to