zsh-users
 help / color / mirror / code / Atom feed
* How to avoid infinite recursion in ZLE widgets
@ 2020-09-23  8:34 Peter Slížik
  2020-09-23 11:21 ` Peter Stephenson
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Peter Slížik @ 2020-09-23  8:34 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 958 bytes --]

Hello,

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

[-- Attachment #2: Type: text/html, Size: 1320 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-09-26 10:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23  8:34 How to avoid infinite recursion in ZLE widgets Peter Slížik
2020-09-23 11:21 ` Peter Stephenson
2020-09-23 11:24   ` Peter Slížik
2020-09-23 11:29 ` Daniel Shahaf
2020-09-23 11:32   ` Peter Slížik
2020-09-23 18:25 ` zsugabubus
2020-09-24  9:55   ` Peter Slížik
2020-09-25 14:19     ` Peter Slížik
2020-09-25 14:43       ` Peter Stephenson
2020-09-26  9:27         ` Daniel Shahaf
2020-09-26  9:40           ` Roman Perepelitsa
2020-09-26 10:24             ` Daniel Shahaf
2020-09-26 10:31               ` Roman Perepelitsa

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).