How to debug elisp?

Usually the easiest way to debug is to use printf . What can be done to debug emacs-lisp? How can I print something in the emacs editor from elisp? Or is there a way to debug elisp code?

For example, how can I check if the following code is executing in a .emacs file?

 (load "auctex.el" nil tt) 
+44
debugging emacs elisp
Jul 15 2018-10-15T00:
source share
5 answers

The debugger (edebug) is pretty easy to use. Go to the function definition and type Mx edebug-defun . The next time it is called, you can execute the code as with any other debugger. Enter ? for a list of key bindings or check out the documentation for edebug .

+57
Jul 15 '10 at 17:26
source share

GNU Emacs has two debuggers:

  • edebug - explained in another post here
  • debugging

I am using debug . These are common entry points (how to use it):

  • Mx debug-on-entry , followed by the function that you want to enter using the debugger.

  • Mx toggle-debug-on-error - Enter the debugger when an error occurs.

  • Mx toggle-debug-on-quit - Enter a debugger when the user presses Cg .
  • Place explicit calls to the debug function in specific places (breakpoints) in your code to enter the debugger in these places:
     (debug)

You go through the debugger with d or c to skip the details of a particular evaluation.

+22
Aug 21 '11 at 2:16
source share

This is useful for printing values.

 (message "Hello (%s)" foo) 

but not so good for data structures. To do this, use

 (prin1 list-foo) 

or (prin1-to-string) to insert it into (message).

+11
Jun 10 '12 at 18:05
source share

The easiest way to debug is to run your code interactively. You can do this in the lisp buffer by placing your dot after the expression and running Cx Ce ( eval-last-sexp ).

As an alternative:

 (message "hello world") 

Ch f message to learn more about the built-in message function. If you create a lot of messages, you can set the message-log-max variable to a larger value.

+6
Jul 15 '10 at 16:44
source share

To answer your questions one by one:

  • type something: there are a million ways. (message "Hello") places the string in the echo area; (insert "hello") puts the string in the current buffer at the point ...
  • How can I check if the following code is running: I would simply replace "auctex.el" with (say) "frotzumotzulous" (i.e. any line at all, if it does not name the real file), and then see if a message appears about the error. If you do not get an error, then it is clear that the code does not run.
+3
Jul 15 '10 at 23:08
source share



All Articles