Subject: Re: bug#60464: 29.0.60; Regression - pcomplete-arg fails with argument 'last

From: Stefan Monnier <[email-masked]>
Date: Wed, 04 Jan 2023 10:56:26 -0500

Gregory Heytings [2023-01-04 15:39:26] wrote:
>> Your implementation with the 'last condition doesn't make sense.
> Can you please try to make it fail?
>> It is not a good idea to treat 'last specially such that we return a
>> different type in this case.
> I'm not the one who wrote that code.  According to my analysis of the code,
> the only place where pcomplete-arg is called with a 'last' argument is
> pcomplete-parse-arguments, where you will see the following:
>
> (defun pcomplete-parse-arguments (&optional expand-p)
>   ...
>   (let ((results (funcall pcomplete-parse-arguments-function)))
>     (when results
>       (setq ...
> 	    pcomplete-stub (pcomplete-arg 'last))
>       (let ...
> 	(if (and (listp pcomplete-stub) ;??
> 		 (not pcomplete-expand-only-p))
> 	    ;; If `pcomplete-stub' is a list, it means it's a list of
>             ;; completions computed during parsing, e.g. Eshell uses
>             ;; that to turn globs into lists of completions.

That's also my understanding.  So I think The Right Fix (or at least The
Better Fix) is to pay no special attention to `last` in `pcomplete-arg`
and instead in the above code of `pcomplete-parse-arguments` to look for
the `pcomplete-arg-value` property.

Maybe for `emacs-29` we can use your patch (with a comment about why
`last` is handled specially pointing to its handling in
`pcomplete-parse-arguments`) and then in `master` we remove this special
handling of `last`?

        Stefan