A Nifty Example of Metaprogramming

Some of the most enjoyable programming I do is metaprogramming: writing code that writes code. Lisp macros are all about that, of course, but the idea is much more general. Often times the code that the code writes is just a simple shell script. Several years ago when my main workstation was a Linux machine, the ripperX program was broken for one reason or another so I wrote a program to read the CD directory and generate a shell script to rip the tracks. It was nice because I had complete control over the format of the names assigned to the tracks.

I just came across a nifty example of this sort of thing over at Sacha Chua’s blog. Chua was working on cutting the video stream from the recent Emacs Conference 2015 into individual talks1. The idea is to note the start time and duration of each talk and use that in a call to ffmpeg. You can write those ffmpeg calls by hand, of course, but that’s boring and error prone.

Instead, Chua captured the talk title, start time, and end time in an Org table and used the table spread sheet functionality to calculate the duration. Then she used a code block in the Org file to output the calls to ffmpeg automatically. A nice example of metaprogramming using Org mode. It’s a great post and well worth a read. Perhaps it will give you some ideas for your own work. In any event, we’re all the beneficiaries of Chua’s work because now we can watch those conference talks. See Chua’s post for the details.

Footnotes:

1

Here’s another Chua post with some background on the technical details of the media she was working with.

This entry was posted in General and tagged , . Bookmark the permalink.