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