Subject: Re: bug#70198: M-x shell: deal with environment variables present when tab expanding

From: Federico Tedin <[email-masked]>
Date: Wed, 10 Jul 2024 20:11:07 +0200

Eli Zaretskii <[email-masked]> writes:

> What happens if the command itself has embedded '='?

Ah good point, I incorrectly assumed that after
`comint-match-partial-filename' was called, the point would be at the
beginning of the command rather than at the end. That being said if we
used (match-beginning 0) as PT then it would address this particular
scenario (when calling `shell--skip-environment-variables' I mean).

> What happens if the '=' character is quoted?

What would be an example of this? (in the context of writing shell
commands).

> I think a better idea might be first to try to find what is "the word
> at point", and then complete only that word.  WDYT?

Yep, however I do think we still need to walk back some words in order
to ensure that we are not autocompleting an argument; for example

$ echo whoam[TAB]

should not autocomplete to "whoami", I'm assuming.

So for the actual walking backwards we need to maybe:
- modify shell-backward-command so that it leaves the point at the
beginning of the command, but after any env vars
- or, move backwards using `shell-command-regexp' until the last thing
that does not look like FOO=BAR or FOO= is found.

All of this just to ensure that the word at point is an actual command
and not an argument to a command. Maybe this approach itself could be
re-evaluated though !