@ -58,6 +58,13 @@ _zsh_highlight()
# Store the previous command return code to restore it whatever happens.
# Store the previous command return code to restore it whatever happens.
local ret = $?
local ret = $?
# Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
# For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
if [ [ $WIDGET = = zle-isearch-update ] ] ; then
region_highlight = ( )
return $ret
fi
setopt localoptions warncreateglobal
setopt localoptions warncreateglobal
setopt localoptions noksharrays
setopt localoptions noksharrays
local REPLY # don't leak $REPLY into global scope
local REPLY # don't leak $REPLY into global scope
@ -250,8 +257,20 @@ _zsh_highlight_bind_widgets()
}
}
# Override ZLE widgets to make them invoke _zsh_highlight.
# Override ZLE widgets to make them invoke _zsh_highlight.
local -U widgets_to_bind
widgets_to_bind = ( ${ ${ (k)widgets } : #(.*|orig-*|run-help|which-command|beep|set-local-history|yank) } )
# Always wrap special zle-line-finish widget. This is needed to decide if the
# current line ends and special highlighting logic needs to be applied.
# E.g. remove cursor imprint, don't highlight partial paths, ...
widgets_to_bind += ( zle-line-finish)
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
# This is needed because we need to disable highlighting in that case.
widgets_to_bind += ( zle-isearch-update)
local cur_widget
local cur_widget
for cur_widget in ${ ${ (k)widgets } : #(.*|orig-*|run-help|which-command|beep|set-local-history|yank) } ; do
for cur_widget in $widgets_to_bind ; do
case $widgets [ $cur_widget ] in
case $widgets [ $cur_widget ] in
# Already rebound event: do nothing.
# Already rebound event: do nothing.
@ -277,8 +296,15 @@ _zsh_highlight_bind_widgets()
builtin ) eval " _zsh_highlight_widget_ ${ (q)cur_widget } () { _zsh_highlight_call_widget . ${ (q)cur_widget } -- \"\$@\" } "
builtin ) eval " _zsh_highlight_widget_ ${ (q)cur_widget } () { _zsh_highlight_call_widget . ${ (q)cur_widget } -- \"\$@\" } "
zle -N $cur_widget _zsh_highlight_widget_$cur_widget ; ;
zle -N $cur_widget _zsh_highlight_widget_$cur_widget ; ;
# Incomplete or nonexistent widget: Bind to z-sy-h directly.
*)
if [ [ $cur_widget = = zle-* ] ] && [ [ -z $widgets [ $cur_widget ] ] ] ; then
_zsh_highlight_widget_${ cur_widget } ( ) { :; _zsh_highlight }
zle -N $cur_widget _zsh_highlight_widget_$cur_widget
else
# Default: unhandled case.
# Default: unhandled case.
*) print -r -- >& 2 " zsh-syntax-highlighting: unhandled ZLE widget ' $cur_widget ' " ; ;
print -r -- >& 2 " zsh-syntax-highlighting: unhandled ZLE widget ' $cur_widget ' "
fi
esac
esac
done
done
}
}