1

How can I set timers in Emacs to trigger at certain times of day? Midnight mode adds hooks for a single "midnight" time, but I would like to create separate hooks for multiple clock times.

2

You can use run-at-time to run some code at a specific time.

For example, to message "go home" every day at 5 pm:

(setq go-home-timer
      (run-at-time "5:00pm"
                   (* 24 60 60)
                   (lambda ()
                     (message "go home!"))))

You can stop it with:

(cancel-timer go-home-timer)

You can create a hook and set it up to run at 5pm every day:

(defun end-of-work-hook nil
  "The hook run at the end of the day")

(setq go-home-timer
      (run-at-time "5:00pm"
                   (* 24 60 60)
                   (lambda () (run-hooks 'end-of-work-hook))))

Then you add things to that hook as normal:

(add-hook 'end-of-work-hook
          (lambda ()
            (message "go home!")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.