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

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

Open
Iskustvo opened this issue Aug 13, 2022 · 5 comments

Comments

@Iskustvo
Copy link

Steps to reproduce:

  • Start the zsh in new terminal emulator, without any configuration
    termite -e 'zsh -dfi'
  • Source z-sy-h from where it's installed, and use only the main highlighter with defined substitution style
    source "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
    ZSH_HIGHLIGHT_HIGHLIGHTERS=(main)
    ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]='fg=magenta'
  • Observe that highlighting of $( and ) is done with magenta color, as specified
    2022-08-13-182616_1920x1080_scrot
  • Add brackets highlighter to the mix
    ZSH_HIGHLIGHT_HIGHLIGHTERS+=brackets
  • Observe that same expression has different highlighting for brackets now
    2022-08-13-183106_1920x1080_scrot

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
Copy link
Member

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

@Iskustvo
Copy link
Author

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

  • 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
    ( ( ( echo a ) ) ) # All parentheses are colored with the same color
    { { { echo a } } } # All brackets are colored with the same color

@danielshahaf
Copy link
Member

Sorry about that.

Two other ideas:

  • 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.

  • 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.

@Iskustvo
Copy link
Author

  • 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 😄
Regarding the zsh version restriction, I find that perfectly fine - Community should strive to use latest versions of the packages.

@danielshahaf
Copy link
Member

danielshahaf commented Oct 11, 2022 via email

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

No branches or pull requests

2 participants