Rewrite "large file" detection
Adds a doom-inhibit-large-file-detection letvar for disabling it in some contexts.
This commit is contained in:
parent
eca50f4766
commit
0f2bb647eb
1 changed files with 17 additions and 11 deletions
|
@ -9,7 +9,10 @@ detected.")
|
||||||
indentation settings or not. This should be set by editorconfig if it
|
indentation settings or not. This should be set by editorconfig if it
|
||||||
successfully sets indent_style/indent_size.")
|
successfully sets indent_style/indent_size.")
|
||||||
|
|
||||||
(defvar-local doom-large-file-p nil)
|
(defvar doom-inhibit-large-file-detection nil
|
||||||
|
"If non-nil, inhibit large/long file detection when opening files.")
|
||||||
|
|
||||||
|
(defvar doom-large-file-p nil)
|
||||||
(put 'doom-large-file-p 'permanent-local t)
|
(put 'doom-large-file-p 'permanent-local t)
|
||||||
|
|
||||||
(defvar doom-large-file-size-alist '(("." . 1.0))
|
(defvar doom-large-file-size-alist '(("." . 1.0))
|
||||||
|
@ -40,22 +43,25 @@ runtime costs (or disable themselves) to ensure the buffer is as fast as
|
||||||
possible."
|
possible."
|
||||||
:before #'abort-if-file-too-large
|
:before #'abort-if-file-too-large
|
||||||
(and (numberp size)
|
(and (numberp size)
|
||||||
|
(null doom-inhibit-large-file-detection)
|
||||||
(ignore-errors
|
(ignore-errors
|
||||||
(> size
|
(> size
|
||||||
(* 1024 1024
|
(* 1024 1024
|
||||||
(assoc-default filename doom-large-file-size-alist
|
(assoc-default filename doom-large-file-size-alist
|
||||||
#'string-match-p))))
|
#'string-match-p))))
|
||||||
(setq doom-large-file-p size)))
|
(setq-local doom-large-file-p size)))
|
||||||
|
|
||||||
|
(add-hook! 'find-file-hook
|
||||||
|
(defun doom-optimize-for-large-files-h ()
|
||||||
|
"Trigger `so-long-minor-mode' if the file is large."
|
||||||
|
(when (and doom-large-file-p buffer-file-name)
|
||||||
|
(if (or doom-inhibit-large-file-detection
|
||||||
|
(memq major-mode doom-large-file-excluded-modes))
|
||||||
|
(kill-local-variable 'doom-large-file-p)
|
||||||
|
(when (fboundp 'so-long-minor-mode) ; in case the user disabled it
|
||||||
|
(so-long-minor-mode +1))
|
||||||
|
(message "Large file detected! Cutting a few corners to improve performance...")))))
|
||||||
|
|
||||||
(defadvice! doom--optimize-for-large-files-a (&rest _)
|
|
||||||
"Trigger `so-long-minor-mode' if the file is large."
|
|
||||||
:after #'after-find-file
|
|
||||||
(when (and doom-large-file-p buffer-file-name)
|
|
||||||
(if (memq major-mode doom-large-file-excluded-modes)
|
|
||||||
(setq doom-large-file-p nil)
|
|
||||||
(when (fboundp 'so-long-minor-mode) ; in case the user disabled it
|
|
||||||
(so-long-minor-mode +1))
|
|
||||||
(message "Large file detected! Cutting a few corners to improve performance..."))))
|
|
||||||
|
|
||||||
;; Resolve symlinks when opening files, so that any operations are conducted
|
;; Resolve symlinks when opening files, so that any operations are conducted
|
||||||
;; from the file's true directory (like `find-file').
|
;; from the file's true directory (like `find-file').
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue