mirror of
https://github.com/zsh-users/zsh
synced 2024-10-04 15:09:11 +00:00
Tweaks to MULTI_FUNC_DEF
Output multiple function definitions using "function" form. Note exceptions to errors with NO_MULTI_FUNC_DEF
This commit is contained in:
parent
a99f96797f
commit
b26b6b3fe0
|
@ -1,3 +1,9 @@
|
||||||
|
2022-06-07 Peter Stephenson <p.stephenson@samsung.com>
|
||||||
|
|
||||||
|
* 50339: Doc/Zsh/options.yo, Src/text.c, Test/C04funcdef.ztst:
|
||||||
|
Make multiple function output safer with NO_MULTI_FUNC_DEF and
|
||||||
|
document exceptions to errors raised by MULTI_FUNC_DEF.
|
||||||
|
|
||||||
2022-06-04 Bart Schaefer <schaefer@zsh.org>
|
2022-06-04 Bart Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
* 50323: Completion/Base/Utility/_shadow (new file),
|
* 50323: Completion/Base/Utility/_shadow (new file),
|
||||||
|
|
|
@ -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)
|
a parse error. Definition of multiple functions with the tt(function)
|
||||||
keyword is always allowed. Multiple function definitions are not often
|
keyword is always allowed. Multiple function definitions are not often
|
||||||
used and can cause obscure errors.
|
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(MULTIOS)
|
||||||
pindex(NO_MULTIOS)
|
pindex(NO_MULTIOS)
|
||||||
|
|
12
Src/text.c
12
Src/text.c
|
@ -578,11 +578,16 @@ gettext2(Estate state)
|
||||||
Wordcode end = p + WC_FUNCDEF_SKIP(code);
|
Wordcode end = p + WC_FUNCDEF_SKIP(code);
|
||||||
int nargs = *state->pc++;
|
int nargs = *state->pc++;
|
||||||
|
|
||||||
|
if (nargs > 1)
|
||||||
|
taddstr("function ");
|
||||||
taddlist(state, nargs);
|
taddlist(state, nargs);
|
||||||
if (nargs)
|
if (nargs)
|
||||||
taddstr(" ");
|
taddstr(" ");
|
||||||
if (tjob) {
|
if (tjob) {
|
||||||
taddstr("() { ... }");
|
if (nargs > 1)
|
||||||
|
taddstr("{ ... }");
|
||||||
|
else
|
||||||
|
taddstr("() { ... }");
|
||||||
state->pc = end;
|
state->pc = end;
|
||||||
if (!nargs) {
|
if (!nargs) {
|
||||||
/*
|
/*
|
||||||
|
@ -594,7 +599,10 @@ gettext2(Estate state)
|
||||||
}
|
}
|
||||||
stack = 1;
|
stack = 1;
|
||||||
} else {
|
} else {
|
||||||
taddstr("() {");
|
if (nargs > 1)
|
||||||
|
taddstr("{");
|
||||||
|
else
|
||||||
|
taddstr("() {");
|
||||||
tindent++;
|
tindent++;
|
||||||
taddnl(1);
|
taddnl(1);
|
||||||
n = tpush(code, 1);
|
n = tpush(code, 1);
|
||||||
|
|
|
@ -53,6 +53,26 @@
|
||||||
>b: redirection
|
>b: redirection
|
||||||
>a: 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
|
functions -M m1
|
||||||
m1() { (( $# )) }
|
m1() { (( $# )) }
|
||||||
print $(( m1() ))
|
print $(( m1() ))
|
||||||
|
|
Loading…
Reference in a new issue