about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2014-11-15 21:33:32 +0100
committerOliver Kiddle <opk@zsh.org>2014-11-15 21:33:32 +0100
commit1e934556f7a91cc15e78272763dab05ea16b6d78 (patch)
treee84a11d1a989bf1c551bd4a574fea5ad1b63a19b
parent13f3eec61dd806682141d45520fb4a08726831e0 (diff)
downloadzsh-1e934556f7a91cc15e78272763dab05ea16b6d78.tar.gz
zsh-1e934556f7a91cc15e78272763dab05ea16b6d78.tar.xz
zsh-1e934556f7a91cc15e78272763dab05ea16b6d78.zip
33697: new vim style vi-backward-word-end widgets
-rw-r--r--ChangeLog3
-rw-r--r--Doc/Zsh/zle.yo9
-rw-r--r--Src/Zle/iwidgets.list2
-rw-r--r--Src/Zle/zle_word.c67
4 files changed, 78 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 50b0fb881..f3ccb15f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2014-11-15  Oliver Kiddle  <opk@zsh.org>
 
+	* 33697: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle_word.c:
+	new vim style vi-backward-word-end widgets
+
 	* 33696: Doc/Zsh/zle.yo, Src/Zle/iwidgets.list, Src/Zle/zle_hist.c:
 	simple up/down line widgets that don't go through history lines
 
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 854510fa1..6fe7c9bf2 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -1049,6 +1049,11 @@ item(tt(vi-backward-blank-word) (unbound) (B) (unbound))(
 Move backward one word, where a word is defined as a series of
 non-blank characters.
 )
+tindex(vi-backward-blank-word-end)
+item(tt(vi-backward-blank-word-end) (unbound) (unbound) (unbound))(
+Move to the end of the previous word, where a word is defined as a
+series of non-blank characters.
+)
 tindex(backward-char)
 item(tt(backward-char) (^B ESC-[D) (unbound) (unbound))(
 Move backward one character.
@@ -1069,6 +1074,10 @@ tindex(vi-backward-word)
 item(tt(vi-backward-word) (unbound) (b) (unbound))(
 Move to the beginning of the previous word, vi-style.
 )
+tindex(vi-backward-word-end)
+item(tt(vi-backward-word-end) (unbound) (unbound) (unbound))(
+Move to the end of the previous word, vi-style.
+)
 tindex(beginning-of-line)
 item(tt(beginning-of-line) (^A) (unbound) (unbound))(
 Move to the beginning of the line.  If already at the beginning
diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list
index 0401397e1..a2bad5aa9 100644
--- a/Src/Zle/iwidgets.list
+++ b/Src/Zle/iwidgets.list
@@ -123,6 +123,8 @@
 "vi-backward-delete-char", vibackwarddeletechar, ZLE_KEEPSUFFIX
 "vi-backward-kill-word", vibackwardkillword, ZLE_KEEPSUFFIX
 "vi-backward-word", vibackwardword, 0
+"vi-backward-word-end", vibackwardwordend, 0
+"vi-backward-blank-word-end", vibackwardblankwordend, 0
 "vi-beginning-of-line", vibeginningofline, 0
 "vi-caps-lock-panic", vicapslockpanic, ZLE_LASTCOL
 "vi-change", vichange, ZLE_LASTCOL
diff --git a/Src/Zle/zle_word.c b/Src/Zle/zle_word.c
index e59304ecd..301b18d4a 100644
--- a/Src/Zle/zle_word.c
+++ b/Src/Zle/zle_word.c
@@ -148,8 +148,13 @@ viforwardblankwordend(UNUSED(char **args))
 {
     int n = zmult;
 
-    if (n < 0)
-	return 1;
+    if (n < 0) {
+	int ret;
+	zmult = -n;
+	ret = viforwardblankwordend(args);
+	zmult = n;
+	return ret;
+    }
     while (n--) {
 	while (zlecs != zlell) {
 	    int pos = zlecs;
@@ -180,7 +185,7 @@ viforwardwordend(char **args)
     if (n < 0) {
 	int ret;
 	zmult = -n;
-	ret = backwardword(args);
+	ret = vibackwardwordend(args);
 	zmult = n;
 	return ret;
     }
@@ -336,6 +341,62 @@ vibackwardblankword(char **args)
 
 /**/
 int
+vibackwardwordend(char **args)
+{
+    int n = zmult;
+
+    if (n < 0) {
+	int ret;
+	zmult = -n;
+	ret = viforwardwordend(args);
+	zmult = n;
+	return ret;
+    }
+    while (n-- && zlecs > 1) {
+	int start = 0;
+	if (Z_vialnum(zleline[zlecs]))
+	    start = 1;
+	else if (!ZC_iblank(zleline[zlecs]))
+	    start = 2;
+	DECCS();
+	while (zlecs) {
+	    int same = (start != 1) && ZC_iblank(zleline[zlecs]);
+	    if (start)
+		same |= Z_vialnum(zleline[zlecs]);
+	    if (same == (start == 2))
+		break;
+	    DECCS();
+	}
+	while (zlecs && ZC_iblank(zleline[zlecs]))
+	    DECCS();
+    }
+    return 0;
+}
+
+/**/
+int
+vibackwardblankwordend(char **args)
+{
+    int n = zmult;
+
+    if (n < 0) {
+	int ret;
+	zmult = -n;
+	ret = viforwardblankwordend(args);
+	zmult = n;
+	return ret;
+    }
+    while (n--) {
+	while (zlecs && !ZC_iblank(zleline[zlecs]))
+	    DECCS();
+	while (zlecs && ZC_iblank(zleline[zlecs]))
+	    DECCS();
+    }
+    return 0;
+}
+
+/**/
+int
 emacsbackwardword(char **args)
 {
     int n = zmult;