-(defcustom midnight-mode nil
- "Non-nil means run `midnight-hook' at midnight.
-Setting this variable outside customize has no effect;
-call `cancel-timer' or `timer-activate' on `midnight-timer' instead."
- :type 'boolean
- :group 'midnight
- :require 'midnight
- :initialize 'custom-initialize-default
- :set (lambda (symb val)
- (set symb val) (require 'midnight)
- (if val (timer-activate midnight-timer)
- (cancel-timer midnight-timer))))
+;;;###autoload
+(define-minor-mode 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)))