From 1e75763616ac95c7e6d6dce99e911b73aa5cee79 Mon Sep 17 00:00:00 2001 From: "Jaisser J. Sanguino" Date: Sat, 30 May 2026 00:55:50 -0300 Subject: [PATCH] feat(init): force fundamental-mode for files over 5MB Prevents performance degradation by disabling undo and setting large files to read-only fundamental-mode on open. --- configs/init-functions.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configs/init-functions.el b/configs/init-functions.el index 94b9768..d29f07d 100644 --- a/configs/init-functions.el +++ b/configs/init-functions.el @@ -159,5 +159,15 @@ If PROJECT is not specified, assume current project root." (global-corfu-mode 1) ) +(defun force-fundamental-for-large-files () + "If a file is over 5MB, open it in fundamental-mode and disable undo." + (when (> (buffer-size) (* 5 1024 1024)) + (setq buffer-read-only t) + (buffer-disable-undo) + (fundamental-mode) + (message "Buffer set to fundamental-mode and read-only due to size."))) + +(add-hook 'find-file-hook #'force-fundamental-for-large-files) + (provide 'init-functions) ;;; init-functions.el ends here.