I'm using Elpy for Python development, and when I run code with C-c C-c the source buffer closes -- which I don't want. Have to constantly reopen.

One idea is to set a breakpoint in kill-buffer - except upon doing C-h f on kill-buffer I find that it's written in C source code. How then would I debug invocations of kill-buffer?

1 Answer 1


M-x debug-on-entry kill-buffer

That opens the standard Emacs debugger whenever kill-buffer is invoked. It doesn't matter that it's a built-in (primitive, not coded in Lisp).

See the Elisp manual, nodes Function Debugging and Using Debugger.

  • 1
    Thanks - that's useful - although it's already raising new questions. It opens a Backtrace buffer with the call stack. It seems that elpy is very sensitive to this - just scrolling through my source file provokes breaks into Backtrace. Then if I attempt to move the mouse from the source buffer to Backtrace, Backtrace disappears. ... I wrote more .. but stackex tells me "too long by 400 chars." Ah - pastebin.com/YjP0FNcw
    – patfla
    Jun 16, 2021 at 21:59
  • 2
    Buffers are a data type in Emacs -- they are created and killed behind the scenes all the time. Consider the with-temp-buffer macro, for instance. You can expect kill-buffer to be called frequently.
    – phils
    Jun 16, 2021 at 22:18
  • What @phils said. The answer tells you how to do it, but it's better to tell you that you probably don't want to do it, except maybe briefly, just to see which function initially invoked kill-buffer.
    – Drew
    Jun 17, 2021 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.