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