Skip to content

subshells highlighted as incorrect syntax #166

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

Closed
anntzer opened this issue Apr 14, 2015 · 12 comments
Closed

subshells highlighted as incorrect syntax #166

anntzer opened this issue Apr 14, 2015 · 12 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented Apr 14, 2015

(cd ~; ls): the opening parenthesis is highlighted in red; the first command (cd) is not highlighted though the second one is.

@danielshahaf
Copy link
Member

The fix would be to make the for arg in ${(z)…} loop check if arg is an unquoted parenthesis.

@anntzer
Copy link
Contributor Author

anntzer commented Sep 2, 2015

PS: it would be nice if your fix also handled the (more typical) use case: tar cf - * | (cd /target; tar xfp -) (or similar).

@danielshahaf
Copy link
Member

It probably will; the code has an internal notion of "at command position" ($new_expression) and subshells always occur at command position.

A quick and dirty implementation is simply to add '(' to the value of ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS in main-highlighter.zsh.

Could I persuade you to write a test case for this?

@anntzer
Copy link
Contributor Author

anntzer commented Sep 2, 2015

Something like

BUFFER='tar cf - * | (cd /target; tar xfp -)'

expected_region_highlight=(
  "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar
  "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd
  "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar
)

?

@danielshahaf
Copy link
Member

Yes, thank you.

@danielshahaf
Copy link
Member

Committed the test in 22c8736.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 30, 2015

Kindly requesting a reopen, as I realized that the test I wrote was not enough: in fact, the opening parenthesis is still highlighted in red for me.

This should be a more exhaustive test:

BUFFER='tar cf - * | (cd /target; tar xfp -)'

expected_region_highlight=(
  "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar
  "14 14 none" # (
  "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd
  "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar
  "36 36 none" # )
)

@danielshahaf danielshahaf reopened this Oct 30, 2015
danielshahaf added a commit that referenced this issue Oct 30, 2015
@danielshahaf
Copy link
Member

Good catch. I can reproduce that here, too. I extended the test in 5a38710, but I made it expect the ( to be highlighted as a reserved word, for consistency with () and {.

danielshahaf added a commit to danielshahaf/zsh-syntax-highlighting that referenced this issue Oct 30, 2015
@danielshahaf
Copy link
Member

I think master...danielshahaf:i166bis-subshells fixes this, but I'll give it a closer look later.

@danielshahaf
Copy link
Member

Merged. Closing, but please re-open if anything is still wrong.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 30, 2015

Sorry to keep reopening this issue but the closing parenthesis should have the same highlighting as the opening one :-)

@danielshahaf
Copy link
Member

There's no need to apologise! I agree that would be good to have, but I think it fits best as a separate ticket. Filed it as #226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants