Subject: Re: bufferwords() lexes a subshell in a shortloop repeat as a string
From: Peter Stephenson <[email-masked]>
To: [email-masked]
Date: Fri, 15 Jan 2016 09:41:17 +0000
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Fri, 15 Jan 2016 06:26:48 +0000
Daniel Shahaf <[email-masked]> wrote:
> The ${(z)} modifier gives me a subshell as a single unit:

It doesn't know it's a subshell; it doesn't know you want the first
character to be in command position.  It's not parsing the whole thing
as a command expression, it's just splitting words, and (... ...) indeed
works as a complete word:

% noglob print -l one (two three) four
one
(two three)
four

The noglob hints at why parentheses not in command position are treated
like that --- it's convenient for glob qualifiers.

Having the parenthesised expressions in the strings

'one (two three) four'

and

'(two three)'

split in different ways by the same function typically would be confusing,
though it depends what you're doing with the result.

It might be possible to add a flag to cause an expression you pass in to
be split as if it were a complete command line, not just an arbitrary
set of arguments, but that's a whole new ball game.

If you're trying to make the (z) work as a kind of eval without
execution, I think you're expecting too much.

pws