How to interrupt emacs when control-g does not work in very large files?

I've run into some kind of O(n^2) or worse behavior when viewing very large (e.g. 128MB) files in Emacs and jumping to the end of the file. I think it may have to do with my coloring algorithm to color the text contextually. If I type control-g (keyboard-quit), the operation is not affected. I'd like some way to recover my emacs session without just killing it. I tried sending a SIGINT, but emacs just exited. Are there any signals I can send, or some other way (perhaps in a debugger) to force the whatever action is running to give up and return control to me?


I doubt it's font lock mode. That probably only does sections near what's visible. It's probably copying data in memory.

sigusr1

sigusr2

These events are generated when the Emacs process receives the signals SIGUSR1 and SIGUSR2. They contain no additional data because signals do not carry additional information. They can be useful for debugging (see Error Debugging).

Source: GNU Emacs Lisp Reference Manual: Misc Events

I don't know what it would do (or what version of emacs you are running) but you could try a PROBABLY non-destructive signal (USR1 or USR2).

$ kill -USR1 pid

Or you could go to sleep and see if it recovers.


I'm unaware of any signal handling that emacs does but you could use the Emacs Server by putting server-start in your ~/.emacs file so you can do RPC on your running instance of emacs.

Then when you want to kill emacs and write you can call from your shell emacsclient -e '(save-buffers-kill-emacs t)'.