mirror of
https://github.com/zsh-users/zsh-syntax-highlighting.git
synced 2025-04-17 11:35:32 +08:00
'main': Add :alias: state.
This commit is contained in:
parent
cf88b63523
commit
d937cee71b
@ -319,6 +319,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
#
|
#
|
||||||
# The states are:
|
# The states are:
|
||||||
# - :start: Command word
|
# - :start: Command word
|
||||||
|
# - :alias: :start: and alias expansion is allowed
|
||||||
# - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i")
|
# - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i")
|
||||||
# - :sudo_arg: The argument to a sudo leading-dash option that takes one,
|
# - :sudo_arg: The argument to a sudo leading-dash option that takes one,
|
||||||
# when given as a separate word; i.e., "foo" in "-u foo" (two
|
# when given as a separate word; i.e., "foo" in "-u foo" (two
|
||||||
@ -351,7 +352,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
# $in_redirection. The value of $next_word from the iteration that processed
|
# $in_redirection. The value of $next_word from the iteration that processed
|
||||||
# the operator is discarded.
|
# the operator is discarded.
|
||||||
#
|
#
|
||||||
local this_word=':start:' next_word
|
local this_word=':start::alias:' next_word
|
||||||
integer in_redirection
|
integer in_redirection
|
||||||
# Processing buffer
|
# Processing buffer
|
||||||
local proc_buf="$buf"
|
local proc_buf="$buf"
|
||||||
@ -386,7 +387,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
# the string's color.
|
# the string's color.
|
||||||
integer already_added=0
|
integer already_added=0
|
||||||
style=unknown-token
|
style=unknown-token
|
||||||
if [[ $this_word == *':start:'* ]]; then
|
if [[ $this_word == *':alias:'* ]]; then
|
||||||
in_array_assignment=false
|
in_array_assignment=false
|
||||||
if [[ $arg == 'noglob' ]]; then
|
if [[ $arg == 'noglob' ]]; then
|
||||||
highlight_glob=false
|
highlight_glob=false
|
||||||
@ -485,9 +486,11 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
case "$arg" in
|
case "$arg" in
|
||||||
# Flag that requires an argument
|
# Flag that requires an argument
|
||||||
'-'[Cgprtu]) this_word=${this_word//:start:/};
|
'-'[Cgprtu]) this_word=${this_word//:start:/};
|
||||||
|
this_word=${this_word//:alias:/};
|
||||||
next_word=':sudo_arg:';;
|
next_word=':sudo_arg:';;
|
||||||
# This prevents misbehavior with sudo -u -otherargument
|
# This prevents misbehavior with sudo -u -otherargument
|
||||||
'-'*) this_word=${this_word//:start:/};
|
'-'*) this_word=${this_word//:start:/};
|
||||||
|
this_word=${this_word//:alias:/};
|
||||||
next_word+=':start:';
|
next_word+=':start:';
|
||||||
next_word+=':sudo_opt:';;
|
next_word+=':sudo_opt:';;
|
||||||
*) ;;
|
*) ;;
|
||||||
@ -502,13 +505,14 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
if [[ $this_word == *':always:'* && $arg == 'always' ]]; then
|
if [[ $this_word == *':always:'* && $arg == 'always' ]]; then
|
||||||
# try-always construct
|
# try-always construct
|
||||||
style=reserved-word # de facto a reserved word, although not de jure
|
style=reserved-word # de facto a reserved word, although not de jure
|
||||||
next_word=':start:'
|
next_word=':start:' # :alias: will be added to $next_word when $this_word is \x7b.
|
||||||
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
|
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
|
||||||
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
|
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
|
||||||
style=precommand
|
style=precommand
|
||||||
elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then
|
elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then
|
||||||
style=precommand
|
style=precommand
|
||||||
next_word=${next_word//:regular:/}
|
next_word=${next_word//:regular:/}
|
||||||
|
next_word=${next_word//:alias:/}
|
||||||
next_word+=':sudo_opt:'
|
next_word+=':sudo_opt:'
|
||||||
next_word+=':start:'
|
next_word+=':start:'
|
||||||
else
|
else
|
||||||
@ -541,6 +545,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
case $arg in
|
case $arg in
|
||||||
($'\x7b')
|
($'\x7b')
|
||||||
braces_stack='Y'"$braces_stack"
|
braces_stack='Y'"$braces_stack"
|
||||||
|
next_word+=':alias:'
|
||||||
;;
|
;;
|
||||||
($'\x7d')
|
($'\x7d')
|
||||||
# We're at command word, so no need to check $right_brace_is_recognised_everywhere
|
# We're at command word, so no need to check $right_brace_is_recognised_everywhere
|
||||||
@ -627,6 +632,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
# assignment to a scalar parameter.
|
# assignment to a scalar parameter.
|
||||||
# (For array assignments, the command doesn't start until the ")" token.)
|
# (For array assignments, the command doesn't start until the ")" token.)
|
||||||
next_word+=':start:'
|
next_word+=':start:'
|
||||||
|
next_word+=':alias:'
|
||||||
if (( start_pos + i <= end_pos )); then
|
if (( start_pos + i <= end_pos )); then
|
||||||
() {
|
() {
|
||||||
local highlight_glob=false
|
local highlight_glob=false
|
||||||
@ -704,18 +710,21 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
style=assign
|
style=assign
|
||||||
in_array_assignment=false
|
in_array_assignment=false
|
||||||
next_word+=':start:'
|
next_word+=':start:'
|
||||||
|
next_word+=':alias:'
|
||||||
else
|
else
|
||||||
if _zsh_highlight_main__stack_pop 'S'; then
|
if _zsh_highlight_main__stack_pop 'S'; then
|
||||||
REPLY=$start_pos
|
REPLY=$start_pos
|
||||||
reply=($list_highlights)
|
reply=($list_highlights)
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
# TODO: next_word can only be a command separator now
|
||||||
_zsh_highlight_main__stack_pop 'R' reserved-word
|
_zsh_highlight_main__stack_pop 'R' reserved-word
|
||||||
fi;;
|
fi;;
|
||||||
$'\x28\x29') # possibly a function definition
|
$'\x28\x29') # possibly a function definition
|
||||||
if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
|
if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
|
||||||
then
|
then
|
||||||
next_word+=':start:'
|
next_word+=':start:'
|
||||||
|
next_word+=':alias:'
|
||||||
fi
|
fi
|
||||||
style=reserved-word
|
style=reserved-word
|
||||||
;;
|
;;
|
||||||
@ -755,12 +764,18 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
next_word=':regular:'
|
next_word=':regular:'
|
||||||
else
|
else
|
||||||
next_word=':start:'
|
next_word=':start:'
|
||||||
|
next_word+=':alias:'
|
||||||
highlight_glob=true
|
highlight_glob=true
|
||||||
fi
|
fi
|
||||||
elif
|
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]]; then
|
||||||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] ||
|
|
||||||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then
|
|
||||||
next_word=':start:'
|
next_word=':start:'
|
||||||
|
next_word+=':alias:'
|
||||||
|
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then
|
||||||
|
next_word=':start:'
|
||||||
|
# Special-case two reserved words that _can_ be followed by aliases
|
||||||
|
if [[ $arg == ('noglob'|'nocorrect') ]]; then
|
||||||
|
next_word+=':alias:'
|
||||||
|
fi
|
||||||
elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then
|
elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then
|
||||||
# skip the repeat-count word
|
# skip the repeat-count word
|
||||||
in_redirection=2
|
in_redirection=2
|
||||||
@ -771,7 +786,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
# or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`).
|
# or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`).
|
||||||
#
|
#
|
||||||
# The repeat-count word will be handled like a redirection target.
|
# The repeat-count word will be handled like a redirection target.
|
||||||
this_word=':start::regular:'
|
this_word=':start::alias::regular:'
|
||||||
fi
|
fi
|
||||||
start_pos=$end_pos
|
start_pos=$end_pos
|
||||||
if (( in_redirection == 0 )); then
|
if (( in_redirection == 0 )); then
|
||||||
|
Loading…
Reference in New Issue
Block a user