diff options
author | Frank Terbeck <bewater@users.sourceforge.net> | 2011-03-30 21:17:07 +0000 |
---|---|---|
committer | Frank Terbeck <bewater@users.sourceforge.net> | 2011-03-30 21:17:07 +0000 |
commit | abe0ee3936c7f4a291666af3a9d70ed2a6d710f4 (patch) | |
tree | 8298dd598fd7d7ce375c13473e780c0c6e4259c5 | |
parent | d7bcf2bb96047aa6a00d59885d1343ef4e0db54f (diff) | |
download | zsh-abe0ee3936c7f4a291666af3a9d70ed2a6d710f4.tar.gz zsh-abe0ee3936c7f4a291666af3a9d70ed2a6d710f4.tar.xz zsh-abe0ee3936c7f4a291666af3a9d70ed2a6d710f4.zip |
28960: Add functions to add/remove static hooks.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Doc/Zsh/contrib.yo | 28 | ||||
-rw-r--r-- | Functions/VCS_Info/.distfiles | 2 | ||||
-rw-r--r-- | Functions/VCS_Info/vcs_info | 2 | ||||
-rw-r--r-- | Functions/VCS_Info/vcs_info_hookadd | 22 | ||||
-rw-r--r-- | Functions/VCS_Info/vcs_info_hookdel | 45 |
6 files changed, 104 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog index a18ac7163..808344d2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,11 @@ * 28958: Functions/VCS_Info/VCS_INFO_hook: Support registering hooks independent of the context. + * 28960: Doc/Zsh/contrib.yo, Functions/VCS_Info/.distfiles, + Functions/VCS_Info/vcs_info, Functions/VCS_Info/vcs_info_hookadd, + Functions/VCS_Info/vcs_info_hookdel: Add functions to add/remove + static hooks. + 2011-03-29 Mikael Magnusson <mikachu@gmail.com> * unposted: Completion/Unix/Command/_vim: Fix typo in @@ -14402,5 +14407,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5236 $ +* $Revision: 1.5237 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 81167bf3e..5c82c5d46 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1117,6 +1117,24 @@ tt(Variable description) below). If an argument is given, that string will be used instead of tt(default) in the tt(user-context) field of the style context. ) +findex(vcs_info_hookadd) +item(tt(vcs_info_hookadd))( +Statically registers a number of functions to a given hook. The hook needs +to be given as the first argument; what follows is a list of hook-function +names to register to the hook. The `tt(+vi-)' prefix needs to be left out +here. See tt(Hooks in vcs_info) below for details. +) +findex(vcs_info_hookdel) +item(tt(vcs_info_hookdel))( +Remove hook-functions from a given hook. The hook needs to be given as the +first non-option argument; what follows is a list of hook-function +names to un-register from the hook. If `tt(-a)' is used as the first +argument, tt(all) occurances of the functions are unregistered. Otherwise +only the last occurance is removed (if a function was registered to a hook +more than once) . The `tt(+vi-)' prefix needs to be left out here. See +tt(Hooks in vcs_info) below for details. +) +findex(vcs_info_lastmsg) item(tt(vcs_info_lastmsg))( Outputs the last var(${vcs_info_msg_*_}) value. Takes into account the value of the tt(use-prompt-escapes) style in @@ -1129,6 +1147,7 @@ Prints a list of all supported version control systems. Useful to find out possible contexts (and which of them are enabled) or values for the var(disable) style. ) +findex(vcs_info_setsys) item(tt(vcs_info_setsys))( Initializes var(vcs_info)'s internal list of available backends. With this function, you can add support for new VCSs @@ -1176,13 +1195,20 @@ avoid namespace problems, all registered function names are prepended by a `+vi-', so the actual functions called for the `foo' hook are `tt(+vi-bar)' and `tt(+vi-baz)'. +If you would like to register a function to a hook regardless of the +current context, you may use the var(vcs_info_hookadd) function. To remove +a function that was added like that, the var(vcs_info_hookdel) function +can be used. + If something seems weird, you can enable the `debug' boolean style in the proper context and the hook-calling code will print what it tried to execute and whether the function in question existed. When you register more than one function to a hook, all functions are executed one after another until one function returns non-zero or until -all functions have been called. +all functions have been called. Context-sensitive hook functions are +executed tt(before) statically registered ones (the ones added by +var(vcs_info_hookadd)). You may pass data between functions via an associative array, tt(user_data). For example: diff --git a/Functions/VCS_Info/.distfiles b/Functions/VCS_Info/.distfiles index 988e7ada4..b6e55d2fc 100644 --- a/Functions/VCS_Info/.distfiles +++ b/Functions/VCS_Info/.distfiles @@ -1,6 +1,8 @@ DISTFILES_SRC=' .distfiles vcs_info +vcs_info_hookadd +vcs_info_hookdel VCS_INFO_adjust VCS_INFO_bydir_detect VCS_INFO_check_com diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info index 6ce1cd702..385a451da 100644 --- a/Functions/VCS_Info/vcs_info +++ b/Functions/VCS_Info/vcs_info @@ -26,6 +26,8 @@ static_functions=( VCS_INFO_reposub VCS_INFO_set + vcs_info_hookadd + vcs_info_hookdel vcs_info_lastmsg vcs_info_printsys vcs_info_setsys diff --git a/Functions/VCS_Info/vcs_info_hookadd b/Functions/VCS_Info/vcs_info_hookadd new file mode 100644 index 000000000..867f7e271 --- /dev/null +++ b/Functions/VCS_Info/vcs_info_hookadd @@ -0,0 +1,22 @@ +## vim:ft=zsh +## Written by Frank Terbeck <ft@bewatermyfriend.org> +## Distributed under the same BSD-ish license as zsh itself. + +emulate -L zsh +setopt extendedglob + +if (( ${#argv} < 2 )); then + print 'usage: vcs_info_hookadd <HOOK> <FUNCTION(s)...>' + return 1 +fi + +local hook func context +local -a old + +hook=$1 +shift +context=":vcs_info-static_hooks:${hook}" + +zstyle -a "${context}" hooks old +zstyle "${context}" hooks "${old[@]}" "$@" +return $? diff --git a/Functions/VCS_Info/vcs_info_hookdel b/Functions/VCS_Info/vcs_info_hookdel new file mode 100644 index 000000000..e09a0575e --- /dev/null +++ b/Functions/VCS_Info/vcs_info_hookdel @@ -0,0 +1,45 @@ +## vim:ft=zsh +## Written by Frank Terbeck <ft@bewatermyfriend.org> +## Distributed under the same BSD-ish license as zsh itself. + +emulate -L zsh +setopt extendedglob + +local -i all + +if [[ "x$1" == 'x-a' ]]; then + all=1 + shift +else + all=0 +fi + +if (( ${#argv} < 2 )); then + print 'usage: vcs_info_hookdel [-a] <HOOK> <FUNCTION(s)...>' + return 1 +fi + +local hook func context +local -a old + +hook=$1 +shift +context=":vcs_info-static_hooks:${hook}" + +zstyle -a "${context}" hooks old || return 0 +for func in "$@"; do + if [[ -n ${(M)old:#$func} ]]; then + old[(Re)$func]=() + else + printf 'Not statically registered to `%s'\'': "%s"\n' \ + "${hook}" "${func}" + continue + fi + if (( all )); then + while [[ -n ${(M)old:#$func} ]]; do + old[(Re)$func]=() + done + fi +done +zstyle "${context}" hooks "${old[@]}" +return $? |