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 727 invoked from network); 15 Jun 2023 14:12:14 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Jun 2023 14:12:14 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1686838335; b=PinzrkKg1o21JIYp0lCm2RNz11TJ+nmnMPQU+GLCiVhfAcKbTBlPAg+vNNKtTrKnDTIB/QVQC/ eZH9O+wjR9ODft2KqNmYSxYz7YUmcT+OHcZ6hogc1prS/OPHr67LL/tLB47HbdlT7pR1GIj/0N IQIwoZZRqKmD320+CdaZ3kFH4/lPzjPWjvHYSdoiPh6117+2bU3I7LRjClyFlDkCaieHEAn6bL bLL82CLDFqCLccP6kbExhPcEYpQugUWlBt63ZL5kI4QrEnX+2PVMhumF7zph4bNEG+6Ip34D58 sprIrIbWDxP2Z1h/rZl4MJRQtfjgXfq2QnzEaTv1WJzhbg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f182.google.com) smtp.remote-ip=209.85.208.182; 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=1686838335; bh=uRx3fmvAF3G/KWzeeBQdPTF/WJvT4LNsVWH3mrG0Xcw=; 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=haA/YUbkSmidx+iqxK71iN30Ncx+kgEM4cOO+qEnvFYkF7wOGVoG9YRdoo1dh1bZpDtrpsKb8G XGL3uvDBicF8dfXcALC9bejBcasrMEtRH4GfA1eZhXFYlSd+KHrn7+aIPi6XPM4Z2OqOoGwfDN doYP7/oKTjM4e61cSIyTYOfSfSYxtMKN1JMnYSmOFR3adqa9zQrCHls+FkL/isMEccNIbObmKV WFqSv88/Psp+1WQ0QAT+af6FrnyybcifJexuBLq4fQRiF38Jcyx/Xg0jYETS57bOC+ebIoTUy+ XEuWvhnG+Nk0asDR2rHyrn95q9TK/CUULqYKDbyQ1l7jow==; 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=aUSnO5nmHuD/d4ikVW4teYwo7qxO38MwUZuUNJ2+RzY=; b=eKtwFROjFIAPqrebz1siU1h8N0 YFLp/h0hBnBt5kaPYRcY7+JCFW2QWedj46akUKktyX07S7Mc8J0pjCpQ2EKkfXMe1ssqZtjX/8lcj tupWd1lFxk3wLtCzZ0XAiKGKAILciB9YvOtV1W92SR+fGZLgJf8pPSJfrNaQd8UfMt8mupwRUBMgG MKH6qijg4MLRBsJVati8SQsaCAyM72vcJxELUYDol2UimGyDvTU/9ujOl/07VrrEhgvoWhAraBuCk JrQx1ZjorVZuPMiMrmepAWnSOgRzC8c3HWvqKk7Okz+4J7MXqhiGbOpvEhPnDklyscHsL3eHkfcs0 hdnEytsw==; Received: by zero.zsh.org with local id 1q9nht-000I4S-AL; Thu, 15 Jun 2023 14:12:13 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f182.google.com) smtp.remote-ip=209.85.208.182; 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-f182.google.com ([209.85.208.182]:38294) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1q9ngy-000HjW-1c; Thu, 15 Jun 2023 14:11:18 +0000 Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2b447c7ab48so1695851fa.1 for ; Thu, 15 Jun 2023 07:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686838275; x=1689430275; 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=aUSnO5nmHuD/d4ikVW4teYwo7qxO38MwUZuUNJ2+RzY=; b=DeuuNA0dls5kmSK1N6XPjeEwm4un6IyILSmJrJFkIVx1wWJQQlNbfbm7zLYaJ1krfo t/64/WWVTbspwQQRtYpMqdSHj0TMhAAzhTRlIQ0KEfgTJMkIrhJtd1Je1dleS2auBnty iyOYcbtX3FQTByBPWHf0h/3srlWKBi+9Q0UfUemX0/tr1VSOVyXsnHhc0cBN66DM9Soc F4AtqGJERjjzqnuwf30TMWm8BPIMsjObbKrghp9iAZ05VifFCKmn8sJbG91UvWdXFa+v IiJo081U88AdmXPl0v8ePdTqd+VeHYtT4tgd/KhaQiCIu6GTgTZ7HiuOWd5YNt8T8QP1 L5LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686838275; x=1689430275; 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=aUSnO5nmHuD/d4ikVW4teYwo7qxO38MwUZuUNJ2+RzY=; b=Vhvomqc01BVt6DvVvZIt30XrogmaLO8CtXHzaJMFXQPOo6APGjHf87bebvrqmmRYms otTK7798UNdWRa/vKxJ4u13mpIP2uAJgOwbahvHLwOJT3g3LCZ3SlZDZpla/WKVKhgT9 Z3MeYYjCWExLwpOEBLALIBoNPorTX8ma0CDctSggi7Tow7dRutedfBUC8GI9dBiWX+Er 9PzvYpIZDpyGujaIQGXCDX+VsgWa3112YBIaM/3mLX2gJIRzJnwkkeHDTKH5J2N4C4zz H6X81fPyIr2ghH/9QvvQGHdZgXlaQUMS/SjpC5xJmRdPNitvhMn/OvRlHjIH404tipMU l/qw== X-Gm-Message-State: AC+VfDzcwQO00iEoALX6krPWgd4asmbNhfC0CxEuiJS8wkX+sguT4fIb kRoYxLV6D0KAYgTU0lMzebc= X-Google-Smtp-Source: ACHHUZ6AQJhIclWMv9iBBRJqnQ+eAP3lF4Yge+guNQBw5Vy2Br69iGCNOc8TqFQdq4r+LojHVR7Jvw== X-Received: by 2002:ac2:446f:0:b0:4f7:5566:72ea with SMTP id y15-20020ac2446f000000b004f7556672eamr4569455lfl.0.1686838274554; Thu, 15 Jun 2023 07:11:14 -0700 (PDT) Received: from localhost.localdomain (178-55-121-159.bb.dnainternet.fi. [178.55.121.159]) by smtp.gmail.com with ESMTPSA id l1-20020ac24a81000000b004cc9042c9cfsm2568697lfp.158.2023.06.15.07.11.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 15 Jun 2023 07:11:13 -0700 (PDT) From: Marlon Richert To: "Jun . T" Cc: zsh-workers@zsh.org Subject: Re: [PATCH 1/3] Fix _prefix insertion logic Date: Thu, 15 Jun 2023 17:11:12 +0300 Message-Id: <20230615141112.12919-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: 51860 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: You're right, the test cases still fail. I added test cases to the build and wrote code until they past. However, I had bugs in the test cases and thus ended up not solving the problem. Here's a new patch, below. I added more exhaustive testing to make sure it definitely works correctly now. --- Fix _prefix insertion logic This solves the following problems in the _prefix completer: - The old code had logic for dealing with compstate[unambiguous] that was unnecessary. It works fine without it. - Because of this logic, if a widget set compstate[insert]=1 after calling _main_complete, an `x` was left after the completion on the command line. - If the same widget also set `compstate[to_end]=`, then instead, the last character of the inserted completion would be treated as an autoremovable suffix, with the actual suffix being inserted to the line as a normal character. - After inserting a completion, the cursor would move to the end of the entire current word on the command, not the end of word that was inserted. This is not what you want with _prefix, since you are trying to complete a word _before_ the one on the command line, after which you usually want to insert a separator, such as a space or slash, before the next word. Discussed in workers/51641. --- Completion/Base/Completer/_prefix | 9 ++---- Test/Y01completion.ztst | 48 +++++++++++++++++++++++++++++++ Test/comptest | 10 +++++-- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Completion/Base/Completer/_prefix b/Completion/Base/Completer/_prefix index 74be5f47d..aea2f7863 100644 --- a/Completion/Base/Completer/_prefix +++ b/Completion/Base/Completer/_prefix @@ -49,13 +49,8 @@ for tmp in "$comp[@]"; do fi if [[ "$tmp" != _prefix ]] && "$tmp"; then - [[ compstate[nmatches] -gt 1 ]] && return 0 - compadd -U -i "$IPREFIX" -I "$ISUFFIX" - "${compstate[unambiguous]%$suf}x" - compstate[list]= - if [[ -n $compstate[unambiguous] ]]; then - compstate[insert]=unambiguous - else - compstate[insert]=0 + if [[ -n $compstate[old_list] || ${compstate[unambiguous]%$suf} == $PREFIX ]]; then + compstate[to_end]=match fi return 0 fi diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst index fb369ea69..fc18b19a4 100644 --- a/Test/Y01completion.ztst +++ b/Test/Y01completion.ztst @@ -35,6 +35,54 @@ >line: {: dir1/}{} >line: {: dir2/}{} + comptest $': d\t\t\t\t\t \t' +0:unambiguous prefix and autoremovable suffix +>line: {: dir}{} +>line: {: dir}{} +>DESCRIPTION:{file} +>DI:{dir1} +>DI:{dir2} +>line: {: dir1/}{} +>line: {: dir2/}{} +>line: {: dir1/}{} +>line: {: dir1 }{} +>DESCRIPTION:{file} +>DI:{dir1} +>DI:{dir2} +>FI:{file1} +>FI:{file2} + + comptest $': suf\ebd\t\t\t\t\t \t' +0:unambiguous prefix and autoremovable suffix with _prefix completer +>line: {: dir}{suf} +>line: {: dir}{suf} +>DESCRIPTION:{file} +>DI:{dir1} +>DI:{dir2} +>line: {: dir1/}{suf} +>line: {: dir2/}{suf} +>line: {: dir1/}{suf} +>line: {: dir1 }{suf} +>DESCRIPTION:{file} +>DI:{dir1} +>DI:{dir2} +>FI:{file1} +>FI:{file2} +F:regression test workers/51641 + + comptesteval 'comptest-postfunc() { compstate[insert]=1 compstate[list]= }' + comptest $': \t \t' +0:compstate[insert]=1 compstate[list]= +>line: {: dir1/}{} +>line: {: dir1 dir1/}{} + + comptest $': suf\eb\t \t' +0:compstate[insert]=1 compstate[list]= with _prefix completer +>line: {: dir1/}{suf} +>line: {: dir1 dir1/}{suf} +F:regression test workers/51641 + + comptesteval 'comptest-postfunc() {}' comptest $': *\t\t\t\t\t\t' 0:_expand shows file types >line: {: dir1/}{} diff --git a/Test/comptest b/Test/comptest index 79c69979a..4a9bd9b7f 100644 --- a/Test/comptest +++ b/Test/comptest @@ -21,7 +21,7 @@ comptestinit () { export PS1="" zpty zsh "$comptest_zsh -f +Z" - zpty -r zsh log1 "**" || { + zpty -r zsh log1 "**" || { print "first prompt hasn't appeared." return 1 } @@ -40,7 +40,7 @@ KEYTIMEOUT=1 setopt zle autoload -U compinit compinit -u -zstyle ":completion:*" completer _expand _complete _ignored +zstyle ":completion:*" completer _expand _complete _prefix _ignored zstyle ":completion:*:default" list-colors "no=" "fi=" "di=" "ln=" "pi=" "so=" "bd=" "cd=" "ex=" "mi=" "tc=" "sp=" "lc=" "ec=\n" "rc=" zstyle ":completion:*" group-name "" zstyle ":completion:*:messages" format "%d @@ -51,6 +51,12 @@ zstyle ":completion:*:options" verbose yes zstyle ":completion:*:values" verbose yes setopt noalwayslastprompt listrowsfirst completeinword zmodload zsh/complist +zle -C complete-word complete-word complete-word-with-postfunc +complete-word-with-postfunc() { + local +h -a comppostfuncs=( comptest-postfunc ) + _main_complete "$@" +} +comptest-postfunc() {} complete-word-with-report () { print -lr "" zle complete-word -- 2.39.2 (Apple Git-143)