1

Is there a way to find out, what function called?

Let's say, there's a handler-function that monitors requests to an external process. Before it processes the requests, it prints them into a log file for later inspection.

Can this function find out, by which function it got called?

nobae
  • 13
  • 3
  • Take a look at the variables `this-command` and `last-command`. – Dan Jul 26 '14 at 10:38
  • 1
    Aargh. Yes. And documented smack in the middle of the comand loop description in the manual. I know, I know, first do homework, then start foraging useful, certified knowledge. – nobae Jul 26 '14 at 12:04

1 Answers1

1

The answer is no, there is no way to know which function was just called, or which function called a function that is currently being evaluated.

Consider, for example, what happens when byte-compiled code is executed: functions you see in the source code are typically absent from the byte-compiled code.

The comment about this-command and last-command is valid, but it applies only to commands, not functions in general. Be aware too that some functions change the value of this-command or last-command, so these do not necessarily always indicate what their names suggest.

Drew
  • 29,895
  • 7
  • 74
  • 104
  • You're right. These variables are perfectly useless for my purpose. I dreaded I'll have to supply the function name with every call, which feels unelegant and *will* look horrible. Yet it doesn't seem to be a matter of choice. – nobae Jul 27 '14 at 15:23