Sporadically when I open a large file in emacs it will hang forever, except the GUI will remain responsive! I can move my mouse between frames and the cursor will fill in, hovering over files in dired mode still highlights them, etc. but clicking doesn't cause any action to actually be performed. Ideally of course whatever bug is in emacs will get fixed eventually, but for now, is there anyway I can interrupt emacs loading the file, or change my .emacs to make it interruptible? Ctrl+G doesn't work.

Clarification: I'm trying not to lose my work -- so I mean interrupt emacs without killing it, as in, have it return to just how it was before I tried opening the file.

1 Answer
1

I use the following hook to force Emacs to open large files in fundamental mode, read only, and without undo. This does speed up viewing large files as avoids any time spent during fontification. I've found this to be helpful behavior, and I can always turn on any of those features easily if I want. UPDATE - fixed typo with find-file-hook.

(defun my-find-file-check-make-large-file-read-only-hook ()
"If a file is over a given size, make the buffer read only."
(when (> (buffer-size) (* 10 1024 1024))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode)
; (message "Buffer is set to read-only because it is large. Undo also disabled.")
))
(add-hook 'find-file-hook 'my-find-file-check-make-large-file-read-only-hook)