From 424b2a5e13ba8854cfe4f90e070fe0eb859d9add Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Sat, 21 Sep 2024 14:51:21 +0200 Subject: [PATCH] Don't activate midnight-mode when loading 'midnight' * lisp/midnight.el (midnight-mode): Call 'midnight-delay-set' again when the mode is activated. (midnight-delay-set): Only start the timer if the mode is turned on. (Bug#73291) * etc/NEWS: Document the change in behaviour. (cherry picked from commit 4745bafa6a1d6aeda5ad08e09541d076ee223382) --- etc/NEWS | 7 +++++++ lisp/midnight.el | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 7263987a418..541e5edfe80 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -346,6 +346,13 @@ functionality of the standard 'xref' commands in TeX buffers. You can restore the standard 'etags' backend with the 'M-x xref-etags-mode' toggle. +** Midnight mode + +--- +*** Change for activating the mode +Putting (require 'midnight) in your init file no longer activates the +mode. Now, one needs to say (midnight-mode +1) instead. + * New Modes and Packages in Emacs 31.1 diff --git a/lisp/midnight.el b/lisp/midnight.el index ea30f5462f2..e5dd7221591 100644 --- a/lisp/midnight.el +++ b/lisp/midnight.el @@ -52,12 +52,11 @@ the time when it is run.") "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 @@ to its second argument TM." "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. -- 2.39.2