Skip to content

Commit

Permalink
'driver': Don't highlight in isearch
Browse files Browse the repository at this point in the history
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 zsh-users#257.
  • Loading branch information
m0vie committed Jun 20, 2016
1 parent 8dfe7b0 commit 56b81a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ custom widgets have been created (i.e., after all `zle -N` calls and after
running `compinit`). Widgets created later will work, but will not update the
syntax highlighting.

### Why does syntax highlighting not work while searching history?

In `zsh` versions before 5.3 is not possible for `zsh-syntax-highlighting.zsh`
to know if an incremental search is currently active and that matched parts of the
buffer should be underlined (or otherwise highlighted). Therefore, it is not possible
for `zsh-syntax-highlighting.zsh` to apply syntax highlighting and to underline the
matched part of the search. While searching the history, the latter is more important,
so syntax highlighting is disabled in this case.

### How are new releases announced?

There is currently no "push" announcements channel. However, the following
Expand Down
12 changes: 12 additions & 0 deletions zsh-syntax-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ _zsh_highlight()
# Store the previous command return code to restore it whatever happens.
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?'
# and http://www.zsh.org/mla/users/2016/msg00415.html.
if [[ $WIDGET == zle-isearch-update ]]; then
region_highlight=()
return $ret
fi

setopt localoptions warncreateglobal
setopt localoptions noksharrays
local REPLY # don't leak $REPLY into global scope
Expand Down Expand Up @@ -243,6 +251,10 @@ _zsh_highlight_bind_widgets()
# 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
for cur_widget in $widgets_to_bind; do
case $widgets[$cur_widget] in
Expand Down

0 comments on commit 56b81a9

Please sign in to comment.