Subject: Re: bug#54374: 29.0.50; previous-completion fails at beginning of completions buffer

From: Philip Kaludercic <[email-masked]>
Date: Mon, 14 Mar 2022 14:12:40 +0000

Juri Linkov <[email-masked]> writes:

>> This seems to fix it:
>>
>> diff --git a/lisp/simple.el b/lisp/simple.el
>> index accc119e2b..7d47aba1ee 100644
>> --- a/lisp/simple.el
>> +++ b/lisp/simple.el
>> @@ -9125,7 +9125,7 @@ next-completion
>>          (unless (get-text-property (point) 'mouse-face)
>>            (goto-char (next-single-property-change (point) 'mouse-face nil end)))
>>          (setq n (1- n)))
>> -      (while (< n 0)
>> +      (while (and (< n 0) (< 1 (point)))
>>          (let ((prop (get-text-property (1- (point)) 'mouse-face)))
>>            ;; If in a completion, move to the start of it.
>>            (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
>
> Thanks, I confirm that it doesn't fail.
>
> However, there is some strange behaviour: when point is at the beginning
> of the completion buffer, then previous-completion switches to the minibuffer.
> But if point is at the first completion, then previous-completion wraps
> to the last completion.  Shouldn't point at the beginning of the buffer
> wrap to the last completion as well?

I didn't notice that, because completion-auto-select was enabled on my
end.  How about this:

diff --git a/lisp/simple.el b/lisp/simple.el
index accc119e2b..5fba27b868 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9108,6 +9108,13 @@ next-completion
 With prefix argument N, move N items (negative N means move
 backward)."
   (interactive "p")
+  (let ((prev (previous-single-property-change (point) 'mouse-face)))
+    (goto-char (cond
+                ((not prev)
+                 (1- (next-single-property-change (point) 'mouse-face)))
+                ((/= prev (point))
+                 (point))
+                (t prev))))
   (let ((beg (point-min)) (end (point-max)))
     (catch 'bound
       (while (> n 0)

(Note that this also fixes the "issue" jumping back to the beginning of
the same completion option, if the point is not at the beginning of said
option.)

-- 
	Philip Kaludercic