From ad3d514ac79b573ce43fa7089175de519f39f21d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 19 May 2009 15:33:24 +0000 Subject: 26973: zmathfuncdef enhancements --- Functions/Misc/zmathfuncdef | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'Functions/Misc/zmathfuncdef') diff --git a/Functions/Misc/zmathfuncdef b/Functions/Misc/zmathfuncdef index 21d3c249e..e5692e769 100644 --- a/Functions/Misc/zmathfuncdef +++ b/Functions/Misc/zmathfuncdef @@ -5,18 +5,34 @@ emulate -L zsh setopt extendedglob +local -a match mbegin mend line +local func -if (( $# < 1 || $# > 2 )); then - print "Usage: $0 name [body]" >&2 +if (( $# > 2 )); then + print "Usage: $0 [name [body]]" >&2 return 1 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 fname="zsh_math_func_$1" if (( $# == 1 )); then functions +M $mname && unfunction $fname return 0 +elif [[ -n $functions[$fname] ]]; then + functions +M $mname fi integer iarg=0 ioptarg -- cgit 1.4.1