summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2014-07-11 16:19:58 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2014-07-11 16:19:58 +0400
commit3aa96ff51efd72767f1a4e04c546187269b008c0 (patch)
tree64b09920082278cf2d84137dd1fe66f2179b15bf /lisp
parent5f7c30e757680f66be9ef4c399fd1d7ce5b66203 (diff)
downloademacs-3aa96ff51efd72767f1a4e04c546187269b008c0.tar.gz
* src/alloc.c (Fmemory_info) [HAVE_LINUX_SYSINFO]: Return nil if
sysinfo failed. Adjust docstring. * doc/lispref/internals.texi (Garbage Collection): Mention memory-info. * lisp/files.el (out-of-memory-warning-percentage): New defcustom. (warn-maybe-out-of-memory): Use it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/files.el23
2 files changed, 22 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3965da7287b..faa5a3dffff 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2014-07-11 Dmitry Antipov <dmantipov@yandex.ru>
+
+ * files.el (out-of-memory-warning-percentage): New defcustom.
+ (warn-maybe-out-of-memory): Use it.
+
2014-07-11 Michael Albinus <michael.albinus@gmx.de>
* subr.el (read-passwd): Use `read-hide-char' if non-nil. Bind it
diff --git a/lisp/files.el b/lisp/files.el
index 258a37616c1..d3aa063e788 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1786,6 +1786,14 @@ When nil, never request confirmation."
:version "22.1"
:type '(choice integer (const :tag "Never request confirmation" nil)))
+(defcustom out-of-memory-warning-percentage 50
+ "Warn if file size exceeds this percentage of available free memory.
+When nil, never issue warning."
+ :group 'files
+ :group 'find-file
+ :version "24.4"
+ :type '(choice integer (const :tag "Never issue warning" nil)))
+
(defun abort-if-file-too-large (size op-type filename)
"If file SIZE larger than `large-file-warning-threshold', allow user to abort.
OP-TYPE specifies the file operation being performed (for message to user)."
@@ -1798,19 +1806,22 @@ OP-TYPE specifies the file operation being performed (for message to user)."
(defun warn-maybe-out-of-memory (size)
"Warn if an attempt to open file of SIZE bytes may run out of memory."
- (when (and (numberp size) (not (zerop size)))
+ (when (and (numberp size) (not (zerop size))
+ (integerp out-of-memory-warning-percentage))
(let ((meminfo (memory-info)))
(when (consp meminfo)
- (let ((total-free-memory (+ (nth 1 meminfo) (nth 3 meminfo))))
- (when (> (/ size 1024) total-free-memory)
+ (let ((total-free-memory (float (+ (nth 1 meminfo) (nth 3 meminfo)))))
+ (when (> (/ size 1024)
+ (/ (* total-free-memory out-of-memory-warning-percentage)
+ 100.0))
(warn
"You are trying to open a file whose size (%s)
-exceeds the amount of currently available free memory (%s).
+exceeds the %S%% of currently available free memory (%s).
If that fails, try to open it with `find-file-literally'
\(but note that some characters might be displayed incorrectly)."
(file-size-human-readable size)
- (file-size-human-readable
- (* (float total-free-memory) 1024)))))))))
+ out-of-memory-warning-percentage
+ (file-size-human-readable (* total-free-memory 1024)))))))))
(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
"Read file FILENAME into a buffer and return the buffer.