Who Called My Function?
Someone asked why his Emacs starts up with two split screen.
Apparently something in his init.el
caused that.
But how can we find what caused the problem? I searched around and
found a way to check "backtrace frame" in Emacs:
backtrace-frames
.
Here is what I cooked up:
(advice-add 'split-window-right :before (lambda (&rest _) (print (backtrace-frames)))) (defun some-function () (split-window-right))
So when I call the function some-funtion
, a split
window is created with following information printed:
((t backtrace-frames nil nil) (nil print ((backtrace-frames)) nil) (t (lambda (&rest _) (print (backtrace-frames))) nil nil) (t apply ((lambda (&rest _) (print (backtrace-frames))) nil) nil) (t split-window-right nil nil) (t some-function nil nil) (t eval ((some-function) nil) nil) (t elisp--eval-last-sexp (t) nil) (t eval-last-sexp (t) nil) (t eval-print-last-sexp (nil) nil) (t funcall-interactively (eval-print-last-sexp nil) nil) (t call-interactively (eval-print-last-sexp nil nil) nil) (t command-execute (eval-print-last-sexp) nil))
We can see some-funtion
is right before
split-window
. Cool. As for the other t
and
nil
stuff, I chose to not bother.