Closed olets closed 1 year ago
It looks like you have a small typo my_wigdet
% my_widget() {}
% bindkey '^[[B' my_wigdet # bind to down arrow
Does that fix it?
Thanks for the quick response!
Good catch but that typo was in the issue writeup only. Also missed creating the keymap. And the example could be more minimal, ls
isn't necessary. Edited.
I've found the— intended steps? bug workaround?: add my widget to ZSH_AUTOSUGGEST_IGNORE_WIDGETS
(before creating the keymap).
# setup
% zsh -df
% source path/to/zsh-autosuggestions.zsh
% my_widget() {}
% typeset -ga ZSH_AUTOSUGGEST_IGNORE_WIDGETS # new
% ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(my_widget) # new
% zle -N my_widget
% bindkey '^[[B' my_widget # bind to down arrow
# zle autosuggest-clear example
% my_widget() { zle autosuggest-clear }
% s # `source path/to/zsh-autosuggestions.zsh` is suggested
# down arrow clears the suggestion
# _zsh_autosuggest_clear example
% my_widget() { _zsh_autosuggest_clear }
% s # `source path/to/zsh-autosuggestions.zsh` is suggested
# down arrow clears the suggestion
My own need is cleared up. Still seems like either a bug or something missing from the documentation. The README doesn't suggest that adding to ZSH_AUTOSUGGEST_IGNORE_WIDGETS
will be necessary. Maybe the _zsh_autosuggest_bind_widget
source suggests it, but it doesn't to my eye.
Happy to PR a clarification to https://github.com/zsh-users/zsh-autosuggestions#key-bindings if that'd be helpful.
I had time, so opened a PR with the expectation that you might simply close it.
One thing maybe worth noting is that the intended way to use those provided autosuggest-*
widgets is by binding keys to them directly e.g. bindkey '^[[B' autosuggest-clear
instead of my_widget() { zle autosuggest-clear }; zle -N my_widget; bindkey '^[[B' my_widget
.
If you want a custom widget to clear a suggestion rather than have a suggestion fetched after it runs, you should actually add it to ZSH_AUTOSUGGEST_CLEAR_WIDGETS
rather than manually calling zle autosuggest-clear
and adding it to ZSH_AUTOSUGGEST_IGNORE_WIDGETS
❯ zsh -df
ericfreese% source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
ericfreese% my_widget() {}
ericfreese% zle -N my_widget
ericfreese% bindkey '^[[B' my_widget
ericfreese% ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(my_widget)
ericfreese% s # pressing down arrow clears the suggestion
There's some additional documentation about that here: https://github.com/zsh-users/zsh-autosuggestions#widget-mapping
Aha! Missed that. Thank you.
edit oh look at that, sorry for the noise. I'm not sure I've ever referenced a GitHub issue in a commit message body, didn't know it would generate activity.
Describe the bug
I can't clear suggestions from custom widgets.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Widgets can clear suggestions.
Screenshots
Desktop
Additional context