I would like to check whether a new file has been visited by an interactive command (e.g. visited using C-x C-f) or if it has been visited programmatically by some Lisp code.

Use case: I cooked my own template/auto-insert/skeleton functionality using yasnippet, and I mainly use it for LaTeX files. I would like the template functionality to apply only if I create the file by hand, and not whenever some Lisp code does that. In particular, my template function interactively asks for some input, and this should not happen when executing Lisp code.

Example: AUCTeX creates LaTeX buffers (with the corresponding files) from time to time, for example the region.tex file if you use TeX-pin-region functionality. I don't want the template function to apply here.

  • 1
    Using called-interactively-p might work.
    – wasamasa
    Nov 15, 2014 at 13:09
  • Submit a bug to Auctex. Packages shouldn't visit files.
    – Malabarba
    Nov 15, 2014 at 15:15

1 Answer 1



Add your setup function to find-file-hook. That hook is meant for files visited by the user, and packages shouldn't trigger it during non-interactive processing.

If AucTeX triggers this hook when it shouldn't, please file a bug report.


Unfortunately, there are instances in which find-file is wrongly used, which leads to that hook being triggered for non-interactive stuff like temp files.

In these situations, you should be able to check whether the file was visited by the user with the predicate (called-interactively-p 'any). Use this inside your setup function.
It will return nil if your function is called as part of an idle timer, so it might serve your purpose.

  • what should non-interactive elisp functions be using to read files into buffers?
    – stsquad
    Nov 17, 2014 at 15:38
  • @stsquad see the end of the linked question.
    – Malabarba
    Nov 17, 2014 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.