about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/Zle/zle_misc.c40
2 files changed, 32 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d215a1e6..33a0cac28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2005-11-02  Peter Stephenson  <pws@csr.com>
 
+	* users/9610: Src/Zle/zle_misc.c: Handle digit argument
+	in copy-prev-word and copy-prev-shell-word.
+
 	* 21973: Src/Zle/zle_misc.c: idigit() test in digitargument()
 	had reversed sense.
 
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 2557fb0ed..8605c4624 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -616,17 +616,28 @@ universalargument(char **args)
 int
 copyprevword(UNUSED(char **args))
 {
-    int len, t0;
+    int len, t0 = zlecs, t1;
 
-    for (t0 = zlecs - 1; t0 >= 0; t0--)
-	if (ZC_iword(zleline[t0]))
-	    break;
-    for (; t0 >= 0; t0--)
-	if (!ZC_iword(zleline[t0]))
-	    break;
-    if (t0)
-	t0++;
-    len = zlecs - t0;
+    if (zmult > 0) {
+	int count = zmult;
+
+	for (;;) {
+	    t1 = t0;
+
+	    while (t0 && !ZC_iword(zleline[t0-1]))
+		t0--;
+	    while (t0 && ZC_iword(zleline[t0-1]))
+		t0--;
+
+	    if (!--count)
+		break;
+	    if (t0 == 0)
+		return 1;
+	}
+    }
+    else
+	return 1;
+    len = t1 - t0;
     spaceinline(len);
     ZS_memcpy(zleline + zlecs, zleline + t0, len);
     zlecs += len;
@@ -642,12 +653,19 @@ copyprevshellword(UNUSED(char **args))
     int i;
     unsigned char *p = NULL;
 
-    if ((l = bufferwords(NULL, NULL, &i)))
+    if (zmult <= 0)
+	return 1;
+
+    if ((l = bufferwords(NULL, NULL, &i))) {
+	i -= (zmult-1);
+	if (i < 0)
+	    return 1;
         for (n = firstnode(l); n; incnode(n))
             if (!i--) {
                 p = (unsigned char *)getdata(n);
                 break;
             }
+    }
 
     if (p) {
 	int len;