Jon-Michael Deldin

BMX, bike trials, & software from the Pacific Northwest

How to Make Emacs Miserable with One Weird Trick

Have you ever wanted to be periodically reminded of something in Emacs in an intrusive way? Perhaps, something like cron + alert("HI MOM") for Emacs? Maybe you want to print a (de)motivational message every few hours, or run some 1337-elisp to update your iWatch’s NTP server.

Enter run-with-idle-timer. Here’s an example that displays a message every four hours:

;; paste this into your *scratch* buffer
;; execute with M-x eval-buffer RET
(defun debugging-advice ()
  "Sage wisdom, from a computer."
  (interactive)
  (message "Have you tried turning it off and then on?"))

;; assign your timer to a variable. this is important -- without this,
;; you will be unable to easily cancel your timer
(setq my-timer (run-with-idle-timer 14400 t 'debugging-advice))

;; 4 hours (14,400 seconds) too soon? cancel it:
;; (cancel-timer my-timer)

You can view active timers with C-h v timer-idle-list RET.

* * *