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.

This commit is contained in:
jimmijj 2014-10-04 00:36:01 +00:00
parent df99f5f61a
commit f728546b74

View File

@ -62,6 +62,31 @@ _zsh_highlight_main_highlighter_predicate()
_zsh_highlight_buffer_modified _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. # Main syntax highlighting function.
_zsh_highlight_main_highlighter() _zsh_highlight_main_highlighter()
{ {
@ -213,7 +238,7 @@ _zsh_highlight_main_highlighter_check_path()
local -a tmp local -a tmp
# got a path prefix? # got a path prefix?
tmp=( ${expanded_path}*(N) ) 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? # or maybe an approximate path?
tmp=( (#a1)${expanded_path}*(N) ) tmp=( (#a1)${expanded_path}*(N) )
(( $#arg > 3 && $#tmp > 0 )) && style_override=path_approx && return 0 (( $#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 [[ -d $expanded_arg ]] && return 1
[[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos ]] && matched_file=(${expanded_arg}*(Noa^/[1])) [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos ]] && matched_file=(${expanded_arg}*(Noa^/[1]))
[[ -e $expanded_arg || -e $matched_file ]] && lsstyle=none || return 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 [[ ! -z $ZSH_HIGHLIGHT_STYLES[file] ]] && lsstyle=$ZSH_HIGHLIGHT_STYLES[file] && return 0