Unfortunate interaction with OMZ plugin fancy-ctrl-z #82
@mickk-on-cpp There's a rewrite underway in PR #91. It's available on branch v0.1.x. Can you verify that the problem still exists on that branch?
@ericfreese it’s a bit hard to tell, there appears to be something going on when I try this branch. I’ll walk you through what I did to my .zshrc file in case i did something wrong:
- I got rid of the previous config as per the old README (i.e. removed the widgets).
- I commented out the use of the history-substring-search plugin (the one that ships with omz, I don’t use the upstream one)
- commented out some other
sourcestatements for other 3rd-party plugins to avoid conflicts, leaving me with only stock plugins as well as: - moved the
sourcestatement for zsh-syntax-highlighting to the bottom of the .zshrc as per new README instructions
Now if I e.g. go into Vim and Ctrl-Z once I suspend Vim and go back to the zsh prompt, as expected. But the 2nd Ctrl-Z puts fg into the buffer while outputting the following error:
No such widget `autosuggest-orig-fancy-ctrl-z'
Do I have to set one of the ZSH_AUTOSUGGEST_*_WIDGETS variables? I noticed I had a similar error with up/down when I have the history-substring-search plugin turned on and I didn’t follow the README instructions precisely enough.
Ok, I've finally reproduced this using the v0.2.x branch of this plugin that adds support for Oh My Zsh.
I've got a basic Oh My Zsh installation with zsh-autosuggestions (branch v0.2.x) installed to $ZSH_CUSTOM/plugins
I've loaded only the zsh-autosuggestions and fancy-ctrl-z plugins via:
plugins=(zsh-autosuggestions fancy-ctrl-z)Now if I e.g. go into Vim and Ctrl-Z once I suspend Vim and go back to the zsh prompt, as expected. But the 2nd Ctrl-Z puts fg into the buffer while outputting the following error:
I get the same behavior as above except the error is no longer printed in the v0.2.x branch.
If fancy-ctrl-z is changed to instead use .accept-line, its functionality is restored. I'm unsure what's really at fault here
I'm pretty sure the fancy-ctrl-z plugin is at fault here. I believe the best solution would be for fancy-ctrl-z to add the -w flag to their zle calls, so...
zle accept-line
would become
zle accept-line -w
The manual has this to say about the zle [widget] and the -w flag:
Normally, calling a widget in this way does not set the special parameter WIDGET and related parameters, so that the environment appears as if the top-level widget called by the user were still active. With the option -w, WIDGET and related parameters are set to reflect the widget being executed by the zle call.
If they use the -w flag, the handler for zsh-autosuggestions will get triggered and will still call the original widget (.accept-line) correctly.
If they use zle .accept-line, the handler for zsh-autosuggestions will not get triggered, but it still calls the original widget correctly.
I think it's probably best if other handlers are triggered in this case. This would be my recommended fix:
diff --git a/plugins/fancy-ctrl-z/fancy-ctrl-z.plugin.zsh b/plugins/fancy-ctrl-z/fancy-ctrl-z.plugin.zsh
index 8ab2979..82b9688 100644
--- a/plugins/fancy-ctrl-z/fancy-ctrl-z.plugin.zsh
+++ b/plugins/fancy-ctrl-z/fancy-ctrl-z.plugin.zsh
@@ -1,10 +1,10 @@
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
- zle accept-line
+ zle accept-line -w
else
- zle push-input
- zle clear-screen
+ zle push-input -w
+ zle clear-screen -w
fi
}
zle -N fancy-ctrl-z
OMZ comes with the fancy-ctrl-z plugin, which allows the user to use ^Z to quickly switch between zsh and a suspended program:
Note in particular that the
accept-linewidget is used. As it turns out,autosuggest-resume()intercepts that widget. If myzle-line-inithook callszle autosuggest-start, then I lose fancy-ctrl-z functionality: hitting ^Z seemingly inputs an empty buffer instead of inputtingfgas expected (to restore the suspended program).If fancy-ctrl-z is changed to instead use
.accept-line, its functionality is restored.I'm unsure what's really at fault here, and what should or shouldn't be done.