plugin.zsh,*mod*body,*atload-handler: Make *-mod-function-body autoload

This commit is contained in:
Sebastian Gniazdowski 2019-09-25 05:16:55 +02:00
parent 0ef896d158
commit 061d8073dc
3 changed files with 24 additions and 22 deletions

23
.za-bgn-mod-function-body Normal file
View file

@ -0,0 +1,23 @@
# Copyright (c) 2019 Sebastian Gniazdowski
# License MIT
#
# Returns the body of the function wrapping a function
local name="$1" target_func="$2" dir="$3"
integer set_gem_home="$4" set_node_path="$5" set_cwd="$6"
if [[ "$name" = "$target_func" ]]; then
target_func="${target_func}--za-bgn-orig"
functions[$target_func]="${functions[$name]}"
fi
REPLY="function $name {
${${(M)set_gem_home:#1}:+local -x GEM_HOME=${(qqq)dir}}
${${(M)set_node_path:#1}:+local -x NODE_PATH=${(qqq)dir}/node_modules}
${${(M)set_cwd:#1}:+"local oldpwd=${(qqq)PWD}
() { setopt localoptions noautopushd; builtin cd -q ${(qqq)dir}; }"}
${(qqq)target_func} \"\$@\"
${${(M)set_cwd:#1}:+"() { setopt localoptions noautopushd; builtin cd -q \"\$oldpwd\"; }"}
}"
# vim:ft=zsh:sw=4:sts=4:et

View file

@ -48,28 +48,6 @@ local nl=$'\n'
return 0
} # }}}
# FUNCTION: .za-bgn-mod-function-body {{{
# Returns the body of the function wrapping a function
.za-bgn-mod-function-body() {
local name="$1" target_func="$2" dir="$3"
integer set_gem_home="$4" set_node_path="$5" set_cwd="$6"
if [[ "$name" = "$target_func" ]]; then
target_func="${target_func}--za-bgn-orig"
functions[$target_func]="${functions[$name]}"
fi
REPLY="function $name {
${${(M)set_gem_home:#1}:+local -x GEM_HOME=${(qqq)dir}}
${${(M)set_node_path:#1}:+local -x NODE_PATH=${(qqq)dir}/node_modules}
${${(M)set_cwd:#1}:+"local oldpwd=${(qqq)PWD}
() { setopt localoptions noautopushd; builtin cd -q ${(qqq)dir}; }"}
${(qqq)target_func} \"\$@\"
${${(M)set_cwd:#1}:+"() { setopt localoptions noautopushd; builtin cd -q \"\$oldpwd\"; }"}
}"
}
# }}}
#
# gem'' ice
#

View file

@ -8,6 +8,7 @@
0="${${(M)0:#/*}:-$PWD/$0}"
autoload .za-bgn-bin-or-src-function-body \
.za-bgn-mod-function-body \
:za-bgn-atload-handler :za-bgn-atclone-handler \
:za-bgn-atpull-handler :za-bgn-help-handler \
:za-bgn-atdelete-handler