Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

How to avoid infinite recursion in ZLE widgets


I'd like to replicate the functionality found in some text editors - namely that if you press a single or double quote, the editor inserts two of them and places the cursor inside the pair.

With some necessary checks for word boundaries, etc. left out, the solution looks rather trivial:

function insert-single-quotes() {
    zle self-insert "''"    # that's "_'_'_"
    zle backward-char

zle -N insert-single-quotes
bindkey "'" insert-single-quotes    # that's "_'_"

However, this solution creates infinite recursion (a single quote bound to insert a single quote).

1. How to prevent the recursion? Is self-insert the right widget for this task?
2. I played with zle -U. What are the use cases for zle self-insert and zle -U?
3. I tried to avoid the recursion by using "zle -K .safe -U text", but it ended with "too many arguments for -K". How is zle -K expected to be used?

Thanks for your time,
Peter Slížik

Messages sorted by: Reverse Date, Date, Thread, Author