Skip to main content

The Craft of Emacs

Quotes, lists and lambdas

1 hour 30 minutes

In this chapter we will expand our M‑x xx command. It can already compute the number of skeins needed for plain patterns, but needs a few tweaks to work for vibrant ones.

Open the bakery.xx pattern file and call M‑x coe‑xx‑mode.

You’ll see a pattern of several lovable Kirbys. Unlike our previous pattern, this one contains stitches of several different colours.

To save you some counting, there are 1500 black stitches, 1450 magenta stitches and 2500 pink stitches.

Call M‑x xx three times to compute the number of skeins for each colour.

You should find you have 2 black skeins, 2 magenta skeins and 3 pink skeins respectively.

Calling M‑x xx three times and noting down each result is a bit laborious. Our final goal is for the number of skeins of each colour to be calculated automatically in an M‑x xx‑basket‑add command.

To take a step closer to that goal, we’re going to modify M‑x xx to work for multiple coloured threads.

As well as saving some labour, this will give us the opportunity to manipulate collections. We’ll see how to code a group of colours and calculate the number of skeins for each colour in the group.

To do this we’ll learn some new syntax and a few new special forms. We’ll work with Emacs’s built-in packages; learn how to use them, and more importantly learn how to explore them.

For the time being, we’ll focus solely on hard-coded collections. We’ll explore how to build dynamic ones in the next chapter.

Learning objectives