zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: Shift-Insert overwrites ZLE CUTBUFFER
Date: Sun, 20 Nov 2016 23:32:56 +0100	[thread overview]
Message-ID: <71618.1479681176@hydra.kiddle.eu> (raw)
In-Reply-To: <161117191641.ZM7944@torch.brasslantern.com>

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;
 }
 


      reply	other threads:[~2016-11-23 21:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAMtVo_PG_fd62V1FZ4r7fRUragzzS6H4McN5sO1=hhY=6DR6Yg@mail.gmail.com>
     [not found] ` <161025091249.ZM7232@torch.brasslantern.com>
     [not found]   ` <CAMtVo_N6qOQr++Amzn11+m3pkOxjc908mwFUerur77+OWd92uw@mail.gmail.com>
     [not found]     ` <161026090133.ZM11120@torch.brasslantern.com>
     [not found]       ` <CAMtVo_P09j6fyJytA21iu_qOom6bCTvJEWn-dXTBX97Bp00Sdg@mail.gmail.com>
     [not found]         ` <161026165138.ZM12130@torch.brasslantern.com>
     [not found]           ` <87h97x36sa.fsf@lwm.klanderman.net>
     [not found]             ` <161027133523.ZM15655@torch.brasslantern.com>
     [not found]               ` <43312.1477929414@hydra.kiddle.eu>
     [not found]                 ` <CGME20161031160350epcas3p4849616fbcc05783a9966320a28ed731c@epcas3p4.samsung.com>
     [not found]                   ` <20161031161605.23af1751@pwslap01u.europe.root.pri>
2016-11-09 17:27                     ` Bart Schaefer
2016-11-10 16:21                       ` Oliver Kiddle
2016-11-10 17:17                         ` Bart Schaefer
2016-11-15 21:41                           ` Oliver Kiddle
2016-11-15 22:07                             ` Bart Schaefer
2016-11-17 16:53                               ` Oliver Kiddle
2016-11-18  3:16                                 ` Bart Schaefer
2016-11-20 22:32                                   ` Oliver Kiddle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=71618.1479681176@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).