2025-09-08 Emacs Artist clock

Last edit

Summary: +image, fix typo

Changed:

< Of course, my immediate thought was, why not create an [[https://gitlab.com/mbork_mbork_pl/artist-clock/-/blob/master/artist-clock.el?ref_type=heads|ASCII-art analog clock]] using Artist mode? The task seems easy enough – in fact, the most non-obvious thing was doing the geometric calculations (including simple trigonometry, correction for the 2:1 aspect ratio and transforming between the Artist mode coordinae system and the (sort of) polar coordinate system of the clock, where angle 0 is headed up instead of to the right).

to

> Of course, my immediate thought was, why not create an [[https://gitlab.com/mbork_mbork_pl/artist-clock/-/blob/master/artist-clock.el?ref_type=heads|ASCII-art analog clock]] using Artist mode? The task seems easy enough – in fact, the most non-obvious thing was doing the geometric calculations (including simple trigonometry, correction for the 2:1 aspect ratio and transforming between the Artist mode coordinate system and the (sort of) polar coordinate system of the clock, where angle 0 is headed up instead of to the right).
> [[image:artist-clock.png]]


A few months ago I mentioned Artist mode. It seems that at least one person liked that post enough to mention it (thanks!), even if indirectly. That very post also mentioned svg-clock, which is a cute analog clock displayed directly in Emacs.

Of course, my immediate thought was, why not create an ASCII-art analog clock using Artist mode? The task seems easy enough – in fact, the most non-obvious thing was doing the geometric calculations (including simple trigonometry, correction for the 2:1 aspect ratio and transforming between the Artist mode coordinate system and the (sort of) polar coordinate system of the clock, where angle 0 is headed up instead of to the right).

artist-clock.png

The code could probably be a bit more polished – it’s possible that (for example) the switch-to-buffer is not the best idea (it is a function which should not usually be called non-interactively), although in this particular case it seems to do exactly the right thing. (The assumption is that the user themselves will create the window which should display the clock.) Also, the clock is not really “optimized” – each minute (or second) the whole thing is just erased and redrawn, but Artist mode actually allows to “undraw” shapes.

Perhaps one of the two most interesting tidbits (which I knew about but completely forgot) is a very special case of the run-at-time function where the first argument given is t – that function is then ideally suited to displaying clocks. Another one is the second (optional) argument to get-buffer-window, which makes Emacs look for the window displaying the given buffer also on non-selected frames.

That’s it for today, I hope you like my clock!

CategoryEnglish, CategoryBlog, CategoryEmacs