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