# How to specify default contents for a new .tex file in Emacs?

I would like have Emacs copy, by default, the contents of some defined file in the buffer of any non-existent .tex file I visit.

I am using AUCTeX and I believe that would be feasible by editing the file or variable that is responsible for appending the lines %%% Local Variables:, etc. in new .tex files, but I would prefer a solution by way of altering the .emacs file, for convenient portability and customizability.

In trying to look into it, I did encounter such Emacs hooks as find-file[-noselect]-hook, but I am unsure of how to specify that a hook will only be run for empty (non-existent) .tex files, or which Lisp function copies a file's contents in the current buffer.

Note: Use of the \input{...} command is not a work-around for what I intend to use this scheme for. To give a small example, I am trying to have the default .tex "skeleton" look somewhat like this:

\documentclass[11pt]{article}

\input{$HOME/defaults} %$
\title{ enter title here }

\begin{document}
\maketitle

% document body %

\bibliography{ specify bib file here }

\end{document}


Update

Thanks to Tom, I've found that I can get the above default contents (and in an actually better way, too) by using Emacs skeletons along with auto-insert-mode. Hence, I would put the following in my .emacs file:

(define-skeleton latex-skeleton
"Default LaTeX file initial contents."
"Title: "
"\\documentclass[11pt]{article}\n\n"
"\\input{\$HOME/defaults} %\$\n"
"\\title{ "str | " ENTER TITLE HERE " "}\n\n"
"\\begin{document}\n"
"\\maketitle\n\n"
""_"\n\n"
"\\bibliography{" (skeleton-read "BIB-file: ") | " SPECIFY BIB FILE HERE " "}\n\n"
"\\end{document}\n")

(require 'autoinsert)
(setq auto-insert-query nil)
(setq auto-insert-alist
'(("\\.tex\$" . latex-skeleton)))


However, this does not work for .tex files, nor does it work for latex-mode (specified by changing the last line above to '((latex-mode . latex-skeleton))))!

If, instead, I use any other file extension or Emacs major mode it works fine. Therefore, I believe this to be caused by the AUCTeX-defined default actions on visiting a new .tex file, such as prompting the user to set the master file, appending lines like %%% Local Variables:, etc.

How could it be possible that I set AUCTeX to incorporate my customizations to its defaults? Or would there be some other work-around?

-
Your customization works for me: if I start with emacs -Q -l /path/to/auctex, and then evaluate your snippet, and open a new tex file the skeleton does run as expected. So there must be something else in your .emacs that is causing it to not work. If you can track it down by doing a binary search of your .emacs then we can find a work around. –  Ivan Andrus Mar 10 '12 at 11:21
@IvanAndrus's suggestion also works for me. I'm having a similar problem. –  Phillip Cloud Mar 11 '12 at 20:42

Thanks! auto-insert-mode seems to be just the thing, particularly if used in conjunction with skeletons. Unfortunately, however, it seems that the default actions defined by AucTeX (e.g. prompting for a master file, and appending %%% Local Variables: , and so forth) suppress the auto-insert actions I define in my .emacs file... (I've updated my question as well.) –  Sweeters Mar 6 '12 at 20:29