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 4510 invoked from network); 27 May 2023 13:13:41 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 27 May 2023 13:13:41 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1685193221; b=qdFSfw+c5Od52h1A2/HajZcO/C6/6TmZ7vcXG+RwP6DMUqUgCdQ/kR+9xs6AhrEmnNp0nTodvh ZMPOIPTmEqhIfcLUkVXLmOtuOnWDYodTrR7LnLz3LzJLCiK7L2aA1FnoRRan+b0xNdSCbT9vYk Z/64ybpUXBtmeEE36c4/j8zNkHNboYS2Zk8IQabx06v51otbjPeNpfbZveNAtKDVtPBivaiWXP b/fnyRjM9iFu3O/vChI09kPJM4olWTebOk/ALQcC513yxIew1xSVjmh24iNyLs8NPdVr4iVVb1 ys2sFJd2zmkWj250PsbPf6ticq3UTav66o3LeFblai565g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f180.google.com) smtp.remote-ip=209.85.208.180; 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=1685193221; bh=cxUvOUxjNAygvAzvHMdU+cb2ltmKqhE8jhKybwTOF3U=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:To:From:DKIM-Signature:DKIM-Signature; b=BfCCHl2bdldqNixdLUXc0/ux4nKyTqm9fG0N5qV9RNeZoo7sUTV+aCKL9eCE9itz89vr7Q8cdp RWPHsEZYnamxey2UBLUE72T/jxgI+i9LMyqhKcwiD/0SBl4aVETYK1FEohGzWJncqllizeqYaO KueLAdRbFrDmVdP6bJX10ZCS1db+D2KicjyjHnCdkDIdsn1hi+qBVGSV6+lO8ozoAoFZ2gaSSc bEXugbdGiJZMxe/SLHMAIlfOd6ymX7BmtU2992mS/9C06Cha/7E9C8bovjDupOM7odJrDtm7Rm CQGnn3B0u2NKG9iadFDIisnBA9KnvfR9S6INWknlD/qjow==; 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:Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=4dC244y8qDSPlS9mifOoQ0lHFFRBfMVg2+h/11I78gg=; b=oZSLcV8Ed3gPbai//kfgdlc2Ku Y+rJqM5NceMUg6MtHvvU3Z2K3TGQ/rV0ut9RaJ0j6wXKB5b7TWqaVr5UHVwBS2YK1J7FlEpDAdQyN ASj5PcK/OkMy4xH5XkqBJqzkuiXMP2FFdHrrwpEmZXHiDbNL4PEnH/hcLyicphTsb5x3z05utojbQ C6cQxw/CqKP8LWTtMZk4BhjO8aXVp9B9N2/NiUoSDlHze56Ld5XgIUAGb2b/zMnlqJL5AmfxGk/5Q 3fPEzEB5XWNP9HSaM2qlOlC80uPq8mEDQRI7in2RCAj8x256xWwjhtD6XuKw3Esd/Y3G6ETfwLYHF E1kFvrtA==; Received: by zero.zsh.org with local id 1q2tjo-00027y-WB; Sat, 27 May 2023 13:13:41 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f180.google.com) smtp.remote-ip=209.85.208.180; 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-f180.google.com ([209.85.208.180]:39166) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1q2tj7-0001nQ-0W; Sat, 27 May 2023 13:13:02 +0000 Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2b07762d292so536691fa.0 for ; Sat, 27 May 2023 06:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685193176; x=1687785176; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=4dC244y8qDSPlS9mifOoQ0lHFFRBfMVg2+h/11I78gg=; b=eUGllFvxf8jm8Qng102FnBU0Z51rQt5Kkgkv5TQP15lOwycEO6WmWC7rRm5qKLwGa5 1nj7sNk8fYRCxmSCdhLc31jOE+Jv5NZ/jySKKMXHec942Dr/rw8vz9Zq1Q6r71QvVK4Z 7EyTlroAMNJEuYFZOSBylNUMG8an+pjmRpTuzgQJMiye9U5tfZeSwA+a/Efvk8B5t3wc 9YILoB9JQ1sfGz00scNup4ebYb/R4pPnwFjlKqlM3majl0VS596o3RlLEkcMiSd5Zhbf jMdcridWiocWPVzNiKUbz8hFnZyxFQYImHBuvI2K4r3gauIPE+tpr3XU9MHOH3yS7gAF jM2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685193176; x=1687785176; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4dC244y8qDSPlS9mifOoQ0lHFFRBfMVg2+h/11I78gg=; b=B2Yq5K8KB1b4cUIjXGnAsyvfOBUj79rlEFqRNGRPU/kBWWqI7ILO1Ik0n46OJ09IJv aAvYXqqIGITjVgh4tmmJvq1HG5NAtFqMNMcRhIn6EkS/X/DquEgyVofZ4R08RzzdY4pP 9L29ttv0jD8ubPDoPAGTWmc+JvqfXYClzePf2peRi7FTMHUEpKd3wPKNJgc1DHftDkzO Ib3k2aL9Z06KVd5LK3NoQ2EE5osgy4P72OJUoGikHAUKY6oQo36+UamLf7RPYOzrIske XW+V/CzDZhO0oPMuYx0G1Fu6x+Ce49ZyilWe6Nr9NqQdVxvhMSnf42e5p/gSBfEEsgNf QPcw== X-Gm-Message-State: AC+VfDwT0nZj58Q+EfmqlfuK216PzjRn/ESNZcpbSGTXqYfRXn/li1kJ /FoZg4F/EEuUw6Ncs2BJ+4UAFVilIr84XQ== X-Google-Smtp-Source: ACHHUZ5VorE63M1iR6+HnQ6AoF0o4DT2+myAltqoj9My/Gf4NgEcwLI5KKdqjsASP/7jxUHE7tHuHg== X-Received: by 2002:a2e:aaa6:0:b0:2af:1ac5:f712 with SMTP id bj38-20020a2eaaa6000000b002af1ac5f712mr1461910ljb.3.1685193175428; Sat, 27 May 2023 06:12:55 -0700 (PDT) Received: from localhost.localdomain (176-93-107-108.bb.dnainternet.fi. [176.93.107.108]) by smtp.gmail.com with ESMTPSA id t4-20020a2e9c44000000b002ad99aa3fa8sm1378897ljj.13.2023.05.27.06.12.54 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 27 May 2023 06:12:54 -0700 (PDT) From: Marlon Richert To: zsh-workers@zsh.org Subject: [PATCH] Let _approximate work w/ possible compadd function Date: Sat, 27 May 2023 16:12:53 +0300 Message-Id: <20230527131253.33840-1-marlon.richert@gmail.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 51804 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: Before this patch, if compadd had been overridden by a function of the same name, _approximate would not do corrections. --- Completion/Base/Completer/_approximate | 55 ++++++++++++++------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/Completion/Base/Completer/_approximate b/Completion/Base/Completer/_approximate index dcd8b2776..cdde7a623 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,35 @@ 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 +[[ -v functions[compadd] ]] && functions -c compadd _approximate_compadd +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 - (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) && - _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]} + (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) && + _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]} + if [[ -v functions[_approximate_compadd] ]]; then + $functions[_approximate_compadd] "$_correct_expl[@]" "$@" + else builtin compadd "$_correct_expl[@]" "$@" - } -fi + fi +} _comp_correct=1 @@ -115,7 +115,12 @@ while [[ _comp_correct -le comax ]]; do done } always { - [[ -n $dounfunction ]] && (( $+functions[compadd] )) && unfunction compadd + if [[ -v functions[_approximate_compadd] ]]; then + functions -c _approximate_compadd compadd + unfunction _approximate_compadd + else + unfunction compadd + fi } (( ret == 0 )) && return 0 -- 2.39.2 (Apple Git-143)