A few weeks ago I wrote about my toy train timetable clock. I used it with my son a few times since then, and it worked great. However, some things that I imagined would be a good idea turned out to be a bit worse UI-wise.
For example, I noticed that it would be quite useful to be able to pause and resume the time. This is a bit difficult to achieve in my initial design, where instead of keeping track of the “current toy time”, I store the start times (both real and toy) and compute the toy time on every update. I thought that was clever and allowed me to avoid problems with timers being late, but after I read the docs again, I realized that I could just increment the “toy time” on every call to ttt-refresh and the result will be (almost) the same. (Theoretically, if Emacs is really busy, say performs some computations taking a minute, then the previous approach would update the toy time to the current value immediately, and the “new” one would update it four times in 15-second increments in quick succession – but (1) I don’t expect that to ever happen, and (2) even if it sometimes does, it’s not a big problem.)
After spending some time thinking about the new design, I considerably simplified the UI. From now on, the ttt-start command (the main entry point) no longer asks the user for the “real start time” – the user just enters the “start toy time” and the clock starts running. The main innovation (from the user’s perspective) are two buttons below the clock: pause (which is self-explanatory) and restart. The latter works like this: the “start toy time” is stored in the new variable ttt-start-toy-time, and restart just sets the toy time to that value (and refreshes the screen so that the update is visible at once).
As usual, Emacs turns out to be a perfect platform for coding little “apps” like this. Much like the web, you get the whole UI “for free”. In the case of the web, you have HTML, CSS if you want it to look fancier, and JavaScript for handling various “events” (like clicks and key presses). In the case of Emacs, you get the machinery of major and minor modes, the concept of keybindings and things like completion or ASCII art drawings. Both platforms support even pretty sophisticated cases like date/time input. In the case of the web, there is the (infamously bad) <input type="date"> and its relatives <input type="datetime-local"> and <input type="time">. In the case of Emacs, there is the (famously great) org-read-date. Of course, the big upside of the web is that basically everyone who has a computer these days (including phones) has the runtime; the big upside of Emacs is that, well, it’s Emacs, so us Emacsers get the integration with one of the best tools in existence.
That’s it for today, happy hacking!