Skip to content

Commit 796b30f

Browse files
committed
main: Move in_redirection to its own branch
1 parent 6539f0d commit 796b30f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ _zsh_highlight_main_highlighter_highlight_list()
651651

652652
# The Great Fork: is this a command word? Is this a non-command word?
653653
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
654-
if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then
655-
# Missing closing square bracket(s)
654+
if (( in_redirection )) || _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then
655+
# Unfinished redirection or missing closing square bracket(s)
656656
style=unknown-token
657657
elif [[ $this_word == *':regular:'* ]]; then
658658
# This highlights empty commands (semicolon follows nothing) as an error.
@@ -668,11 +668,21 @@ _zsh_highlight_main_highlighter_highlight_list()
668668
next_word=':start:'
669669
highlight_glob=true
670670
fi
671-
elif ! (( in_redirection)) && [[ $this_word == *':always:'* && $arg == 'always' ]]; then
671+
elif (( in_redirection )); then
672+
if [[ $this_word == *:function:* ]]; then
673+
this_word=':start:'
674+
fi
675+
if [[ $arg == ($'\x29'|'()') ]] || { [[ $arg == $'\x7d' ]] && $right_brace_is_recognised_everywhere }; then
676+
style=unknown-token
677+
else
678+
_zsh_highlight_main_highlighter_highlight_argument 1 0
679+
continue
680+
fi
681+
elif [[ $this_word == *':always:'* && $arg == 'always' ]]; then
672682
# try-always construct
673683
style=reserved-word # de facto a reserved word, although not de jure
674684
next_word=':start:'
675-
elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word
685+
elif [[ $this_word == *':start:'* ]]; then # $arg is the command word
676686
if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then
677687
style=precommand
678688
flags_with_argument=${precommand_options[$arg]%:*}
@@ -831,8 +841,6 @@ _zsh_highlight_main_highlighter_highlight_list()
831841
style=assign
832842
in_array_assignment=false
833843
next_word+=':start:'
834-
elif (( in_redirection )); then
835-
style=unknown-token
836844
else
837845
if _zsh_highlight_main__stack_pop 'S'; then
838846
REPLY=$start_pos
@@ -858,7 +866,7 @@ _zsh_highlight_main_highlighter_highlight_list()
858866
#
859867
# Additionally, `tt(})' is recognized in any position if neither the
860868
# tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.
861-
if (( in_redirection )) || $in_array_assignment; then
869+
if $in_array_assignment; then
862870
style=unknown-token
863871
else
864872
_zsh_highlight_main__stack_pop 'Y' reserved-word
@@ -873,7 +881,7 @@ _zsh_highlight_main_highlighter_highlight_list()
873881
elif [[ $arg == $'\x5d' ]] && _zsh_highlight_main__stack_pop 'Q' builtin; then
874882
:
875883
else
876-
_zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 != in_redirection ))
884+
_zsh_highlight_main_highlighter_highlight_argument 1 1
877885
continue
878886
fi
879887
;;

0 commit comments

Comments
 (0)