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

Compability with zsh-syntax-highlighting plugin #9

Open
lukeflo opened this issue Jan 13, 2025 · 11 comments
Open

Compability with zsh-syntax-highlighting plugin #9

lukeflo opened this issue Jan 13, 2025 · 11 comments
Labels
documentation Improvements or additions to documentation

Comments

@lukeflo
Copy link

lukeflo commented Jan 13, 2025

So far, the Helix mode works great. But I encountered a little flaw. (Sorry, for opening so much issues 😉 )

I use zsh-syntax-highlighting because it directly gives feedback if a typed command exists, highlights strings wrapped in quotes etc.

Now, since using your most up-to-date version, the syntax highlighting stopped working, as you can see in the following screenshot. Upper line is before sourcing zsh-helix-mode, lower line the same command after sourcing, same for string highlighting:

2025-01-13_08-59-34

2025-01-13_09-13-08

It has to do with one of your more recent changes, since syntax highlighting still worked last week when I tried Helix mode last time.

@Multirious
Copy link
Owner

You can submit as many issue as you'd like 😁. I love interacting with issues and see how the plugin is being used.

For this issue, this might've caused from me screwing around with region_highlight which is supposedly used by zsh-syntax-highlight. I'm changing from using MARK and zle_highlight to region_highlight to add support for multi-cursor. Now, I'm not sure what is causing the issue here because I think I'm only interacting with the plugin's array entries here.

@Multirious Multirious added the bug Something isn't working label Jan 13, 2025
@lukeflo
Copy link
Author

lukeflo commented Jan 13, 2025

I'm changing from using MARK and zle_highlight to region_highlight to add support for multi-cursor. Now, I'm not sure what is causing the issue here because I think I'm only interacting with the plugin's array entries here.

That might be the point where it gets screwed. zsh-sytax-highlighting uses ZLE to create the coloring.

AFAIK its a very popular plugin (over 20k stars on GitHub, for example). Thus, compatibility might be an important thing for zsh-helix-mode.

@Multirious
Copy link
Owner

Multirious commented Jan 13, 2025

Were you sourcing zsh-syntax-highlighting before zsh-helix-mode? It's recommended here. I replicated the issue by sourcing zsh-syntax-highlighting before zsh-helix-mode. Syntax highlighting seems to work fine when sourced after zsh-helix-mode.

After further testing,the cursor selection doesn't shows up instead... 😔

@lukeflo
Copy link
Author

lukeflo commented Jan 13, 2025

I was sourcing it manually through the command line. Therefore it was sourced after zsh-helix-mode, my bad. Ok, changing the order a little bit resolved it partly, but:

After further testing,the cursor selection doesn't shows up instead... 😔

this...

Here the command source is selected but not highlighted correctly:

2025-01-13_10-15-44

PS:

Plus, at every char typed you can see the whole line getting (re)highlighted. Not a very bad thing, but just mentioning it.

@Multirious
Copy link
Owner

Multirious commented Jan 13, 2025

Ok, I just pushed another commit, there was some bug regarding the variable substitution. But highlighting still wouldn't work here.
To have the highlight works again, we must overpower zsh-syntax-highlighting by strapping on additional hook after sourcing the syntax highlighting plugin.

# source zsh-helix-mode

# source zsh-syntax-highlighting

function redraw-zhm-highlight {
  __zhm_update_region_highlight
}

add-zle-hook-widget zle-line-pre-redraw redraw-zhm-highlight

Not exactly ideal but this should make work.

@lukeflo
Copy link
Author

lukeflo commented Jan 13, 2025

Ok, will try it. But in the long run zhm would need a solution which doesn't asks the users to make manual changes in their .zshrc. At least, if you want to publish it through some distro package managers etc.

@Multirious
Copy link
Owner

Multirious commented Jan 13, 2025

I can't think of a solution at the moment that doesn't require some kind of change. It's something regarding plugin ordering and that zsh-syntax-highlighting overpowers/removes all previous highlighting.

zsh-syntax-highlighting requires to be sourced after all previous plugin so it will properly adds highlighting after every redraw.
But by the plugin adding highlighting (with it wrapping all widgets/hooks), it also overpowers zsh-helix-mode highlighting. So our only option here without adding changes to zsh-syntax-highlighting is to add more hooks after zsh-syntax-highlighting.

I haven't look at their docs in details just yet. Maybe there's some additional configuration here that we can use instead of using add-zle-hook-widget

@Multirious
Copy link
Owner

Multirious commented Jan 13, 2025

Seems like we can implement a custom highlighter, which still requires manual changes by the user. I'll look more into this. We probably could expose some functions that aids in making the custom highlighter. Or alternatively stays with the add-zle-hook-widget

@lukeflo
Copy link
Author

lukeflo commented Jan 13, 2025

Sounds interesting. I, personally, manage anything manually through my zshrc/zshenv etc. I also source things like zsh-syntax-highlighting through all these files in $ZDOTDIR and don't use Oh-My-Zsh or whatever plugin system. So, for me its fine to source it in my config file before syntax highlighting.

But many people do. They run things with plugin manager or directly system packages without touching the .zshrc and other config files very often.

Maybe you have to make kind of a design/availability decision:

  1. Make it as portable as possible which means also package managers etc. But that also seems to be more work, especially regarding compatibility
  2. Let ZHM be more kind of a custom widget which needs direct interaction by the users. Seems to be less work beside some installing informations in the readme, but will likely not make it as widely used/available.

PS: I also had a look how the package manager of my distro handles those zsh plugins which are available as system plugins. They're simply installed to /usr/share/zsh/plugins/{package-name} from where they're sourced by zsh. But how this keeps the order of e.g. zsh-syntax-highlighting being sourced last, I couldn't figure out so far...

@Multirious
Copy link
Owner

I think that no system package managers were sourcing any plugins automatically on install. In all of the guide I've seen so far include commands/instructions to add source command to .zshrc directly.

@lukeflo
Copy link
Author

lukeflo commented Jan 13, 2025

No, I meant ZSH is sourcing stuff from /usr/share/zsh, as it does for completion scripts. Will try to install one of this packages on my distro and check how it works.

@Multirious Multirious added documentation Improvements or additions to documentation and removed bug Something isn't working labels Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants