Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix highlighting of multiline aliases #696

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
`_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`
[#727, #731, #732, #733]

- Fix highlighting of alias whose definitions use a simple command terminator
(such as `;`, `|`, `&&`) before a newline
[#677; had regressed in 0.7.0]

# Changes in version 0.7.1

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


# Changes in version 0.6.0
Expand Down
12 changes: 10 additions & 2 deletions highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,17 @@ _zsh_highlight_main_highlighter_highlight_list()
style=commandseparator
elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then
style=commandseparator
elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( in_alias )); then
style=commandseparator
else
# This highlights empty commands (semicolon follows nothing) as an error.
# Zsh accepts them, though.
# Empty commands (semicolon follows nothing) are valid syntax.
# However, in interactive use they are likely to be erroneous;
# therefore, we highlight them as errors.
#
# Alias definitions are exempted from this check to allow multiline aliases
# with explicit (redundant) semicolons: «alias foo=$'bar;\nbaz'» (issue #677).
#
# See also #691 about possibly changing the style used here.
style=unknown-token
fi

Expand Down
2 changes: 1 addition & 1 deletion highlighters/main/test-data/alias-comment1.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ alias x=$'# foo\npwd'
BUFFER='x'

expected_region_highlight=(
'1 1 alias "issue #677"' # x
'1 1 alias' # x
)