From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27254 invoked by alias); 4 Apr 2016 12:56:50 -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: 38239 Received: (qmail 25082 invoked from network); 4 Apr 2016 12:56:48 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-AuditID: cbfec7f4-f796c6d000001486-02-5702648a8c27 Date: Mon, 04 Apr 2016 13:56:39 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Another Message-id: <20160404135639.0edccf62@pwslap01u.europe.root.pri> In-reply-to: <20160404124945.7be02c99@pwslap01u.europe.root.pri> References: <20160404113524.GA21769@tarsus.local2> <20160404124945.7be02c99@pwslap01u.europe.root.pri> 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+NgFrrALMWRmVeSWpSXmKPExsVy+t/xq7pdKUzhBlPeq1ocbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujGcnW5kKFohU9P2fxtTA+JW/i5GTQ0LARKJhz1kWCFtM4sK9 9WxdjFwcQgJLGSUap09lgXBmMElsvNrGDOGcZpQ4cucqE4RzhlHi4pcOdpB+FgFViScPLoLN YhMwlJi6aTYjiC0iIC5xdu15sLiwgLzEt9YWNhCbV8Be4sfVLtYuRg4OTgEHif9XNEDCQgIZ Ese7boC18gvoS1z9+4kJ4jx7iZlXzjBCtApK/Jh8D2wks4CWxOZtTawQtrzE5jVvmSHmqEvc uLubfQKj8CwkLbOQtMxC0rKAkXkVo2hqaXJBcVJ6rqFecWJucWleul5yfu4mRkg4f9nBuPiY 1SFGAQ5GJR7eD0cZw4VYE8uKK3MPMUpwMCuJ8OolM4UL8aYkVlalFuXHF5XmpBYfYpTmYFES 5527632IkEB6YklqdmpqQWoRTJaJg1OqgXGNW0nt/nKxxaZ370wMZ+hLu/tHeqFExH/OhPdP +xPic0JSW1k7H3bt2/FPdNtSjktXblb2Hz3507AoSTil6e/Xz0rM1hfWvPhYW/L71+rjbLcP zvs3/WUQc2N9a8WCz3x1SrnPav6odmzbvMjr505tgYcqItvmOHq8f3Jv49pJHWIlcaHsDTeU WIozEg21mIuKEwEYbb/xYwIAAA== On Mon, 4 Apr 2016 12:49:45 +0100 Peter Stephenson wrote: > On Mon, 4 Apr 2016 11:35:24 +0000 > Daniel Shahaf wrote: > > In 'zsh -f', typing > > > > > > > > at the prompt gives me " " with the <...> part in reverse video. > > Presumably what it should do is exit reverse search and execute > set-mark-command. > > I think the problem is probably that the isn't being saved for > re-evaluation properly when search is exited. This looks like it fixes this. The new function can also be used to simplify a bit of memory management elsewhere. The ungetkeycmd() call is the crucial one. As far as I can see the remaining two cases that don't unmetafy are correct: the other case in zle_hist.c is for a key string, which isn't metafied (it claims), and vichgbuf appears to be a raw byte string (although the comment above "examination of the code suggests..." which I added myself isn't a great confidence booster). diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 382eb8d..bf38085 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1615,8 +1615,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) else lastchar = lastc; if(lastlen != keybuflen) { - unmetafy(keybuf + lastlen, &keybuflen); - ungetbytes(keybuf+lastlen, keybuflen); + ungetbytes_unmeta(keybuf+lastlen, keybuflen); if(vichgflag) vichgbufptr -= keybuflen; keybuf[lastlen] = 0; @@ -1672,7 +1671,7 @@ getkeybuf(int w) mod_export void ungetkeycmd(void) { - ungetbytes(keybuf, keybuflen); + ungetbytes_unmeta(keybuf, keybuflen); } /* read a command from the current keymap, with widgets */ @@ -1698,9 +1697,7 @@ getkeycmd(void) hops = 0; return NULL; } - pb = unmetafy(ztrdup(str), &len); - ungetbytes(pb, len); - zfree(pb, strlen(str) + 1); + ungetbytes_unmeta(str, len); goto sentstring; } if (func == Th(z_executenamedcmd) && !statusline) { diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 104e5d6..472e326 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -357,6 +357,21 @@ ungetbytes(char *s, int len) ungetbyte(*--s); } +/**/ +void +ungetbytes_unmeta(char *s, int len) +{ + s += len; + while (len--) { + if (len && s[-2] == Meta) { + ungetbyte(*--s ^ 32); + len--; + s--; + } else + ungetbyte(*--s); + } +} + #if defined(pyr) && defined(HAVE_SELECT) static int breakread(int fd, char *buf, int n)