From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 521 invoked by alias); 22 Jun 2016 11:53:32 -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: 38746 Received: (qmail 1929 invoked from network); 22 Jun 2016 11:53:30 -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: cbfec7f5-f792a6d000001302-6f-576a7c372500 Date: Wed, 22 Jun 2016 12:53:24 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: bug: suffix alias and tabcompletion Message-id: <20160622125324.44e00539@pwslap01u.europe.root.pri> In-reply-to: <20160622100159.1d82792f@pwslap01u.europe.root.pri> References: <20160621193918.GA3768@fau.de> <20160622100159.1d82792f@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/xa7rmNVnhBgsP6FkcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujM+zOhgLropUTFyX0MC4RqCLkYNDQsBE4tUl7y5GTiBTTOLC vfVsXYxcHEICSxklphzezQzhzGCS2PLkChOEc45R4s+5ZnYI5yyjxJb9B9lA+lkEVCVeX/rE BGKzCRhKTN00mxHEFhHQkthx8iRYXFjAQOLc5zfsIDavgL3Exd+tzCA2p4CDxNmVf1ghhi5n lGh/eh2sgV9AX+LqX4ihEkANM6+cYYRoFpT4MfkeC4jNDLRg87YmVghbXmLzmrdgQ4UE1CVu 3N3NPoFReBaSlllIWmYhaVnAyLyKUTS1NLmgOCk910ivODG3uDQvXS85P3cTIyScv+5gXHrM 6hCjAAejEg8vQ1dmuBBrYllxZe4hRgkOZiUR3oyyrHAh3pTEyqrUovz4otKc1OJDjNIcLEri vDN3vQ8REkhPLEnNTk0tSC2CyTJxcEo1MGZEV80T91QzUnVexLN0/sz5UxZL9kk2FNt0M9Xf XcJ+9MsUlYjmhzNFK73/eD485WDvKbxkc4Gk0MH+0KDQdc43DDZKqx/PZdyxrWTbvQRvzUy5 huwUx/MHdGKzray3Ofs0NF+6Y2p4Xu3XnHWZar/yFp2PLL+g220m0dyUpL7E9qGz0VYRJZbi jERDLeai4kQAgrC6s2MCAAA= On Wed, 22 Jun 2016 10:01:59 +0100 Peter Stephenson wrote: > On Tue, 21 Jun 2016 13:18:21 -0700 > Bart Schaefer wrote: > > On Tue, Jun 21, 2016 at 12:39 PM, Michael Gebhard > > wrote: > > > > > > running the following commands and trying to complete the last line > > > by pressing tab produces a zsh taking up 100% cpu. > > > > > > zsh -f > > > touch foo.bar > > > alias -s bar='echo a &' > > > > It's not (just) completion; attempting to run the command "foo.bar" > > produces a similar infinite loop. You get it with ";", too, which is easier to test. > I suppose we'd need some way of marking something as having had a suffix > alias expanded before it, and then we'd need to reset that flag if we > encountered something not at the start of that input that was in command > position so we could expand a new suffix alias. After enough failed attempts, the right way presented itself. We can make this near enough to the normal alias case by attaching the alias to be expanded (where we record the fact it's in use) to the argument, not to the alias expansion itself. The input stack that's recording this doesn't care, and this makes it look pretty much exactly like the normal case. Obviously, this now gives "command not found" on the re-executed suffix argument, which is the only sensible alternative to recursion. pws diff --git a/Src/lex.c b/Src/lex.c index e36a01e..5ad3474 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1842,10 +1842,11 @@ checkalias(void) if ((suf = strrchr(zshlextext, '.')) && suf[1] && suf > zshlextext && suf[-1] != Meta && (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) && - !an->inuse && incmdpos) { - inpush(dupstring(zshlextext), INP_ALIAS, NULL); + !an->inuse && incmdpos && + !(inbufflags & INP_ALSUFF)) { + inpush(dupstring(zshlextext), INP_ALIAS, an); inpush(" ", INP_ALIAS, NULL); - inpush(an->text, INP_ALIAS, an); + inpush(an->text, INP_ALIAS, NULL); lexstop = 0; return 1; } diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst index 49e4756..1e09cd3 100644 --- a/Test/A02alias.ztst +++ b/Test/A02alias.ztst @@ -104,3 +104,9 @@ >0 ?(eval):2: invalid alias 'x=y' encountered while printing aliases # Currently, 'alias -L' returns 0 in this case. Perhaps it should return 1. + + alias -s mysuff='print -r "You said it.";' + eval 'thingummy.mysuff' +127:No endless loop with suffix alias in command position +>You said it. +?(eval):1: command not found: thingummy.mysuff