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

alias including a newline is not highlighted anymore #677

Closed
itchyny opened this issue Jan 22, 2020 · 7 comments · Fixed by #696
Closed

alias including a newline is not highlighted anymore #677

itchyny opened this issue Jan 22, 2020 · 7 comments · Fixed by #696

Comments

@itchyny
Copy link

itchyny commented Jan 22, 2020

With the config

alias foobar='echo foo;
  echo bar'

foobar at the head of the prompt should be highlighted like a command but not highlighted. This used to work before the commit 9cc0060.

@phy1729
Copy link
Member

phy1729 commented Jan 22, 2020

Note that

alias foobar='echo foo
  echo bar'

will result in foobar being highlighted in green again.

The issue is that

elif [[ $this_word == *':regular:'* ]]; then
# This highlights empty commands (semicolon follows nothing) as an error.
# Zsh accepts them, though.
style=commandseparator
else
style=unknown-token
fi
doesn't distinguish between ; ; (which is likely a typo) and ; followed by a newline (which while unnecessary doesn't indicate a likely typo).

@itchyny
Copy link
Author

itchyny commented Jan 22, 2020

For reference, another failure case

alias foobar='git status ||
  echo failure'

@danielshahaf
Copy link
Member

danielshahaf commented Jan 22, 2020

Thanks for the report and the diagnosis.

Triage: This is not a recent regression, there's an easy workaround (two, actually: you could also add a : after the semicolon (unless the thing before the semicolon is the start of a SHORT_LOOPS syntax loop)), and 0.7.0 is overdue; therefore I'm leaning towards not holding the release for this. (We could always do a 0.7.1.)

#651 adds code to distinguish between semicolons and newlines, which we could use here. I'll see what I can do about that. I guess the order of business is:

Does this sound good?

@itchyny Naturally, if you'd like to look into a fix, you'd be welcome to.

@danielshahaf danielshahaf self-assigned this Jan 24, 2020
@danielshahaf
Copy link
Member

Documented in changelog as a known issue.

@danielshahaf
Copy link
Member

Isn't this the same issue as #616?

@danielshahaf
Copy link
Member

danielshahaf commented Mar 15, 2020

Isn't this the same issue as #616?

It's related but not the same. Compare these two tests:

# see alias-comment2.zsh
setopt interactivecomments
alias x=$'# foo\npwd'
BUFFER='x'
expected_region_highlight=(
'1 1 alias "issue #616"' # x
)

setopt interactivecomments
BUFFER=$'# foo\ntrue'
expected_region_highlight=(
'1 5 comment' # # foo
'6 6 commandseparator "issue #501"' # \n
'7 10 builtin' # true
)

With #651 having been merged, the second test sees arg=$'\n' but the first test does not, because the alias parsing codepath runs ${(z)} separately.

To complicate things, there's another test that calls itself #616:

# Newline after semicolon isn't unknown-token
BUFFER=$':;\n:'
expected_region_highlight=(
'1 1 builtin' # :
'2 2 commandseparator' # ;
'3 3 commandseparator "issue #616"' # \n
'4 4 builtin' # :
)

So:

danielshahaf added a commit that referenced this issue Mar 15, 2020
See #677 (comment) for details.

(In particular, there's already another test that calls itself #616.)
danielshahaf added a commit that referenced this issue Mar 15, 2020
Fixes #501.

Fixes #616 (the original form; not the form in
test-data/alias-comment1.zsh which is now considered o be #677 (see
previous commit for details)).

Fixes a latent bug in test-data/always2.zsh.

No user-visible effect, and therefore, no changelog entry.
@danielshahaf
Copy link
Member

A third workaround is to convert the alias to a function. In the given example that's probably a good idea anyway, since functions can't misfire when used in SHORT_LOOPS loop bodies. (alias x='date; pwd'; repeat 2 x)

danielshahaf added a commit to danielshahaf/zsh-syntax-highlighting that referenced this issue Mar 15, 2020
The fix is to exempt such aliases from the empty commands sanity check.
danielshahaf added a commit to danielshahaf/zsh-syntax-highlighting that referenced this issue Mar 15, 2020
The fix is to exempt such aliases from the empty commands sanity check.
danielshahaf added a commit to danielshahaf/zsh-syntax-highlighting that referenced this issue May 22, 2020
The fix is to exempt such aliases from the empty commands sanity check.
danielshahaf added a commit to danielshahaf/zsh-syntax-highlighting that referenced this issue May 22, 2020
The fix is to exempt such aliases from the empty commands sanity check.
danielshahaf added a commit that referenced this issue Jul 14, 2020
* origin/master: (297 commits)
  driver: Follow-up to grandparent: Have all test suite entry points declare the mock $region_highlight.
  Use the new, unreleased zsh 'memo=' feature to remove only our own entries from $region_highlight.
  driver: Stop re-declaring $region_highlight.  It's unneeded.
  docs: regexp highlighter: Fix a wrong associative array name in the example.
  docs: Fix obs-repository link
  tests: Fix a wrong value of $PREBUFFER in a test, and add checks to prevent this from recurring.
  test harness: Fix use of an undefined variable in an error message.
  'main': Don't progress the $in_redirection staller while $in_param.
  tests: Add an XFail test for issue #712.
  'main': Highlight the parentheses of array assignments as reserved words.
  CI += zsh-5.8
  main: Add tests for arithmetic expansion
  main: Add arithmetic substitution highlighting
  changelog.md: Restore vertical whitespace before section headers.
  'main': Fix issue #677, concerning multiline aliases.
  changelog: Update through HEAD.
  'main': Further optimize argument parsing.
  'main': Optimize a hot path.
  tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file.
  changelog: Update through HEAD.
  test harness: Print the expected-v.-actual on every failure, not just upon cardinality failures.
  Document ZSH_HIGHLIGHT_MAXLENGTH.
  'main': Fix the last commit's bug concerning parameter elision not happening in redirects in command position.
  'main': Add a test for parameter elision not happening in redirects in command position.
  'main': Fix regression in zsh 5.3.1 and older: all precmd hooks later than z-sy-h would be aborted.
  changelog += WARN_NESTED_VAR fixes (#727, #731)
  'main': Fix a regression caused by the great-grandparent commit's WARN_NESTED_VAR fix.
  'main': Don't run `_zsh_highlight_main__type` on every non-command word.
  'make perf': Show only a cumulative datum per highligher, rather than per test file.
  'main': Don't trip WARN_NESTED_VAR.
  'main': Follow-up to previous: Document the version number, and deduplicate some option letters.
  'main': precommands += strace
  editorconfig: Fix Makefile settings
  Fix typo
  Bump copyright years.
  driver: Fix "_zsh_highlight:3: read-only variable: ret" warnings when POSIX_BUILTINS is set.
  tests: Add a test for the infinite loop fixed by each of the last two commits.
  'main': Fix expansion of positional parameters in `_zsh_highlight_main_highlighter__try_expand_parameter`.
  'main': Fix an infinite loop.
  'main': precommands += ionice(1) (from util-linux)
  driver: Simplify initialization of $zsyh_user_options in the fallback codepath.
  driver: Make sure we don't change the return value in a called function.
  'main': Make logic more robust.  No functional change.
  'main': Break out an anonymous function into a named function.
  Fix typos in comments.
  main: Add test for issue #713
  'main': Support the 'env' precommand.
  test harness: Fix the pretty-printer's padding implementation.
  Revert "test harness: Rewrite the columnar pretty-printer without external tools." and "travis: Remove bsdmainutils since column(1) has been removed, three commits ago."
  changelog: Update through HEAD.
  'main': Correctly highlight '&&' and '||' inside '[[ … ]]' conditions.
  'main': Highlight reserved words following assignments as errors.
  tests: Add tests for issue #461.
  test harness: Output the time information to the same place the test name was printed to.
  test harness: Stringify values in a more readable manner.
  tests: Add a unit test for a path specified with mixed quoting.
  tests: Add a test for issue #498, which has already been fixed.
  tests: Test that global qualifiers and command substitutions aren't evaluated.
  'main': Don't consider path_prefix in alias expansions.
  'main': Add a test for aliases to AUTO_CD directories.
  'main': Let AUTO_CD directories be highlighted with their own style.
  'main': Add an auxiliary variable for readability.
  'main': In command position, do not highlight directories (unless AUTO_CD is set) and non-executable files.
  'main': Extend tests to capture the current behaviour.
  'main': Add an XFail test for issue #202.
  'main': Highlight errors from the EQUALS option.
  'main': Let the type determination ignore global aliases when it ignores regular ones.
  'main': Add a regression test for parameters that expand to global aliases.
  'main': Enable the zsh/parameter codepath of global aliases highlighting.
  changelog: Update through HEAD.
  travis: Remove bsdmainutils since column(1) has been removed, three commits ago.
  'main': Highlight global aliases
  tests: Record current behaviour on global aliases.
  test harness: Rewrite the columnar pretty-printer without external tools.
  test harness: Fix an issue with the pretty-printed $expected_region_highlight/$region_highlight diffing.
  'main': Support the "close file descriptor" and "coproc" redirection syntaxes
  tests: Add a test for the "close file descriptor" and "coproc" redirection syntaxes
  tests: Fix the test added in the last commit.
  tests: Add a test for issue #705, concerning continuation lines.
  test harness: Let tests fail early by exiting non-zero or by setting a flag.
  test harness: Print the test name when $skip_test is set.
  test harness: Remove a bogus check.
  test harness: Fix $skip_test support, broken yesterday.
  travis: Install bsdmainutils to provide column(1).
  test harness: When the cardinality check fails, pretty-print \$expected_region_highlight and \$region_highlight.
  test harness: Don't leak options from test files to the test harness.
  test harness: Fix test failures under zsh 5.0.8 and older.
  'main': Fix a bug manifesting under zsh 5.2 and older.
  'main': Don't highlight arithmetic expansions as command substitutions.
  tests: Add a test documenting the current state, prior to introducing #704.
  test harness: Change cardinality check semantics
  test harness: No-op change to minimize the next diff.
  'main': Document additional meanings of the 'S' $braces_stack flag.
  'main': When the redirection operator '>&' or '<&' is followed by a positive integer, do not consider that as a filename; it's always a file descriptor.
  'main': Add $last_arg for "lookbehind".
  noop: Clarify comment.
  'main': Honour the MULTIOS option when applying the 'globbing' style.
  'main': Document what $in_redirection is currently used for.
  'main': The optimized cmdsubst input syntax doesn't glob.
  changelog: Fix markup.
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants