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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 1216 invoked from network); 15 Jun 2023 14:29:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Jun 2023 14:29:34 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1686839374; b=kJhPLQwlNJ7v5EdErU5XHpm+U4gH0Frxiw4OmzxP/8/gQEv3g7IPOrop08G5SL9m2IuuVwTqO0 gkL9dje+q9CcQqRot2krI6ExXq4bBZronGVh76yeJ0uYsje//zIria9M1eM0DbUBZEY2hLLmrO g0wEx6p0qt4t4roDUcvqrcns3EfV7Js41Ok2XeyNxmOHC8kAVomFrFym7JkrO9CG3w0h/wehpu s66ODAPF7Ss13xDl52xDOkbM9p2ivRn5+pB5cRODfmD/TpFXAxXwnD8DKFxJ9A/asHLp+QxLxj OCK0/oS8ybimvPpmZu7Lrvpamirs74fSpTK4tMmVyxpEeg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f174.google.com) smtp.remote-ip=209.85.208.174; dkim=pass header.d=gmail.com header.s=20221208 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=1686839374; bh=d/IniTeqaBZJbcz16GdFp82uF9xfi9BZ/HIjd/O/rjc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:DKIM-Signature: DKIM-Signature; b=eeIMUUazmx78bLCmxt3vnp9vxIVDvZyUWuZxiE24D7ecmz5d8v/rfL5SVpBD5G+UTqnDGUgHMq IlCZEmfB81XWcNwtiZiiaFh0fAsmA/2lDN7HMw+Gs8sTGyyB66Q0TARrbiMJEYVMVXzXyzit5s d/k7Ld9nyFn0ZNeAU+ndjm7bWbhSSwKy/aoMtWTXgOQtegR9LXLNqKgobv3qkuM19gk9fjiPPx knrk6tjWrKlSecNZi+pEBEHHNQagJZUqQZNudHeZLdYuObcBXJl5rhcz++6/SyJxxxkUt42J1p e0XNRXEZSH1jCuCS873dRoIqUmCCf7RobliasFlzCyAroA==; 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: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=xviU5zcd65B69/GiTVndVMNGx2K9SH2rjNtZxXW1pwM=; b=ZXL5pWOX5qWztFpUY3ud1ZcKWT e3AIPiyvaEQnRFuOWzvlBp6R+9MQ0gUprlZ8QaToDuQz2wPuJk0KnNcD2Q20C8T5VL9fpP44oMn91 q+kowACUsE53YNoB7U3e+OPnq8EmuxhpQQKUECEjxpfdyRg/2YUYYeLTRJFH5bZq548cX8BLviDSR jpefHaR5MZCUerdAc3sg5S6un9nsRdEGmnfGoWqXUy+txefx3ywM4GiEvCQpIplBm7rckYYr/KF3D Cjxf3CTAprTrDhJLMgKWK77bgj1GXG9GuF3J0QxQ60q+ex5cS0CXwe1wHWDdI2aa3dTlhq8iyfLak iAcPYR0A==; Received: by zero.zsh.org with local id 1q9nyf-000J0x-Ip; Thu, 15 Jun 2023 14:29:33 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f174.google.com) smtp.remote-ip=209.85.208.174; dkim=pass header.d=gmail.com header.s=20221208 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f174.google.com ([209.85.208.174]:39102) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1q9nyQ-000Iha-Qi; Thu, 15 Jun 2023 14:29:20 +0000 Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2b07762d292so21145871fa.0 for ; Thu, 15 Jun 2023 07:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686839358; x=1689431358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xviU5zcd65B69/GiTVndVMNGx2K9SH2rjNtZxXW1pwM=; b=DnDmagO3mycx6zFEgXQF5p1iT0wcYfu8l94WRID/jEf2HMF2w33gww15pIM9tFkCjF A9BlHv3FOydtTmeFsA02N/OyKETbGXiZlZLxcp47ks7eicrVT2Rgz+ZGiUvYSwR8ZGiP FAE98M6OnYkx8VjZwEkn6Y55j3mvLjq9iIm/Yu9xkSXUrH/Kl/TIVwhK/djlbx6Tg/4P 8BNJMTw+PQK2IHaaAM0+Pf70tzyUV6g9215/NKFHOLfwyToBppHCJ0D4bVzd3Ftx42gc vBSDaHWA/WJHY8Oiy1wQIjlcvq8vBtqD+geiSw1+GBEKhwJLhiHa9II68s8MgnUWDTaf fv9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686839358; x=1689431358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xviU5zcd65B69/GiTVndVMNGx2K9SH2rjNtZxXW1pwM=; b=UNXW3ii13iLaXCAhqj0GPTATduds9K/ODvrZY9ippNmmo2HV09bML92ezUvA654yCC QbSRg6jX/PVh+S36PvW2+t5S/Amso0+0kR+JiGunsBgDiOJYCDjnnC31W8kKpTPE15dp Qtc7+K4Y+61BYQJG5AesUZkPHArpNOPO0PWyEKEYwQhEOknRQUOo63i2lDWPSp4l12MU 7kTS3I8X8TMFtafUrRzk4o/VtNtxozh9ecJaBZ9D9Y0xGcDdF4sMYkDa51HSkElAJ+lH tGczjdZVktvggX9oTU6yrCTXoPqsry2EGvdorhqLvdBnJZreqj0zYVDSOjNoQJuJc56Q zIZQ== X-Gm-Message-State: AC+VfDwIN6wnd2FqoWUHmb5QeD3O5G/oDXiCcRmoWQIoOAvZTh32IntA aEoI4GqEy9H5y/22Orm4X46atOfP1GM= X-Google-Smtp-Source: ACHHUZ78Ph61OOai0u9++48MCgkm+pZm3bfcXjzRcpn+03IUkwX8pxvjTxZmLUbFpwJt0gg1pXQ2Kg== X-Received: by 2002:a2e:b5dc:0:b0:2b1:c184:9afe with SMTP id g28-20020a2eb5dc000000b002b1c1849afemr10209616ljn.4.1686839357814; Thu, 15 Jun 2023 07:29:17 -0700 (PDT) Received: from localhost.localdomain (178-55-121-159.bb.dnainternet.fi. [178.55.121.159]) by smtp.gmail.com with ESMTPSA id h8-20020a2e3a08000000b002b200d9838bsm3029037lja.104.2023.06.15.07.29.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 15 Jun 2023 07:29:17 -0700 (PDT) From: Marlon Richert To: Bart Schaefer Cc: zsh-workers@zsh.org Subject: Re: [PATCH] Let _approximate work w/ possible compadd function Date: Thu, 15 Jun 2023 17:29:16 +0300 Message-Id: <20230615142916.20616-1-marlon.richert@gmail.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 51861 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: Thanks, I wasn't aware of _shadow. Below is a new patch. I would find _shadow useful in my own Zsh code, too, not just completions. How about moving it from Completion/ to Functions/? -- Before this patch, if compadd had been overridden by a function of the same name, _approximate would not do corrections. --- Completion/Base/Completer/_approximate | 48 ++++++++++++-------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/Completion/Base/Completer/_approximate b/Completion/Base/Completer/_approximate index dcd8b2776..c0e605439 100644 --- a/Completion/Base/Completer/_approximate +++ b/Completion/Base/Completer/_approximate @@ -12,7 +12,6 @@ local _comp_correct _correct_expl _correct_group comax cfgacc match local oldcontext="${curcontext}" opm="$compstate[pattern_match]" -local dounfunction integer ret=1 if [[ "$1" = -a* ]]; then @@ -44,34 +43,31 @@ fi _tags corrections original -# Otherwise temporarily define a function to use instead of -# the builtin that adds matches. This is used to be able -# to stick the `(#a...)' in the right place (after an -# ignored prefix). +# Otherwise temporarily define a function to use instead of the builtin that +# adds matches. This is used to be able to stick the `(#a...)' in the right +# place (after an ignored prefix). # -# Current shell structure for use with "always", to make sure -# we unfunction the compadd. +# Current shell structure for use with "always", to make sure we unfunction our +# compadd and restore any compadd function defined previously. { -if (( ! $+functions[compadd] )); then - dounfunction=1 - compadd() { - local ppre="$argv[(I)-p]" - - [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 && - "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return - - if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then - PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}" - else - PREFIX="(#a${_comp_correct})$PREFIX" - fi +_shadow -s _approximate compadd +compadd() { + local ppre="$argv[(I)-p]" - (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) && - _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]} + [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 && + "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return - builtin compadd "$_correct_expl[@]" "$@" - } -fi + if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then + PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}" + else + PREFIX="(#a${_comp_correct})$PREFIX" + fi + + (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) && + _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]} + + compadd@_approximate "$_correct_expl[@]" "$@" +} _comp_correct=1 @@ -115,7 +111,7 @@ while [[ _comp_correct -le comax ]]; do done } always { - [[ -n $dounfunction ]] && (( $+functions[compadd] )) && unfunction compadd + _unshadow -s _approximate compadd } (( ret == 0 )) && return 0 -- 2.39.2 (Apple Git-143)