-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
zsh-syntax-highlighting interoperability: Please register zle-line-pre-redraw hooks #529
Comments
Thanks for the analysis @danielshahaf! I’ll take a look at this soon |
@danielshahaf Would it be possible/helpful for z-sy-h to kind of simulate the effect of the |
@ericfreese It would be nice to be able to simulate the Suppose z-sy-h is called by a For However, I suspect I'm missing something here. Secondly, there are two less likely cases: if someone calls Of course, that's just me; other z-sy-h developers may have a different take. We should discuss this on the z-sy-h issue tracker, if needed, so everyone can participate. |
Ok you're right about how I've tried naively adding the two I'm a bit short on time for at least the next few weeks, but if you (or anyone) has time to provide a PR that fixes the interop while keeping the test suite green and ideally not calling fetch twice per keystroke, it would help greatly. Generally though, I'm concerned that zsh-users/zsh-syntax-highlighting#418 is a show-stopper for merging the redraw hook branch. It seems it will break and force modifications on any plugin that happens to use As another idea for a possible solution, could z-sy-h implement a POSTDISPLAY highlighter that would supersede the highlighting provided by z-asug? One might make the argument that if z-sy-h is going to clear |
Thanks for having a look.
$ zsh -f
% f() { zle -M "$(typeset -p LASTWIDGET)" }
% autoload add-zle-hook-widget
% add-zle-hook-widget line-pre-redraw f
% x<CURSOR>
typeset -r LASTWIDGET=self-insert Furthermore, What am I missing?
Neither do I. The proposal was intended to be a proof-of-concept, the smallest change that would achieve correctness; I didn't know z-asug's code well enough to devise a complete patch. To avoid the duplicate work, couldn't the widget-binding code simply be skipped altogether when pre-redraw mode is in use? That's what z-sy-h does: https://github.com/zsh-users/zsh-syntax-highlighting/blob/b08d508cd8792df2b6c8e044e42dffeb7f9118fe/zsh-syntax-highlighting.zsh#L339
Thanks for the invitation. Simply providing a patch that disables the widget binding if pre-redraw is available and uses Anyway, I assume the approach should be as follows:
Merging feature/redrawhook would cause On the other hand, I don't think it's practical to keep feature/redrawhook waiting until everyone has upgraded to a zsh with the owner= patch. Perhaps z-sy-h could merge feature/redrawhook but have the code continue to use the "wrap all widgets" strategy unless zsh has the owner= patch. That should avoid regressions. It would leave users of z-sy-h HEAD and zsh new enough to support pre-redraw hook on the legacy codepath, though, but I'm not sure if there's a better option.
We can change the name, of course. Plenty of time to decide on a name later on, though; getting the semantics right is a higher priority. Does the patch look okay, aside from the choice of words? I am particularly interested in your take on the API docs part of the patch, as you maintain a
Sorry, could you clarify? I assume you're thinking of the case of someone using z-asug HEAD + z-sy-h HEAD post the feature/redrawhook merge + zsh without zsh-users/zsh#57 [which, as of this writing, hasn't been merged, let alone released], and proposing that in that case z-sy-h should arrange for z-asug's POSTDISPLAY That would seem to amount to reimplementing zle-line-pre-redraw in z-sy-h, and it would still require code changes in every plugin affected by zsh-users/zsh-syntax-highlighting#418, wouldn't it? Cheers! 👍 |
I was noticing the problem when adding a second line-pre-redraw hook (as z-asug would be doing on top of the one already added by z-sy-h):
The triggering widget name is lost once the first redraw hook runs.
Ok gotcha, yes I agree this should be possible 😄
I hope it's not too bad. If you have docker installed, you can run the tests with from the project directory with:
You should be able to change the value of
I'll take a closer look at this in the coming days/weeks and get back to you.
Yeah, sorry for the confusion. This suggestion is for exactly the scenario you've outlined. It's meant as a short term solution before zsh-users/zsh#57 is released and widely available- a possible alternative to implementing fixes for zsh-users/zsh-syntax-highlighting#418 throughout all
I haven't looked into exactly how the highlighters work, but I'm thinking it would work like any of the other highlighters. Only it would highlight the POSTDISPLAY. Depending on how much you wanted to couple to z-asug, it could even pull from the
Code changes would be required for each plugin affected by zsh-users/zsh-syntax-highlighting#418 in the form of highlighters being added. The difference is that those code changes would be contained within the z-sy-h repo (the one deciding to empty |
Ouch. Yes, I see what you mean now. I think the best you can do here under zsh 5.8 and earlier is to continue to wrap widgets, but not with the existing wrapper that does autosuggesting, but with another wrapper that just does
Thanks. I don't have docker already installed, so I'll have to set that up first, and I'll probably do that in a VM, which I'd have to install first… fortunately, it's not turtles all the way down — the turtles are only two or three layers deep — so the problem is solvable; just need time. (And in the meantime we're making good progress with designing the solution.)
Thanks! I'll take the liberty of pressing the "Request review" button in github, then; let me know if you prefer I cancel that.
Yes, it sounds like merging redrawhook will be a flag day for all such plugins. It won't particularly help that many z-sy-h users use the I've opened zsh-users/zsh-syntax-highlighting#735 for this.
In a nutshell, a highlighter is simply a callback function with a well-known name (
Hmm. I'm not sure I like this idea. This would require the z-sy-h maintainers to maintain code for every single other plugin that uses region_highlight… and there's no reason to assume all such plugins are public, either. I think I'd prefer for workarounds to be deployed in the other plugins: this distributes maintenance effort to the people more familiar with those plugins, and doesn't require different technical solutions depending on whether a third-party plugin is public or private. However, as above, my preferred approach is to make the redrawhook codepath conditional on the owner= codepath, which solves the interoperability concerns without any changes to other plugins. |
Thread: workers/46004 |
Committed in zsh-users/zsh@0cffb0a. That hopefully unrolls the discussion back to #529 (comment):
Since that comment, the "owner" patch referenced therein has been committed, and zsh-users/zsh-syntax-highlighting#418 is expected to be fixed in z-sy-h soon, which will fix the interop issue under zsh≥5.9 without z-asug changes (see zsh-users/zsh-syntax-highlighting#579 (comment); the testing described in that comment was done with z-asug's Makes sense? |
Fixes #579 (zsh-autosuggestions interoperability). Fixes #735 (ditto). See #579 (comment) See zsh-users/zsh-autosuggestions#529 (comment)
So, zsh-users/zsh-syntax-highlighting#418 has been fixed in z-sy-h master and zsh-users/zsh-syntax-highlighting#579 was fixed on the redrawhook branch. That resolves the interoperability concerns with current z-asug This voids the original justification for the proposed change. The change may still be a good idea, but it's no longer an interop concern, so I don't expect I'll be working on the z-asug change after all. Thanks for the support, though! |
By the way, I think that means using the feature/redrawhook branch may be a viable workaround for some of the issues mentioned in the OP. |
Is your feature request related to a problem? Please describe.
As described in zsh-users/zsh-syntax-highlighting#579, zsh-syntax-highlighting's
feature/redrawhook
branch and z-asug don't interoperate.See zsh-users/zsh-syntax-highlighting#579 (comment) for my latest analysis.
Describe the solution you'd like
Solution in the short term: z-asug should run
at some point after z-sy-h ran its
add-zle-hook-widget zle-line-pre-redraw …
commands. This way, z-asug and z-sy-h will both work.Describe alternatives you've considered
In the longer term, I have patches for zsh and z-sy-h that, between them, allow z-sy-h and z-asug to coexist with no changes to z-asug and without the relative ordering requirement described above: zsh-users/zsh-syntax-highlighting#418 (comment)
However, a patch that requires rebuilding zsh is not a practical option for users in the short term.
Furthermore, I have considered making a minor API change to add-zle-hook-widget, along these lines —
— but I think a solution that doesn't involve changes to zsh would be preferable, even if the changes don't require recompilation to be deployed.
Additional context
Under zsh's that support add-zle-hook-widget, there's no need to wrap all widgets. However, that's merely an optimization, and doesn't block fixing the interoperability bug.
z-sy-h wraps zle-line-finish as well, so z-asug may want to wrap that as well (I haven't tested).
I think this may address #483. I haven't tested #158 and #294.
tl;dr
Please have z-asug do those two add-zle-hook-widget calls so I can merge feature/redrawhook on the z-sy-h side ☺
Thanks!
The text was updated successfully, but these errors were encountered: