Skip to content

Commit ade4b28

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 ade4b28

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
`_zsh_highlight_main__precmd_hook:1: array parameter _zsh_highlight_main__command_type_cache set in enclosing scope in function _zsh_highlight_main__precmd_hook`
8686
[#727, #731, #732, #733]
8787

88+
- Fix highlighting of alias whose definitions use a simple command terminator
89+
(such as `;`, `|`, `&&`) before a newline
90+
[#677; had regressed in 0.7.0]
91+
8892
# Changes in version 0.7.1
8993

9094
- Remove out-of-date information from the 0.7.0 changelog.
@@ -159,6 +163,7 @@ Known issues include:
159163
before a newline will incorrectly be highlighted as an error. See issue #677
160164
for examples and workarounds.
161165
[#677]
166+
[UPDATE: Fixed in 0.8.0]
162167

163168

164169
# Changes in version 0.6.0

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)