zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Marlon Richert <marlon.richert@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] Incorrect usage of $PREFIX and $SUFFIX in completion functions
Date: Tue, 09 Apr 2024 11:14:55 +0200	[thread overview]
Message-ID: <52343-1712654095.077817@pvBu.uHUo._xjG> (raw)
In-Reply-To: <CAHLkEDvOWRUzDka4XAQf1rue8YhrtEbAQsth2V7FR9+n0NRSJA@mail.gmail.com>

Marlon Richert wrote:
> Many completion functions in the Zsh code base use $PREFIX$SUFFIX to get the
> word to complete on the command line. However, this seems incorrect to me,
> because it prevents the _prefix completer from functioning correctly for those
> completion functions.

If it is being used to get the word to complete then it is wrong. In
some complex cases, it may be a necessary compromise. There are also
cases where $words[CURRENT] is used (wrongly) instead of $PREFIX.

However, most cases of $PREFIX$SUFFIX found in a search of the functions
look valid at a brief glance. Note that, e.g.
  [[ $PREFIX$SUFFIX = */* ]]
is equivalent to doing
  [[ $PREFIX = */* || $SUFFIX = */* ]]

> Shouldn't all completion functions simply use $PREFIX to get the word to
> complete, since it is the responsibility of the completer function (_complete,
> _prefix, etc.) to decide whether the character to the right should be
> considered part of the word to be completed?

Depends on what exactly you mean by "word to complete". It is best
to leave matching up to the completion system so that it can handle
matching control etc correctly. There are cases where generating matches
is faster if you let the external tools filter by prefix. This is also
not uncommon in completions that have been converted from bash (which
isn't really the case for any included with zsh).

> Shouldn't _complete do `PREFIX+=$SUFFIX; SUFFIX=` before calling completion
> functions, since, otherwise, there is no meaningful difference between it and
> _prefix?

Definitely not. Given a<cursor>c and candidate matches abc and acd,
_complete should complete to abc with complete_in_word set, offer both with
_prefix and complete to acd if complete_in_word is unset.

Oliver


      reply	other threads:[~2024-04-09  9:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09  7:27 Marlon Richert
2024-04-09  9:14 ` Oliver Kiddle [this message]

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=52343-1712654095.077817@pvBu.uHUo._xjG \
    --to=opk@zsh.org \
    --cc=marlon.richert@gmail.com \
    --cc=zsh-workers@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).