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 14540 invoked from network); 31 Mar 2021 08:11:44 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 Mar 2021 08:11:44 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1617178304; b=vlkb++N1TBuj3tFsOGiPiYHT9DfkhQrUf2vkrzsDy4O/TznKuuoyTBcI7c5PkiwZjJz4HnRB7f 0crJHjHrY2lIEJoDRzjQLOxs+EMLwNDmbs2x79ztQl+RzI0rUN+3Typ2h2BZPvxoRIkkzwgqCN eG7Qr30wFymFQjxjZhou/CON6pKgkktt8kbPljX2C2Aye7zADkJ0AriVak3dCQQFG6s39b/pQQ 2oU9YA4jzjIN46BqT2sW162sTBPgbwICaU4+zW6TdyocyCAmTzx/tMqewFYnFy11R1esnBEu9/ 3yAhDpqzlsR7G/BwOz+g99s5xQ7YPxhXsDdXjk0P4yDxQQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f53.google.com) smtp.remote-ip=209.85.167.53; 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=1617178304; bh=9ydAhIVCEI9/3sXY9GUrGpadL3MVZmLjI5gQZ9mDFmc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=SpYAv2uZ+znChIEzJJk3kF/UczRGP56lGxAif6d4FM5ybrCi26A4ml1LzZD7KUEs1KCWBQZka8 tIaqfv8DGAOYLwf4Tlozg+hktg6nLwmg2Am3xUJKLTGbyFMYxf1KQYkHN/kict70GKqTsc7bGw vmn/AlBbVuvDzkCJNPh7caooK4arDxbfcSbL662wlB1xyakH5YPS7Ea2v+Ott7T7N7O2f8joDt SwaVxuViWY4HYzG5+9V4gQEPy7igH3dh3RIrnxwq0a1O3g4NY25Q79xqtSt1UWrbmWXAkGQGZy 0MNfAcqxcrDYlHUzrvfUSWXjMTaYk8BxnwXJqXH9QTzS8w==; 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:In-Reply-To:References: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; bh=pJGpLr5XpqwsSmq3FXChsOAiZ+qVc7CnH0PbHluxFV4=; b=bJzgpLZZIOAWt6YBrzbfJNgWzg TONaSKNSUKdL3AXGbzs5/O0xKh6FtpVbY0WVSUaLpfGeBfDcoyUerr//fHAFdPXq+/0a9KhzyvEfN 0BzrTbgqMJiHBMUGMZCPfBHCnz2oVGhSqsHyPqoD/M3H76Y6el89MPXTKZimD3q3qONR/rYVxgiM4 wS1aez3nR5BOvMbclIFW0BOw8AH58wXcbbp4eRjHbBokfy51r9AsUcWBvO5RnOxdMu8n7jCpBFPtp Sdfs2p7QqYmcI3IJUEbbVGCVxy7tKR7IqmZlTYsT0dQ0pvWjSsyBZ1LO+idi8ls6DfkKtHrZYWHai 7dG3m6sw==; Received: from authenticated user by zero.zsh.org with local id 1lRVww-000DHQ-Lm; Wed, 31 Mar 2021 08:11:38 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f53.google.com) smtp.remote-ip=209.85.167.53; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f53.google.com ([209.85.167.53]:34748) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lRVwe-000D84-Nt; Wed, 31 Mar 2021 08:11:21 +0000 Received: by mail-lf1-f53.google.com with SMTP id i26so27777987lfl.1 for ; Wed, 31 Mar 2021 01:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=pJGpLr5XpqwsSmq3FXChsOAiZ+qVc7CnH0PbHluxFV4=; b=bgCzkYIzXohxsLj72aXGgbajXipkWcdc8KxE3YXb+H41W1dqDX3rC7T8w9hJfYpbzN WG2VTLfksX3xXhyl8TMcwHbtYAYLaBx/0ZdVX8+MLrwCI3XDDsQoT3YDB/xOI9Ft6J1R yBpj3nNUpvr75HPkuCr3c8dJFb6dxUm1isppC/THAZB7fvVqCaEzXaADlOXD18LUpwvk LZ7+RyaVbKUAyES6k4ki17mMVEHmOkFtYd4CgMYkOno96NUXBE+xNvCTrEnmNkRbLBp5 /B6WNNoUzWqsIXCL140CT9k2+SbuW/entosw32d7RTh0tVnMQtjWz+/frpA3/2wzar75 2nFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=pJGpLr5XpqwsSmq3FXChsOAiZ+qVc7CnH0PbHluxFV4=; b=GqwxEKs6AvcqhIpJ1ofi6ximxSmCIyFqM6ko1qpv/A8mnbeRv8VFZYwzcFMcWUbpZv ak4VBFw+BzGwrb0U2yVER0o24jM2ppcGM9Yx4vEXbKp2MYXd27gC6BZ9mt2QhBWlKuyb My12R35Sbue9d8dxXyBFUFCMQTaAhprrDiKJ6pODdwvErVchXorHf4WeE7a2d5pV1qgw d81iLdFXm9OqRGBs1kBTzGT3t86cVDNnonFljntEpzs4DPuFTienvFdGLwc7aqU/VXJt U7Z1J0L0QB/pwEwl71EW8cQoC0VzcQ86RZVqfzd/JDqCvuB2nNu9OE+P+SA6Fq1TotxK 4jAQ== X-Gm-Message-State: AOAM530/Rug602MM7c8FaCDBb8O0E+6OA24GhPmib36x2zVDg3/jaBir AUupa3m1Pl8IjIXZtN7sbqJPvREvFVm79S1iiEMpDKx3krY= X-Google-Smtp-Source: ABdhPJxaBAKaKAZgmxQfuJ0C2tI44evVKSWoDWjjEby3L5JAlKKmD95dUtDoer4I7cHIYEPH2UmBsXwTAKtk6Wa2RZE= X-Received: by 2002:a05:6512:3d27:: with SMTP id d39mr1498459lfv.463.1617178279410; Wed, 31 Mar 2021 01:11:19 -0700 (PDT) MIME-Version: 1.0 References: <1857440792.3267285.1611587238431@mail2.virginmedia.com> In-Reply-To: <1857440792.3267285.1611587238431@mail2.virginmedia.com> From: Marlon Richert Date: Wed, 31 Mar 2021 11:10:43 +0300 Message-ID: Subject: Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 48342 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Could someone please review Peter's patch, below? On Mon, Jan 25, 2021 at 5:07 PM Peter Stephenson wrote: > > On 21 January 2021 at 14:37 Marlon Richert wrote: > > % cd $(mktemp -d) > > % ZDOTDIR=$PWD HOME=$PWD zsh -f > > % autoload -Uz compinit > > % compinit > > % zsh_directory_name() { [[ $1 == c ]] && compadd -S ']' foo } > > > > Given the above setup, when > > > > 1. $LBUFFER is `cd ~[` or `cd ~[fo`, > > 2. $RBUFFER is empty, and > > 3. I press ^I, > > 4. then $LBUFFER becomes `cd ~[foo]`. > > > > 1. $LBUFFER is `cd ~[`, > > 2. $RBUFFER is `fo` or `]`, and > > 3. I press ^I, > > 4. then completion beeps and the buffer remains unchanged. > > > > `functions -t _complete` shows that the problem is caused by > > $compstate[context] becoming `tilde` instead of `subscript` as soon as > > $SUFFIX is non-empty, which causes _complete() to not call _subscript(), > > which is the only point of entry to _dynamic_directory_name(). > > The following is somewhere near, but this is quite complex and somewhat > at odds with completion in other contexts --- it's not clear to me > whether or not I should need that special diversion in _main_complete > but currently I do. (Your compadd -S ']' is going to add too many > ']'s in this case, I think, but that's a separate problem.) > > diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete > index 6b2cf2bcf..2bcbd2118 100644 > --- a/Completion/Base/Core/_main_complete > +++ b/Completion/Base/Core/_main_complete > @@ -94,8 +94,18 @@ if [[ -z "$compstate[quote]" ]]; then > if [[ -o equals ]] && compset -P 1 '='; then > compstate[context]=equal > elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then > - compset -p 1 > - compstate[context]=tilde > + if [[ "$PREFIX" = '~['[^\]]## ]]; then > + # Inside ~[...] should be treated as a subscript. > + compset -p 2 > + # To be consistent, we ignore all but the contents of the square > + # brackets. > + compset -S '\]*' > + compstate[context]=subscript > + [[ -n $_comps[-subscript-] ]] && $_comps[-subscript-] && return > + else > + compset -p 1 > + compstate[context]=tilde > + fi > fi > fi > > diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript > index 0c9a89ad5..0d9632864 100644 > --- a/Completion/Zsh/Context/_subscript > +++ b/Completion/Zsh/Context/_subscript > @@ -1,6 +1,8 @@ > #compdef -subscript- > > -local expl ind osuf=']' flags sep > +local expl ind osuf flags sep > + > +[[ $ISUFFIX = *\]* ]] || osuf=\] > > if [[ "$1" = -q ]]; then > compquote osuf > diff --git a/Functions/Chpwd/zsh_directory_name_cdr b/Functions/Chpwd/zsh_directory_name_cdr > index cb72e4600..b653e7c38 100644 > --- a/Functions/Chpwd/zsh_directory_name_cdr > +++ b/Functions/Chpwd/zsh_directory_name_cdr > @@ -16,8 +16,10 @@ elif [[ $1 = c ]]; then > typeset -a keys values > values=(${${(f)"$(cdr -l)"}/ ##/:}) > keys=(${values%%:*}) > + local addsuffix > + [[ $ISUFFIX = *\]* ]] || addsuffix='-S]' > _describe -t dir-index 'recent directory index' \ > - values -V unsorted -S']' > + values -V unsorted $addsuffix > return > fi > fi > diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c > index 8c0534708..1622d8a6b 100644 > --- a/Src/Zle/zle_main.c > +++ b/Src/Zle/zle_main.c > @@ -1067,6 +1067,7 @@ redrawhook(void) > int old_incompfunc = incompfunc; > char *args[2]; > Thingy lbindk_save = lbindk, bindk_save = bindk; > + struct modifier zmod_save = zmod; > > refthingy(lbindk_save); > refthingy(bindk_save); > @@ -1094,6 +1095,7 @@ redrawhook(void) > * restore lastcmd manually so that we don't mess up the global state > */ > lastcmd = lastcmd_prev; > + zmod = zmod_save; > } > }