Refactor doom|check-large-file

More checks, fewer false positives.
This commit is contained in:
Henrik Lissner 2018-06-14 19:51:11 +02:00
parent 3228369d73
commit 421d00f085
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -49,16 +49,18 @@ successfully sets indent_style/indent_size.")
"Check if the buffer's file is large (see `doom-large-file-size'). If so, ask
for confirmation to open it literally (read-only, disabled undo and in
fundamental-mode) for performance sake."
(let ((size (nth 7 (file-attributes buffer-file-name))))
(when (and (not (memq major-mode doom-large-file-modes-list))
size (> size (* 1024 1024 doom-large-file-size))
(y-or-n-p
(format (concat "%s is a large file, open literally to "
"avoid performance issues?")
(file-relative-name buffer-file-name))))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode))))
(when (and (not (memq major-mode doom-large-file-modes-list))
auto-mode-alist
(get-buffer-window (current-buffer)))
(when-let* ((size (nth 7 (file-attributes buffer-file-name))))
(when (and (> size (* 1024 1024 doom-large-file-size))
(y-or-n-p
(format (concat "%s is a large file, open literally to "
"avoid performance issues?")
(file-relative-name buffer-file-name))))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode)))))
(add-hook 'find-file-hook #'doom|check-large-file)