@@ -58,6 +58,13 @@ _zsh_highlight()
58
58
# Store the previous command return code to restore it whatever happens.
59
59
local ret=$?
60
60
61
+ # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
62
+ # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
63
+ if [[ $WIDGET == zle-isearch-update ]]; then
64
+ region_highlight=()
65
+ return $ret
66
+ fi
67
+
61
68
setopt localoptions warncreateglobal
62
69
setopt localoptions noksharrays
63
70
local REPLY # don't leak $REPLY into global scope
@@ -250,8 +257,20 @@ _zsh_highlight_bind_widgets()
250
257
}
251
258
252
259
# Override ZLE widgets to make them invoke _zsh_highlight.
260
+ local -U widgets_to_bind
261
+ widgets_to_bind=(${${(k)widgets} :# (.* |orig-* |run-help|which-command|beep|set-local-history|yank)} )
262
+
263
+ # Always wrap special zle-line-finish widget. This is needed to decide if the
264
+ # current line ends and special highlighting logic needs to be applied.
265
+ # E.g. remove cursor imprint, don't highlight partial paths, ...
266
+ widgets_to_bind+=(zle-line-finish)
267
+
268
+ # Always wrap special zle-isearch-update widget to be notified of updates in isearch.
269
+ # This is needed because we need to disable highlighting in that case.
270
+ widgets_to_bind+=(zle-isearch-update)
271
+
253
272
local cur_widget
254
- for cur_widget in ${ ${(k)widgets} :# (. * |orig- * |run-help|which-command|beep|set-local-history|yank)} ; do
273
+ for cur_widget in $widgets_to_bind ; do
255
274
case $widgets [$cur_widget ] in
256
275
257
276
# Already rebound event: do nothing.
@@ -277,8 +296,15 @@ _zsh_highlight_bind_widgets()
277
296
builtin) eval " _zsh_highlight_widget_${(q)cur_widget} () { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$ @\" }"
278
297
zle -N $cur_widget _zsh_highlight_widget_$cur_widget ;;
279
298
299
+ # Incomplete or nonexistent widget: Bind to z-sy-h directly.
300
+ * )
301
+ if [[ $cur_widget == zle-* ]] && [[ -z $widgets [$cur_widget ] ]]; then
302
+ _zsh_highlight_widget_${cur_widget} () { : ; _zsh_highlight }
303
+ zle -N $cur_widget _zsh_highlight_widget_$cur_widget
304
+ else
280
305
# Default: unhandled case.
281
- * ) print -r -- >&2 " zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget '" ;;
306
+ print -r -- >&2 " zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget '"
307
+ fi
282
308
esac
283
309
done
284
310
}
0 commit comments