From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3651 invoked from network); 23 Sep 2020 08:35:49 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Sep 2020 08:35:49 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1600850149; b=R9WmwV838l/52Pif+zICCqQCmRRDVyTOoNynIj1wkia53RHB3DynYLzQXPikuFW77lgk4bIOV4 KCPWT7FMPthfVv4JH/0558fQaJaxExvY5t8UiFRx6/++QooKntD4B3BmBViLJZOKrd0YLSNiuL vQwGC5G6T8ZcnTIxN8iEtsta58B+rLvnGUfY25GKut96JerV3bGzTAWPptDPYQzqa2d6GX73Bk xgtiAI5B91v44e1JkrtZeWRtlF77y4uh7jq/orPq8Xj3ZyOPaP7m/LZz8mxgqZb1YbDBOAtD7l 6hw9KpIGYIbldS6WGH6O8BxxEAcFP4H+yIc53428F2pwoQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f43.google.com) smtp.remote-ip=209.85.208.43; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1600850149; bh=DOYPI+KHZero6y8UvUgoHLumbqitPhNXBwMNxk06Kvg=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=uD3DZM/Hxbu8Bw+5l3FuaoxcgnNIxbR08NDBMnqeJeFcx7Rs3ojP3IhB4lkn+oXp7PV4x++E3r yky71i89Fm0QP+xlBxVZnoF/vFueC9NXygdlQ6uEyATnUl9zI1VQUCWHk8Sv1oMK1BCKTmw1uJ kLECliwLvRsdXT/NECsJa6qSM2jWGVQ8CjWhhNHrKqylRX1hWm1YWozXZ8zzE0y/09E7zvozzu kh2LRcn9nK1p76tpjD/XlvFGIyg8qutHDH56a3D76ro/3a2tj+1DYBR3SbeMX1En1uSr53hiKY D6QPhFptoRN1yn85MT8966kCj+DeF+zYGd2RM6gCBGnO7A==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=52Kyrrtaf8tY9PHvrakNLZNV6vs+m10EAOfu7p3vBn0=; b=H1WPlMr/ydFCGDMx98Bg94PmFk saf0FjmOYtghMN44XUu/lwM+dU2y7h3D9v/wEGCdPAQ0U9tlQYj4kEgsN+HYhn36lyhvBJeA6HE0+ K07El5RaGYcjrEIaWaSB6GKF1nABUWuW6K9DLdb5fR9loCzQZdcFxdp9if6grHpOGDvG1Mi4oKu5n 9Iza4wFWtCLGHoe1t9TR7j1YSYmpjCxbekvR1d+a9HtJlEXPYlZ1bE3WOZXS4MTuKrocMJW7CVYHR bkWk72LvFiPrEjwV1KpkeSReVL8TgJC0X/BHlk/MiNSbLhoUHzZL32yvGXkqlJpe+m/EXGS65ZlAU aXm0SxNg==; Received: from authenticated user by zero.zsh.org with local id 1kL0Fa-0007tw-72; Wed, 23 Sep 2020 08:35:42 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f43.google.com) smtp.remote-ip=209.85.208.43; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ed1-f43.google.com ([209.85.208.43]:42324) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kL0F1-0007WW-AX; Wed, 23 Sep 2020 08:35:07 +0000 Received: by mail-ed1-f43.google.com with SMTP id j2so18921803eds.9 for ; Wed, 23 Sep 2020 01:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=52Kyrrtaf8tY9PHvrakNLZNV6vs+m10EAOfu7p3vBn0=; b=F7oXqQgvJYBzShW1kF9m7GJYqepokHLLe2M+rBu6w9cvigh5H7RRbdCNuofzBU2yJF EhmvlJiBVjESnzlv7to3LAwxxqloHYTuf+Sp68pCpxmuij8tOEHZXo4YSaZrRS5IpBxp bR5FDXSyFE0d2wypKyLWRAsylS17ogJvpXyrO+cNskDgfSvHMJu0SX8fo3UQbaYv+bUW T8Qz/KwXABr6xJw+XwpJ8uAIe+JiyN2n1zyJnC/lL8JKEBS38lRwLQxQXGCBSBiUhVhS zKANsuseErggyUnD8Bl1jeoNhiZ4P3MhX6K2XleEQLXt7XEDuk/ozCBBZXwdWlhL8v2K +KZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=52Kyrrtaf8tY9PHvrakNLZNV6vs+m10EAOfu7p3vBn0=; b=gp5ixs20w6WejDRre4XHPLm5OVzcMOjbJHTDYSM1T5vLLtwsdfIBU32c7ku7EUQKYw YeyRCYhEEopJI+Z8XjvZB4+2iF3hmAJ52BzLDkIOynXCn+SKtSQ7nu2fO4y4jgD4/lnn 3cMdVPeIIZXi0GPbfnzGgOfewOnMEpkn/W01NHqy/0RwVjQFc1PQjTiW+mwHdO10ICxQ AEVuZ+ezAY1H5zIuRC1AMbG76UtwO/zG9Gdq2NQ7/qOd4CVcII1wIyVVkm0M+ZeHVZfk 8CKBXBlNAjMhR8z5Vc8uJJ/3KfVUJNBZmou3veq593HoyFIGINhmCl+l9o5QKFI0hE91 w1tA== X-Gm-Message-State: AOAM530BdBwGL9GHzwscXQAF0Qy7RbJ3Inlgp/LK2IpuhA+CLWJPBWkG 1pkRqdqdKL/jz96sEvAmSWK1Iez0j8UchzE0QQjcUunJ6mLjzg== X-Google-Smtp-Source: ABdhPJxpVc3RbXN4BzOVZPa9MviNyDkcoqbY2KIeCpCax6kbCv70JL9IdBeLoFvqS8ePHZ4ZFFWfcM0iRyhjxfS/zrE= X-Received: by 2002:aa7:cd90:: with SMTP id x16mr8418763edv.302.1600850106667; Wed, 23 Sep 2020 01:35:06 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?B?UGV0ZXIgU2zDrcW+aWs=?= Date: Wed, 23 Sep 2020 10:34:50 +0200 Message-ID: Subject: How to avoid infinite recursion in ZLE widgets To: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="000000000000f255e105aff6f5c9" X-Seq: 26073 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: --000000000000f255e105aff6f5c9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=C3=AD=C5=BEik --000000000000f255e105aff6f5c9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

I'd like to repli= cate the functionality found in some text editors - namely that if you pres= s a single or double quote, the editor inserts two of them and places the c= ursor inside the pair.

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

function insert-single-quotes() {
=C2=A0=C2= =A0=C2=A0 zle self-insert "''"=C2=A0=C2=A0=C2=A0 # that&#= 39;s "_'_'_"
=C2=A0=C2=A0=C2=A0 zle backward-ch= ar
}

zle -N insert-single-quotes
bindkey "'" insert-single-quotes=C2=A0=C2=A0=C2=A0 # t= hat's "_'_"

However, this soluti= on creates infinite recursion (a single quote bound to insert a single quot= e).

1. How to prevent the recursion? Is self-inser= t the right widget for this task?
2. I played with zle -U. What a= re the use cases for zle self-insert and zle -U?
3. I tried to av= oid the recursion by using "zle -K .safe -U text", but it ended w= ith "too many arguments for -K". How is zle -K expected to be use= d?

Thanks for your time,
Peter Sl=C3= =AD=C5=BEik
--000000000000f255e105aff6f5c9--