[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to reject visiting a file
From: |
Óscar Fuentes |
Subject: |
Re: How to reject visiting a file |
Date: |
Fri, 12 Dec 2014 16:47:20 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>>> Is there a way to error-out when Emacs tries to visit certain file
>>>> before the file is loaded? I'll like to use a hook that receives the
>>>> file name and be able to throw an error from there that aborts the
>>>> operation.
>>> You could define a file-handler for these files.
>> Yes, that looks like a solution.
>> For the record, the relevant info is in the Elisp manual:
>> Making Certain File Names “Magic”
>
> I think that's going to be pretty heavyweight.
I hope not. The function will inspect the file name (possibly the
primitive too) and either throw an error or delegate to
file-name-non-special.
> A simpler approach is something like
>
> (defun sm-prevent-visiting-files (filename &rest _)
> (if (string-match "nasty-file-name" filename)
> (error "Bad! Bad file name! Bad!")))
> (advice-add 'find-file-noselect :before #'sm-prevent-visiting-files)
That was my first idea, but it was discarded because I'm not sure about
its coverage. I don't know the method a given package can use to
visit/load/read a file.