'main': Pass parameters through the multi-word machinery, as we already do for aliases.
Fixes #674.
This commit is contained in:
parent
52ea5c686a
commit
1a55dc8fc2
@ -77,6 +77,16 @@ _zsh_highlight_main_add_region_highlight() {
|
|||||||
[[ $1 == unknown-token ]] && alias_style=unknown-token
|
[[ $1 == unknown-token ]] && alias_style=unknown-token
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
if (( in_param )); then
|
||||||
|
if [[ $1 == unknown-token ]]; then
|
||||||
|
param_style=unknown-token
|
||||||
|
fi
|
||||||
|
if [[ -n $param_style ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
param_style=$1
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# The calculation was relative to $buf but region_highlight is relative to $BUFFER.
|
# The calculation was relative to $buf but region_highlight is relative to $BUFFER.
|
||||||
(( start += buf_offset ))
|
(( start += buf_offset ))
|
||||||
@ -406,11 +416,13 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
# alias_style is the style to apply to an alias once in_alias=0
|
# alias_style is the style to apply to an alias once in_alias=0
|
||||||
# Usually 'alias' but set to 'unknown-token' if any word expanded from
|
# Usually 'alias' but set to 'unknown-token' if any word expanded from
|
||||||
# the alias would be highlighted as unknown-token
|
# the alias would be highlighted as unknown-token
|
||||||
local alias_style arg buf=$4 highlight_glob=true style
|
# param_style is analogous for parameter expansions
|
||||||
|
local alias_style param_style arg buf=$4 highlight_glob=true style
|
||||||
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
||||||
# in_alias is equal to the number of shifts needed until arg=args[1] pops an
|
# in_alias is equal to the number of shifts needed until arg=args[1] pops an
|
||||||
# arg from BUFFER and not added by an alias.
|
# arg from BUFFER and not added by an alias.
|
||||||
integer in_alias=0 len=$#buf
|
# in_param is analogous for parameter expansions
|
||||||
|
integer in_alias=0 in_param=0 len=$#buf
|
||||||
local -a match mbegin mend list_highlights
|
local -a match mbegin mend list_highlights
|
||||||
# seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a
|
# seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a
|
||||||
local -A seen_alias
|
local -A seen_alias
|
||||||
@ -489,6 +501,14 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
|
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if (( in_param )); then
|
||||||
|
(( in_param-- ))
|
||||||
|
if (( in_param == 0 )); then
|
||||||
|
# start_pos and end_pos are of the '$foo' word (previous $arg) here
|
||||||
|
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style
|
||||||
|
param_style=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Initialize this_word and next_word.
|
# Initialize this_word and next_word.
|
||||||
if (( in_redirection == 0 )); then
|
if (( in_redirection == 0 )); then
|
||||||
@ -513,7 +533,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( in_alias == 0 )); then
|
if (( in_alias == 0 && in_param == 0 )); then
|
||||||
# Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
|
# Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
|
||||||
[[ "$proc_buf" = (#b)(#s)(([ $'\t']|\\$'\n')#)* ]]
|
[[ "$proc_buf" = (#b)(#s)(([ $'\t']|\\$'\n')#)* ]]
|
||||||
# The first, outer parenthesis
|
# The first, outer parenthesis
|
||||||
@ -626,6 +646,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
local -a match mbegin mend
|
local -a match mbegin mend
|
||||||
local MATCH; integer MBEGIN MEND
|
local MATCH; integer MBEGIN MEND
|
||||||
local parameter_name
|
local parameter_name
|
||||||
|
local -a words
|
||||||
if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then
|
if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then
|
||||||
parameter_name=${${arg:2}%?}
|
parameter_name=${${arg:2}%?}
|
||||||
elif [[ $arg[1] == '$' ]]; then
|
elif [[ $arg[1] == '$' ]]; then
|
||||||
@ -638,14 +659,16 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
# Set $arg.
|
# Set $arg.
|
||||||
case ${(tP)MATCH} in
|
case ${(tP)MATCH} in
|
||||||
(*array*|*assoc*)
|
(*array*|*assoc*)
|
||||||
local -a words; words=( ${(P)MATCH} )
|
words=( ${(P)MATCH} )
|
||||||
arg=${words[1]}
|
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
# scalar, presumably
|
# scalar, presumably
|
||||||
arg=${(P)MATCH}
|
words=( ${(P)MATCH} )
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
(( in_param = 1 + $#words ))
|
||||||
|
args=( $words $args )
|
||||||
|
arg=$args[1]
|
||||||
_zsh_highlight_main__type "$arg" 0
|
_zsh_highlight_main__type "$arg" 0
|
||||||
res=$REPLY
|
res=$REPLY
|
||||||
fi
|
fi
|
||||||
@ -946,6 +969,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
|
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
|
||||||
done
|
done
|
||||||
(( in_alias == 1 )) && in_alias=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
|
(( in_alias == 1 )) && in_alias=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
|
||||||
|
(( in_param == 1 )) && in_param=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style
|
||||||
[[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]]
|
[[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]]
|
||||||
REPLY=$(( end_pos + ${#match[1]} - 1 ))
|
REPLY=$(( end_pos + ${#match[1]} - 1 ))
|
||||||
reply=($list_highlights)
|
reply=($list_highlights)
|
||||||
|
@ -36,7 +36,7 @@ BUFFER='$sudo_u phy1729 echo foo'
|
|||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
'1 7 precommand' # $sudo_u
|
'1 7 precommand' # $sudo_u
|
||||||
'9 15 default "issue #674"' # phy1729
|
'9 15 default' # phy1729
|
||||||
'18 20 command "issue #540"' # echo (not builtin)
|
'18 20 command "issue #540"' # echo (not builtin)
|
||||||
'22 24 default' # foo
|
'22 24 default' # foo
|
||||||
)
|
)
|
||||||
|
@ -36,7 +36,7 @@ BUFFER='$sudo_u phy1729 ls foo'
|
|||||||
|
|
||||||
expected_region_highlight=(
|
expected_region_highlight=(
|
||||||
'1 7 precommand' # sudo_u
|
'1 7 precommand' # sudo_u
|
||||||
'9 15 default "issue #674"' # phy1729
|
'9 15 default' # phy1729
|
||||||
'17 18 command "issue #674"' # ls
|
'17 18 command' # ls
|
||||||
'20 22 default' # foo
|
'20 22 default' # foo
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user