User Interface

We now have a complete suite of functions for manipulating a crossword data structure, obeying the rules we've chosen; but there's not yet any way for a user to interact with a crossword grid. We must write the user interface, which includes commands to invoke the various crossword operations and a means of displaying the crossword grid and keeping the display up to date.

Display

Let's choose a visual representation for a crossword grid, to be used in an Emacs buffer.

Each row of the crossword grid should be represented by one line of the buffer. Each column of the grid, however, should take up two screen columns—because, on most displays, this helps the grid look squarer. (In most display fonts, the space for a single character is much higher than it is wide, making an nxn block of characters look ludicrously narrow.)

Empty grid squares will be represented by a dot (.). Blocks will be represented by a hash mark (#). Semi-empty cells will be represented by a question mark (?). And of course, cells containing letters will display that letter.

Here is a function that inserts a representation of a crossword grid into the current buffer. It doesn't erase the buffer first, or position the cursor; that's up to the caller of this function, which we'll define later.

(defun crossword-insert-grid (crossword)
  "Insert CROSSWORD into the current buffer."
  (mapcar 'crossword-insert-row crossword))

Recall from Other Useful List Functions in Chapter 6 that mapcar applies a function to ...

Get Writing GNU Emacs Extensions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.