Subject: Re: bug#76658: Emacs 27.2; Prioritized invisible overlay is NOT taking precedence over non-prioritized display overlay

From: Eli Zaretskii <[email-masked]>
Date: Sat, 01 Mar 2025 12:35:49 +0200

tags 76658 notabug
thanks

> From: "David's Coding Lounge" <[email-masked]>
> Date: Fri, 28 Feb 2025 18:23:41 -0500
> 
> This bug report is essentially taken from my Emacs Stack Exchange post:
> https://emacs.stackexchange.com/questions/83169/why-doesnt-a-prioritized-invisible-overlay-take-precedence-over-non-prioritized

It is not easy to understand what exactly is the issue which you are
reporting and for which you are asking for explanations.  Both this
report and the linked postings have a lot of stuff, most of which is
AFAIU irrelevant.

My understanding is that the issue you are asking about is the effect
on display of having both 'display' and 'invisible' property start at
the same buffer position.  If this is not the issue you are asking
about, what's below may or may not make sense.

When both 'display' and 'invisible' properties start at the same
buffer position, and the 'display' property is a "replacing" property
(i.e. it instructs Emacs to show something else instead of buffer
text), then the 'display' property "wins", in the sense that the
invisible property is effectively ignored.  This happens due to how
the Emacs display engine processes properties:

  . it processes 'display' properties before 'invisible'
  . when either a replacing 'display' property or 'invisible' property
    is found, the display engine completely skips the text covered by
    the property, so any other properties in the same text are not
    processed

This should explain everything that you see.  In particular, overlay
priorities have nothing to do with this, since (as the ELisp manual
says) the priorities are only examined when two or more overlays have
the same property for the same buffer position, which is not the case
here.  Also, it explains why, if the 'invisible' property starts
before 'display', it makes all the text invisible, including the
overlay that specifies a 'display' property which shows an image.

If you sometimes need to have the image (defined via the 'display'
property) to vanish from display, simply remove the 'display'
property, or use the conditional 'display' property of the form
'(when CONDITION . DISPLAY-SPEC)' and change Lisp variables that
affect CONDITION.

Bottom line: this is not a bug.