From 5591e2adb1f7c8d68c91bc18d8d3e6f01e9837eb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 15:12:24 +0000 Subject: [PATCH] driver: Rewrite without a state variable Suggested-by: m0viefreak --- zsh-syntax-highlighting.zsh | 41 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4300bed..e6070c0 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -86,13 +86,6 @@ _zsh_highlight__function_callable_p() { fi } -integer zsh_highlight_use_redrawhook -if _zsh_highlight__function_callable_p add-zle-hook-widget -then - autoload -U add-zle-hook-widget - (( zsh_highlight_use_redrawhook=1 )) -fi - # ------------------------------------------------------------------------------------------------- # Core highlighting update system # ------------------------------------------------------------------------------------------------- @@ -274,7 +267,23 @@ _zsh_highlight_call_widget() _zsh_highlight } -if true; then +if _zsh_highlight__function_callable_p add-zle-hook-widget +then + autoload -U add-zle-hook-widget + _zsh_highlight__zle-line-finish() { + # Reset $WIDGET since the 'main' highlighter depends on it. + # + # A nested function is required to hide zle parameters; see + # "User-defined widgets" in zshall. + () { + local -h +r WIDGET=zle-line-finish + _zsh_highlight "$@" + } "$@" + } + _zsh_highlight_bind_widgets(){} + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish +else # Rebind all ZLE widgets to make them invoke _zsh_highlights. _zsh_highlight_bind_widgets() { @@ -321,22 +330,6 @@ if true; then } fi -if (( $zsh_highlight_use_redrawhook )); then - _zsh_highlight__zle-line-finish() { - # Reset $WIDGET since the 'main' highlighter depends on it. - # - # A nested function is required to hide zle parameters; see - # "User-defined widgets" in zshall. - () { - local -h +r WIDGET=zle-line-finish - _zsh_highlight "$@" - } "$@" - } - _zsh_highlight_bind_widgets(){} - add-zle-hook-widget zle-line-pre-redraw _zsh_highlight - add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish -fi - # Load highlighters from directory. # # Arguments: