Skip to content

Commit cf1d58e

Browse files
committed
'main': Fix issue zsh-users#677, concerning multiline aliases.
The fix is to exempt such aliases from the empty commands sanity check.
1 parent 8211a95 commit cf1d58e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

highlighters/main/main-highlighter.zsh

+10-2
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,17 @@ _zsh_highlight_main_highlighter_highlight_list()
854854
style=commandseparator
855855
elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then
856856
style=commandseparator
857+
elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( in_alias )); then
858+
style=commandseparator
857859
else
858-
# This highlights empty commands (semicolon follows nothing) as an error.
859-
# Zsh accepts them, though.
860+
# Empty commands (semicolon follows nothing) are valid syntax.
861+
# However, in interactive use they are likely to be erroneous;
862+
# therefore, we highlight them as errors.
863+
#
864+
# Alias definitions are exempted from this check to allow multiline aliases
865+
# with explicit (redundant) semicolons: «alias foo=$'bar;\nbaz'» (issue #677).
866+
#
867+
# See also #691 about possibly changing the style used here.
860868
style=unknown-token
861869
fi
862870

highlighters/main/test-data/alias-comment1.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ alias x=$'# foo\npwd'
3333
BUFFER='x'
3434

3535
expected_region_highlight=(
36-
'1 1 alias "issue #677"' # x
36+
'1 1 alias' # x
3737
)

0 commit comments

Comments
 (0)