Subject: Re: bug#79421: 30.1; display-timer

From: Eli Zaretskii <[email-masked]>
Date: Wed, 10 Sep 2025 14:50:06 +0300

> From: Francesco Potortì <[email-masked]>
> Date: Wed, 10 Sep 2025 13:31:58 +0200
> 
> When I read mail with Rmail, I sometimes get a message "timer--activate: Timer already activate", which I supose is linked to display-time.

I have display-time running in my production sessions, but never saw
such a message, FWIW.  But then my setup doesn't check for email as
part of display-time, it only updates the time and the system load
shown on the mode line.

> Even if rarely, I had situations in which the mail status in the mode line was not updated and I cured that using M-x display-time RET
> 
> I suspect the two above issues are related.

I'm not sure.  How about running with debug-on-message set to catch
this message, and when it does, show the backtrace?

> This time I had a look at list-timers and played with it, by hitting 'g' repeatedly until I saw this:
> 
>        -1d 23h 59m 59.0s           1m display-time-event-handler
>               59.0s           1m appt-check
>           48m 57.2s           1h url-cookie-write-file
>        17h 7m 59.0s           1d diary
>        17h 8m 59.0s           1d sunrise-sunset
>    *           0.1s            t csv-field-index
>    *           0.1s            t show-paren-function
>    *           0.5s            t #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_11>
>    *           2.0s         2.0s garbage-collect
>    *          30.0s            - desktop-auto-save
>    *        1m 0.0s            t bibtex-parse-buffers-stealthily
> 
> I have no idea if the negative time is normal, but at first sight it does not look so, and I though it was nice to report.

A timer with a negative time will never fire.

Does your system ever go to sleep?  If so, could it be that these
negative values appear after the system is awaken?

And what is your value of timer-max-repeats?

If nothing else help, try writing a function which will periodically
check this value, and tell you when it becomes negative.  Then maybe
you could figure out what causes it, and we can take it from there.

> Note that I have written a display-time-mail-function which is heavier than the standerd one: rather than looking for files existence it counts the number of "^From " patterns by calling grep, do not know if this could nake things more complex.

Not a very good idea, IMO: functions run off timers should not be
expensive, because they delay the Emacs response to input.