From a6c1e86adf1dcf37d9c217faadb82cc153866686 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 22:13:46 +0200 Subject: [PATCH] don't highlight in isearch We are unable to re-apply zle_highlight on top in current zsh versions. 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. --- README.md | 9 +++++++++ zsh-syntax-highlighting.zsh | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index ac8beafab..feab82e80 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 634bbc24f..84508d609 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -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 @@ -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