Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Shift-Insert overwrites ZLE CUTBUFFER



On 17 Nov, Bart wrote:
> } Coming back to the original point of this thread, would it make
> } sense to instead put the bracketed-paste text in a register?
>
> ..., so it makes sense to me to put it there on the paste
> action (the first real chance we have to sync up with the global
> clipboard state).  It's more that people aren't used to having a
> copy-paste affect their shell that way that is causing an issue,
> than the logic of the operation (I think, someone will probably
> contradict me).

Let's leave it as it is then. We can always come back to it if it really
ends up bothering a lot of people. And even that might reduce as more
programs support bracketed-paste and expectations change.

> I'm not going to respond in detail to your musings about emacs
> register operations; my only thought is that we're supposed to be
> maintaining a shell here, not re-implementing several editors.

I take your point. The emacs register widgets don't take much more than
about three lines each to do as shell widgets anyway. The main thing I
actually care about is that if we were to add emacs register widgets,
that it should use the same buffers (and marks) so that people can mix
and match with the vi widgets.

Anyway, as the 0-9 vi registers are quite separate from the emacs
killring (yanks only go into "0), they should be added to the new
associative array - patch for that follows.

Oliver

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index fe6a7e9..e6b315a 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -993,7 +993,7 @@ ifnzman(noderef(Character Highlighting)) for details.
 )
 vindex(registers)
 item(tt(registers) (associative array))(
-The contents of each of the `named' vi register buffers. These are
+The contents of each of the vi register buffers. These are
 typically set using tt(vi-set-buffer) followed by a delete, change or
 yank command.
 )
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index cb8dac8..78e7835 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -729,15 +729,22 @@ static void
 set_register(Param pm, char *value)
 {
     int n = 0;
+    int offset = -1;
     Cutbuffer reg;
 
-    if (!pm->node.nam || *pm->node.nam < 'a' || *pm->node.nam > 'z' ||
-	    pm->node.nam[1]) {
+    if (!pm->node.nam || pm->node.nam[1])
+	;
+    else if (*pm->node.nam >= '0' && *pm->node.nam <= '9')
+	offset = '0' - 26;
+    else if (*pm->node.nam >= 'a' && *pm->node.nam <= 'z')
+	offset = 'a';
+
+    if (offset == -1) {
 	zerr("invalid zle register: %s", pm->node.nam);
 	return;
     }
 
-    reg = &vibuf[*pm->node.nam - 'a'];
+    reg = &vibuf[*pm->node.nam - offset];
     if (*value)
 	reg->buf = stringaszleline(value, 0, &n, NULL, NULL);
     reg->len = n;
@@ -755,18 +762,21 @@ static void
 scan_registers(UNUSED(HashTable ht), ScanFunc func, int flags)
 {
     int i;
+    char ch;
     struct param pm;
 
     memset((void *)&pm, 0, sizeof(struct param));
     pm.node.flags = PM_SCALAR | PM_READONLY;
     pm.gsu.s = &nullsetscalar_gsu;
 
-    for (i = 0; i < 26; i++) {
+    for (i = 0, ch = 'a'; i < 36; i++) {
 	pm.node.nam = zhalloc(2);
-	*pm.node.nam = 'a' + i;
+	*pm.node.nam = ch;
 	pm.node.nam[1] = '\0';
 	pm.u.str = zlelineasstring(vibuf[i].buf, vibuf[i].len, 0, NULL, NULL, 1);
 	func(&pm.node, flags);
+	if (ch++ == 'z')
+	    ch = '0';
     }
 }
 
@@ -775,17 +785,24 @@ static HashNode
 get_registers(UNUSED(HashTable ht), const char *name)
 {
     Param pm = (Param) hcalloc(sizeof(struct param));
+    int reg = -1;
     pm->node.nam = dupstring(name);
     pm->node.flags = PM_SCALAR;
     pm->gsu.s = &register_gsu;
 
-    if (*name < 'a' || *name > 'z' || name[1]) {
+    if (name[1])
+       ;
+    else if (*name >= '0' && *name <= '9')
+	reg = *name - '0' + 26;
+    else if (*name >= 'a' && *name <= 'z')
+	reg = *name - 'a';
+
+    if (reg == -1) {
 	pm->u.str = dupstring("");
 	pm->node.flags |= (PM_UNSET|PM_SPECIAL);
-    } else {
-	int reg = *name - 'a';
+    } else
 	pm->u.str = zlelineasstring(vibuf[reg].buf, vibuf[reg].len, 0, NULL, NULL, 1);
-    }
+
     return &pm->node;
 }
 



Messages sorted by: Reverse Date, Date, Thread, Author