Mercurial > emacs
comparison lisp/autoinsert.el @ 20809:c582e15d8cfc
(auto-insert-mode): New function.
(auto-insert-mode): New customize variable to automatically load
the package. Other variables customized.
author | Stephen Eglen <stephen@gnu.org> |
---|---|
date | Sun, 01 Feb 1998 19:13:59 +0000 |
parents | 11218164bc54 |
children | f61d91aef100 |
comparison
equal
deleted
inserted
replaced
20808:e1e1f6fd72bd | 20809:c582e15d8cfc |
---|---|
33 ;; | 33 ;; |
34 ;; To use: | 34 ;; To use: |
35 ;; (add-hook 'find-file-hooks 'auto-insert) | 35 ;; (add-hook 'find-file-hooks 'auto-insert) |
36 ;; setq auto-insert-directory to an appropriate slash-terminated value | 36 ;; setq auto-insert-directory to an appropriate slash-terminated value |
37 ;; | 37 ;; |
38 ;; You can also customize the variable `auto-insert-mode' to load the | |
39 ;; package. Alternatively, add the following to your .emacs file: | |
40 ;; (auto-insert-mode 1) | |
41 ;; | |
38 ;; Author: Charlie Martin | 42 ;; Author: Charlie Martin |
39 ;; Department of Computer Science and | 43 ;; Department of Computer Science and |
40 ;; National Biomedical Simulation Resource | 44 ;; National Biomedical Simulation Resource |
41 ;; Box 3709 | 45 ;; Box 3709 |
42 ;; Duke University Medical Center | 46 ;; Duke University Medical Center |
43 ;; Durham, NC 27710 | 47 ;; Durham, NC 27710 |
44 ;; (crm@cs.duke.edu,mcnc!duke!crm) | 48 ;; (crm@cs.duke.edu,mcnc!duke!crm) |
45 | 49 |
46 ;;; Code: | 50 ;;; Code: |
47 | 51 |
48 (defvar auto-insert 'not-modified | 52 (defgroup auto-insert nil |
53 "Automatic mode-dependent insertion of text into new files." | |
54 :prefix "auto-insert-" | |
55 :group 'files) | |
56 | |
57 | |
58 (defcustom auto-insert-mode nil | |
59 "Toggle auto-insert-mode. | |
60 You must modify via \\[customize] for this variable to have an effect." | |
61 :set (lambda (symbol value) | |
62 (auto-insert-mode (or value 0))) | |
63 :initialize 'custom-initialize-default | |
64 :type 'boolean | |
65 :group 'auto-insert | |
66 :require 'autoinsert) | |
67 | |
68 (defcustom auto-insert 'not-modified | |
49 "*Controls automatic insertion into newly found empty files: | 69 "*Controls automatic insertion into newly found empty files: |
50 nil do nothing | 70 nil do nothing |
51 t insert if possible | 71 t insert if possible |
52 other insert if possible, but mark as unmodified. | 72 other insert if possible, but mark as unmodified. |
53 Insertion is possible when something appropriate is found in | 73 Insertion is possible when something appropriate is found in |
54 `auto-insert-alist'. When the insertion is marked as unmodified, you can | 74 `auto-insert-alist'. When the insertion is marked as unmodified, you can |
55 save it with \\[write-file] RET. | 75 save it with \\[write-file] RET. |
56 This variable is used when `auto-insert' is called as a function, e.g. | 76 This variable is used when `auto-insert' is called as a function, e.g. |
57 when you do (add-hook 'find-file-hooks 'auto-insert). | 77 when you do (add-hook 'find-file-hooks 'auto-insert). |
58 With \\[auto-insert], this is always treated as if it were `t'.") | 78 With \\[auto-insert], this is always treated as if it were `t'." |
59 | 79 :type '(choice (const t) (const nil) (const not-modified)) |
60 | 80 :group 'auto-insert) |
61 (defvar auto-insert-query 'function | 81 |
82 (defcustom auto-insert-query 'function | |
62 "*If non-`nil', ask user before auto-inserting. | 83 "*If non-`nil', ask user before auto-inserting. |
63 When this is `function', only ask when called non-interactively.") | 84 When this is `function', only ask when called non-interactively." |
64 | 85 :type '(choice (const t) (const nil) (const function)) |
65 | 86 :group 'auto-insert) |
66 (defvar auto-insert-prompt "Perform %s auto-insertion? " | 87 |
88 (defcustom auto-insert-prompt "Perform %s auto-insertion? " | |
67 "*Prompt to use when querying whether to auto-insert. | 89 "*Prompt to use when querying whether to auto-insert. |
68 If this contains a %s, that will be replaced by the matching rule.") | 90 If this contains a %s, that will be replaced by the matching rule." |
69 | 91 :type 'string |
70 | 92 :group 'auto-insert) |
71 (defvar auto-insert-alist | 93 |
94 | |
95 (defcustom auto-insert-alist | |
72 '((("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . "C / C++ header") | 96 '((("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . "C / C++ header") |
73 (upcase (concat (file-name-nondirectory | 97 (upcase (concat (file-name-nondirectory |
74 (substring buffer-file-name 0 (match-beginning 0))) | 98 (substring buffer-file-name 0 (match-beginning 0))) |
75 "_" | 99 "_" |
76 (substring buffer-file-name (1+ (match-beginning 0))))) | 100 (substring buffer-file-name (1+ (match-beginning 0))))) |
166 Only the first matching element is effective. | 190 Only the first matching element is effective. |
167 Optional DESCRIPTION is a string for filling `auto-insert-prompt'. | 191 Optional DESCRIPTION is a string for filling `auto-insert-prompt'. |
168 ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute | 192 ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute |
169 file-name or one relative to `auto-insert-directory' or a function to call. | 193 file-name or one relative to `auto-insert-directory' or a function to call. |
170 ACTION may also be a vector containing several successive single actions as | 194 ACTION may also be a vector containing several successive single actions as |
171 described above, e.g. [\"header.insert\" date-and-author-update].") | 195 described above, e.g. [\"header.insert\" date-and-author-update]." |
196 :type 'sexp | |
197 :group 'auto-insert) | |
172 | 198 |
173 | 199 |
174 ;; Establish a default value for auto-insert-directory | 200 ;; Establish a default value for auto-insert-directory |
175 (defvar auto-insert-directory "~/insert/" | 201 (defcustom auto-insert-directory "~/insert/" |
176 "*Directory from which auto-inserted files are taken.") | 202 "*Directory from which auto-inserted files are taken." |
203 :type 'directory | |
204 :group 'auto-insert) | |
177 | 205 |
178 | 206 |
179 ;;;###autoload | 207 ;;;###autoload |
180 (defun auto-insert () | 208 (defun auto-insert () |
181 "Insert default contents into a new file if `auto-insert' is non-nil. | 209 "Insert default contents into a new file if `auto-insert' is non-nil. |
251 (if after | 279 (if after |
252 (nconc auto-insert-alist (list (cons key action))) | 280 (nconc auto-insert-alist (list (cons key action))) |
253 (setq auto-insert-alist (cons (cons key action) | 281 (setq auto-insert-alist (cons (cons key action) |
254 auto-insert-alist)))))) | 282 auto-insert-alist)))))) |
255 | 283 |
284 ;;;###autoload | |
285 (defun auto-insert-mode (&optional arg) | |
286 "Toggle auto-insert mode. | |
287 With prefix ARG, turn auto-insert mode on if and only if ARG is positive. | |
288 Returns the new status of auto-insert mode (non-nil means on). | |
289 | |
290 When auto-insert mode is enabled, when new files are created you can | |
291 insert a template for the file depending on the mode of the buffer." | |
292 (interactive "P") | |
293 (let ((on-p (if arg | |
294 (> (prefix-numeric-value arg) 0) | |
295 (not auto-insert-mode)))) | |
296 (if on-p | |
297 (add-hook 'find-file-hooks 'auto-insert) | |
298 (remove-hook 'find-file-hooks 'auto-insert)) | |
299 (if (interactive-p) | |
300 (message "Auto-insert now %s." (if on-p "on" "off"))) | |
301 (setq auto-insert-mode on-p) | |
302 )) | |
303 | |
304 (if auto-insert-mode | |
305 (auto-insert-mode 1)) | |
306 | |
256 (provide 'autoinsert) | 307 (provide 'autoinsert) |
257 | 308 |
258 ;;; autoinsert.el ends here | 309 ;;; autoinsert.el ends here |