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

Re: Why is an 'x' appended in _prefix completer?



> On 8 Mar 2023, at 19:48, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Wed, Mar 8, 2023 at 4:49 AM Mikael Magnusson <mikachu@xxxxxxxxx> 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.



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