annotate man/autotype.texi @ 26070:c83405930bcb

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Mon, 18 Oct 1999 02:01:56 +0000
parents 7094579127c8
children 983ad33e1d97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25848
Dave Love <fx@gnu.org>
parents:
diff changeset
1 @c This is part of the Emacs manual.
Dave Love <fx@gnu.org>
parents:
diff changeset
2 @c Copyright (C) 1994, 1995 Free Software Foundation, Inc.
Dave Love <fx@gnu.org>
parents:
diff changeset
3 @c Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
Dave Love <fx@gnu.org>
parents:
diff changeset
4 @c See file emacs.texi for copying conditions.
Dave Love <fx@gnu.org>
parents:
diff changeset
5 @node Autotypist, Picture, Abbrevs, Top
Dave Love <fx@gnu.org>
parents:
diff changeset
6 @chapter Features for Automatic Typing
Dave Love <fx@gnu.org>
parents:
diff changeset
7 @cindex text
Dave Love <fx@gnu.org>
parents:
diff changeset
8 @cindex selfinserting text
Dave Love <fx@gnu.org>
parents:
diff changeset
9 @cindex autotypist
Dave Love <fx@gnu.org>
parents:
diff changeset
10
Dave Love <fx@gnu.org>
parents:
diff changeset
11 @dircategory Editors
Dave Love <fx@gnu.org>
parents:
diff changeset
12 @direntry
Dave Love <fx@gnu.org>
parents:
diff changeset
13 * Autotype: (autotype). Convenient features for text that you enter frequently
Dave Love <fx@gnu.org>
parents:
diff changeset
14 in Emacs.
Dave Love <fx@gnu.org>
parents:
diff changeset
15 @end direntry
Dave Love <fx@gnu.org>
parents:
diff changeset
16
Dave Love <fx@gnu.org>
parents:
diff changeset
17 Under certain circumstances you will find yourself typing similar things
Dave Love <fx@gnu.org>
parents:
diff changeset
18 over and over again. This is especially true of form letters and programming
Dave Love <fx@gnu.org>
parents:
diff changeset
19 language constructs. Project-specific header comments, flow-control
Dave Love <fx@gnu.org>
parents:
diff changeset
20 constructs or magic numbers are essentially the same every time. Emacs has
Dave Love <fx@gnu.org>
parents:
diff changeset
21 various features for doing tedious and repetitive typing chores for you.
Dave Love <fx@gnu.org>
parents:
diff changeset
22
Dave Love <fx@gnu.org>
parents:
diff changeset
23 One solution is using skeletons, flexible rules that say what to
Dave Love <fx@gnu.org>
parents:
diff changeset
24 insert, and how to do it. Various programming language modes offer some
Dave Love <fx@gnu.org>
parents:
diff changeset
25 ready-to-use skeletons, and you can adapt them to suit your needs or
Dave Love <fx@gnu.org>
parents:
diff changeset
26 taste, or define new ones.
Dave Love <fx@gnu.org>
parents:
diff changeset
27
Dave Love <fx@gnu.org>
parents:
diff changeset
28 Another feature is automatic insertion of what you want into empty files,
Dave Love <fx@gnu.org>
parents:
diff changeset
29 depending on the file-name or the mode as appropriate. You can have a file or
Dave Love <fx@gnu.org>
parents:
diff changeset
30 a skeleton inserted, or you can call a function. Then there is the
Dave Love <fx@gnu.org>
parents:
diff changeset
31 possibility to have Un*x interpreter scripts automatically take on a magic
Dave Love <fx@gnu.org>
parents:
diff changeset
32 number and be executable as soon as they are saved. Or you can have a
Dave Love <fx@gnu.org>
parents:
diff changeset
33 copyright notice's year updated, if necessary, every time you save a file.
Dave Love <fx@gnu.org>
parents:
diff changeset
34
Dave Love <fx@gnu.org>
parents:
diff changeset
35 @menu
Dave Love <fx@gnu.org>
parents:
diff changeset
36 * Using Skeletons:: How to insert a skeleton into your text.
Dave Love <fx@gnu.org>
parents:
diff changeset
37 * Wrapping Skeletons:: Putting existing text within a skeleton.
Dave Love <fx@gnu.org>
parents:
diff changeset
38 * Skeletons as Abbrevs:: An alternative for issuing skeleton commands.
Dave Love <fx@gnu.org>
parents:
diff changeset
39 * Skeleton Language:: Making skeleton commands insert what you want.
Dave Love <fx@gnu.org>
parents:
diff changeset
40 * Inserting Pairs:: Typing one character and getting another after point.
Dave Love <fx@gnu.org>
parents:
diff changeset
41 * Autoinserting:: Filling up empty files as soon as you visit them.
Dave Love <fx@gnu.org>
parents:
diff changeset
42 * Copyrights:: Inserting and updating copyrights.
Dave Love <fx@gnu.org>
parents:
diff changeset
43 * Executables:: Turning interpreter scripts into executables.
Dave Love <fx@gnu.org>
parents:
diff changeset
44 @end menu
Dave Love <fx@gnu.org>
parents:
diff changeset
45
Dave Love <fx@gnu.org>
parents:
diff changeset
46
Dave Love <fx@gnu.org>
parents:
diff changeset
47
Dave Love <fx@gnu.org>
parents:
diff changeset
48 @node Using Skeletons
Dave Love <fx@gnu.org>
parents:
diff changeset
49 @section Using Skeletons
Dave Love <fx@gnu.org>
parents:
diff changeset
50 @cindex skeletons
Dave Love <fx@gnu.org>
parents:
diff changeset
51 @cindex using skeletons
Dave Love <fx@gnu.org>
parents:
diff changeset
52
Dave Love <fx@gnu.org>
parents:
diff changeset
53 When you want Emacs to insert a form letter or a typical construct of the
Dave Love <fx@gnu.org>
parents:
diff changeset
54 programming language you are using, skeletons are a means of accomplishing
Dave Love <fx@gnu.org>
parents:
diff changeset
55 this. Normally skeletons each have a command of their own, that, when called,
Dave Love <fx@gnu.org>
parents:
diff changeset
56 will insert the skeleton. These commands can be issued in the usual ways
Dave Love <fx@gnu.org>
parents:
diff changeset
57 (@xref{Commands}). Modes that offer various skeletons will often bind these
Dave Love <fx@gnu.org>
parents:
diff changeset
58 to key-sequences on the @kbd{C-c} prefix, as well as having an @cite{Insert}
Dave Love <fx@gnu.org>
parents:
diff changeset
59 menu and maybe even predefined abbrevs for them (@xref{Skeletons as Abbrevs}).
Dave Love <fx@gnu.org>
parents:
diff changeset
60
Dave Love <fx@gnu.org>
parents:
diff changeset
61 The simplest kind of skeleton will simply insert some text indented
Dave Love <fx@gnu.org>
parents:
diff changeset
62 according to the major mode and leave the cursor at a likely place in the
Dave Love <fx@gnu.org>
parents:
diff changeset
63 middle. Interactive skeletons may prompt you for a string that will be part
Dave Love <fx@gnu.org>
parents:
diff changeset
64 of the inserted text.
Dave Love <fx@gnu.org>
parents:
diff changeset
65
Dave Love <fx@gnu.org>
parents:
diff changeset
66 Skeletons may ask for input several times. They even have a looping
Dave Love <fx@gnu.org>
parents:
diff changeset
67 mechanism in which you will be asked for input as long as you are willing to
Dave Love <fx@gnu.org>
parents:
diff changeset
68 furnish it. An example would be multiple ``else if'' conditions. You can
Dave Love <fx@gnu.org>
parents:
diff changeset
69 recognize this situation by a prompt ending in ``RET, C-g or C-h''. This
Dave Love <fx@gnu.org>
parents:
diff changeset
70 means that entering an empty string will simply assume that you are finished.
Dave Love <fx@gnu.org>
parents:
diff changeset
71 Typing quit on the other hand terminates the loop but also the rest of the
Dave Love <fx@gnu.org>
parents:
diff changeset
72 skeleton, e.g. an ``else'' clause is skipped. Only a syntactically necessary
Dave Love <fx@gnu.org>
parents:
diff changeset
73 termination still gets inserted.
Dave Love <fx@gnu.org>
parents:
diff changeset
74
Dave Love <fx@gnu.org>
parents:
diff changeset
75
Dave Love <fx@gnu.org>
parents:
diff changeset
76
Dave Love <fx@gnu.org>
parents:
diff changeset
77 @node Wrapping Skeletons
Dave Love <fx@gnu.org>
parents:
diff changeset
78 @section Wrapping Skeletons Around Existing Test
Dave Love <fx@gnu.org>
parents:
diff changeset
79 @cindex wrapping skeletons
Dave Love <fx@gnu.org>
parents:
diff changeset
80
Dave Love <fx@gnu.org>
parents:
diff changeset
81 Often you will find yourself with some code that for whatever reason
Dave Love <fx@gnu.org>
parents:
diff changeset
82 suddenly becomes conditional. Or you have written a bit of text and want to
Dave Love <fx@gnu.org>
parents:
diff changeset
83 put it in the middle of a form letter. Skeletons provide a means for
Dave Love <fx@gnu.org>
parents:
diff changeset
84 accomplishing this, and can even, in the case of programming languages,
Dave Love <fx@gnu.org>
parents:
diff changeset
85 reindent the wrapped code for you.
Dave Love <fx@gnu.org>
parents:
diff changeset
86
Dave Love <fx@gnu.org>
parents:
diff changeset
87 Skeleton commands take an optional numeric prefix argument
Dave Love <fx@gnu.org>
parents:
diff changeset
88 (@xref{Arguments}). This is interpreted in two different ways depending
Dave Love <fx@gnu.org>
parents:
diff changeset
89 on whether the prefix is positive, i.e. forwards oriented or negative,
Dave Love <fx@gnu.org>
parents:
diff changeset
90 i.e. backwards oriented.
Dave Love <fx@gnu.org>
parents:
diff changeset
91
Dave Love <fx@gnu.org>
parents:
diff changeset
92 A positive prefix means to wrap the skeleton around that many following
Dave Love <fx@gnu.org>
parents:
diff changeset
93 words. This is accomplished by putting the words there where the point is
Dave Love <fx@gnu.org>
parents:
diff changeset
94 normally left after that skeleton is inserted (@xref{Using Skeletons}). The
Dave Love <fx@gnu.org>
parents:
diff changeset
95 point (@xref{Point}) is left at the next interesting spot in the skeleton
Dave Love <fx@gnu.org>
parents:
diff changeset
96 instead.
Dave Love <fx@gnu.org>
parents:
diff changeset
97
Dave Love <fx@gnu.org>
parents:
diff changeset
98 A negative prefix means to do something similar with that many precedingly
Dave Love <fx@gnu.org>
parents:
diff changeset
99 marked interregions (@xref{Mark}). In the simplest case, if you type
Dave Love <fx@gnu.org>
parents:
diff changeset
100 @kbd{M--} just before issuing the skeleton command, that will wrap the
Dave Love <fx@gnu.org>
parents:
diff changeset
101 skeleton around the current region, just like a positive argument would have
Dave Love <fx@gnu.org>
parents:
diff changeset
102 wrapped it around a number of words.
Dave Love <fx@gnu.org>
parents:
diff changeset
103
Dave Love <fx@gnu.org>
parents:
diff changeset
104 Smaller negative arguments will wrap that many interregions into successive
Dave Love <fx@gnu.org>
parents:
diff changeset
105 interesting spots within the skeleton, again leaving the point at the next one.
Dave Love <fx@gnu.org>
parents:
diff changeset
106 We speak about interregions rather than regions here, because we treat them in
Dave Love <fx@gnu.org>
parents:
diff changeset
107 the order they appear in the buffer, which coincides with successive regions
Dave Love <fx@gnu.org>
parents:
diff changeset
108 only if they were marked in order.
Dave Love <fx@gnu.org>
parents:
diff changeset
109
Dave Love <fx@gnu.org>
parents:
diff changeset
110 That is, if you marked in alphabetical order the points A B C [] (where []
Dave Love <fx@gnu.org>
parents:
diff changeset
111 represents the point) and call a skeleton command with @kbd{M-- 3}, you will
Dave Love <fx@gnu.org>
parents:
diff changeset
112 wrap the text from A to B into the first interesting spot of the skeleton, the
Dave Love <fx@gnu.org>
parents:
diff changeset
113 text from B to C into the next one, the text from C to the point into the
Dave Love <fx@gnu.org>
parents:
diff changeset
114 third one, and leave the point in the fourth one. If there are less marks in
Dave Love <fx@gnu.org>
parents:
diff changeset
115 the buffer, or if the skeleton defines less interesting points, the surplus is
Dave Love <fx@gnu.org>
parents:
diff changeset
116 ignored.
Dave Love <fx@gnu.org>
parents:
diff changeset
117
Dave Love <fx@gnu.org>
parents:
diff changeset
118 If, on the other hand, you marked in alphabetical order the points [] A C B,
Dave Love <fx@gnu.org>
parents:
diff changeset
119 and call a skeleton command with @kbd{M-- 3}, you will wrap the text from
Dave Love <fx@gnu.org>
parents:
diff changeset
120 point to A, then the text from A to C and finally the text from C to B. This
Dave Love <fx@gnu.org>
parents:
diff changeset
121 is done because the regions overlap and Emacs would be helplessly lost if it
Dave Love <fx@gnu.org>
parents:
diff changeset
122 tried to follow the order in which you marked these points.
Dave Love <fx@gnu.org>
parents:
diff changeset
123
Dave Love <fx@gnu.org>
parents:
diff changeset
124
Dave Love <fx@gnu.org>
parents:
diff changeset
125
Dave Love <fx@gnu.org>
parents:
diff changeset
126 @node Skeletons as Abbrevs
Dave Love <fx@gnu.org>
parents:
diff changeset
127 @section Skeletons as Abbrev Expansions
Dave Love <fx@gnu.org>
parents:
diff changeset
128 @cindex skeletons as abbrevs
Dave Love <fx@gnu.org>
parents:
diff changeset
129
Dave Love <fx@gnu.org>
parents:
diff changeset
130 Rather than use a keybinding for every skeleton command, you can also define
Dave Love <fx@gnu.org>
parents:
diff changeset
131 an abbreviation (@xref{Defining Abbrevs}) that will expand (@xref{Expanding
Dave Love <fx@gnu.org>
parents:
diff changeset
132 Abbrevs}) into the skeleton.
Dave Love <fx@gnu.org>
parents:
diff changeset
133
Dave Love <fx@gnu.org>
parents:
diff changeset
134 Say you want @samp{ifst} to be an abbreviation for the C language if
Dave Love <fx@gnu.org>
parents:
diff changeset
135 statement. You will tell Emacs that @samp{ifst} expands to the empty string
Dave Love <fx@gnu.org>
parents:
diff changeset
136 and then calls the skeleton command. In Emacs-lisp you can say something like
Dave Love <fx@gnu.org>
parents:
diff changeset
137 @code{(define-abbrev c-mode-abbrev-table "ifst" "" 'c-if)}. Or you can edit
Dave Love <fx@gnu.org>
parents:
diff changeset
138 the output from @kbd{M-x list-abbrevs} to make it look like this:
Dave Love <fx@gnu.org>
parents:
diff changeset
139
Dave Love <fx@gnu.org>
parents:
diff changeset
140 @example
Dave Love <fx@gnu.org>
parents:
diff changeset
141 (c-mode-abbrev-table)
Dave Love <fx@gnu.org>
parents:
diff changeset
142 "if" 0 "" c-if
Dave Love <fx@gnu.org>
parents:
diff changeset
143 @end example
Dave Love <fx@gnu.org>
parents:
diff changeset
144
Dave Love <fx@gnu.org>
parents:
diff changeset
145 @noindent
Dave Love <fx@gnu.org>
parents:
diff changeset
146 (Some blank lines of no semantic significance, and other abbrev tables,
Dave Love <fx@gnu.org>
parents:
diff changeset
147 have been omitted.)
Dave Love <fx@gnu.org>
parents:
diff changeset
148
Dave Love <fx@gnu.org>
parents:
diff changeset
149
Dave Love <fx@gnu.org>
parents:
diff changeset
150
Dave Love <fx@gnu.org>
parents:
diff changeset
151 @node Skeleton Language
Dave Love <fx@gnu.org>
parents:
diff changeset
152 @section Skeleton Language
Dave Love <fx@gnu.org>
parents:
diff changeset
153 @cindex skeleton language
Dave Love <fx@gnu.org>
parents:
diff changeset
154
Dave Love <fx@gnu.org>
parents:
diff changeset
155 @findex skeleton-insert
Dave Love <fx@gnu.org>
parents:
diff changeset
156 Skeletons are an shorthand extension to the Lisp language, where various
Dave Love <fx@gnu.org>
parents:
diff changeset
157 atoms directly perform either actions on the current buffer or rudimentary
Dave Love <fx@gnu.org>
parents:
diff changeset
158 flow control mechanisms. Skeletons are interpreted by the function
Dave Love <fx@gnu.org>
parents:
diff changeset
159 @code{skeleton-insert}.
Dave Love <fx@gnu.org>
parents:
diff changeset
160
Dave Love <fx@gnu.org>
parents:
diff changeset
161 A skeleton is a list starting with an interactor, which is usually a
Dave Love <fx@gnu.org>
parents:
diff changeset
162 prompt-string, or @code{nil} when not needed, but can also be a Lisp
Dave Love <fx@gnu.org>
parents:
diff changeset
163 expression for complex read functions or for returning some calculated value.
Dave Love <fx@gnu.org>
parents:
diff changeset
164 The rest of the list are any number of elements as described in the following
Dave Love <fx@gnu.org>
parents:
diff changeset
165 table:
Dave Love <fx@gnu.org>
parents:
diff changeset
166
Dave Love <fx@gnu.org>
parents:
diff changeset
167 @table @code
Dave Love <fx@gnu.org>
parents:
diff changeset
168 @item "string", ?c, ?\c
Dave Love <fx@gnu.org>
parents:
diff changeset
169 @vindex skeleton-transformation
Dave Love <fx@gnu.org>
parents:
diff changeset
170 Insert string or character. Literal strings and characters are passed through
Dave Love <fx@gnu.org>
parents:
diff changeset
171 @code{skeleton-transformation} when that is non-@code{nil}.
Dave Love <fx@gnu.org>
parents:
diff changeset
172 @item \n
Dave Love <fx@gnu.org>
parents:
diff changeset
173 Insert a newline and align under current line. Use newline character
Dave Love <fx@gnu.org>
parents:
diff changeset
174 @code{?\n} to prevent alignment.
Dave Love <fx@gnu.org>
parents:
diff changeset
175 @item _
Dave Love <fx@gnu.org>
parents:
diff changeset
176 Interesting point. When wrapping skeletons around successive regions, they are
Dave Love <fx@gnu.org>
parents:
diff changeset
177 put at these places. Point is left at first @code{_} where nothing is wrapped.
Dave Love <fx@gnu.org>
parents:
diff changeset
178 @item >
Dave Love <fx@gnu.org>
parents:
diff changeset
179 Indent line according to major mode. When following element is @code{_}, and
Dave Love <fx@gnu.org>
parents:
diff changeset
180 there is a interregion that will be wrapped here, indent that interregion.
Dave Love <fx@gnu.org>
parents:
diff changeset
181 @item &
Dave Love <fx@gnu.org>
parents:
diff changeset
182 Logical and. Iff preceding element moved point, i.e. usually inserted
Dave Love <fx@gnu.org>
parents:
diff changeset
183 something, do following element.
Dave Love <fx@gnu.org>
parents:
diff changeset
184 @item |
Dave Love <fx@gnu.org>
parents:
diff changeset
185 Logical xor. Iff preceding element didn't move point, i.e. usually inserted
Dave Love <fx@gnu.org>
parents:
diff changeset
186 nothing, do following element.
Dave Love <fx@gnu.org>
parents:
diff changeset
187 @item -number
Dave Love <fx@gnu.org>
parents:
diff changeset
188 Delete preceding number characters. Depends on value of
Dave Love <fx@gnu.org>
parents:
diff changeset
189 @code{skeleton-untabify}.
Dave Love <fx@gnu.org>
parents:
diff changeset
190 @item (), nil
Dave Love <fx@gnu.org>
parents:
diff changeset
191 Ignored.
Dave Love <fx@gnu.org>
parents:
diff changeset
192 @item lisp expression
Dave Love <fx@gnu.org>
parents:
diff changeset
193 Evaluated, and the return value is again interpreted as a skeleton element.
Dave Love <fx@gnu.org>
parents:
diff changeset
194 @item str
Dave Love <fx@gnu.org>
parents:
diff changeset
195 A special variable that, when evaluated the first time, usually prompts
Dave Love <fx@gnu.org>
parents:
diff changeset
196 for input according to the skeleton's interactor. It is then set to the
Dave Love <fx@gnu.org>
parents:
diff changeset
197 return value resulting from the interactor. Each subskeleton has its local
Dave Love <fx@gnu.org>
parents:
diff changeset
198 copy of this variable.
Dave Love <fx@gnu.org>
parents:
diff changeset
199 @item v1, v2
Dave Love <fx@gnu.org>
parents:
diff changeset
200 Skeleton-local user variables.
Dave Love <fx@gnu.org>
parents:
diff changeset
201 @item '
Dave Love <fx@gnu.org>
parents:
diff changeset
202 Evaluate following lisp expression for its side-effect, but prevent it from
Dave Love <fx@gnu.org>
parents:
diff changeset
203 being interpreted as a skeleton element.
Dave Love <fx@gnu.org>
parents:
diff changeset
204 @item skeleton
Dave Love <fx@gnu.org>
parents:
diff changeset
205 Subskeletons are inserted recursively, not once, but as often as the user
Dave Love <fx@gnu.org>
parents:
diff changeset
206 enters something at the subskeletons interactor. Thus there must be a
Dave Love <fx@gnu.org>
parents:
diff changeset
207 @code{str} in the subskeleton. They can also be used non-interactively, when
Dave Love <fx@gnu.org>
parents:
diff changeset
208 prompt is a lisp-expression that returns successive list-elements.
Dave Love <fx@gnu.org>
parents:
diff changeset
209 @item resume:
Dave Love <fx@gnu.org>
parents:
diff changeset
210 Ignored. Execution resumes here when the user quit during skeleton
Dave Love <fx@gnu.org>
parents:
diff changeset
211 interpretation.
Dave Love <fx@gnu.org>
parents:
diff changeset
212 @item quit
Dave Love <fx@gnu.org>
parents:
diff changeset
213 A constant which is non-@code{nil} when the @code{resume:} section was entered
Dave Love <fx@gnu.org>
parents:
diff changeset
214 because the user quit.
Dave Love <fx@gnu.org>
parents:
diff changeset
215 @end table
Dave Love <fx@gnu.org>
parents:
diff changeset
216
Dave Love <fx@gnu.org>
parents:
diff changeset
217 @findex skeleton-further-elements
Dave Love <fx@gnu.org>
parents:
diff changeset
218 Some modes also use other skeleton elements they themselves defined. For
Dave Love <fx@gnu.org>
parents:
diff changeset
219 example in shell script mode's skeletons you will find @code{<} which does a
Dave Love <fx@gnu.org>
parents:
diff changeset
220 rigid indentation backwards, or in cc-mode's skeletons you find the
Dave Love <fx@gnu.org>
parents:
diff changeset
221 self-inserting elements @code{@{} and @code{@}}. These are defined by the
Dave Love <fx@gnu.org>
parents:
diff changeset
222 buffer-local variable @code{skeleton-further-elements} which is a list of
Dave Love <fx@gnu.org>
parents:
diff changeset
223 variables bound while interpreting a skeleton.
Dave Love <fx@gnu.org>
parents:
diff changeset
224
Dave Love <fx@gnu.org>
parents:
diff changeset
225 @findex define-skeleton
Dave Love <fx@gnu.org>
parents:
diff changeset
226 The macro @code{define-skeleton} defines a command for interpreting a
Dave Love <fx@gnu.org>
parents:
diff changeset
227 skeleton. The first argument is the command name, the second is a
Dave Love <fx@gnu.org>
parents:
diff changeset
228 documentation string, and the rest is an interactor and any number of skeleton
Dave Love <fx@gnu.org>
parents:
diff changeset
229 elements together forming a skeleton. This skeleton is assigned to a variable
Dave Love <fx@gnu.org>
parents:
diff changeset
230 of the same name as the command and can thus be overridden from your
Dave Love <fx@gnu.org>
parents:
diff changeset
231 @file{~/.emacs} file (@xref{Init File}).
Dave Love <fx@gnu.org>
parents:
diff changeset
232
Dave Love <fx@gnu.org>
parents:
diff changeset
233
Dave Love <fx@gnu.org>
parents:
diff changeset
234
Dave Love <fx@gnu.org>
parents:
diff changeset
235 @node Inserting Pairs
Dave Love <fx@gnu.org>
parents:
diff changeset
236 @section Inserting Matching Pairs of Characters
Dave Love <fx@gnu.org>
parents:
diff changeset
237 @cindex inserting pairs
Dave Love <fx@gnu.org>
parents:
diff changeset
238 @cindex pairs
Dave Love <fx@gnu.org>
parents:
diff changeset
239
Dave Love <fx@gnu.org>
parents:
diff changeset
240 Various characters usually appear in pairs. When, for example, you insert
Dave Love <fx@gnu.org>
parents:
diff changeset
241 an open parenthesis, no matter whether you are programming or writing prose,
Dave Love <fx@gnu.org>
parents:
diff changeset
242 you will surely enter a closing one later. By entering both at the same time
Dave Love <fx@gnu.org>
parents:
diff changeset
243 and leaving the cursor inbetween, Emacs can guarantee you that such
Dave Love <fx@gnu.org>
parents:
diff changeset
244 parentheses are always balanced. And if you have a non-qwerty keyboard, where
Dave Love <fx@gnu.org>
parents:
diff changeset
245 typing some of the stranger programming language symbols makes you bend your
Dave Love <fx@gnu.org>
parents:
diff changeset
246 fingers backwards, this can be quite relieving too.
Dave Love <fx@gnu.org>
parents:
diff changeset
247
Dave Love <fx@gnu.org>
parents:
diff changeset
248 @findex pair-insert-maybe
Dave Love <fx@gnu.org>
parents:
diff changeset
249 @vindex pair
Dave Love <fx@gnu.org>
parents:
diff changeset
250 This is done by binding the first key (@xref{Rebinding}) of the pair to
Dave Love <fx@gnu.org>
parents:
diff changeset
251 @code{pair-insert-maybe} instead of @code{self-insert-command}. The maybe
Dave Love <fx@gnu.org>
parents:
diff changeset
252 comes from the fact that this at first surprising behaviour is initially
Dave Love <fx@gnu.org>
parents:
diff changeset
253 turned off. To enable it, you must set @code{pair} to some non-@code{nil}
Dave Love <fx@gnu.org>
parents:
diff changeset
254 value. And even then, a positive argument (@xref{Arguments}) will make this
Dave Love <fx@gnu.org>
parents:
diff changeset
255 key behave like a self inserting key (@xref{Inserting Text}).
Dave Love <fx@gnu.org>
parents:
diff changeset
256
Dave Love <fx@gnu.org>
parents:
diff changeset
257 @findex pair-on-word
Dave Love <fx@gnu.org>
parents:
diff changeset
258 While this breaks with the stated intention of always balancing pairs, it
Dave Love <fx@gnu.org>
parents:
diff changeset
259 turns out that one often doesn't want pairing to occur, when the following
Dave Love <fx@gnu.org>
parents:
diff changeset
260 character is part of a word. If you want pairing to occur even then, set
Dave Love <fx@gnu.org>
parents:
diff changeset
261 @code{pair-on-word} to some non-@code{nil} value.
Dave Love <fx@gnu.org>
parents:
diff changeset
262
Dave Love <fx@gnu.org>
parents:
diff changeset
263 @vindex pair-alist
Dave Love <fx@gnu.org>
parents:
diff changeset
264 Pairing is possible for all visible characters. By default the parenthesis
Dave Love <fx@gnu.org>
parents:
diff changeset
265 `(', the square bracket `[', the brace `@{', the pointed bracket `<' and the
Dave Love <fx@gnu.org>
parents:
diff changeset
266 backquote ``' will all pair to the symmetrical character. All other
Dave Love <fx@gnu.org>
parents:
diff changeset
267 characters will pair themselves. This behaviour can be modified by the
Dave Love <fx@gnu.org>
parents:
diff changeset
268 variable @code{pair-alist}. This is in fact an alist of skeletons
Dave Love <fx@gnu.org>
parents:
diff changeset
269 (@xref{Skeleton Language}), with the first part of each sublist matching the
Dave Love <fx@gnu.org>
parents:
diff changeset
270 typed character. This is the position of the interactor, but since pairs
Dave Love <fx@gnu.org>
parents:
diff changeset
271 don't need the @code{str} element, this is ignored.
Dave Love <fx@gnu.org>
parents:
diff changeset
272
Dave Love <fx@gnu.org>
parents:
diff changeset
273 Some modes have bound the command @code{pair-insert-maybe} to relevant keys.
Dave Love <fx@gnu.org>
parents:
diff changeset
274 These modes also configure the pairs as appropriate. For example, when typing
Dave Love <fx@gnu.org>
parents:
diff changeset
275 english prose, you'd expect the backquote (`) to pair to the quote (') while
Dave Love <fx@gnu.org>
parents:
diff changeset
276 in Shell script mode it must pair to itself. They can also inhibit pairing
Dave Love <fx@gnu.org>
parents:
diff changeset
277 in certain contexts. For example an escaped character will stand for itself.
Dave Love <fx@gnu.org>
parents:
diff changeset
278
Dave Love <fx@gnu.org>
parents:
diff changeset
279
Dave Love <fx@gnu.org>
parents:
diff changeset
280
Dave Love <fx@gnu.org>
parents:
diff changeset
281 @node Autoinserting
Dave Love <fx@gnu.org>
parents:
diff changeset
282 @section Autoinserting Text in Empty Files
Dave Love <fx@gnu.org>
parents:
diff changeset
283 @cindex autoinserting
Dave Love <fx@gnu.org>
parents:
diff changeset
284
Dave Love <fx@gnu.org>
parents:
diff changeset
285 @findex auto-insert
Dave Love <fx@gnu.org>
parents:
diff changeset
286 @kbd{M-x auto-insert} will put some predefined text at the beginning of
Dave Love <fx@gnu.org>
parents:
diff changeset
287 the buffer. The main application for this function, as its name suggests,
Dave Love <fx@gnu.org>
parents:
diff changeset
288 is to have it be called automatically every time an empty, and only an
Dave Love <fx@gnu.org>
parents:
diff changeset
289 empty file is visited. This is accomplished by putting @code{(add-hook
Dave Love <fx@gnu.org>
parents:
diff changeset
290 'find-file-hooks 'auto-insert)} into your @file{~/.emacs} file (@xref{Init
Dave Love <fx@gnu.org>
parents:
diff changeset
291 File}).
Dave Love <fx@gnu.org>
parents:
diff changeset
292
Dave Love <fx@gnu.org>
parents:
diff changeset
293 @vindex auto-insert-alist
Dave Love <fx@gnu.org>
parents:
diff changeset
294 What gets inserted, if anything, is determined by the variable
Dave Love <fx@gnu.org>
parents:
diff changeset
295 @code{auto-insert-alist}. The @code{car}s of this list are each either a mode
Dave Love <fx@gnu.org>
parents:
diff changeset
296 name, making an element applicable when a buffer is in that mode. Or they
Dave Love <fx@gnu.org>
parents:
diff changeset
297 can be a string, which is a regexp matched against the buffer's file name.
Dave Love <fx@gnu.org>
parents:
diff changeset
298 In that way different kinds of files that have the same mode in Emacs can be
Dave Love <fx@gnu.org>
parents:
diff changeset
299 distinguished. The @code{car}s may also be @code{cons}-cells consisting of
Dave Love <fx@gnu.org>
parents:
diff changeset
300 mode name or regexp as above and an additional descriptive string.
Dave Love <fx@gnu.org>
parents:
diff changeset
301
Dave Love <fx@gnu.org>
parents:
diff changeset
302 When a matching element is found, the @code{cdr} says what to do. It may
Dave Love <fx@gnu.org>
parents:
diff changeset
303 be a string, which is a file name, whose contents are to be inserted, if
Dave Love <fx@gnu.org>
parents:
diff changeset
304 that file is found in the directory @code{auto-insert-directory} or under a
Dave Love <fx@gnu.org>
parents:
diff changeset
305 absolute file name. Or it can be a skeleton (@xref{Skeleton Language}) to
Dave Love <fx@gnu.org>
parents:
diff changeset
306 be inserted.
Dave Love <fx@gnu.org>
parents:
diff changeset
307
Dave Love <fx@gnu.org>
parents:
diff changeset
308 It can also be a function, which allows doing various things. The function
Dave Love <fx@gnu.org>
parents:
diff changeset
309 can simply insert some text, indeed, it can be skeleton command (@xref{Using
Dave Love <fx@gnu.org>
parents:
diff changeset
310 Skeletons}). It can be a lambda function which will for example conditionally
Dave Love <fx@gnu.org>
parents:
diff changeset
311 call another function. Or it can even reset the mode for the buffer. If you
Dave Love <fx@gnu.org>
parents:
diff changeset
312 want to perform several such actions in order, you use a vector, i.e. several
Dave Love <fx@gnu.org>
parents:
diff changeset
313 of the above elements between square brackets ([...]).
Dave Love <fx@gnu.org>
parents:
diff changeset
314
Dave Love <fx@gnu.org>
parents:
diff changeset
315 By default C and C++ headers insert a definition of a symbol derived from
Dave Love <fx@gnu.org>
parents:
diff changeset
316 the filename to prevent multiple inclusions. C and C++ sources insert an
Dave Love <fx@gnu.org>
parents:
diff changeset
317 include of the header. Makefiles insert the file makefile.inc if it exists.
Dave Love <fx@gnu.org>
parents:
diff changeset
318
Dave Love <fx@gnu.org>
parents:
diff changeset
319 TeX and bibTeX mode files insert the file tex-insert.tex if it exists, while
Dave Love <fx@gnu.org>
parents:
diff changeset
320 LaTeX mode files insert insert a typical @code{\documentclass} frame. Html
Dave Love <fx@gnu.org>
parents:
diff changeset
321 files insert a skeleton with the usual frame.
Dave Love <fx@gnu.org>
parents:
diff changeset
322
Dave Love <fx@gnu.org>
parents:
diff changeset
323 Ada mode files call the Ada header skeleton command. Emacs lisp source
Dave Love <fx@gnu.org>
parents:
diff changeset
324 files insert the usual header, with a copyright of your environment variable
Dave Love <fx@gnu.org>
parents:
diff changeset
325 @code{$ORGANIZATION} or else the FSF, and prompt for valid keywords describing
Dave Love <fx@gnu.org>
parents:
diff changeset
326 the contents. Files in a @code{bin/} directory for which Emacs could
Dave Love <fx@gnu.org>
parents:
diff changeset
327 determine no specialised mode (@xref{Choosing Modes}) are set to Shell script
Dave Love <fx@gnu.org>
parents:
diff changeset
328 mode.
Dave Love <fx@gnu.org>
parents:
diff changeset
329
Dave Love <fx@gnu.org>
parents:
diff changeset
330 @findex define-auto-insert
Dave Love <fx@gnu.org>
parents:
diff changeset
331 In Lisp (@xref{Init File}) you can use the function @code{define-auto-insert}
Dave Love <fx@gnu.org>
parents:
diff changeset
332 to add to or modify @code{auto-insert-alist}. See its documentation with
Dave Love <fx@gnu.org>
parents:
diff changeset
333 @kbd{C-h f auto-insert-alist}.
Dave Love <fx@gnu.org>
parents:
diff changeset
334
Dave Love <fx@gnu.org>
parents:
diff changeset
335 @vindex auto-insert
Dave Love <fx@gnu.org>
parents:
diff changeset
336 The variable @code{auto-insert} says what to do when @code{auto-insert} is
Dave Love <fx@gnu.org>
parents:
diff changeset
337 called non-interactively, e.g. when a newly found file is empty (see above):
Dave Love <fx@gnu.org>
parents:
diff changeset
338 @table @code
Dave Love <fx@gnu.org>
parents:
diff changeset
339 @item nil
Dave Love <fx@gnu.org>
parents:
diff changeset
340 Do nothing.
Dave Love <fx@gnu.org>
parents:
diff changeset
341 @item t
Dave Love <fx@gnu.org>
parents:
diff changeset
342 Insert something if possible, i.e. there is a matching entry in
Dave Love <fx@gnu.org>
parents:
diff changeset
343 @code{auto-insert-alist}.
Dave Love <fx@gnu.org>
parents:
diff changeset
344 @item other
Dave Love <fx@gnu.org>
parents:
diff changeset
345 Insert something if possible, but mark as unmodified.
Dave Love <fx@gnu.org>
parents:
diff changeset
346 @end table
Dave Love <fx@gnu.org>
parents:
diff changeset
347
Dave Love <fx@gnu.org>
parents:
diff changeset
348 @vindex auto-insert-query
Dave Love <fx@gnu.org>
parents:
diff changeset
349 The variable @code{auto-insert-query} controls whether to ask about
Dave Love <fx@gnu.org>
parents:
diff changeset
350 inserting something. When this is @code{nil} inserting is only done with
Dave Love <fx@gnu.org>
parents:
diff changeset
351 @kbd{M-x auto-insert}. When this is @code{'function} you are queried
Dave Love <fx@gnu.org>
parents:
diff changeset
352 whenever @code{auto-insert} is called as a function, such as when Emacs
Dave Love <fx@gnu.org>
parents:
diff changeset
353 visits an empty file and you have set the above-mentioned hook. Otherwise
Dave Love <fx@gnu.org>
parents:
diff changeset
354 you are alway queried.
Dave Love <fx@gnu.org>
parents:
diff changeset
355
Dave Love <fx@gnu.org>
parents:
diff changeset
356 @vindex auto-insert-prompt
Dave Love <fx@gnu.org>
parents:
diff changeset
357 When querying, the variable @code{auto-insert-prompt}'s value is used as a
Dave Love <fx@gnu.org>
parents:
diff changeset
358 prompt for a y-or-n-type question. If this includes a @code{%s} construct,
Dave Love <fx@gnu.org>
parents:
diff changeset
359 that is replaced by what caused the insertion rule to be chosen. This is
Dave Love <fx@gnu.org>
parents:
diff changeset
360 either a descriptive text, the mode-name of the buffer or the regular
Dave Love <fx@gnu.org>
parents:
diff changeset
361 expression that matched the filename.
Dave Love <fx@gnu.org>
parents:
diff changeset
362
Dave Love <fx@gnu.org>
parents:
diff changeset
363
Dave Love <fx@gnu.org>
parents:
diff changeset
364
Dave Love <fx@gnu.org>
parents:
diff changeset
365 @node Copyrights
Dave Love <fx@gnu.org>
parents:
diff changeset
366 @section Inserting and Updating Copyrights
Dave Love <fx@gnu.org>
parents:
diff changeset
367 @cindex copyrights
Dave Love <fx@gnu.org>
parents:
diff changeset
368
Dave Love <fx@gnu.org>
parents:
diff changeset
369 @findex copyright
Dave Love <fx@gnu.org>
parents:
diff changeset
370 @kbd{M-x copyright} is a skeleton inserting command, that adds a copyright
Dave Love <fx@gnu.org>
parents:
diff changeset
371 notice at the point. The ``by'' part is taken from your environment variable
Dave Love <fx@gnu.org>
parents:
diff changeset
372 @code{$ORGANIZATION} or if that isn't set you are prompted for it. If the
Dave Love <fx@gnu.org>
parents:
diff changeset
373 buffer has a comment syntax (@xref{Comments}), this is inserted as a comment.
Dave Love <fx@gnu.org>
parents:
diff changeset
374
Dave Love <fx@gnu.org>
parents:
diff changeset
375 @findex copyright-update
Dave Love <fx@gnu.org>
parents:
diff changeset
376 @vindex copyright-limit
Dave Love <fx@gnu.org>
parents:
diff changeset
377 @vindex copyright-current-year
Dave Love <fx@gnu.org>
parents:
diff changeset
378 @kbd{M-x copyright-update} looks for a copyright notice in the first
Dave Love <fx@gnu.org>
parents:
diff changeset
379 @code{copyright-limit} characters of the buffer and updates it when necessary.
Dave Love <fx@gnu.org>
parents:
diff changeset
380 The current year (variable @code{copyright-current-year}) is added to the
Dave Love <fx@gnu.org>
parents:
diff changeset
381 existing ones, in the same format as the preceding year, i.e. 1994, '94 or 94.
Dave Love <fx@gnu.org>
parents:
diff changeset
382 If a dash-separated year list up to last year is found, that is extended to
Dave Love <fx@gnu.org>
parents:
diff changeset
383 current year, else the year is added separated by a comma. Or it replaces
Dave Love <fx@gnu.org>
parents:
diff changeset
384 them when this is called with a prefix argument. If a header referring to a
Dave Love <fx@gnu.org>
parents:
diff changeset
385 wrong version of the GNU General Public License (@xref{Copying}) is found,
Dave Love <fx@gnu.org>
parents:
diff changeset
386 that is updated too.
Dave Love <fx@gnu.org>
parents:
diff changeset
387
Dave Love <fx@gnu.org>
parents:
diff changeset
388 An interesting application for this function is to have it be called
Dave Love <fx@gnu.org>
parents:
diff changeset
389 automatically every time a file is saved. This is accomplished by putting
Dave Love <fx@gnu.org>
parents:
diff changeset
390 @code{(add-hook 'write-file-hooks 'copyright-update)} into your @file{~/.emacs}
Dave Love <fx@gnu.org>
parents:
diff changeset
391 file (@xref{Init File}).
Dave Love <fx@gnu.org>
parents:
diff changeset
392
Dave Love <fx@gnu.org>
parents:
diff changeset
393 @vindex copyright-query
Dave Love <fx@gnu.org>
parents:
diff changeset
394 The variable @code{copyright-query} controls whether to update the
Dave Love <fx@gnu.org>
parents:
diff changeset
395 copyright or whether to ask about it. When this is @code{nil} updating is
Dave Love <fx@gnu.org>
parents:
diff changeset
396 only done with @kbd{M-x copyright-update}. When this is @code{'function}
Dave Love <fx@gnu.org>
parents:
diff changeset
397 you are queried whenever @code{copyright-update} is called as a function,
Dave Love <fx@gnu.org>
parents:
diff changeset
398 such as in the @code{write-file-hooks} feature mentioned above. Otherwise
Dave Love <fx@gnu.org>
parents:
diff changeset
399 you are always queried.
Dave Love <fx@gnu.org>
parents:
diff changeset
400
Dave Love <fx@gnu.org>
parents:
diff changeset
401
Dave Love <fx@gnu.org>
parents:
diff changeset
402
Dave Love <fx@gnu.org>
parents:
diff changeset
403 @node Executables
Dave Love <fx@gnu.org>
parents:
diff changeset
404 @section Making Interpreter Scripts Executable
Dave Love <fx@gnu.org>
parents:
diff changeset
405 @cindex executables
Dave Love <fx@gnu.org>
parents:
diff changeset
406
Dave Love <fx@gnu.org>
parents:
diff changeset
407 @vindex executable-prefix
Dave Love <fx@gnu.org>
parents:
diff changeset
408 @vindex executable-chmod
Dave Love <fx@gnu.org>
parents:
diff changeset
409 Various Un*x interpreter modes such as Shell script mode or AWK mode
Dave Love <fx@gnu.org>
parents:
diff changeset
410 will automatically insert or update the buffer's magic number, a special
Dave Love <fx@gnu.org>
parents:
diff changeset
411 comment on the first line that makes the @code{exec()} systemcall know how
Dave Love <fx@gnu.org>
parents:
diff changeset
412 to execute the script. To this end the script is automatically made
Dave Love <fx@gnu.org>
parents:
diff changeset
413 executable upon saving, with @code{executable-chmod} as argument to the
Dave Love <fx@gnu.org>
parents:
diff changeset
414 system @code{chmod} command. The magic number is prefixed by the value of
Dave Love <fx@gnu.org>
parents:
diff changeset
415 @code{executable-prefix}.
Dave Love <fx@gnu.org>
parents:
diff changeset
416
Dave Love <fx@gnu.org>
parents:
diff changeset
417 @vindex executable-magicless-file-regexp
Dave Love <fx@gnu.org>
parents:
diff changeset
418 Any file whos name matches @code{executable-magicless-file-regexp} is not
Dave Love <fx@gnu.org>
parents:
diff changeset
419 furnished with a magic number, nor is it made executable. This is mainly
Dave Love <fx@gnu.org>
parents:
diff changeset
420 intended for resource files, which are only meant to be read in.
Dave Love <fx@gnu.org>
parents:
diff changeset
421
Dave Love <fx@gnu.org>
parents:
diff changeset
422 @vindex executable-insert
Dave Love <fx@gnu.org>
parents:
diff changeset
423 The variable @code{executable-insert} says what to do when
Dave Love <fx@gnu.org>
parents:
diff changeset
424 @code{executable-set-magic} is called non-interactively, e.g. when file has no
Dave Love <fx@gnu.org>
parents:
diff changeset
425 or the wrong magic number:
Dave Love <fx@gnu.org>
parents:
diff changeset
426 @table @code
Dave Love <fx@gnu.org>
parents:
diff changeset
427 @item nil
Dave Love <fx@gnu.org>
parents:
diff changeset
428 Do nothing.
Dave Love <fx@gnu.org>
parents:
diff changeset
429 @item t
Dave Love <fx@gnu.org>
parents:
diff changeset
430 Insert or update magic number.
Dave Love <fx@gnu.org>
parents:
diff changeset
431 @item other
Dave Love <fx@gnu.org>
parents:
diff changeset
432 Insert or update magic number, but mark as unmodified.
Dave Love <fx@gnu.org>
parents:
diff changeset
433 @end table
Dave Love <fx@gnu.org>
parents:
diff changeset
434
Dave Love <fx@gnu.org>
parents:
diff changeset
435 @findex executable-set-magic
Dave Love <fx@gnu.org>
parents:
diff changeset
436 @vindex executable-query
Dave Love <fx@gnu.org>
parents:
diff changeset
437 The variable @code{executable-query} controls whether to ask about
Dave Love <fx@gnu.org>
parents:
diff changeset
438 inserting or updating the magic number. When this is @code{nil} updating
Dave Love <fx@gnu.org>
parents:
diff changeset
439 is only done with @kbd{M-x executable-set-magic}. When this is
Dave Love <fx@gnu.org>
parents:
diff changeset
440 @code{'function} you are queried whenever @code{executable-set-magic} is
Dave Love <fx@gnu.org>
parents:
diff changeset
441 called as a function, such as when Emacs puts a buffer in Shell script
Dave Love <fx@gnu.org>
parents:
diff changeset
442 mode. Otherwise you are alway queried.
Dave Love <fx@gnu.org>
parents:
diff changeset
443
Dave Love <fx@gnu.org>
parents:
diff changeset
444 @findex executable-self-display
Dave Love <fx@gnu.org>
parents:
diff changeset
445 @kbd{M-x executable-self-display} adds a magic number to the buffer, which
Dave Love <fx@gnu.org>
parents:
diff changeset
446 will turn it into a self displaying text file, when called as a Un*x command.
Dave Love <fx@gnu.org>
parents:
diff changeset
447 The ``interpreter'' used is @code{executable-self-display} with argument
Dave Love <fx@gnu.org>
parents:
diff changeset
448 @code{+2}.