Subject: Re: bug#78861: [PATCH] Avoid calendar flicker

From: Manuel Giraud <[email-masked]>
Date: Mon, 23 Jun 2025 09:50:23 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Manuel Giraud <[email-masked]>
>> Cc: [email-masked]
>> Date: Sun, 22 Jun 2025 18:22:15 +0200
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> >> From: Manuel Giraud <[email-masked]>
>> >> Cc: [email-masked]
>> >> Date: Sun, 22 Jun 2025 16:08:37 +0200
>> >> 
>> >> Eli Zaretskii <[email-masked]> writes:
>> >> 
>> >> > If the above is the best scenario you can offer, then please point me
>> >> > to the code in calendar that first draws the numbers in black and then
>> >> > redraws them in red, and I will take a look.
>> >> 
>> >> Thanks Eli.  I think most takes place in `diary-mark-entries' at
>> >> diary-lib.el:1377.
>> >
>> > Thanks.  Then I guess the problem is the calls to sit-for, which
>> > performs redisplay, in calendar-generate-window before it calls
>> > diary-mark-entries.  Any idea why we are calling sit-for there?  If
>> > you remove those calls or add the optional second argument non-nil to
>> > them, does the problem go away?
>> 
>> Thanks.  I have commented both sit-for and the issue completely goes
>> away.  I dig into history and those sit-for are here from ecaa0527104b
>> (the initial revision in 1992!)
>
> Can you (or anyone else) think of any reasons to have these sit-for
> calls there?  For example, when there's no need to call
> diary-mark-entries at all?

Both sit-for are guarded behind a `in-calendar-window' meaning that the
window-buffer is the calendar buffer.  So maybe the explanation for
those sit-for was to have some interactive visual feed back when
activating marks of diary entries.  But now that we could end up calling
`dairy-mark-entries' when we scroll this just creates too much flicker,
IMO.

> If we can think of no valid reason, I think TRT is simply to remove
> these calls.  It's possible that this was there for when Emacs had a
> completely different way of fontifying buffers than what we have now.

Here is an updated patch that removes those sit-for.
>From 76a569bed53a94c4f2b10970182aca3a9bf1f025 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Mon, 23 Jun 2025 09:45:49 +0200
Subject: [PATCH] Avoid flicker when marking diary entries (bug#78861)

* lisp/calendar/calendar.el (calendar-generate-window): Remove
historical and not really understood `sit-for' calls.
---
 lisp/calendar/calendar.el | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 1c98de98b9b..917624c489e 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -1432,12 +1432,10 @@ calendar-generate-window
 	  (fit-window-to-buffer nil nil calendar-minimum-window-height)
 	;; For a full height window or a window that is horizontally
 	;; combined don't fit height to that of its buffer.
-	(set-window-vscroll nil 0))
-      (sit-for 0))
+	(set-window-vscroll nil 0)))
     (and calendar-mark-holidays-flag
          ;; (calendar-date-is-valid-p today) ; useful for BC dates
-         (calendar-mark-holidays)
-         (and in-calendar-window (sit-for 0)))
+         (calendar-mark-holidays))
     (unwind-protect
         (if calendar-mark-diary-entries-flag (diary-mark-entries))
       (run-hooks (if today-visible
-- 
2.49.0

-- 
Manuel Giraud