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 21:15:23 +0100	[thread overview]
Message-ID: <20220105201522.GA6768@polanet.pl> (raw)
In-Reply-To: <20220105194643.GA13958@polanet.pl>

On Wed, Jan 05, 2022 at 20:46:43 +0100, Tomasz Pala wrote:

> 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.

OK, this was pretty straightforward:

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


It sacrifices *-using glob only (more robust test required?) because
that signals rough pattern (we do not want to break some refined ones).


And the problem is "provided pattern" vs "unambiguous prefix"...

In general this problem is not trivial, since preserving the ZLE-provided
pattern while completing unambiguous part would require to distinguish,
how much of that pattern was already consumed and needs to be
dropped, preserving the rest; the remaining part must match the same
items being prepended by the unambiguous part.


Having said that - does this behaviour deserve upstreaming with it's own
zstyle, or is it too hacky?

This allows for incremental completion with repeating (manual) globbing
provisioning, which seems fine for some quick and dirty patterns like *z
(for *.xz files), tastes best with undo/redo in finger memory.

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


  parent reply	other threads:[~2022-01-05 20:23 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
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 [this message]
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=20220105201522.GA6768@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).