main: Allow for patterned fallbacks

This commit is contained in:
Matthew Martin 2018-03-12 19:34:25 -05:00
parent 2fd7fbc3c2
commit 8a0ffe1c43

View file

@ -67,37 +67,34 @@ _zsh_highlight_main_add_region_highlight() {
integer start=$1 end=$2 integer start=$1 end=$2
shift 2 shift 2
if (( $+argv[2] )); then # Automate inheritance.
# Caller specified inheritance explicitly. typeset -A fallback_of; fallback_of=(
else alias arg0
# Automate inheritance. suffix-alias arg0
typeset -A fallback_of; fallback_of=( builtin arg0
alias arg0 function arg0
suffix-alias arg0 command arg0
builtin arg0 precommand arg0
function arg0 hashed-command arg0
command arg0 arg0_\* arg0
precommand arg0
hashed-command arg0
path_prefix path path_prefix path
# The path separator fallback won't ever be used, due to the optimisation # The path separator fallback won't ever be used, due to the optimisation
# in _zsh_highlight_main_highlighter_highlight_path_separators(). # in _zsh_highlight_main_highlighter_highlight_path_separators().
path_pathseparator path path_pathseparator path
path_prefix_pathseparator path_prefix path_prefix_pathseparator path_prefix
single-quoted-argument{-unclosed,} single-quoted-argument{-unclosed,}
double-quoted-argument{-unclosed,} double-quoted-argument{-unclosed,}
dollar-quoted-argument{-unclosed,} dollar-quoted-argument{-unclosed,}
back-quoted-argument{-unclosed,} back-quoted-argument{-unclosed,}
) )
local needle=$1 value local needle=$1 value
while [[ -n ${value::=$fallback_of[$needle]} ]]; do while [[ -n ${value::=$fallback_of[(k)$needle]} ]]; do
unset "fallback_of[$needle]" # paranoia against infinite loops unset "fallback_of[$needle]" # paranoia against infinite loops
argv+=($value) argv+=($value)
needle=$value needle=$value
done done
fi
# The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is
# relative to $BUFFER. # relative to $BUFFER.
@ -640,7 +637,7 @@ _zsh_highlight_highlighter_main_paint()
fi fi
fi fi
;; ;;
*) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res arg0 *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res
already_added=1 already_added=1
;; ;;
esac esac