Mercurial > emacs
comparison lisp/autoinsert.el @ 26661:a3246f443a38
Minor doc fixes.
(auto-insert): Return nil.
author | Dave Love <fx@gnu.org> |
---|---|
date | Tue, 30 Nov 1999 14:45:39 +0000 |
parents | 39d56f4cc4fd |
children | 6731a720a7a1 |
comparison
equal
deleted
inserted
replaced
26660:4a90f5041fd2 | 26661:a3246f443a38 |
---|---|
30 ;; automatically inserted when a new file is created, and a function | 30 ;; automatically inserted when a new file is created, and a function |
31 ;; which automatically inserts these files; the idea is to insert | 31 ;; which automatically inserts these files; the idea is to insert |
32 ;; default text much as the mode is automatically set using | 32 ;; default text much as the mode is automatically set using |
33 ;; auto-mode-alist. | 33 ;; auto-mode-alist. |
34 ;; | 34 ;; |
35 ;; To use: | 35 ;; To use: |
36 ;; (add-hook 'find-file-hooks 'auto-insert) | 36 ;; (add-hook 'find-file-hooks 'auto-insert) |
37 ;; setq auto-insert-directory to an appropriate slash-terminated value | 37 ;; setq auto-insert-directory to an appropriate slash-terminated value |
38 ;; | 38 ;; |
39 ;; You can also customize the variable `auto-insert-mode' to load the | 39 ;; You can also customize the variable `auto-insert-mode' to load the |
40 ;; package. Alternatively, add the following to your .emacs file: | 40 ;; package. Alternatively, add the following to your .emacs file: |
44 ;; Department of Computer Science and | 44 ;; Department of Computer Science and |
45 ;; National Biomedical Simulation Resource | 45 ;; National Biomedical Simulation Resource |
46 ;; Box 3709 | 46 ;; Box 3709 |
47 ;; Duke University Medical Center | 47 ;; Duke University Medical Center |
48 ;; Durham, NC 27710 | 48 ;; Durham, NC 27710 |
49 ;; (crm@cs.duke.edu,mcnc!duke!crm) | 49 ;; (crm@cs.duke.edu,mcnc!duke!crm) |
50 | 50 |
51 ;;; Code: | 51 ;;; Code: |
52 | 52 |
53 (defgroup auto-insert nil | 53 (defgroup auto-insert nil |
54 "Automatic mode-dependent insertion of text into new files." | 54 "Automatic mode-dependent insertion of text into new files." |
56 :group 'files | 56 :group 'files |
57 :group 'convenience) | 57 :group 'convenience) |
58 | 58 |
59 | 59 |
60 (defcustom auto-insert-mode nil | 60 (defcustom auto-insert-mode nil |
61 "Toggle auto-insert-mode. | 61 "Toggle Auto-insert mode. |
62 Setting this variable directly does not take effect; | 62 Setting this variable directly does not take effect; |
63 use either \\[customize] or the function `auto-insert-mode'." | 63 use either \\[customize] or the function `auto-insert-mode'." |
64 :set (lambda (symbol value) | 64 :set (lambda (symbol value) |
65 (auto-insert-mode (or value 0))) | 65 (auto-insert-mode (or value 0))) |
66 :initialize 'custom-initialize-default | 66 :initialize 'custom-initialize-default |
67 :type 'boolean | 67 :type 'boolean |
68 :group 'auto-insert | 68 :group 'auto-insert |
69 :require 'autoinsert) | 69 :require 'autoinsert) |
70 | 70 |
71 (defcustom auto-insert 'not-modified | 71 (defcustom auto-insert 'not-modified |
72 "*Controls automatic insertion into newly found empty files: | 72 "*Controls automatic insertion into newly found empty files. |
73 Possible values: | |
73 nil do nothing | 74 nil do nothing |
74 t insert if possible | 75 t insert if possible |
75 other insert if possible, but mark as unmodified. | 76 other insert if possible, but mark as unmodified. |
76 Insertion is possible when something appropriate is found in | 77 Insertion is possible when something appropriate is found in |
77 `auto-insert-alist'. When the insertion is marked as unmodified, you can | 78 `auto-insert-alist'. When the insertion is marked as unmodified, you can |
78 save it with \\[write-file] RET. | 79 save it with \\[write-file] RET. |
79 This variable is used when `auto-insert' is called as a function, e.g. | 80 This variable is used when `auto-insert' is called as a function, e.g. |
80 when you do (add-hook 'find-file-hooks 'auto-insert). | 81 when you do (add-hook 'find-file-hooks 'auto-insert). |
81 With \\[auto-insert], this is always treated as if it were `t'." | 82 With \\[auto-insert], this is always treated as if it were t." |
82 :type '(choice (const :tag "Insert if possible" t) | 83 :type '(choice (const :tag "Insert if possible" t) |
83 (const :tag "Do nothing" nil) | 84 (const :tag "Do nothing" nil) |
84 (other :tag "insert if possible, mark as unmodified." | 85 (other :tag "insert if possible, mark as unmodified." |
85 not-modified)) | 86 not-modified)) |
86 :group 'auto-insert) | 87 :group 'auto-insert) |
87 | 88 |
88 (defcustom auto-insert-query 'function | 89 (defcustom auto-insert-query 'function |
89 "*If non-`nil', ask user before auto-inserting. | 90 "*Non-nil means ask user before auto-inserting. |
90 When this is `function', only ask when called non-interactively." | 91 When this is `function', only ask when called non-interactively." |
91 :type '(choice (const :tag "Don't ask" nil) | 92 :type '(choice (const :tag "Don't ask" nil) |
92 (const :tag "Ask if called non-interactively" function) | 93 (const :tag "Ask if called non-interactively" function) |
93 (other :tag "Ask" t)) | 94 (other :tag "Ask" t)) |
94 :group 'auto-insert) | 95 :group 'auto-insert) |
262 (if (vectorp action) | 263 (if (vectorp action) |
263 action | 264 action |
264 (vector action)))) | 265 (vector action)))) |
265 (and (buffer-modified-p) | 266 (and (buffer-modified-p) |
266 (not (eq this-command 'auto-insert)) | 267 (not (eq this-command 'auto-insert)) |
267 (set-buffer-modified-p (eq auto-insert t)))))) | 268 (set-buffer-modified-p (eq auto-insert t))))) |
269 ;; Return nil so that it could be used in | |
270 ;; `find-file-not-found-hooks', though that's probably inadvisable. | |
271 nil) | |
268 | 272 |
269 | 273 |
270 ;;;###autoload | 274 ;;;###autoload |
271 (defun define-auto-insert (condition action &optional after) | 275 (defun define-auto-insert (condition action &optional after) |
272 "Associate CONDITION with (additional) ACTION in `auto-insert-alist'. | 276 "Associate CONDITION with (additional) ACTION in `auto-insert-alist'. |
287 (setq auto-insert-alist (cons (cons condition action) | 291 (setq auto-insert-alist (cons (cons condition action) |
288 auto-insert-alist)))))) | 292 auto-insert-alist)))))) |
289 | 293 |
290 ;;;###autoload | 294 ;;;###autoload |
291 (defun auto-insert-mode (&optional arg) | 295 (defun auto-insert-mode (&optional arg) |
292 "Toggle auto-insert mode. | 296 "Toggle Auto-insert mode. |
293 With prefix ARG, turn auto-insert mode on if and only if ARG is positive. | 297 With prefix ARG, turn Auto-insert mode on if and only if ARG is positive. |
294 Returns the new status of auto-insert mode (non-nil means on). | 298 Returns the new status of Auto-insert mode (non-nil means on). |
295 | 299 |
296 When auto-insert mode is enabled, when new files are created you can | 300 When Auto-insert mode is enabled, when new files are created you can |
297 insert a template for the file depending on the mode of the buffer." | 301 insert a template for the file depending on the mode of the buffer." |
298 (interactive "P") | 302 (interactive "P") |
299 (let ((on-p (if arg | 303 (let ((on-p (if arg |
300 (> (prefix-numeric-value arg) 0) | 304 (> (prefix-numeric-value arg) 0) |
301 (not auto-insert-mode)))) | 305 (not auto-insert-mode)))) |
302 (if on-p | 306 (if on-p |
303 (add-hook 'find-file-hooks 'auto-insert) | 307 (add-hook 'find-file-hooks 'auto-insert) |
304 (remove-hook 'find-file-hooks 'auto-insert)) | 308 (remove-hook 'find-file-hooks 'auto-insert)) |
305 (if (interactive-p) | 309 (if (interactive-p) |
306 (message "Auto-insert now %s." (if on-p "on" "off"))) | 310 (message "Auto-insert now %s." (if on-p "on" "off"))) |
307 (setq auto-insert-mode on-p) | 311 (setq auto-insert-mode on-p))) |
308 )) | |
309 | 312 |
310 (if auto-insert-mode | 313 (if auto-insert-mode |
311 (auto-insert-mode 1)) | 314 (auto-insert-mode 1)) |
312 | 315 |
313 (provide 'autoinsert) | 316 (provide 'autoinsert) |