From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Minor bug(s) with NO_MULTI_FUNC_DEF
Date: Mon, 6 Jun 2022 16:53:20 +0100 (BST) [thread overview]
Message-ID: <872369693.652069.1654530800982@mail2.virginmedia.com> (raw)
In-Reply-To: <136424222.632634.1654505131089@mail2.virginmedia.com>
> On 06 June 2022 at 09:45 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:>
> > To be more precise ... we still don't need to do it differently based
> > on the option, but we might need to retain the "name()" format when
> > it's not affected by the option.
>
> Hmm, this is a real issue. As NO_MULTI_FUNC_DEF is in effect
> for sh emulation, we could in fact tie it to the option. But your
> suggestion has a much lower effect on output of compiled shell code, so that
> could be the way to go.
This looks easy.
pws
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 5e673eb5c..bf73664c9 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1884,6 +1884,11 @@ fn2)var(...)tt(LPAR()RPAR())'; if the option is not set, this causes
a parse error. Definition of multiple functions with the tt(function)
keyword is always allowed. Multiple function definitions are not often
used and can cause obscure errors.
+
+Note that no error is raised if multiple functions are defined as a
+result of a set of names that were originally read as a single word on
+the command line, for example `tt(TRAP{INT,QUIT})'. Although there are
+no plans to change this behaviour at present, it is not guaranteed.
)
pindex(MULTIOS)
pindex(NO_MULTIOS)
diff --git a/Src/text.c b/Src/text.c
index 5cd7685fd..56127c457 100644
--- a/Src/text.c
+++ b/Src/text.c
@@ -578,11 +578,16 @@ gettext2(Estate state)
Wordcode end = p + WC_FUNCDEF_SKIP(code);
int nargs = *state->pc++;
+ if (nargs > 1)
+ taddstr("function ");
taddlist(state, nargs);
if (nargs)
taddstr(" ");
if (tjob) {
- taddstr("() { ... }");
+ if (nargs > 1)
+ taddstr("{ ... }");
+ else
+ taddstr("() { ... }");
state->pc = end;
if (!nargs) {
/*
@@ -594,7 +599,10 @@ gettext2(Estate state)
}
stack = 1;
} else {
- taddstr("() {");
+ if (nargs > 1)
+ taddstr("{");
+ else
+ taddstr("() {");
tindent++;
taddnl(1);
n = tpush(code, 1);
diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst
index af469c527..b8509b25c 100644
--- a/Test/C04funcdef.ztst
+++ b/Test/C04funcdef.ztst
@@ -53,6 +53,26 @@
>b: redirection
>a: redirection
+ define_multiple() {
+ fn1 fn2 fn3() {
+ print This is $0
+ }
+ }
+ which -x2 define_multiple
+ define_multiple
+ fn1
+ fn2
+ fn3
+0: Safe output of multiple function definitions
+>define_multiple () {
+> function fn1 fn2 fn3 {
+> print This is $0
+> }
+>}
+>This is fn1
+>This is fn2
+>This is fn3
+
functions -M m1
m1() { (( $# )) }
print $(( m1() ))
next prev parent reply other threads:[~2022-06-06 15:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 20:31 Bart Schaefer
2022-05-31 9:03 ` Peter Stephenson
2022-05-31 17:07 ` Bart Schaefer
2022-05-31 17:14 ` Bart Schaefer
2022-06-06 8:45 ` Peter Stephenson
2022-06-06 15:53 ` Peter Stephenson [this message]
2022-06-02 10:23 ` Daniel Shahaf
2022-06-02 15:23 ` Bart Schaefer
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=872369693.652069.1654530800982@mail2.virginmedia.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).