Closed CyberShadow closed 5 years ago
I also experienced this, but only very rarely and the last time was a long time ago too. so I spent only relatively little time debugging it. I hope you have better luck getting to the bottom of this.
Any ideas on what to look for? Any interesting variables' states to observe?
I did some research after encountering this today, and compared the states/behavior of Emacs instances with a broken and working visual-regexp. Though I did not find what initially causes visual-regexp to break, I did find how its effect makes visual-regexp stops working:
The global value of after-change-functions
becomes nil
.
The documentation of after-change-functions
says:
If an unhandled error happens in running these functions, the variable’s value remains nil. That prevents the error from happening repeatedly and making Emacs nonfunctional.
So, it looks like visual-regexp
breaks when one of the hooks in after-change-functions
(possibly but not necessarily vr--after-change
) runs into an error.
The workaround to fix it is to run (add-hook 'after-change-functions 'vr--after-change)
again.
One permanent workaround would be to move the add-hook
call to the visual-regexp
interactive commands, which would also work as a small optimization by deferring adding the hook until vr-replace is ignored. (Come to think of it, that hook should actually only be set for the minibuffer, not all buffers.) I'd like to figure out what causes after-change-functions
to become nil
though, as that breaks the remaining hooks too.
Thanks a lot for investigating. I made a commit that implements your proposed workaround:
https://github.com/benma/visual-regexp.el/commit/3e3ed81a3cbadef1f1f4cb16f9112a58641d70ca
I haven't encountered this problem since your fix. Thank you!
Invariantly, after Emacs has been running for a few hours, visual-regexp stops displaying live previews.
I haven't tracked down what exactly causes it to break.
I'm not sure how to debug this, so here's some screenshots for now:
Working
Broken