Subject: Re: bug#68893: 30.0.50; pixel-fill-region errors when folding message headers in Gnus

From: Stephen Berman <[email-masked]>
Date: Fri, 02 Feb 2024 20:35:29 +0100

On Fri, 02 Feb 2024 17:52:48 +0200 Eli Zaretskii <[email-masked]> wrote:

> merge 68893 67791
> thanks
>
>> Date: Fri, 02 Feb 2024 16:33:00 +0100
>> From:  Stephen Berman via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>>
>> When I type `t' (gnus-summary-toggle-header) on many (but not all)
>> articles in the Gnus Summary buffer, I get an error in pixel-fill-region
>> that the indentation is wider than the fill width.  I can reproduce the
>> error as follows:
>>
>> 0. emacs -Q
>> 1. Enable debug-on-error.
>> 2. M-x gnus, type `y' at the prompt, then type `B RET news.gmane.io
>>    RET', then `C-s emacs.bugs RET RET 1 RET' to enter the Gnus Summary
>>    buffer showing the latest article in the gnu.emacs.bugs group.  Then
>>    type `j' and at the prompt paste the following Message-ID (of an
>>    article that reliably induces the error) into the minibuffer:
>>    <[email-masked]>
>> 3. Type `t'.  This raises an error and produces the following backtrace:
>
> This is another duplicate of bug#67791.  Please see there for the
> analysis and the proposed solutions.

Ah, I actually had seen that report and also the recent other one that
you merged with it, but unfortunately I didn't remember them when I
encountered the issue myself today.  Thanks for the pointer.  And
indeed, not only does Katsumi Yamaoka's patch to
gnus-article-treat-fold-headers fix the problem for me too, but also
your suggestion to apply the fix to pixel-fill-region instead, as in the
following patch, works just as well:

diff --git a/lisp/textmodes/pixel-fill.el b/lisp/textmodes/pixel-fill.el
index 25c0b46cee9..dcd57acc2e5 100644
--- a/lisp/textmodes/pixel-fill.el
+++ b/lisp/textmodes/pixel-fill.el
@@ -73,7 +73,8 @@ pixel-fill-region
 If START isn't at the start of a line, the horizontal position of
 START, converted to pixel units, will be used as the indentation
 prefix on subsequent lines."
-  (save-excursion
+  (save-window-excursion
+    (set-window-buffer nil (current-buffer))
     (goto-char start)
     (let ((indentation
            (car (window-text-pixel-size nil (line-beginning-position)

(I also tried your suggestion to use buffer-text-pixel-size in place of
window-text-pixel-size in pixel-fill-region, and while that prevented
the error, it resulted in irregular and very large indentation of the
continuations of overlong headers, and I didn't immediately see an easy
way to avoid that.)

Steve Berman