Mercurial > emacs
annotate lisp/autoinsert.el @ 52605:50c6e94a91cb
(c-parse-state): Fixed bug that could cause errors when the state
cache contains info on parts that have been narrowed out.
(c-forward-keyword-clause): Fixed error handling. This bug could
cause interactive font locking to bail out.
(c-just-after-func-arglist-p): Handle paren-style types in Pike. Also
fixed some cases of insufficient handling of unbalanced parens.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Wed, 24 Sep 2003 13:55:23 +0000 |
parents | 695cf19ef79e |
children | 4728f7603f2a 375f2633d815 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
180
diff
changeset
|
1 ;;; autoinsert.el --- automatic mode-dependent insertion of text into new files |
14169 | 2 |
49024
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
3 ;; Copyright (C) 1985, 86, 87, 94, 95, 98, 2000, 03 Free Software Foundation, Inc. |
845 | 4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Author: Charlie Martin <crm@cs.duke.edu> |
23869 | 6 ;; Adapted-By: Daniel Pfeiffer <occitan@esperanto.org> |
22250
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21287
diff
changeset
|
7 ;; Keywords: convenience |
17976 | 8 ;; Maintainer: FSF |
180 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
180 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
180 | 26 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
27 ;;; Commentary: |
180 | 28 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
29 ;; The following defines an association list for text to be |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
30 ;; automatically inserted when a new file is created, and a function |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
31 ;; which automatically inserts these files; the idea is to insert |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
32 ;; default text much as the mode is automatically set using |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
33 ;; auto-mode-alist. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
34 ;; |
26661 | 35 ;; To use: |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
36 ;; (add-hook 'find-file-hooks 'auto-insert) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
37 ;; setq auto-insert-directory to an appropriate slash-terminated value |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
38 ;; |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
39 ;; You can also customize the variable `auto-insert-mode' to load the |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
40 ;; package. Alternatively, add the following to your .emacs file: |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
41 ;; (auto-insert-mode 1) |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
42 ;; |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
43 ;; Author: Charlie Martin |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
44 ;; Department of Computer Science and |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
45 ;; National Biomedical Simulation Resource |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
46 ;; Box 3709 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
47 ;; Duke University Medical Center |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
48 ;; Durham, NC 27710 |
26661 | 49 ;; (crm@cs.duke.edu,mcnc!duke!crm) |
180 | 50 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
51 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
52 |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
53 (defgroup auto-insert nil |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
54 "Automatic mode-dependent insertion of text into new files." |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
55 :prefix "auto-insert-" |
22250
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21287
diff
changeset
|
56 :group 'files |
a77d473867b8
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21287
diff
changeset
|
57 :group 'convenience) |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
58 |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
59 |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
60 (defcustom auto-insert 'not-modified |
26661 | 61 "*Controls automatic insertion into newly found empty files. |
62 Possible values: | |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
63 nil do nothing |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
64 t insert if possible |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
65 other insert if possible, but mark as unmodified. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
66 Insertion is possible when something appropriate is found in |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
67 `auto-insert-alist'. When the insertion is marked as unmodified, you can |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
68 save it with \\[write-file] RET. |
31878 | 69 This variable is used when the function `auto-insert' is called, e.g. |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
70 when you do (add-hook 'find-file-hooks 'auto-insert). |
26661 | 71 With \\[auto-insert], this is always treated as if it were t." |
21287
f61d91aef100
(auto-insert, auto-insert-query): :tag choices.
Dave Love <fx@gnu.org>
parents:
20809
diff
changeset
|
72 :type '(choice (const :tag "Insert if possible" t) |
f61d91aef100
(auto-insert, auto-insert-query): :tag choices.
Dave Love <fx@gnu.org>
parents:
20809
diff
changeset
|
73 (const :tag "Do nothing" nil) |
26661 | 74 (other :tag "insert if possible, mark as unmodified." |
21287
f61d91aef100
(auto-insert, auto-insert-query): :tag choices.
Dave Love <fx@gnu.org>
parents:
20809
diff
changeset
|
75 not-modified)) |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
76 :group 'auto-insert) |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
77 |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
78 (defcustom auto-insert-query 'function |
26661 | 79 "*Non-nil means ask user before auto-inserting. |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
80 When this is `function', only ask when called non-interactively." |
22567
b20af24c6cdd
(auto-insert, auto-insert-query): Use `other'
Andreas Schwab <schwab@suse.de>
parents:
22250
diff
changeset
|
81 :type '(choice (const :tag "Don't ask" nil) |
b20af24c6cdd
(auto-insert, auto-insert-query): Use `other'
Andreas Schwab <schwab@suse.de>
parents:
22250
diff
changeset
|
82 (const :tag "Ask if called non-interactively" function) |
b20af24c6cdd
(auto-insert, auto-insert-query): Use `other'
Andreas Schwab <schwab@suse.de>
parents:
22250
diff
changeset
|
83 (other :tag "Ask" t)) |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
84 :group 'auto-insert) |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
85 |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
86 (defcustom auto-insert-prompt "Perform %s auto-insertion? " |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
87 "*Prompt to use when querying whether to auto-insert. |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
88 If this contains a %s, that will be replaced by the matching rule." |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
89 :type 'string |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
90 :group 'auto-insert) |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
91 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
92 |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
93 (defcustom auto-insert-alist |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
94 '((("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . "C / C++ header") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
95 (upcase (concat (file-name-nondirectory |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
96 (substring buffer-file-name 0 (match-beginning 0))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
97 "_" |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
98 (substring buffer-file-name (1+ (match-beginning 0))))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
99 "#ifndef " str \n |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
100 "#define " str "\n\n" |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
101 _ "\n\n#endif") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
102 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
103 (("\\.\\([Cc]\\|cc\\|cpp\\)\\'" . "C / C++ program") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
104 nil |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
105 "#include \"" |
42161
18516f8e5cff
(auto-insert-alist): Redo finding C and C++ headers.
Richard M. Stallman <rms@gnu.org>
parents:
34380
diff
changeset
|
106 (let ((stem (file-name-sans-extension buffer-file-name))) |
18516f8e5cff
(auto-insert-alist): Redo finding C and C++ headers.
Richard M. Stallman <rms@gnu.org>
parents:
34380
diff
changeset
|
107 (cond ((file-exists-p (concat stem ".h")) |
18516f8e5cff
(auto-insert-alist): Redo finding C and C++ headers.
Richard M. Stallman <rms@gnu.org>
parents:
34380
diff
changeset
|
108 (file-name-nondirectory (concat stem ".h"))) |
18516f8e5cff
(auto-insert-alist): Redo finding C and C++ headers.
Richard M. Stallman <rms@gnu.org>
parents:
34380
diff
changeset
|
109 ((file-exists-p (concat stem ".hh")) |
18516f8e5cff
(auto-insert-alist): Redo finding C and C++ headers.
Richard M. Stallman <rms@gnu.org>
parents:
34380
diff
changeset
|
110 (file-name-nondirectory (concat stem ".hh"))))) |
18516f8e5cff
(auto-insert-alist): Redo finding C and C++ headers.
Richard M. Stallman <rms@gnu.org>
parents:
34380
diff
changeset
|
111 & ?\" | -10) |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
112 |
42161
18516f8e5cff
(auto-insert-alist): Redo finding C and C++ headers.
Richard M. Stallman <rms@gnu.org>
parents:
34380
diff
changeset
|
113 (("[Mm]akefile\\'" . "Makefile") . "makefile.inc") |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
114 |
14153
3e949d37e46f
(auto-insert-alist): For html-mode, use `sgml-tag'.
Richard M. Stallman <rms@gnu.org>
parents:
12502
diff
changeset
|
115 (html-mode . (lambda () (sgml-tag "html"))) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49024
diff
changeset
|
116 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
117 (plain-tex-mode . "tex-insert.tex") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
118 (bibtex-mode . "tex-insert.tex") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
119 (latex-mode |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
120 ;; should try to offer completing read for these |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
121 "options, RET: " |
33252
ffb346e61cf2
(auto-insert-alist) <latex-mode>: Use
Dave Love <fx@gnu.org>
parents:
33184
diff
changeset
|
122 "\\documentclass[" str & ?\] | -1 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
123 ?{ (read-string "class: ") "}\n" |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
124 ("package, %s: " |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
125 "\\usepackage[" (read-string "options, RET: ") & ?\] | -1 ?{ str "}\n") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
126 _ "\n\\begin{document}\n" _ |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
127 "\n\\end{document}") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
128 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
129 (("/bin/.*[^/]\\'" . "Shell-Script mode magic number") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
130 lambda () |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
131 (if (eq major-mode default-major-mode) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
132 (sh-mode))) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49024
diff
changeset
|
133 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
134 (ada-mode . ada-header) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
135 |
49024
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
136 (("\\.[1-9]\\'" . "Man page skeleton") |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
137 "Short description: " |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
138 ".\\\" Copyright (C), " (substring (current-time-string) -4) " " |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
139 (getenv "ORGANIZATION") | "Free Software Foundation, Inc." |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
140 " |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
141 .\\\" You may distribute this file under the terms of the GNU Free |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
142 .\\\" Documentation Licence. |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
143 .TH " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
144 " " (file-name-extension (buffer-file-name)) |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
145 " " (format-time-string "%Y-%m-%d ") |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
146 "\n.SH NAME\n" |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
147 (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
148 " \\- " str |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
149 "\n.SH SYNOPSIS |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
150 .B " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
151 "\n" |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
152 _ |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
153 " |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
154 .SH DESCRIPTION |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
155 .SH OPTIONS |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
156 .SH FILES |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
157 .SH \"SEE ALSO\" |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
158 .SH BUGS |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
159 .SH AUTHOR |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
160 " (user-full-name) |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
161 '(if (search-backward "&" (line-beginning-position) t) |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
162 (replace-match (capitalize (user-login-name)) t t)) |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
163 '(end-of-line 1) " <" (progn user-mail-address) ">\n") |
417bead90660
(auto-insert-alist): Add man page skeleton.
Dave Love <fx@gnu.org>
parents:
45025
diff
changeset
|
164 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
165 (("\\.el\\'" . "Emacs Lisp header") |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
166 "Short description: " |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
167 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str " |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
168 |
34380
45cb6948fefa
(auto-insert-alist): Add missing final \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33794
diff
changeset
|
169 ;; Copyright (C) " (substring (current-time-string) -4) " " |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
170 (getenv "ORGANIZATION") | "Free Software Foundation, Inc." " |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
171 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
172 ;; Author: " (user-full-name) |
31878 | 173 '(if (search-backward "&" (line-beginning-position) t) |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
174 (replace-match (capitalize (user-login-name)) t t)) |
23782
ffae9b995e65
(auto-insert-alist): Use user-mail-address.
Richard M. Stallman <rms@gnu.org>
parents:
23708
diff
changeset
|
175 '(end-of-line 1) " <" (progn user-mail-address) "> |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
176 ;; Keywords: " |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
177 '(require 'finder) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
178 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
179 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x)))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
180 finder-known-keywords) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
181 v2 (mapconcat (lambda (x) (format "%10.0s: %s" (car x) (cdr x))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
182 finder-known-keywords |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
183 "\n")) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
184 ((let ((minibuffer-help-form v2)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
185 (completing-read "Keyword, C-h: " v1 nil t)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
186 str ", ") & -2 " |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
187 |
23708
b91d56a036ef
(auto-insert-alist): Don't assume *.el is part of GNU Emacs.
Karl Heuer <kwzh@gnu.org>
parents:
22567
diff
changeset
|
188 ;; This file is free software; you can redistribute it and/or modify |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
189 ;; it under the terms of the GNU General Public License as published by |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
190 ;; the Free Software Foundation; either version 2, or (at your option) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
191 ;; any later version. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
192 |
23708
b91d56a036ef
(auto-insert-alist): Don't assume *.el is part of GNU Emacs.
Karl Heuer <kwzh@gnu.org>
parents:
22567
diff
changeset
|
193 ;; This file is distributed in the hope that it will be useful, |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
194 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
195 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
196 ;; GNU General Public License for more details. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
197 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
198 ;; You should have received a copy of the GNU General Public License |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
199 ;; along with GNU Emacs; see the file COPYING. If not, write to |
14181
aacf08497202
(auto-insert-alist): Use FSF's new address.
Erik Naggum <erik@naggum.no>
parents:
14169
diff
changeset
|
200 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
aacf08497202
(auto-insert-alist): Use FSF's new address.
Erik Naggum <erik@naggum.no>
parents:
14169
diff
changeset
|
201 ;; Boston, MA 02111-1307, USA. |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
202 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
203 ;;; Commentary: |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
204 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
205 ;; " _ " |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
206 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
207 ;;; Code: |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
208 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
209 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
210 |
33794
f35b09043a64
(auto-insert-alist): Add `provide' to elisp skeleton.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33252
diff
changeset
|
211 \(provide '" |
f35b09043a64
(auto-insert-alist): Add `provide' to elisp skeleton.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33252
diff
changeset
|
212 (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) |
f35b09043a64
(auto-insert-alist): Add `provide' to elisp skeleton.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33252
diff
changeset
|
213 ") |
34380
45cb6948fefa
(auto-insert-alist): Add missing final \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33794
diff
changeset
|
214 ;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")) |
180 | 215 "A list specifying text to insert by default into a new file. |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
216 Elements look like (CONDITION . ACTION) or ((CONDITION . DESCRIPTION) . ACTION). |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
217 CONDITION maybe a regexp that must match the new file's name, or it may be |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
218 a symbol that must match the major mode for this element to apply. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
219 Only the first matching element is effective. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
220 Optional DESCRIPTION is a string for filling `auto-insert-prompt'. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
221 ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
222 file-name or one relative to `auto-insert-directory' or a function to call. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
223 ACTION may also be a vector containing several successive single actions as |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
224 described above, e.g. [\"header.insert\" date-and-author-update]." |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
225 :type 'sexp |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
226 :group 'auto-insert) |
180 | 227 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
228 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
229 ;; Establish a default value for auto-insert-directory |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
230 (defcustom auto-insert-directory "~/insert/" |
44978
9b2201ff0db7
(auto-insert-directory): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
42161
diff
changeset
|
231 "*Directory from which auto-inserted files are taken. |
45025
b38fc6fb7a1a
(auto-insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
44984
diff
changeset
|
232 The value must be an absolute directory name; |
b38fc6fb7a1a
(auto-insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
44984
diff
changeset
|
233 thus, on a GNU or Unix system, it must end in a slash." |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
234 :type 'directory |
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
235 :group 'auto-insert) |
180 | 236 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
237 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
238 ;;;###autoload |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
239 (defun auto-insert () |
31878 | 240 "Insert default contents into new files if variable `auto-insert' is non-nil. |
180 | 241 Matches the visited file name against the elements of `auto-insert-alist'." |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
242 (interactive) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
243 (and (not buffer-read-only) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
244 (or (eq this-command 'auto-insert) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
245 (and auto-insert |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
246 (bobp) (eobp))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
247 (let ((alist auto-insert-alist) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
248 case-fold-search cond desc action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
249 (goto-char 1) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
250 ;; find first matching alist entry |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
251 (while alist |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
252 (if (atom (setq cond (car (car alist)))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
253 (setq desc cond) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
254 (setq desc (cdr cond) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
255 cond (car cond))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
256 (if (if (symbolp cond) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
257 (eq cond major-mode) |
31878 | 258 (and buffer-file-name |
259 (string-match cond buffer-file-name))) | |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
260 (setq action (cdr (car alist)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
261 alist nil) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
262 (setq alist (cdr alist)))) |
180 | 263 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
264 ;; Now, if we found something, do it |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
265 (and action |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
266 (if (stringp action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
267 (file-readable-p (concat auto-insert-directory action)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
268 t) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
269 (if auto-insert-query |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
270 (or (if (eq auto-insert-query 'function) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
271 (eq this-command 'auto-insert)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
272 (y-or-n-p (format auto-insert-prompt desc))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
273 t) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
274 (mapcar |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
275 (lambda (action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
276 (if (stringp action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
277 (if (file-readable-p |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
278 (setq action (concat auto-insert-directory action))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
279 (insert-file-contents action)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
280 (save-window-excursion |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
281 ;; make buffer visible before skeleton or function |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
282 ;; which might ask the user for something |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
283 (switch-to-buffer (current-buffer)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
284 (if (and (consp action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
285 (not (eq (car action) 'lambda))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
286 (skeleton-insert action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
287 (funcall action))))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
288 (if (vectorp action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
289 action |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
290 (vector action)))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
291 (and (buffer-modified-p) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
292 (not (eq this-command 'auto-insert)) |
26661 | 293 (set-buffer-modified-p (eq auto-insert t))))) |
294 ;; Return nil so that it could be used in | |
295 ;; `find-file-not-found-hooks', though that's probably inadvisable. | |
296 nil) | |
180 | 297 |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
298 |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
299 ;;;###autoload |
21287
f61d91aef100
(auto-insert, auto-insert-query): :tag choices.
Dave Love <fx@gnu.org>
parents:
20809
diff
changeset
|
300 (defun define-auto-insert (condition action &optional after) |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
301 "Associate CONDITION with (additional) ACTION in `auto-insert-alist'. |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
302 Optional AFTER means to insert action after all existing actions for CONDITION, |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
303 or if CONDITION had no actions, after all other CONDITIONs." |
21287
f61d91aef100
(auto-insert, auto-insert-query): :tag choices.
Dave Love <fx@gnu.org>
parents:
20809
diff
changeset
|
304 (let ((elt (assoc condition auto-insert-alist))) |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
305 (if elt |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
306 (setcdr elt |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
307 (if (vectorp (cdr elt)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
308 (vconcat (if after (cdr elt)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
309 (if (vectorp action) action (vector action)) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
310 (if after () (cdr elt))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
311 (if after |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
312 (vector (cdr elt) action) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
313 (vector action (cdr elt))))) |
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
314 (if after |
21287
f61d91aef100
(auto-insert, auto-insert-query): :tag choices.
Dave Love <fx@gnu.org>
parents:
20809
diff
changeset
|
315 (nconc auto-insert-alist (list (cons condition action))) |
f61d91aef100
(auto-insert, auto-insert-query): :tag choices.
Dave Love <fx@gnu.org>
parents:
20809
diff
changeset
|
316 (setq auto-insert-alist (cons (cons condition action) |
12502
8bb3424bf745
extended to use skeletons or call functions
Karl Heuer <kwzh@gnu.org>
parents:
8764
diff
changeset
|
317 auto-insert-alist)))))) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
180
diff
changeset
|
318 |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
319 ;;;###autoload |
32025
e67c88d8e5c4
(auto-insert-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31878
diff
changeset
|
320 (define-minor-mode auto-insert-mode |
26661 | 321 "Toggle Auto-insert mode. |
322 With prefix ARG, turn Auto-insert mode on if and only if ARG is positive. | |
323 Returns the new status of Auto-insert mode (non-nil means on). | |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
324 |
26661 | 325 When Auto-insert mode is enabled, when new files are created you can |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
326 insert a template for the file depending on the mode of the buffer." |
33184
8e6b63f3317d
(auto-insert-mode): Drop unneeded positional args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32025
diff
changeset
|
327 :global t :group 'auto-insert |
32025
e67c88d8e5c4
(auto-insert-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31878
diff
changeset
|
328 (if auto-insert-mode |
e67c88d8e5c4
(auto-insert-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31878
diff
changeset
|
329 (add-hook 'find-file-hooks 'auto-insert) |
e67c88d8e5c4
(auto-insert-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31878
diff
changeset
|
330 (remove-hook 'find-file-hooks 'auto-insert))) |
20809
c582e15d8cfc
(auto-insert-mode): New function.
Stephen Eglen <stephen@gnu.org>
parents:
18383
diff
changeset
|
331 |
18383 | 332 (provide 'autoinsert) |
333 | |
52401 | 334 ;;; arch-tag: 5b6630ac-c735-43cf-b097-b78c622af909 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
180
diff
changeset
|
335 ;;; autoinsert.el ends here |