summaryrefslogtreecommitdiff
path: root/lisp/files.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el19
1 files changed, 18 insertions, 1 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 27d3ec7464e..63bdf636b63 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1796,6 +1796,22 @@ OP-TYPE specifies the file operation being performed (for message to user)."
(file-size-human-readable size) op-type))))
(error "Aborted")))
+(defun warn-maybe-out-of-memory (size)
+ "Warn if an attempt to open file of SIZE bytes may run out of memory."
+ (let ((meminfo (memory-info)))
+ (when (consp meminfo)
+ (let ((total-free-memory (+ (nth 1 meminfo) (nth 3 meminfo))))
+ (when (and (not (zerop size))
+ (> (/ size 1024) total-free-memory))
+ (warn
+ "You are trying to open file which size (%s)
+exceeds an amount of available free memory (%s). If that
+fails, try to open it with `find-file-literally' (but note
+that some characters may be displayed incorrectly)."
+ (file-size-human-readable size)
+ (file-size-human-readable
+ (* (float total-free-memory) 1024))))))))
+
(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
"Read file FILENAME into a buffer and return the buffer.
If a buffer exists visiting FILENAME, return that one, but
@@ -1848,7 +1864,8 @@ the various files."
(setq buf other))))
;; Check to see if the file looks uncommonly large.
(when (not (or buf nowarn))
- (abort-if-file-too-large (nth 7 attributes) "open" filename))
+ (abort-if-file-too-large (nth 7 attributes) "open" filename)
+ (warn-maybe-out-of-memory (nth 7 attributes)))
(if buf
;; We are using an existing buffer.
(let (nonexistent)