Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: vi-backward-word-end widgets
- X-seq: zsh-workers 33697
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: vi-backward-word-end widgets
- Date: Sat, 15 Nov 2014 08:16:46 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1416035807; bh=e+VWEa03f3yNEz/szO8ne3X9xoqj2nyGZ9++pZpPjZk=; h=From:To:Subject:Date:From:Subject; b=cUpnB6/p3MPXTLZM3QLX0oY/Aoujhzuul38BYvczy+vYw7yEZkh/C6N6cpVThwy5Ipsv9jpAJwLicH/LQjt7S1w+Oy3H+L7fQ+H+7Sne+kKQJOphOJFx3B4UlzJ661lKRs66OG8i48Mp8LVdtrPRkVetn6CSQkM+cn+3TyB0383DfepFfK/7HhsrH7pvUlP/Fs0xCjbxzhjWXWybMkd500LMj+HvOe+RtQuEAhVyCovciagHYaVm/50flMBzdGfS9M3qU/OcsdbLRbpMOWO3Mc9Xj26LUYZuHRbuAOMAfdHHuELiNcwb28j/ksfgvNO9BqD+GnRTK85yBt5E+9uXeA==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=cSsGEasOAhbXd1wsb7W3f50CN9xN9DuFWyCUqJR5Q8o6yoPAZ4IAwPZ3zawjXrUtsNHLt2q0OMiOLw4R+XDyQqW67vwUPcPfQG0jpGLAxWfXK8YFQml+DsICzeKFOV8YeUIhPFGaTxaH38iyuNo/1AtB4Fw8fgr92z3uG1j9AamS8pPXVP/31zU9YU4voB0ned9V7L99kkEnFWFNZboLfH1OvHAoezQ483NtAY5sweHfsXKZuozVIFkfmqVslg/uOUJJyJNuW0IihSgc9WQJyK9KTDrv8fze61iOQ/Bf3Aa+Eko+DcPEJozcdkuXY5Hgx/Lf+xxsNadd8MA0u5aPoA==;
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
In vim, ge and gE go back to the end of the previous word. I've had this
in my own configuration with a shell widget but that isn't perfect. This
adds native C widgets.
Oliver
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index c549990..bf1b315 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 36c46d2..39c81e6 100644
--- a/Src/Zle/iwidgets.list
+++ b/Src/Zle/iwidgets.list
@@ -122,6 +122,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 e59304e..301b18d 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;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author