23

When I open a large file in emacs, I get a message saying 'foo.bar file is large; really open?'

How do I stop emacs from asking me this question all the time? In other words, if I open the file, I want to open the file, no matter how big it is.

2
  • Answer is available here: superuser.com/questions/508498/… (setq large-file-warning-threshold nil)
    – R Perrin
    Jan 7, 2014 at 19:26
  • Gilles' answer below is more complete and will teach you how to solve your next problems.
    – jrouquie
    Nov 3, 2015 at 9:12

1 Answer 1

36

Via the manual

In the manual (which you can browse inside Emacs in Info: C-h i m Emacs RET): go to the chapter on files, then to the section on visiting (i.e. opening) files. Look for the word “large”:

If you try to visit a file larger than large-file-warning-threshold (the default is 10000000, which is about 10 megabytes), Emacs asks you for confirmation first. You can answer y to proceed with visiting the file.

This is not the whole story, you can find more information by looking at the documentation of large-file-warning-threshold (C-h v large-file-warning-threshold RET).

large-file-warning-threshold is a variable defined in files.el.
Its value is 10000000

Maximum size of file above which a confirmation is requested.
When nil, never request confirmation.

To set the value, you can either use the Customize interface (there's a link in the help screen for the variable), or put the following statement in your .emacs:

(setq large-file-warning-threshold nil)

Type C-M-x while the point is on that line to execute it now.

In the Customize interface

Under “Files”, under “Find Files”, there is a setting “Large File Warning Threshold”. You can set it to a large value, though on a 32-bit machine you may run into Emacs's relatively small hard limit on integer sizes.

By reading the source

Look at the function to open files: C-h k C-x C-f (or C-h f find-file RET). Click on files.el to browse the source file (you must have the Lisp sources installed). Don't read the code — it's pretty big — but search for parts of the message in that file. You'll find

(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)."
  (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")))

The message is only displayed when some conditions are met. The first condition is large-file-warning-threshold (interpreted as a boolean), i.e. large-file-warning-threshold must be non-nil. So you can disable the message by setting that variable to nil. (You can confirm that it's a global variable by looking at its definition in the same file — it's a customizable item, and the documentation explains how it's used if you aren't familiar enough with Lisp and only figured out that the variable mattered in some way.)

2
  • To open the emacs manual "C-h r" is easier than "C-h i m Emacs RET" Mar 12, 2023 at 16:19
  • Still correct, except for the small bit (nitpicky, I know ;-)) where the "File %s is large" isn't in abort-if-file-too-large anymore, it's been moved to a helper function files--ask-user-about-large-file at some point between 2014 and Emacs 29. Sep 22, 2023 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .