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 6791 invoked from network); 20 Mar 2021 18:23:50 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Mar 2021 18:23:50 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1616264630; b=x7hBOsI4Zi8xI1Fqgttw8k9Hp9WU448dEJPzo1FS4FASTA+oIC0/EYE4l9XMRHL39yESy/MMsk cDNFwiK7kCsmwf+uhYCG1R3fyjMaglgBnIMWIVFxZlXMfhrh/SeMpE00HeATk/ucedVNX4v/jf tsBYLJGIqC9Lk8qloTOkIQGdDoMexoe5qXLKOo4S6q8rSGk5Tc8Kn71RmHNlOTIwY5wi3wBKro sSOAopgZJsAv1w7b8Kn2TDfSh1oO8nuwlqliLaaxiFxV7Pq7R7xNAZhD3W5H6egk/AUXgm2goT Y0QSsdS/Mzc5s9OhjlyFlKTYvVHF/ejLQCoAepJO4Jw+kw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f51.google.com) smtp.remote-ip=209.85.167.51; 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=1616264630; bh=FAD/Co7W4p93NTxGyKBolpSjsnH07DTTSgjHa0aYvJQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=qZpZaVDhjkV7ymdStSxp8AhFWOTXwE+iP+yR4HohLkbpTaFuKBAbQ+44XC0xtNjLFom1GFuOS9 jReFG1JgX1gH7hyO3Oc2WUPKR3bqcWeqX9OuEgZ+YQVobtyk2NdwFQOEeqp98DXLBiyeB4DmOr 8YP+nOfWekSkOdCPUf+DZg/hvrVGcS9CF4Pn27J3v8CT+kA/CN5cuYMGxmoZpUOokYqM1/WHja yKIFYrxbAKDy6/OtCelClQ151iRCimIUo+icOwBS4wD/CwYbbFb4nhdVc+rU177raI0yMyDa8t YU9xi47BCuuAm9SkqNCAPkYghGvIjFISxtrSfhsSNL4beg==; 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-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=q3RvXffR3mwPY/zbau1X4m2ktHKQxYzP+6SeW5I5z3Q=; b=nbd4v0fB+7l4EkbuVmqNwsfM7K fX+FQC8e3BF32d3Ug0YSmWQsbUTbLs7UBuIjX0z70Nys1U4q4Pg35ByS/urUANe6Kz4LgsNRiM47O BJpXeojKEIDtLaGOIwSTY0tEiQpcmGcIdkkMgnA6g4FWT1cLDS8rvZGZfwXgw9vHIsvT/xVRTiABe DTVDVVCbDYq9rb2eg0rZ/bEDI3SpeeuxHsWyye7iwq/soStR92EP5piP7G9T24B2qYuYknR1LoSxV W57tfNI2SVKAV0q+DahYs76JVrm/vbA04C7GSjTpIZdJlSu1fKJr1o3tx8OWiPZmKDa0orrtLyBQX vwvg19TA==; Received: from authenticated user by zero.zsh.org with local id 1lNgGK-000N6c-BT; Sat, 20 Mar 2021 18:23:48 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f51.google.com) smtp.remote-ip=209.85.167.51; 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-f51.google.com ([209.85.167.51]:41832) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lNgG3-000Mxj-5u; Sat, 20 Mar 2021 18:23:32 +0000 Received: by mail-lf1-f51.google.com with SMTP id b14so1740027lfv.8 for ; Sat, 20 Mar 2021 11:23:31 -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 :cc:content-transfer-encoding; bh=q3RvXffR3mwPY/zbau1X4m2ktHKQxYzP+6SeW5I5z3Q=; b=hrpimNM3IjLAnCdgPFJIilsorzbTufPNCeWJuSG++oZbHwJOk6PwAFFco0CDeX8WsZ UJlJHi0EbcC3BPpMGd2ZvXUfcmikGrwXlCE/0khnBRJDGqUgm4Zxi8usWVaUhDYZQml+ BQtqa/hP22mcmWQWKgspLTMCqTv9F5QFI446sAOeiM2t96q5jCQNnrfgAeg47TcLKLAO O7re63ci5+bYFR4isbj77whElNELdcloCkgdnmW7qc0Q3pH92gYWzNX6Rs6bhFeijHZF 8p9IEramnU69zeEBjsuF8Cu1tRtJ61rLX4B4Mnvs9JlcWCrmOnWWq6xwNCPcEAHp7ST8 Txtw== 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:cc:content-transfer-encoding; bh=q3RvXffR3mwPY/zbau1X4m2ktHKQxYzP+6SeW5I5z3Q=; b=qWR8QRdpB/ZP4/KRgS2VdYmC5ufVW5BIIcjGbjnO6Yxol5kgtW2S+AObfQCtrIQCwP mJkmH23J3Vb3KZKvd1e/n3Pt00qDJQpCZ68PpbEo3L/CQnvD18zmkmtPN7aWlfXcl4bB RqBnYD3adx64uSaXBV9LxXVnNsxHAmZ9i8mCY+RO3NeRupA3ROlYEMYkAExMLN1lWm7w bQy7MHQr5jKRCH6CGc7zT+lIzVl3oBpw+fU2zCTKRzy10JezQsc4XKAdpmtvWXzqsRPe GTWNefN00YWgWv6SUhfQKzr5hb+TWgyo0MIqO7EoWS8X7ERNAopiOyiNcrd0u3rETFrx l4Hw== X-Gm-Message-State: AOAM5311f6+iILb0BrIlSeQJvl54SYRhKz30Iq9FiTvdsDSWNcsxNaCc SMFMoj9ccMEBH1R0NRTAOvUx7kRe7MNUyatHjhiomDcRINGUQnV+ X-Google-Smtp-Source: ABdhPJxI1kOrYe0TWxYxi+ZNJ0ajQYbEtuvIUCFf2gTnKM4VYoLV32b8GCnkgLqdiwLjSVD/UBNC1eyOUHrNDmInTRo= X-Received: by 2002:a05:6512:1311:: with SMTP id x17mr4163587lfu.307.1616264610209; Sat, 20 Mar 2021 11:23:30 -0700 (PDT) MIME-Version: 1.0 References: <6c372e58-7709-4629-b2d0-e472a120404d@www.fastmail.com> In-Reply-To: From: Marlon Richert Date: Sat, 20 Mar 2021 20:22:52 +0200 Message-ID: Subject: Re: Bug + patch: _expand() fails to insert unambiguous prefix To: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 48204 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: On Sat, Mar 20, 2021 at 4:43 PM Lawrence Vel=C3=A1zquez wrot= e: > Sorry, that was more to elicit a review from a dev, but you're welcome to= expand the patch of course. New patch with accompanying test and all existing tests passing: diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand index def522a76..ea63d97ce 100644 --- a/Completion/Base/Completer/_expand +++ b/Completion/Base/Completer/_expand @@ -11,7 +11,7 @@ setopt localoptions nonomatch [[ _matcher_num -gt 1 ]] && return 1 -local exp word sort expr expl subd suf=3D" " force opt asp tmp opre pre ep= re +local exp word sort expr expl subd pref suf=3D" " force opt asp tmp opre p= re epre local continue=3D0 (( $# )) && @@ -181,6 +181,7 @@ if (( $#exp =3D=3D 1 )); then fi fi +pref=3D"${${${word:#[~/]*}:+$PWD/}:-/}" if [[ -z "$compstate[insert]" ]] ;then if [[ "$sort" =3D menu ]]; then _description expansions expl expansions "o:$word" @@ -188,7 +189,7 @@ if [[ -z "$compstate[insert]" ]] ;then _description -V expansions expl expansions "o:$word" fi - compadd "$expl[@]" -UQ -qS "$suf" -a exp + compadd "$expl[@]" -fW "$pref" -UQ -qS "$suf" -a exp else _tags all-expansions expansions original @@ -214,9 +215,9 @@ else normal=3D( "$normal[@]" "$i" ) fi done - (( $#dir )) && compadd "$expl[@]" -UQ -qS/ -a dir - (( $#space )) && compadd "$expl[@]" -UQ -qS " " -a space - (( $#normal )) && compadd "$expl[@]" -UQ -qS "" -a normal + (( $#dir )) && compadd "$expl[@]" -fW "$pref" -UQ -qS/ -a dir + (( $#space )) && compadd "$expl[@]" -fW "$pref" -UQ -qS " " -a space + (( $#normal )) && compadd "$expl[@]" -fW "$pref" -UQ -qS "" -a normal fi if _requested all-expansions; then local disp dstr @@ -232,8 +233,7 @@ else else disp=3D() fi - [[ -o multios ]] && exp=3D($exp[1] $compstate[redirect]${^exp[2,-1]}) - compadd "$disp[@]" "$expl[@]" -UQ -qS "$suf" - "$exp" + compadd "$disp[@]" "$expl[@]" -UQ -qS "$suf" -C fi _requested original expl original && compadd "$expl[@]" -UQ - "$word" diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index 169ca1f40..ebf04dc25 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -248,11 +248,10 @@ if [[ $compstate[old_list] =3D keep || nm -gt 1 ]]; t= hen ( -n "$_menu_style[(r)select=3Dlong-list]" || -n "$_menu_style[(r)(yes|true|on|1)=3Dlong-list]" ) ]]; then compstate[insert]=3Dmenu - elif [[ "$compstate[insert]" =3D "$_saved_insert" ]]; then - if [[ -n "$compstate[insert]" && + elif [[ -n "$compstate[insert]" && -n "$_menu_style[(r)(yes|true|1|on)=3Dlong]" && tmp -gt LINES ]]= ; then compstate[insert]=3Dmenu - else + elif [[ -n "$_saved_insert" && -n "$compstate[insert]" ]]; then sel=3D( "${(@M)_menu_style:#(yes|true|1|on)*}" ) if (( $#sel )); then @@ -289,16 +288,19 @@ if [[ $compstate[old_list] =3D keep || nm -gt 1 ]]; t= hen (( max )) || break done fi + [[ $compstate[insert] =3D menu ]] && + compstate[list]=3D"${compstate[list]/ambiguous/list}" if [[ ( -n "$min" && nm -ge min && ( -z "$max" || nm -lt max ) ) || ( -n "$_menu_style[(r)auto*]" && - "$compstate[insert]" =3D automenu ) ]]; then + "$_saved_insert" =3D automenu ) ]]; then compstate[insert]=3Dmenu elif [[ -n "$max" && nm -ge max ]]; then compstate[insert]=3Dunambiguous elif [[ -n "$_menu_style[(r)auto*]" && - "$compstate[insert]" !=3D automenu ]]; then + "$_saved_insert" !=3D automenu ]]; then compstate[insert]=3Dautomenu-unambiguous - fi + else + compstate[insert]=3D"$_saved_insert" fi fi diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst index f6474c4a1..cf0abe85d 100644 --- a/Test/Y01completion.ztst +++ b/Test/Y01completion.ztst @@ -44,6 +44,25 @@ >line: {: dir1/}{} >line: {: dir2/}{} + comptesteval "zstyle ':completion:*' completer _expand" + comptesteval "zstyle ':completion:*' tag-order '! original'" + comptesteval "zstyle ':completion:*:expand:*' keep-prefix no" + comptest $': d*\C-K\C-Wf*\C-K' +0:_expand inserts unambiguous prefix and highlights file types +>line: {: dir}{} +>DESCRIPTION:{expansions} +>DI:{dir1} +>DI:{dir2} +>DESCRIPTION:{all expansions} +>NO:{dir1 dir2} +>line: {: file}{} +>DESCRIPTION:{expansions} +>FI:{file1} +>FI:{file2} +>DESCRIPTION:{all expansions} +>NO:{file1 file2} + + comptesteval "zstyle -d ':completion:*' completer" comptesteval '_users () { compadd user1 user2 }' comptest $': ~\t\t\t\t\t' 0:tilde diff --git a/Test/comptest b/Test/comptest index a36e301e0..2069e48ac 100644 --- a/Test/comptest +++ b/Test/comptest @@ -57,6 +57,13 @@ expand-or-complete-with-report () { zle clear-screen zle -R } +complete-word-with-report () { + print -lr "" + zle complete-word + print -lr - "$LBUFFER" "$RBUFFER" + zle clear-screen + zle -R +} list-choices-with-report () { print -lr "" zle list-choices @@ -81,10 +88,12 @@ zle-finish () { zle accept-line } zle -N expand-or-complete-with-report +zle -N complete-word-with-report zle -N list-choices-with-report zle -N comp-finish zle -N zle-finish bindkey "^I" expand-or-complete-with-report +bindkey "^K" complete-word-with-report bindkey "^D" list-choices-with-report bindkey "^Z" comp-finish bindkey "^X" zle-finish