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

From: Manuel Giraud <[email-masked]>
Date: Sat, 03 May 2025 13:41:22 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Manuel Giraud <[email-masked]>
>> Date: Mon, 28 Apr 2025 16:47:31 +0200
>> 
>> 
>> It seems that the calendar is not reliable with its marking of diary
>> events.  Here is a recipe:
>> 
>>     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.
>> 
>> Maybe this is a limitation of overlays but when I tried to test
>> (lightly) with overlapping overlays the visual results were always the
>> same.
>
> Thanks, but could you please describe the issue in more detail?  We
> don't have an active maintainer of diary-lib, but you seem to imply
> that there's some more basic issue with overlays here?  can you
> elaborate on that, and perhaps show some Lisp that is not specific to
> diary-lib?

No I think that overlays are correct and that the calendar marking is
doing something wrong™.  I think I have a better example.  Consider the
recipe above but this time with following contents in /tmp/diary:

--8<---------------cut here---------------start------------->8---
%%(diary-block 5 4 2025 5 4 2025 '(:background "lightgrey")) Success
May 4 2025 Good day
--8<---------------cut here---------------end--------------->8---

When you repeatedly hit 'm' in the calendar, you'll see that sometimes
the foreground of the '4' is highlighted and sometimes it is not.

Now consider the following code:
--8<---------------cut here---------------start------------->8---
(defun foo ()
  (interactive)
  (remove-overlays)
  (let* ((start 1)
	 (fore (make-overlay start (+ start 4)))
	 (back (make-overlay start (+ start 4))))
    (overlay-put fore 'face 'error)
    (overlay-put back 'face '(:background "lightgrey"))))

(local-set-key (kbd "m") 'foo)
--8<---------------cut here---------------end--------------->8---

If you evaluate those two forms in a test buffer and hit 'm' repeatedly,
the overlays are always correct: an error face on light grey background.
-- 
Manuel Giraud