zsh-users / zsh-syntax-highlighting

Fish shell like syntax highlighting for Zsh.
github.com/zsh-users/zsh-syntax-highlighting
BSD 3-Clause "New" or "Revised" License
20k stars 1.33k forks source link

Bracket highlighter overrides the main highlighter's substitution delimiter #889

Open Iskustvo opened 2 years ago

Iskustvo commented 2 years ago

Steps to reproduce:

Can this be changed so that main highlighter has priority when parenthesis is part of the delimiter syntax? I don't think hacking brackets highlighter's levels of nesting would solve this in the general case because some delimiters use only one pair of parentheses ($()), while arithmetic evaluation for example uses 2 pairs of parentheses ($(())).

Versions:

zsh - 5.9-1
zsh-syntax-highlighting - 0.7.1-1
danielshahaf commented 2 years ago

So, sort ZSH_HIGHLIGHT_HIGHLIGHTERS the way around (brackets before main)?

Iskustvo commented 2 years ago

While that solves the mentioned issue, doing that is equivalent to turning brackets off :smile:

danielshahaf commented 2 years ago

Sorry about that.

Two other ideas:

Iskustvo commented 2 years ago
  • Skip adding highlighting for a pair of brackets if either of them is already covered by a $region_highlight element for which $((end - start >= 2)) — i.e., an element that covers multiple characters.

This one feels kind of like a hack, so I would avoid it.

  • Have highlighters some information in the $region_highlight memo= field about the thing highlighted by that $region_highlight element: e.g., memo=zsh-syntax-highlighting:${ZSH_HIGHLIGHT_VERSION}:main:command-substitution. The brackets highlighter could use that information to selectively disable itself. Requires zsh ≥5.9.

This one seems like a proper way to go about it. In fact, I read ZLE documentation multiple times last week and still couldn't understand the point of memo, just after reading your comment have I realized how it should be utilized :smile: Regarding the zsh version restriction, I find that perfectly fine - Community should strive to use latest versions of the packages.

danielshahaf commented 1 year ago

While that solves the mentioned issue, doing that is equivalent to turning brackets off :smile:

Now you're just moving the goalposts! :)

  • No warning for unbalanced parentheses
  • No highlight for matching parenthesis when cursor is positioned on the parenthesis
  • No colors for nested parentheses, even when they have no dollar signs in front of them

Sorry about that.

Two other ideas: