diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/files.el | 19 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d14a3a8584b..ffb1eee945e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2014-07-10 Dmitry Antipov <dmantipov@yandex.ru> + + * files.el (warn-maybe-out-of-memory): New function. + (find-file-noselect): Use it. + 2014-07-09 Sam Steingold <sds@gnu.org> * progmodes/cperl-mode.el (cperl-block-p): Treat the perl keyword 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) |
