From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 966 invoked by alias); 25 Mar 2015 15:59:20 -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: 34776 Received: (qmail 28932 invoked from network); 25 Mar 2015 15:59:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f126d000001e9a-33-5512d83fc08d Date: Wed, 25 Mar 2015 15:48:53 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working) Message-id: <20150325154853.7efc21d0@pwslap01u.europe.root.pri> In-reply-to: <20150323213426.21fd79c8@ntlworld.com> References: <20150319105716.620cd931@pwslap01u.europe.root.pri> <20150319125351.1e270c2d@pwslap01u.europe.root.pri> <20150320105703.2754b6af@pwslap01u.europe.root.pri> <150320090420.ZM21908@torch.brasslantern.com> <20150322183556.1fa0f143@ntlworld.com> <150322162235.ZM1728@torch.brasslantern.com> <20150323213426.21fd79c8@ntlworld.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKLMWRmVeSWpSXmKPExsVy+t/xq7r2N4RCDU4s4bI42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGVN6pzIVTNWpePu5tIHxq0IXIyeHhICJxK9D59ggbDGJC/fW A9lcHEICSxkl5q/ewwzhLGGS+L10HhOEs41R4m5fGzNIC4uAqsSzpd8ZQWw2AUOJqZtmA9kc HCIC2hLtH8VAwsICKRIrLx0DK+cVsJc4PXMBC4jNKWAscfJqLwvEzDfMEm+O3AE7g19AX+Lq 309MECfZS8y8coYRollQ4sfke2DNzAJaEpu3NbFC2PISm9e8BVsgJKAucePubvYJjEKzkLTM QtIyC0nLAkbmVYyiqaXJBcVJ6bmGesWJucWleel6yfm5mxghQftlB+PiY1aHGAU4GJV4eHc8 EAwVYk0sK67MPcQowcGsJMK7c5NQqBBvSmJlVWpRfnxRaU5q8SFGJg5OqQbGCU21P7b83MV8 4pJI2wppB10xtYv50fGlDl4H4qsnR+SIF3vaHTLvCb++fRVvk5q9jq5kyfcjHPvfiIcUvV9c EbDFyvHhnj9/unqfms+oKk+/Ju78992V/8Eyj17mn94y8U/880x/XrHHUtUNVmxOp08lXDPr jPgg5tRaUpdqplQibNbQeVmJpTgj0VCLuag4EQBG3cZtOAIAAA== On Mon, 23 Mar 2015 21:34:26 +0000 Peter Stephenson wrote: > Ideally, I think we'd handle not adding > the alias text to history the way we've been doing in other cases by > checking INP_* flags, which is much less hit and miss. That ought not > to be too difficult, but I haven't really got my mind round the > consequences yet. Hmm... I typed this in more or less as below (with one subsequent fix to testing flags for interaction with !-history) and was expecting it to fail horribly, and so far it's failed to fail. Perhaps my expectations were low simply because it's been the old way since 2 million BC. I'll try it further. Obviously this doesn't change the fact that "{bar" turns into "echobar" for execution after alias expansion (it no longer does so in the history), since that's up in the lexer. Some more tidying up may now be possible given that removing aliases from history is less of a special case. hwget() had a special hack for aliases, which I don't think should be needed now, but I'd like to know --- the DEBUG code should tell us if something nasty is happening. pws diff --git a/Src/hist.c b/Src/hist.c index b44f4ad..990e609 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -245,7 +245,6 @@ hist_context_save(struct hist_stack *hs, int toplevel) hs->chwords = chwords; hs->chwordlen = chwordlen; hs->chwordpos = chwordpos; - hs->hwgetword = hwgetword; hs->hgetc = hgetc; hs->hungetc = hungetc; hs->hwaddc = hwaddc; @@ -289,7 +288,6 @@ hist_context_restore(const struct hist_stack *hs, int toplevel) chwords = hs->chwords; chwordlen = hs->chwordlen; chwordpos = hs->chwordpos; - hwgetword = hs->hwgetword; hgetc = hs->hgetc; hungetc = hs->hungetc; hwaddc = hs->hwaddc; @@ -338,8 +336,7 @@ ihwaddc(int c) * fashion as we never need the expansion in the history * line, only in the lexer and above. */ - !((histactive & HA_INWORD) && - (inbufflags & (INP_ALIAS|INP_HIST)) == INP_ALIAS)) { + (inbufflags & (INP_ALIAS|INP_HIST)) != INP_ALIAS) { /* Quote un-expanded bangs in the history line. */ if (c == bangchar && stophist < 2 && qbang) /* If qbang is not set, we do not escape this bangchar as it's * @@ -915,8 +912,7 @@ ihungetc(int c) zlemetall--; exlast++; } - if (!(histactive & HA_INWORD) || - (inbufflags & (INP_ALIAS|INP_HIST)) != INP_ALIAS) { + if ((inbufflags & (INP_ALIAS|INP_HIST)) != INP_ALIAS) { DPUTS(hptr <= chline, "BUG: hungetc attempted at buffer start"); hptr--; DPUTS(*hptr != (char) c, "BUG: wrong character in hungetc() "); @@ -1536,28 +1532,17 @@ hend(Eprog prog) return !(flag & HISTFLAG_NOEXEC || errflag); } -/* Gives current expansion word if not last word before chwordpos. */ - -/**/ -int hwgetword = -1; - /* begin a word */ /**/ void ihwbegin(int offset) { - if (stophist == 2 || (histactive & HA_INWORD)) + if (stophist == 2 || (histactive & HA_INWORD) || + (inbufflags & (INP_ALIAS|INP_HIST)) == INP_ALIAS) return; if (chwordpos%2) chwordpos--; /* make sure we're on a word start, not end */ - /* If we're expanding an alias, we should overwrite the expansion - * in the history. - */ - if ((inbufflags & INP_ALIAS) && !(inbufflags & INP_HIST)) - hwgetword = chwordpos; - else - hwgetword = -1; chwords[chwordpos++] = hptr - chline + offset; } @@ -1567,7 +1552,8 @@ ihwbegin(int offset) void ihwend(void) { - if (stophist == 2 || (histactive & HA_INWORD)) + if (stophist == 2 || (histactive & HA_INWORD) || + (inbufflags & (INP_ALIAS|INP_HIST)) == INP_ALIAS) return; if (chwordpos%2 && chline) { /* end of word reached and we've already begun a word */ @@ -1578,13 +1564,6 @@ ihwend(void) (chwordlen += 32) * sizeof(short)); } - if (hwgetword > -1 && - (inbufflags & INP_ALIAS) && !(inbufflags & INP_HIST)) { - /* We want to reuse the current word position */ - chwordpos = hwgetword; - /* Start from where previous word ended, if possible */ - hptr = chline + chwords[chwordpos ? chwordpos - 1 : 0]; - } } else { /* scrub that last word, it doesn't exist */ chwordpos--; @@ -1608,17 +1587,17 @@ histbackword(void) static void hwget(char **startptr) { - int pos = hwgetword > -1 ? hwgetword : chwordpos - 2; + int pos = chwordpos - 2; #ifdef DEBUG /* debugging only */ - if (hwgetword == -1 && !chwordpos) { + if (!chwordpos) { /* no words available */ DPUTS(1, "BUG: hwget() called with no words"); *startptr = ""; return; - } - else if (hwgetword == -1 && chwordpos%2) { + } + else if (chwordpos%2) { DPUTS(1, "BUG: hwget() called in middle of word"); *startptr = ""; return; @@ -1640,9 +1619,9 @@ hwrep(char *rep) if (!strcmp(rep, start)) return; - + hptr = start; - chwordpos = (hwgetword > -1) ? hwgetword : chwordpos - 2; + chwordpos = chwordpos - 2; hwbegin(0); qbang = 1; while (*rep) @@ -1670,7 +1649,6 @@ hgetline(void) /* reset line */ hptr = chline; chwordpos = 0; - hwgetword = -1; return ret; } diff --git a/Src/zsh.h b/Src/zsh.h index 9a97263..403e8d3 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2709,7 +2709,6 @@ struct hist_stack { short *chwords; int chwordlen; int chwordpos; - int hwgetword; int (*hgetc) _((void)); void (*hungetc) _((int)); void (*hwaddc) _((int));