Skip to content

Commit 5d9b3e7

Browse files
committed
'driver': Don't highlight in isearch
zsh version 5.2 and lower don't support ISEARCHMATCH_ACTIE and we are unable to re-apply zle_highlight on top. Therefore it is impossible to see the underlined matched area. Since that information is more important, completely disable highlighting in isearch in that case. To do that, we need to make sure we are actually called when something changes in isearch. Trumps #257.
1 parent 276d31e commit 5d9b3e7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ custom widgets have been created (i.e., after all `zle -N` calls and after
3232
running `compinit`). Widgets created later will work, but will not update the
3333
syntax highlighting.
3434

35+
### Why does syntax highlighting not work while searching history?
36+
37+
In `zsh` versions before 5.3 is not possible for `zsh-syntax-highlighting.zsh`
38+
to know if an incremental search is currently active and that matched parts of the
39+
buffer should be underlined (or otherwise highlighted). Therefore, it is not possible
40+
for `zsh-syntax-highlighting.zsh` to apply syntax highlighting and to underline the
41+
matched part of the search. While searching the history, the latter is more important,
42+
so syntax highlighting is disabled in this case.
43+
3544
### How are new releases announced?
3645

3746
There is currently no "push" announcements channel. However, the following

zsh-syntax-highlighting.zsh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ _zsh_highlight()
5858
# Store the previous command return code to restore it whatever happens.
5959
local ret=$?
6060

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+
# and http://www.zsh.org/mla/users/2016/msg00415.html.
64+
if [[ $WIDGET == zle-isearch-update ]]; then
65+
region_highlight=()
66+
return $ret
67+
fi
68+
6169
setopt localoptions warncreateglobal
6270
setopt localoptions noksharrays
6371
local REPLY # don't leak $REPLY into global scope
@@ -243,6 +251,10 @@ _zsh_highlight_bind_widgets()
243251
# E.g. remove cursor imprint, don't highlight partial paths, ...
244252
widgets_to_bind+=(zle-line-finish)
245253

254+
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
255+
# This is needed because we need to disable highlighting in that case.
256+
widgets_to_bind+=(zle-isearch-update)
257+
246258
local cur_widget
247259
for cur_widget in $widgets_to_bind; do
248260
case $widgets[$cur_widget] in

0 commit comments

Comments
 (0)