emacs: debugging why Emacs would hang on saving


Emacs was occasionally hanging on me when I tried to save the buffer. This would consistently happen on XML files in particular, for whatever reason. Online advice didn’t help, but I learned that SIGUSR2 makes Emacs to drop into a debugger. So I saved, let it hang, and got this backtrace:

Debugger entered--Lisp error: (quit)
  #f(compiled-function () #<bytecode -0x1c8aa446c53011eb>)()
  undo-tree-save-history(nil overwrite)
  undo-tree-save-history-from-hook()
  kill-buffer("pom.xml")
  funcall-interactively(kill-buffer "pom.xml")
  call-interactively(kill-buffer nil nil)
  command-execute(kill-buffer)

It looks like undo-tree was the culprit, so I just turned off undo-tree-auto-save-history, and the problem was gone.