www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro_15.html   search  
Buy the book!

Programming in Emacs Lisp

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Generate an Error Message

Partly so you won't worry if you do it accidentally, we will now give a command to the Lisp interpreter that generates an error message. This is a harmless activity; and indeed, we will often try to generate error messages intentionally. Once you understand the jargon, error messages can be informative. Instead of being called "error" messages, they should be called "help" messages. They are like signposts to a traveller in a strange country; deciphering them can be hard, but once understood, they can point the way.

The error message is generated by a built-in GNU Emacs debugger. We will `enter the debugger'. You get out of the debugger by typing q.

What we will do is evaluate a list that is not quoted and does not have a meaningful command as its first element. Here is a list almost exactly the same as the one we just used, but without the single-quote in front of it. Position the cursor right after it and type C-x C-e:

(this is an unquoted list)

What you see depends on which version of Emacs you are running. GNU Emacs version 21 provides more information than version 20 and before. First, the more recent result of generating an error; then the earlier, version 20 result.

In GNU Emacs version 21, a `*Backtrace*' window will open up and you will see the following in it:

---------- Buffer: *Backtrace* ----------
Debugger entered--Lisp error: (void-function this)
  (this is an unquoted list)
  eval((this is an unquoted list))
---------- Buffer: *Backtrace* ----------

Your cursor will be in this window (you may have to wait a few seconds before it becomes visible). To quit the debugger and make the debugger window go away, type:


Please type q right now, so you become confident that you can get out of the debugger. Then, type C-x C-e again to re-enter it.

Based on what we already know, we can almost read this error message.

You read the `*Backtrace*' buffer from the bottom up; it tells you what Emacs did. When you typed C-x C-e, you made an interactive call to the command eval-last-sexp. eval is an abbreviation for `evaluate' and sexp is an abbreviation for `symbolic expression'. The command means `evaluate last symbolic expression', which is the expression just before your cursor.

Each line above tells you what the Lisp interpreter evaluated next. The most recent action is at the top. The buffer is called the `*Backtrace*' buffer because it enables you to track Emacs backwards.

At the top of the `*Backtrace*' buffer, you see the line:

Debugger entered--Lisp error: (void-function this)

The Lisp interpreter tried to evaluate the first atom of the list, the word `this'. It is this action that generated the error message `void-function this'.

The message contains the words `void-function' and `this'.

The word `function' was mentioned once before. It is a very important word. For our purposes, we can define it by saying that a function is a set of instructions to the computer that tell the computer to do something.

Now we can begin to understand the error message: `void-function this'. The function (that is, the word `this') does not have a definition of any set of instructions for the computer to carry out.

The slightly odd word, `void-function', is designed to cover the way Emacs Lisp is implemented, which is that when a symbol does not have a function definition attached to it, the place that should contain the instructions is `void'.

On the other hand, since we were able to add 2 plus 2 successfully, by evaluating (+ 2 2), we can infer that the symbol + must have a set of instructions for the computer to obey and those instructions must be to add the numbers that follow the +.

In GNU Emacs version 20, and in earlier versions, you will see only one line of error message; it will appear in the echo area and look like this:

Symbol's function definition is void: this

(Also, your terminal may beep at you--some do, some don't; and others blink. This is just a device to get your attention.) The message goes away as soon as you type another key, even just to move the cursor.

We know the meaning of the word `Symbol'. It refers to the first atom of the list, the word `this'. The word `function' refers to the instructions that tell the computer what to do. (Technically, the symbol tells the computer where to find the instructions, but this is a complication we can ignore for the moment.)

The error message can be understood: `Symbol's function definition is void: this'. The symbol (that is, the word `this') lacks instructions for the computer to carry out.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003