Subject: bug#59963: 29.0.50; 'window-max-chars-per-line' doesn't always work on GUI without fringe

From: martin rudalics <[email-masked]>
Date: Mon, 12 Dec 2022 17:50:44 +0100

>> (let (max-chars)
 >>     (setq right-fringe-width 0)
 >>     (setq max-chars (window-max-chars-per-line))
 >>     (set-window-buffer nil (window-buffer))
 >>     max-chars)
 >>
 >> which currently yields 79 and would yield 80 with your proposal.
 >
 > Do we have such code somewhere?

No.  Fringes should be set by users only.

 > The correct way of doing that is to
 > swap the lines that call window-max-chars-per-line and
 > set-window-buffer, because AFAIU the latter will cause window-margins

... 'window-max-chars-per-line' I presume ...

 > to return the values consistent with right-fringe-width just set.

My example is a simplification.  There might be many more buffer-local
variables to set and the conclusive 'set-window-buffer' call to put them
into action might appear much later, maybe also in some other function.

The simplest approach should be to put an extra

(set-window-buffer nil (window-buffer))

right after the

   (with-selected-window (window-normalize-window window t)

in 'window-max-chars-per-line'.  But there's no right KEEP-MARGINS value
to pass here.

Maybe you should just say in the doc-string that if there are any
pending buffer-local changes, they should be applied before calling
'window-max-chars-per-line'.

martin