1 ;;; autoinsert.el --- automatic mode-dependent insertion of text into new files
3 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;;; The following defines an association list for files to be
26 ;;; automatically inserted when a new file is created, and a function
27 ;;; which automatically inserts these files; the idea is to insert
28 ;;; default files much as the mode is automatically set using
31 ;;; The auto-insert-alist consists of dotted pairs of
32 ;;; ( REGEXP . FILENAME ) where REGEXP is a regular expression, and
33 ;;; FILENAME is the file name of a file which is to be inserted into
34 ;;; all new files matching the regular expression with which it is
38 ;;; load autoinsert.el
39 ;;; setq auto-insert-directory to an appropriate value, which
42 ;;; Author: Charlie Martin
43 ;;; Department of Computer Science and
44 ;;; National Biomedical Simulation Resource
46 ;;; Duke University Medical Center
48 ;;; (crm@cs.duke.edu,mcnc!duke!crm)
50 ;;; Date: Fri Jul 1 16:15:31 EDT 1988
52 (defvar auto-insert-alist
'(("\\.tex$" .
"tex-insert.tex")
53 ("\\.c$" .
"c-insert.c")
54 ("\\.h$" .
"h-insert.c")
55 ("[Mm]akefile" .
"makefile.inc")
56 ("\\.bib$" .
"tex-insert.tex"))
57 "A list specifying text to insert by default into a new file.
58 Elements look like (REGEXP . FILENAME); if the new file's name
59 matches REGEXP, then the file FILENAME is inserted into the buffer.
60 Only the first matching element is effective.")
62 ;;; Establish a default value for auto-insert-directory
63 (defvar auto-insert-directory
"~/insert/"
64 "*Directory from which auto-inserted files are taken.")
66 (defun insert-auto-insert-files ()
67 "Insert default contents into a new file.
68 Matches the visited file name against the elements of `auto-insert-alist'."
69 (let ((alist auto-insert-alist
)
70 ;; remove backup suffixes from file name
71 (name (file-name-sans-versions buffer-file-name
))
74 ;; find first matching alist entry
75 (while (and (not insert-file
) alist
)
76 (if (string-match (car (car alist
)) name
)
77 (setq insert-file
(cdr (car alist
)))
78 (setq alist
(cdr alist
))))
80 ;; Now, if we found an appropriate insert file, insert it
82 (let ((file (concat auto-insert-directory insert-file
)))
83 (if (file-readable-p file
)
85 (insert-file-contents file
)
86 (set-buffer-modified-p nil
))
87 (message "Auto-insert: file %s not found" file
)
90 ;; Make this feature take effect when a nonexistent file is visited.
91 (setq find-file-not-found-hooks
92 (cons 'insert-auto-insert-files
93 find-file-not-found-hooks
))
95 ;;; autoinsert.el ends here