emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Large-file check in files.el


From: Adrian Robert
Subject: Re: Large-file check in files.el
Date: Tue, 1 Apr 2008 15:02:04 +0300

On Tue, Apr 1, 2008 at 8:57 AM, Stefan Monnier <address@hidden> wrote:
> > In find-file-noselect, confirmation is required for filesize >
>  > large-file-warning-threshold, yet in insert-file-1, it is not.  Is
>  > there a reason large files should be allowed to be inserted -- but not
>  > loaded by themselves -- without confirmation?  If not, I propose the
>  > patch below.
>
>  That makes sense.  But please factor out the size-check code into its
>  own function which you can then call from both places.  This will be
>  better than duplicating the code like your patch currently does.

OK, here is a new version of the patch.
------------------


Index: files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.966
diff -c -b -r1.966 files.el
*** files.el    14 Mar 2008 17:14:09 -0000      1.966
--- files.el    1 Apr 2008 12:00:30 -0000
***************
*** 1507,1512 ****
--- 1507,1523 ----
    :version "22.1"
    :type '(choice integer (const :tag "Never request confirmation" nil)))

+ (defun should-abort-large-file (attributes opType &optional buf nowarn)
+   "Utility function: return t if file is larger than
large-file-warning-threshold
+ and user declines loading it.  If buf or nowarn are true, always return nil."
+   (if (and large-file-warning-threshold (nth 7 attributes) (not (or
buf nowarn)))
+       (and (> (nth 7 attributes) large-file-warning-threshold)
+          (not (y-or-n-p
+                (format "File %s is large (%dMB), really %s? "
+                        (file-name-nondirectory filename)
+                        (/ (nth 7 attributes) 1048576) opType))))
+     nil))
+
  (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,1572 ****
              (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"))
        (if buf
            ;; We are using an existing buffer.
--- 1569,1575 ----
              (if (or find-file-existing-other-name find-file-visit-truename)
                  (setq buf other))))
        ;; Check to see if the file looks uncommonly large.
!       (when (should-abort-large-file attributes "open" buf nowarn)
          (error "Aborted"))
        (if buf
            ;; We are using an existing buffer.
***************
*** 1796,1801 ****
--- 1799,1807 ----
    (if (file-directory-p filename)
        (signal 'file-error (list "Opening input file" "file is a directory"
                                  filename)))
+   ;; Check whether the file is uncommonly large (see find-file-noselect):
+   (when (should-abort-large-file (file-attributes filename) "insert")
+     (error "Aborted"))
    (let* ((buffer (find-buffer-visiting (abbreviate-file-name
(file-truename filename))
                                         #'buffer-modified-p))
           (tem (funcall insert-func filename)))


Diffs between working revision and workfile end here.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]