summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2014-07-10 16:33:35 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2014-07-10 16:33:35 +0400
commit9242810cd3bb14056dde937fc9ad39fc49261dfd (patch)
treeabd85cf5087ecbb123c3a511d78244fc9d069482 /lisp
parent80fb41cd90467782f4cfb21074aaa4f95308985e (diff)
downloademacs-9242810cd3bb14056dde937fc9ad39fc49261dfd.tar.gz
* configure.ac: Check whether sys/sysinfo.h provides
Linux 'sysinfo' function and 'struct sysinfo' type. * src/alloc.c (Fmemory_info): New function. * lisp/files.el (warn-maybe-out-of-memory): New function. (find-file-noselect): Use it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/files.el19
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)