Skip to content

Commit 2561e4d

Browse files
committed
main: Stop highlighting empty commands as errors
Fixes zsh-users#501
1 parent d9e326b commit 2561e4d

File tree

6 files changed

+8
-12
lines changed

6 files changed

+8
-12
lines changed

highlighters/main/main-highlighter.zsh

+3-7
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ _zsh_highlight_main_highlighter_highlight_list()
641641
# Not an option flag; nothing to do. (If the command line is
642642
# syntactically valid, ${this_word//:sudo_opt:/} should be
643643
# non-empty now.)
644-
this_word=${this_word//:sudo_opt:/}
645644
fi
646645
elif [[ $this_word == *':sudo_arg:'* ]]; then
647646
next_word+=':sudo_opt:'
@@ -651,15 +650,12 @@ _zsh_highlight_main_highlighter_highlight_list()
651650

652651
# The Great Fork: is this a command word? Is this a non-command word?
653652
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
654-
if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then
653+
if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q ||
654+
[[ $this_word == *:sudo_arg:* || $this_word == *:sudo_opt:* ]]; then
655655
# Missing closing square bracket(s)
656656
style=unknown-token
657-
elif [[ $this_word == *':regular:'* ]]; then
658-
# This highlights empty commands (semicolon follows nothing) as an error.
659-
# Zsh accepts them, though.
660-
style=commandseparator
661657
else
662-
style=unknown-token
658+
style=commandseparator
663659
fi
664660
if [[ $arg == ';' ]] && $in_array_assignment; then
665661
# literal newline inside an array assignment

highlighters/main/test-data/always2.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BUFFER=$'{\nls\n} always { pwd }'
3232

3333
expected_region_highlight=(
3434
'1 1 reserved-word' # {
35-
'2 2 unknown-token' # \n
35+
'2 2 commandseparator' # \n
3636
'3 4 command' # ls
3737
'5 5 commandseparator' # \n
3838
'6 6 reserved-word' # }

highlighters/main/test-data/comment-followed.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ BUFFER=$'# foo\ntrue'
3333

3434
expected_region_highlight=(
3535
'1 5 comment' # # foo
36-
'6 6 commandseparator "issue #501"' # \n
36+
'6 6 commandseparator' # \n
3737
'7 10 builtin' # true
3838
)

highlighters/main/test-data/empty-command.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ BUFFER='echo; ;'
3232
expected_region_highlight=(
3333
"1 4 builtin" # echo
3434
"5 5 commandseparator" # ;
35-
"7 7 unknown-token" # ;
35+
"7 7 commandseparator" # ;
3636
)

highlighters/main/test-data/empty-command2.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ BUFFER='echo; ;'
3535
expected_region_highlight=(
3636
"1 4 builtin" # echo
3737
"5 5 commandseparator" # ;
38-
"7 7 unknown-token" # ;
38+
"7 7 commandseparator" # ;
3939
)

highlighters/main/test-data/empty-line.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
BUFFER=$'\\\n; ls'
3232

3333
expected_region_highlight=(
34-
'3 3 unknown-token' # ;
34+
'3 3 commandseparator' # ;
3535
'5 6 command' # ls
3636
)

0 commit comments

Comments
 (0)