How to execute widgets from inside functions? #183
Ah, yeah this is kind of confusing behavior, but I think it has to do with the fact that any un-mapped widget (those not included in any of these configured lists) currently triggers the fetching and display of a new suggestion after running.
From the readme:
Widgets not in any of these lists will update the suggestion when invoked.
So your foo widget is wrapped by z-asug, and when invoked with ^K: (1) clears the suggestion via zle autosuggest-clear, and then (2) the modification behavior is triggered, which fetches a new suggestion. That new suggestion will likely be the same as the last, so it appears that the suggestion was not cleared at all.
As a workaround for now, instead of calling zle autosuggest-clear from your widget, I'd suggest adding the foo widget to the list of widgets that clear the autosuggestion:
% function foo() { ... }
% zle -N foo
% bindkey '^K' foo
% ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(foo)A potential fix to this problem may be to change the logic of the modify widget to only fetch and display a new suggestion if the wrapped widget actually changes the $BUFFER content.
This fix would amend the above statement from the readme to something like:
Widgets not in any of these lists will update the suggestion if they modify the buffer when invoked.
The fixes/only_fetch_if_buffer_changed branch implements the fix described at the bottom of my last comment. Try it out and let me know what you think.
I'm trying to execute
autosuggest-clearandautosuggest-acceptfrom inside a function. This is my most basic case:foogets executed onCtrl + K, butzle autosuggest-cleardoes nothing. Am I missing something?