help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to reject visiting a file


From: Stefan Monnier
Subject: Re: How to reject visiting a file
Date: Fri, 12 Dec 2014 10:56:53 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

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

find-file-noselect is the "single entry" used normally to visit a file
in a normal file buffer, no matter how this is triggered (find-file,
find-file-other-window, clinking on an error in a *compile* buffer, ...)
so it should have excellent coverage.

This advice doesn't prevent Emacs from accessing the file (e.g. you can
still use insert-file-contents to read the file and put it in some
buffer and you can still use M-x insert-file as well), but it would be
*very* weird for a package to use such an approach over just calling
find-file-noselect.

I'll let you judge if it's good enough for your use case.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]