Mercurial > emacs
annotate man/programs.texi @ 27687:ee4f82952cde
*** empty log message ***
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sat, 12 Feb 2000 19:50:59 +0000 |
parents | 4a723a7bc25a |
children | 6e740f27f255 |
rev | line source |
---|---|
25829 | 1 @c This is part of the Emacs manual. |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
2 @c Copyright (C) 1985,86,87,93,94,95,97,99,2000 Free Software Foundation, Inc. |
25829 | 3 @c See file emacs.texi for copying conditions. |
4 @node Programs, Building, Text, Top | |
5 @chapter Editing Programs | |
6 @cindex Lisp editing | |
7 @cindex C editing | |
8 @cindex program editing | |
9 | |
10 Emacs has many commands designed to understand the syntax of programming | |
11 languages such as Lisp and C. These commands can | |
12 | |
13 @itemize @bullet | |
14 @item | |
15 Move over or kill balanced expressions or @dfn{sexps} (@pxref{Lists}). | |
16 @item | |
17 Move over or mark top-level expressions---@dfn{defuns}, in Lisp; | |
18 functions, in C (@pxref{Defuns}). | |
19 @item | |
20 Show how parentheses balance (@pxref{Matching}). | |
21 @item | |
22 Insert, kill or align comments (@pxref{Comments}). | |
23 @item | |
24 Follow the usual indentation conventions of the language | |
25 (@pxref{Program Indent}). | |
26 @end itemize | |
27 | |
28 The commands for words, sentences and paragraphs are very useful in | |
29 editing code even though their canonical application is for editing | |
30 human language text. Most symbols contain words (@pxref{Words}); | |
31 sentences can be found in strings and comments (@pxref{Sentences}). | |
32 Paragraphs per se don't exist in code, but the paragraph commands are | |
33 useful anyway, because programming language major modes define | |
34 paragraphs to begin and end at blank lines (@pxref{Paragraphs}). | |
35 Judicious use of blank lines to make the program clearer will also | |
36 provide useful chunks of text for the paragraph commands to work | |
37 on. | |
38 | |
39 The selective display feature is useful for looking at the overall | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
40 structure of a function (@pxref{Selective Display}). This feature |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
41 causes only the lines that are indented less than a specified amount to |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
42 appear on the screen. Programming modes often support outline minor |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
43 mode (@pxref{Outline Mode}). |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
44 |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
45 The `automatic typing' features may be useful when writing programs. |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
46 @xref{Top, Autotyping, autotype, Features for Automatic Typing}. |
25829 | 47 |
48 @menu | |
49 * Program Modes:: Major modes for editing programs. | |
50 * Lists:: Expressions with balanced parentheses. | |
51 * List Commands:: The commands for working with list and sexps. | |
52 * Defuns:: Each program is made up of separate functions. | |
53 There are editing commands to operate on them. | |
54 * Program Indent:: Adjusting indentation to show the nesting. | |
55 * Matching:: Insertion of a close-delimiter flashes matching open. | |
56 * Comments:: Inserting, killing, and aligning comments. | |
57 * Balanced Editing:: Inserting two matching parentheses at once, etc. | |
58 * Symbol Completion:: Completion on symbol names of your program or language. | |
59 * Which Function:: Which Function mode shows which function you are in. | |
60 * Documentation:: Getting documentation of functions you plan to call. | |
61 * Change Log:: Maintaining a change history for your program. | |
62 * Tags:: Go direct to any function in your program in one | |
63 command. Tags remembers which file it is in. | |
64 * Emerge:: A convenient way of merging two versions of a program. | |
26264 | 65 * C Modes:: Special commands of C, C++, Objective-C, |
25829 | 66 Java, and Pike modes. |
67 * Fortran:: Fortran mode and its special features. | |
68 * Asm Mode:: Asm mode and its special features. | |
69 @end menu | |
70 | |
71 @node Program Modes | |
72 @section Major Modes for Programming Languages | |
73 | |
74 @cindex modes for programming languages | |
75 @cindex Perl mode | |
76 @cindex Icon mode | |
77 @cindex Awk mode | |
78 @cindex Makefile mode | |
79 @cindex Tcl mode | |
80 @cindex CPerl mode | |
26106 | 81 @cindex DSSSL mode |
82 @cindex Octave mode | |
83 @cindex Metafont mode | |
84 @cindex Modula2 mode | |
85 @cindex Prolog mode | |
86 @cindex Simula mode | |
87 @cindex VHDL mode | |
88 @cindex M4 mode | |
89 @cindex Shell-script mode | |
25829 | 90 Emacs also has major modes for the programming languages Lisp, Scheme |
26106 | 91 (a variant of Lisp) and the Scheme-based DSSSL expression language, Awk, |
92 C, C++, Fortran (free and fixed format), Icon, Java, Metafont (@TeX{}'s | |
93 +companion for font creation), Modula2, Objective-C, Octave, Pascal, | |
94 Perl, Pike, Prolog, Simula, VHDL, CORBA IDL, and Tcl. There is also a | |
95 major mode for makefiles, called Makefile mode. An alternative mode for | |
96 Perl is called CPerl mode. | |
25829 | 97 |
98 Ideally, a major mode should be implemented for each programming | |
99 language that you might want to edit with Emacs; but often the mode for | |
100 one language can serve for other syntactically similar languages. The | |
101 language modes that exist are those that someone decided to take the | |
102 trouble to write. | |
103 | |
104 There are several forms of Lisp mode, which differ in the way they | |
105 interface to Lisp execution. @xref{Executing Lisp}. | |
106 | |
107 Each of the programming language major modes defines the @key{TAB} key | |
108 to run an indentation function that knows the indentation conventions of | |
109 that language and updates the current line's indentation accordingly. | |
110 For example, in C mode @key{TAB} is bound to @code{c-indent-line}. | |
111 @kbd{C-j} is normally defined to do @key{RET} followed by @key{TAB}; | |
112 thus, it too indents in a mode-specific fashion. | |
113 | |
114 @kindex DEL @r{(programming modes)} | |
115 @findex backward-delete-char-untabify | |
116 In most programming languages, indentation is likely to vary from line to | |
117 line. So the major modes for those languages rebind @key{DEL} to treat a | |
118 tab as if it were the equivalent number of spaces (using the command | |
119 @code{backward-delete-char-untabify}). This makes it possible to rub out | |
120 indentation one column at a time without worrying whether it is made up of | |
121 spaces or tabs. Use @kbd{C-b C-d} to delete a tab character before point, | |
122 in these modes. | |
123 | |
124 Programming language modes define paragraphs to be separated only by | |
125 blank lines, so that the paragraph commands remain useful. Auto Fill mode, | |
126 if enabled in a programming language major mode, indents the new lines | |
127 which it creates. | |
128 | |
129 @cindex mode hook | |
130 @vindex c-mode-hook | |
131 @vindex lisp-mode-hook | |
132 @vindex emacs-lisp-mode-hook | |
133 @vindex lisp-interaction-mode-hook | |
134 @vindex scheme-mode-hook | |
135 @vindex muddle-mode-hook | |
136 Turning on a major mode runs a normal hook called the @dfn{mode hook}, | |
137 which is the value of a Lisp variable. Each major mode has a mode hook, | |
138 and the hook's name is always made from the mode command's name by | |
139 adding @samp{-hook}. For example, turning on C mode runs the hook | |
140 @code{c-mode-hook}, while turning on Lisp mode runs the hook | |
141 @code{lisp-mode-hook}. @xref{Hooks}. | |
142 | |
143 @node Lists | |
144 @section Lists and Sexps | |
145 | |
146 @cindex Control-Meta | |
147 By convention, Emacs keys for dealing with balanced expressions are | |
148 usually Control-Meta characters. They tend to be analogous in | |
149 function to their Control and Meta equivalents. These commands are | |
150 usually thought of as pertaining to expressions in programming | |
151 languages, but can be useful with any language in which some sort of | |
152 parentheses exist (including human languages). | |
153 | |
154 @cindex list | |
155 @cindex sexp | |
156 @cindex expression | |
157 @cindex parentheses, moving across | |
158 @cindex matching parenthesis, moving to | |
159 These commands fall into two classes. Some deal only with @dfn{lists} | |
160 (parenthetical groupings). They see nothing except parentheses, brackets, | |
161 braces (whichever ones must balance in the language you are working with), | |
162 and escape characters that might be used to quote those. | |
163 | |
164 The other commands deal with expressions or @dfn{sexps}. The word `sexp' | |
165 is derived from @dfn{s-expression}, the ancient term for an expression in | |
166 Lisp. But in Emacs, the notion of `sexp' is not limited to Lisp. It | |
167 refers to an expression in whatever language your program is written in. | |
168 Each programming language has its own major mode, which customizes the | |
169 syntax tables so that expressions in that language count as sexps. | |
170 | |
171 Sexps typically include symbols, numbers, and string constants, as well | |
172 as anything contained in parentheses, brackets or braces. | |
173 | |
174 In languages that use prefix and infix operators, such as C, it is not | |
175 possible for all expressions to be sexps. For example, C mode does not | |
176 recognize @samp{foo + bar} as a sexp, even though it @emph{is} a C expression; | |
177 it recognizes @samp{foo} as one sexp and @samp{bar} as another, with the | |
178 @samp{+} as punctuation between them. This is a fundamental ambiguity: | |
179 both @samp{foo + bar} and @samp{foo} are legitimate choices for the sexp to | |
180 move over if point is at the @samp{f}. Note that @samp{(foo + bar)} is a | |
181 single sexp in C mode. | |
182 | |
183 Some languages have obscure forms of expression syntax that nobody | |
184 has bothered to make Emacs understand properly. | |
185 | |
186 @node List Commands | |
187 @section List And Sexp Commands | |
188 | |
189 @c doublewidecommands | |
190 @table @kbd | |
191 @item C-M-f | |
192 Move forward over a sexp (@code{forward-sexp}). | |
193 @item C-M-b | |
194 Move backward over a sexp (@code{backward-sexp}). | |
195 @item C-M-k | |
196 Kill sexp forward (@code{kill-sexp}). | |
197 @item C-M-@key{DEL} | |
198 Kill sexp backward (@code{backward-kill-sexp}). | |
199 @item C-M-u | |
200 Move up and backward in list structure (@code{backward-up-list}). | |
201 @item C-M-d | |
202 Move down and forward in list structure (@code{down-list}). | |
203 @item C-M-n | |
204 Move forward over a list (@code{forward-list}). | |
205 @item C-M-p | |
206 Move backward over a list (@code{backward-list}). | |
207 @item C-M-t | |
208 Transpose expressions (@code{transpose-sexps}). | |
209 @item C-M-@@ | |
210 Put mark after following expression (@code{mark-sexp}). | |
211 @end table | |
212 | |
213 @kindex C-M-f | |
214 @kindex C-M-b | |
215 @findex forward-sexp | |
216 @findex backward-sexp | |
217 To move forward over a sexp, use @kbd{C-M-f} (@code{forward-sexp}). If | |
218 the first significant character after point is an opening delimiter | |
219 (@samp{(} in Lisp; @samp{(}, @samp{[} or @samp{@{} in C), @kbd{C-M-f} | |
220 moves past the matching closing delimiter. If the character begins a | |
221 symbol, string, or number, @kbd{C-M-f} moves over that. | |
222 | |
223 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a | |
224 sexp. The detailed rules are like those above for @kbd{C-M-f}, but with | |
225 directions reversed. If there are any prefix characters (single-quote, | |
226 backquote and comma, in Lisp) preceding the sexp, @kbd{C-M-b} moves back | |
227 over them as well. The sexp commands move across comments as if they | |
228 were whitespace in most modes. | |
229 | |
230 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the | |
231 specified number of times; with a negative argument, it moves in the | |
232 opposite direction. | |
233 | |
234 @kindex C-M-k | |
235 @findex kill-sexp | |
236 @kindex C-M-DEL | |
237 @findex backward-kill-sexp | |
238 Killing a whole sexp can be done with @kbd{C-M-k} (@code{kill-sexp}) | |
239 or @kbd{C-M-@key{DEL}} (@code{backward-kill-sexp}). @kbd{C-M-k} kills | |
240 the characters that @kbd{C-M-f} would move over, and @kbd{C-M-@key{DEL}} | |
241 kills the characters that @kbd{C-M-b} would move over. | |
242 | |
243 @kindex C-M-n | |
244 @kindex C-M-p | |
245 @findex forward-list | |
246 @findex backward-list | |
247 The @dfn{list commands} move over lists, as the sexp commands do, but skip | |
248 blithely over any number of other kinds of sexps (symbols, strings, etc.). | |
249 They are @kbd{C-M-n} (@code{forward-list}) and @kbd{C-M-p} | |
250 (@code{backward-list}). The main reason they are useful is that they | |
251 usually ignore comments (since the comments usually do not contain any | |
252 lists).@refill | |
253 | |
254 @kindex C-M-u | |
255 @kindex C-M-d | |
256 @findex backward-up-list | |
257 @findex down-list | |
258 @kbd{C-M-n} and @kbd{C-M-p} stay at the same level in parentheses, when | |
259 that's possible. To move @emph{up} one (or @var{n}) levels, use @kbd{C-M-u} | |
260 (@code{backward-up-list}). | |
261 @kbd{C-M-u} moves backward up past one unmatched opening delimiter. A | |
262 positive argument serves as a repeat count; a negative argument reverses | |
263 direction of motion and also requests repetition, so it moves forward and | |
264 up one or more levels.@refill | |
265 | |
266 To move @emph{down} in list structure, use @kbd{C-M-d} | |
267 (@code{down-list}). In Lisp mode, where @samp{(} is the only opening | |
268 delimiter, this is nearly the same as searching for a @samp{(}. An | |
269 argument specifies the number of levels of parentheses to go down. | |
270 | |
271 @cindex transposition | |
272 @kindex C-M-t | |
273 @findex transpose-sexps | |
274 A somewhat random-sounding command which is nevertheless handy is | |
275 @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous sexp | |
276 across the next one. An argument serves as a repeat count, and a | |
277 negative argument drags backwards (thus canceling out the effect of | |
278 @kbd{C-M-t} with a positive argument). An argument of zero, rather than | |
279 doing nothing, transposes the sexps ending after point and the mark. | |
280 | |
281 @kindex C-M-@@ | |
282 @findex mark-sexp | |
283 To set the region around the next sexp in the buffer, use @kbd{C-M-@@} | |
284 (@code{mark-sexp}), which sets mark at the same place that @kbd{C-M-f} | |
285 would move to. @kbd{C-M-@@} takes arguments like @kbd{C-M-f}. In | |
286 particular, a negative argument is useful for putting the mark at the | |
287 beginning of the previous sexp. | |
288 | |
289 The list and sexp commands' understanding of syntax is completely | |
290 controlled by the syntax table. Any character can, for example, be | |
291 declared to be an opening delimiter and act like an open parenthesis. | |
292 @xref{Syntax}. | |
293 | |
294 @node Defuns | |
295 @section Defuns | |
296 @cindex defuns | |
297 | |
298 In Emacs, a parenthetical grouping at the top level in the buffer is | |
299 called a @dfn{defun}. The name derives from the fact that most top-level | |
300 lists in a Lisp file are instances of the special form @code{defun}, but | |
301 any top-level parenthetical grouping counts as a defun in Emacs parlance | |
302 regardless of what its contents are, and regardless of the programming | |
303 language in use. For example, in C, the body of a function definition is a | |
304 defun. | |
305 | |
306 @c doublewidecommands | |
307 @table @kbd | |
308 @item C-M-a | |
309 Move to beginning of current or preceding defun | |
310 (@code{beginning-of-defun}). | |
311 @item C-M-e | |
312 Move to end of current or following defun (@code{end-of-defun}). | |
313 @item C-M-h | |
314 Put region around whole current or following defun (@code{mark-defun}). | |
315 @end table | |
316 | |
317 @kindex C-M-a | |
318 @kindex C-M-e | |
319 @kindex C-M-h | |
320 @findex beginning-of-defun | |
321 @findex end-of-defun | |
322 @findex mark-defun | |
323 The commands to move to the beginning and end of the current defun are | |
324 @kbd{C-M-a} (@code{beginning-of-defun}) and @kbd{C-M-e} (@code{end-of-defun}). | |
325 | |
326 @findex c-mark-function | |
327 If you wish to operate on the current defun, use @kbd{C-M-h} | |
328 (@code{mark-defun}) which puts point at the beginning and mark at the end | |
329 of the current or next defun. For example, this is the easiest way to get | |
330 ready to move the defun to a different place in the text. In C mode, | |
331 @kbd{C-M-h} runs the function @code{c-mark-function}, which is almost the | |
332 same as @code{mark-defun}; the difference is that it backs up over the | |
333 argument declarations, function name and returned data type so that the | |
334 entire C function is inside the region. @xref{Marking Objects}. | |
335 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
336 @cindex open-parenthesis in leftmost column |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
337 @cindex ( in leftmost column |
25829 | 338 Emacs assumes that any open-parenthesis found in the leftmost column |
339 is the start of a defun. Therefore, @strong{never put an | |
340 open-parenthesis at the left margin in a Lisp file unless it is the | |
341 start of a top-level list. Never put an open-brace or other opening | |
342 delimiter at the beginning of a line of C code unless it starts the body | |
343 of a function.} The most likely problem case is when you want an | |
344 opening delimiter at the start of a line inside a string. To avoid | |
345 trouble, put an escape character (@samp{\}, in C and Emacs Lisp, | |
346 @samp{/} in some other Lisp dialects) before the opening delimiter. It | |
347 will not affect the contents of the string. | |
348 | |
349 In the remotest past, the original Emacs found defuns by moving upward a | |
350 level of parentheses until there were no more levels to go up. This always | |
351 required scanning all the way back to the beginning of the buffer, even for | |
352 a small function. To speed up the operation, Emacs was changed to assume | |
353 that any @samp{(} (or other character assigned the syntactic class of | |
354 opening-delimiter) at the left margin is the start of a defun. This | |
355 heuristic is nearly always right and avoids the costly scan; however, | |
356 it mandates the convention described above. | |
357 | |
358 @node Program Indent | |
359 @section Indentation for Programs | |
360 @cindex indentation for programs | |
361 | |
362 The best way to keep a program properly indented is to use Emacs to | |
363 reindent it as you change it. Emacs has commands to indent properly | |
364 either a single line, a specified number of lines, or all of the lines | |
365 inside a single parenthetical grouping. | |
366 | |
367 @menu | |
368 * Basic Indent:: Indenting a single line. | |
369 * Multi-line Indent:: Commands to reindent many lines at once. | |
370 * Lisp Indent:: Specifying how each Lisp function should be indented. | |
371 * C Indent:: Extra features for indenting C and related modes. | |
372 * Custom C Indent:: Controlling indentation style for C and related modes. | |
373 @end menu | |
374 | |
375 Emacs also provides a Lisp pretty-printer in the library @code{pp}. | |
376 This program reformats a Lisp object with indentation chosen to look nice. | |
377 | |
378 @node Basic Indent | |
379 @subsection Basic Program Indentation Commands | |
380 | |
381 @c WideCommands | |
382 @table @kbd | |
383 @item @key{TAB} | |
384 Adjust indentation of current line. | |
385 @item C-j | |
386 Equivalent to @key{RET} followed by @key{TAB} (@code{newline-and-indent}). | |
387 @end table | |
388 | |
389 @kindex TAB @r{(programming modes)} | |
390 @findex c-indent-line | |
391 @findex lisp-indent-line | |
392 The basic indentation command is @key{TAB}, which gives the current line | |
393 the correct indentation as determined from the previous lines. The | |
394 function that @key{TAB} runs depends on the major mode; it is @code{lisp-indent-line} | |
395 in Lisp mode, @code{c-indent-line} in C mode, etc. These functions | |
396 understand different syntaxes for different languages, but they all do | |
397 about the same thing. @key{TAB} in any programming-language major mode | |
398 inserts or deletes whitespace at the beginning of the current line, | |
399 independent of where point is in the line. If point is inside the | |
400 whitespace at the beginning of the line, @key{TAB} leaves it at the end of | |
401 that whitespace; otherwise, @key{TAB} leaves point fixed with respect to | |
402 the characters around it. | |
403 | |
404 Use @kbd{C-q @key{TAB}} to insert a tab at point. | |
405 | |
406 @kindex C-j | |
407 @findex newline-and-indent | |
408 When entering lines of new code, use @kbd{C-j} (@code{newline-and-indent}), | |
409 which is equivalent to a @key{RET} followed by a @key{TAB}. @kbd{C-j} creates | |
410 a blank line and then gives it the appropriate indentation. | |
411 | |
412 @key{TAB} indents the second and following lines of the body of a | |
413 parenthetical grouping each under the preceding one; therefore, if you | |
414 alter one line's indentation to be nonstandard, the lines below will | |
415 tend to follow it. This behavior is convenient in cases where you have | |
416 overridden the standard result of @key{TAB} because you find it | |
417 unaesthetic for a particular line. | |
418 | |
419 Remember that an open-parenthesis, open-brace or other opening delimiter | |
420 at the left margin is assumed by Emacs (including the indentation routines) | |
421 to be the start of a function. Therefore, you must never have an opening | |
422 delimiter in column zero that is not the beginning of a function, not even | |
423 inside a string. This restriction is vital for making the indentation | |
424 commands fast; you must simply accept it. @xref{Defuns}, for more | |
425 information on this. | |
426 | |
427 @node Multi-line Indent | |
428 @subsection Indenting Several Lines | |
429 | |
430 When you wish to reindent several lines of code which have been altered | |
431 or moved to a different level in the list structure, you have several | |
432 commands available. | |
433 | |
434 @table @kbd | |
435 @item C-M-q | |
436 Reindent all the lines within one list (@code{indent-sexp}). | |
437 @item C-u @key{TAB} | |
438 Shift an entire list rigidly sideways so that its first line | |
439 is properly indented. | |
440 @item C-M-\ | |
441 Reindent all lines in the region (@code{indent-region}). | |
442 @end table | |
443 | |
444 @kindex C-M-q | |
445 @findex indent-sexp | |
446 You can reindent the contents of a single list by positioning point | |
447 before the beginning of it and typing @kbd{C-M-q} (@code{indent-sexp} in | |
448 Lisp mode, @code{c-indent-exp} in C mode; also bound to other suitable | |
449 commands in other modes). The indentation of the line the sexp starts on | |
450 is not changed; therefore, only the relative indentation within the list, | |
451 and not its position, is changed. To correct the position as well, type a | |
452 @key{TAB} before the @kbd{C-M-q}. | |
453 | |
454 @kindex C-u TAB | |
455 If the relative indentation within a list is correct but the | |
456 indentation of its first line is not, go to that line and type @kbd{C-u | |
457 @key{TAB}}. @key{TAB} with a numeric argument reindents the current | |
458 line as usual, then reindents by the same amount all the lines in the | |
459 grouping starting on the current line. In other words, it reindents the | |
460 whole grouping rigidly as a unit. It is clever, though, and does not | |
461 alter lines that start inside strings, or C preprocessor lines when in C | |
462 mode. | |
463 | |
464 Another way to specify the range to be reindented is with the region. | |
465 The command @kbd{C-M-\} (@code{indent-region}) applies @key{TAB} to | |
466 every line whose first character is between point and mark. | |
467 | |
468 @node Lisp Indent | |
469 @subsection Customizing Lisp Indentation | |
470 @cindex customizing Lisp indentation | |
471 | |
472 The indentation pattern for a Lisp expression can depend on the function | |
473 called by the expression. For each Lisp function, you can choose among | |
474 several predefined patterns of indentation, or define an arbitrary one with | |
475 a Lisp program. | |
476 | |
477 The standard pattern of indentation is as follows: the second line of the | |
478 expression is indented under the first argument, if that is on the same | |
479 line as the beginning of the expression; otherwise, the second line is | |
480 indented underneath the function name. Each following line is indented | |
481 under the previous line whose nesting depth is the same. | |
482 | |
483 @vindex lisp-indent-offset | |
484 If the variable @code{lisp-indent-offset} is non-@code{nil}, it overrides | |
485 the usual indentation pattern for the second line of an expression, so that | |
486 such lines are always indented @code{lisp-indent-offset} more columns than | |
487 the containing list. | |
488 | |
489 @vindex lisp-body-indent | |
490 The standard pattern is overridden for certain functions. Functions | |
491 whose names start with @code{def} always indent the second line by | |
492 @code{lisp-body-indent} extra columns beyond the open-parenthesis | |
493 starting the expression. | |
494 | |
495 The standard pattern can be overridden in various ways for individual | |
496 functions, according to the @code{lisp-indent-function} property of the | |
497 function name. There are four possibilities for this property: | |
498 | |
499 @table @asis | |
500 @item @code{nil} | |
501 This is the same as no property; the standard indentation pattern is used. | |
502 @item @code{defun} | |
503 The pattern used for function names that start with @code{def} is used for | |
504 this function also. | |
505 @item a number, @var{number} | |
506 The first @var{number} arguments of the function are | |
507 @dfn{distinguished} arguments; the rest are considered the @dfn{body} | |
508 of the expression. A line in the expression is indented according to | |
509 whether the first argument on it is distinguished or not. If the | |
510 argument is part of the body, the line is indented @code{lisp-body-indent} | |
511 more columns than the open-parenthesis starting the containing | |
512 expression. If the argument is distinguished and is either the first | |
513 or second argument, it is indented @emph{twice} that many extra columns. | |
514 If the argument is distinguished and not the first or second argument, | |
515 the standard pattern is followed for that line. | |
516 @item a symbol, @var{symbol} | |
517 @var{symbol} should be a function name; that function is called to | |
518 calculate the indentation of a line within this expression. The | |
519 function receives two arguments: | |
520 @table @asis | |
521 @item @var{state} | |
522 The value returned by @code{parse-partial-sexp} (a Lisp primitive for | |
523 indentation and nesting computation) when it parses up to the | |
524 beginning of this line. | |
525 @item @var{pos} | |
526 The position at which the line being indented begins. | |
527 @end table | |
528 @noindent | |
529 It should return either a number, which is the number of columns of | |
530 indentation for that line, or a list whose car is such a number. The | |
531 difference between returning a number and returning a list is that a | |
532 number says that all following lines at the same nesting level should | |
533 be indented just like this one; a list says that following lines might | |
534 call for different indentations. This makes a difference when the | |
535 indentation is being computed by @kbd{C-M-q}; if the value is a | |
536 number, @kbd{C-M-q} need not recalculate indentation for the following | |
537 lines until the end of the list. | |
538 @end table | |
539 | |
540 @node C Indent | |
541 @subsection Commands for C Indentation | |
542 | |
543 Here are the commands for indentation in C mode and related modes: | |
544 | |
545 @table @code | |
546 @item C-c C-q | |
547 @kindex C-c C-q @r{(C mode)} | |
548 @findex c-indent-defun | |
549 Reindent the current top-level function definition or aggregate type | |
550 declaration (@code{c-indent-defun}). | |
551 | |
552 @item C-M-q | |
553 @kindex C-M-q @r{(C mode)} | |
554 @findex c-indent-exp | |
555 Reindent each line in the balanced expression that follows point | |
556 (@code{c-indent-exp}). A prefix argument inhibits error checking and | |
557 warning messages about invalid syntax. | |
558 | |
559 @item @key{TAB} | |
560 @findex c-indent-command | |
561 Reindent the current line, and/or in some cases insert a tab character | |
562 (@code{c-indent-command}). | |
563 | |
564 If @code{c-tab-always-indent} is @code{t}, this command always reindents | |
565 the current line and does nothing else. This is the default. | |
566 | |
567 If that variable is @code{nil}, this command reindents the current line | |
568 only if point is at the left margin or in the line's indentation; | |
569 otherwise, it inserts a tab (or the equivalent number of spaces, | |
570 if @code{indent-tabs-mode} is @code{nil}). | |
571 | |
572 Any other value (not @code{nil} or @code{t}) means always reindent the | |
573 line, and also insert a tab if within a comment, a string, or a | |
574 preprocessor directive. | |
575 | |
576 @item C-u @key{TAB} | |
577 Reindent the current line according to its syntax; also rigidly reindent | |
578 any other lines of the expression that starts on the current line. | |
579 @xref{Multi-line Indent}. | |
580 @end table | |
581 | |
582 To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This | |
583 first selects the whole buffer as the region, then reindents that | |
584 region. | |
585 | |
586 To reindent the current block, use @kbd{C-M-u C-M-q}. This moves | |
587 to the front of the block and then reindents it all. | |
588 | |
589 @node Custom C Indent | |
590 @subsection Customizing C Indentation | |
591 | |
592 C mode and related modes use a simple yet flexible mechanism for | |
593 customizing indentation. The mechanism works in two steps: first it | |
594 classifies the line syntactically according to its contents and context; | |
595 second, it associates each kind of syntactic construct with an | |
596 indentation offset which you can customize. | |
597 | |
598 @menu | |
599 * Syntactic Analysis:: | |
600 * Indentation Calculation:: | |
601 * Changing Indent Style:: | |
602 * Syntactic Symbols:: | |
603 * Variables for C Indent:: | |
604 * C Indent Styles:: | |
605 @end menu | |
606 | |
607 @node Syntactic Analysis | |
608 @subsubsection Step 1---Syntactic Analysis | |
609 @cindex syntactic analysis | |
610 | |
611 In the first step, the C indentation mechanism looks at the line | |
612 before the one you are currently indenting and determines the syntactic | |
613 components of the construct on that line. It builds a list of these | |
614 syntactic components, each of which contains a @dfn{syntactic symbol} | |
615 and sometimes also a buffer position. Some syntactic symbols describe | |
616 grammatical elements, for example @code{statement} and | |
617 @code{substatement}; others describe locations amidst grammatical | |
618 elements, for example @code{class-open} and @code{knr-argdecl}. | |
619 | |
620 Conceptually, a line of C code is always indented relative to the | |
621 indentation of some line higher up in the buffer. This is represented | |
622 by the buffer positions in the syntactic component list. | |
623 | |
624 Here is an example. Suppose we have the following code in a C++ mode | |
625 buffer (the line numbers don't actually appear in the buffer): | |
626 | |
627 @example | |
628 1: void swap (int& a, int& b) | |
629 2: @{ | |
630 3: int tmp = a; | |
631 4: a = b; | |
632 5: b = tmp; | |
633 6: @} | |
634 @end example | |
635 | |
636 If you type @kbd{C-c C-s} (which runs the command | |
637 @code{c-show-syntactic-information}) on line 4, it shows the result of | |
638 the indentation mechanism for that line: | |
639 | |
640 @example | |
641 ((statement . 32)) | |
642 @end example | |
643 | |
644 This indicates that the line is a statement and it is indented | |
645 relative to buffer position 32, which happens to be the @samp{i} in | |
646 @code{int} on line 3. If you move the cursor to line 3 and type | |
647 @kbd{C-c C-s}, it displays this: | |
648 | |
649 @example | |
650 ((defun-block-intro . 28)) | |
651 @end example | |
652 | |
653 This indicates that the @code{int} line is the first statement in a | |
654 block, and is indented relative to buffer position 28, which is the | |
655 brace just after the function header. | |
656 | |
657 @noindent | |
658 Here is another example: | |
659 | |
660 @example | |
661 1: int add (int val, int incr, int doit) | |
662 2: @{ | |
663 3: if (doit) | |
664 4: @{ | |
665 5: return (val + incr); | |
666 6: @} | |
667 7: return (val); | |
668 8: @} | |
669 @end example | |
670 | |
671 @noindent | |
672 Typing @kbd{C-c C-s} on line 4 displays this: | |
673 | |
674 @example | |
675 ((substatement-open . 43)) | |
676 @end example | |
677 | |
678 This says that the brace @emph{opens} a substatement block. By the | |
679 way, a @dfn{substatement} indicates the line after an @code{if}, | |
680 @code{else}, @code{while}, @code{do}, @code{switch}, @code{for}, | |
681 @code{try}, @code{catch}, @code{finally}, or @code{synchronized} | |
682 statement. | |
683 | |
684 @cindex syntactic component | |
685 @cindex syntactic symbol | |
686 @vindex c-syntactic-context | |
687 Within the C indentation commands, after a line has been analyzed | |
688 syntactically for indentation, the variable @code{c-syntactic-context} | |
689 contains a list that describes the results. Each element in this list | |
690 is a @dfn{syntactic component}: a cons cell containing a syntactic | |
691 symbol and (optionally) its corresponding buffer position. There may be | |
692 several elements in a component list; typically only one element has a | |
693 buffer position. | |
694 | |
695 @node Indentation Calculation | |
696 @subsubsection Step 2---Indentation Calculation | |
697 @cindex Indentation Calculation | |
698 | |
699 The C indentation mechanism calculates the indentation for the current | |
700 line using the list of syntactic components, @code{c-syntactic-context}, | |
701 derived from syntactic analysis. Each component is a cons cell that | |
702 contains a syntactic symbol and may also contain a buffer position. | |
703 | |
704 Each component contributes to the final total indentation of the line | |
705 in two ways. First, the syntactic symbol identifies an element of | |
706 @code{c-offsets-alist}, which is an association list mapping syntactic | |
707 symbols into indentation offsets. Each syntactic symbol's offset adds | |
708 to the total indentation. Second, if the component includes a buffer | |
709 position, the column number of that position adds to the indentation. | |
710 All these offsets and column numbers, added together, give the total | |
711 indentation. | |
712 | |
713 The following examples demonstrate the workings of the C indentation | |
714 mechanism: | |
715 | |
716 @example | |
717 1: void swap (int& a, int& b) | |
718 2: @{ | |
719 3: int tmp = a; | |
720 4: a = b; | |
721 5: b = tmp; | |
722 6: @} | |
723 @end example | |
724 | |
725 Suppose that point is on line 3 and you type @key{TAB} to reindent the | |
726 line. As explained above (@pxref{Syntactic Analysis}), the syntactic | |
727 component list for that line is: | |
728 | |
729 @example | |
730 ((defun-block-intro . 28)) | |
731 @end example | |
732 | |
733 In this case, the indentation calculation first looks up | |
734 @code{defun-block-intro} in the @code{c-offsets-alist} alist. Suppose | |
735 that it finds the integer 2; it adds this to the running total | |
736 (initialized to zero), yielding a updated total indentation of 2 spaces. | |
737 | |
738 The next step is to find the column number of buffer position 28. | |
739 Since the brace at buffer position 28 is in column zero, this adds 0 to | |
740 the running total. Since this line has only one syntactic component, | |
741 the total indentation for the line is 2 spaces. | |
742 | |
743 @example | |
744 1: int add (int val, int incr, int doit) | |
745 2: @{ | |
746 3: if (doit) | |
747 4: @{ | |
748 5: return(val + incr); | |
749 6: @} | |
750 7: return(val); | |
751 8: @} | |
752 @end example | |
753 | |
754 If you type @key{TAB} on line 4, the same process is performed, but | |
755 with different data. The syntactic component list for this line is: | |
756 | |
757 @example | |
758 ((substatement-open . 43)) | |
759 @end example | |
760 | |
761 Here, the indentation calculation's first job is to look up the | |
762 symbol @code{substatement-open} in @code{c-offsets-alist}. Let's assume | |
763 that the offset for this symbol is 2. At this point the running total | |
764 is 2 (0 + 2 = 2). Then it adds the column number of buffer position 43, | |
765 which is the @samp{i} in @code{if} on line 3. This character is in | |
766 column 2 on that line. Adding this yields a total indentation of 4 | |
767 spaces. | |
768 | |
769 @vindex c-strict-syntax-p | |
770 If a syntactic symbol in the analysis of a line does not appear in | |
771 @code{c-offsets-alist}, it is ignored; if in addition the variable | |
772 @code{c-strict-syntax-p} is non-@code{nil}, it is an error. | |
773 | |
774 @node Changing Indent Style | |
775 @subsubsection Changing Indentation Style | |
776 | |
777 There are two ways to customize the indentation style for the C-like | |
778 modes. First, you can select one of several predefined styles, each of | |
779 which specifies offsets for all the syntactic symbols. For more | |
780 flexibility, you can customize the handling of individual syntactic | |
781 symbols. @xref{Syntactic Symbols}, for a list of all defined syntactic | |
782 symbols. | |
783 | |
784 @table @kbd | |
785 @item M-x c-set-style @key{RET} @var{style} @key{RET} | |
786 Select predefined indentation style @var{style}. Type @kbd{?} when | |
787 entering @var{style} to see a list of supported styles; to find out what | |
788 a style looks like, select it and reindent some C code. | |
789 | |
790 @item C-c C-o @var{symbol} @key{RET} @var{offset} @key{RET} | |
791 Set the indentation offset for syntactic symbol @var{symbol} | |
792 (@code{c-set-offset}). The second argument @var{offset} specifies the | |
793 new indentation offset. | |
794 @end table | |
795 | |
796 The @code{c-offsets-alist} variable controls the amount of | |
797 indentation to give to each syntactic symbol. Its value is an | |
798 association list, and each element of the list has the form | |
799 @code{(@var{syntactic-symbol} . @var{offset})}. By changing the offsets | |
800 for various syntactic symbols, you can customize indentation in fine | |
801 detail. To change this alist, use @code{c-set-offset} (see below). | |
802 | |
803 Each offset value in @code{c-offsets-alist} can be an integer, a | |
804 function or variable name, a list, or one of the following symbols: @code{+}, | |
805 @code{-}, @code{++}, @code{--}, @code{*}, or @code{/}, indicating positive or negative | |
806 multiples of the variable @code{c-basic-offset}. Thus, if you want to | |
807 change the levels of indentation to be 3 spaces instead of 2 spaces, set | |
808 @code{c-basic-offset} to 3. | |
809 | |
810 Using a function as the offset value provides the ultimate flexibility | |
811 in customizing indentation. The function is called with a single | |
812 argument containing the @code{cons} of the syntactic symbol and | |
813 the buffer position, if any. The function should return an integer | |
814 offset. | |
26264 | 815 |
25829 | 816 If the offset value is a list, its elements are processed according |
817 to the rules above until a non-@code{nil} value is found. That value is | |
818 then added to the total indentation in the normal manner. The primary | |
819 use for this is to combine the results of several functions. | |
820 | |
821 @kindex C-c C-o @r{(C mode)} | |
822 @findex c-set-offset | |
823 The command @kbd{C-c C-o} (@code{c-set-offset}) is the easiest way to | |
824 set offsets, both interactively or in your @file{~/.emacs} file. First | |
825 specify the syntactic symbol, then the offset you want. @xref{Syntactic | |
826 Symbols}, for a list of valid syntactic symbols and their meanings. | |
827 | |
828 @node Syntactic Symbols | |
829 @subsubsection Syntactic Symbols | |
830 | |
831 Here is a table of valid syntactic symbols for indentation in C and | |
832 related modes, with their syntactic meanings. Normally, most of these | |
833 symbols are assigned offsets in @code{c-offsets-alist}. | |
834 | |
835 @table @code | |
836 @item string | |
837 Inside a multi-line string. | |
838 | |
839 @item c | |
840 Inside a multi-line C style block comment. | |
841 | |
842 @item defun-open | |
843 On a brace that opens a function definition. | |
844 | |
845 @item defun-close | |
846 On a brace that closes a function definition. | |
847 | |
848 @item defun-block-intro | |
849 In the first line in a top-level defun. | |
850 | |
851 @item class-open | |
852 On a brace that opens a class definition. | |
853 | |
854 @item class-close | |
855 On a brace that closes a class definition. | |
856 | |
857 @item inline-open | |
858 On a brace that opens an in-class inline method. | |
859 | |
860 @item inline-close | |
861 On a brace that closes an in-class inline method. | |
862 | |
863 @item extern-lang-open | |
864 On a brace that opens an external language block. | |
865 | |
866 @item extern-lang-close | |
867 On a brace that closes an external language block. | |
868 | |
869 @item func-decl-cont | |
870 The region between a function definition's argument list and the defun | |
871 opening brace (excluding K&R function definitions). In C, you cannot | |
872 put anything but whitespace and comments between them; in C++ and Java, | |
873 @code{throws} declarations and other things can appear in this context. | |
874 | |
875 @item knr-argdecl-intro | |
876 On the first line of a K&R C argument declaration. | |
877 | |
878 @item knr-argdecl | |
879 In one of the subsequent lines in a K&R C argument declaration. | |
880 | |
881 @item topmost-intro | |
882 On the first line in a topmost construct definition. | |
883 | |
884 @item topmost-intro-cont | |
885 On the topmost definition continuation lines. | |
886 | |
887 @item member-init-intro | |
888 On the first line in a member initialization list. | |
889 | |
890 @item member-init-cont | |
891 On one of the subsequent member initialization list lines. | |
892 | |
893 @item inher-intro | |
894 On the first line of a multiple inheritance list. | |
895 | |
896 @item inher-cont | |
897 On one of the subsequent multiple inheritance lines. | |
898 | |
899 @item block-open | |
900 On a statement block open brace. | |
901 | |
902 @item block-close | |
903 On a statement block close brace. | |
904 | |
905 @item brace-list-open | |
906 On the opening brace of an @code{enum} or @code{static} array list. | |
907 | |
908 @item brace-list-close | |
909 On the closing brace of an @code{enum} or @code{static} array list. | |
910 | |
911 @item brace-list-intro | |
912 On the first line in an @code{enum} or @code{static} array list. | |
913 | |
914 @item brace-list-entry | |
915 On one of the subsequent lines in an @code{enum} or @code{static} array | |
916 list. | |
917 | |
918 @item brace-entry-open | |
919 On one of the subsequent lines in an @code{enum} or @code{static} array | |
920 list, when the line begins with an open brace. | |
921 | |
922 @item statement | |
923 On an ordinary statement. | |
924 | |
925 @item statement-cont | |
926 On a continuation line of a statement. | |
927 | |
928 @item statement-block-intro | |
929 On the first line in a new statement block. | |
930 | |
931 @item statement-case-intro | |
932 On the first line in a @code{case} ``block.'' | |
933 | |
934 @item statement-case-open | |
935 On the first line in a @code{case} block starting with brace. | |
936 | |
937 @item inexpr-statement | |
938 On a statement block inside an expression. This is used for a GNU | |
939 extension to the C language, and for Pike special functions that take a | |
940 statement block as an argument. | |
941 | |
942 @item inexpr-class | |
943 On a class definition inside an expression. This is used for anonymous | |
944 classes and anonymous array initializers in Java. | |
945 | |
946 @item substatement | |
947 On the first line after an @code{if}, @code{while}, @code{for}, | |
948 @code{do}, or @code{else}. | |
949 | |
950 @item substatement-open | |
951 On the brace that opens a substatement block. | |
952 | |
953 @item case-label | |
954 On a @code{case} or @code{default} label. | |
955 | |
956 @item access-label | |
957 On a C++ @code{private}, @code{protected}, or @code{public} access label. | |
958 | |
959 @item label | |
960 On any ordinary label. | |
961 | |
962 @item do-while-closure | |
963 On the @code{while} that ends a @code{do}-@code{while} construct. | |
964 | |
965 @item else-clause | |
966 On the @code{else} of an @code{if}-@code{else} construct. | |
967 | |
968 @item catch-clause | |
969 On the @code{catch} and @code{finally} lines in | |
970 @code{try}@dots{}@code{catch} constructs in C++ and Java. | |
971 | |
972 @item comment-intro | |
973 On a line containing only a comment introduction. | |
974 | |
975 @item arglist-intro | |
976 On the first line in an argument list. | |
977 | |
978 @item arglist-cont | |
979 On one of the subsequent argument list lines when no arguments follow on | |
980 the same line as the arglist opening parenthesis. | |
981 | |
982 @item arglist-cont-nonempty | |
983 On one of the subsequent argument list lines when at least one argument | |
984 follows on the same line as the arglist opening parenthesis. | |
985 | |
986 @item arglist-close | |
987 On the closing parenthesis of an argument list. | |
988 | |
989 @item stream-op | |
990 On one of the lines continuing a stream operator construct. | |
991 | |
992 @item inclass | |
993 On a construct that is nested inside a class definition. The | |
994 indentation is relative to the open brace of the class definition. | |
995 | |
996 @item inextern-lang | |
997 On a construct that is nested inside an external language block. | |
998 | |
999 @item inexpr-statement | |
1000 On the first line of statement block inside an expression. This is used | |
1001 for the GCC extension to C that uses the syntax @code{(@{ @dots{} @})}. | |
1002 It is also used for the special functions that takes a statement block | |
1003 as an argument in Pike. | |
1004 | |
1005 @item inexpr-class | |
1006 On the first line of a class definition inside an expression. This is | |
1007 used for anonymous classes and anonymous array initializers in Java. | |
1008 | |
1009 @item cpp-macro | |
1010 On the start of a cpp macro. | |
1011 | |
1012 @item friend | |
1013 On a C++ @code{friend} declaration. | |
1014 | |
1015 @item objc-method-intro | |
1016 On the first line of an Objective-C method definition. | |
1017 | |
1018 @item objc-method-args-cont | |
1019 On one of the lines continuing an Objective-C method definition. | |
1020 | |
1021 @item objc-method-call-cont | |
1022 On one of the lines continuing an Objective-C method call. | |
1023 | |
1024 @item inlambda | |
1025 Like @code{inclass}, but used inside lambda (i.e. anonymous) functions. Only | |
1026 used in Pike. | |
1027 | |
1028 @item lambda-intro-cont | |
1029 On a line continuing the header of a lambda function, between the | |
1030 @code{lambda} keyword and the function body. Only used in Pike. | |
1031 @end table | |
1032 | |
1033 @node Variables for C Indent | |
1034 @subsubsection Variables for C Indentation | |
1035 | |
1036 This section describes additional variables which control the | |
1037 indentation behavior of C mode and related mode. | |
1038 | |
1039 @table @code | |
1040 @item c-offsets-alist | |
1041 @vindex c-offsets-alist | |
1042 Association list of syntactic symbols and their indentation offsets. | |
1043 You should not set this directly, only with @code{c-set-offset}. | |
1044 @xref{Changing Indent Style}, for details. | |
1045 | |
1046 @item c-style-alist | |
1047 @vindex c-style-alist | |
1048 Variable for defining indentation styles; see below. | |
1049 | |
1050 @item c-basic-offset | |
1051 @vindex c-basic-offset | |
1052 Amount of basic offset used by @code{+} and @code{-} symbols in | |
26264 | 1053 @code{c-offsets-alist}.@refill |
25829 | 1054 |
1055 @item c-special-indent-hook | |
1056 @vindex c-special-indent-hook | |
1057 Hook for user-defined special indentation adjustments. This hook is | |
1058 called after a line is indented by C mode and related modes. | |
1059 @end table | |
1060 | |
1061 The variable @code{c-style-alist} specifies the predefined indentation | |
1062 styles. Each element has form @code{(@var{name} | |
1063 @var{variable-setting}@dots{})}, where @var{name} is the name of the | |
1064 style. Each @var{variable-setting} has the form @code{(@var{variable} | |
1065 . @var{value})}; @var{variable} is one of the customization variables | |
1066 used by C mode, and @var{value} is the value for that variable when | |
1067 using the selected style. | |
1068 | |
1069 When @var{variable} is @code{c-offsets-alist}, that is a special case: | |
1070 @var{value} is appended to the front of the value of @code{c-offsets-alist} | |
1071 instead of replacing that value outright. Therefore, it is not necessary | |
1072 for @var{value} to specify each and every syntactic symbol---only those | |
1073 for which the style differs from the default. | |
1074 | |
1075 The indentation of lines containing only comments is also affected by | |
1076 the variable @code{c-comment-only-line-offset} (@pxref{Comments in C}). | |
1077 | |
1078 @node C Indent Styles | |
1079 @subsubsection C Indentation Styles | |
1080 @cindex c indentation styles | |
1081 | |
1082 A @dfn{C style} is a collection of indentation style customizations. | |
1083 Emacs comes with several predefined indentation styles for C and related | |
1084 modes, including @code{gnu}, @code{k&r}, @code{bsd}, @code{stroustrup}, | |
1085 @code{linux}, @code{python}, @code{java}, @code{whitesmith}, | |
1086 @code{ellemtel}, and @code{cc-mode}. The default style is @code{gnu}. | |
1087 | |
1088 @findex c-set-style | |
1089 @vindex c-default-style | |
1090 To choose the style you want, use the command @kbd{M-x c-set-style}. | |
1091 Specify a style name as an argument (case is not significant in C style | |
1092 names). The chosen style only affects newly visited buffers, not those | |
1093 you are already editing. You can also set the variable | |
1094 @code{c-default-style} to specify the style for various major modes. | |
1095 Its value should be an alist, in which each element specifies one major | |
1096 mode and which indentation style to use for it. For example, | |
1097 | |
1098 @example | |
1099 (setq c-default-style | |
1100 '((java-mode . "java") (other . "gnu"))) | |
1101 @end example | |
1102 | |
1103 @noindent | |
1104 specifies an explicit choice for Java mode, and the default @samp{gnu} | |
1105 style for the other C-like modes. | |
1106 | |
1107 @findex c-add-style | |
1108 To define a new C indentation style, call the function | |
1109 @code{c-add-style}: | |
1110 | |
1111 @example | |
1112 (c-add-style @var{name} @var{values} @var{use-now}) | |
1113 @end example | |
1114 | |
1115 @noindent | |
1116 Here @var{name} is the name of the new style (a string), and | |
1117 @var{values} is an alist whose elements have the form | |
1118 @code{(@var{variable} . @var{value})}. The variables you specify should | |
1119 be among those documented in @ref{Variables for C Indent}. | |
1120 | |
1121 If @var{use-now} is non-@code{nil}, @code{c-add-style} switches to the | |
1122 new style after defining it. | |
1123 | |
1124 @node Matching | |
1125 @section Automatic Display Of Matching Parentheses | |
1126 @cindex matching parentheses | |
1127 @cindex parentheses, displaying matches | |
1128 | |
1129 The Emacs parenthesis-matching feature is designed to show | |
1130 automatically how parentheses match in the text. Whenever you type a | |
1131 self-inserting character that is a closing delimiter, the cursor moves | |
1132 momentarily to the location of the matching opening delimiter, provided | |
1133 that is on the screen. If it is not on the screen, some text near it is | |
1134 displayed in the echo area. Either way, you can tell what grouping is | |
1135 being closed off. | |
1136 | |
1137 In Lisp, automatic matching applies only to parentheses. In C, it | |
1138 applies to braces and brackets too. Emacs knows which characters to regard | |
1139 as matching delimiters based on the syntax table, which is set by the major | |
1140 mode. @xref{Syntax}. | |
1141 | |
1142 If the opening delimiter and closing delimiter are mismatched---such as | |
1143 in @samp{[x)}---a warning message is displayed in the echo area. The | |
1144 correct matches are specified in the syntax table. | |
1145 | |
1146 @vindex blink-matching-paren | |
1147 @vindex blink-matching-paren-distance | |
1148 @vindex blink-matching-delay | |
1149 Three variables control parenthesis match display. | |
1150 @code{blink-matching-paren} turns the feature on or off; @code{nil} | |
1151 turns it off, but the default is @code{t} to turn match display on. | |
1152 @code{blink-matching-delay} says how many seconds to wait; the default | |
1153 is 1, but on some systems it is useful to specify a fraction of a | |
1154 second. @code{blink-matching-paren-distance} specifies how many | |
1155 characters back to search to find the matching opening delimiter. If | |
1156 the match is not found in that far, scanning stops, and nothing is | |
1157 displayed. This is to prevent scanning for the matching delimiter from | |
1158 wasting lots of time when there is no match. The default is 12,000. | |
1159 | |
1160 @cindex Show Paren mode | |
1161 @findex show-paren-mode | |
1162 When using X Windows, you can request a more powerful alternative kind | |
1163 of automatic parenthesis matching by enabling Show Paren mode. This | |
1164 mode turns off the usual kind of matching parenthesis display and | |
1165 instead uses highlighting to show what matches. Whenever point is after | |
1166 a close parenthesis, the close parenthesis and its matching open | |
1167 parenthesis are both highlighted; otherwise, if point is before an open | |
1168 parenthesis, the matching close parenthesis is highlighted. (There is | |
1169 no need to highlight the open parenthesis after point because the cursor | |
1170 appears on top of that character.) Use the command @kbd{M-x | |
1171 show-paren-mode} to enable or disable this mode. | |
1172 | |
1173 @node Comments | |
1174 @section Manipulating Comments | |
1175 @cindex comments | |
1176 | |
1177 Because comments are such an important part of programming, Emacs | |
1178 provides special commands for editing and inserting comments. | |
1179 | |
1180 @menu | |
1181 * Comment Commands:: | |
1182 * Multi-Line Comments:: | |
1183 * Options for Comments:: | |
1184 @end menu | |
1185 | |
1186 @node Comment Commands | |
1187 @subsection Comment Commands | |
1188 | |
1189 @kindex M-; | |
1190 @cindex indentation for comments | |
1191 @findex indent-for-comment | |
1192 | |
1193 The comment commands insert, kill and align comments. | |
1194 | |
1195 @c WideCommands | |
1196 @table @kbd | |
1197 @item M-; | |
1198 Insert or align comment (@code{indent-for-comment}). | |
1199 @item C-x ; | |
1200 Set comment column (@code{set-comment-column}). | |
1201 @item C-u - C-x ; | |
1202 Kill comment on current line (@code{kill-comment}). | |
1203 @item C-M-j | |
1204 Like @key{RET} followed by inserting and aligning a comment | |
1205 (@code{indent-new-comment-line}). | |
1206 @item M-x comment-region | |
1207 Add or remove comment delimiters on all the lines in the region. | |
1208 @end table | |
1209 | |
1210 The command that creates a comment is @kbd{M-;} (@code{indent-for-comment}). | |
1211 If there is no comment already on the line, a new comment is created, | |
1212 aligned at a specific column called the @dfn{comment column}. The comment | |
1213 is created by inserting the string Emacs thinks comments should start with | |
1214 (the value of @code{comment-start}; see below). Point is left after that | |
1215 string. If the text of the line extends past the comment column, then the | |
1216 indentation is done to a suitable boundary (usually, at least one space is | |
1217 inserted). If the major mode has specified a string to terminate comments, | |
1218 that is inserted after point, to keep the syntax valid. | |
1219 | |
1220 @kbd{M-;} can also be used to align an existing comment. If a line | |
1221 already contains the string that starts comments, then @kbd{M-;} just moves | |
1222 point after it and reindents it to the conventional place. Exception: | |
1223 comments starting in column 0 are not moved. | |
1224 | |
1225 Some major modes have special rules for indenting certain kinds of | |
1226 comments in certain contexts. For example, in Lisp code, comments which | |
1227 start with two semicolons are indented as if they were lines of code, | |
1228 instead of at the comment column. Comments which start with three | |
1229 semicolons are supposed to start at the left margin. Emacs understands | |
1230 these conventions by indenting a double-semicolon comment using @key{TAB}, | |
1231 and by not changing the indentation of a triple-semicolon comment at all. | |
1232 | |
1233 @example | |
1234 ;; This function is just an example | |
1235 ;;; Here either two or three semicolons are appropriate. | |
1236 (defun foo (x) | |
1237 ;;; And now, the first part of the function: | |
1238 ;; The following line adds one. | |
1239 (1+ x)) ; This line adds one. | |
1240 @end example | |
1241 | |
1242 In C code, a comment preceded on its line by nothing but whitespace | |
1243 is indented like a line of code. | |
1244 | |
1245 Even when an existing comment is properly aligned, @kbd{M-;} is still | |
1246 useful for moving directly to the start of the comment. | |
1247 | |
1248 @kindex C-u - C-x ; | |
1249 @findex kill-comment | |
1250 @kbd{C-u - C-x ;} (@code{kill-comment}) kills the comment on the current line, | |
1251 if there is one. The indentation before the start of the comment is killed | |
1252 as well. If there does not appear to be a comment in the line, nothing is | |
1253 done. To reinsert the comment on another line, move to the end of that | |
1254 line, do @kbd{C-y}, and then do @kbd{M-;} to realign it. Note that | |
1255 @kbd{C-u - C-x ;} is not a distinct key; it is @kbd{C-x ;} (@code{set-comment-column}) | |
1256 with a negative argument. That command is programmed so that when it | |
1257 receives a negative argument it calls @code{kill-comment}. However, | |
1258 @code{kill-comment} is a valid command which you could bind directly to a | |
1259 key if you wanted to. | |
1260 | |
1261 @node Multi-Line Comments | |
1262 @subsection Multiple Lines of Comments | |
1263 | |
1264 @kindex C-M-j | |
1265 @cindex blank lines in programs | |
1266 @findex indent-new-comment-line | |
1267 If you are typing a comment and wish to continue it on another line, | |
1268 you can use the command @kbd{C-M-j} (@code{indent-new-comment-line}). | |
1269 This terminates the comment you are typing, creates a new blank line | |
1270 afterward, and begins a new comment indented under the old one. When | |
1271 Auto Fill mode is on, going past the fill column while typing a comment | |
1272 causes the comment to be continued in just this fashion. If point is | |
1273 not at the end of the line when @kbd{C-M-j} is typed, the text on | |
1274 the rest of the line becomes part of the new comment line. | |
1275 | |
1276 @findex comment-region | |
1277 To turn existing lines into comment lines, use the @kbd{M-x | |
1278 comment-region} command. It adds comment delimiters to the lines that start | |
1279 in the region, thus commenting them out. With a negative argument, it | |
1280 does the opposite---it deletes comment delimiters from the lines in the | |
1281 region. | |
1282 | |
1283 With a positive argument, @code{comment-region} duplicates the last | |
1284 character of the comment start sequence it adds; the argument specifies | |
1285 how many copies of the character to insert. Thus, in Lisp mode, | |
1286 @kbd{C-u 2 M-x comment-region} adds @samp{;;} to each line. Duplicating | |
1287 the comment delimiter is a way of calling attention to the comment. It | |
1288 can also affect how the comment is indented. In Lisp, for proper | |
1289 indentation, you should use an argument of two, if between defuns, and | |
1290 three, if within a defun. | |
1291 | |
1292 @vindex comment-padding | |
1293 The variable @code{comment-padding} specifies how many spaces | |
1294 @code{comment-region} should insert on each line between the | |
1295 comment delimiter and the line's original text. The default is 1. | |
1296 | |
1297 @node Options for Comments | |
1298 @subsection Options Controlling Comments | |
1299 | |
1300 @vindex comment-column | |
1301 @kindex C-x ; | |
1302 @findex set-comment-column | |
1303 The comment column is stored in the variable @code{comment-column}. You | |
1304 can set it to a number explicitly. Alternatively, the command @kbd{C-x ;} | |
1305 (@code{set-comment-column}) sets the comment column to the column point is | |
1306 at. @kbd{C-u C-x ;} sets the comment column to match the last comment | |
1307 before point in the buffer, and then does a @kbd{M-;} to align the | |
1308 current line's comment under the previous one. Note that @kbd{C-u - C-x ;} | |
1309 runs the function @code{kill-comment} as described above. | |
1310 | |
1311 The variable @code{comment-column} is per-buffer: setting the variable | |
1312 in the normal fashion affects only the current buffer, but there is a | |
1313 default value which you can change with @code{setq-default}. | |
1314 @xref{Locals}. Many major modes initialize this variable for the | |
1315 current buffer. | |
1316 | |
1317 @vindex comment-start-skip | |
1318 The comment commands recognize comments based on the regular | |
1319 expression that is the value of the variable @code{comment-start-skip}. | |
1320 Make sure this regexp does not match the null string. It may match more | |
1321 than the comment starting delimiter in the strictest sense of the word; | |
1322 for example, in C mode the value of the variable is @code{@t{"/\\*+ | |
1323 *"}}, which matches extra stars and spaces after the @samp{/*} itself. | |
1324 (Note that @samp{\\} is needed in Lisp syntax to include a @samp{\} in | |
1325 the string, which is needed to deny the first star its special meaning | |
1326 in regexp syntax. @xref{Regexps}.) | |
1327 | |
1328 @vindex comment-start | |
1329 @vindex comment-end | |
1330 When a comment command makes a new comment, it inserts the value of | |
1331 @code{comment-start} to begin it. The value of @code{comment-end} is | |
1332 inserted after point, so that it will follow the text that you will insert | |
1333 into the comment. In C mode, @code{comment-start} has the value | |
1334 @w{@code{"/* "}} and @code{comment-end} has the value @w{@code{" */"}}. | |
1335 | |
1336 @vindex comment-multi-line | |
1337 The variable @code{comment-multi-line} controls how @kbd{C-M-j} | |
1338 (@code{indent-new-comment-line}) behaves when used inside a comment. If | |
1339 @code{comment-multi-line} is @code{nil}, as it normally is, then the | |
1340 comment on the starting line is terminated and a new comment is started | |
1341 on the new following line. If @code{comment-multi-line} is not | |
1342 @code{nil}, then the new following line is set up as part of the same | |
1343 comment that was found on the starting line. This is done by not | |
1344 inserting a terminator on the old line, and not inserting a starter on | |
1345 the new line. In languages where multi-line comments work, the choice | |
1346 of value for this variable is a matter of taste. | |
1347 | |
1348 @vindex comment-indent-function | |
1349 The variable @code{comment-indent-function} should contain a function | |
1350 that will be called to compute the indentation for a newly inserted | |
1351 comment or for aligning an existing comment. It is set differently by | |
1352 various major modes. The function is called with no arguments, but with | |
1353 point at the beginning of the comment, or at the end of a line if a new | |
1354 comment is to be inserted. It should return the column in which the | |
1355 comment ought to start. For example, in Lisp mode, the indent hook | |
1356 function bases its decision on how many semicolons begin an existing | |
1357 comment, and on the code in the preceding lines. | |
1358 | |
1359 @node Balanced Editing | |
1360 @section Editing Without Unbalanced Parentheses | |
1361 | |
1362 @table @kbd | |
1363 @item M-( | |
1364 Put parentheses around next sexp(s) (@code{insert-parentheses}). | |
1365 @item M-) | |
1366 Move past next close parenthesis and reindent | |
1367 (@code{move-past-close-and-reindent}). | |
1368 @end table | |
1369 | |
1370 @kindex M-( | |
1371 @kindex M-) | |
1372 @findex insert-parentheses | |
1373 @findex move-past-close-and-reindent | |
1374 The commands @kbd{M-(} (@code{insert-parentheses}) and @kbd{M-)} | |
1375 (@code{move-past-close-and-reindent}) are designed to facilitate a style | |
1376 of editing which keeps parentheses balanced at all times. @kbd{M-(} | |
1377 inserts a pair of parentheses, either together as in @samp{()}, or, if | |
1378 given an argument, around the next several sexps. It leaves point after | |
1379 the open parenthesis. The command @kbd{M-)} moves past the close | |
1380 parenthesis, deleting any indentation preceding it, and indenting with | |
1381 @kbd{C-j} after it. | |
1382 | |
1383 For example, instead of typing @kbd{( F O O )}, you can type @kbd{M-( | |
1384 F O O}, which has the same effect except for leaving the cursor before | |
1385 the close parenthesis. | |
1386 | |
1387 @vindex parens-require-spaces | |
1388 @kbd{M-(} may insert a space before the open parenthesis, depending on | |
1389 the syntax class of the preceding character. Set | |
1390 @code{parens-require-spaces} to @code{nil} value if you wish to inhibit | |
1391 this. | |
1392 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1393 @findex check-parens |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1394 You can use @kbd{M-x check-parens} to find any unbalanced parentheses in |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1395 a buffer. |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1396 |
25829 | 1397 @node Symbol Completion |
1398 @section Completion for Symbol Names | |
1399 @cindex completion (symbol names) | |
1400 | |
1401 Usually completion happens in the minibuffer. But one kind of completion | |
1402 is available in all buffers: completion for symbol names. | |
1403 | |
1404 @kindex M-TAB | |
1405 The character @kbd{M-@key{TAB}} runs a command to complete the partial | |
1406 symbol before point against the set of meaningful symbol names. Any | |
1407 additional characters determined by the partial name are inserted at | |
1408 point. | |
1409 | |
1410 If the partial name in the buffer has more than one possible completion | |
1411 and they have no additional characters in common, a list of all possible | |
1412 completions is displayed in another window. | |
1413 | |
1414 @cindex completion using tags | |
1415 @cindex tags completion | |
1416 @cindex Info index completion | |
1417 @findex complete-symbol | |
1418 In most programming language major modes, @kbd{M-@key{TAB}} runs the | |
1419 command @code{complete-symbol}, which provides two kinds of completion. | |
1420 Normally it does completion based on a tags table (@pxref{Tags}); with a | |
1421 numeric argument (regardless of the value), it does completion based on | |
1422 the names listed in the Info file indexes for your language. Thus, to | |
1423 complete the name of a symbol defined in your own program, use | |
1424 @kbd{M-@key{TAB}} with no argument; to complete the name of a standard | |
1425 library function, use @kbd{C-u M-@key{TAB}}. Of course, Info-based | |
1426 completion works only if there is an Info file for the standard library | |
1427 functions of your language, and only if it is installed at your site. | |
1428 | |
1429 @cindex Lisp symbol completion | |
1430 @cindex completion in Lisp | |
1431 @findex lisp-complete-symbol | |
1432 In Emacs-Lisp mode, the name space for completion normally consists of | |
1433 nontrivial symbols present in Emacs---those that have function | |
1434 definitions, values or properties. However, if there is an | |
1435 open-parenthesis immediately before the beginning of the partial symbol, | |
1436 only symbols with function definitions are considered as completions. | |
1437 The command which implements this is @code{lisp-complete-symbol}. | |
1438 | |
1439 In Text mode and related modes, @kbd{M-@key{TAB}} completes words | |
1440 based on the spell-checker's dictionary. @xref{Spelling}. | |
1441 | |
1442 @node Which Function | |
1443 @section Which Function Mode | |
1444 | |
1445 Which Function mode is a minor mode that displays the current function | |
1446 name in the mode line, as you move around in a buffer. | |
1447 | |
1448 @findex which-function-mode | |
1449 @vindex which-func-modes | |
1450 To enable (or disable) Which Function mode, use the command @kbd{M-x | |
1451 which-function-mode}. This command is global; it applies to all | |
1452 buffers, both existing ones and those yet to be created. However, this | |
1453 only affects certain major modes, those listed in the value of | |
1454 @code{which-func-modes}. (If the value is @code{t}, then Which Function | |
1455 mode applies to all major modes that know how to support it---which are | |
1456 the major modes that support Imenu.) | |
1457 | |
1458 @node Documentation | |
1459 @section Documentation Commands | |
1460 | |
1461 As you edit Lisp code to be run in Emacs, the commands @kbd{C-h f} | |
1462 (@code{describe-function}) and @kbd{C-h v} (@code{describe-variable}) can | |
1463 be used to print documentation of functions and variables that you want to | |
1464 call. These commands use the minibuffer to read the name of a function or | |
1465 variable to document, and display the documentation in a window. | |
1466 | |
1467 For extra convenience, these commands provide default arguments based on | |
1468 the code in the neighborhood of point. @kbd{C-h f} sets the default to the | |
1469 function called in the innermost list containing point. @kbd{C-h v} uses | |
1470 the symbol name around or adjacent to point as its default. | |
1471 | |
1472 @cindex Eldoc mode | |
1473 @findex eldoc-mode | |
1474 For Emacs Lisp code, you can also use Eldoc mode. This minor mode | |
1475 constantly displays in the echo area the argument list for the function | |
1476 being called at point. (In other words, it finds the function call that | |
1477 point is contained in, and displays the argument list of that function.) | |
1478 Eldoc mode applies in Emacs Lisp and Lisp Interaction modes only. Use | |
1479 the command @kbd{M-x eldoc-mode} to enable or disable this feature. | |
1480 | |
1481 @findex info-lookup-symbol | |
1482 @findex info-lookup-file | |
1483 @kindex C-h C-i | |
1484 For C, Lisp, and other languages, you can use @kbd{C-h C-i} | |
1485 (@code{info-lookup-symbol}) to view the Info documentation for a symbol. | |
1486 You specify the symbol with the minibuffer; by default, it uses the | |
1487 symbol that appears in the buffer at point. The major mode determines | |
1488 where to look for documentation for the symbol---which Info files and | |
1489 which indices. You can also use @kbd{M-x info-lookup-file} to look for | |
1490 documentation for a file name. | |
1491 | |
1492 @findex manual-entry | |
1493 You can read the ``man page'' for an operating system command, library | |
1494 function, or system call, with the @kbd{M-x manual-entry} command. It | |
1495 runs the @code{man} program to format the man page, and runs it | |
1496 asynchronously if your system permits, so that you can keep on editing | |
1497 while the page is being formatted. (MS-DOS and MS-Windows 3 do not | |
1498 permit asynchronous subprocesses, so on these systems you cannot edit | |
1499 while Emacs waits for @code{man} to exit.) The result goes in a buffer | |
1500 named @samp{*Man @var{topic}*}. These buffers use a special major mode, | |
1501 Man mode, that facilitates scrolling and examining other manual pages. | |
1502 For details, type @kbd{C-h m} while in a man page buffer. | |
1503 | |
1504 @vindex Man-fontify-manpage-flag | |
1505 For a long man page, setting the faces properly can take substantial | |
1506 time. By default, Emacs uses faces in man pages if Emacs can display | |
1507 different fonts or colors. You can turn off use of faces in man pages | |
1508 by setting the variable @code{Man-fontify-manpage-flag} to @code{nil}. | |
1509 | |
1510 @findex Man-fontify-manpage | |
1511 If you insert the text of a man page into an Emacs buffer in some | |
1512 other fashion, you can use the command @kbd{M-x Man-fontify-manpage} to | |
1513 perform the same conversions that @kbd{M-x manual-entry} does. | |
1514 | |
1515 Eventually the GNU project hopes to replace most man pages with | |
1516 better-organized manuals that you can browse with Info. @xref{Misc | |
1517 Help}. Since this process is only partially completed, it is still | |
1518 useful to read manual pages. | |
1519 | |
1520 @node Change Log | |
1521 @section Change Logs | |
1522 | |
1523 @cindex change log | |
1524 @kindex C-x 4 a | |
1525 @findex add-change-log-entry-other-window | |
1526 The Emacs command @kbd{C-x 4 a} adds a new entry to the change log | |
1527 file for the file you are editing | |
1528 (@code{add-change-log-entry-other-window}). | |
1529 | |
1530 A change log file contains a chronological record of when and why you | |
1531 have changed a program, consisting of a sequence of entries describing | |
1532 individual changes. Normally it is kept in a file called | |
1533 @file{ChangeLog} in the same directory as the file you are editing, or | |
1534 one of its parent directories. A single @file{ChangeLog} file can | |
1535 record changes for all the files in its directory and all its | |
1536 subdirectories. | |
1537 | |
1538 A change log entry starts with a header line that contains your name, | |
1539 your email address (taken from the variable @code{user-mail-address}), | |
1540 and the current date and time. Aside from these header lines, every | |
1541 line in the change log starts with a space or a tab. The bulk of the | |
1542 entry consists of @dfn{items}, each of which starts with a line starting | |
1543 with whitespace and a star. Here are two entries, both dated in May | |
1544 1993, each with two items: | |
1545 | |
1546 @iftex | |
1547 @medbreak | |
1548 @end iftex | |
1549 @smallexample | |
1550 1993-05-25 Richard Stallman <rms@@gnu.org> | |
1551 | |
1552 * man.el: Rename symbols `man-*' to `Man-*'. | |
1553 (manual-entry): Make prompt string clearer. | |
1554 | |
1555 * simple.el (blink-matching-paren-distance): | |
1556 Change default to 12,000. | |
1557 | |
1558 1993-05-24 Richard Stallman <rms@@gnu.org> | |
1559 | |
1560 * vc.el (minor-mode-map-alist): Don't use it if it's void. | |
1561 (vc-cancel-version): Doc fix. | |
1562 @end smallexample | |
1563 | |
1564 @noindent | |
1565 (Previous Emacs versions used a different format for the date.) | |
1566 | |
1567 One entry can describe several changes; each change should have its | |
1568 own item. Normally there should be a blank line between items. When | |
1569 items are related (parts of the same change, in different places), group | |
1570 them by leaving no blank line between them. The second entry above | |
1571 contains two items grouped in this way. | |
1572 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1573 @vindex add-log-keep-changes-together |
25829 | 1574 @kbd{C-x 4 a} visits the change log file and creates a new entry |
1575 unless the most recent entry is for today's date and your name. It also | |
1576 creates a new item for the current file. For many languages, it can | |
1577 even guess the name of the function or other object that was changed. | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1578 When the option @code{add-log-keep-changes-together} is set, @kbd{C-x 4 |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1579 a} adds to any existing entry for the file rather than starting a new |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1580 entry. |
25829 | 1581 |
1582 @cindex Change Log mode | |
1583 @findex change-log-mode | |
1584 The change log file is visited in Change Log mode. In this major | |
1585 mode, each bunch of grouped items counts as one paragraph, and each | |
1586 entry is considered a page. This facilitates editing the entries. | |
1587 @kbd{C-j} and auto-fill indent each new line like the previous line; | |
1588 this is convenient for entering the contents of an entry. | |
1589 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1590 @findex change-log-merge |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1591 The command @kbd{M-x change-log-merge} can be used to merge other log |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1592 files into a buffer in Change Log Mode, preserving the date ordering |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1593 of entries with either the current or old-style date formats. |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1594 |
25829 | 1595 Version control systems are another way to keep track of changes in your |
1596 program and keep a change log. @xref{Log Buffer}. | |
1597 | |
1598 @node Tags | |
1599 @section Tags Tables | |
1600 @cindex tags table | |
1601 | |
1602 A @dfn{tags table} is a description of how a multi-file program is | |
1603 broken up into files. It lists the names of the component files and the | |
1604 names and positions of the functions (or other named subunits) in each | |
1605 file. Grouping the related files makes it possible to search or replace | |
1606 through all the files with one command. Recording the function names | |
1607 and positions makes possible the @kbd{M-.} command which finds the | |
1608 definition of a function by looking up which of the files it is in. | |
1609 | |
1610 Tags tables are stored in files called @dfn{tags table files}. The | |
1611 conventional name for a tags table file is @file{TAGS}. | |
1612 | |
1613 Each entry in the tags table records the name of one tag, the name of the | |
1614 file that the tag is defined in (implicitly), and the position in that file | |
1615 of the tag's definition. | |
1616 | |
1617 Just what names from the described files are recorded in the tags table | |
1618 depends on the programming language of the described file. They | |
1619 normally include all functions and subroutines, and may also include | |
1620 global variables, data types, and anything else convenient. Each name | |
1621 recorded is called a @dfn{tag}. | |
1622 | |
1623 @menu | |
26264 | 1624 * Tag Syntax:: Tag syntax for various types of code and text files. |
25829 | 1625 * Create Tags Table:: Creating a tags table with @code{etags}. |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1626 * Etags Regexps:: Create arbitrary tags using regular expressions. |
25829 | 1627 * Select Tags Table:: How to visit a tags table. |
26264 | 1628 * Find Tag:: Commands to find the definition of a specific tag. |
25829 | 1629 * Tags Search:: Using a tags table for searching and replacing. |
1630 * List Tags:: Listing and finding tags defined in a file. | |
1631 @end menu | |
1632 | |
1633 @node Tag Syntax | |
1634 @subsection Source File Tag Syntax | |
1635 | |
1636 Here is how tag syntax is defined for the most popular languages: | |
1637 | |
1638 @itemize @bullet | |
1639 @item | |
1640 In C code, any C function or typedef is a tag, and so are definitions of | |
26264 | 1641 @code{struct}, @code{union} and @code{enum}. You can tag function |
26292
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1642 declarations and external variables in addition to function definitions |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1643 by giving the @samp{--declarations} option to @code{etags}. |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1644 @code{#define} macro definitions and @code{enum} constants are also |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1645 tags, unless you specify @samp{--no-defines} when making the tags table. |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1646 Similarly, global variables are tags, unless you specify |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1647 @samp{--no-globals}. Use of @samp{--no-globals} and @samp{--no-defines} |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1648 can make the tags table file much smaller. |
25829 | 1649 |
1650 @item | |
1651 In C++ code, in addition to all the tag constructs of C code, member | |
1652 functions are also recognized, and optionally member variables if you | |
1653 use the @samp{--members} option. Tags for variables and functions in | |
1654 classes are named @samp{@var{class}::@var{variable}} and | |
26264 | 1655 @samp{@var{class}::@var{function}}. @code{operator} functions tags are |
1656 named, for example @samp{operator+}. | |
25829 | 1657 |
1658 @item | |
1659 In Java code, tags include all the constructs recognized in C++, plus | |
26264 | 1660 the @code{interface}, @code{extends} and @code{implements} constructs. |
1661 Tags for variables and functions in classes are named | |
1662 @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}. | |
25829 | 1663 |
1664 @item | |
1665 In La@TeX{} text, the argument of any of the commands @code{\chapter}, | |
1666 @code{\section}, @code{\subsection}, @code{\subsubsection}, | |
1667 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite}, @code{\bibitem}, | |
1668 @code{\part}, @code{\appendix}, @code{\entry}, or @code{\index}, is a | |
1669 tag.@refill | |
1670 | |
1671 Other commands can make tags as well, if you specify them in the | |
1672 environment variable @code{TEXTAGS} before invoking @code{etags}. The | |
1673 value of this environment variable should be a colon-separated list of | |
1674 command names. For example, | |
1675 | |
1676 @example | |
1677 TEXTAGS="def:newcommand:newenvironment" | |
1678 export TEXTAGS | |
1679 @end example | |
1680 | |
1681 @noindent | |
1682 specifies (using Bourne shell syntax) that the commands @samp{\def}, | |
1683 @samp{\newcommand} and @samp{\newenvironment} also define tags. | |
1684 | |
1685 @item | |
1686 In Lisp code, any function defined with @code{defun}, any variable | |
1687 defined with @code{defvar} or @code{defconst}, and in general the first | |
1688 argument of any expression that starts with @samp{(def} in column zero, is | |
1689 a tag. | |
1690 | |
1691 @item | |
1692 In Scheme code, tags include anything defined with @code{def} or with a | |
1693 construct whose name starts with @samp{def}. They also include variables | |
1694 set with @code{set!} at top level in the file. | |
1695 @end itemize | |
1696 | |
1697 Several other languages are also supported: | |
1698 | |
1699 @itemize @bullet | |
26264 | 1700 |
1701 @item | |
26292
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1702 In Ada code, functions, procedures, packages, tasks, and types are |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1703 tags. Use the @samp{--packages-only} option to create tags for packages |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1704 only. |
26264 | 1705 |
25829 | 1706 @item |
1707 In assembler code, labels appearing at the beginning of a line, | |
1708 followed by a colon, are tags. | |
1709 | |
1710 @item | |
1711 In Bison or Yacc input files, each rule defines as a tag the nonterminal | |
1712 it constructs. The portions of the file that contain C code are parsed | |
1713 as C code. | |
1714 | |
1715 @item | |
1716 In Cobol code, tags are paragraph names; that is, any word starting in | |
1717 column 8 and followed by a period. | |
1718 | |
1719 @item | |
1720 In Erlang code, the tags are the functions, records, and macros defined | |
1721 in the file. | |
1722 | |
1723 @item | |
1724 In Fortran code, functions, subroutines and blockdata are tags. | |
1725 | |
1726 @item | |
1727 In Objective C code, tags include Objective C definitions for classes, | |
1728 class categories, methods, and protocols. | |
1729 | |
1730 @item | |
1731 In Pascal code, the tags are the functions and procedures defined in | |
1732 the file. | |
1733 | |
1734 @item | |
26264 | 1735 In Perl code, the tags are the procedures defined by the @code{sub}, |
1736 @code{my} and @code{local} keywords. Use @samp{--globals} if you want | |
1737 to tag global variables. | |
25829 | 1738 |
1739 @item | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
1740 In PostScript code, the tags are the functions. |
25829 | 1741 |
1742 @item | |
1743 In Prolog code, a tag name appears at the left margin. | |
1744 | |
26264 | 1745 @item |
1746 In Python code, @code{def} or @code{class} at the beginning of a line | |
1747 generate a tag. | |
26292
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1748 @end itemize |
26264 | 1749 |
26462 | 1750 You can also generate tags based on regexp matching (@pxref{Etags |
26264 | 1751 Regexps}) to handle other formats and languages. |
25829 | 1752 |
1753 @node Create Tags Table | |
1754 @subsection Creating Tags Tables | |
1755 @cindex @code{etags} program | |
1756 | |
1757 The @code{etags} program is used to create a tags table file. It knows | |
1758 the syntax of several languages, as described in | |
1759 @iftex | |
1760 the previous section. | |
1761 @end iftex | |
1762 @ifinfo | |
1763 @ref{Tag Syntax}. | |
1764 @end ifinfo | |
1765 Here is how to run @code{etags}: | |
1766 | |
1767 @example | |
1768 etags @var{inputfiles}@dots{} | |
1769 @end example | |
1770 | |
1771 @noindent | |
26264 | 1772 The @code{etags} program reads the specified files, and writes a tags |
1773 table named @file{TAGS} in the current working directory. You can | |
1774 intermix compressed and plain text source file names. @code{etags} | |
1775 knows about the most common compression formats, and does the right | |
1776 thing. So you can compress all your source files and have @code{etags} | |
1777 look for compressed versions of its file name arguments, if it does not | |
1778 find uncompressed versions. Under MS-DOS, @code{etags} also looks for | |
1779 file names like @samp{mycode.cgz} if it is given @samp{mycode.c} on the | |
1780 command line and @samp{mycode.c} does not exist. | |
1781 | |
1782 @code{etags} recognizes the language used in an input file based on | |
1783 its file name and contents. You can specify the language with the | |
25829 | 1784 @samp{--language=@var{name}} option, described below. |
1785 | |
1786 If the tags table data become outdated due to changes in the files | |
1787 described in the table, the way to update the tags table is the same way it | |
1788 was made in the first place. It is not necessary to do this often. | |
1789 | |
1790 If the tags table fails to record a tag, or records it for the wrong | |
1791 file, then Emacs cannot possibly find its definition. However, if the | |
1792 position recorded in the tags table becomes a little bit wrong (due to | |
1793 some editing in the file that the tag definition is in), the only | |
1794 consequence is a slight delay in finding the tag. Even if the stored | |
1795 position is very wrong, Emacs will still find the tag, but it must | |
1796 search the entire file for it. | |
1797 | |
1798 So you should update a tags table when you define new tags that you want | |
1799 to have listed, or when you move tag definitions from one file to another, | |
1800 or when changes become substantial. Normally there is no need to update | |
1801 the tags table after each edit, or even every day. | |
1802 | |
1803 One tags table can effectively include another. Specify the included | |
1804 tags file name with the @samp{--include=@var{file}} option when creating | |
1805 the file that is to include it. The latter file then acts as if it | |
1806 contained all the files specified in the included file, as well as the | |
1807 files it directly contains. | |
1808 | |
1809 If you specify the source files with relative file names when you run | |
1810 @code{etags}, the tags file will contain file names relative to the | |
1811 directory where the tags file was initially written. This way, you can | |
1812 move an entire directory tree containing both the tags file and the | |
1813 source files, and the tags file will still refer correctly to the source | |
1814 files. | |
1815 | |
1816 If you specify absolute file names as arguments to @code{etags}, then | |
1817 the tags file will contain absolute file names. This way, the tags file | |
1818 will still refer to the same files even if you move it, as long as the | |
1819 source files remain in the same place. Absolute file names start with | |
1820 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows. | |
1821 | |
1822 When you want to make a tags table from a great number of files, you | |
1823 may have problems listing them on the command line, because some systems | |
1824 have a limit on its length. The simplest way to circumvent this limit | |
1825 is to tell @code{etags} to read the file names from its standard input, | |
1826 by typing a dash in place of the file names, like this: | |
1827 | |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1828 @smallexample |
25829 | 1829 find . -name "*.[chCH]" -print | etags - |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1830 @end smallexample |
25829 | 1831 |
1832 Use the option @samp{--language=@var{name}} to specify the language | |
1833 explicitly. You can intermix these options with file names; each one | |
1834 applies to the file names that follow it. Specify | |
1835 @samp{--language=auto} to tell @code{etags} to resume guessing the | |
1836 language from the file names and file contents. Specify | |
1837 @samp{--language=none} to turn off language-specific processing | |
26264 | 1838 entirely; then @code{etags} recognizes tags by regexp matching alone |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1839 (@pxref{Etags Regexps}). |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1840 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1841 @samp{etags --help} prints the list of the languages @code{etags} |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1842 knows, and the file name rules for guessing the language. It also prints |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1843 a list of all the available @code{etags} options, together with a short |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1844 explanation. |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1845 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1846 @node Etags Regexps |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1847 @subsection Etags Regexps |
25829 | 1848 |
1849 The @samp{--regex} option provides a general way of recognizing tags | |
1850 based on regexp matching. You can freely intermix it with file names. | |
1851 Each @samp{--regex} option adds to the preceding ones, and applies only | |
1852 to the following files. The syntax is: | |
1853 | |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1854 @smallexample |
25829 | 1855 --regex=/@var{tagregexp}[/@var{nameregexp}]/ |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1856 @end smallexample |
26264 | 1857 |
25829 | 1858 @noindent |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1859 where @var{tagregexp} is used to match the lines to tag. It is always |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1860 anchored, that is, it behaves as if preceded by @samp{^}. If you want |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1861 to account for indentation, just match any initial number of blanks by |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1862 beginning your regular expression with @samp{[ \t]*}. In the regular |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1863 expressions, @samp{\} quotes the next character, and @samp{\t} stands |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1864 for the tab character. Note that @code{etags} does not handle the other |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1865 C escape sequences for special characters. |
25829 | 1866 |
1867 @cindex interval operator (in regexps) | |
1868 The syntax of regular expressions in @code{etags} is the same as in | |
1869 Emacs, augmented with the @dfn{interval operator}, which works as in | |
1870 @code{grep} and @code{ed}. The syntax of an interval operator is | |
1871 @samp{\@{@var{m},@var{n}\@}}, and its meaning is to match the preceding | |
1872 expression at least @var{m} times and up to @var{n} times. | |
1873 | |
1874 You should not match more characters with @var{tagregexp} than that | |
1875 needed to recognize what you want to tag. If the match is such that | |
26106 | 1876 more characters than needed are unavoidably matched by @var{tagregexp} |
1877 (as will usually be the case), you should add a @var{nameregexp}, to | |
1878 pick out just the tag. This will enable Emacs to find tags more | |
1879 accurately and to do completion on tag names more reliably. You can | |
1880 find some examples below. | |
1881 | |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1882 The option @samp{--ignore-case-regex} (or @samp{-c}) is like |
26106 | 1883 @samp{--regex}, except that the regular expression provided will be |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1884 matched without regard to case, which is appropriate for various |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1885 programming languages. |
25829 | 1886 |
1887 The @samp{-R} option deletes all the regexps defined with | |
1888 @samp{--regex} options. It applies to the file names following it, as | |
1889 you can see from the following example: | |
1890 | |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1891 @smallexample |
25829 | 1892 etags --regex=/@var{reg1}/ voo.doo --regex=/@var{reg2}/ \ |
1893 bar.ber -R --lang=lisp los.er | |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1894 @end smallexample |
25829 | 1895 |
1896 @noindent | |
1897 Here @code{etags} chooses the parsing language for @file{voo.doo} and | |
1898 @file{bar.ber} according to their contents. @code{etags} also uses | |
1899 @var{reg1} to recognize additional tags in @file{voo.doo}, and both | |
1900 @var{reg1} and @var{reg2} to recognize additional tags in | |
1901 @file{bar.ber}. @code{etags} uses the Lisp tags rules, and no regexp | |
1902 matching, to recognize tags in @file{los.er}. | |
1903 | |
26289
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1904 A regular expression can be bound to a given language, by prepending |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1905 it with @samp{@{lang@}}. When you do this, @code{etags} will use the |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1906 regular expression only for files of that language. @samp{etags --help} |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1907 prints the list of languages recognised by @code{etags}. The following |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1908 example tags the @code{DEFVAR} macros in the Emacs source files. |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1909 @code{etags} applies this regular expression to C files only: |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1910 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1911 @smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1912 --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/' |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1913 @end smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1914 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1915 @noindent |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1916 This feature is particularly useful when storing a list of regular |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1917 expressions in a file. The following option syntax instructs |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1918 @code{etags} to read two files of regular expressions. The regular |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1919 expressions contained in the second file are matched without regard to |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1920 case. |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1921 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1922 @smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1923 --regex=@@first-file --ignore-case-regex=@@second-file |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1924 @end smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1925 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1926 @noindent |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1927 A regex file contains one regular expressions per line. Empty lines, |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1928 and lines beginning with space or tab are ignored. When the first |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1929 character in a line is @samp{@@}, @code{etags} assumes that the rest of |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1930 the line is the name of a file of regular expressions. This means that |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1931 such files can be nested. All the other lines are taken to be regular |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1932 expressions. For example, one can create a file called |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1933 @samp{emacs.tags} with the following contents (the first line in the |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1934 file is a comment): |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1935 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1936 @smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1937 -- This is for GNU Emacs source files |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1938 @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/ |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1939 @end smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1940 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1941 @noindent |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1942 and then use it like this: |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1943 |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1944 @smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1945 etags --regex=@@emacs.tags *.[ch] */*.[ch] |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1946 @end smallexample |
6651db4a4b1f
Document regexp changes in etags.
Francesco Potortì <pot@gnu.org>
parents:
26264
diff
changeset
|
1947 |
25829 | 1948 Here are some more examples. The regexps are quoted to protect them |
1949 from shell interpretation. | |
1950 | |
1951 @itemize @bullet | |
1952 | |
1953 @item | |
26292
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1954 Tag Octave files: |
25829 | 1955 |
1956 @smallexample | |
26292
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1957 etags --language=none \ |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1958 --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \ |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1959 --regex='/###key \(.*\)/\1/' \ |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1960 --regex='/[ \t]*global[ \t].*/' \ |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1961 *.m |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1962 @end smallexample |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1963 |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1964 @noindent |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1965 Note that tags are not generated for scripts so that you have to add a |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1966 line by yourself of the form `###key <script-name>' if you want to jump |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1967 to it. |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1968 |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1969 @item |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1970 Tag Tcl files: |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1971 |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1972 @smallexample |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1973 etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl |
25829 | 1974 @end smallexample |
1975 | |
1976 @item | |
26292
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1977 Tag VHDL files: |
25829 | 1978 |
1979 @smallexample | |
26292
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1980 --language=none \ |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1981 --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \ |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1982 --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\ |
81cd0c225dd9
Last changes for etags (I hope).
Francesco Potortì <pot@gnu.org>
parents:
26289
diff
changeset
|
1983 \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/' |
25829 | 1984 @end smallexample |
1985 @end itemize | |
1986 | |
1987 @node Select Tags Table | |
1988 @subsection Selecting a Tags Table | |
1989 | |
1990 @vindex tags-file-name | |
1991 @findex visit-tags-table | |
1992 Emacs has at any time one @dfn{selected} tags table, and all the commands | |
1993 for working with tags tables use the selected one. To select a tags table, | |
1994 type @kbd{M-x visit-tags-table}, which reads the tags table file name as an | |
1995 argument. The name @file{TAGS} in the default directory is used as the | |
1996 default file name. | |
1997 | |
1998 All this command does is store the file name in the variable | |
1999 @code{tags-file-name}. Emacs does not actually read in the tags table | |
2000 contents until you try to use them. Setting this variable yourself is just | |
2001 as good as using @code{visit-tags-table}. The variable's initial value is | |
2002 @code{nil}; that value tells all the commands for working with tags tables | |
2003 that they must ask for a tags table file name to use. | |
2004 | |
2005 Using @code{visit-tags-table} when a tags table is already loaded | |
2006 gives you a choice: you can add the new tags table to the current list | |
2007 of tags tables, or start a new list. The tags commands use all the tags | |
2008 tables in the current list. If you start a new list, the new tags table | |
2009 is used @emph{instead} of others. If you add the new table to the | |
2010 current list, it is used @emph{as well as} the others. When the tags | |
2011 commands scan the list of tags tables, they don't always start at the | |
2012 beginning of the list; they start with the first tags table (if any) | |
2013 that describes the current file, proceed from there to the end of the | |
2014 list, and then scan from the beginning of the list until they have | |
2015 covered all the tables in the list. | |
2016 | |
2017 @vindex tags-table-list | |
2018 You can specify a precise list of tags tables by setting the variable | |
2019 @code{tags-table-list} to a list of strings, like this: | |
2020 | |
2021 @c keep this on two lines for formatting in smallbook | |
2022 @example | |
2023 @group | |
2024 (setq tags-table-list | |
2025 '("~/emacs" "/usr/local/lib/emacs/src")) | |
2026 @end group | |
2027 @end example | |
2028 | |
2029 @noindent | |
2030 This tells the tags commands to look at the @file{TAGS} files in your | |
2031 @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src} | |
2032 directory. The order depends on which file you are in and which tags | |
2033 table mentions that file, as explained above. | |
2034 | |
2035 Do not set both @code{tags-file-name} and @code{tags-table-list}. | |
2036 | |
2037 @node Find Tag | |
2038 @subsection Finding a Tag | |
2039 | |
2040 The most important thing that a tags table enables you to do is to find | |
2041 the definition of a specific tag. | |
2042 | |
2043 @table @kbd | |
2044 @item M-.@: @var{tag} @key{RET} | |
2045 Find first definition of @var{tag} (@code{find-tag}). | |
2046 @item C-u M-. | |
2047 Find next alternate definition of last tag specified. | |
2048 @item C-u - M-. | |
2049 Go back to previous tag found. | |
2050 @item C-M-. @var{pattern} @key{RET} | |
2051 Find a tag whose name matches @var{pattern} (@code{find-tag-regexp}). | |
2052 @item C-u C-M-. | |
2053 Find the next tag whose name matches the last pattern used. | |
2054 @item C-x 4 .@: @var{tag} @key{RET} | |
2055 Find first definition of @var{tag}, but display it in another window | |
2056 (@code{find-tag-other-window}). | |
2057 @item C-x 5 .@: @var{tag} @key{RET} | |
2058 Find first definition of @var{tag}, and create a new frame to select the | |
2059 buffer (@code{find-tag-other-frame}). | |
2060 @item M-* | |
2061 Pop back to where you previously invoked @kbd{M-.} and friends. | |
2062 @end table | |
2063 | |
2064 @kindex M-. | |
2065 @findex find-tag | |
2066 @kbd{M-.}@: (@code{find-tag}) is the command to find the definition of | |
2067 a specified tag. It searches through the tags table for that tag, as a | |
2068 string, and then uses the tags table info to determine the file that the | |
2069 definition is in and the approximate character position in the file of | |
2070 the definition. Then @code{find-tag} visits that file, moves point to | |
2071 the approximate character position, and searches ever-increasing | |
2072 distances away to find the tag definition. | |
2073 | |
2074 If an empty argument is given (just type @key{RET}), the sexp in the | |
2075 buffer before or around point is used as the @var{tag} argument. | |
2076 @xref{Lists}, for info on sexps. | |
2077 | |
2078 You don't need to give @kbd{M-.} the full name of the tag; a part | |
2079 will do. This is because @kbd{M-.} finds tags in the table which | |
2080 contain @var{tag} as a substring. However, it prefers an exact match | |
2081 to a substring match. To find other tags that match the same | |
2082 substring, give @code{find-tag} a numeric argument, as in @kbd{C-u | |
2083 M-.}; this does not read a tag name, but continues searching the tags | |
2084 table's text for another tag containing the same substring last used. | |
2085 If you have a real @key{META} key, @kbd{M-0 M-.}@: is an easier | |
2086 alternative to @kbd{C-u M-.}. | |
2087 | |
2088 @kindex C-x 4 . | |
2089 @findex find-tag-other-window | |
2090 @kindex C-x 5 . | |
2091 @findex find-tag-other-frame | |
2092 Like most commands that can switch buffers, @code{find-tag} has a | |
2093 variant that displays the new buffer in another window, and one that | |
2094 makes a new frame for it. The former is @kbd{C-x 4 .}, which invokes | |
2095 the command @code{find-tag-other-window}. The latter is @kbd{C-x 5 .}, | |
2096 which invokes @code{find-tag-other-frame}. | |
2097 | |
2098 To move back to places you've found tags recently, use @kbd{C-u - | |
2099 M-.}; more generally, @kbd{M-.} with a negative numeric argument. This | |
2100 command can take you to another buffer. @kbd{C-x 4 .} with a negative | |
2101 argument finds the previous tag location in another window. | |
2102 | |
2103 @kindex M-* | |
2104 @findex pop-tag-mark | |
2105 @vindex find-tag-marker-ring-length | |
2106 As well as going back to places you've found tags recently, you can go | |
2107 back to places @emph{from where} you found them. Use @kbd{M-*}, which | |
2108 invokes the command @code{pop-tag-mark}, for this. Typically you would | |
2109 find and study the definition of something with @kbd{M-.} and then | |
2110 return to where you were with @kbd{M-*}. | |
2111 | |
2112 Both @kbd{C-u - M-.} and @kbd{M-*} allow you to retrace your steps to | |
2113 a depth determined by the variable @code{find-tag-marker-ring-length}. | |
2114 | |
2115 @findex find-tag-regexp | |
2116 @kindex C-M-. | |
2117 The command @kbd{C-M-.} (@code{find-tag-regexp}) visits the tags that | |
2118 match a specified regular expression. It is just like @kbd{M-.} except | |
2119 that it does regexp matching instead of substring matching. | |
2120 | |
2121 @node Tags Search | |
2122 @subsection Searching and Replacing with Tags Tables | |
2123 | |
2124 The commands in this section visit and search all the files listed in the | |
2125 selected tags table, one by one. For these commands, the tags table serves | |
2126 only to specify a sequence of files to search. | |
2127 | |
2128 @table @kbd | |
2129 @item M-x tags-search @key{RET} @var{regexp} @key{RET} | |
2130 Search for @var{regexp} through the files in the selected tags | |
2131 table. | |
2132 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET} | |
2133 Perform a @code{query-replace-regexp} on each file in the selected tags table. | |
2134 @item M-, | |
2135 Restart one of the commands above, from the current location of point | |
2136 (@code{tags-loop-continue}). | |
2137 @end table | |
2138 | |
2139 @findex tags-search | |
2140 @kbd{M-x tags-search} reads a regexp using the minibuffer, then | |
2141 searches for matches in all the files in the selected tags table, one | |
2142 file at a time. It displays the name of the file being searched so you | |
2143 can follow its progress. As soon as it finds an occurrence, | |
2144 @code{tags-search} returns. | |
2145 | |
2146 @kindex M-, | |
2147 @findex tags-loop-continue | |
2148 Having found one match, you probably want to find all the rest. To find | |
2149 one more match, type @kbd{M-,} (@code{tags-loop-continue}) to resume the | |
2150 @code{tags-search}. This searches the rest of the current buffer, followed | |
2151 by the remaining files of the tags table.@refill | |
2152 | |
2153 @findex tags-query-replace | |
2154 @kbd{M-x tags-query-replace} performs a single | |
2155 @code{query-replace-regexp} through all the files in the tags table. It | |
2156 reads a regexp to search for and a string to replace with, just like | |
2157 ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x | |
2158 tags-search}, but repeatedly, processing matches according to your | |
2159 input. @xref{Replace}, for more information on query replace. | |
2160 | |
2161 It is possible to get through all the files in the tags table with a | |
2162 single invocation of @kbd{M-x tags-query-replace}. But often it is | |
2163 useful to exit temporarily, which you can do with any input event that | |
2164 has no special query replace meaning. You can resume the query replace | |
2165 subsequently by typing @kbd{M-,}; this command resumes the last tags | |
2166 search or replace command that you did. | |
2167 | |
2168 The commands in this section carry out much broader searches than the | |
2169 @code{find-tag} family. The @code{find-tag} commands search only for | |
2170 definitions of tags that match your substring or regexp. The commands | |
2171 @code{tags-search} and @code{tags-query-replace} find every occurrence | |
2172 of the regexp, as ordinary search commands and replace commands do in | |
2173 the current buffer. | |
2174 | |
2175 These commands create buffers only temporarily for the files that they | |
2176 have to search (those which are not already visited in Emacs buffers). | |
2177 Buffers in which no match is found are quickly killed; the others | |
2178 continue to exist. | |
2179 | |
2180 It may have struck you that @code{tags-search} is a lot like | |
2181 @code{grep}. You can also run @code{grep} itself as an inferior of | |
2182 Emacs and have Emacs show you the matching lines one by one. This works | |
2183 much like running a compilation; finding the source locations of the | |
2184 @code{grep} matches works like finding the compilation errors. | |
2185 @xref{Compilation}. | |
26264 | 2186 |
25829 | 2187 @node List Tags |
2188 @subsection Tags Table Inquiries | |
2189 | |
2190 @table @kbd | |
2191 @item M-x list-tags @key{RET} @var{file} @key{RET} | |
2192 Display a list of the tags defined in the program file @var{file}. | |
2193 @item M-x tags-apropos @key{RET} @var{regexp} @key{RET} | |
2194 Display a list of all tags matching @var{regexp}. | |
2195 @end table | |
2196 | |
2197 @findex list-tags | |
2198 @kbd{M-x list-tags} reads the name of one of the files described by | |
2199 the selected tags table, and displays a list of all the tags defined in | |
2200 that file. The ``file name'' argument is really just a string to | |
2201 compare against the file names recorded in the tags table; it is read as | |
2202 a string rather than as a file name. Therefore, completion and | |
2203 defaulting are not available, and you must enter the file name the same | |
2204 way it appears in the tags table. Do not include a directory as part of | |
2205 the file name unless the file name recorded in the tags table includes a | |
2206 directory. | |
2207 | |
2208 @findex tags-apropos | |
2209 @kbd{M-x tags-apropos} is like @code{apropos} for tags | |
2210 (@pxref{Apropos}). It reads a regexp, then finds all the tags in the | |
2211 selected tags table whose entries match that regexp, and displays the | |
2212 tag names found. | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
2213 @vindex tags-apropos-additional-actions |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
2214 You can display additional output with @kbd{M-x tags-apropos} by customizing |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
2215 the variable @code{tags-apropos-additional-actions}. See its |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
2216 documentation for details. |
25829 | 2217 |
2218 You can also perform completion in the buffer on the name space of tag | |
2219 names in the current tags tables. @xref{Symbol Completion}. | |
2220 | |
2221 @node Emerge | |
2222 @section Merging Files with Emerge | |
2223 @cindex Emerge | |
2224 @cindex merging files | |
2225 | |
2226 It's not unusual for programmers to get their signals crossed and modify | |
2227 the same program in two different directions. To recover from this | |
2228 confusion, you need to merge the two versions. Emerge makes this | |
2229 easier. See also @ref{Comparing Files}, for commands to compare | |
2230 in a more manual fashion, and @ref{Emerge,,, ediff, The Ediff Manual}. | |
2231 | |
2232 @menu | |
2233 * Overview of Emerge:: How to start Emerge. Basic concepts. | |
2234 * Submodes of Emerge:: Fast mode vs. Edit mode. | |
2235 Skip Prefers mode and Auto Advance mode. | |
2236 * State of Difference:: You do the merge by specifying state A or B | |
2237 for each difference. | |
2238 * Merge Commands:: Commands for selecting a difference, | |
2239 changing states of differences, etc. | |
2240 * Exiting Emerge:: What to do when you've finished the merge. | |
2241 * Combining in Emerge:: How to keep both alternatives for a difference. | |
2242 * Fine Points of Emerge:: Misc. | |
2243 @end menu | |
2244 | |
2245 @node Overview of Emerge | |
2246 @subsection Overview of Emerge | |
2247 | |
2248 To start Emerge, run one of these four commands: | |
2249 | |
2250 @table @kbd | |
2251 @item M-x emerge-files | |
2252 @findex emerge-files | |
2253 Merge two specified files. | |
2254 | |
2255 @item M-x emerge-files-with-ancestor | |
2256 @findex emerge-files-with-ancestor | |
2257 Merge two specified files, with reference to a common ancestor. | |
2258 | |
2259 @item M-x emerge-buffers | |
2260 @findex emerge-buffers | |
2261 Merge two buffers. | |
2262 | |
2263 @item M-x emerge-buffers-with-ancestor | |
2264 @findex emerge-buffers-with-ancestor | |
2265 Merge two buffers with reference to a common ancestor in a third | |
2266 buffer. | |
2267 @end table | |
2268 | |
2269 @cindex merge buffer (Emerge) | |
2270 @cindex A and B buffers (Emerge) | |
2271 The Emerge commands compare two files or buffers, and display the | |
2272 comparison in three buffers: one for each input text (the @dfn{A buffer} | |
2273 and the @dfn{B buffer}), and one (the @dfn{merge buffer}) where merging | |
2274 takes place. The merge buffer shows the full merged text, not just the | |
2275 differences. Wherever the two input texts differ, you can choose which | |
2276 one of them to include in the merge buffer. | |
2277 | |
2278 The Emerge commands that take input from existing buffers use only the | |
2279 accessible portions of those buffers, if they are narrowed | |
2280 (@pxref{Narrowing}). | |
2281 | |
2282 If a common ancestor version is available, from which the two texts to | |
2283 be merged were both derived, Emerge can use it to guess which | |
2284 alternative is right. Wherever one current version agrees with the | |
2285 ancestor, Emerge presumes that the other current version is a deliberate | |
2286 change which should be kept in the merged version. Use the | |
2287 @samp{with-ancestor} commands if you want to specify a common ancestor | |
2288 text. These commands read three file or buffer names---variant A, | |
2289 variant B, and the common ancestor. | |
2290 | |
2291 After the comparison is done and the buffers are prepared, the | |
2292 interactive merging starts. You control the merging by typing special | |
2293 @dfn{merge commands} in the merge buffer. The merge buffer shows you a | |
2294 full merged text, not just differences. For each run of differences | |
2295 between the input texts, you can choose which one of them to keep, or | |
2296 edit them both together. | |
2297 | |
2298 The merge buffer uses a special major mode, Emerge mode, with commands | |
2299 for making these choices. But you can also edit the buffer with | |
2300 ordinary Emacs commands. | |
2301 | |
2302 At any given time, the attention of Emerge is focused on one | |
2303 particular difference, called the @dfn{selected} difference. This | |
2304 difference is marked off in the three buffers like this: | |
2305 | |
2306 @example | |
2307 vvvvvvvvvvvvvvvvvvvv | |
2308 @var{text that differs} | |
2309 ^^^^^^^^^^^^^^^^^^^^ | |
2310 @end example | |
2311 | |
2312 @noindent | |
2313 Emerge numbers all the differences sequentially and the mode | |
2314 line always shows the number of the selected difference. | |
2315 | |
2316 Normally, the merge buffer starts out with the A version of the text. | |
2317 But when the A version of a difference agrees with the common ancestor, | |
2318 then the B version is initially preferred for that difference. | |
2319 | |
2320 Emerge leaves the merged text in the merge buffer when you exit. At | |
2321 that point, you can save it in a file with @kbd{C-x C-w}. If you give a | |
2322 numeric argument to @code{emerge-files} or | |
2323 @code{emerge-files-with-ancestor}, it reads the name of the output file | |
2324 using the minibuffer. (This is the last file name those commands read.) | |
2325 Then exiting from Emerge saves the merged text in the output file. | |
2326 | |
2327 Normally, Emerge commands save the output buffer in its file when you | |
2328 exit. If you abort Emerge with @kbd{C-]}, the Emerge command does not | |
2329 save the output buffer, but you can save it yourself if you wish. | |
2330 | |
2331 @node Submodes of Emerge | |
2332 @subsection Submodes of Emerge | |
2333 | |
2334 You can choose between two modes for giving merge commands: Fast mode | |
2335 and Edit mode. In Fast mode, basic merge commands are single | |
2336 characters, but ordinary Emacs commands are disabled. This is | |
2337 convenient if you use only merge commands. In Edit mode, all merge | |
2338 commands start with the prefix key @kbd{C-c C-c}, and the normal Emacs | |
2339 commands are also available. This allows editing the merge buffer, but | |
2340 slows down Emerge operations. | |
2341 | |
2342 Use @kbd{e} to switch to Edit mode, and @kbd{C-c C-c f} to switch to | |
2343 Fast mode. The mode line indicates Edit and Fast modes with @samp{E} | |
2344 and @samp{F}. | |
2345 | |
2346 Emerge has two additional submodes that affect how particular merge | |
2347 commands work: Auto Advance mode and Skip Prefers mode. | |
2348 | |
2349 If Auto Advance mode is in effect, the @kbd{a} and @kbd{b} commands | |
2350 advance to the next difference. This lets you go through the merge | |
2351 faster as long as you simply choose one of the alternatives from the | |
2352 input. The mode line indicates Auto Advance mode with @samp{A}. | |
2353 | |
2354 If Skip Prefers mode is in effect, the @kbd{n} and @kbd{p} commands | |
2355 skip over differences in states prefer-A and prefer-B (@pxref{State of | |
2356 Difference}). Thus you see only differences for which neither version | |
2357 is presumed ``correct.'' The mode line indicates Skip Prefers mode with | |
2358 @samp{S}. | |
2359 | |
2360 @findex emerge-auto-advance-mode | |
2361 @findex emerge-skip-prefers-mode | |
2362 Use the command @kbd{s a} (@code{emerge-auto-advance-mode}) to set or | |
2363 clear Auto Advance mode. Use @kbd{s s} | |
2364 (@code{emerge-skip-prefers-mode}) to set or clear Skip Prefers mode. | |
2365 These commands turn on the mode with a positive argument, turns it off | |
2366 with a negative or zero argument, and toggle the mode with no argument. | |
2367 | |
2368 @node State of Difference | |
2369 @subsection State of a Difference | |
2370 | |
2371 In the merge buffer, a difference is marked with lines of @samp{v} and | |
2372 @samp{^} characters. Each difference has one of these seven states: | |
2373 | |
2374 @table @asis | |
2375 @item A | |
2376 The difference is showing the A version. The @kbd{a} command always | |
2377 produces this state; the mode line indicates it with @samp{A}. | |
2378 | |
2379 @item B | |
2380 The difference is showing the B version. The @kbd{b} command always | |
2381 produces this state; the mode line indicates it with @samp{B}. | |
2382 | |
2383 @item default-A | |
2384 @itemx default-B | |
2385 The difference is showing the A or the B state by default, because you | |
2386 haven't made a choice. All differences start in the default-A state | |
2387 (and thus the merge buffer is a copy of the A buffer), except those for | |
2388 which one alternative is ``preferred'' (see below). | |
2389 | |
2390 When you select a difference, its state changes from default-A or | |
2391 default-B to plain A or B. Thus, the selected difference never has | |
2392 state default-A or default-B, and these states are never displayed in | |
2393 the mode line. | |
2394 | |
2395 The command @kbd{d a} chooses default-A as the default state, and @kbd{d | |
2396 b} chooses default-B. This chosen default applies to all differences | |
2397 which you haven't ever selected and for which no alternative is preferred. | |
2398 If you are moving through the merge sequentially, the differences you | |
2399 haven't selected are those following the selected one. Thus, while | |
2400 moving sequentially, you can effectively make the A version the default | |
2401 for some sections of the merge buffer and the B version the default for | |
2402 others by using @kbd{d a} and @kbd{d b} between sections. | |
2403 | |
2404 @item prefer-A | |
2405 @itemx prefer-B | |
2406 The difference is showing the A or B state because it is | |
2407 @dfn{preferred}. This means that you haven't made an explicit choice, | |
2408 but one alternative seems likely to be right because the other | |
2409 alternative agrees with the common ancestor. Thus, where the A buffer | |
2410 agrees with the common ancestor, the B version is preferred, because | |
2411 chances are it is the one that was actually changed. | |
2412 | |
2413 These two states are displayed in the mode line as @samp{A*} and @samp{B*}. | |
2414 | |
2415 @item combined | |
2416 The difference is showing a combination of the A and B states, as a | |
2417 result of the @kbd{x c} or @kbd{x C} commands. | |
2418 | |
2419 Once a difference is in this state, the @kbd{a} and @kbd{b} commands | |
2420 don't do anything to it unless you give them a numeric argument. | |
2421 | |
2422 The mode line displays this state as @samp{comb}. | |
2423 @end table | |
2424 | |
2425 @node Merge Commands | |
2426 @subsection Merge Commands | |
2427 | |
2428 Here are the Merge commands for Fast mode; in Edit mode, precede them | |
2429 with @kbd{C-c C-c}: | |
2430 | |
2431 @table @kbd | |
2432 @item p | |
2433 Select the previous difference. | |
2434 | |
2435 @item n | |
2436 Select the next difference. | |
2437 | |
2438 @item a | |
2439 Choose the A version of this difference. | |
2440 | |
2441 @item b | |
2442 Choose the B version of this difference. | |
2443 | |
2444 @item C-u @var{n} j | |
2445 Select difference number @var{n}. | |
2446 | |
2447 @item . | |
2448 Select the difference containing point. You can use this command in the | |
2449 merge buffer or in the A or B buffer. | |
2450 | |
2451 @item q | |
2452 Quit---finish the merge. | |
2453 | |
2454 @item C-] | |
2455 Abort---exit merging and do not save the output. | |
2456 | |
2457 @item f | |
2458 Go into Fast mode. (In Edit mode, this is actually @kbd{C-c C-c f}.) | |
2459 | |
2460 @item e | |
2461 Go into Edit mode. | |
2462 | |
2463 @item l | |
2464 Recenter (like @kbd{C-l}) all three windows. | |
2465 | |
26264 | 2466 @item - |
25829 | 2467 Specify part of a prefix numeric argument. |
2468 | |
2469 @item @var{digit} | |
2470 Also specify part of a prefix numeric argument. | |
2471 | |
2472 @item d a | |
2473 Choose the A version as the default from here down in | |
2474 the merge buffer. | |
2475 | |
2476 @item d b | |
2477 Choose the B version as the default from here down in | |
2478 the merge buffer. | |
2479 | |
2480 @item c a | |
2481 Copy the A version of this difference into the kill ring. | |
2482 | |
2483 @item c b | |
2484 Copy the B version of this difference into the kill ring. | |
2485 | |
2486 @item i a | |
2487 Insert the A version of this difference at point. | |
2488 | |
2489 @item i b | |
2490 Insert the B version of this difference at point. | |
2491 | |
2492 @item m | |
2493 Put point and mark around the difference. | |
2494 | |
2495 @item ^ | |
2496 Scroll all three windows down (like @kbd{M-v}). | |
2497 | |
2498 @item v | |
2499 Scroll all three windows up (like @kbd{C-v}). | |
2500 | |
2501 @item < | |
2502 Scroll all three windows left (like @kbd{C-x <}). | |
2503 | |
2504 @item > | |
2505 Scroll all three windows right (like @kbd{C-x >}). | |
2506 | |
2507 @item | | |
2508 Reset horizontal scroll on all three windows. | |
2509 | |
2510 @item x 1 | |
2511 Shrink the merge window to one line. (Use @kbd{C-u l} to restore it | |
2512 to full size.) | |
2513 | |
2514 @item x c | |
2515 Combine the two versions of this difference (@pxref{Combining in | |
2516 Emerge}). | |
2517 | |
2518 @item x f | |
2519 Show the names of the files/buffers Emerge is operating on, in a Help | |
2520 window. (Use @kbd{C-u l} to restore windows.) | |
2521 | |
2522 @item x j | |
2523 Join this difference with the following one. | |
2524 (@kbd{C-u x j} joins this difference with the previous one.) | |
2525 | |
2526 @item x s | |
2527 Split this difference into two differences. Before you use this | |
2528 command, position point in each of the three buffers at the place where | |
2529 you want to split the difference. | |
2530 | |
2531 @item x t | |
2532 Trim identical lines off the top and bottom of the difference. | |
2533 Such lines occur when the A and B versions are | |
2534 identical but differ from the ancestor version. | |
2535 @end table | |
2536 | |
2537 @node Exiting Emerge | |
2538 @subsection Exiting Emerge | |
2539 | |
2540 The @kbd{q} command (@code{emerge-quit}) finishes the merge, storing | |
2541 the results into the output file if you specified one. It restores the | |
2542 A and B buffers to their proper contents, or kills them if they were | |
2543 created by Emerge and you haven't changed them. It also disables the | |
2544 Emerge commands in the merge buffer, since executing them later could | |
2545 damage the contents of the various buffers. | |
2546 | |
2547 @kbd{C-]} aborts the merge. This means exiting without writing the | |
2548 output file. If you didn't specify an output file, then there is no | |
2549 real difference between aborting and finishing the merge. | |
2550 | |
2551 If the Emerge command was called from another Lisp program, then its | |
2552 return value is @code{t} for successful completion, or @code{nil} if you | |
2553 abort. | |
2554 | |
2555 @node Combining in Emerge | |
2556 @subsection Combining the Two Versions | |
2557 | |
2558 Sometimes you want to keep @emph{both} alternatives for a particular | |
2559 difference. To do this, use @kbd{x c}, which edits the merge buffer | |
2560 like this: | |
2561 | |
2562 @example | |
2563 @group | |
2564 #ifdef NEW | |
2565 @var{version from A buffer} | |
2566 #else /* not NEW */ | |
2567 @var{version from B buffer} | |
2568 #endif /* not NEW */ | |
2569 @end group | |
2570 @end example | |
2571 | |
2572 @noindent | |
2573 @vindex emerge-combine-versions-template | |
2574 While this example shows C preprocessor conditionals delimiting the two | |
2575 alternative versions, you can specify the strings to use by setting | |
2576 the variable @code{emerge-combine-versions-template} to a string of your | |
2577 choice. In the string, @samp{%a} says where to put version A, and | |
2578 @samp{%b} says where to put version B. The default setting, which | |
2579 produces the results shown above, looks like this: | |
2580 | |
2581 @example | |
2582 @group | |
2583 "#ifdef NEW\n%a#else /* not NEW */\n%b#endif /* not NEW */\n" | |
2584 @end group | |
2585 @end example | |
2586 | |
2587 @node Fine Points of Emerge | |
2588 @subsection Fine Points of Emerge | |
2589 | |
2590 During the merge, you mustn't try to edit the A and B buffers yourself. | |
2591 Emerge modifies them temporarily, but ultimately puts them back the way | |
2592 they were. | |
2593 | |
2594 You can have any number of merges going at once---just don't use any one | |
2595 buffer as input to more than one merge at once, since the temporary | |
2596 changes made in these buffers would get in each other's way. | |
2597 | |
2598 Starting Emerge can take a long time because it needs to compare the | |
2599 files fully. Emacs can't do anything else until @code{diff} finishes. | |
2600 Perhaps in the future someone will change Emerge to do the comparison in | |
2601 the background when the input files are large---then you could keep on | |
2602 doing other things with Emacs until Emerge is ready to accept | |
2603 commands. | |
2604 | |
2605 @vindex emerge-startup-hook | |
2606 After setting up the merge, Emerge runs the hook | |
2607 @code{emerge-startup-hook} (@pxref{Hooks}). | |
2608 | |
2609 @node C Modes | |
2610 @section C and Related Modes | |
2611 @cindex C mode | |
2612 @cindex Java mode | |
2613 @cindex Pike mode | |
2614 @cindex IDL mode | |
2615 @cindex CORBA IDL mode | |
2616 @cindex Objective C mode | |
2617 @cindex C++ mode | |
2618 @cindex mode, Java | |
2619 @cindex mode, C | |
2620 @cindex mode, Objective C | |
2621 @cindex mode, CORBA IDL | |
2622 @cindex mode, Pike | |
2623 | |
2624 This section describes special features available in C, C++, | |
2625 Objective-C, Java, CORBA IDL, and Pike modes. When we say ``C mode and | |
2626 related modes,'' those are the modes we mean. | |
2627 | |
2628 @menu | |
2629 * Motion in C:: | |
2630 * Electric C:: | |
2631 * Hungry Delete:: | |
2632 * Other C Commands:: | |
2633 * Comments in C:: | |
2634 @end menu | |
2635 | |
2636 @node Motion in C | |
2637 @subsection C Mode Motion Commands | |
2638 | |
2639 This section describes commands for moving point, in C mode and | |
2640 related modes. | |
2641 | |
2642 @table @code | |
2643 @item C-c C-u | |
2644 @kindex C-c C-u @r{(C mode)} | |
2645 @findex c-up-conditional | |
2646 Move point back to the containing preprocessor conditional, leaving the | |
2647 mark behind. A prefix argument acts as a repeat count. With a negative | |
2648 argument, move point forward to the end of the containing | |
2649 preprocessor conditional. When going backwards, @code{#elif} is treated | |
2650 like @code{#else} followed by @code{#if}. When going forwards, | |
2651 @code{#elif} is ignored.@refill | |
2652 | |
2653 @item C-c C-p | |
2654 @kindex C-c C-p @r{(C mode)} | |
2655 @findex c-backward-conditional | |
2656 Move point back over a preprocessor conditional, leaving the mark | |
2657 behind. A prefix argument acts as a repeat count. With a negative | |
2658 argument, move forward. | |
2659 | |
2660 @item C-c C-n | |
2661 @kindex C-c C-n @r{(C mode)} | |
2662 @findex c-forward-conditional | |
2663 Move point forward across a preprocessor conditional, leaving the mark | |
2664 behind. A prefix argument acts as a repeat count. With a negative | |
2665 argument, move backward. | |
2666 | |
2667 @item M-a | |
2668 @kindex ESC a | |
2669 @findex c-beginning-of-statement | |
2670 Move point to the beginning of the innermost C statement | |
2671 (@code{c-beginning-of-statement}). If point is already at the beginning | |
2672 of a statement, move to the beginning of the preceding statement. With | |
2673 prefix argument @var{n}, move back @var{n} @minus{} 1 statements. | |
2674 | |
2675 If point is within a string or comment, or next to a comment (only | |
2676 whitespace between them), this command moves by sentences instead of | |
2677 statements. | |
2678 | |
2679 When called from a program, this function takes three optional | |
2680 arguments: the numeric prefix argument, a buffer position limit | |
2681 (don't move back before that place), and a flag that controls whether | |
2682 to do sentence motion when inside of a comment. | |
2683 | |
2684 @item M-e | |
2685 @kindex ESC e | |
2686 @findex c-end-of-statement | |
2687 Move point to the end of the innermost C statement; like @kbd{M-a} | |
2688 except that it moves in the other direction (@code{c-end-of-statement}). | |
2689 | |
2690 @item M-x c-backward-into-nomenclature | |
2691 @findex c-backward-into-nomenclature | |
2692 Move point backward to beginning of a C++ nomenclature section or word. | |
2693 With prefix argument @var{n}, move @var{n} times. If @var{n} is | |
2694 negative, move forward. C++ nomenclature means a symbol name in the | |
2695 style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital letter | |
2696 begins a section or word. | |
2697 | |
2698 In the GNU project, we recommend using underscores to separate words | |
2699 within an identifier in C or C++, rather than using case distinctions. | |
2700 | |
2701 @item M-x c-forward-into-nomenclature | |
2702 @findex c-forward-into-nomenclature | |
2703 Move point forward to end of a C++ nomenclature section or word. | |
2704 With prefix argument @var{n}, move @var{n} times. | |
2705 @end table | |
2706 | |
2707 @node Electric C | |
2708 @subsection Electric C Characters | |
2709 | |
2710 In C mode and related modes, certain printing characters are | |
2711 ``electric''---in addition to inserting themselves, they also reindent | |
2712 the current line and may insert newlines. This feature is controlled by | |
2713 the variable @code{c-auto-newline}. The ``electric'' characters are | |
2714 @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#}, @kbd{;}, @kbd{,}, @kbd{<}, | |
2715 @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and @kbd{)}. | |
2716 | |
2717 Electric characters insert newlines only when the @dfn{auto-newline} | |
2718 feature is enabled (indicated by @samp{/a} in the mode line after the | |
2719 mode name). This feature is controlled by the variable | |
2720 @code{c-auto-newline}. You can turn this feature on or off with the | |
2721 command @kbd{C-c C-a}: | |
2722 | |
2723 @table @kbd | |
2724 @item C-c C-a | |
2725 @kindex C-c C-a @r{(C mode)} | |
2726 @findex c-toggle-auto-state | |
2727 Toggle the auto-newline feature (@code{c-toggle-auto-state}). With a | |
2728 prefix argument, this command turns the auto-newline feature on if the | |
2729 argument is positive, and off if it is negative. | |
2730 @end table | |
2731 | |
2732 The colon character is electric because that is appropriate for a | |
2733 single colon. But when you want to insert a double colon in C++, the | |
2734 electric behavior of colon is inconvenient. You can insert a double | |
2735 colon with no reindentation or newlines by typing @kbd{C-c :}: | |
2736 | |
2737 @table @kbd | |
2738 @item C-c : | |
2739 @kindex C-c : @r{(C mode)} | |
2740 @findex c-scope-operator | |
2741 Insert a double colon scope operator at point, without reindenting the | |
2742 line or adding any newlines (@code{c-scope-operator}). | |
2743 @end table | |
2744 | |
2745 The electric @kbd{#} key reindents the line if it appears to be the | |
2746 beginning of a preprocessor directive. This happens when the value of | |
2747 @code{c-electric-pound-behavior} is @code{(alignleft)}. You can turn | |
2748 this feature off by setting @code{c-electric-pound-behavior} to | |
2749 @code{nil}. | |
2750 | |
2751 The variable @code{c-hanging-braces-alist} controls the insertion of | |
2752 newlines before and after inserted braces. It is an association list | |
2753 with elements of the following form: @code{(@var{syntactic-symbol} | |
2754 . @var{nl-list})}. Most of the syntactic symbols that appear in | |
2755 @code{c-offsets-alist} are meaningful here as well. | |
2756 | |
2757 The list @var{nl-list} may contain either of the symbols | |
2758 @code{before} or @code{after}, or both; or it may be @code{nil}. When a | |
2759 brace is inserted, the syntactic context it defines is looked up in | |
2760 @code{c-hanging-braces-alist}; if it is found, the @var{nl-list} is used | |
2761 to determine where newlines are inserted: either before the brace, | |
2762 after, or both. If not found, the default is to insert a newline both | |
2763 before and after braces. | |
2764 | |
2765 The variable @code{c-hanging-colons-alist} controls the insertion of | |
2766 newlines before and after inserted colons. It is an association list | |
2767 with elements of the following form: @code{(@var{syntactic-symbol} | |
2768 . @var{nl-list})}. The list @var{nl-list} may contain either of the | |
2769 symbols @code{before} or @code{after}, or both; or it may be @code{nil}. | |
2770 | |
2771 When a colon is inserted, the syntactic symbol it defines is looked | |
2772 up in this list, and if found, the @var{nl-list} is used to determine | |
2773 where newlines are inserted: either before the brace, after, or both. | |
2774 If the syntactic symbol is not found in this list, no newlines are | |
2775 inserted. | |
2776 | |
2777 Electric characters can also delete newlines automatically when the | |
2778 auto-newline feature is enabled. This feature makes auto-newline more | |
2779 acceptable, by deleting the newlines in the most common cases where you | |
2780 do not want them. Emacs can recognize several cases in which deleting a | |
2781 newline might be desirable; by setting the variable | |
2782 @code{c-cleanup-list}, you can specify @emph{which} of these cases that | |
2783 should happen. The variable's value is a list of symbols, each | |
2784 describing one case for possible deletion of a newline. Here are the | |
2785 meaningful symbols, and their meanings: | |
2786 | |
2787 @table @code | |
2788 @item brace-catch-brace | |
2789 Clean up @samp{@} catch (@var{condition}) @{} constructs by placing the | |
2790 entire construct on a single line. The clean-up occurs when you type | |
2791 the @samp{@{}, if there is nothing between the braces aside from | |
2792 @code{catch} and @var{condition}. | |
2793 | |
2794 @item brace-else-brace | |
2795 Clean up @samp{@} else @{} constructs by placing the entire construct on | |
2796 a single line. The clean-up occurs when you type the @samp{@{} after | |
2797 the @code{else}, but only if there is nothing but white space between | |
2798 the braces and the @code{else}. | |
2799 | |
2800 @item brace-elseif-brace | |
2801 Clean up @samp{@} else if (@dots{}) @{} constructs by placing the entire | |
2802 construct on a single line. The clean-up occurs when you type the | |
2803 @samp{@{}, if there is nothing but white space between the @samp{@}} and | |
2804 @samp{@{} aside from the keywords and the @code{if}-condition. | |
2805 | |
2806 @item empty-defun-braces | |
2807 Clean up empty defun braces by placing the braces on the same | |
2808 line. Clean-up occurs when you type the closing brace. | |
2809 | |
2810 @item defun-close-semi | |
2811 Clean up the semicolon after a @code{struct} or similar type | |
2812 declaration, by placing the semicolon on the same line as the closing | |
2813 brace. Clean-up occurs when you type the semicolon. | |
2814 | |
2815 @item list-close-comma | |
2816 Clean up commas following braces in array and aggregate | |
2817 initializers. Clean-up occurs when you type the comma. | |
2818 | |
2819 @item scope-operator | |
2820 Clean up double colons which may designate a C++ scope operator, by | |
2821 placing the colons together. Clean-up occurs when you type the second | |
2822 colon, but only when the two colons are separated by nothing but | |
2823 whitespace. | |
2824 @end table | |
2825 | |
2826 @node Hungry Delete | |
2827 @subsection Hungry Delete Feature in C | |
2828 | |
2829 When the @dfn{hungry-delete} feature is enabled (indicated by | |
2830 @samp{/h} or @samp{/ah} in the mode line after the mode name), a single | |
2831 @key{DEL} command deletes all preceding whitespace, not just one space. | |
2832 To turn this feature on or off, use @kbd{C-c C-d}: | |
2833 | |
2834 @table @kbd | |
2835 @item C-c C-d | |
2836 @kindex C-c C-d @r{(C mode)} | |
2837 @findex c-toggle-hungry-state | |
2838 Toggle the hungry-delete feature (@code{c-toggle-hungry-state}). With a | |
2839 prefix argument, this command turns the hungry-delete feature on if the | |
2840 argument is positive, and off if it is negative. | |
2841 | |
2842 @item C-c C-t | |
2843 @kindex C-c C-t @r{(C mode)} | |
2844 @findex c-toggle-auto-hungry-state | |
2845 Toggle the auto-newline and hungry-delete features, both at once | |
2846 (@code{c-toggle-auto-hungry-state}). | |
2847 @end table | |
2848 | |
2849 @vindex c-hungry-delete-key | |
2850 The variable @code{c-hungry-delete-key} controls whether the | |
2851 hungry-delete feature is enabled. | |
2852 | |
2853 @node Other C Commands | |
2854 @subsection Other Commands for C Mode | |
2855 | |
2856 @table @kbd | |
2857 @item C-M-h | |
2858 @findex c-mark-function | |
2859 @kindex C-M-h @r{(C mode)} | |
2860 Put mark at the end of a function definition, and put point at the | |
2861 beginning (@code{c-mark-function}). | |
2862 | |
2863 @item M-q | |
2864 @kindex M-q @r{(C mode)} | |
2865 @findex c-fill-paragraph | |
2866 Fill a paragraph, handling C and C++ comments (@code{c-fill-paragraph}). | |
2867 If any part of the current line is a comment or within a comment, this | |
2868 command fills the comment or the paragraph of it that point is in, | |
2869 preserving the comment indentation and comment delimiters. | |
2870 | |
2871 @item C-c C-e | |
2872 @cindex macro expansion in C | |
2873 @cindex expansion of C macros | |
2874 @findex c-macro-expand | |
2875 @kindex C-c C-e @r{(C mode)} | |
2876 Run the C preprocessor on the text in the region, and show the result, | |
2877 which includes the expansion of all the macro calls | |
2878 (@code{c-macro-expand}). The buffer text before the region is also | |
2879 included in preprocessing, for the sake of macros defined there, but the | |
2880 output from this part isn't shown. | |
2881 | |
2882 When you are debugging C code that uses macros, sometimes it is hard to | |
2883 figure out precisely how the macros expand. With this command, you | |
2884 don't have to figure it out; you can see the expansions. | |
2885 | |
2886 @item C-c C-\ | |
2887 @findex c-backslash-region | |
2888 @kindex C-c C-\ @r{(C mode)} | |
2889 Insert or align @samp{\} characters at the ends of the lines of the | |
2890 region (@code{c-backslash-region}). This is useful after writing or | |
2891 editing a C macro definition. | |
2892 | |
2893 If a line already ends in @samp{\}, this command adjusts the amount of | |
2894 whitespace before it. Otherwise, it inserts a new @samp{\}. However, | |
2895 the last line in the region is treated specially; no @samp{\} is | |
2896 inserted on that line, and any @samp{\} there is deleted. | |
2897 | |
2898 @item M-x cpp-highlight-buffer | |
2899 @cindex preprocessor highlighting | |
2900 @findex cpp-highlight-buffer | |
2901 Highlight parts of the text according to its preprocessor conditionals. | |
2902 This command displays another buffer named @samp{*CPP Edit*}, which | |
2903 serves as a graphic menu for selecting how to display particular kinds | |
2904 of conditionals and their contents. After changing various settings, | |
2905 click on @samp{[A]pply these settings} (or go to that buffer and type | |
2906 @kbd{a}) to rehighlight the C mode buffer accordingly. | |
2907 | |
2908 @item C-c C-s | |
2909 @findex c-show-syntactic-information | |
2910 @kindex C-c C-s @r{(C mode)} | |
2911 Display the syntactic information about the current source line | |
2912 (@code{c-show-syntactic-information}). This is the information that | |
2913 directs how the line is indented. | |
2914 @end table | |
2915 | |
2916 @node Comments in C | |
2917 @subsection Comments in C Modes | |
2918 | |
2919 C mode and related modes use a number of variables for controlling | |
2920 comment format. | |
2921 | |
2922 @table @code | |
2923 @item c-comment-only-line-offset | |
2924 @vindex c-comment-only-line-offset | |
2925 Extra offset for line which contains only the start of a comment. It | |
2926 can be either an integer or a cons cell of the form | |
2927 @code{(@var{non-anchored-offset} . @var{anchored-offset})}, where | |
2928 @var{non-anchored-offset} is the amount of offset given to | |
2929 non-column-zero anchored comment-only lines, and @var{anchored-offset} | |
2930 is the amount of offset to give column-zero anchored comment-only lines. | |
2931 Just an integer as value is equivalent to @code{(@var{val} . 0)}. | |
2932 | |
2933 @item c-comment-start-regexp | |
2934 @vindex c-comment-start-regexp | |
2935 This buffer-local variable specifies how to recognize the start of a comment. | |
2936 | |
2937 @item c-hanging-comment-ender-p | |
2938 @vindex c-hanging-comment-ender-p | |
2939 If this variable is @code{nil}, @code{c-fill-paragraph} leaves the | |
2940 comment terminator of a block comment on a line by itself. The default | |
2941 value is @code{t}, which puts the comment-end delimiter @samp{*/} at the | |
2942 end of the last line of the comment text. | |
2943 | |
2944 @item c-hanging-comment-starter-p | |
2945 @vindex c-hanging-comment-starter-p | |
2946 If this variable is @code{nil}, @code{c-fill-paragraph} leaves the | |
2947 starting delimiter of a block comment on a line by itself. The default | |
2948 value is @code{t}, which puts the comment-start delimiter @samp{/*} at | |
2949 the beginning of the first line of the comment text. | |
2950 @end table | |
2951 | |
2952 @node Fortran | |
2953 @section Fortran Mode | |
2954 @cindex Fortran mode | |
2955 @cindex mode, Fortran | |
2956 | |
2957 Fortran mode provides special motion commands for Fortran statements and | |
2958 subprograms, and indentation commands that understand Fortran conventions | |
2959 of nesting, line numbers and continuation statements. Fortran mode has | |
2960 its own Auto Fill mode that breaks long lines into proper Fortran | |
2961 continuation lines. | |
2962 | |
2963 Special commands for comments are provided because Fortran comments | |
2964 are unlike those of other languages. Built-in abbrevs optionally save | |
2965 typing when you insert Fortran keywords. | |
2966 | |
2967 @findex fortran-mode | |
2968 Use @kbd{M-x fortran-mode} to switch to this major mode. This command | |
2969 runs the hook @code{fortran-mode-hook} (@pxref{Hooks}). | |
2970 | |
26106 | 2971 @cindex Fortran77 |
2972 @cindex Fortran90 | |
2973 @findex f90-mode | |
2974 @findex fortran-mode | |
2975 Note that Fortan mode described here (obtained with the | |
2976 @code{fortran-mode} command) is for editing the old Fortran77 | |
2977 idiosyncratic `fixed format' source form. For editing the modern | |
2978 Fortran90 `free format' source form (which is supported by the GNU | |
2979 Fortran compiler) use @code{f90-mode}. | |
2980 | |
2981 By default @code{fortran-mode} is invoked on files with extension | |
2982 @samp{.f}, @samp{.F} or @samp{.for} and @code{f90-mode} is invoked for | |
2983 the extension @samp{.f90}. | |
2984 | |
25829 | 2985 @menu |
2986 * Motion: Fortran Motion. Moving point by statements or subprograms. | |
2987 * Indent: Fortran Indent. Indentation commands for Fortran. | |
2988 * Comments: Fortran Comments. Inserting and aligning comments. | |
2989 * Autofill: Fortran Autofill. Auto fill minor mode for Fortran. | |
2990 * Columns: Fortran Columns. Measuring columns for valid Fortran. | |
2991 * Abbrev: Fortran Abbrev. Built-in abbrevs for Fortran keywords. | |
2992 * Misc: Fortran Misc. Other Fortran mode features. | |
2993 @end menu | |
2994 | |
2995 @node Fortran Motion | |
2996 @subsection Motion Commands | |
2997 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
2998 In addition to the normal commands for moving by and operating on |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
2999 `defuns' (Fortran subprograms---functions |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3000 and subroutines) Fortran mode provides special commands to move by statements. |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3001 |
25829 | 3002 @kindex C-c C-p @r{(Fortran mode)} |
3003 @kindex C-c C-n @r{(Fortran mode)} | |
3004 @findex fortran-previous-statement | |
3005 @findex fortran-next-statement | |
3006 | |
3007 @table @kbd | |
3008 @item C-c C-n | |
3009 Move to beginning of current or next statement | |
3010 (@code{fortran-next-statement}). | |
3011 @item C-c C-p | |
3012 Move to beginning of current or previous statement | |
3013 (@code{fortran-previous-statement}). | |
3014 @end table | |
3015 | |
3016 @node Fortran Indent | |
3017 @subsection Fortran Indentation | |
3018 | |
3019 Special commands and features are needed for indenting Fortran code in | |
3020 order to make sure various syntactic entities (line numbers, comment line | |
3021 indicators and continuation line flags) appear in the columns that are | |
3022 required for standard Fortran. | |
3023 | |
3024 @menu | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3025 * Commands: ForIndent Commands. Commands for indenting and filling Fortran. |
25829 | 3026 * Contline: ForIndent Cont. How continuation lines indent. |
3027 * Numbers: ForIndent Num. How line numbers auto-indent. | |
3028 * Conv: ForIndent Conv. Conventions you must obey to avoid trouble. | |
3029 * Vars: ForIndent Vars. Variables controlling Fortran indent style. | |
3030 @end menu | |
3031 | |
3032 @node ForIndent Commands | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3033 @subsubsection Fortran-Specific Indentation and Filling Commands |
25829 | 3034 |
3035 @table @kbd | |
3036 @item C-M-j | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3037 Break the current line and set up a continuation line |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3038 (@code{fortran-split-line}). |
25829 | 3039 @item M-^ |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3040 Join this line to the previous line (@code{fortran-join-line}). |
25829 | 3041 @item C-M-q |
3042 Indent all the lines of the subprogram point is in | |
3043 (@code{fortran-indent-subprogram}). | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3044 @item M-q |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3045 Fill a comment block or statement. |
25829 | 3046 @end table |
3047 | |
3048 @kindex C-M-q @r{(Fortran mode)} | |
3049 @findex fortran-indent-subprogram | |
3050 The key @kbd{C-M-q} runs @code{fortran-indent-subprogram}, a command | |
3051 to reindent all the lines of the Fortran subprogram (function or | |
3052 subroutine) containing point. | |
3053 | |
3054 @kindex C-M-j @r{(Fortran mode)} | |
3055 @findex fortran-split-line | |
3056 The key @kbd{C-M-j} runs @code{fortran-split-line}, which splits | |
3057 a line in the appropriate fashion for Fortran. In a non-comment line, | |
3058 the second half becomes a continuation line and is indented | |
3059 accordingly. In a comment line, both halves become separate comment | |
3060 lines. | |
3061 | |
3062 @kindex M-^ @r{(Fortran mode)} | |
26106 | 3063 @kindex C-c C-d @r{(Fortran mode)} |
3064 @findex fortran-join-line | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3065 @kbd{M-^} or @kbd{C-c C-d} runs the command @code{fortran-join-line}, |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3066 which joins a continuation line back to the previous line, roughly as |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3067 the inverse of @code{fortran-split-line}. The point must be on a |
26106 | 3068 continuation line when this command is invoked. |
3069 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3070 @kindex M-q @r{(Fortran mode)} |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3071 Fortran mode defines the function for filling paragraphs such that |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3072 @kbd{M-q} fills the comment block or statement around point. Filling a |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3073 statement removes excess statement continuations. |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3074 |
25829 | 3075 @node ForIndent Cont |
3076 @subsubsection Continuation Lines | |
3077 @cindex Fortran continuation lines | |
3078 | |
3079 @vindex fortran-continuation-string | |
3080 Most modern Fortran compilers allow two ways of writing continuation | |
3081 lines. If the first non-space character on a line is in column 5, then | |
3082 that line is a continuation of the previous line. We call this | |
3083 @dfn{fixed format}. (In GNU Emacs we always count columns from 0.) The | |
3084 variable @code{fortran-continuation-string} specifies what character to | |
3085 put on column 5. A line that starts with a tab character followed by | |
3086 any digit except @samp{0} is also a continuation line. We call this | |
3087 style of continuation @dfn{tab format}. | |
3088 | |
3089 @vindex indent-tabs-mode @r{(Fortran mode)} | |
3090 Fortran mode can make either style of continuation line, but you | |
3091 must specify which one you prefer. The value of the variable | |
3092 @code{indent-tabs-mode} controls the choice: @code{nil} for fixed | |
3093 format, and non-@code{nil} for tab format. You can tell which style | |
3094 is presently in effect by the presence or absence of the string | |
3095 @samp{Tab} in the mode line. | |
3096 | |
3097 If the text on a line starts with the conventional Fortran | |
3098 continuation marker @samp{$}, or if it begins with any non-whitespace | |
3099 character in column 5, Fortran mode treats it as a continuation line. | |
3100 When you indent a continuation line with @key{TAB}, it converts the line | |
3101 to the current continuation style. When you split a Fortran statement | |
3102 with @kbd{C-M-j}, the continuation marker on the newline is created | |
3103 according to the continuation style. | |
3104 | |
3105 The setting of continuation style affects several other aspects of | |
3106 editing in Fortran mode. In fixed format mode, the minimum column | |
3107 number for the body of a statement is 6. Lines inside of Fortran | |
3108 blocks that are indented to larger column numbers always use only the | |
3109 space character for whitespace. In tab format mode, the minimum | |
3110 column number for the statement body is 8, and the whitespace before | |
3111 column 8 must always consist of one tab character. | |
3112 | |
3113 @vindex fortran-tab-mode-default | |
3114 @vindex fortran-analyze-depth | |
3115 When you enter Fortran mode for an existing file, it tries to deduce the | |
3116 proper continuation style automatically from the file contents. The first | |
3117 line that begins with either a tab character or six spaces determines the | |
3118 choice. The variable @code{fortran-analyze-depth} specifies how many lines | |
3119 to consider (at the beginning of the file); if none of those lines | |
3120 indicates a style, then the variable @code{fortran-tab-mode-default} | |
3121 specifies the style. If it is @code{nil}, that specifies fixed format, and | |
3122 non-@code{nil} specifies tab format. | |
3123 | |
3124 @node ForIndent Num | |
3125 @subsubsection Line Numbers | |
3126 | |
3127 If a number is the first non-whitespace in the line, Fortran | |
3128 indentation assumes it is a line number and moves it to columns 0 | |
3129 through 4. (Columns always count from 0 in GNU Emacs.) | |
3130 | |
3131 @vindex fortran-line-number-indent | |
3132 Line numbers of four digits or less are normally indented one space. | |
3133 The variable @code{fortran-line-number-indent} controls this; it | |
3134 specifies the maximum indentation a line number can have. Line numbers | |
3135 are indented to right-justify them to end in column 4 unless that would | |
3136 require more than this maximum indentation. The default value of the | |
3137 variable is 1. | |
3138 | |
3139 @vindex fortran-electric-line-number | |
3140 Simply inserting a line number is enough to indent it according to | |
3141 these rules. As each digit is inserted, the indentation is recomputed. | |
3142 To turn off this feature, set the variable | |
3143 @code{fortran-electric-line-number} to @code{nil}. Then inserting line | |
3144 numbers is like inserting anything else. | |
3145 | |
3146 @node ForIndent Conv | |
3147 @subsubsection Syntactic Conventions | |
3148 | |
3149 Fortran mode assumes that you follow certain conventions that simplify | |
3150 the task of understanding a Fortran program well enough to indent it | |
3151 properly: | |
3152 | |
3153 @itemize @bullet | |
3154 @item | |
3155 Two nested @samp{do} loops never share a @samp{continue} statement. | |
3156 | |
3157 @item | |
3158 Fortran keywords such as @samp{if}, @samp{else}, @samp{then}, @samp{do} | |
3159 and others are written without embedded whitespace or line breaks. | |
3160 | |
3161 Fortran compilers generally ignore whitespace outside of string | |
3162 constants, but Fortran mode does not recognize these keywords if they | |
3163 are not contiguous. Constructs such as @samp{else if} or @samp{end do} | |
3164 are acceptable, but the second word should be on the same line as the | |
3165 first and not on a continuation line. | |
3166 @end itemize | |
3167 | |
3168 @noindent | |
3169 If you fail to follow these conventions, the indentation commands may | |
3170 indent some lines unaesthetically. However, a correct Fortran program | |
3171 retains its meaning when reindented even if the conventions are not | |
3172 followed. | |
3173 | |
3174 @node ForIndent Vars | |
3175 @subsubsection Variables for Fortran Indentation | |
3176 | |
3177 @vindex fortran-do-indent | |
3178 @vindex fortran-if-indent | |
3179 @vindex fortran-structure-indent | |
3180 @vindex fortran-continuation-indent | |
3181 @vindex fortran-check-all-num@dots{} | |
3182 @vindex fortran-minimum-statement-indent@dots{} | |
3183 Several additional variables control how Fortran indentation works: | |
3184 | |
3185 @table @code | |
3186 @item fortran-do-indent | |
3187 Extra indentation within each level of @samp{do} statement (default 3). | |
3188 | |
3189 @item fortran-if-indent | |
3190 Extra indentation within each level of @samp{if} statement (default 3). | |
3191 This value is also used for extra indentation within each level of the | |
3192 Fortran 90 @samp{where} statement. | |
3193 | |
3194 @item fortran-structure-indent | |
3195 Extra indentation within each level of @samp{structure}, @samp{union}, or | |
3196 @samp{map} statements (default 3). | |
3197 | |
3198 @item fortran-continuation-indent | |
3199 Extra indentation for bodies of continuation lines (default 5). | |
3200 | |
3201 @item fortran-check-all-num-for-matching-do | |
3202 If this is @code{nil}, indentation assumes that each @samp{do} statement | |
3203 ends on a @samp{continue} statement. Therefore, when computing | |
3204 indentation for a statement other than @samp{continue}, it can save time | |
3205 by not checking for a @samp{do} statement ending there. If this is | |
3206 non-@code{nil}, indenting any numbered statement must check for a | |
3207 @samp{do} that ends there. The default is @code{nil}. | |
3208 | |
3209 @item fortran-blink-matching-if | |
3210 If this is @code{t}, indenting an @samp{endif} statement moves the | |
3211 cursor momentarily to the matching @samp{if} statement to show where it | |
3212 is. The default is @code{nil}. | |
3213 | |
3214 @item fortran-minimum-statement-indent-fixed | |
3215 Minimum indentation for fortran statements when using fixed format | |
3216 continuation line style. Statement bodies are never indented less than | |
3217 this much. The default is 6. | |
3218 | |
3219 @item fortran-minimum-statement-indent-tab | |
3220 Minimum indentation for fortran statements for tab format continuation line | |
3221 style. Statement bodies are never indented less than this much. The | |
3222 default is 8. | |
3223 @end table | |
3224 | |
3225 @node Fortran Comments | |
3226 @subsection Fortran Comments | |
3227 | |
3228 The usual Emacs comment commands assume that a comment can follow a line | |
3229 of code. In Fortran, the standard comment syntax requires an entire line | |
3230 to be just a comment. Therefore, Fortran mode replaces the standard Emacs | |
3231 comment commands and defines some new variables. | |
3232 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3233 Fortran mode can also handle the Fortran90 comment syntax where comments |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3234 start with @samp{!} and can follow other text. Because only some Fortran77 |
25829 | 3235 compilers accept this syntax, Fortran mode will not insert such comments |
3236 unless you have said in advance to do so. To do this, set the variable | |
3237 @code{comment-start} to @samp{"!"} (@pxref{Variables}). | |
3238 | |
3239 @table @kbd | |
3240 @item M-; | |
3241 Align comment or insert new comment (@code{fortran-comment-indent}). | |
3242 | |
3243 @item C-x ; | |
3244 Applies to nonstandard @samp{!} comments only. | |
3245 | |
3246 @item C-c ; | |
3247 Turn all lines of the region into comments, or (with argument) turn them back | |
3248 into real code (@code{fortran-comment-region}). | |
3249 @end table | |
3250 | |
3251 @kbd{M-;} in Fortran mode is redefined as the command | |
3252 @code{fortran-comment-indent}. Like the usual @kbd{M-;} command, this | |
3253 recognizes any kind of existing comment and aligns its text appropriately; | |
3254 if there is no existing comment, a comment is inserted and aligned. But | |
3255 inserting and aligning comments are not the same in Fortran mode as in | |
3256 other modes. | |
3257 | |
3258 When a new comment must be inserted, if the current line is blank, a | |
3259 full-line comment is inserted. On a non-blank line, a nonstandard @samp{!} | |
3260 comment is inserted if you have said you want to use them. Otherwise a | |
3261 full-line comment is inserted on a new line before the current line. | |
3262 | |
3263 Nonstandard @samp{!} comments are aligned like comments in other | |
3264 languages, but full-line comments are different. In a standard full-line | |
3265 comment, the comment delimiter itself must always appear in column zero. | |
3266 What can be aligned is the text within the comment. You can choose from | |
3267 three styles of alignment by setting the variable | |
3268 @code{fortran-comment-indent-style} to one of these values: | |
3269 | |
3270 @vindex fortran-comment-indent-style | |
3271 @vindex fortran-comment-line-extra-indent | |
3272 @table @code | |
3273 @item fixed | |
3274 Align the text at a fixed column, which is the sum of | |
3275 @code{fortran-comment-line-extra-indent} and the minimum statement | |
3276 indentation. This is the default. | |
3277 | |
3278 The minimum statement indentation is | |
3279 @code{fortran-minimum-statement-indent-fixed} for fixed format | |
3280 continuation line style and @code{fortran-minimum-statement-indent-tab} | |
3281 for tab format style. | |
3282 | |
3283 @item relative | |
3284 Align the text as if it were a line of code, but with an additional | |
3285 @code{fortran-comment-line-extra-indent} columns of indentation. | |
3286 | |
3287 @item nil | |
3288 Don't move text in full-line comments automatically at all. | |
3289 @end table | |
3290 | |
3291 @vindex fortran-comment-indent-char | |
3292 In addition, you can specify the character to be used to indent within | |
3293 full-line comments by setting the variable | |
3294 @code{fortran-comment-indent-char} to the single-character string you want | |
3295 to use. | |
3296 | |
3297 @vindex comment-line-start | |
3298 @vindex comment-line-start-skip | |
3299 Fortran mode introduces two variables @code{comment-line-start} and | |
3300 @code{comment-line-start-skip}, which play for full-line comments the same | |
3301 roles played by @code{comment-start} and @code{comment-start-skip} for | |
3302 ordinary text-following comments. Normally these are set properly by | |
3303 Fortran mode, so you do not need to change them. | |
3304 | |
3305 The normal Emacs comment command @kbd{C-x ;} has not been redefined. If | |
3306 you use @samp{!} comments, this command can be used with them. Otherwise | |
3307 it is useless in Fortran mode. | |
3308 | |
3309 @kindex C-c ; @r{(Fortran mode)} | |
3310 @findex fortran-comment-region | |
3311 @vindex fortran-comment-region | |
3312 The command @kbd{C-c ;} (@code{fortran-comment-region}) turns all the | |
3313 lines of the region into comments by inserting the string @samp{C$$$} at | |
3314 the front of each one. With a numeric argument, it turns the region | |
3315 back into live code by deleting @samp{C$$$} from the front of each line | |
3316 in it. The string used for these comments can be controlled by setting | |
3317 the variable @code{fortran-comment-region}. Note that here we have an | |
3318 example of a command and a variable with the same name; these two uses | |
3319 of the name never conflict because in Lisp and in Emacs it is always | |
3320 clear from the context which one is meant. | |
3321 | |
3322 @node Fortran Autofill | |
3323 @subsection Fortran Auto Fill Mode | |
3324 | |
3325 Fortran Auto Fill mode is a minor mode which automatically splits | |
3326 Fortran statements as you insert them when they become too wide. | |
3327 Splitting a statement involves making continuation lines using | |
3328 @code{fortran-continuation-string} (@pxref{ForIndent Cont}). This | |
3329 splitting happens when you type @key{SPC}, @key{RET}, or @key{TAB}, and | |
3330 also in the Fortran indentation commands. | |
3331 | |
3332 @findex fortran-auto-fill-mode | |
3333 @kbd{M-x fortran-auto-fill-mode} turns Fortran Auto Fill mode on if it | |
3334 was off, or off if it was on. This command works the same as @kbd{M-x | |
3335 auto-fill-mode} does for normal Auto Fill mode (@pxref{Filling}). A | |
3336 positive numeric argument turns Fortran Auto Fill mode on, and a | |
3337 negative argument turns it off. You can see when Fortran Auto Fill mode | |
3338 is in effect by the presence of the word @samp{Fill} in the mode line, | |
3339 inside the parentheses. Fortran Auto Fill mode is a minor mode, turned | |
3340 on or off for each buffer individually. @xref{Minor Modes}. | |
3341 | |
3342 @vindex fortran-break-before-delimiters | |
3343 Fortran Auto Fill mode breaks lines at spaces or delimiters when the | |
3344 lines get longer than the desired width (the value of @code{fill-column}). | |
3345 The delimiters that Fortran Auto Fill mode may break at are @samp{,}, | |
3346 @samp{'}, @samp{+}, @samp{-}, @samp{/}, @samp{*}, @samp{=}, and @samp{)}. | |
3347 The line break comes after the delimiter if the variable | |
3348 @code{fortran-break-before-delimiters} is @code{nil}. Otherwise (and by | |
3349 default), the break comes before the delimiter. | |
3350 | |
3351 By default, Fortran Auto Fill mode is not enabled. If you want this | |
3352 feature turned on permanently, add a hook function to | |
3353 @code{fortran-mode-hook} to execute @code{(fortran-auto-fill-mode 1)}. | |
3354 @xref{Hooks}. | |
3355 | |
3356 @node Fortran Columns | |
3357 @subsection Checking Columns in Fortran | |
3358 | |
3359 @table @kbd | |
3360 @item C-c C-r | |
3361 Display a ``column ruler'' momentarily above the current line | |
3362 (@code{fortran-column-ruler}). | |
3363 @item C-c C-w | |
3364 Split the current window horizontally temporarily so that it is 72 | |
3365 columns wide. This may help you avoid making lines longer than the | |
3366 72-character limit that some Fortran compilers impose | |
3367 (@code{fortran-window-create-momentarily}). | |
3368 @end table | |
3369 | |
3370 @kindex C-c C-r @r{(Fortran mode)} | |
3371 @findex fortran-column-ruler | |
3372 @vindex fortran-column-ruler | |
3373 The command @kbd{C-c C-r} (@code{fortran-column-ruler}) shows a column | |
3374 ruler momentarily above the current line. The comment ruler is two lines | |
3375 of text that show you the locations of columns with special significance in | |
3376 Fortran programs. Square brackets show the limits of the columns for line | |
3377 numbers, and curly brackets show the limits of the columns for the | |
3378 statement body. Column numbers appear above them. | |
3379 | |
3380 Note that the column numbers count from zero, as always in GNU Emacs. | |
3381 As a result, the numbers may be one less than those you are familiar | |
3382 with; but the positions they indicate in the line are standard for | |
3383 Fortran. | |
3384 | |
26264 | 3385 The text used to display the column ruler depends on the value of |
25829 | 3386 the variable @code{indent-tabs-mode}. If @code{indent-tabs-mode} is |
3387 @code{nil}, then the value of the variable | |
3388 @code{fortran-column-ruler-fixed} is used as the column ruler. | |
3389 Otherwise, the variable @code{fortran-column-ruler-tab} is displayed. | |
3390 By changing these variables, you can change the column ruler display. | |
3391 | |
26106 | 3392 @kindex C-u C-c C-w @r{(Fortran mode)} |
25829 | 3393 @findex fortran-window-create |
26106 | 3394 For even more help, use @kbd{M-x fortran-window-create}), a |
25829 | 3395 command which splits the current window horizontally, making a window 72 |
3396 columns wide. By editing in this window you can immediately see when you | |
3397 make a line too wide to be correct Fortran. | |
3398 | |
26106 | 3399 @kindex C-c C-w @r{(Fortran mode)} |
3400 @findex fortran-window-create-momentarily | |
3401 Also, @kbd{C-c C-w} (@code{fortran-window-create-momentarily}) can be | |
3402 used temporarily to split the current window horizontally, making a | |
3403 window 72 columns wide to check column widths rather than to edit in | |
3404 this mode. The normal width is restored when you type a space. | |
3405 | |
25829 | 3406 @node Fortran Abbrev |
3407 @subsection Fortran Keyword Abbrevs | |
3408 | |
3409 Fortran mode provides many built-in abbrevs for common keywords and | |
3410 declarations. These are the same sort of abbrev that you can define | |
3411 yourself. To use them, you must turn on Abbrev mode. @xref{Abbrevs}. | |
3412 | |
3413 The built-in abbrevs are unusual in one way: they all start with a | |
3414 semicolon. You cannot normally use semicolon in an abbrev, but Fortran | |
3415 mode makes this possible by changing the syntax of semicolon to ``word | |
3416 constituent.'' | |
3417 | |
3418 For example, one built-in Fortran abbrev is @samp{;c} for | |
3419 @samp{continue}. If you insert @samp{;c} and then insert a punctuation | |
3420 character such as a space or a newline, the @samp{;c} expands automatically | |
3421 to @samp{continue}, provided Abbrev mode is enabled.@refill | |
3422 | |
3423 Type @samp{;?} or @samp{;C-h} to display a list of all the built-in | |
3424 Fortran abbrevs and what they stand for. | |
3425 | |
3426 @node Fortran Misc | |
3427 @subsection Other Fortran Mode Commands | |
3428 | |
27221
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3429 The command @kbd{fortran-strip-sqeuence-nos} can be used to remove text |
4a723a7bc25a
Mention outline-minor-mode, check-parens,
Dave Love <fx@gnu.org>
parents:
26462
diff
changeset
|
3430 past Fortran column 72, which is typically old `sequence numbers'. |
25829 | 3431 |
3432 @node Asm Mode | |
3433 @section Asm Mode | |
3434 | |
3435 @cindex Asm mode | |
26106 | 3436 @cindex Assembler mode |
25829 | 3437 Asm mode is a major mode for editing files of assembler code. It |
3438 defines these commands: | |
3439 | |
3440 @table @kbd | |
3441 @item @key{TAB} | |
3442 @code{tab-to-tab-stop}. | |
3443 @item C-j | |
3444 Insert a newline and then indent using @code{tab-to-tab-stop}. | |
3445 @item : | |
3446 Insert a colon and then remove the indentation from before the label | |
3447 preceding colon. Then do @code{tab-to-tab-stop}. | |
3448 @item ; | |
3449 Insert or align a comment. | |
3450 @end table | |
3451 | |
3452 The variable @code{asm-comment-char} specifies which character | |
3453 starts comments in assembler syntax. |