zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [Pkg-zsh-devel] Bug#793168: zsh: expand-substitution-on-TAB broke for $(()) in 5.0.8 [origin: adi@hexapodia.org]
Date: Sat, 25 Jul 2015 21:30:16 +0100	[thread overview]
Message-ID: <20150725213016.5578c764@ntlworld.com> (raw)
In-Reply-To: <20150725201509.42d34c1d@ntlworld.com>

On Sat, 25 Jul 2015 20:15:09 +0100
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Sat, 25 Jul 2015 19:03:41 +0200
> Axel Beckert <abe@deuxchevaux.org> wrote:
> > with zsh 5.0.7 and earlier versions, if I type $((5*8)) and then hit TAB,
> > the expression is replaced with its evaluation ("40" in this case). The
> > same feature works with many different substitutions.
> > 
> > as of 5.0.8 TAB-substituting does not work with $(()) anymore.
> > 
> > It does still work right with "${VAR}" and "$[5+8]".
> I think the patch below fixes the expand-or-complete case.
> 
> The _expand case is in shell code.  The difference apparently
> comes from the fact that in the new code $(( ... )) gets
> tokenised such that the outer parentheses become Inparmath
> and Outparmath, while the inner parentheses don't get tokenised.

This fixes the standard quoting code, which is used by completion in a
slightly non-standard (surprised?) way, with tokens still present
in the string, so we can detect the math expression and avoid quoting it
further.  _expand now works.

This is evidently not how $[...] gets handled, but as we have syntactic
markers in the present case we might as well make use of them.

pws

diff --git a/Src/utils.c b/Src/utils.c
index 0acab88..f7aaaed 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5551,7 +5551,25 @@ quotestring(const char *s, char **e, int instring)
 		/* Needs to be passed straight through. */
 		if (dobackslash)
 		    *v++ = '\\';
-		*v++ = *u++;
+		if (*u == Inparmath) {
+		    /*
+		     * Already syntactically quoted: don't
+		     * add more.
+		     */
+		    int inmath = 1;
+		    *v++ = *u++;
+		    for (;;) {
+			char uc = *u;
+			*v++ = *u++;
+			if (uc == '\0')
+			    break;
+			else if (uc == Outparmath && !--inmath)
+			    break;
+			else if (uc == Inparmath)
+			    ++inmath;
+		    }
+		} else
+		    *v++ = *u++;
 		continue;
 	    }
 


      reply	other threads:[~2015-07-25 20:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-25 17:03 Fwd: " Axel Beckert
2015-07-25 18:54 ` Bart Schaefer
2015-07-25 19:15 ` Peter Stephenson
2015-07-25 20:30   ` 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=20150725213016.5578c764@ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).