Emacs: Alarm for Breaks

As a programmer who sits before a computer more than 8 hours a day, standing up and exercising a bit regularly is said to be a good way to extend my lifespan. In this era, I believe even living a little longer could make a tremendous difference (see 《永生的阶梯》 by Cixin Liu, or Technological singularity on Wikipedia).

Given that I keep the emacs process live as long as my computer is on, I decide to set some alarms in emacs so it reminds to stand up and do some stretches every hour.

I posted this question on both Google+ and #emacs and got some feedback. Many people recommend org-pomodoro, which is an emacs implementation of the Pomodoro Technique.

I read its document and it looks promising, but I want something simpler. So I keep searching and trying different solutions until appt solves the problem imperfectly.

First step, install appt in emacs: M-x el-get-install appt (or through any other emacs plugins installation approach)

However, it turns out that appt requires some functions that are not available in emacs 24.4. Therefore, I have to do some small modifications to appt.

Remove the elc in case it affects anything: M-x delete-file ~/.emacs.d/el-get/appt/appt.elc

Then open the appt.el, C-x C-f ~/.emacs.d/el-get/appt/appt.el, search for update-calendar-mode-line and delete every line that contains it. C-x C-s, save the file. Now appt is usable.

Evaluate the following s-expressions and put them in your init.el:

;; Diary entries notification
(require 'appt)
(setq appt-message-warning-time 0)      ; 0 minute time before warning
(setq diary-file "~/diary")             ; diary file

Since I just want to stand up and do some stretches regularly, I set appt-message-warning-time to 0, otherwise warnings would pop up a few minutes in advance.

Then specify a diary file: ~/diary (you can set it to any file you like)

Create this diary file C-x C-f ~/diary and write the following content to it (there might be more concise ways to express what I wrote, I didn’t read through the document):

Monday
  9:00am stand up
  10:00am stand up
  11:00am stand up
  12:00pm lunch time
  2:00pm stand up
  3:00pm stand up
  4:00pm stand up
  5:00pm leave office
Tuesday
  9:00am stand up
  10:00am stand up
  11:00am stand up
  12:00pm lunch time
  2:00pm stand up
  3:00pm stand up
  4:00pm stand up
  5:00pm leave office
Wednesday
  9:00am stand up
  10:00am stand up
  11:00am stand up
  12:00pm lunch time
  2:00pm stand up
  3:00pm stand up
  4:00pm stand up
  5:00pm leave office
Thursday
  9:00am stand up
  10:00am stand up
  11:00am stand up
  12:00pm lunch time
  2:00pm stand up
  3:00pm stand up
  4:00pm stand up
  5:00pm leave office
Friday
  9:00am stand up
  10:00am stand up
  11:00am stand up
  12:00pm lunch time
  2:00pm stand up
  3:00pm stand up
  4:00pm stand up
  5:00pm leave office

Save this file and press M-x appt-activate, done, emacs will pop up a new buffer for each entry in the diary on time.

Reference: http://www.gnu.org/software/emacs/manual/html_node/emacs/Appointments.html

3 thoughts on “Emacs: Alarm for Breaks

  1. Piotr F. Mieszkowski

    Appt has been a part of GNU Emacs for a long time, so you shouldn’t have to install it. Check if it isn’t there, in your Emacs installation directory (in my case it is /usr/local/share/emacs/24.3/lisp/calendar/appt.el.gz).
    Besides, Emacs Diary has this neat functionality of “S-exp Entries” (https://www.gnu.org/software/emacs/manual/html_node/emacs/Sexp-Diary-Entries.html), you might try using it to achieve something simpler (maybe you could keep only one “work-day” entry instead of 5 entries for each day of the week).

    Reply
  2. Wenshan Post author

    Thanks for your feedback.

    I built my emacs from the trunk.

    (emacs-verison) returns `GNU Emacs 24.4.50.1 and appt is in /usr/local/share/emacs/24.4.50/lisp/calendar. However, M-x appt says something like “cannot open appt/appt”. I didn’t investigate deeper since it is also available on el-get.

    The S-exp Entries section looks pretty promising, I’ll read through it, thank you very much.

    Reply

Leave a Reply