The incomparable Sacha Chua has a very nice solution to a problem posed by David Pape: how can we enter a range of numbers as list of distinct numbers in Emacs? Pape’s specific problem was entering the numbers of error reports that a Git commit closes. Rather than entering something like
closes: 47, 48, 49, 50, 51, 70
he’d like to enter something like
closes: 47-51 70
and call an Emacs function to have it expanded into the first example.
Chua has a very nice solution that covers that case as well things like
47-51, 70
or even
5-15/2
to expand into the sequence
5, 7, 9, 11, 13, 15
Most of the heavy lifting is done by the number-sequence function. The rest of the work is parsing the input string into either a single number or a range of numbers that number-sequence can work on.
Chua’s solution strikes me as an example of Emacs at its best. The problem it solves is not earth shattering. It’s simply a bit of friction in a user’s everyday workflow but Emacs easily provides a solution that makes the friction disappear. Take a look at her code. It not only shows an ingenious solution to the problem but also demonstrates the power of Emacs and Elisp to make the application of that genius simple.