zsh-syntax-highlighting
zsh-syntax-highlighting copied to clipboard
Highlight precommands and correct expansions order
This is i343-precommands-v2, but rebased, and with an extra commit about ${foo} parameter expansions.
Related to #264, #328, #343, #168, #365 (see log messages and added comments).
Tests pass locally.
Haven't had a chance to figure out why but when on this branch
% zsh -f
% . ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
% alias a=b
% : 'azsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument
'a'
That last line is typing : 'a'.
Note to self: audit for null argument elision.
The problem is here:
https://github.com/danielshahaf/zsh-syntax-highlighting/blob/e9ab802593ebbfce5cf749b1854d2cc201b3aa68/highlighters/main/main-highlighter.zsh#L471-L482
$arg starts out as 'a' (three characters), then _zsh_highlight_main_highlighter_expand_path dequotes, _zsh_highlight_main__type returns alias, and _zsh_highlight_main__resolve_alias doesn't find an alias named 'a' (there's only an a alias) and returns an empty string, which is elided in _zsh_highlight_main_highlighter_check_path at https://github.com/danielshahaf/zsh-syntax-highlighting/blob/e9ab802593ebbfce5cf749b1854d2cc201b3aa68/highlighters/main/main-highlighter.zsh#L850-L852 .
The breakage is that alias lookup should be done on the non-dequoted argument. Not sure how to fix (ideas?).
Good catch!
Filed #479 which would affect the failure mode of this.
Remaining tasks:
- [ ] Resolve all review comments
- [ ] Update changelog
- [ ] Fix trailing whitespace
- [ ]
alias a=b; : 'a'issue above, compare #479 - [ ] Tests fail under zsh<5.1 # alias-comment1 1..1 not ok 1 - [1,1] «x» - expected "alias", observed "unknown-token". # TODO 'interactivecomments applies to aliases'
Tests fail under zsh<5.1
Testing interactively in zsh-4.3.17, I get the expected output from running x, namely, pwd gets executed. So the test's expectations are correct for those old versions too. I don't immediately see the cause for the failure under 5.0.8.
Need precommand_options[nice]+=':'
(Can't add it as a review comment)
edit: Done in 06ae6f9
Left:
- Address https://github.com/zsh-users/zsh-syntax-highlighting/pull/471#issuecomment-357249607 - alias lookup should only be done if it's either a global alias or at command word position
- Address https://github.com/zsh-users/zsh-syntax-highlighting/pull/471#discussion_r161374006
- Resolve conflicts
- Merge
- Address https://github.com/zsh-users/zsh-syntax-highlighting/pull/471#discussion_r161105273
Triage: Incomplete; deferred ☹