I started to use Dired. The movie files will be opened by another external application (VLC) with the help of the package openwith
.
So I would like to supress the confirmation File foobar.avi is too large, really open? (y or n)
for movie files.
When exploring this feature, I found the variable large-file-warning-thresold
, the docstring is:
The variable is large-file-warning-threshold. Documentation:
large-file-warning-threshold is a variable defined in `files.el'.
Its value is 10000000
Documentation:
Maximum size of file above which a confirmation is requested.
When nil, never request confirmation.
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 22.1 of Emacs.
So I would like to disable this thresold for only specific extensions like .mp4
or .mkv
, but don't change it for another extensions.
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.)
So I would add the condition for .mp4
and .mkv4
files.
Any idea how I could achieve that, without fiddling with the source code for Dired? I could use defadvice
, but it's currently unclear to me how I could apply extra conditional for confirmation messages.