summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-04-19 14:16:22 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-04-19 14:16:22 +0000
commitc6dfb2999d51be6e71176358a2e14360fe6e6ee6 (patch)
treee781f3f174a3a2c7978d3b2ad89589e8439aec3e /Src/Zle
parent0d101890d0faeaefa863099042e3510f5021fbc3 (diff)
downloadzsh-c6dfb2999d51be6e71176358a2e14360fe6e6ee6.tar.gz
zsh-c6dfb2999d51be6e71176358a2e14360fe6e6ee6.tar.xz
zsh-c6dfb2999d51be6e71176358a2e14360fe6e6ee6.zip
users/11419: zle copy-region-as-kill <string>
adds text to the kill ring
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/zle_misc.c21
-rw-r--r--Src/Zle/zle_utils.c37
2 files changed, 45 insertions, 13 deletions
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 30fa0cc5b..48739e531 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -337,14 +337,21 @@ killregion(UNUSED(char **args))
 
 /**/
 int
-copyregionaskill(UNUSED(char **args))
+copyregionaskill(char **args)
 {
-    if (mark > zlell)
-	mark = zlell;
-    if (mark > zlecs)
-	cut(zlecs, mark - zlecs, 0);
-    else
-	cut(mark, zlecs - mark, 1);
+    if (*args) {
+        int len;
+        ZLE_STRING_T line = stringaszleline(*args, 0, &len, NULL, NULL);
+	cuttext(line, len, -1);
+	free(line);
+    } else {
+	if (mark > zlell)
+	    mark = zlell;
+	if (mark > zlecs)
+	    cut(zlecs, mark - zlecs, 0);
+	else
+	    cut(mark, zlecs - mark, 1);
+    }
     return 0;
 }
 
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 9b769b5a0..6583ef503 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -420,10 +420,35 @@ forekill(int ct, int dir)
     shiftchars(i, ct);
 }
 
+
+/*
+ * Put the ct characters starting at zleline + i into the
+ * cutbuffer, circling the kill ring if necessary (it's
+ * not if we're dealing with vi buffers, which is detected
+ * internally).  The text is not removed from zleline.
+ *
+ * dir indicates how the text is to be added to the cutbuffer,
+ * if the cutbuffer wasn't zeroed (this depends on the last
+ * command being a kill).  If dir is 1, the new text goes
+ * to the front of the cut buffer.  If dir is -1, the cutbuffer
+ * is completely overwritten.
+ */
+
 /**/
 void
 cut(int i, int ct, int dir)
 {
+  cuttext(zleline + i, ct, dir);
+}
+
+/*
+ * As cut, but explicitly supply the text together with its length.
+ */
+
+/**/
+void
+cuttext(ZLE_STRING_T line, int ct, int dir)
+{
     if (!ct)
 	return;
 
@@ -434,7 +459,7 @@ cut(int i, int ct, int dir)
 	if (!(zmod.flags & MOD_VIAPP) || !b->buf) {
 	    free(b->buf);
 	    b->buf = (ZLE_STRING_T)zalloc(ct * ZLE_CHAR_SIZE);
-	    ZS_memcpy(b->buf, zleline + i, ct);
+	    ZS_memcpy(b->buf, line, ct);
 	    b->len = ct;
 	    b->flags = vilinerange ? CUTBUFFER_LINE : 0;
 	} else {
@@ -448,7 +473,7 @@ cut(int i, int ct, int dir)
 			* ZLE_CHAR_SIZE);
 	    if (b->flags & CUTBUFFER_LINE)
 		b->buf[len++] = ZWC('\n');
-	    ZS_memcpy(b->buf + len, zleline + i, ct);
+	    ZS_memcpy(b->buf + len, line, ct);
 	    b->len = len + ct;
 	}
 	return;
@@ -459,7 +484,7 @@ cut(int i, int ct, int dir)
 	for(n=34; n>26; n--)
 	    vibuf[n] = vibuf[n-1];
 	vibuf[26].buf = (ZLE_STRING_T)zalloc(ct * ZLE_CHAR_SIZE);
-	ZS_memcpy(vibuf[26].buf, zleline + i, ct);
+	ZS_memcpy(vibuf[26].buf, line, ct);
 	vibuf[26].len = ct;
 	vibuf[26].flags = vilinerange ? CUTBUFFER_LINE : 0;
     }
@@ -467,7 +492,7 @@ cut(int i, int ct, int dir)
 	cutbuf.buf = (ZLE_STRING_T)zalloc(ZLE_CHAR_SIZE);
 	cutbuf.buf[0] = ZWC('\0');
 	cutbuf.len = cutbuf.flags = 0;
-    } else if (!(lastcmd & ZLE_KILL)) {
+    } else if (!(lastcmd & ZLE_KILL) || dir < 0) {
 	Cutbuffer kptr;
 	if (!kring) {
 	    kringsize = KRINGCTDEF;
@@ -485,7 +510,7 @@ cut(int i, int ct, int dir)
     if (dir) {
 	ZLE_STRING_T s = (ZLE_STRING_T)zalloc((cutbuf.len + ct)*ZLE_CHAR_SIZE);
 
-	ZS_memcpy(s, zleline + i, ct);
+	ZS_memcpy(s, line, ct);
 	ZS_memcpy(s + ct, cutbuf.buf, cutbuf.len);
 	free(cutbuf.buf);
 	cutbuf.buf = s;
@@ -493,7 +518,7 @@ cut(int i, int ct, int dir)
     } else {
 	cutbuf.buf = realloc((char *)cutbuf.buf,
 			     (cutbuf.len + ct) * ZLE_CHAR_SIZE);
-	ZS_memcpy(cutbuf.buf + cutbuf.len, zleline + i, ct);
+	ZS_memcpy(cutbuf.buf + cutbuf.len, line, ct);
 	cutbuf.len += ct;
     }
     if(vilinerange)