Mercurial > emacs
annotate man/autotype.texi @ 60158:7c92649144ac
Document problems with PCL-CVS wrt CVS v1.12.8 and 1.12.9.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 19 Feb 2005 12:56:21 +0000 |
parents | 5ff790f43164 |
children | 3723093a21fd 6d92d69fae33 |
rev | line source |
---|---|
26151 | 1 \input texinfo |
2 @c This is an annex of the Emacs manual. | |
47737
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
3 @c Copyright (C) 1994, 1995, 2002 Free Software Foundation, Inc. |
25848 | 4 @c Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389 |
26151 | 5 @setfilename ../info/autotype |
6 @c @node Autotypist, Picture, Abbrevs, Top | |
7 @c @chapter Features for Automatic Typing | |
8 @settitle Features for Automatic Typing | |
9 @c @cindex text | |
10 @c @cindex selfinserting text | |
11 @c @cindex autotypist | |
25848 | 12 |
47737
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
13 @copying |
26151 | 14 Copyright @copyright{} 1994, 1995, 1999 Free Software Foundation, Inc. |
32315 | 15 |
47737
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
16 @quotation |
32315 | 17 Permission is granted to copy, distribute and/or modify this document |
18 under the terms of the GNU Free Documentation License, Version 1.1 or | |
19 any later version published by the Free Software Foundation; with the | |
20 Invariant Sections being ``The GNU Manifesto'', ``Distribution'' and | |
21 ``GNU GENERAL PUBLIC LICENSE'', with the Front-Cover texts being ``A GNU | |
22 Manual'', and with the Back-Cover Texts as in (a) below. A copy of the | |
23 license is included in the section entitled ``GNU Free Documentation | |
24 License'' in the Emacs manual. | |
26151 | 25 |
32315 | 26 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify |
27 this GNU Manual, like GNU software. Copies published by the Free | |
28 Software Foundation raise funds for GNU development.'' | |
29 | |
30 This document is part of a collection distributed under the GNU Free | |
31 Documentation License. If you want to distribute this document | |
32 separately from the collection, you can do so by adding a copy of the | |
33 license to the document, as described in section 6 of the license. | |
47737
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
34 @end quotation |
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
35 @end copying |
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
36 |
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
37 @dircategory Emacs |
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
38 @direntry |
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
39 * Autotype: (autotype). Convenient features for text that you enter frequently |
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
40 in Emacs. |
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
41 @end direntry |
26151 | 42 |
43 @titlepage | |
44 @sp 10 | |
45 | |
46 @center @titlefont{Autotyping} | |
47 @sp 2 | |
48 @center @subtitlefont{Convenient features for text that you enter | |
49 frequently in Emacs} | |
50 @sp 2 | |
51 @center Daniel Pfeiffer | |
52 @center additions by Dave Love | |
53 | |
54 @page | |
55 @vskip 0pt plus 1filll | |
47737
0a70200bde27
use @copying instead of @ifinfo.
Karl Berry <karl@gnu.org>
parents:
46918
diff
changeset
|
56 @insertcopying |
26151 | 57 @end titlepage |
58 | |
59 @node Top | |
60 @top Autotyping | |
61 | |
25848 | 62 Under certain circumstances you will find yourself typing similar things |
63 over and over again. This is especially true of form letters and programming | |
64 language constructs. Project-specific header comments, flow-control | |
65 constructs or magic numbers are essentially the same every time. Emacs has | |
26151 | 66 various features for doing tedious and repetitive typing chores for you |
67 in addition to the Abbrev features (@pxref{(emacs)Abbrevs}). | |
25848 | 68 |
69 One solution is using skeletons, flexible rules that say what to | |
70 insert, and how to do it. Various programming language modes offer some | |
71 ready-to-use skeletons, and you can adapt them to suit your needs or | |
72 taste, or define new ones. | |
73 | |
74 Another feature is automatic insertion of what you want into empty files, | |
75 depending on the file-name or the mode as appropriate. You can have a file or | |
76 a skeleton inserted, or you can call a function. Then there is the | |
77 possibility to have Un*x interpreter scripts automatically take on a magic | |
78 number and be executable as soon as they are saved. Or you can have a | |
26151 | 79 copyright notice's year updated, if necessary, every time you save a |
80 file. Similarly for time stamps in the file. | |
81 | |
82 URLs can be inserted based on a word at point. Flexible templates can | |
83 be defined for inserting and navigating between text more generally. A | |
84 sort of meta-expansion facility can be used to try a set of alternative | |
85 completions and expansions of text at point. | |
25848 | 86 |
87 @menu | |
88 * Using Skeletons:: How to insert a skeleton into your text. | |
89 * Wrapping Skeletons:: Putting existing text within a skeleton. | |
90 * Skeletons as Abbrevs:: An alternative for issuing skeleton commands. | |
91 * Skeleton Language:: Making skeleton commands insert what you want. | |
26151 | 92 * Inserting Pairs:: Typing one character and getting another |
93 after point. | |
25848 | 94 * Autoinserting:: Filling up empty files as soon as you visit them. |
95 * Copyrights:: Inserting and updating copyrights. | |
96 * Executables:: Turning interpreter scripts into executables. | |
26151 | 97 * Timestamps:: Updating dates and times in modified files. |
98 * QuickURL:: Inserting URLs based on text at point. | |
99 * Tempo:: Flexible template insertion. | |
100 * Hippie Expand:: Expansion of text trying various methods. | |
101 | |
102 * Concept Index:: | |
103 * Command Index:: | |
104 * Variable Index:: | |
25848 | 105 @end menu |
106 | |
107 | |
108 | |
109 @node Using Skeletons | |
26151 | 110 @chapter Using Skeletons |
25848 | 111 @cindex skeletons |
112 @cindex using skeletons | |
113 | |
114 When you want Emacs to insert a form letter or a typical construct of the | |
115 programming language you are using, skeletons are a means of accomplishing | |
116 this. Normally skeletons each have a command of their own, that, when called, | |
117 will insert the skeleton. These commands can be issued in the usual ways | |
26463 | 118 (@pxref{(emacs)Commands}). Modes that offer various skeletons will often |
26151 | 119 bind these to key-sequences on the @kbd{C-c} prefix, as well as having |
120 an @cite{Insert} menu and maybe even predefined abbrevs for them | |
26463 | 121 (@pxref{Skeletons as Abbrevs}). |
25848 | 122 |
123 The simplest kind of skeleton will simply insert some text indented | |
124 according to the major mode and leave the cursor at a likely place in the | |
125 middle. Interactive skeletons may prompt you for a string that will be part | |
126 of the inserted text. | |
127 | |
128 Skeletons may ask for input several times. They even have a looping | |
129 mechanism in which you will be asked for input as long as you are willing to | |
130 furnish it. An example would be multiple ``else if'' conditions. You can | |
36506 | 131 recognize this situation by a prompt ending in @key{RET}, @kbd{C-g} |
132 or @kbd{C-h}. This | |
25848 | 133 means that entering an empty string will simply assume that you are finished. |
134 Typing quit on the other hand terminates the loop but also the rest of the | |
135 skeleton, e.g. an ``else'' clause is skipped. Only a syntactically necessary | |
136 termination still gets inserted. | |
137 | |
138 | |
139 | |
140 @node Wrapping Skeletons | |
26151 | 141 @chapter Wrapping Skeletons Around Existing Text |
25848 | 142 @cindex wrapping skeletons |
143 | |
144 Often you will find yourself with some code that for whatever reason | |
145 suddenly becomes conditional. Or you have written a bit of text and want to | |
146 put it in the middle of a form letter. Skeletons provide a means for | |
147 accomplishing this, and can even, in the case of programming languages, | |
148 reindent the wrapped code for you. | |
149 | |
150 Skeleton commands take an optional numeric prefix argument | |
26463 | 151 (@pxref{(emacs)Arguments}). This is interpreted in two different ways depending |
25848 | 152 on whether the prefix is positive, i.e. forwards oriented or negative, |
153 i.e. backwards oriented. | |
154 | |
26151 | 155 A positive prefix means to wrap the skeleton around that many |
156 following words. This is accomplished by putting the words there where | |
26463 | 157 the point is normally left after that skeleton is inserted (@pxref{Using |
158 Skeletons}). The point (@pxref{(emacs)Point}) is left at the next | |
26151 | 159 interesting spot in the skeleton instead. |
25848 | 160 |
161 A negative prefix means to do something similar with that many precedingly | |
26463 | 162 marked interregions (@pxref{(emacs)Mark}). In the simplest case, if you type |
25848 | 163 @kbd{M--} just before issuing the skeleton command, that will wrap the |
164 skeleton around the current region, just like a positive argument would have | |
165 wrapped it around a number of words. | |
166 | |
167 Smaller negative arguments will wrap that many interregions into successive | |
168 interesting spots within the skeleton, again leaving the point at the next one. | |
169 We speak about interregions rather than regions here, because we treat them in | |
170 the order they appear in the buffer, which coincides with successive regions | |
171 only if they were marked in order. | |
172 | |
173 That is, if you marked in alphabetical order the points A B C [] (where [] | |
174 represents the point) and call a skeleton command with @kbd{M-- 3}, you will | |
175 wrap the text from A to B into the first interesting spot of the skeleton, the | |
176 text from B to C into the next one, the text from C to the point into the | |
177 third one, and leave the point in the fourth one. If there are less marks in | |
178 the buffer, or if the skeleton defines less interesting points, the surplus is | |
179 ignored. | |
180 | |
181 If, on the other hand, you marked in alphabetical order the points [] A C B, | |
182 and call a skeleton command with @kbd{M-- 3}, you will wrap the text from | |
183 point to A, then the text from A to C and finally the text from C to B. This | |
184 is done because the regions overlap and Emacs would be helplessly lost if it | |
185 tried to follow the order in which you marked these points. | |
186 | |
187 | |
188 | |
189 @node Skeletons as Abbrevs | |
26151 | 190 @chapter Skeletons as Abbrev Expansions |
25848 | 191 @cindex skeletons as abbrevs |
192 | |
39268 | 193 Rather than use a key binding for every skeleton command, you can also |
26463 | 194 define an abbreviation (@pxref{(emacs)Defining Abbrevs}) that will expand |
195 (@pxref{(emacs)Expanding Abbrevs}) into the skeleton. | |
25848 | 196 |
197 Say you want @samp{ifst} to be an abbreviation for the C language if | |
198 statement. You will tell Emacs that @samp{ifst} expands to the empty string | |
55201 | 199 and then calls the skeleton command. In Emacs Lisp you can say something like |
25848 | 200 @code{(define-abbrev c-mode-abbrev-table "ifst" "" 'c-if)}. Or you can edit |
201 the output from @kbd{M-x list-abbrevs} to make it look like this: | |
202 | |
203 @example | |
204 (c-mode-abbrev-table) | |
205 "if" 0 "" c-if | |
206 @end example | |
207 | |
208 @noindent | |
209 (Some blank lines of no semantic significance, and other abbrev tables, | |
210 have been omitted.) | |
211 | |
212 | |
213 | |
214 @node Skeleton Language | |
26151 | 215 @chapter Skeleton Language |
25848 | 216 @cindex skeleton language |
217 | |
218 @findex skeleton-insert | |
219 Skeletons are an shorthand extension to the Lisp language, where various | |
220 atoms directly perform either actions on the current buffer or rudimentary | |
221 flow control mechanisms. Skeletons are interpreted by the function | |
222 @code{skeleton-insert}. | |
223 | |
224 A skeleton is a list starting with an interactor, which is usually a | |
225 prompt-string, or @code{nil} when not needed, but can also be a Lisp | |
226 expression for complex read functions or for returning some calculated value. | |
227 The rest of the list are any number of elements as described in the following | |
228 table: | |
229 | |
36506 | 230 @table @asis |
231 @item @code{"@var{string}"}, @code{?@var{c}}, @code{?\@var{c}} | |
25848 | 232 @vindex skeleton-transformation |
233 Insert string or character. Literal strings and characters are passed through | |
234 @code{skeleton-transformation} when that is non-@code{nil}. | |
36506 | 235 @item @code{?\n} |
236 @c ??? something seems very wrong here. | |
25848 | 237 Insert a newline and align under current line. Use newline character |
238 @code{?\n} to prevent alignment. | |
36506 | 239 @item @code{_} |
25848 | 240 Interesting point. When wrapping skeletons around successive regions, they are |
241 put at these places. Point is left at first @code{_} where nothing is wrapped. | |
36506 | 242 @item @code{>} |
25848 | 243 Indent line according to major mode. When following element is @code{_}, and |
244 there is a interregion that will be wrapped here, indent that interregion. | |
36506 | 245 @item @code{&} |
25848 | 246 Logical and. Iff preceding element moved point, i.e. usually inserted |
247 something, do following element. | |
36506 | 248 @item @code{|} |
25848 | 249 Logical xor. Iff preceding element didn't move point, i.e. usually inserted |
250 nothing, do following element. | |
36506 | 251 @item @code{-@var{number}} |
25848 | 252 Delete preceding number characters. Depends on value of |
253 @code{skeleton-untabify}. | |
36506 | 254 @item @code{()} or @code{nil} |
25848 | 255 Ignored. |
36506 | 256 @item @var{lisp-expression} |
25848 | 257 Evaluated, and the return value is again interpreted as a skeleton element. |
36506 | 258 @item @code{str} |
25848 | 259 A special variable that, when evaluated the first time, usually prompts |
260 for input according to the skeleton's interactor. It is then set to the | |
261 return value resulting from the interactor. Each subskeleton has its local | |
262 copy of this variable. | |
36506 | 263 @item @code{v1}, @code{v2} |
25848 | 264 Skeleton-local user variables. |
36506 | 265 @item @code{'@var{expression}} |
55201 | 266 Evaluate following Lisp expression for its side-effect, but prevent it from |
25848 | 267 being interpreted as a skeleton element. |
36506 | 268 @item @var{skeleton} |
25848 | 269 Subskeletons are inserted recursively, not once, but as often as the user |
270 enters something at the subskeletons interactor. Thus there must be a | |
271 @code{str} in the subskeleton. They can also be used non-interactively, when | |
272 prompt is a lisp-expression that returns successive list-elements. | |
36506 | 273 @item @code{resume:} |
274 Ignored. Execution resumes here if the user quits during skeleton | |
25848 | 275 interpretation. |
36506 | 276 @item @code{quit} |
25848 | 277 A constant which is non-@code{nil} when the @code{resume:} section was entered |
278 because the user quit. | |
279 @end table | |
280 | |
281 @findex skeleton-further-elements | |
282 Some modes also use other skeleton elements they themselves defined. For | |
283 example in shell script mode's skeletons you will find @code{<} which does a | |
36506 | 284 rigid indentation backwards, or in CC mode's skeletons you find the |
25848 | 285 self-inserting elements @code{@{} and @code{@}}. These are defined by the |
286 buffer-local variable @code{skeleton-further-elements} which is a list of | |
287 variables bound while interpreting a skeleton. | |
288 | |
289 @findex define-skeleton | |
290 The macro @code{define-skeleton} defines a command for interpreting a | |
291 skeleton. The first argument is the command name, the second is a | |
292 documentation string, and the rest is an interactor and any number of skeleton | |
293 elements together forming a skeleton. This skeleton is assigned to a variable | |
294 of the same name as the command and can thus be overridden from your | |
26463 | 295 @file{~/.emacs} file (@pxref{(emacs)Init File}). |
25848 | 296 |
297 | |
298 | |
299 @node Inserting Pairs | |
26151 | 300 @chapter Inserting Matching Pairs of Characters |
25848 | 301 @cindex inserting pairs |
302 @cindex pairs | |
303 | |
304 Various characters usually appear in pairs. When, for example, you insert | |
305 an open parenthesis, no matter whether you are programming or writing prose, | |
306 you will surely enter a closing one later. By entering both at the same time | |
307 and leaving the cursor inbetween, Emacs can guarantee you that such | |
308 parentheses are always balanced. And if you have a non-qwerty keyboard, where | |
309 typing some of the stranger programming language symbols makes you bend your | |
310 fingers backwards, this can be quite relieving too. | |
311 | |
29480
3f09d2029838
(Inserting Pairs): Add the missing `skeleton-' prefix to vars and funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26463
diff
changeset
|
312 @findex skeleton-pair-insert-maybe |
3f09d2029838
(Inserting Pairs): Add the missing `skeleton-' prefix to vars and funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26463
diff
changeset
|
313 @vindex skeleton-pair |
36506 | 314 This is done by binding the first key (@pxref{(emacs)Rebinding}) of |
315 the pair to @code{skeleton-pair-insert-maybe} instead of | |
316 @code{self-insert-command}. The ``maybe'' comes from the fact that | |
38017
32f10000ac35
Don't use the British spelling of "behaviour".
Eli Zaretskii <eliz@gnu.org>
parents:
36506
diff
changeset
|
317 this at-first surprising behavior is initially turned off. To enable |
36506 | 318 it, you must set @code{skeleton-pair} to some non-@code{nil} value. |
319 And even then, a positive argument (@pxref{(emacs)Arguments}) will | |
320 make this key behave like a self-inserting key | |
321 (@pxref{(emacs)Inserting Text}). | |
25848 | 322 |
29480
3f09d2029838
(Inserting Pairs): Add the missing `skeleton-' prefix to vars and funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26463
diff
changeset
|
323 @vindex skeleton-pair-on-word |
25848 | 324 While this breaks with the stated intention of always balancing pairs, it |
325 turns out that one often doesn't want pairing to occur, when the following | |
326 character is part of a word. If you want pairing to occur even then, set | |
29480
3f09d2029838
(Inserting Pairs): Add the missing `skeleton-' prefix to vars and funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26463
diff
changeset
|
327 @code{skeleton-pair-on-word} to some non-@code{nil} value. |
25848 | 328 |
29480
3f09d2029838
(Inserting Pairs): Add the missing `skeleton-' prefix to vars and funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26463
diff
changeset
|
329 @vindex skeleton-pair-alist |
36506 | 330 Pairing is possible for all visible characters. By default the |
331 parenthesis @samp{(}, the square bracket @samp{[}, the brace | |
332 @samp{@{}, the pointed bracket @samp{<} and the backquote @samp{`} all | |
333 pair with the symmetrical character. All other characters pair | |
38017
32f10000ac35
Don't use the British spelling of "behaviour".
Eli Zaretskii <eliz@gnu.org>
parents:
36506
diff
changeset
|
334 themselves. This behavior can be modified by the variable |
36506 | 335 @code{skeleton-pair-alist}. This is in fact an alist of skeletons |
336 (@pxref{Skeleton Language}), with the first part of each sublist | |
337 matching the typed character. This is the position of the interactor, | |
338 but since pairs don't need the @code{str} element, this is ignored. | |
25848 | 339 |
36506 | 340 Some modes have bound the command @code{skeleton-pair-insert-maybe} |
341 to relevant keys. These modes also configure the pairs as | |
342 appropriate. For example, when typing english prose, you'd expect the | |
343 backquote (@samp{`}) to pair with the quote (@samp{'}), while in Shell | |
344 script mode it must pair to itself. They can also inhibit pairing in | |
345 certain contexts. For example an escaped character stands for itself. | |
25848 | 346 |
347 | |
348 | |
349 @node Autoinserting | |
26151 | 350 @chapter Autoinserting Text in Empty Files |
25848 | 351 @cindex autoinserting |
352 | |
353 @findex auto-insert | |
354 @kbd{M-x auto-insert} will put some predefined text at the beginning of | |
355 the buffer. The main application for this function, as its name suggests, | |
356 is to have it be called automatically every time an empty, and only an | |
357 empty file is visited. This is accomplished by putting @code{(add-hook | |
45979
87962bf716e3
*** empty log message ***
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39268
diff
changeset
|
358 'find-file-hook 'auto-insert)} into your @file{~/.emacs} file |
26463 | 359 (@pxref{(emacs)Init File}). |
25848 | 360 |
361 @vindex auto-insert-alist | |
362 What gets inserted, if anything, is determined by the variable | |
36506 | 363 @code{auto-insert-alist}. The @sc{car}s of this list are each either |
364 a mode name, making an element applicable when a buffer is in that | |
365 mode. Or they can be a string, which is a regexp matched against the | |
366 buffer's file name. In that way different kinds of files that have | |
367 the same mode in Emacs can be distinguished. The @sc{car}s may also | |
368 be cons cells consisting of mode name or regexp as above and an | |
369 additional descriptive string. | |
25848 | 370 |
36506 | 371 When a matching element is found, the @sc{cdr} says what to do. It may |
25848 | 372 be a string, which is a file name, whose contents are to be inserted, if |
373 that file is found in the directory @code{auto-insert-directory} or under a | |
26463 | 374 absolute file name. Or it can be a skeleton (@pxref{Skeleton Language}) to |
25848 | 375 be inserted. |
376 | |
377 It can also be a function, which allows doing various things. The function | |
26463 | 378 can simply insert some text, indeed, it can be skeleton command (@pxref{Using |
25848 | 379 Skeletons}). It can be a lambda function which will for example conditionally |
380 call another function. Or it can even reset the mode for the buffer. If you | |
381 want to perform several such actions in order, you use a vector, i.e. several | |
36506 | 382 of the above elements between square brackets (@samp{[@r{@dots{}}]}). |
25848 | 383 |
384 By default C and C++ headers insert a definition of a symbol derived from | |
385 the filename to prevent multiple inclusions. C and C++ sources insert an | |
386 include of the header. Makefiles insert the file makefile.inc if it exists. | |
387 | |
388 TeX and bibTeX mode files insert the file tex-insert.tex if it exists, while | |
36330
a16d8ed56e9c
(Autoinserting): Remove doubled `insert'.
Gerd Moellmann <gerd@gnu.org>
parents:
32315
diff
changeset
|
389 LaTeX mode files insert a typical @code{\documentclass} frame. Html |
25848 | 390 files insert a skeleton with the usual frame. |
391 | |
36506 | 392 Ada mode files call the Ada header skeleton command. Emacs lisp |
393 source files insert the usual header, with a copyright of your | |
394 environment variable @env{$ORGANIZATION} or else the FSF, and prompt | |
395 for valid keywords describing the contents. Files in a @file{bin} | |
46918
82d113655734
Minor spelling and grammar corrections.
Paul Eggert <eggert@twinsun.com>
parents:
45979
diff
changeset
|
396 directory for which Emacs could determine no specialized mode |
36506 | 397 (@pxref{(emacs)Choosing Modes}) are set to Shell script mode. |
25848 | 398 |
399 @findex define-auto-insert | |
36506 | 400 In Lisp (@pxref{(emacs)Init File}) you can use the function |
401 @code{define-auto-insert} to add to or modify | |
402 @code{auto-insert-alist}. See its documentation with @kbd{C-h f | |
59588
5ff790f43164
(Autoinserting): Fix small error.
Richard M. Stallman <rms@gnu.org>
parents:
56097
diff
changeset
|
403 define-auto-insert}. |
25848 | 404 |
405 @vindex auto-insert | |
406 The variable @code{auto-insert} says what to do when @code{auto-insert} is | |
407 called non-interactively, e.g. when a newly found file is empty (see above): | |
36506 | 408 @table @asis |
409 @item @code{nil} | |
25848 | 410 Do nothing. |
36506 | 411 @item @code{t} |
25848 | 412 Insert something if possible, i.e. there is a matching entry in |
413 @code{auto-insert-alist}. | |
414 @item other | |
415 Insert something if possible, but mark as unmodified. | |
416 @end table | |
417 | |
418 @vindex auto-insert-query | |
419 The variable @code{auto-insert-query} controls whether to ask about | |
36506 | 420 inserting something. When this is @code{nil}, inserting is only done with |
421 @kbd{M-x auto-insert}. When this is @code{function}, you are queried | |
25848 | 422 whenever @code{auto-insert} is called as a function, such as when Emacs |
423 visits an empty file and you have set the above-mentioned hook. Otherwise | |
424 you are alway queried. | |
425 | |
426 @vindex auto-insert-prompt | |
427 When querying, the variable @code{auto-insert-prompt}'s value is used as a | |
36506 | 428 prompt for a y-or-n-type question. If this includes a @samp{%s} construct, |
25848 | 429 that is replaced by what caused the insertion rule to be chosen. This is |
430 either a descriptive text, the mode-name of the buffer or the regular | |
431 expression that matched the filename. | |
432 | |
433 | |
434 | |
435 @node Copyrights | |
26151 | 436 @chapter Inserting and Updating Copyrights |
25848 | 437 @cindex copyrights |
438 | |
439 @findex copyright | |
440 @kbd{M-x copyright} is a skeleton inserting command, that adds a copyright | |
441 notice at the point. The ``by'' part is taken from your environment variable | |
36506 | 442 @env{$ORGANIZATION} or if that isn't set you are prompted for it. If the |
26463 | 443 buffer has a comment syntax (@pxref{(emacs)Comments}), this is inserted as a comment. |
25848 | 444 |
445 @findex copyright-update | |
446 @vindex copyright-limit | |
447 @vindex copyright-current-year | |
448 @kbd{M-x copyright-update} looks for a copyright notice in the first | |
449 @code{copyright-limit} characters of the buffer and updates it when necessary. | |
450 The current year (variable @code{copyright-current-year}) is added to the | |
451 existing ones, in the same format as the preceding year, i.e. 1994, '94 or 94. | |
452 If a dash-separated year list up to last year is found, that is extended to | |
453 current year, else the year is added separated by a comma. Or it replaces | |
454 them when this is called with a prefix argument. If a header referring to a | |
26463 | 455 wrong version of the GNU General Public License (@pxref{(emacs)Copying}) is found, |
25848 | 456 that is updated too. |
457 | |
458 An interesting application for this function is to have it be called | |
56097
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
459 automatically every time a file is saved. This is accomplished by |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
460 putting @code{(add-hook 'before-save-hook 'copyright-update)} into |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
461 your @file{~/.emacs} file (@pxref{(emacs)Init File}). Alternative, |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
462 you can do @kbd{M-x customize-variable @key{RET} before-save-hook |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
463 @key{RET}}. @code{copyright-update} is conveniently listed as an |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
464 option in the customization buffer. |
25848 | 465 |
466 @vindex copyright-query | |
467 The variable @code{copyright-query} controls whether to update the | |
468 copyright or whether to ask about it. When this is @code{nil} updating is | |
36506 | 469 only done with @kbd{M-x copyright-update}. When this is @code{function} |
25848 | 470 you are queried whenever @code{copyright-update} is called as a function, |
56097
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
471 such as in the @code{before-save-hook} feature mentioned above. Otherwise |
25848 | 472 you are always queried. |
473 | |
474 | |
475 | |
476 @node Executables | |
26151 | 477 @chapter Making Interpreter Scripts Executable |
25848 | 478 @cindex executables |
479 | |
480 @vindex executable-prefix | |
481 @vindex executable-chmod | |
36506 | 482 Various interpreter modes such as Shell script mode or AWK mode will |
483 automatically insert or update the buffer's magic number, a special | |
484 comment on the first line that makes the @code{exec} systemcall know | |
485 how to execute the script. To this end the script is automatically | |
486 made executable upon saving, with @code{executable-chmod} as argument | |
487 to the system @code{chmod} command. The magic number is prefixed by | |
488 the value of @code{executable-prefix}. | |
25848 | 489 |
490 @vindex executable-magicless-file-regexp | |
26151 | 491 Any file whose name matches @code{executable-magicless-file-regexp} is not |
25848 | 492 furnished with a magic number, nor is it made executable. This is mainly |
493 intended for resource files, which are only meant to be read in. | |
494 | |
495 @vindex executable-insert | |
496 The variable @code{executable-insert} says what to do when | |
497 @code{executable-set-magic} is called non-interactively, e.g. when file has no | |
498 or the wrong magic number: | |
36506 | 499 @table @asis |
500 @item @code{nil} | |
25848 | 501 Do nothing. |
36506 | 502 @item @code{t} |
25848 | 503 Insert or update magic number. |
504 @item other | |
505 Insert or update magic number, but mark as unmodified. | |
506 @end table | |
507 | |
508 @findex executable-set-magic | |
509 @vindex executable-query | |
510 The variable @code{executable-query} controls whether to ask about | |
511 inserting or updating the magic number. When this is @code{nil} updating | |
512 is only done with @kbd{M-x executable-set-magic}. When this is | |
36506 | 513 @code{function} you are queried whenever @code{executable-set-magic} is |
25848 | 514 called as a function, such as when Emacs puts a buffer in Shell script |
515 mode. Otherwise you are alway queried. | |
516 | |
517 @findex executable-self-display | |
518 @kbd{M-x executable-self-display} adds a magic number to the buffer, which | |
519 will turn it into a self displaying text file, when called as a Un*x command. | |
520 The ``interpreter'' used is @code{executable-self-display} with argument | |
36506 | 521 @samp{+2}. |
26151 | 522 |
523 @node Timestamps | |
524 @chapter Maintaining Timestamps in Modified Files | |
525 @cindex timestamps | |
526 | |
527 @findex time-stamp | |
56097
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
528 @vindex before-save-hook |
26151 | 529 The @code{time-stamp} command can be used to update automatically a |
530 template in a file with a new time stamp every time you save the file. | |
56097
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
531 Customize the hook @code{before-save-hook} to add the function |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
532 @code{time-stamp} to arrange this. It you use Custom to do this, |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
533 then @code{time-stamp} is conveniently listed as an option in the |
b5382c383798
(Copyrights, Timestamps): Recommend `before-save-hook' instead of
Luc Teirlinck <teirllm@auburn.edu>
parents:
55201
diff
changeset
|
534 customization buffer. |
26151 | 535 |
536 @vindex time-stamp-active | |
537 @vindex time-stamp-format | |
538 @vindex time-stamp-start | |
539 The time stamp is updated only if the customizable variable | |
540 @code{time-stamp-active} is on, which it is by default; the command | |
541 @code{time-stamp-toggle-active} can be used to toggle it. The format of | |
542 the time stamp is set by the customizable variable | |
543 @code{time-stamp-format}. | |
544 | |
545 @vindex time-stamp-line-limit | |
546 @vindex time-stamp-end | |
547 @vindex time-stamp-count | |
548 @vindex time-stamp-inserts-lines | |
549 The variables @code{time-stamp-line-limit}, @code{time-stamp-start}, | |
550 @code{time-stamp-end}, @code{time-stamp-count}, and | |
551 @code{time-stamp-inserts-lines} control finding the template. Do not | |
552 change these in your init file or you will be incompatible with other | |
553 people's files. If you must change them, do so only in the local | |
554 variables section of the file itself. | |
555 | |
556 Normally the template must appear in the first 8 lines of a file and | |
557 look like one of the following: | |
558 | |
559 @example | |
560 Time-stamp: <> | |
561 Time-stamp: " " | |
562 @end example | |
563 | |
564 The time stamp is written between the brackets or quotes: | |
565 | |
566 @example | |
567 Time-stamp: <1998-02-18 10:20:51 gildea> | |
568 @end example | |
569 | |
570 @node QuickURL | |
571 @chapter QuickURL: Inserting URLs Based on Text at Point | |
572 | |
573 @vindex quickurl-url-file | |
574 @findex quickurl | |
575 @cindex URLs | |
576 @kbd{M-x quickurl} can be used to insert a URL into a buffer based on | |
577 the text at point. The URLs are stored in an external file defined by | |
578 the variable @code{quickurl-url-file} as a list of either cons cells of | |
579 the form @code{(@var{key} . @var{URL})} or | |
580 lists of the form @code{(@var{key} @var{URL} @var{comment})}. These | |
581 specify that @kbd{M-x quickurl} should insert @var{URL} if the word | |
582 @var{key} is at point, for example: | |
583 | |
584 @example | |
585 (("FSF" "http://www.fsf.org/" "The Free Software Foundation") | |
586 ("emacs" . "http://www.emacs.org/") | |
587 ("hagbard" "http://www.hagbard.demon.co.uk" "Hagbard's World")) | |
588 @end example | |
589 | |
590 @findex quickurl-add-url | |
591 @findex quickurl-list | |
592 @kbd{M-x quickurl-add-url} can be used to add a new @var{key}/@var{URL} | |
593 pair. @kbd{M-x quickurl-list} provides interactive editing of the URL | |
594 list. | |
595 | |
596 @node Tempo | |
597 @chapter Tempo: Flexible Template Insertion | |
598 | |
599 @cindex templates | |
600 The Tempo package provides a simple way to define powerful templates, or | |
601 macros, if you wish. It is mainly intended for, but not limited to, | |
30870 | 602 programmers to be used for creating shortcuts for editing |
26151 | 603 certain kinds of documents. |
604 | |
605 @findex tempo-backward-mark | |
606 @findex tempo-forward-mark | |
607 A template is defined as a list of items to be inserted in the current | |
608 buffer at point. Some can be simple strings, while others can control | |
609 formatting or define special points of interest in the inserted text. | |
610 @kbd{M-x tempo-backward-mark} and @kbd{M-x tempo-forward-mark} can be | |
611 used to jump between such points. | |
612 | |
55201 | 613 More flexible templates can be created by including Lisp symbols, which |
36330
a16d8ed56e9c
(Autoinserting): Remove doubled `insert'.
Gerd Moellmann <gerd@gnu.org>
parents:
32315
diff
changeset
|
614 will be evaluated as variables, or lists, which will be evaluated |
55201 | 615 as Lisp expressions. Automatic completion of specified tags to expanded |
26151 | 616 templates can be provided. |
617 | |
618 @findex tempo-define-template | |
619 See the documentation for @code{tempo-define-template} for the different | |
620 items that can be used to define a tempo template with a command for | |
621 inserting it. | |
622 | |
623 See the commentary in @file{tempo.el} for more information on using the | |
624 Tempo package. | |
625 | |
626 @node Hippie Expand | |
627 @chapter `Hippie' Expansion | |
628 | |
629 @findex hippie-expand | |
630 @kindex M-/ | |
631 @vindex hippie-expand-try-functions-list | |
632 @kbd{M-x hippie-expand} is a single command providing a variety of | |
633 completions and expansions. Called repeatedly, it tries all possible | |
634 completions in succession. | |
635 | |
636 Which ones to try, and in which order, is determined by the contents of | |
637 the customizable option @code{hippie-expand-try-functions-list}. Much | |
38017
32f10000ac35
Don't use the British spelling of "behaviour".
Eli Zaretskii <eliz@gnu.org>
parents:
36506
diff
changeset
|
638 customization of the expansion behavior can be made by changing the |
26151 | 639 order of, removing, or inserting new functions in this list. Given a |
640 positive numeric argument, @kbd{M-x hippie-expand} jumps directly that | |
641 number of functions forward in this list. Given some other argument (a | |
642 negative argument or just @kbd{C-u}) it undoes the tried completion. | |
643 | |
644 See the commentary in @file{hippie-exp.el} for more information on the | |
645 possibilities. | |
646 | |
647 Typically you would bind @code{hippie-expand} to @kbd{M-/} with | |
648 @code{dabbrev-expand}, the standard binding of @kbd{M-/}, providing one | |
649 of the expansion possibilities. | |
650 | |
651 | |
652 @node Concept Index | |
653 @unnumbered Concept Index | |
654 @printindex cp | |
655 | |
656 @node Command Index | |
657 @unnumbered Command Index | |
658 @printindex fn | |
659 | |
660 @node Variable Index | |
661 @unnumbered Variable Index | |
662 @printindex vr | |
663 | |
29713 | 664 @setchapternewpage odd |
26151 | 665 @contents |
666 @bye | |
52401 | 667 |
668 @ignore | |
669 arch-tag: 54001b27-5ef8-4a9d-a199-905d650fafba | |
670 @end ignore |