aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Antipov2014-07-10 16:33:35 +0400
committerDmitry Antipov2014-07-10 16:33:35 +0400
commit9242810cd3bb14056dde937fc9ad39fc49261dfd (patch)
treeabd85cf5087ecbb123c3a511d78244fc9d069482 /lisp
parent80fb41cd90467782f4cfb21074aaa4f95308985e (diff)
downloademacs-9242810cd3bb14056dde937fc9ad39fc49261dfd.tar.gz
emacs-9242810cd3bb14056dde937fc9ad39fc49261dfd.zip
* 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 @@
12014-07-10 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * files.el (warn-maybe-out-of-memory): New function.
4 (find-file-noselect): Use it.
5
12014-07-09 Sam Steingold <sds@gnu.org> 62014-07-09 Sam Steingold <sds@gnu.org>
2 7
3 * progmodes/cperl-mode.el (cperl-block-p): Treat the perl keyword 8 * 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)."
1796 (file-size-human-readable size) op-type)))) 1796 (file-size-human-readable size) op-type))))
1797 (error "Aborted"))) 1797 (error "Aborted")))
1798 1798
1799(defun warn-maybe-out-of-memory (size)
1800 "Warn if an attempt to open file of SIZE bytes may run out of memory."
1801 (let ((meminfo (memory-info)))
1802 (when (consp meminfo)
1803 (let ((total-free-memory (+ (nth 1 meminfo) (nth 3 meminfo))))
1804 (when (and (not (zerop size))
1805 (> (/ size 1024) total-free-memory))
1806 (warn
1807 "You are trying to open file which size (%s)
1808exceeds an amount of available free memory (%s). If that
1809fails, try to open it with `find-file-literally' (but note
1810that some characters may be displayed incorrectly)."
1811 (file-size-human-readable size)
1812 (file-size-human-readable
1813 (* (float total-free-memory) 1024))))))))
1814
1799(defun find-file-noselect (filename &optional nowarn rawfile wildcards) 1815(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
1800 "Read file FILENAME into a buffer and return the buffer. 1816 "Read file FILENAME into a buffer and return the buffer.
1801If a buffer exists visiting FILENAME, return that one, but 1817If a buffer exists visiting FILENAME, return that one, but
@@ -1848,7 +1864,8 @@ the various files."
1848 (setq buf other)))) 1864 (setq buf other))))
1849 ;; Check to see if the file looks uncommonly large. 1865 ;; Check to see if the file looks uncommonly large.
1850 (when (not (or buf nowarn)) 1866 (when (not (or buf nowarn))
1851 (abort-if-file-too-large (nth 7 attributes) "open" filename)) 1867 (abort-if-file-too-large (nth 7 attributes) "open" filename)
1868 (warn-maybe-out-of-memory (nth 7 attributes)))
1852 (if buf 1869 (if buf
1853 ;; We are using an existing buffer. 1870 ;; We are using an existing buffer.
1854 (let (nonexistent) 1871 (let (nonexistent)