changeset 93688:3961ad1ac8f2

files.el: add abort-if-file-too-large and use it in find-file-noselect and insert-file-1
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Sat, 05 Apr 2008 12:03:23 +0000
parents 4a2fb96d5195
children 40434d3c3093
files lisp/ChangeLog lisp/files.el
diffstat 2 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Apr 05 10:06:14 2008 +0000
+++ b/lisp/ChangeLog	Sat Apr 05 12:03:23 2008 +0000
@@ -1,3 +1,8 @@
+2008-04-05  Adrian Robert  <Adrian.B.Robert@gmail.com>
+
+	* files.el (abort-if-file-too-large): New function.
+	(find-file-noselect, insert-file-1): Use it.
+
 2008-04-05  Reto Zimmermann  <reto@gnu.org>
 
 	* progmodes/vhdl-mode.el (vhdl-mode-map-init):
--- a/lisp/files.el	Sat Apr 05 10:06:14 2008 +0000
+++ b/lisp/files.el	Sat Apr 05 12:03:23 2008 +0000
@@ -1507,6 +1507,17 @@
   :version "22.1"
   :type '(choice integer (const :tag "Never request confirmation" nil)))
 
+(defun abort-if-file-too-large (size op-type)
+  "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)."
+  (when (and large-file-warning-threshold size
+	   (> size large-file-warning-threshold)
+	   (not (y-or-n-p
+		 (format "File %s is large (%dMB), really %s? "
+			 (file-name-nondirectory filename)
+			 (/ size 1048576) op-type))))
+	  (error "Aborted")))
+
 (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
@@ -1558,16 +1569,8 @@
 	      (if (or find-file-existing-other-name find-file-visit-truename)
 		  (setq buf other))))
 	;; Check to see if the file looks uncommonly large.
-	(when (and large-file-warning-threshold (nth 7 attributes)
-		   ;; Don't ask again if we already have the file or
-		   ;; if we're asked to be quiet.
-		   (not (or buf nowarn))
-		   (> (nth 7 attributes) large-file-warning-threshold)
-		   (not (y-or-n-p
-			 (format "File %s is large (%dMB), really open? "
-				 (file-name-nondirectory filename)
-				   (/ (nth 7 attributes) 1048576)))))
-	  (error "Aborted"))
+	(when (not (or buf nowarn))
+	  (abort-if-file-too-large (nth 7 attributes) "open"))
 	(if buf
 	    ;; We are using an existing buffer.
 	    (let (nonexistent)
@@ -1796,6 +1799,8 @@
   (if (file-directory-p filename)
       (signal 'file-error (list "Opening input file" "file is a directory"
                                 filename)))
+  ;; Check whether the file is uncommonly large
+  (abort-if-file-too-large (nth 7 (file-attributes filename)) "insert")
   (let* ((buffer (find-buffer-visiting (abbreviate-file-name (file-truename filename))
                                        #'buffer-modified-p))
          (tem (funcall insert-func filename)))