Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Completion: Improve _man (3)



On Fri, Jun 15, 2018 at 4:55 PM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> Mikael Magnusson wrote on Fri, Jun 15, 2018 at 16:39:36 +0200:
>> Please don't use () for 1 {} a b c style loops in actual scripts, it
>> is not guaranteed to work. Instead, use () { for 1 { } } a b c which
>> is the documented syntax.
>
> Now that you mention it, I think completion functions may not use shortloops
> syntax: compinit doesn't reset that option.
>
> That _still_ leaves us with a «for 1» loop, which I'm not actually sure is a
> documented syntax, but it's useful enough that I'd welcome a regression test
> for it.

It isn't shortloops syntax, but it exploits the fact that writing a
for loop with braces also tells the anonymous function parser that the
function definition ends while not ending the command itself. Leaving
out the 'in a b c' or '(a b c)' part is documented as using the
positional arguments, and works in dash as well. Using 1 as the loop
variable doesn't work in dash, and is possibly somewhat questionable,
but I don't see why we would ever break that, and it saves a 'local'.

Dana wrote:
> Someone on IRC told me it was safe :(

It probably is, but if someone ever decides to rewrite the parser, it
might be hard to retain this particular quirk. When you asked, you
didn't say it was for a to-be distributed completion script :).

Peter wrote:
> It is certainly a long-standing general expectation that variant syntax
> is avoided in widely distributed shell code as it's both a confusion and
> a possible source of problems with people's own option settings

Is it actually possible to disable the alternative syntax? In any
case, it might be nicer to do
() { for 1; do ..stuff..; done } $sects
or even
() { local sect; for sect; do ..stuff..; done } $sects
or even even
() { local sect; for sect in $sects; do ..stuff..; done }

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author