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

From: Eli Zaretskii <[email-masked]>
Date: Wed, 07 May 2025 14:44:06 +0300

> From: Michael Heerdegen <[email-masked]>
> Cc: Manuel Giraud <[email-masked]>,  [email-masked]
> Date: Wed, 07 May 2025 00:44:33 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Each face has a meaning, I presume?  If one face marks a date because
> > John Doe was born at that day, and another face marks the same date
> > because I have an important meeting, then the latter should "win",
> > right?
> 
> It depends?  If John doe is your husband, maybe he is much more
> important and should "win".  Maybe you will have a free day at his
> birthday anyway.

While these situations are possible, I think they are quite rare in
practice.  So while today we have this problem in all the cases, with
the change I propose we will have it only rarely: a clear "win", IMO.

I also made another suggestion: to change the default definition of
some of the faces so that they don't all use the same face attribute.
Then we could fix this problem even cleaner, IMO.  But no one
responded to that suggestion, and I wonder why.

> So this is a good example of how difficult this is.  It totally depends
> on your life and your circumstances.  Also, Emacs doesn't know what an
> "important meeting" is, and who John Doe is.

We usually solve this for the most probable situation, and leave the
rest to user customizations of the faces.  It isn't the first time we
bump into this problem.

Moreover, to reason about this in a useful way, we need a list of
faces that could conflict and their semantics.  AFAICT, no one posted
such a list.  So for now we are having an almost purely academic
discussion, without even knowing how many faces could conflict in this
way.

So I think you reject this kind of solution too early.

> And the same is true for other sources of highlighting.  Are holidays
> important?  Depends on how religious you are etc.

If indeed you are right, and the importance is frequently inverted
(and I'm not yet sure you are right), then we could provide user
options for resolving the conflicts.  But such user options should not
be overlay priorities, but something like "face importance", from
which the code should derive the priorities.  Asking users to provide
priorities themselves is not user-friendly, for the reasons I
explained up-thread.

> > Not names, meanings.  The names here don't explain themselves: 'diary'
> > and 'success'.  If you know what those faces mean, please tell, and I
> > will try to suggest which one should win in this case.
> 
> Note: the success face had been specified in the diary file (see the
> recipe).  The user can specify any face name in the file.  Emacs doesn't
> know what these "mean".  The only thing Emacs can know is: was the entry
> that caused the mark a normal diary entry, a sexp entry, or does the
> mark come from some function or via a hook - with other words, a rough
> category that doesn't tell much on it's own.

I think the other face has a more clear semantics, and the face
specified by the user also has semantics, albeit a more vague one.  So
this kind of solutions could still be possible.

> > (Up front, I'd say that 'diary' should override the others, but I'm
> > open to counter-arguments.)
> 
> May suggestion: first, when Emacs tries to mark a date, and there is
> already a mark, we use the existing overlay instead of placing multiple.
> 
> Then, a function, value of a new defcustom, is used to decide what face
> to place in a conflict.  And I would introduce a new face that means
> "multiple marks on this date" that it can use.

That's possible, yes.  We could also use this special case with two
overlays, but in case where we decide to use this special case we
could also make its overlay priority higher.  The result will be the
same.

The solution you propose might cause complications, because removing
the overlay will effectively remove both marks.  I don't know
diary-lib enough to tell whether this is a real problem.

> But more importantly, it would be good if the mouse over text would list
> the entries for that day.  Much more useful than programming face
> fights.  Just give me a hint that there are multiple things "on" that
> date.  This feature (listing diary entries for the clicked date) is
> already available by explicit request via the mouse-3 menu btw.

We could, of course, add this, and it would be useful on its own
right, but don't forget that Emacs can work without a mouse.  In any
case, I think this is almost orthogonal to the issue at hand.