zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: bug: suffix alias and tabcompletion
Date: Wed, 22 Jun 2016 12:53:24 +0100	[thread overview]
Message-ID: <20160622125324.44e00539@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20160622100159.1d82792f@pwslap01u.europe.root.pri>

On Wed, 22 Jun 2016 10:01:59 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Tue, 21 Jun 2016 13:18:21 -0700
> Bart Schaefer <schaefer@brasslantern.com> wrote:
> > On Tue, Jun 21, 2016 at 12:39 PM, Michael Gebhard
> > <michael.gebhard@fau.de> 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


      reply	other threads:[~2016-06-22 11:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-21 19:39 Michael Gebhard
2016-06-21 20:18 ` Bart Schaefer
2016-06-22  9:01   ` Peter Stephenson
2016-06-22 11:53     ` Peter Stephenson [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=20160622125324.44e00539@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --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).