Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Make _expand_alias more usable as a completer

On Sun, Jul 18, 2021 at 4:35 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:
> On Sun, Jun 20, 2021, at 6:24 PM, Marlon Richert wrote:
> > On Mon, Jun 21, 2021 at 12:08 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > >
> > > On 6/20/21, Lawrence Velázquez <larryv@xxxxxxx> wrote:
> > > > On Thu, Jun 3, 2021, at 5:42 PM, Marlon Richert wrote:
> > > >> On Thu, Jun 3, 2021 at 2:24 AM Oliver Kiddle <opk@xxxxxxx> wrote:
> > > >>
> > > >> > I also wonder if this would be better done from within _command_names
> > > >> > directly but I'm not sure.

Handling it in _command_names would not be sufficient for global
aliases.  That said, I haven't actually investigated the use of
_expand_alias for global aliases.

> > > >> Actually, I feel like it could instead be added to the _expand
> > > >> completer. Would that be a better idea than what I presented in this
> > > >> patch?
> > > >
> > > > Anyone have answers to Marlon's questions?
> > >
> > > If it helps, I disagree with conflating _expand_alias (expanding
> > > aliases) and _expand (filename expansion).
> >
> > _expand already handles a lot more than just "filename expansion"
> > (which it actually does not handle at all).

Naming has always been a bit strange here.  Yes, strictly per the
docs, "filename expansion" refers to replacing a leading tilde with a
path prefix, and "filename generation" is a fancy term for globbing
but is considered a form of expansion.  I've forgotten why we couldn't
just stick with "tilde expansion" and "globbing" and leave "filename"
out of it entirely, but there you are.  In any event I think it's
likely that Mikael was referring to globbing.

> > Since alias expansion is in fact listed at
> > https://zsh.sourceforge.io/Doc/Release/Expansion.html, I don't think
> > it would be too weird to add it to the _expand completer.

I think it's actually a bit weird to allow _expand_alias to work as a
completer at all, because the completion system generally functions
very badly when the matches do not consist of single words, and
aliases don't usually have one-word replacements.  As soon as you
introduce something that contains spaces, completion gets very
confused (unless you force it directly into menu completion or
selection); if (otherwise) you attempt to press TAB twice to enter
menu completion, it'll instead start a new completion based on the
word after the rightmost space that is still to the left of the
cursor.  This is especially true when using compadd -U.

I suspect this may be where Oliver's tests and Marlon's attempt to
reproduce, went astray from one another.  In any case, I'm fairly sure
this is the reason that _expand_alias (before the patch) does not
allow other completers to run, and similarly it's why the user is
admonished to place _expand before _complete in the zstyle.

> Any other feedback on 48946?

Looking independently at the two questions, my feeling is I'd avoid
the patch as-is, but it wouldn't be unreasonable for _expand to handle
aliases (under control of a zstyle).

Messages sorted by: Reverse Date, Date, Thread, Author