2

Once every hour, or when I open a new file; I am usually getting error related to reading undo-tree history, which lead emacs daemon to frozen, and everytime I have to re-start the emacs.

The error I am having, where Emacs get frozen:

Error reading undo-tree history from "/home/alper/.emacs.d/undo/.!home!alper!personalize!emacs_q_git_edit.el.~undo-tree~"

How could I prevent emacs to get frozen due the Error reading undo-tree history from its file? Please note that when emacs frozen I was unable to debug it to invest it further.


The way I installed emacs:

mkdir -p ~/tools && cd ~/tools
git clone git://git.savannah.gnu.org/emacs.git && cd emacs
./autogen.sh
./configure --with-x-toolkit=yes --with-x-toolkit=no --with-native-compilation
make -j$(nproc)
sudo mkdir -p /opt/ss
sudo rm -f /opt/ss/*
sudo ln -s ~/tools/emacs/lib-src/emacsclient /opt/ss/
sudo ln -s ~/tools/emacs/src/emacs /opt/ss/

my configuration relevant to undo-tree, related:

(require 'undo-tree)
(setq undo-tree-auto-save-history t)
(global-undo-tree-mode t)
(setq undo-tree-auto-save-history t)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))
(global-set-key "\C-x\C-v" 'undo-tree-visualize)
(require 'linum)
(defun undo-tree-visualizer-update-linum (&rest args)
    (linum-update undo-tree-visualizer-parent-buffer))
(advice-add 'undo-tree-visualize-undo :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-redo :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-undo-to-x :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-redo-to-x :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualizer-mouse-set :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualizer-set :after #'undo-tree-visualizer-update-linum)
alper
  • 1,238
  • 11
  • 30

2 Answers2

2

You can try to disable undo-in-region. It is buggy and responsible for slowing down.

(setq undo-tree-enable-undo-in-region nil)
djangoliv
  • 3,169
  • 16
  • 31
  • Hopefully it will fix the problem I am having. I will update if I still face with the same error even `undo-tree-enable-undo-in-region` is disabled – alper Dec 17 '21 at 19:57
  • I should do `(setq undo-tree-enable-undo-in-region nil)` right? – alper Dec 17 '21 at 20:14
  • right. I updated the code in the message. – djangoliv Dec 18 '21 at 19:53
  • Is there any way to kill undo-tree when this kind of bug frozes emacs? – alper Dec 19 '21 at 15:05
  • not to my knowledge ... – djangoliv Dec 20 '21 at 08:24
  • Assuming you're on a Unix-like system, you can try `kill -USR2 ` for the Emacs process ID, which has much the same effect as typing `C-g` if you'd already enabled `debug-on-quit` (n.b. it does in fact enable that variable). Or `killall -e -i -USR2 emacs` (read the man page to see what that will do). – phils Jul 25 '23 at 23:11
2

I had a similar issue, and I figure documenting my diagnostic process here might help people with this sort of problem, as it applies for other emacs issues.

I used ctrl-G to stop the save operation, then set the variable debug-on-quit to t, saved again and then hit ctrl-g to find the stack trace and find that the issue was caused by the undo-tree-mode.

I then ran m-x undo-tree-mode to disable the undo tree mode, which allowed me to save successfully.

After this I set debug-on-quit back to nil.

It's not a permanent fix, but lets me save without having to quit emacs, recompile or anything like that.

vivicat
  • 21
  • 1