about summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2014-12-08 17:23:23 +0100
committerOliver Kiddle <opk@zsh.org>2014-12-08 17:24:48 +0100
commit88f4e24d4c42de1072898cd0e26e3d43c7de448c (patch)
tree326ea242e10e31ece5279ae9049abb19f01a1574 /Src/Zle
parent53e44daeba8481858cded683a780841085f36988 (diff)
downloadzsh-88f4e24d4c42de1072898cd0e26e3d43c7de448c.tar.gz
zsh-88f4e24d4c42de1072898cd0e26e3d43c7de448c.tar.xz
zsh-88f4e24d4c42de1072898cd0e26e3d43c7de448c.zip
33924: allow vi line/characterwise mode to be forced
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/iwidgets.list2
-rw-r--r--Src/Zle/zle.h2
-rw-r--r--Src/Zle/zle_move.c12
-rw-r--r--Src/Zle/zle_vi.c13
4 files changed, 26 insertions, 3 deletions
diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list
index 1a664e5e8..40750221e 100644
--- a/Src/Zle/iwidgets.list
+++ b/Src/Zle/iwidgets.list
@@ -156,7 +156,7 @@
 "vi-forward-word-end", viforwardwordend, 0
 "vi-goto-column", vigotocolumn, 0
 "vi-goto-mark", vigotomark, 0
-"vi-goto-mark-line", vigotomarkline, 0
+"vi-goto-mark-line", vigotomarkline, ZLE_LINEMOVE
 "vi-history-search-backward", vihistorysearchbackward, 0
 "vi-history-search-forward", vihistorysearchforward, 0
 "vi-indent", viindent, ZLE_LASTCOL
diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h
index 8a85ee342..a46b52ded 100644
--- a/Src/Zle/zle.h
+++ b/Src/Zle/zle.h
@@ -243,6 +243,8 @@ struct modifier {
 #define MOD_VIAPP (1<<3)   /* appending to the vi cut buffer */
 #define MOD_NEG   (1<<4)   /* last command was negate argument */
 #define MOD_NULL  (1<<5)   /* throw away text for the vi cut buffer */
+#define MOD_CHAR  (1<<6)   /* force character-wise movement */
+#define MOD_LINE  (1<<7)   /* force line-wise movement */
 
 /* current modifier status */
 
diff --git a/Src/Zle/zle_move.c b/Src/Zle/zle_move.c
index 939cfb1d0..d751c4333 100644
--- a/Src/Zle/zle_move.c
+++ b/Src/Zle/zle_move.c
@@ -511,6 +511,12 @@ exchangepointandmark(UNUSED(char **args))
 int
 visualmode(UNUSED(char **args))
 {
+    if (virangeflag) {
+	prefixflag = 1;
+	zmod.flags &= ~MOD_LINE;
+	zmod.flags |= MOD_CHAR;
+	return 0;
+    }
     switch (region_active) {
     case 1:
 	region_active = 0;
@@ -529,6 +535,12 @@ visualmode(UNUSED(char **args))
 int
 visuallinemode(UNUSED(char **args))
 {
+    if (virangeflag) {
+	prefixflag = 1;
+	zmod.flags &= ~MOD_CHAR;
+	zmod.flags |= MOD_LINE;
+	return 0;
+    }
     switch (region_active) {
     case 2:
 	region_active = 0;
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 249e38f15..1a11ca7d5 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -259,15 +259,24 @@ getvirange(int wf)
     /* Was it a line-oriented move?  If so, the command will have set *
      * the vilinerange flag.  In this case, entire lines are taken,   *
      * rather than just the sequence of characters delimited by pos   *
-     * and zlecs.  The terminating newline is left out of the range,     *
+     * and zlecs.  The terminating newline is left out of the range,  *
      * which the real command must deal with appropriately.  At this  *
      * point we just need to make the range encompass entire lines.   */
-    if(vilinerange) {
+    vilinerange = (zmod.flags & MOD_LINE) ||
+	    (vilinerange && !(zmod.flags & MOD_CHAR));
+    if (vilinerange) {
 	int newcs = findbol();
 	lastcol = zlecs - newcs;
 	zlecs = pos;
 	pos = findeol();
 	zlecs = newcs;
+    } else if (!visual) {
+	/* for a character-wise move don't include a newline at the *
+	 * end of the range                                         */
+	int prev = pos;
+	DECPOS(prev);
+	if (zleline[prev] == ZWC('\n'))
+	    pos = prev;
     }
     return pos;
 }