From: Mikael Magnusson <mikachu@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: dana <dana@dana.is>, Zsh workers <zsh-workers@zsh.org>
Subject: Re: [PATCH] Completion: Improve _man (3)
Date: Fri, 15 Jun 2018 19:27:57 +0200 [thread overview]
Message-ID: <CAHYJk3T5vhvDLA29N4-yZaOByqAEM10WGMK7t1LJOBj21izvtA@mail.gmail.com> (raw)
In-Reply-To: <20180615145536.phgtjn4hnxvbumn4@tarpaulin.shahaf.local2>
On Fri, Jun 15, 2018 at 4:55 PM, Daniel Shahaf <d.s@daniel.shahaf.name> 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
next prev parent reply other threads:[~2018-06-15 17:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-10 6:06 [PATCH] Completion: Improve _man dana
2018-06-10 13:07 ` Oliver Kiddle
2018-06-10 14:02 ` dana
2018-06-11 10:48 ` [PATCH] Completion: Improve _man (2) dana
2018-06-14 9:50 ` Daniel Shahaf
2018-06-14 10:20 ` dana
2018-06-15 13:59 ` [PATCH] Completion: Improve _man (3) dana
2018-06-15 14:05 ` Daniel Shahaf
2018-06-15 14:21 ` dana
2018-06-15 14:39 ` Mikael Magnusson
2018-06-15 14:55 ` Daniel Shahaf
2018-06-15 15:14 ` dana
2018-06-15 15:36 ` Peter Stephenson
2018-06-15 17:27 ` Mikael Magnusson [this message]
2018-06-15 14:47 ` Daniel Shahaf
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=CAHYJk3T5vhvDLA29N4-yZaOByqAEM10WGMK7t1LJOBj21izvtA@mail.gmail.com \
--to=mikachu@gmail.com \
--cc=d.s@daniel.shahaf.name \
--cc=dana@dana.is \
--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).