From f728546b746d5d0b420f4ccf5d2783b7915f8bcd Mon Sep 17 00:00:00 2001 From: jimmijj Date: Sat, 4 Oct 2014 00:36:01 +0000 Subject: [PATCH] Defined predicate_switcher function in order to be able to use main highlighter when cursor has moved. Normally turning on this feature for the whole main highlighter is not advisable, however it is still helpful in edge cases and solves the problem with highlighting the prefix of the path and file. To prevent slowdown the predicate_switcher is defined in such a way that it activates main highlighter with respect to cursor movement just for one call, and after that returns automatically to the default mode, i.e. highlighting only after buffer is modified. --- highlighters/main/main-highlighter.zsh | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b0a1a6d..00b6a88 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -62,6 +62,31 @@ _zsh_highlight_main_highlighter_predicate() _zsh_highlight_buffer_modified } +## In case we need to highlight in other circumstances then default from highlighter_predicate lets define a switcher +_zsh_highlight_main_highlighter_predicate_switcher() +{ + case $1 in + 'b') # buffer + _zsh_highlight_main_highlighter_predicate() + { + _zsh_highlight_buffer_modified + };; + 'c') # cursor + _zsh_highlight_main_highlighter_predicate() + { + _zsh_highlight_cursor_moved + };; + 'bc') bccounter=0 # buffer and cursor + _zsh_highlight_main_highlighter_predicate() + { + bccounter=$((bccounter+1)) + (( $bccounter > 1 )) && _zsh_highlight_main_highlighter_predicate_switcher b + _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified + };; + *);; + esac +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -213,7 +238,7 @@ _zsh_highlight_main_highlighter_check_path() local -a tmp # got a path prefix? tmp=( ${expanded_path}*(N) ) - (( $#tmp > 0 )) && style_override=path_prefix && return 0 + (( $#tmp > 0 )) && style_override=path_prefix && _zsh_highlight_main_highlighter_predicate_switcher bc && return 0 # or maybe an approximate path? tmp=( (#a1)${expanded_path}*(N) ) (( $#arg > 3 && $#tmp > 0 )) && style_override=path_approx && return 0 @@ -319,6 +344,7 @@ _zsh_highlight_main_highlighter_check_file() [[ -d $expanded_arg ]] && return 1 [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos ]] && matched_file=(${expanded_arg}*(Noa^/[1])) [[ -e $expanded_arg || -e $matched_file ]] && lsstyle=none || return 1 + [[ -e $matched_file ]] && _zsh_highlight_main_highlighter_predicate_switcher bc [[ ! -z $ZSH_HIGHLIGHT_STYLES[file] ]] && lsstyle=$ZSH_HIGHLIGHT_STYLES[file] && return 0