all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Adrian Robert" <adrian.b.robert@gmail.com>
To: "Stefan Monnier" <monnier@iro.umontreal.ca>
Cc: emacs- devel <emacs-devel@gnu.org>
Subject: Re: Large-file check in files.el
Date: Tue, 1 Apr 2008 15:02:04 +0300	[thread overview]
Message-ID: <55f7df060804010502j689f88c4k8888030298f3d065@mail.gmail.com> (raw)
In-Reply-To: <jwv8wzy9kyn.fsf-monnier+emacs@gnu.org>

On Tue, Apr 1, 2008 at 8:57 AM, Stefan Monnier <monnier@iro.umontreal.ca> 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	other threads:[~2008-04-01 12:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-01  4:55 Large-file check in files.el Adrian Robert
2008-04-01  5:57 ` Stefan Monnier
2008-04-01 12:02   ` Adrian Robert [this message]
2008-04-01 15:56     ` Stefan Monnier
2008-04-02 17:59       ` Adrian Robert
2008-04-03 14:03         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55f7df060804010502j689f88c4k8888030298f3d065@mail.gmail.com \
    --to=adrian.b.robert@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.