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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26965 invoked from network); 9 Oct 2021 22:13:25 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Oct 2021 22:13:25 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1633817605; b=LOvwmLQhDI9VXpLZ23OTpLQnwdJ0dzK27eNE9tKn9iRmIgJo2gvCVHAA217DbgJhFWbM0V9b/q algxUO7Gwl5Nu8SbJEJtQYUcXg6697oAg8Tw72QIY20AVUb7hqCPu4a5r/PoBtV5PTKKuuSA1d ZkTDvgYfVL8bFW1wYrnujXdnF3I1Jjvz1iyqb34Zhrc7K4rZ492ThmtA2x3uIecuNL9+weK71F kvGE/OOewhexFdxm41lHCJJgvVzT1H42Id79yuvIcu5kJEJBmNQzEHJ5x3oietlom5Iow8ZOJI O3Nk8USmtgesJioBHFl02m/3krENYSUJxhsf4vcpTdyMbQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f42.google.com) smtp.remote-ip=209.85.217.42; dkim=pass header.d=gmail.com header.s=20210112 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=1633817605; bh=JndMPLN8wgeNLwJn5jtM55Y0VX4GCWbGgxmz8d3s7Dw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=fu0ldj2N354t4M3Mk00tD/WlkS559ePIpYQNquwm4Lf7hzaNVJFLCr3C09h9D3viGemkqM9eBg PTo8aB9tEkXalZcpZs7DuRgQ7fIrVl0gPy1QLadDDn5M+dBSkNcYy4EPaRFiuhbZzIsMwnO1me mXNyiTW6C97d6w2/JPC7pyKqYJIrfFewtHNEIW2QdGs8D6BK/vshmH12DgqCIrbg41XkhKoVAt IKU4+iFHIzTQF0wD2OKf0u9cwsuhXoFbhXPxnfsUC+3Q92hGfsNKjOCwc0hjz7lL7GIXAt4N/L u+jZ1EYYlizpShiawf9NFGbZsOT3XcWNpTvfFgfMIPoE4g==; 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:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=7cV7XtKPuZtzqtlAh3TpUdvxUtUHxs7r3XIktwzZ1R8=; b=E0jH8h+nfE1sK+4UBKfimGfSgW qCnZ/Y4GCC2KwMTaR1EvwifRd1yhJhX3KVcJ7yjVE/hmcd3F0aZegvEqImSuEL6mhprGNqT0IgAxX /YuGmCefFjcbjpx4LTUGte4r1MHFUt/PAPt1LZQcP/J8Oy26mEgLRyLkADCMvj0MTRTYg8gNFZMO4 AXq7mJ+hNS4rGdDoSqQs7T1TGy4868JuzgTYB0O6X7di5TeQt5k5cub9Ps7/WpXNaz1KuVbIEKfu7 oNHZ0fJ+JZ9PS504P2zCukim8yyvUIDjAAFek9KuxagasLS74EN+pb6P3VgqkSzLQehPhhWfU7nMa LHz9k3hw==; Received: from authenticated user by zero.zsh.org with local id 1mZKar-00056f-C0; Sat, 09 Oct 2021 22:13:25 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f42.google.com) smtp.remote-ip=209.85.217.42; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f42.google.com ([209.85.217.42]:39859) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mZKaK-0004N8-DI; Sat, 09 Oct 2021 22:12:53 +0000 Received: by mail-vs1-f42.google.com with SMTP id o124so14578164vsc.6; Sat, 09 Oct 2021 15:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=7cV7XtKPuZtzqtlAh3TpUdvxUtUHxs7r3XIktwzZ1R8=; b=fDeonDZv8BJ1vR+5RTKrcu6cOS2fb2AsTu9iLE3fQb0LUZqgdDjZAQq7X/GU5ly6Cl vrrEMC54a4IkLBDjRr2MJM/5VncQUKkvxYoIBMYnBwsXJU2YqfaQjoemj5Z8gpAb6QOP Ouhh64SvDJnlUiSfE6iVdCxFjRUN+pfdS9gJUo8708WYEVgjLnfaOOuAykB+nwJWzVi6 aKfmTrEsP97YcuU/snEkTdJN4llR8x08WmIcUBCbUjtj7TazDvU4b8Ofwjb9+ydZe/eE JBElWcKceazE3W/FqwyuXNn/o1fqbYCGmwAZfaoniyw5ZzwxMq3p+/08GQchUsWM7Qmk zrtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=7cV7XtKPuZtzqtlAh3TpUdvxUtUHxs7r3XIktwzZ1R8=; b=ZN+GfzKf/CE0X3lD1ZzVaZCjLk/BKh4L8w+EaPhYY//5j27aVrawUHRm6PY0pWB9yl gkf9avlicWp3o5AXstZj8gHujBrv/1SzzBoJKP4SgyaV3mZ0uDE7HdpHn9BtTwavueeY cjEK1ELP7JVjbLmk20m6nvGC9LBUI4aZJly0GvLAThVwbk8Tfk6g7RBZPjYPslA0/VL+ MyVlEbYMwScN/jra8bEaauy1Fm0Dly7S6AwiJ/4ejOxUsh8aHaU8+fddXAbvLZAo35lT T7FB6HZNP7XU9a9bS1XZ91MMQOOMTZR54SiTNnJ9b/eOT/xZxeh1981cl+WWJGWXiiKI pyUg== X-Gm-Message-State: AOAM532uOXGRgKyNcM6MECJhzbkmpdhgtJh5D2At5+adggk7u4AWHdat pvnBLg5dDvPahXi1gCYs9eO9Mv17sCnBlCiRafUsdlOr X-Google-Smtp-Source: ABdhPJzVt90YoS04+mV1twP1swALvP5hVdfeuR4C5QQcU98sgTK5YIDQtkSDA9EPhPVbQmOAy9b44Z9kMehwS5Gblms= X-Received: by 2002:a67:ae4b:: with SMTP id u11mr18079055vsh.33.1633817571224; Sat, 09 Oct 2021 15:12:51 -0700 (PDT) MIME-Version: 1.0 References: <20296-1632661753.678317@ipjb.25sX.Whnd> In-Reply-To: From: Marlon Richert Date: Sun, 10 Oct 2021 01:12:15 +0300 Message-ID: Subject: Re: Questions about completion matchers To: Bart Schaefer Cc: Oliver Kiddle , Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 27224 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: On Sat, Oct 9, 2021 at 7:23 PM Bart Schaefer wr= ote: > > I think what you've missed is that there are two things being > examined: The word on the command line, and the "trial completion", > that is, the word passed to compadd that might replace the one on the > command line. It's not merely (choosing the first of your seeming > duplications) > > > * b:$lpat=3D$tpat -> ${word/#$~lpat/$~tpat} > > * l:|$lpat=3D$tpat -> ${word/#$~lpat/$~tpat} > > Rather it's > > * b:$lpat=3D$tpat -> [[ $trial =3D ${~lpat}* ]] && > ${word/#$~lpat/$~tpat} > * l:|$lpat=3D$tpat -> [[ $trial =3D *${~lpat}* ]] && > ${word/#$~lpat/$~tpat} Perhaps I'm mistaken, but aren't you mixing up $lpat and $lanchor here? In the docs, it says: > Matching for lpat and tpat is as for m and M, but the pattern lpat matche= d on the command line must be preceded by the pattern lanchor. The lanchor = can be blank to anchor the match to the start of the command line string; o= therwise the anchor can occur anywhere, but must match in both the command = line and trial completion strings. Above, $lanchor is blank and thus needs to match only the start of the command line string, whereas anything to the right of $lanchor that matches $~lpat is simply replaced with $~tpat, just as in m:$lpat=3D$tpat. Are the docs wrong or am I understanding them wrong? Thanks, though, for this example, because it does help me understand what the documentation means with: > If no lpat is given but a ranchor is, this matches the gap between substr= ings matched by lanchor and ranchor. Unlike lanchor, the ranchor only needs= to match the trial completion string. Before, it was unclear to me how I should interpret "only needs to match the trial completion string", but now, I suppose it would be like this: l:$lanchor||$ranchor=3D$tpat -> [[ $trial =3D=3D *$~lanchor$~tpat$~ranchor* ]] && ${word//(#m)($~lanchor)/$MATCH$~tpat} However, isn't that equivalent to the following? l:$lanchor||$ranchor=3D$tpat -> ${word//(#m)($~lanchor)/$MATCH$~tpat$~ranch= or} Correct me if I'm wrong, but this seems to match the exact same trial strings. But then, the above transformation would be equivalent to this one: l:$lanchor|=3D$tpat$ranchor -> ${word//(#b)($~lanchor)/$match[1]$~tpat$~ran= chor} Again, something doesn't seem right here. On Sat, Oct 9, 2021 at 7:23 PM Bart Schaefer wr= ote: > In the cases with r: and R:, $ranchor is only compared to $trial, it > is not used when replacing into $word. Are you sure? The phrase "the ranchor only needs to match the trial completion string" is listed in the docs for l and L. Conversely, in the docs for r and R, it says "As l, L, b and B, with the difference that the command line and trial completion patterns are anchored on the right side." This makes me believe that, in the case of r and R, it is in fact $lanchor that is compared only to $trial, not $ranchor. If your interpretation were correct, l:$lanchor||$ranchor=3D$tpat and r:$lanchor||$ranchor=3D$tpat would be completely equivalent. Perhaps I should consider the _examples_ in the docs to be the truth and just ignore the ambiguous wording given earlier on in the docs. If I do that, then Oliver's examples now start to make sense to me and I can deduce the transformations as follows: Given 'r:|.=3D* r:|=3D*', c.u becomes c(^*.*).u* and c.s.u becomes c(^*.*).s(^*.*).u*. Ergo: * r:$lpat|$ranchor=3D$tpat -> ${word//(#b)$~lpat($~ranchor)/($~tpat~*$~ranchor*)$match[1]} * l:$lanchor|$lpat=3D$tpat -> ${word//(#b)($~lanchor)$~lpat/$match[1]($~tpat~*$~lanchor*)} * r:$lpat|=3D$tpat -> ${word%$~lpat}$~tpat * l:|$lpat=3D$tpat -> $~tpat${word#$~lpat} Given 'r:|.=3D** r:|=3D*', c.u becomes c*.u*. Given 'r:|[[:upper:]0-9]=3D** r:|=3D*', H becomes *H* and 2 becomes *2*. Ergo: * r:$lpat|$ranchor=3D** -> ${word//(#b)$~lpat($~ranchor)/*$match[1]} * l:$lanchor|$lpat=3D** -> ${word//(#b)($~lanchor)$~lpat/$match[1]*} Given 'r:[^[:upper:]0-9]||[[:upper:]0-9]=3D** r:|=3D*', H becomes *[^[:upper:]0-9]H* and 2 becomes *[^[:upper:]0-9]2*. Ergo: * r:$lanchor||$ranchor=3D** -> ${word//(#m)($~ranchor)/*$~lanchor$MATCH} * l:$lanchor||$ranchor=3D** -> ${word//(#m)($~lanchor)/$MATCH$~lanchor*} Given 'B:[nN][oO]=3D M:_=3D M:{[:upper:]}=3D{[:lower:]}', both _NO_f and NONO_f become f. Ergo: * b:$lpat=3D$tpat -> ${word/#(#b)(|?)($~lpat)##/$match[1]$~tpat} * e:$lpat=3D$tpat -> ${word/%(#b)($~lpat)##(|?)/$~tpat$match[-1]} How about changing the docs to just literally state the transformation that each matcher applies? It would be clearer than the prose it currently contains, which is ambiguous and open to interpretation.