Subject: bug#76817: 30.1; completion-preview and shell

From: Eshel Yaron <[email-masked]>
Date: Fri, 14 Mar 2025 17:59:58 +0100

[ Resending with the mailing list back in CC. ]

Hi Rufus,

Rufus Segar <[email-masked]> writes:

> Hey Eshel,
>
>> Of course, I agree that this trailing space is undesirable for exactly
>> the reason you describe below.  You can disable it, as I do, by setting
>> either pcomplete-termination-string or pcomplete-exit-function.  Do you
>> get a better behavior with (setq pcomplete-termination-string "") ?
>
> Thanks! I added a hook to comint-mode to (setq pcomplete-termination-string "")
> and this has resolved the issue for me. Its working great now, so thanks again.

Great, thanks for confirming.

There's an alternative to setting pcomplete-termination-string directly,
which is to set comint-completion-addsuffix e.g. to nil.  Shell mode
consults this variable to and sets pcomplete-termination-string
accordingly, so if you set comint-completion-addsuffix once you don't
need to set pcomplete-termination-string via a hook.

I'd really like to make this work as you expect by default, so users
won't need this piece of configuration.  It's not hard to configure but
it's kind of an annoying gotcha...  It's mostly a matter of picking the
right place to tweak, since there are several intertwined components
that come into play.  For example, pcomplete-default-exit-function can
check if the completion ends with a directory separator (/), and if so
avoid adding pcomplete-termination-string.  I'll give it some thought,
and maybe someone who already gave it some thought will chime in too :)

>> The trailing space comes from the :exit-function that the completion
>> backend specifies.  completion-preview-mode calls that :exit-function
>> when you insert a completion suggestion, so in that sense it does work
>> as intended.
>
> I see. Interesting how it still inserts a trailing space after
> completing shell commands, even with the path completion fix described
> above. The trailing space is desirable here, so I ain't complaining,
> just curious.

Yeah, completion in Shell buffers is... involved.  In this case a
different :exit-function is in effect, which inserts a space regardless
of pcomplete-termination-string.  See shell--command-completion-data.

Regards,

Eshel