From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7435 invoked by alias); 15 Nov 2016 21:47:37 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39952 Received: (qmail 9536 invoked from network); 15 Nov 2016 21:47:37 -0000 X-Qmail-Scanner-Diagnostics: from nm33-vm1.bullet.mail.ir2.yahoo.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(212.82.97.106):SA:0(0.0/5.0):. Processed in 2.014788 secs); 15 Nov 2016 21:47:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: okiddle@yahoo.co.uk X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.mail.yahoo.com designates 212.82.97.106 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1479246118; bh=gamdLmWN1tU5YeyWH+dOY+JINuMfgniF7ls3rMnBW2Q=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=dHL7SwjfEO2foyDZaBh9+EJlCHL7GUjvjI7D63VMupe1ojhO2+SrRdSRx7loNssWZIX/J5WglbqYWD2rqmlMW31PK+cxpZfalfjgPWGzUng6U72kUfcce5V2FjEghnwXRY1SzDm13UWqAjTfwxs7p5wGqTVpkG9+MRIldwF6SUtthgsb7yoEwRg1rL1oC7sDNuXuaxO12hS5hlBKo+x+7HZFInOW+eMIHTclTq/pSmgTEL6mAFCgo2eHaX0bRNkt1i9q09v984yeTHPDiY1EYwvx19B2RSATn/vORSEnqSybOy4yJhVEQpEksckLRoOQrxn3I7KlIC7xgfWu+z2xEg== X-Yahoo-Newman-Id: 417466.39662.bm@smtp121.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: MIZ8Q_UVM1n7eedEH0.yJVghiP.5PpaNdUV1wdTH4XEaQDe 8.CxNEWRE00cGnT45N_5ZVs8.U5hIRdFQaK0i2DPoporvEADm.ySn0Md0Jga sdgSYxv8X7ZlAG_Js7TI.bnRzJJEd9YCq1Xd5M4SIlFfgoCdmymcGnXfxT.c m_4ds53YuRBe6GA2i6IEMr_lAojUKd61iRf9KKLisur_PW9Hpw2lYCxmmMsN qF7SmI5Kp8enUjW31sf3Fetnas0cg6LV.T7TlFJHpZy.nAkHA9ppG0NXdZHt SVoHB0Vk6wwbvxChSGWIcoJn8h9baG0rPLbK0LT34u.1v4wWz.AP3R_p33Ut VbyY2MmRkNDE14QNiRDiuJblD4_llrwz3acLtButnXbXuHpijLvDrta3AO6M XlwoV45pALF8n9yzGGpBbaO6XiLEjtk3QLwFshTlq7w1maro1wfYjq5lqGmX LwgaFg1oglncP9mlwjAbWrnK2SYwbCU6ygiom4w_p.Ur9lfKbpA3WTGZ2mma N93grDBKoigVV3WqgnvKirwdBeD_8ubtV5PIlBE0- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <161110091736.ZM20932@torch.brasslantern.com> From: Oliver Kiddle References: <161025091249.ZM7232@torch.brasslantern.com> <161026090133.ZM11120@torch.brasslantern.com> <161026165138.ZM12130@torch.brasslantern.com> <87h97x36sa.fsf@lwm.klanderman.net> <161027133523.ZM15655@torch.brasslantern.com> <43312.1477929414@hydra.kiddle.eu> <20161031161605.23af1751@pwslap01u.europe.root.pri> <161109092745.ZM2477@torch.brasslantern.com> <4446.1478794906@hydra.kiddle.eu> <161110091736.ZM20932@torch.brasslantern.com> To: zsh-workers@zsh.org Subject: Re: Shift-Insert overwrites ZLE CUTBUFFER MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22834.1479246117.1@hydra.kiddle.eu> Date: Tue, 15 Nov 2016 22:41:57 +0100 Message-ID: <22835.1479246117@hydra.kiddle.eu> On 10 Nov, Bart wrote: > A useful addition to zsh/zleparameter would be a special hash of > register-to-content mappings (emacs calls this register-alist). The following patch adds this under the name "registers" and in zle_params.c rather than zleparameter. That seemed more consistent with, e.g. killring. It means that it is only available when ZLE is active which it wouldn't really need to be (the same goes for killring) but there are advantages to that too. For what it's worth, I think the term "registers" is better than "buffers" and it'd be good to use the same ones with emacs style widgets. What does the "alist" part of the emacs name denote. It contains just the registers 'a' to 'z' for now. Including the numbered registers would just be a duplication of killring/CUTBUFFER. (except the yank register - "0). Why does makezleparams set pm->level to locallevel + 1? That seems wrong. What does the + 1 achieve? Oliver diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 21681e5..a10c2d0 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -991,6 +991,11 @@ and tt(zle_highlight); see ifzman(the section CHARACTER HIGHLIGHTING below)\ ifnzman(noderef(Character Highlighting)) for details. ) +vindex(registers) +item(tt(registers) (associative array))( +The contents of each of the `named' vi buffers. These are typically set +using tt(vi-set-buffer) followed by a delete, change or yank command. +) vindex(SUFFIX_ACTIVE) vindex(SUFFIX_START) vindex(SUFFIX_END) diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index c6387bf..2400bfb 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -118,6 +118,12 @@ static const struct gsu_integer suffixactive_gsu = static const struct gsu_array killring_gsu = { get_killring, set_killring, unset_killring }; + +static const struct gsu_scalar register_gsu = +{ strgetfn, set_register, unset_register }; +static const struct gsu_hash registers_gsu = +{ hashgetfn, set_registers, zleunsetfn }; + /* implementation is in zle_refresh.c */ static const struct gsu_array region_highlight_gsu = { get_region_highlight, set_region_highlight, unset_region_highlight }; @@ -181,6 +187,7 @@ mod_export void makezleparams(int ro) { struct zleparam *zp; + Param reg_param; for(zp = zleparams; zp->name; zp++) { Param pm = createparam(zp->name, (zp->type |PM_SPECIAL|PM_REMOVABLE| @@ -206,6 +213,11 @@ makezleparams(int ro) if ((zp->type & PM_UNSET) && (zmod.flags & (MOD_MULT|MOD_TMULT))) pm->node.flags &= ~PM_UNSET; } + + reg_param = createspecialhash("registers", get_registers, &scan_registers, + PM_LOCAL|PM_REMOVABLE); + reg_param->gsu.h = ®isters_gsu; + reg_param->level = locallevel + 1; } /* Special unset function for ZLE special parameters: act like the standard * @@ -712,6 +724,93 @@ unset_killring(Param pm, int exp) } } +/**/ +static void +set_register(Param pm, char *value) +{ + int n = 0; + + if (!pm->node.nam || *pm->node.nam < 'a' || *pm->node.nam > 'z' || + pm->node.nam[1]) { + zerr("invalid zle register: %s", pm->node.nam); + return; + } + + Cutbuffer reg = &vibuf[*pm->node.nam - 'a']; + if (*value) + reg->buf = stringaszleline(value, 0, &n, NULL, NULL); + reg->len = n; +} + +/**/ +static void +unset_register(Param pm, UNUSED(int exp)) +{ + set_register(pm, ""); +} + +/**/ +static void +scan_registers(UNUSED(HashTable ht), ScanFunc func, int flags) +{ + int i; + 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++) { + pm.node.nam = zhalloc(2); + *pm.node.nam = 'a' + i; + pm.node.nam[1] = '\0'; + pm.u.str = zlelineasstring(vibuf[i].buf, vibuf[i].len, 0, NULL, NULL, 1); + func(&pm.node, flags); + } +} + +/**/ +static HashNode +get_registers(UNUSED(HashTable ht), const char *name) +{ + Param pm = (Param) hcalloc(sizeof(struct param)); + pm->node.nam = dupstring(name); + pm->node.flags = PM_SCALAR; + pm->gsu.s = ®ister_gsu; + + if (*name < 'a' || *name > 'z' || name[1]) { + pm->u.str = dupstring(""); + pm->node.flags |= (PM_UNSET|PM_SPECIAL); + } else { + int reg = *name - 'a'; + pm->u.str = zlelineasstring(vibuf[reg].buf, vibuf[reg].len, 0, NULL, NULL, 1); + } + return &pm->node; +} + +/**/ +static void +set_registers(UNUSED(Param pm), HashTable ht) +{ + int i; + HashNode hn; + + if (!ht) + return; + + for (i = 0; i < ht->hsize; i++) + for (hn = ht->nodes[i]; hn; hn = hn->next) { + struct value v; + v.isarr = v.flags = v.start = 0; + v.end = -1; + v.arr = NULL; + v.pm = (Param) hn; + + set_register(v.pm, getstrvalue(&v)); + } + deleteparamtable(ht); +} + static void set_prepost(ZLE_STRING_T *textvar, int *lenvar, char *x) {