如何中斷 emacs 開啟大檔案?

如何中斷 emacs 開啟大檔案?

有時,當我在 emacs 中開啟一個大檔案時,它會永遠掛起,但 GUI 仍會保持回應!我可以在幀之間移動滑鼠,遊標將填充,將滑鼠懸停在 Dired 模式下的文件上仍然會突出顯示它們,等等,但單擊不會導致實際執行任何操作。當然,理想情況下,emacs 中的任何錯誤最終都會得到修復,但現在,我是否可以中斷 emacs 加載文件,或者更改我的 .emacs 以使其可中斷? Ctrl+G 不起作用。

澄清:我正在努力不丟失我的工作——所以我的意思是中斷 emacs不殺死它,例如,讓它恢復到我嘗試開啟檔案之前的狀態。

答案1

我使用以下鉤子強制 Emacs 以基本模式、唯讀且不撤銷方式開啟大檔案。這確實可以加快查看大檔案的速度,避免在字體化過程中花費任何時間。我發現這是一種有用的行為,如果我願意,我隨時可以輕鬆打開這些功能中的任何一個。更新 - 修復了 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)

相關內容