mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-12 01:11:27 +02:00
26973: zmathfuncdef enhancements
This commit is contained in:
parent
cac27544ff
commit
ad3d514ac7
2 changed files with 25 additions and 4 deletions
|
@ -2371,7 +2371,7 @@ enditem()
|
||||||
See the comments in the function for a few extra tips.
|
See the comments in the function for a few extra tips.
|
||||||
)
|
)
|
||||||
findex(zmathfuncdef)
|
findex(zmathfuncdef)
|
||||||
item(tt(zmathfuncdef) var(mathfunc) [ var(body) ])(
|
item(tt(zmathfuncdef) [ var(mathfunc) [ var(body) ] ])(
|
||||||
A convenient front end to tt(functions -M).
|
A convenient front end to tt(functions -M).
|
||||||
|
|
||||||
With two arguments, define a mathematical function named var(mathfunc)
|
With two arguments, define a mathematical function named var(mathfunc)
|
||||||
|
@ -2383,10 +2383,15 @@ to refer to optional parameters. Note that the forms must be
|
||||||
strictly adhered to for the function to calculate the correct number
|
strictly adhered to for the function to calculate the correct number
|
||||||
of arguments. The implementation is held in a shell function named
|
of arguments. The implementation is held in a shell function named
|
||||||
tt(zsh_math_func_)var(mathfunc); usually the user will not need
|
tt(zsh_math_func_)var(mathfunc); usually the user will not need
|
||||||
to refer to the shell function directly.
|
to refer to the shell function directly. Any existing function
|
||||||
|
of the same name is silently replaced.
|
||||||
|
|
||||||
With one argument, remove the mathematical function var(mathfunc)
|
With one argument, remove the mathematical function var(mathfunc)
|
||||||
as well as the shell function implementation.
|
as well as the shell function implementation.
|
||||||
|
|
||||||
|
With no arguments, list all var(mathfunc) functions in a form
|
||||||
|
suitable for restoring the definition.
|
||||||
|
The functions have not necessarily been defined by tt(zmathfuncdef).
|
||||||
)
|
)
|
||||||
enditem()
|
enditem()
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,34 @@
|
||||||
|
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
setopt extendedglob
|
setopt extendedglob
|
||||||
|
local -a match mbegin mend line
|
||||||
|
local func
|
||||||
|
|
||||||
if (( $# < 1 || $# > 2 )); then
|
if (( $# > 2 )); then
|
||||||
print "Usage: $0 name [body]" >&2
|
print "Usage: $0 [name [body]]" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
zmodload -i zsh/parameter || return 1
|
||||||
|
|
||||||
|
if (( $# == 0 )); then
|
||||||
|
functions -M | while read -A line; do
|
||||||
|
func=${functions[$line[6]]}
|
||||||
|
if [[ $func = (#b)[[:space:]]#\(\([[:space:]]#(*[^[:space:]])[[:space:]]#\)\) ]]; then
|
||||||
|
print "zmathfuncdef $line[3] ${(qq)match[1]}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local mname=$1
|
local mname=$1
|
||||||
local fname="zsh_math_func_$1"
|
local fname="zsh_math_func_$1"
|
||||||
|
|
||||||
if (( $# == 1 )); then
|
if (( $# == 1 )); then
|
||||||
functions +M $mname && unfunction $fname
|
functions +M $mname && unfunction $fname
|
||||||
return 0
|
return 0
|
||||||
|
elif [[ -n $functions[$fname] ]]; then
|
||||||
|
functions +M $mname
|
||||||
fi
|
fi
|
||||||
|
|
||||||
integer iarg=0 ioptarg
|
integer iarg=0 ioptarg
|
||||||
|
|
Loading…
Reference in a new issue