Subject: bug#19511: 25.0.50; Failed assertions in redisplay() code. (dispnew.c:1405; xdisp.c:17524)

From: Eli Zaretskii <[email-masked]>
Date: Mon, 05 Jan 2015 20:24:27 +0200

> From: Vitalie Spinu <[email-masked]>
> Cc: Andreas Matthias <[email-masked]>,  [email-masked]
> Date: Mon, 05 Jan 2015 08:59:02 -0800
> 
> > I hope Polymode will be changed to not call bury-buffer in that
> > situation (I always thought bury-buffer is strictly for interactive
> > use, FWIW).
> 
> Bury-buffer is used to "hide" from the indirect buffer from the
> user. That was the easiest way to implement that and should have been
> rewritten anyways.

bury-buffer is a command.  A command typically does a lot of dwim-ish
stuff that is not directly related to its main job.  If you needed to
merely put the buffer at the end of buffer-list, you could have called
bury-buffer-internal instead, which does precisely that and nothing
else.  Assuming you really need to manipulate buffer-list at all.

> Removing it doesn't change the fact that buffers are switched
> (with-current-buffer ...) inside font-lock-fontify-region-function. But
> I guess that's not an issue (right?).

Right, that's not the issue.  The problem is the call to
switch-to-prev-buffer that bury-buffer does.  That results in a call
to set-window-buffer, which is the one that invalidates window_end_pos
etc.

> Would it be enough to remove `bury-buffer` call to get back the
> optimization?

Probably, but if you show me the changes, I can see if they achieve
that.

> What are other elisp functions that can potentially invalidate
> window_end?

Any function that calls apply_window_adjustment, for example.  Which
is called in just a handful of places, see window.c.  Also
set-window-start and functions that split or delete windows.
Basically, those that really change the window's display (and
therefore shouldn't be called in a fontification function).