unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Michael Heerdegen <michael_heerdegen@web.de>, 73291@debbugs.gnu.org
Subject: bug#73291: 31.0.50; `clean-buffer-list' activates `midnight-mode'
Date: Wed, 18 Sep 2024 11:06:32 +0200	[thread overview]
Message-ID: <87a5g5l49z.fsf@ledu-giraud.fr> (raw)
In-Reply-To: <86y13q9j41.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 17 Sep 2024 22:26:54 +0300")

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: midnight.patch --]
[-- Type: text/x-patch, Size: 1660 bytes --]

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.

[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

  reply	other threads:[~2024-09-18  9:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16  7:49 bug#73291: 31.0.50; `clean-buffer-list' activates `midnight-mode' Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-16 13:09 ` Eli Zaretskii
2024-09-17  8:19   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-17 12:50     ` Eli Zaretskii
2024-09-17 13:15       ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-17 13:17     ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-17 13:46       ` Eli Zaretskii
2024-09-17 19:07         ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-17 19:26           ` Eli Zaretskii
2024-09-18  9:06             ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-09-18 23:52               ` Stefan Kangas
2024-09-19  5:53                 ` Eli Zaretskii
2024-09-21  0:27                   ` Stefan Kangas
2024-09-21 12:55                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-21 13:04                       ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5g5l49z.fsf@ledu-giraud.fr \
    --to=bug-gnu-emacs@gnu.org \
    --cc=73291@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=manuel@ledu-giraud.fr \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).