Subject: bug#78120: 31.0.50; Calendar is not reliable with its marking

From: Eli Zaretskii <[email-masked]>
Date: Sun, 04 May 2025 08:28:42 +0300

> From: Michael Heerdegen <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
> Date: Sun, 04 May 2025 04:03:41 +0200
> 
> Manuel Giraud <[email-masked]> writes:
> 
> > >>     1) emacs -Q
> > >> 
> > >>     2) Open the file "/tmp/diary", fill it with the following
> > >>        contents and save:
> > >> --8<---------------cut here---------------start------------->8---
> > >> %%(diary-block 5 4 2025 5 4 2025 'success) Success
> > >> May 4 2025 Good day
> > >> --8<---------------cut here---------------end--------------->8---
> > >> 
> > >>     3) M-: (use-package diary-lib :custom (diary-file "/tmp/diary")) 
> > >> 
> > >>     4) M-x calendar
> > >> 
> > >>     5) Hit 'm' (diary-mark-entries) a few times.  Observe that the
> > >>        fourth of May has not always the same color.
> 
> I tried your recipe but were not able to reproduce what you describe.
> C-u C-x = always reports exactly one overlay at a marked date, no
> matter how often I hit m.  I don't know why you see this in emacs -Q.

I can reproduce this.  I think the reason is simple: the above
scenario places 2 overlays on that date, each one of them specifying a
different face.  Type "M-x describe-text-properties" on that date, and
you will see it: one face is 'diary', the other 'success'.  One of
these overlays comes from diary-mark-sexp-entries, the other from
calendar-mark-visible-date.  Both overlays have the same (unspecified)
priority, so which one of them "wins" depends on many factors,
including the exact memory layout of the Emacs session.  The latter
changes each time you press 'm', so you sometimes see one or the other
face.

The solution is to decide which overlay should "win" in this case, and
give one of them higher or lower priority, as appropriate.