[Tex/LaTex] How to specify default contents for a new .tex file in Emacs

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)
(add-hook 'find-file-hooks 'auto-insert)
(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?

Best Answer

Do you know about auto insert mode?