Skip to content

Commit

Permalink
tweak: no need to get file size attribute since it is already open!
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jun 26, 2024
1 parent 56f3984 commit 7000897
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions guard-lf.el
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@

;; NOTE: This section is copied around variable `large-file-warning-threshold'.

(defun guard-lf--file-too-large-p (filename)
"Return non-nil if FILENAME's size is too large."
(when-let (((file-readable-p filename))
(attributes (file-attributes filename))
(size (file-attribute-size attributes)))
(and large-file-warning-threshold
(> size large-file-warning-threshold))))

(defun guard-lf--buffer-too-large-p (buffer)
"Return non-nil if BUFFER's size is too large."
(and large-file-warning-threshold
Expand All @@ -93,14 +85,7 @@
;;; API

;;;###autoload
(defun guard-lf-file-p (&optional filename)
"Return non-nil if the large FILENAME is detected."
(when-let ((filename (or filename (buffer-file-name))))
(and (file-regular-p filename)
(guard-lf--file-too-large-p filename))))

;;;###autoload
(defun guard-lf-buffer-p (&optional buffer)
(defun guard-lf-p (&optional buffer)
"Return non-nil if the BUFFER is large."
(when-let ((buffer (or buffer (current-buffer))))
(or (guard-lf--buffer-too-large-p buffer)
Expand All @@ -113,7 +98,7 @@
"Advice around the function `set-auto-mode-0'.
Arguments FNC and ARGS are used to call original operations."
(when (or (guard-lf-file-p) (guard-lf-buffer-p))
(when (guard-lf-p)
(when (and guard-lf-major-mode
(not (apply #'provided-mode-derived-p (cons (car args) guard-lf-intact-major-modes))))
(message "[INFO] Large file detected; use the `%s' as the new major mode"
Expand Down

0 comments on commit 7000897

Please sign in to comment.