From a8582ff9f9573865de018115860d773d99a2dac5 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 21:56:57 +0200 Subject: [PATCH] always bind zle-line-finish and use it instead of accept-* Special handling for cursor imprint or partial path highlighting is needed in more cases than accept-*. For example when accepting a line from isearch, no accept-* widget is invoked. The proper way is to use zle-line-finish. Trumps #259. Fixes #284. --- highlighters/cursor/cursor-highlighter.zsh | 7 +++---- highlighters/main/main-highlighter.zsh | 7 +++---- highlighters/main/test-data/path_prefix2.zsh | 2 +- zsh-syntax-highlighting.zsh | 5 +++++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/highlighters/cursor/cursor-highlighter.zsh b/highlighters/cursor/cursor-highlighter.zsh index 5685c4029..5d61a8e6f 100644 --- a/highlighters/cursor/cursor-highlighter.zsh +++ b/highlighters/cursor/cursor-highlighter.zsh @@ -34,15 +34,14 @@ # Whether the cursor highlighter should be called or not. _zsh_highlight_cursor_highlighter_predicate() { - # accept-* may trigger removal of cursor highlighting - [[ $WIDGET == accept-* ]] || - _zsh_highlight_cursor_moved + # remove cursor highlighting when the line is finished + [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved } # Cursor highlighting function. _zsh_highlight_cursor_highlighter() { - [[ $WIDGET == accept-* ]] && return + [[ $WIDGET == zle-line-finish ]] && return region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]") } diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2f432553b..c29321294 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -60,9 +60,8 @@ # Whether the highlighter should be called or not. _zsh_highlight_main_highlighter_predicate() { - # accept-* may trigger removal of path_prefix highlighting - [[ $WIDGET == accept-* ]] || - _zsh_highlight_buffer_modified + # may need to remove path_prefix highlighting when the line ends + [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified } # Helper to deal with tokens crossing line boundaries. @@ -486,7 +485,7 @@ _zsh_highlight_main_highlighter_check_path() # If this word ends the buffer, check if it's the prefix of a valid path. if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] && - [[ $WIDGET != accept-* ]]; then + [[ $WIDGET != zle-line-finish ]]; then local -a tmp tmp=( ${expanded_path}*(N) ) (( $#tmp > 0 )) && style_override=path_prefix && return 0 diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh index bd6990c5b..f09572041 100644 --- a/highlighters/main/test-data/path_prefix2.zsh +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -32,7 +32,7 @@ ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight BUFFER='ls /bin/s' -WIDGET=accept-line +WIDGET=zle-line-finish expected_region_highlight=( "4 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # /bin/s diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 0b99f8189..634bbc24f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -308,6 +308,11 @@ _zsh_highlight_bind_widgets || { return 1 } +# Always wrap special zle-line-finish widget. This is needed to decide if the +# current line ends and special highlighting logic needs to be applied. +# E.g. remove cursor imprint, don't highlight partial paths, ... +_zsh_highlight_set_or_wrap_special_zle_widget zle-line-finish + # 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