From 8036b61ad18c3fcd4db1a865254924ca6729c73c Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Mon, 19 Dec 2022 11:53:31 -1000 Subject: [PATCH 1/2] docs: widgets calling autosuggestion widgets must be ignored (#716) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3cfd2e8..e35f8ef 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Widgets that modify the buffer and are not found in any of these arrays will fet **Note:** A widget shouldn't belong to more than one of the above arrays. +**Note:** Any widget which calls one of the [autosuggestion widgets](#autosuggestion-widgets) must be added to `ZSH_AUTOSUGGEST_IGNORE_WIDGETS` before creating the new widget's keymap. ### Disabling suggestion for large buffers @@ -102,7 +103,7 @@ Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a [glob pattern](http://zsh.sourcefor **Note:** This only affects the `completion` suggestion strategy. -### Key Bindings +### Autosuggestion widgets This plugin provides a few widgets that you can use with `bindkey`: From 5b1708d3c856e5e02b5985fb0dacaa81375a8377 Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Mon, 19 Dec 2022 11:55:06 -1000 Subject: [PATCH 2/2] docs: autosuggestion widgets can be called directly --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e35f8ef..f11530a 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a [glob pattern](http://zsh.sourcefor ### Autosuggestion widgets -This plugin provides a few widgets that you can use with `bindkey`: +This plugin adds a few [zle widgets](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets): 1. `autosuggest-accept`: Accepts the current suggestion. 2. `autosuggest-execute`: Accepts and executes the current suggestion. @@ -115,12 +115,22 @@ This plugin provides a few widgets that you can use with `bindkey`: 6. `autosuggest-enable`: Re-enables suggestions. 7. `autosuggest-toggle`: Toggles between enabled/disabled suggestions. -For example, this would bind ctrl + space to accept the current suggestion. +You can bind any of these widgets to a keyboard shortcut with [`bindkey`](https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins). For example, the following command would bind ctrl + space to accept the current suggestion. ```sh bindkey '^ ' autosuggest-accept ``` +You can also call any of them directly with `zle`. For example, the following command would accept the current suggestion (for an explanation of `ZSH_AUTOSUGGEST_IGNORE_WIDGETS` see [Widget mapping](#widget-mapping), above). + +```sh +my_widget() { + zle autosuggest-accept +} +typeset -ga ZSH_AUTOSUGGEST_IGNORE_WIDGETS +ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=( my_widget ) +zle -N my_widget +``` ## Troubleshooting