zsh-workers
 help / color / mirror / code / Atom feed
* Why is an 'x' appended in _prefix completer?
@ 2023-03-08 10:32 Marlon Richert
  2023-03-08 12:48 ` Mikael Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: Marlon Richert @ 2023-03-08 10:32 UTC (permalink / raw)
  To: Zsh hackers list

In _prefix, line 53, why is an 'x' appended to the completion? Looks
like a (21-year-old) typo to me.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why is an 'x' appended in _prefix completer?
  2023-03-08 10:32 Why is an 'x' appended in _prefix completer? Marlon Richert
@ 2023-03-08 12:48 ` Mikael Magnusson
  2023-03-08 17:48   ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2023-03-08 12:48 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list

On 3/8/23, Marlon Richert <marlon.richert@gmail.com> wrote:
> In _prefix, line 53, why is an 'x' appended to the completion? Looks
> like a (21-year-old) typo to me.

See the comment above addx() in zle_tricky.c and get_comp_string() (i
don't actually recommend looking at this code). I can't guarantee that
the x in _prefix is like this x, but it seems likely. Also, the patch
where it was added:
https://www.zsh.org/mla/workers/2001/msg02024.html

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why is an 'x' appended in _prefix completer?
  2023-03-08 12:48 ` Mikael Magnusson
@ 2023-03-08 17:48   ` Bart Schaefer
  2023-03-09  9:21     ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2023-03-08 17:48 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Marlon Richert, Zsh hackers list

On Wed, Mar 8, 2023 at 4:49 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> See the comment above addx() in zle_tricky.c and get_comp_string() (i
> don't actually recommend looking at this code).

I always wondered why Sven chose to use "x" instead of, say, something
out-of-band / non-printable.  I guess with metafication etc. maybe
there wasn't any such thing.

Anyway, as I recall it, the point of the extra character is to help
completion distinguish the position of word breaks when completing
somewhere other than at end of line.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why is an 'x' appended in _prefix completer?
  2023-03-08 17:48   ` Bart Schaefer
@ 2023-03-09  9:21     ` Peter Stephenson
  2023-03-09 15:29       ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2023-03-09  9:21 UTC (permalink / raw)
  To: Zsh hackers list

> On 08/03/2023 17:48 Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Wed, Mar 8, 2023 at 4:49 AM Mikael Magnusson <mikachu@gmail.com> wrote:
> >
> > See the comment above addx() in zle_tricky.c and get_comp_string() (i
> > don't actually recommend looking at this code).
> 
> I always wondered why Sven chose to use "x" instead of, say, something
> out-of-band / non-printable.  I guess with metafication etc. maybe
> there wasn't any such thing.
> 
> Anyway, as I recall it, the point of the extra character is to help
> completion distinguish the position of word breaks when completing
> somewhere other than at end of line.

That's a pretty obscure and undocumented effect at the point in question,
though:

      compadd -U -i "$IPREFIX" -I "$ISUFFIX" - "${compstate[unambiguous]%$suf}x"

compadd shouldn't be making this visible to shell code.

This is something to do with inserting an unambiguous prefix; I haven't worked
out on what occasions this line would be hit.  I would guess the _prefix
completer isn't used all that widely?

pws


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why is an 'x' appended in _prefix completer?
  2023-03-09  9:21     ` Peter Stephenson
@ 2023-03-09 15:29       ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2023-03-09 15:29 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Thu, Mar 9, 2023 at 1:23 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> > On 08/03/2023 17:48 Bart Schaefer <schaefer@brasslantern.com> wrote:
> >
> > Anyway, as I recall it, the point of the extra character is to help
> > completion distinguish the position of word breaks when completing
> > somewhere other than at end of line.
>
> That's a pretty obscure and undocumented effect at the point in question,
> compadd shouldn't be making this visible to shell code.

Prefix completion is in the middle of a word but without treating the
suffix as part of the word.  It's supposed to act like completion in
the middle of words in some other shell (old bash?).  So to hack that,
the _prefix completer inserts a space to the right of the cursor and
then completes as usual.  The "x" indicates where to remove the space
again when all is done.  It's not exposing the internals of compadd,
it's just using the same trick in shell code that compadd does in a
different case.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why is an 'x' appended in _prefix completer?
@ 2023-04-11  9:49 Marlon Richert
  0 siblings, 0 replies; 6+ messages in thread
From: Marlon Richert @ 2023-04-11  9:49 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Mikael Magnusson, Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1617 bytes --]

> On 8 Mar 2023, at 19:48, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Wed, Mar 8, 2023 at 4:49 AM Mikael Magnusson <mikachu@gmail.com>
wrote:
>>
>> See the comment above addx() in zle_tricky.c and get_comp_string() (i
>> don't actually recommend looking at this code).
>
> I always wondered why Sven chose to use "x" instead of, say, something
> out-of-band / non-printable.  I guess with metafication etc. maybe
> there wasn't any such thing.
>
> Anyway, as I recall it, the point of the extra character is to help
> completion distinguish the position of word breaks when completing
> somewhere other than at end of line.

I brought this up, because it has bugs.

Here are two test cases, each of which uses the following setup:

% mkdir foo bar baz
% setopt completeinword
% zstyle '*' completer _complete _prefix
% autoload compinit
% compinit
% bindkey '\t' tst
% zle -C tst complete-word tst


*Case 1: Literal x is inserted into command line*

% tst() {
  _main_complete
  compstate[insert]=1
}
% file fbar
       ^ Position the cursor over here, then press Tab

This results in:
% file fooxbar


*Case 2: Wrong character is set as autoremovable suffix*

% test() {
  _main_complete
  compstate[insert]=1
  compstate[to_end]=
}
% file bfoo
       ^ Position the cursor over here, then press Tab

This results in the following, which at first glance looks correct:
% file bar/foo

However, if you then press Space, this results in:
% file ba /foo

If you use region_highlight for the suffix, the r is highlighted as
autoremovable, too.

[-- Attachment #2: Type: text/html, Size: 5056 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-04-11  9:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 10:32 Why is an 'x' appended in _prefix completer? Marlon Richert
2023-03-08 12:48 ` Mikael Magnusson
2023-03-08 17:48   ` Bart Schaefer
2023-03-09  9:21     ` Peter Stephenson
2023-03-09 15:29       ` Bart Schaefer
2023-04-11  9:49 Marlon Richert

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