Skip to content

Commit

Permalink
don't highlight in isearch
Browse files Browse the repository at this point in the history
Therefore we are unable to re-apply zle_highlight on top in
current zsh versions. Therefore it is impossible to see the
underlined matched area.

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 Apr 24, 2016
1 parent a8582ff commit 245a803
Show file tree
Hide file tree
Showing 2 changed files with 19 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 current `zsh` versions it 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
10 changes: 10 additions & 0 deletions zsh-syntax-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ _zsh_highlight()
# Store the previous command return code to restore it whatever happens.
local ret=$?

# Do not highlight in isearch (underlining done by zsh is more important in this case).
if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCH_ACTIVE )); 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 @@ -313,6 +319,10 @@ _zsh_highlight_bind_widgets || {
# E.g. remove cursor imprint, don't highlight partial paths, ...
_zsh_highlight_set_or_wrap_special_zle_widget zle-line-finish

# Always wrap special zle-isearch-update widget to be notified of updates in isearch
_zsh_highlight_set_or_wrap_special_zle_widget zle-isearch-update


# Resolve highlighters directory location.
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2
Expand Down

0 comments on commit 245a803

Please sign in to comment.