main: Remove already_assigned

This commit is contained in:
Matthew Martin 2018-10-01 13:55:14 -04:00
parent c76daac095
commit 9289a57de0

View file

@ -409,16 +409,10 @@ _zsh_highlight_main_highlighter_highlight_list()
# Initialize per-"simple command" [zshmisc(1)] variables: # Initialize per-"simple command" [zshmisc(1)] variables:
# #
# $already_added (see next paragraph)
# $style how to highlight $arg # $style how to highlight $arg
# $in_array_assignment boolean flag for "between '(' and ')' of array assignment" # $in_array_assignment boolean flag for "between '(' and ')' of array assignment"
# $highlight_glob boolean flag for "'noglob' is in effect" # $highlight_glob boolean flag for "'noglob' is in effect"
# #
# $already_added is set to 1 to disable adding an entry to region_highlight
# for this iteration. Currently, that is done for "" and $'' strings,
# which add the entry early so escape sequences within the string override
# the string's color.
integer already_added=0
style=unknown-token style=unknown-token
if [[ $this_word == *':start:'* ]]; then if [[ $this_word == *':start:'* ]]; then
in_array_assignment=false in_array_assignment=false
@ -565,11 +559,11 @@ _zsh_highlight_main_highlighter_highlight_list()
if _zsh_highlight_main__is_redirection $arg ; then if _zsh_highlight_main__is_redirection $arg ; then
if (( in_redirection )); then if (( in_redirection )); then
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
already_added=1
else else
in_redirection=2 in_redirection=2
style=redirection _zsh_highlight_main_add_region_highlight $start_pos $end_pos redirection
fi fi
continue
fi fi
# Expand parameters. # Expand parameters.
@ -722,9 +716,7 @@ _zsh_highlight_main_highlighter_highlight_list()
command) style=command;; command) style=command;;
hashed) style=hashed-command;; hashed) style=hashed-command;;
none) if _zsh_highlight_main_highlighter_check_assign; then none) if _zsh_highlight_main_highlighter_check_assign; then
style=assign _zsh_highlight_main_add_region_highlight $start_pos $end_pos assign
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
already_added=1
local i=$(( arg[(i)=] + 1 )) local i=$(( arg[(i)=] + 1 ))
if [[ $arg[i] == '(' ]]; then if [[ $arg[i] == '(' ]]; then
in_array_assignment=true in_array_assignment=true
@ -740,6 +732,7 @@ _zsh_highlight_main_highlighter_highlight_list()
} }
fi fi
fi fi
continue
elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then
style=history-expansion style=history-expansion
elif [[ $arg[0,1] == $histchars[2,2] ]]; then elif [[ $arg[0,1] == $histchars[2,2] ]]; then
@ -762,13 +755,11 @@ _zsh_highlight_main_highlighter_highlight_list()
# #
# We highlight just the opening parentheses, as a reserved word; this # We highlight just the opening parentheses, as a reserved word; this
# is how [[ ... ]] is highlighted, too. # is how [[ ... ]] is highlighted, too.
style=reserved-word _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) reserved-word
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
already_added=1
if [[ $arg[-2,-1] == '))' ]]; then if [[ $arg[-2,-1] == '))' ]]; then
_zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos reserved-word
already_added=1
fi fi
continue
elif [[ $arg == '()' ]]; then elif [[ $arg == '()' ]]; then
# anonymous function # anonymous function
style=reserved-word style=reserved-word
@ -793,12 +784,12 @@ _zsh_highlight_main_highlighter_highlight_list()
fi fi
;; ;;
*) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res
already_added=1 continue
;; ;;
esac esac
fi fi
fi fi
if (( ! already_added )) && [[ $style == unknown-token ]] && # not handled by the 'command word' codepath if [[ $style == unknown-token ]] && # not handled by the 'command word' codepath
{ (( in_redirection )) || [[ $this_word == *':regular:'* ]] || [[ $this_word == *':sudo_opt:'* ]] || [[ $this_word == *':sudo_arg:'* ]] } { (( in_redirection )) || [[ $this_word == *':regular:'* ]] || [[ $this_word == *':sudo_opt:'* ]] || [[ $this_word == *':sudo_arg:'* ]] }
then # $arg is a non-command word then # $arg is a non-command word
case $arg in case $arg in
@ -842,14 +833,12 @@ _zsh_highlight_main_highlighter_highlight_list()
fi fi
else else
_zsh_highlight_main_highlighter_highlight_argument 1 _zsh_highlight_main_highlighter_highlight_argument 1
already_added=1 continue
fi fi
;; ;;
esac esac
fi fi
if ! (( already_added )); then
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
fi
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
if [[ $arg == ';' ]] && $in_array_assignment; then if [[ $arg == ';' ]] && $in_array_assignment; then
# literal newline inside an array assignment # literal newline inside an array assignment