From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id F159227A82 for ; Mon, 27 May 2024 09:32:27 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1716795147; b=hNgp2My+cP2fNM2js/SHELNhh43btBDIqVM1M2M8eaxx0fAVWaAtoOT3Ws0tVbEYLXzi2tfgHC Fdj4KLcPG9M4H9ia/utHkGyTYkv74c5iKl9InxduZR10ZQaU97SplDFgszg6eHURzxopCyLdYj BXCnTJjumYDaEN9+zEup5wwQiMZK0PHejkxxV/rkTqPqu2/onvcMv4YqcvnPw8cJCZ+VuhLFUr OYpzTm4kYVvWUil2AqdYrbG5o45431D4omAUT3zxvyD9YKfwmEyo/ZBCRvpCWaLc4vQkSUBWFO ea/9qf0X8OQEKo5Tt84y6ufHlqK2DWVB/dUjb2J7KmQkVA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f43.google.com) smtp.remote-ip=209.85.167.43; dkim=pass header.d=gmail.com header.s=20230601 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-20210803; t=1716795147; bh=fELSY5qLsXCBU21AfYs9UY+T2yx8vsqTrfRLp4QOyfU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:References:Message-ID:Cc:Date:In-Reply-To:From:Subject: MIME-Version:Content-Type:DKIM-Signature:DKIM-Signature; b=Jzb0hKrAZgNbpNqeBQZyADwc8UD7YyljfTR9MeYlN8glviyuqMQd8xcelGWrcG8Lh4NVtebRCp 4gQ7zusQ57b1L7cHHxoUXbQnVWrbjQnso8nwxDspw/NVaRwCEykpfWeFsTH0z72HcyrJzwq7KI MLGo33z6bc6OPLPD1xiyzDjL4LzDZLDxIy7BTn6LBf10yWXZBI1xvCiG1pNJlLgU3WY6lIdNt9 rnK8M7s43UMLqGnBeUqqNqe6wbEH4eW1Ly6IkebosZjjpCeWWJ16FkHXlxrKB062Xf2Gt2H3FQ 6vDhK5OSpmue+BCIv10k9O1u9FzbL6vTlktaMRltZ5ZQNA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:To:References:Message-Id:Cc:Date: In-Reply-To:From:Subject:Mime-Version:Content-Type:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=D6RRJ8Y8M2k2+hq69yasPX/53VwJ0tmsE/38nOxr+lU=; b=BnRieMOwo0Os8zGSNO++El/NP1 hhL2vvJ8MdjzSMm4hC8cGroZ5IVKe8luWdxy0gagKlC1DAc9i5e112sc6RtFlpN3zjZjuMMvkVc1V SGSFbfL5to+H76fHj+WMTWExcUrYMYYZmImfH0/AqKYP6jTdE24u1GQ+DpydQRxgpfRdqwR9SaND8 zF9YhC4dxWcb0hJ/jkWpsxNzbJlS/0J6CJHOgev/YxcaR2nE9dz7R9uffVY8Fav9ymS2fSNqweeru x2bFBFkEtkhCFTmqx8FbwTgqdSakrT+IoHIQNSjsvkU9rPnDSS27HVd4K8cb7+y0gTrzSuJaMFubp P6P+nh5w==; Received: by zero.zsh.org with local id 1sBUqI-0002ip-DN; Mon, 27 May 2024 07:32:26 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f43.google.com) smtp.remote-ip=209.85.167.43; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f43.google.com ([209.85.167.43]:39539) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1sBUpO-00023l-Uy; Mon, 27 May 2024 07:31:32 +0000 Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5295f9b4f86so278948e87.2 for ; Mon, 27 May 2024 00:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716795090; x=1717399890; darn=zsh.org; h=to:references:message-id:cc:date:in-reply-to:from:subject :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=D6RRJ8Y8M2k2+hq69yasPX/53VwJ0tmsE/38nOxr+lU=; b=igQxMQXHAFIlVa2MNdmkSkJVohvvBPeQpmf9otpy3/QqQelRfV29xlOD0viQQGK+zV zCcIegJjb7pLd+78I5OFyGxYaSutROPHIShmCfOGpn3nIe7YcwbF2XEtLKM5ABhiTR74 1zFz6VdZmdZ42fZpgFgHbDD6+z9SalrfJZZr1oxNGei7FEBbwhLRENGO0gXiDTDOIIzl sIhWrj21i6HrzO1DDKtrq4nB2NSiAasLWfUbdyI2ZZLFFG5tS2y7I+zzbqjoN+MyYlre HlIKLnHBjItHVZKizP9M30m3XisjE3pKyJreYTpAlx0eyOkMlULoGAKlxmvuNzzPO0fX vEiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716795090; x=1717399890; h=to:references:message-id:cc:date:in-reply-to:from:subject :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D6RRJ8Y8M2k2+hq69yasPX/53VwJ0tmsE/38nOxr+lU=; b=Er+v6BVpJ/4+IBcGecWWt6eLZ7py2jzFUku4pGQ2k7fNgJXrI8HShfNm0cCeb1M/3o dUZEFAyEJNmsvkEeYjUg/Wokfnjs2meT6iTEF/0Pj7DdtwUqLZjUk8Wdx02Mm7Lf19+k efZ6/dy4jAVXbmlojOktuuN1HAuTR9lXPfj9790vLCOpDpH1vIjrvBr5fyVsTsOqGt0g l/xTVoKtm2rl5gpiw+sS54M3/f7xutlnyLGIAf+nsiQOri7Pzn7zlHzcCRmYMwesApc5 +g1K46yucJgEnrohD6tsGn1/xYUpbVSdyzq4WcJEUaufqQlsSn+HeSI5gtNobYq8FhrK g+SQ== X-Gm-Message-State: AOJu0YwAQDwkBuN4Dn7oEvB2C0te1p2QG0gf5MsKneglO3xfx/rO/kKR uXLFx6q7ZpU9LgXYwfpw5VfY8N2TEvQSp5vE3XshOAaJsKpBfEAL X-Google-Smtp-Source: AGHT+IElAwbXivPHC8T5aT4yWaAthum+CEjpi0I2fCi91NxJ4PYshMxabUI6PQEf+3YJ24AYalkswQ== X-Received: by 2002:a05:6512:2395:b0:51f:d82:8e07 with SMTP id 2adb3069b0e04-52964baf40cmr5994194e87.2.1716795089697; Mon, 27 May 2024 00:31:29 -0700 (PDT) Received: from smtpclient.apple ([193.66.59.56]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e886f61sm487654e87.60.2024.05.27.00.31.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2024 00:31:29 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_4F00DB54-DD62-4F22-ACA8-671759CDE888" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: Re: Yank index From: Marlon X-Priority: 3 In-Reply-To: <576626392.1946457.1716211026926@mail.virginmedia.com> Date: Mon, 27 May 2024 10:31:18 +0300 Cc: Zsh Users Message-Id: <4E7F7B4B-F105-4258-8E94-5E2E1814825B@gmail.com> References: <576626392.1946457.1716211026926@mail.virginmedia.com> To: Peter Stephenson X-Mailer: Apple Mail (2.3774.500.171.1.1) X-Seq: 29975 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: --Apple-Mail=_4F00DB54-DD62-4F22-ACA8-671759CDE888 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 20. May 2024, at 16.17, Peter Stephenson = wrote: >=20 >> On 20/05/2024 12:31 BST Marlon Richert = wrote: >> Inside a ZLE widget, is there a way to get the kill ring index of> = the >> active yank? Is it possible to move this index? >=20 > Looking at the code, I think it works in such a way that when you use > the special array $killring, available via the zsh/zleparameter = module, > the first entry is the one most recently yanked, i.e. the killring you > see in the variable effectively cycles by itself. (There is some > relationship between $killring and $CUTBUFFER --- I'm reading the code > as saying they can be manipulated independently, however.) >=20 > You can set killring=3D(...) and that similarly becomes the ring with = the > first entry as if you'd just yanked it, so you can cycle through it = just > by assigning the array in a different order. >=20 > However, I haven't tried this out, so I may be missing subtleties --- = I > doubt this ever got thought through to the level of detail you're now > investigating. I did some testing and doing yank-pop does _not_ cycle $killring. = Here=E2=80=99s what actually happens: - yank inserts $CUTBUFFER - Each successive invocation of yank-pop replaces the active yank with = the next non-zero entry of $killring, until it runs out of these, at = which point it inserts $CUTBUFFER and starts over. If we implement reverse-yank-pop by modifying $CUTBUFFER and $killring, = this will _not_ work correctly, because these changes will affect the = next yank. For example, given the following implementation: reverse-rotate-killring() { killring=3D( "$CUTBUFFER" "$killring[@]" ) CUTBUFFER=3D$killring[-1] shift -p killring } reverse-yank-pop() { zle -f yankbefore reverse-rotate-killring reverse-rotate-killring zle .yank-pop } zle -N reverse-yank-pop bindkey '^[Y' reverse-yank-pop The problem with this approach is that changes to $CUTBUFFER and = $killring are permanent: Whenever you use this particular = reverse-yank-pop widget, you don=E2=80=99t only change what you yank = now, you also change what you will yank _next time._ For example, given the above implementation and CUTBUFFER=3Da killring=3D(= b c ): - If I yank -> yank-pop -> yank, the command line changes a -> b -> ba - If I yank -> reverse-yank-pop -> yank, the command line changes a -> c = -> cc One would expect each yank above to insert a, but for the last yank this = is no longer true, because our clipboard has changed to CUTBUFFER=3Dc = killring=3D( c a ) Instead, this appears to be the only way to get reverse-yank-pop to work = correctly: reverse-yank-pop() { zle -f yankbefore local nonzero=3D( $CUTBUFFER $killring ) repeat $(( $#nonzero - 1 )); do zle .yank-pop; done } zle -N reverse-yank-pop bindkey '^[Y' reverse-yank-pop Being able to do something like (( YANK_INDEX-- )) or zle yank-pop -- -1 = would be a lot cleaner, but at least this implementation is simple and = short. --Apple-Mail=_4F00DB54-DD62-4F22-ACA8-671759CDE888 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On 20. May = 2024, at 16.17, Peter Stephenson <p.w.stephenson@ntlworld.com> = wrote:

On 20/05/2024 12:31 BST Marlon Richert = <marlon.richert@gmail.com> wrote:
Inside a ZLE widget, is there = a way to get the kill ring index of> the
active yank? Is it = possible to move this index?

Looking at the code, I = think it works in such a way that when you use
the special array = $killring, available via the zsh/zleparameter module,
the first entry = is the one most recently yanked, i.e. the killring you
see in the = variable effectively cycles by itself.  (There is = some
relationship between $killring and $CUTBUFFER --- I'm reading = the code
as saying they can be manipulated independently, = however.)

You can set killring=3D(...) and that similarly becomes = the ring with the
first entry as if you'd just yanked it, so you can = cycle through it just
by assigning the array in a different = order.

However, I haven't tried this out, so I may be missing = subtleties --- I
doubt this ever got thought through to the level of = detail you're = now
investigating.

I did = some testing and doing yank-pop does _not_ cycle $killring. Here=E2=80=99s= what actually happens:

- yank inserts = $CUTBUFFER
- Each successive invocation of yank-pop replaces = the active yank with the next non-zero entry of $killring, until it runs = out of these, at which point it inserts $CUTBUFFER and starts = over.

If we implement reverse-yank-pop by = modifying $CUTBUFFER and $killring, this will _not_ work correctly, = because these changes will affect the next = yank.

For example, given the following = implementation:

reverse-rotate-killring() {
  killring=3D( "$CUTBUFFER" "$killring[@]" = )
  = CUTBUFFER=3D$killring[-1]
  shift -p killring
}

reverse-yank-pop() = {
  zle -f = yankbefore
  = reverse-rotate-killring
  reverse-rotate-killring
  zle .yank-pop
}

zle -N reverse-yank-pop
bindkey '^[Y' reverse-yank-pop

The = problem with this approach is that changes to $CUTBUFFER and $killring = are permanent: Whenever you use this particular reverse-yank-pop widget, = you don=E2=80=99t only change what you yank now, you also change what = you will yank _next time._

For example, given = the above implementation and CUTBUFFER=3Da killring=3D( b c = ):

- If I yank -> yank-pop -> yank, the = command line changes a -> b -> ba
- If I yank -> = reverse-yank-pop -> yank, the command line changes a -> c -> = cc

One would expect each yank above to insert = a, but for the last yank this is no longer true, because our clipboard = has changed to CUTBUFFER=3Dc killring=3D( c a = )

Instead, this appears to be the only way to = get reverse-yank-pop to work = correctly:

reverse-yank-pop() {
  zle -f yankbefore
  local nonzero=3D( $CUTBUFFER $killring = )
  repeat $(( = $#nonzero - 1 )); do zle .yank-pop; done
}

zle -N reverse-yank-pop
bindkey '^[Y' = reverse-yank-pop

Being able to do = something like (( YANK_INDEX-- )) or = zle yank-pop -- -1 would be a lot = cleaner, but at least this implementation is simple and = short.

= --Apple-Mail=_4F00DB54-DD62-4F22-ACA8-671759CDE888--