19
votes

There is one thing that I don't like on table function in Org-mode for emacs. I would like to see all the functions that get executed by function that I run as Emacs command.

What is the best way to do that? Any tips how to get started with debuging elisp code, especially single command of interest?

4

4 Answers

26
votes
  1. C-hf function name to find the source code for the function.
  2. C-uC-M-x to instrument the function for Edebug.

Whenever the function is called, Emacs will drop into Edebug which makes it easy to execute the function step by step, inspect variables, and do other typical debugging tasks. See (info "(Elisp)Edebug") for more information.

15
votes

I prefer the traditional Emacs debugger to edebug. To use it:

M-x debug-on-entry the-function RET

Then, whenever the-function is invoked, the debugger is entered. Use d to step through the evaluation, and c if you want to skip through a step (not dive into its details.

It helps to view the definition of the-function in another window/frame while you step through it.

You can cancel debug-on-entry using M-x cancel-debug-on-entry.

0
votes

C-h f to go to function help mode, then type the name of the function. If it is an elisp function, you can then view the source and look for yourself what functions it calls.

0
votes

If you want a programmatic way to see the source of a function (akin to Clojure's source macro) you can use the symbol-function subroutine.

For instance, there is a defun do-math in my .emacs file. To see its source, I can do the following

(symbol-function 'do-math)

and it gives me

ELISP> (symbol-function 'do-math)
(lambda
  (expression)
  (interactive "sexpression:")
  (insert
   (number-to-string
    (eval
     (read expression)))))

See also : https://www.gnu.org/software/emacs/manual/html_node/elisp/Function-Indirection.html

See also also : http://ergoemacs.org/emacs/elisp_symbol.html