diff options
author | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2001-04-02 11:13:30 +0000 |
---|---|---|
committer | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2001-04-02 11:13:30 +0000 |
commit | 9e1b9444345b9a48e4172d7e01b48c62bd253dfa (patch) | |
tree | ea7113a6d316b60c36783d4664279c5118c2e387 /Completion | |
parent | 41ffadf78ffb41447573122f3e2995b775569620 (diff) | |
download | zsh-9e1b9444345b9a48e4172d7e01b48c62bd253dfa.tar.gz zsh-9e1b9444345b9a48e4172d7e01b48c62bd253dfa.tar.xz zsh-9e1b9444345b9a48e4172d7e01b48c62bd253dfa.zip |
moved from Completion/Core/_funcall
Diffstat (limited to 'Completion')
-rw-r--r-- | Completion/Base/Utility/_call_function | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Completion/Base/Utility/_call_function b/Completion/Base/Utility/_call_function new file mode 100644 index 000000000..342f3509e --- /dev/null +++ b/Completion/Base/Utility/_call_function @@ -0,0 +1,32 @@ +#autoload + +# Utility function to call a function if it exists. +# +# Usage: _call_function <return> <name> [ <args> ... ] +# +# If a function named <name> is defined (or defined to be autoloaded), +# it is called. If <return> is given not the string `-' or empty, it is +# taken as the name of a parameter and the return status of the function +# called is stored in this parameter. All other arguments are given +# to the function called. +# The return value of this function is zero if the function was +# called and non-zero otherwise. + +local _name _ret + +[[ "$1" != (|-) ]] && _name="$1" + +shift + +if (( $+functions[$1] )); then + "$@" + _ret="$?" + + [[ -n "$_name" ]] && eval "${_name}=${_ret}" + + compstate[restore]='' + + return 0 +fi + +return 1 |