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 18868 invoked from network); 5 May 2023 11:45:28 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 5 May 2023 11:45:28 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1683287128; b=cVn5T086LpTrVi1pkfZAfwlTrzbOcSub4ahTV2pAYx0bw2HwTa/Fr0uQwXZxdGNUrknLtkmw0G PDBdsvYqA7Fzs2Oe8n1wRszNf9cTo/Up8Bs2oNfW0fohRHfUAqdqGzupEAXMMcFDnpMzxZl+2/ b+oQ4uNHnmiIq6CkzREj8CnaGmpN+/E/KcqpMUmrRid1Q8H7/223jQXYacyDRqzhb9ILC589w5 Z987mDLzkkgJP7tMIGjCIl9HHoSSB6WCH+LH/9jpriAhCa79IY02YPPFco+LoCuByT7GinkmhR dGoRmiRYbA2yK4sjgtFx4dLnfIHpx/KhsN8SXKrt5OID4g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f181.google.com) smtp.remote-ip=209.85.208.181; 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=1683287128; bh=4icdj1ycJAb+tfWHNlyk5SQbnOriejhq5RtB19LlNHk=; 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=mgiLp8vtwSZBPZuL4fR09O/qRURe4EAOzIAnSGizDK4895qclMNIRwcz1rSU9bM6acurgDEpyE 4oPjdZcXEKB+LscBCJ1CxirGW3/8O9p/McKnfxpA1TeV0YnzVuvVGaEwnoSASmntFDET7CdGJV HZ0Xmh1O8KrRnQfmouShYEXu8LXr0cOBN5VfLzU00UrIpc+ctYjx67ixa9QY9msVOiz9tIGTmi Hk8FSzFyvYSSbOWC9TfcQjTcGyb63RYTkX6RpSeZWIMfxzty4c2d2N4l+/1Ki/HW8XvzIVctYo VX1+FoeYSdSbDlT09vpWuxCy8mb9pBpBRjac5TXjm9ImSA==; 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=LCdjK3dpFU/P91KOvMddIjQQxvCdYOkRpOn+Cbjabys=; b=T2YLW5/ukyHHoZB0QLxc319SA5 wrbFrLvj4odQY4oh9n3jKoSNRXlvoL0PK6KQjFnfrSMz+/zmsUOG6rrQR1rT0CsdyTMPJrtbRLbXL AmnN2FbuW4Wqyxb44wEewJxv8NyNhaO2zPiqF/7wiPA2AFPD6F2b0X5z9r0cFzjo4nMJPd1+PzNx1 eJ/U3G1tMbcRbzpGTC07iCJbXBzLh8pruax7CbC3gy87xU/I5JI6HA+qZil4LMWz7f7FWvgWS/hZV VICqWO6ZIendAGwDDpGSzW0WwqkiZJju0JxHywecRPZo8wf+VoRm6hWnpjB1np9X2v5KYBat0V8iC VM3gNrNA==; Received: by zero.zsh.org with local id 1putsL-000MWC-IJ; Fri, 05 May 2023 11:45:25 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f181.google.com) smtp.remote-ip=209.85.208.181; 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-f181.google.com ([209.85.208.181]:39126) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1putrX-000MCa-9A; Fri, 05 May 2023 11:44:37 +0000 Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2ac786d12f7so3236911fa.0 for ; Fri, 05 May 2023 04:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683287074; x=1685879074; 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=LCdjK3dpFU/P91KOvMddIjQQxvCdYOkRpOn+Cbjabys=; b=qmNYz+8mPFGPgWHH2NPTW12x7ZBfhgd3SQY7d8UIpZ+eobu9VRlRSKa4LCcJi5MrX7 Qu2eD8bSbvB4gnoJGrIcHOjRcQDrY1NnprM1kcXQ13aeZ0MfH4A1GjHnPDarLE0GUpZI ZpCbhmUw5RWpfQXT7GgWYS8UT0D6wkPbXHklprIZPll7GqytZZjG6dLuwRF3Dn/SXePK F8k9hmV3uEuKZ1knmoc7B/d+nXxNAJFFDQDqhY26gQH176BMGkROBfrsv8G68B7h+bAT vYKnfvwy+G07SxCwI0QQewwnXZo9AyQDEi8Fqj+bVB/ex4pBevUAQsJqQ7EYWqjx40nR HKmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683287074; x=1685879074; 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=LCdjK3dpFU/P91KOvMddIjQQxvCdYOkRpOn+Cbjabys=; b=Z/x5KrRs57N5lkgCyc+oXmJeFuSu1/C0tKV70m6fBjQStwQDnFkpbqQmlWTxBOw/vm znaxkO9VrsY9AS/KBYkZDm5GP+UDQwBRKX7u2Ew7XCggOhh3QPqbyLMSotNwcXw55pgn ihrP9V20Px59BmEfoKE0KridYq1tOCbLeQApu3Ju2F9Qzbjl4Y3NEG8YunKDG9dYIL6W wERDw0wGtDFDQk9YSX7VV0C0D7X5Pb3wjPcu2Rav+ijxcyf9I5Wt21xAT43e2Bc0CTNt EmQhRk7VZqkYPI7C4lxhGTzV9B8ICWjVtPV7i1w8vZ9kU5EPR7YmH04Wag+zXNM8tJY4 z2DA== X-Gm-Message-State: AC+VfDwT/SoK1PE5SDGK1H1vvZhlEagDgOs46IReHnKomXNp+qWWOv7j ODlC+8Ef5Cb1LkJV43uN5caj4NZYtLkvqQ== X-Google-Smtp-Source: ACHHUZ5LUjrUINbXtE3olEloApUQT8jZhu5Z5bGtVwEjWdRAI2P87LVkixKSaxfQjnxRGSCE85EsGw== X-Received: by 2002:a05:651c:14d:b0:2a7:ab72:1687 with SMTP id c13-20020a05651c014d00b002a7ab721687mr352837ljd.5.1683287073915; Fri, 05 May 2023 04:44:33 -0700 (PDT) Received: from localhost.localdomain (178-55-136-176.bb.dnainternet.fi. [178.55.136.176]) by smtp.gmail.com with ESMTPSA id a16-20020a2e88d0000000b002a8b08882dbsm291085ljk.55.2023.05.05.04.44.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 05 May 2023 04:44:33 -0700 (PDT) From: Marlon Richert X-Google-Original-From: Marlon Richert To: zsh-workers@zsh.org Cc: Marlon Richert Subject: [PATCH 1/3] Fix _prefix insertion logic Date: Fri, 5 May 2023 14:41:55 +0300 Message-Id: <20230505114154.76547-1-marlonrichert@users.noreply.github.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: 51716 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: From: Marlon Richert 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 | 18 ++++++++++++++++++ Test/comptest | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Completion/Base/Completer/_prefix b/Completion/Base/Completer/_prefix index 74be5f47d..01739166e 100644 --- a/Completion/Base/Completer/_prefix +++ b/Completion/Base/Completer/_prefix @@ -49,14 +49,7 @@ 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 - fi + compstate[to_end]='' return 0 fi (( _matcher_num++ )) diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst index f976f9f91..51e246307 100644 --- a/Test/Y01completion.ztst +++ b/Test/Y01completion.ztst @@ -63,6 +63,24 @@ >NO:{file1} >NO:{file2} + comptesteval 'tst-insert() { compstate[insert]=1; compstate[list]= }' + comptesteval 'comppostfuncs=( tst-insert )' + comptest $': dir1\ebf\t' +0:_prefix with compstate[insert]=1 does not move to end +>line: {: file1}{dir1} + + comptesteval 'unfunction tst-insert' + comptesteval 'comppostfuncs=()' + comptest $': dir1\ebf\t\t\t\t' +0:_prefix inserts unambiguous and does not move to end +>line: {: file}{dir1} +>line: {: file}{dir1} +>DESCRIPTION:{file} +>FI:{file1} +>FI:{file2} +>line: {: file1}{dir1} +>line: {: file2}{dir1} + comptesteval $'zstyle -d \'*\' glob' comptesteval '_users () { compadd user1 user2 }' comptest $': ~\t\t\t\t\t' diff --git a/Test/comptest b/Test/comptest index 79c69979a..a57f4bcc4 100644 --- a/Test/comptest +++ b/Test/comptest @@ -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 -- 2.39.2 (Apple Git-143)