zsh-users
 help / color / mirror / code / Atom feed
From: Tomasz Pala <gotar@polanet.pl>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: _complete: insert unambiguous when globbing
Date: Wed, 5 Jan 2022 20:46:43 +0100	[thread overview]
Message-ID: <20220105194643.GA13958@polanet.pl> (raw)
In-Reply-To: <CAH+w=7YobgajzubM-nhbr39cHUn=WcaKMG4oXRkZiorWgdvbjg@mail.gmail.com>

On Mon, Jan 03, 2022 at 16:25:18 -0800, Bart Schaefer wrote:

> The basic problem here is that the set of common prefixes always
> includes the string originally on the command line when deciding
> whether to insert a partial result,

Can I get rid of this "original" string from the set? When backing of
from completion I always use ctrl-g anyway.

> completion process; the prefix from the command line is determined
> very early in both cases.  This suggests that some fiddling with the
> value of compstate[insert] could produce the "show prefix on first
> tab, enter menu on second tab" effect that I think you're asking for,

Yes, something like this - this might happen on one or two tabs or even
on some separate keybinding.


I did some digging and I think I've found a solution for my usecase:


--- /usr/share/zsh/5.8/functions/_main_complete.orig    2020-02-19 00:50:21.000000000 +0100
+++ /usr/share/zsh/5.8/functions/_main_complete    2022-01-05 18:34:57.828262149 +0100
@@ -389,6 +389,12 @@
     unset ZLS_COLORS
   fi
 }
+
+if [[ $PREFIX = *'*'* ]]; then
+    compstate[pattern_insert]=not_menu
+else
+    compstate[old_list]=keep
+fi

 # Now call the post-functions.
===

However since it sacrifices ZLE-provided pattern it's not perfect.

$ cd empty
$ touch 2021.12.29-14:41:02.xz 2021.12.29-19:41:02.xz 2021.12.30-03:41:03.xz 2021.12.30-14:41:04.xz 2021.12.30-19:41:02.xz 2021.12.31-03:41:02.xz 2021.12.31-14:41:04.xz 2021.12.31-19:41:03.xz

$ ls 2*04[tab]	=> 2021.12.3
files
2021.12.30-14:41:04.xz  2021.12.31-14:41:04.xz

so the compstate[old_list]=keep was required for the second [tab] not to
follow the updated ZLE contents. It works like a charm, but I wonder -
what cases would be broken by compstate[old_list]=keep with such a weak
condition? It would be much safer to have something like:

if [[ $PREFIX = *'*'* ]]; then
	compstate[pattern_insert]=not_menu
	compstate[eat_globbing]=yes
elif [ "$compstate[eat_globbing]" = 'true' ]; then
	compstate[old_list]=keep
fi

but I can't find a way to pass this down.

-- 
Tomasz Pala <gotar@pld-linux.org>


  reply	other threads:[~2022-01-05 19:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 12:39 Tomasz Pala
2022-01-03 15:40 ` Tomasz Pala
2022-01-04  0:25 ` Bart Schaefer
2022-01-05 19:46   ` Tomasz Pala [this message]
2022-01-05 20:11     ` Bart Schaefer
2022-01-06  1:52       ` Tomasz Pala
2022-01-06 10:38         ` Tomasz Pala
2022-01-05 20:15     ` Tomasz Pala
2022-01-05 20:25       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220105194643.GA13958@polanet.pl \
    --to=gotar@polanet.pl \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).