Annotation of 43BSDReno/contrib/emacs-18.55/lisp/autoinsert.el, revision 1.1.1.1

1.1       root        1: ;; Automatic mode-dependent insertion of text into new files.
                      2: ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
                      3: 
                      4: ;; This file is part of GNU Emacs.
                      5: 
                      6: ;; GNU Emacs is distributed in the hope that it will be useful,
                      7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      8: ;; accepts responsibility to anyone for the consequences of using it
                      9: ;; or for whether it serves any particular purpose or works at all,
                     10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     11: ;; License for full details.
                     12: 
                     13: ;; Everyone is granted permission to copy, modify and redistribute
                     14: ;; GNU Emacs, but only under the conditions described in the
                     15: ;; GNU Emacs General Public License.   A copy of this license is
                     16: ;; supposed to have been given to you along with GNU Emacs so you
                     17: ;; can know your rights and responsibilities.  It should be in a
                     18: ;; file named COPYING.  Among other things, the copyright notice
                     19: ;; and this notice must be preserved on all copies.
                     20: 
                     21: ;;; autoinsert.el
                     22: 
                     23: ;;;  Abstract:
                     24: ;;;
                     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
                     29: ;;;  auto-mode-alist.
                     30: ;;;
                     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
                     35: ;;;  paired.
                     36: ;;;
                     37: ;;;  To use: 
                     38: ;;;     load autoinsert.el
                     39: ;;;     setq auto-insert-directory to an appropriate value, which
                     40: ;;;       must end in "/"
                     41: ;;;
                     42: ;;;  Author:  Charlie Martin
                     43: ;;;           Department of Computer Science and
                     44: ;;;           National Biomedical Simulation Resource
                     45: ;;;           Box 3709
                     46: ;;;           Duke University Medical Center
                     47: ;;;           Durham, NC 27710
                     48: ;;;          ([email protected],mcnc!duke!crm) 
                     49: ;;;
                     50: ;;;  Date: Fri Jul  1 16:15:31 EDT 1988
                     51: 
                     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:   "Alist 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.")
                     61: 
                     62: ;;; Establish a default value for auto-insert-directory
                     63: (defvar auto-insert-directory "~/insert/"
                     64:   "Directory from which auto-inserted files are taken.")
                     65: 
                     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))
                     72:         (insert-file nil))
                     73: 
                     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))))
                     79: 
                     80:     ;; Now, if we found an appropriate insert file, insert it
                     81:     (if insert-file
                     82:         (let ((file (concat auto-insert-directory insert-file)))
                     83:           (if (file-readable-p file)
                     84:               (insert-file-contents file)
                     85:             (message "Auto-insert: file %s not found" file)
                     86:            (sleep-for 1))))))
                     87: 
                     88: ;; Make this feature take effect when a nonexistent file is visited.
                     89: (setq find-file-not-found-hooks
                     90:       (cons 'insert-auto-insert-files
                     91:            find-file-not-found-hooks))

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.