4

Are there reflection methods available in elisp to examine the stack without invoking the debugger?

For example:

  • Get the calling/callee function
  • Get the function call stack
  • Get the (longer) nested statement stack
  • Get arguments for any of the above

An aside: In my search for applicable features/functions/variables I was surprised to learn that elisp does not (natively) perform tail call optimization! Presumably elisp does then maintain a complete stack.

Drew
  • 75,699
  • 9
  • 109
  • 225
ebpa
  • 7,319
  • 26
  • 53
  • 1
    See `called-interactively-p` for a function doing this. I generally recommend against doing such a thing as it's error-prone, incredibly hard to read and lispy languages don't have the need for it. – wasamasa Jun 10 '16 at 08:03

1 Answers1

3

Short answer : the function backtrace-frame should be what you want.

How did I find this ? Well, here are the steps :

  1. invoke the elisp info manual (my favourite way is C-h r TAB RET), then
  2. search stack in the index via i stack RET.

The first result brings you to (info "(elisp) Internals of Debugger") which mentions backtrace-frame. I think this has all you want.

You can also look at the implementation of the debugger in debug.el, e.g. with M-x find-function RET debug RET if you have the sources installed.

YoungFrog
  • 3,496
  • 15
  • 27