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?
printf
For example, how can I check if the following code is executing in a .emacs file?
.emacs
(load "auctex.el" nil tt)
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 .
GNU Emacs has two debuggers:
I am using debug . These are common entry points (how to use it):
debug
Mx debug-on-entry , followed by the function that you want to enter using the debugger.
Mx debug-on-entry
Mx toggle-debug-on-error - Enter the debugger when an error occurs.
Mx toggle-debug-on-error
Mx toggle-debug-on-quit
(debug)
You go through the debugger with d or c to skip the details of a particular evaluation.
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).
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 ).
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.
message-log-max
To answer your questions one by one: