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:31:18 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

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


-- Stefan




reply via email to

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