Subject: Re: bug#52169: 28.0.60; "Args out of range" when completing shell command

From: Stefan Monnier <[email-masked]>
Date: Sun, 05 Dec 2021 23:24:13 -0500

Kévin Le Gouguec [2021-12-04 18:16:50] wrote:
> Stefan Monnier <[email-masked]> writes:
>> I pushed to `master` a fix for the immediate cause of the `Args out of
>> range` error, which seems to brings us back to Emacs-27's poor behavior.
> Can confirm, thanks!

Thanks.

>> Maybe it's good enough for `emacs-28` as well, but I have to think about
>> this problem a bit more.
> OK; leaving this open for the time being then.

Hmm, I can't think of a good way to make it work correctly without
significant changes to `pcomplete.el` and its API.

For `emacs-28`, I propose the patch below, which is a slightly improved
version of the patch currently on `master`.  As before, it won't fix the
real problem, but will avoid "Args out of range" and revert to the
behavior we had in Emacs-27 (which was/is broken, but tends
to be milder for the user).

Any objection?

        Stefan

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index ca82b4a9e60..21d610fdf44 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -283,8 +283,9 @@ completion-table-subvert
          ((eq (car-safe action) 'boundaries)
           (let ((beg (or (and (eq (car-safe res) 'boundaries) (cadr res)) 0)))
             `(boundaries
-              ,(max (length s1)
-                    (+ beg (- (length s1) (length s2))))
+              ,(min (length string)
+                    (max (length s1)
+                         (+ beg (- (length s1) (length s2)))))
               . ,(and (eq (car-safe res) 'boundaries) (cddr res)))))
          ((stringp res)
           (if (string-prefix-p s2 res completion-ignore-case)