GNU bug report logs - #73291
31.0.50; `clean-buffer-list' activates `midnight-mode'

Previous Next

Package: emacs;

Reported by: Manuel Giraud <manuel <at> ledu-giraud.fr>

Date: Mon, 16 Sep 2024 07:51:02 UTC

Severity: normal

Found in version 31.0.50

Fixed in version 31.1

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #38 received at 73291 <at> debbugs.gnu.org (full text, mbox):

From: Manuel Giraud <manuel <at> ledu-giraud.fr>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 73291 <at> debbugs.gnu.org
Subject: Re: bug#73291: 31.0.50; `clean-buffer-list' activates `midnight-mode'
Date: Wed, 18 Sep 2024 11:06:32 +0200
[Message part 1 (text/plain, inline)]
Hi,

I think the following patch does the trick.  Here is what I tested with
it:

        - A call to `clean-buffer-list' cleans up the list once and does
          not activate the midnight-timer.

        - The midnight mode is toggled on/off by calling
          `midnight-mode'.

        - Calling (customize-variable 'midnight-delay) stops and
          restarts the midnight-timer with the updated delay.

Maybe the line ":initialize #'custom-initialize-default" could be
removed, I don't know.  WDYT?

[midnight.patch (text/x-patch, inline)]
diff --git a/lisp/midnight.el b/lisp/midnight.el
index 6e1e7b5ccb7..ff1392abc05 100644
--- a/lisp/midnight.el
+++ b/lisp/midnight.el
@@ -52,12 +52,11 @@ midnight-mode
   "Non-nil means run `midnight-hook' at midnight."
   :global t
   :initialize #'custom-initialize-default
-  ;; Disable first, since the ':initialize' function above already
-  ;; starts the timer when the mode is turned on for the first time,
-  ;; via setting 'midnight-delay', which calls 'midnight-delay-set',
-  ;; which starts the timer.
-  (when (timerp midnight-timer) (cancel-timer midnight-timer))
-  (if midnight-mode (timer-activate midnight-timer)))
+  ;; Call `midnight-delay-set' again because it takes care of starting
+  ;; the timer if the mode is on.  The ':initialize' function above
+  ;; (which ends up calling `midnight-delay-set') did not know yet if
+  ;; the mode was on or not.
+  (midnight-delay-set 'midnight-delay midnight-delay))
 
 ;;; clean-buffer-list stuff
 
@@ -207,9 +206,11 @@ midnight-delay-set
              "Invalid argument to `midnight-delay-set': `%s'")
   (set symb tm)
   (when (timerp midnight-timer) (cancel-timer midnight-timer))
-  (setq midnight-timer
-        (run-at-time (if (numberp tm) (+ (midnight-next) tm) tm)
-                     midnight-period #'run-hooks 'midnight-hook)))
+  ;; Only start the timer if the mode is turned on.
+  (when midnight-mode
+    (setq midnight-timer
+          (run-at-time (if (numberp tm) (+ (midnight-next) tm) tm)
+                       midnight-period #'run-hooks 'midnight-hook))))
 
 (defcustom midnight-delay 3600
   "The number of seconds after the midnight when the `midnight-timer' is run.
[Message part 3 (text/plain, inline)]
-- 
Manuel Giraud

This bug report was last modified 240 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.