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.
abort-if-file-too-large
raises an error if its conditions are met, and does nothing at all otherwise. As such, all we need to do here is to wrap our own condition around the function, such that the original definition isn't executed at all if we're happy with the filename. Inaround
advice,ad-do-it
is a token which calls the original function; so here that only happens if the filename (which is argument 2 of the original function) isn't a match for our regexp. – phils Oct 03 '15 at 14:06defadvice
, starting with node Defining Advice of the Elisp manual. Unfortunately, this doc was (unwisely, IMHO) removed with 24.4 and later. (Maybe you can find an older manual on line.) – Drew Oct 03 '15 at 16:11advice.el
. Thank goodness for that. As for who removed it from the Elisp manual, and why, see bug 16491. The new advice system has some features that the old does not, and vice versa. But the old was simply tossed, and its doc along with it. – Drew Oct 03 '15 at 16:22