Skip to content

Commit 1081952

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 9931990 commit 1081952

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
@@ -750,9 +750,17 @@ _zsh_highlight_main_highlighter_highlight_list()
750750
style=commandseparator
751751
elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then
752752
style=commandseparator
753+
elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( in_alias )); then
754+
style=commandseparator
753755
else
754-
# This highlights empty commands (semicolon follows nothing) as an error.
755-
# Zsh accepts them, though.
756+
# Empty commands (semicolon follows nothing) are valid syntax.
757+
# However, in interactive use they are likely to be erroneous;
758+
# therefore, we highlight them as errors.
759+
#
760+
# Alias definitions are exempted from this check to allow multiline aliases
761+
# with explicit (redundant) semicolons: «alias foo=$'bar;\nbaz'» (issue #677).
762+
#
763+
# See also #691 about possibly changing the style used here.
756764
style=unknown-token
757765
fi
758766

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)