Skip to content

Commit

Permalink
Defined predicate_switcher function in order to be able to use main h…
Browse files Browse the repository at this point in the history
…ighlighter 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.
  • Loading branch information
jimmijj committed Oct 4, 2014
1 parent df99f5f commit f728546
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion highlighters/main/main-highlighter.zsh
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f728546

Please sign in to comment.