Fix bug #6671 with recentering and other scrolling problems.
[bpt/emacs.git] / doc / emacs / programs.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 1999-2011
3 @c Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Programs, Building, Text, Top
6 @chapter Editing Programs
7 @cindex Lisp editing
8 @cindex C editing
9 @cindex program editing
10
11 Emacs provides many features to facilitate editing programs. Some
12 of these features can
13
14 @itemize @bullet
15 @item
16 Find or move over top-level definitions (@pxref{Defuns}).
17 @item
18 Apply the usual indentation conventions of the language
19 (@pxref{Program Indent}).
20 @item
21 Balance parentheses (@pxref{Parentheses}).
22 @item
23 Insert, kill or align comments (@pxref{Comments}).
24 @item
25 Highlight program syntax (@pxref{Font Lock}).
26 @end itemize
27
28 This chapter describes these features and many more.
29
30 @menu
31 * Program Modes:: Major modes for editing programs.
32 * Defuns:: Commands to operate on major top-level parts
33 of a program.
34 * Program Indent:: Adjusting indentation to show the nesting.
35 * Parentheses:: Commands that operate on parentheses.
36 * Comments:: Inserting, killing, and aligning comments.
37 * Documentation:: Getting documentation of functions you plan to call.
38 * Hideshow:: Displaying blocks selectively.
39 * Symbol Completion:: Completion on symbol names of your program or language.
40 * Glasses:: Making identifiersLikeThis more readable.
41 * Semantic:: Suite of editing tools based on source code parsing.
42 * Misc for Programs:: Other Emacs features useful for editing programs.
43 * C Modes:: Special commands of C, C++, Objective-C,
44 Java, and Pike modes.
45 * Asm Mode:: Asm mode and its special features.
46 @ifnottex
47 * Fortran:: Fortran mode and its special features.
48 @end ifnottex
49 @end menu
50
51 @node Program Modes
52 @section Major Modes for Programming Languages
53 @cindex modes for programming languages
54
55 Emacs has specialized major modes for various programming languages.
56 @xref{Major Modes}. A programming language major mode typically
57 specifies the syntax of expressions, the customary rules for
58 indentation, how to do syntax highlighting for the language, and how
59 to find the beginning or end of a function definition. It often
60 customizes or provides facilities for compiling and debugging programs
61 as well.
62
63 Ideally, Emacs should provide a major mode for each programming
64 language that you might want to edit; if it doesn't have a mode for
65 your favorite language, you can contribute one. But often the mode
66 for one language can serve for other syntactically similar languages.
67 The major mode for language @var{l} is called @code{@var{l}-mode},
68 and you can select it by typing @kbd{M-x @var{l}-mode @key{RET}}.
69 @xref{Choosing Modes}.
70
71 @cindex Perl mode
72 @cindex Icon mode
73 @cindex Makefile mode
74 @cindex Tcl mode
75 @cindex CPerl mode
76 @cindex DSSSL mode
77 @cindex Octave mode
78 @cindex Metafont mode
79 @cindex Modula2 mode
80 @cindex Prolog mode
81 @cindex Python mode
82 @cindex Ruby mode
83 @cindex Simula mode
84 @cindex VHDL mode
85 @cindex M4 mode
86 @cindex Shell-script mode
87 @cindex Delphi mode
88 @cindex PostScript mode
89 @cindex Conf mode
90 @cindex DNS mode
91 @cindex Javascript mode
92 The existing programming language major modes include Lisp, Scheme
93 (a variant of Lisp) and the Scheme-based DSSSL expression language,
94 Ada, ASM, AWK, C, C++, Delphi (Object Pascal), Fortran, Icon, IDL
95 (CORBA), IDLWAVE, Java, Javascript, Metafont (@TeX{}'s companion for
96 font creation), Modula2, Objective-C, Octave, Pascal, Perl, Pike,
97 PostScript, Prolog, Python, Ruby, Simula, Tcl, and VHDL. An
98 alternative mode for Perl is called CPerl mode. Modes are available
99 for the scripting languages of the common GNU and Unix shells, VMS
100 DCL, and MS-DOS/MS-Windows @samp{BAT} files. There are also major
101 modes for editing makefiles, DNS master files, and various sorts of
102 configuration files.
103
104 @kindex DEL @r{(programming modes)}
105 @findex c-electric-backspace
106 In most programming languages, indentation should vary from line to
107 line to illustrate the structure of the program. So the major modes
108 for programming languages arrange for @key{TAB} to update the
109 indentation of the current line (@pxref{Program Indent}). They also
110 rebind @key{DEL} to treat a tab as if it were the equivalent number of
111 spaces; this lets you delete one column of indentation without
112 worrying whether the whitespace consists of spaces or tabs. Use
113 @kbd{C-b C-d} to delete a tab character before point, in these modes.
114
115 Separate manuals are available for the modes for Ada (@pxref{Top, , Ada
116 Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL/Pike/AWK
117 (@pxref{Top, , CC Mode, ccmode, CC Mode}) and the IDLWAVE modes
118 (@pxref{Top, , IDLWAVE, idlwave, IDLWAVE User Manual}). For Fortran
119 mode, see
120 @iftex
121 @ref{Fortran,,, emacs-xtra, Specialized Emacs Features}.
122 @end iftex
123 @ifnottex
124 @ref{Fortran}.
125 @end ifnottex
126
127 @cindex mode hook
128 @vindex c-mode-hook
129 @vindex lisp-mode-hook
130 @vindex emacs-lisp-mode-hook
131 @vindex lisp-interaction-mode-hook
132 @vindex scheme-mode-hook
133 Turning on a major mode runs a normal hook called the @dfn{mode
134 hook}, which is the value of a Lisp variable. Each major mode has a
135 mode hook, and the hook's name is always made from the mode command's
136 name by adding @samp{-hook}. For example, turning on C mode runs the
137 hook @code{c-mode-hook}, while turning on Lisp mode runs the hook
138 @code{lisp-mode-hook}. The purpose of the mode hook is to give you a
139 place to set up customizations for that major mode. @xref{Hooks}.
140
141 @node Defuns
142 @section Top-Level Definitions, or Defuns
143
144 In Emacs, a major definition at the top level in the buffer, such as
145 a function, is called a @dfn{defun}. The name comes from Lisp, but in
146 Emacs we use it for all languages.
147
148 @menu
149 * Left Margin Paren:: An open-paren or similar opening delimiter
150 starts a defun if it is at the left margin.
151 * Moving by Defuns:: Commands to move over or mark a major definition.
152 * Imenu:: Making buffer indexes as menus.
153 * Which Function:: Which Function mode shows which function you are in.
154 @end menu
155
156 @node Left Margin Paren
157 @subsection Left Margin Convention
158
159 @cindex open-parenthesis in leftmost column
160 @cindex ( in leftmost column
161 Many programming-language modes assume by default that any opening
162 delimiter found at the left margin is the start of a top-level
163 definition, or defun. Therefore, @strong{don't put an opening
164 delimiter at the left margin unless it should have that significance}.
165 For instance, never put an open-parenthesis at the left margin in a
166 Lisp file unless it is the start of a top-level list.
167
168 The convention speeds up many Emacs operations, which would
169 otherwise have to scan back to the beginning of the buffer to analyze
170 the syntax of the code.
171
172 If you don't follow this convention, not only will you have trouble
173 when you explicitly use the commands for motion by defuns; other
174 features that use them will also give you trouble. This includes the
175 indentation commands (@pxref{Program Indent}) and Font Lock mode
176 (@pxref{Font Lock}).
177
178 The most likely problem case is when you want an opening delimiter
179 at the start of a line inside a string. To avoid trouble, put an
180 escape character (@samp{\}, in C and Emacs Lisp, @samp{/} in some
181 other Lisp dialects) before the opening delimiter. This will not
182 affect the contents of the string, but will prevent that opening
183 delimiter from starting a defun. Here's an example:
184
185 @example
186 (insert "Foo:
187 \(bar)
188 ")
189 @end example
190
191 To help you catch violations of this convention, Font Lock mode
192 highlights confusing opening delimiters (those that ought to be
193 quoted) in bold red.
194
195 If you need to override this convention, you can do so by setting
196 this user option:
197
198 @defvar open-paren-in-column-0-is-defun-start
199 If this user option is set to @code{t} (the default), opening
200 parentheses or braces at column zero always start defuns. When it's
201 @code{nil}, defuns are found by searching for parens or braces at the
202 outermost level.
203 @end defvar
204
205 Usually, you should leave this option at its default value of
206 @code{t}. If your buffer contains parentheses or braces in column
207 zero which don't start defuns, and it is somehow impractical to remove
208 these parentheses or braces, it might be helpful to set the option to
209 @code{nil}. Be aware that this might make scrolling and display in
210 large buffers quite sluggish. Furthermore, the parentheses and braces
211 must be correctly matched throughout the buffer for it to work
212 properly.
213
214 @node Moving by Defuns
215 @subsection Moving by Defuns
216 @cindex defuns
217
218 These commands move point or set up the region based on top-level
219 major definitions, also called @dfn{defuns}.
220
221 @table @kbd
222 @item C-M-a
223 Move to beginning of current or preceding defun
224 (@code{beginning-of-defun}).
225 @item C-M-e
226 Move to end of current or following defun (@code{end-of-defun}).
227 @item C-M-h
228 Put region around whole current or following defun (@code{mark-defun}).
229 @end table
230
231 @cindex move to beginning or end of function
232 @cindex function, move to beginning or end
233 @kindex C-M-a
234 @kindex C-M-e
235 @kindex C-M-h
236 @findex beginning-of-defun
237 @findex end-of-defun
238 @findex mark-defun
239 The commands to move to the beginning and end of the current defun
240 are @kbd{C-M-a} (@code{beginning-of-defun}) and @kbd{C-M-e}
241 (@code{end-of-defun}). If you repeat one of these commands, or use a
242 positive numeric argument, each repetition moves to the next defun in
243 the direction of motion.
244
245 @kbd{C-M-a} with a negative argument @minus{}@var{n} moves forward
246 @var{n} times to the next beginning of a defun. This is not exactly
247 the same place that @kbd{C-M-e} with argument @var{n} would move to;
248 the end of this defun is not usually exactly the same place as the
249 beginning of the following defun. (Whitespace, comments, and perhaps
250 declarations can separate them.) Likewise, @kbd{C-M-e} with a
251 negative argument moves back to an end of a defun, which is not quite
252 the same as @kbd{C-M-a} with a positive argument.
253
254 @kindex C-M-h @r{(C mode)}
255 @findex c-mark-function
256 To operate on the current defun, use @kbd{C-M-h}
257 (@code{mark-defun}), which sets the mark at the end of the current
258 defun and puts point at its beginning. @xref{Marking Objects}. This
259 is the easiest way to get ready to kill the defun in order to move it
260 to a different place in the file. If you use the command while point
261 is between defuns, it uses the following defun. If you use the
262 command while the mark is already active, it sets the mark but does
263 not move point; furthermore, each successive use of @kbd{C-M-h}
264 extends the end of the region to include one more defun.
265
266 In C mode, @kbd{C-M-h} runs the function @code{c-mark-function},
267 which is almost the same as @code{mark-defun}; the difference is that
268 it backs up over the argument declarations, function name and returned
269 data type so that the entire C function is inside the region. This is
270 an example of how major modes adjust the standard key bindings so that
271 they do their standard jobs in a way better fitting a particular
272 language. Other major modes may replace any or all of these key
273 bindings for that purpose.
274
275 @node Imenu
276 @subsection Imenu
277 @cindex index of buffer definitions
278 @cindex buffer definitions index
279
280 The Imenu facility offers a way to find the major definitions in
281 a file by name. It is also useful in text formatter major modes,
282 where it treats each chapter, section, etc., as a definition.
283 (@xref{Tags}, for a more powerful feature that handles multiple files
284 together.)
285
286 @findex imenu
287 If you type @kbd{M-x imenu}, it reads the name of a definition using
288 the minibuffer, then moves point to that definition. You can use
289 completion to specify the name; the command always displays the whole
290 list of valid names.
291
292 @findex imenu-add-menubar-index
293 Alternatively, you can bind the command @code{imenu} to a mouse
294 click. Then it displays mouse menus for you to select a definition
295 name. You can also add the buffer's index to the menu bar by calling
296 @code{imenu-add-menubar-index}. If you want to have this menu bar
297 item available for all buffers in a certain major mode, you can do
298 this by adding @code{imenu-add-menubar-index} to its mode hook. But
299 if you have done that, you will have to wait a little while each time
300 you visit a file in that mode, while Emacs finds all the definitions
301 in that buffer.
302
303 @vindex imenu-auto-rescan
304 When you change the contents of a buffer, if you add or delete
305 definitions, you can update the buffer's index based on the
306 new contents by invoking the @samp{*Rescan*} item in the menu.
307 Rescanning happens automatically if you set @code{imenu-auto-rescan} to
308 a non-@code{nil} value. There is no need to rescan because of small
309 changes in the text.
310
311 @vindex imenu-sort-function
312 You can customize the way the menus are sorted by setting the
313 variable @code{imenu-sort-function}. By default, names are ordered as
314 they occur in the buffer; if you want alphabetic sorting, use the
315 symbol @code{imenu--sort-by-name} as the value. You can also
316 define your own comparison function by writing Lisp code.
317
318 Imenu provides the information to guide Which Function mode
319 @ifnottex
320 (@pxref{Which Function}).
321 @end ifnottex
322 @iftex
323 (see below).
324 @end iftex
325 The Speedbar can also use it (@pxref{Speedbar}).
326
327 @node Which Function
328 @subsection Which Function Mode
329 @cindex current function name in mode line
330
331 Which Function mode is a minor mode that displays the current
332 function name in the mode line, updating it as you move around in a
333 buffer.
334
335 @findex which-function-mode
336 @vindex which-func-modes
337 To either enable or disable Which Function mode, use the command
338 @kbd{M-x which-function-mode}. This command applies to all buffers,
339 both existing ones and those yet to be created. However, it takes
340 effect only in certain major modes, those listed in the value of
341 @code{which-func-modes}. If the value of @code{which-func-modes} is
342 @code{t} rather than a list of modes, then Which Function mode applies
343 to all major modes that know how to support it---in other words, all
344 the major modes that support Imenu.
345
346 @node Program Indent
347 @section Indentation for Programs
348 @cindex indentation for programs
349
350 The best way to keep a program properly indented is to use Emacs to
351 reindent it as you change it. Emacs has commands to indent either a
352 single line, a specified number of lines, or all of the lines inside a
353 single parenthetical grouping.
354
355 @menu
356 * Basic Indent:: Indenting a single line.
357 * Multi-line Indent:: Commands to reindent many lines at once.
358 * Lisp Indent:: Specifying how each Lisp function should be indented.
359 * C Indent:: Extra features for indenting C and related modes.
360 * Custom C Indent:: Controlling indentation style for C and related modes.
361 @end menu
362
363 @cindex pretty-printer
364 Emacs also provides a Lisp pretty-printer in the library @code{pp}.
365 This program reformats a Lisp object with indentation chosen to look nice.
366
367 @node Basic Indent
368 @subsection Basic Program Indentation Commands
369
370 The basic indentation commands indent a single line according to the
371 usual conventions of the language you are editing.
372
373 @table @kbd
374 @item @key{TAB}
375 Adjust indentation of current line.
376 @item C-j
377 Insert a newline, then adjust indentation of following line
378 (@code{newline-and-indent}).
379 @end table
380
381 @kindex TAB @r{(programming modes)}
382 @findex c-indent-command
383 @findex indent-line-function
384 @findex indent-for-tab-command
385 The basic indentation command is @key{TAB}. In any
386 programming-language major mode, @key{TAB} gives the current line the
387 correct indentation as determined from the previous lines. It does
388 this by inserting or deleting whitespace at the beginning of the
389 current line. If point was inside the whitespace at the beginning of
390 the line, @key{TAB} puts it at the end of that whitespace; otherwise,
391 @key{TAB} keeps point fixed with respect to the characters around it.
392 If the region is active (@pxref{Mark}), @key{TAB} indents every line
393 within the region instead of just the current line. The function that
394 @key{TAB} runs depends on the major mode; for instance, it is
395 @code{c-indent-line-or-region} in C mode. Each function is aware of
396 the syntax and conventions for its particular language.
397
398 Use @kbd{C-q @key{TAB}} to insert a tab character at point.
399
400 @kindex C-j
401 @findex newline-and-indent
402 When entering lines of new code, use @kbd{C-j}
403 (@code{newline-and-indent}), which inserts a newline and then adjusts
404 indentation after it. (It also deletes any trailing whitespace which
405 remains before the new newline.) For instance, @kbd{C-j} at the end
406 of a line creates a blank line with appropriate indentation. In
407 programming language modes, it is equivalent to @key{RET} @key{TAB}.
408
409 When Emacs indents a line that starts within a parenthetical
410 grouping, it usually places the start of the line under the preceding
411 line within the group, or under the text after the parenthesis. If
412 you manually give one of these lines a nonstandard indentation, the
413 lines below will tend to follow it. This behavior is convenient in
414 cases where you have overridden the standard result of @key{TAB}
415 indentation (e.g., for aesthetic purposes).
416
417 Many programming-language modes assume that an open-parenthesis,
418 open-brace or other opening delimiter at the left margin is the start
419 of a function. This assumption speeds up indentation commands. If
420 the text you are editing contains opening delimiters in column zero
421 that aren't the beginning of a functions---even if these delimiters
422 occur inside strings or comments---then you must set
423 @code{open-paren-in-column-0-is-defun-start}. @xref{Left Margin
424 Paren}.
425
426 Normally, Emacs indents lines using an ``optimal'' mix of tab and
427 space characters. If you want Emacs to use spaces only, set
428 @code{indent-tabs-mode} (@pxref{Just Spaces}).
429
430 @node Multi-line Indent
431 @subsection Indenting Several Lines
432
433 Sometimes, you may want to reindent several lines of code at a time.
434 One way to do this is to use the mark; when the mark is active and the
435 region is non-empty, @key{TAB} indents every line within the region.
436 In addition, Emacs provides several other commands for indenting large
437 chunks of code:
438
439 @table @kbd
440 @item C-M-q
441 Reindent all the lines within one parenthetical grouping.
442 @item C-M-\
443 Reindent all lines in the region (@code{indent-region}).
444 @item C-u @key{TAB}
445 Shift an entire parenthetical grouping rigidly sideways so that its
446 first line is properly indented.
447 @item M-x indent-code-rigidly
448 Shift all the lines in the region rigidly sideways, but do not alter
449 lines that start inside comments and strings.
450 @end table
451
452 @kindex C-M-q
453 @findex indent-pp-sexp
454 To reindent the contents of a single parenthetical grouping,
455 position point before the beginning of the grouping and type
456 @kbd{C-M-q}. This changes the relative indentation within the
457 grouping, without affecting its overall indentation (i.e., the
458 indentation of the line where the grouping starts). The function that
459 @kbd{C-M-q} runs depends on the major mode; it is
460 @code{indent-pp-sexp} in Lisp mode, @code{c-indent-exp} in C mode,
461 etc. To correct the overall indentation as well, type @key{TAB}
462 first.
463
464 @kbd{C-M-\} (@code{indent-region}) applies @key{TAB} to the region.
465 This is useful when Transient Mark mode is disabled (@pxref{Persistent
466 Mark}), because in that case @key{TAB} does not act on the region.
467
468 @kindex C-u TAB
469 If you like the relative indentation within a grouping but not the
470 indentation of its first line, move point to that first line and type
471 @kbd{C-u @key{TAB}}. In Lisp, C, and some other major modes,
472 @key{TAB} with a numeric argument reindents the current line as usual,
473 then reindents by the same amount all the lines in the parenthetical
474 grouping starting on the current line. It is clever, though, and does
475 not alter lines that start inside strings. Neither does it alter C
476 preprocessor lines when in C mode, but it does reindent any
477 continuation lines that may be attached to them.
478
479 @findex indent-code-rigidly
480 The command @kbd{M-x indent-code-rigidly} rigidly shifts all the
481 lines in the region sideways, like @code{indent-rigidly} does
482 (@pxref{Indentation Commands}). It doesn't alter the indentation of
483 lines that start inside a string, unless the region also starts inside
484 that string. The prefix arg specifies the number of columns to
485 indent.
486
487 @node Lisp Indent
488 @subsection Customizing Lisp Indentation
489 @cindex customizing Lisp indentation
490
491 The indentation pattern for a Lisp expression can depend on the function
492 called by the expression. For each Lisp function, you can choose among
493 several predefined patterns of indentation, or define an arbitrary one with
494 a Lisp program.
495
496 The standard pattern of indentation is as follows: the second line of the
497 expression is indented under the first argument, if that is on the same
498 line as the beginning of the expression; otherwise, the second line is
499 indented underneath the function name. Each following line is indented
500 under the previous line whose nesting depth is the same.
501
502 @vindex lisp-indent-offset
503 If the variable @code{lisp-indent-offset} is non-@code{nil}, it overrides
504 the usual indentation pattern for the second line of an expression, so that
505 such lines are always indented @code{lisp-indent-offset} more columns than
506 the containing list.
507
508 @vindex lisp-body-indent
509 Certain functions override the standard pattern. Functions whose
510 names start with @code{def} treat the second lines as the start of
511 a @dfn{body}, by indenting the second line @code{lisp-body-indent}
512 additional columns beyond the open-parenthesis that starts the
513 expression.
514
515 @cindex @code{lisp-indent-function} property
516 You can override the standard pattern in various ways for individual
517 functions, according to the @code{lisp-indent-function} property of
518 the function name. Normally you would use this for macro definitions
519 and specify it using the @code{declare} construct (@pxref{Defining
520 Macros,,, elisp, the Emacs Lisp Reference Manual}).
521
522 @node C Indent
523 @subsection Commands for C Indentation
524
525 Here are special features for indentation in C mode and related modes:
526
527 @table @code
528 @item C-c C-q
529 @kindex C-c C-q @r{(C mode)}
530 @findex c-indent-defun
531 Reindent the current top-level function definition or aggregate type
532 declaration (@code{c-indent-defun}).
533
534 @item C-M-q
535 @kindex C-M-q @r{(C mode)}
536 @findex c-indent-exp
537 Reindent each line in the balanced expression that follows point
538 (@code{c-indent-exp}). A prefix argument inhibits warning messages
539 about invalid syntax.
540
541 @item @key{TAB}
542 @findex c-indent-command
543 Reindent the current line, and/or in some cases insert a tab character
544 (@code{c-indent-command}).
545
546 @vindex c-tab-always-indent
547 If @code{c-tab-always-indent} is @code{t}, this command always reindents
548 the current line and does nothing else. This is the default.
549
550 If that variable is @code{nil}, this command reindents the current line
551 only if point is at the left margin or in the line's indentation;
552 otherwise, it inserts a tab (or the equivalent number of spaces,
553 if @code{indent-tabs-mode} is @code{nil}).
554
555 Any other value (not @code{nil} or @code{t}) means always reindent the
556 line, and also insert a tab if within a comment or a string.
557 @end table
558
559 To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This
560 first selects the whole buffer as the region, then reindents that
561 region.
562
563 To reindent the current block, use @kbd{C-M-u C-M-q}. This moves
564 to the front of the block and then reindents it all.
565
566 @node Custom C Indent
567 @subsection Customizing C Indentation
568 @cindex style (for indentation)
569
570 C mode and related modes use a flexible mechanism for customizing
571 indentation. C mode indents a source line in two steps: first it
572 classifies the line syntactically according to its contents and
573 context; second, it determines the indentation offset associated by
574 your selected @dfn{style} with the syntactic construct and adds this
575 onto the indentation of the @dfn{anchor statement}.
576
577 @table @kbd
578 @item C-c . @key{RET} @var{style} @key{RET}
579 Select a predefined style @var{style} (@code{c-set-style}).
580 @end table
581
582 A @dfn{style} is a named collection of customizations that can be
583 used in C mode and the related modes. @ref{Styles,,, ccmode, The CC
584 Mode Manual}, for a complete description. Emacs comes with several
585 predefined styles, including @code{gnu}, @code{k&r}, @code{bsd},
586 @code{stroustrup}, @code{linux}, @code{python}, @code{java},
587 @code{whitesmith}, @code{ellemtel}, and @code{awk}. Some of these
588 styles are primarily intended for one language, but any of them can be
589 used with any of the languages supported by these modes. To find out
590 what a style looks like, select it and reindent some code, e.g., by
591 typing @key{C-M-q} at the start of a function definition.
592
593 @kindex C-c . @r{(C mode)}
594 @findex c-set-style
595 To choose a style for the current buffer, use the command @w{@kbd{C-c
596 .}}. Specify a style name as an argument (case is not significant).
597 This command affects the current buffer only, and it affects only
598 future invocations of the indentation commands; it does not reindent
599 the code already in the buffer. To reindent the whole buffer in the
600 new style, you can type @kbd{C-x h C-M-\}.
601
602 @vindex c-default-style
603 You can also set the variable @code{c-default-style} to specify the
604 default style for various major modes. Its value should be either the
605 style's name (a string) or an alist, in which each element specifies
606 one major mode and which indentation style to use for it. For
607 example,
608
609 @example
610 (setq c-default-style
611 '((java-mode . "java") (awk-mode . "awk") (other . "gnu")))
612 @end example
613
614 @noindent
615 specifies explicit choices for Java and AWK modes, and the default
616 @samp{gnu} style for the other C-like modes. (These settings are
617 actually the defaults.) This variable takes effect when you select
618 one of the C-like major modes; thus, if you specify a new default
619 style for Java mode, you can make it take effect in an existing Java
620 mode buffer by typing @kbd{M-x java-mode} there.
621
622 The @code{gnu} style specifies the formatting recommended by the GNU
623 Project for C; it is the default, so as to encourage use of our
624 recommended style.
625
626 @xref{Indentation Engine Basics,,, ccmode, the CC Mode Manual}, and
627 @ref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for more
628 information on customizing indentation for C and related modes,
629 including how to override parts of an existing style and how to define
630 your own styles.
631
632 @node Parentheses
633 @section Commands for Editing with Parentheses
634
635 @findex check-parens
636 @cindex unbalanced parentheses and quotes
637 This section describes the commands and features that take advantage
638 of the parenthesis structure in a program, or help you keep it
639 balanced.
640
641 When talking about these facilities, the term ``parenthesis'' also
642 includes braces, brackets, or whatever delimiters are defined to match
643 in pairs. The major mode controls which delimiters are significant,
644 through the syntax table (@pxref{Syntax}). In Lisp, only parentheses
645 count; in C, these commands apply to braces and brackets too.
646
647 You can use @kbd{M-x check-parens} to find any unbalanced
648 parentheses and unbalanced string quotes in the buffer.
649
650 @menu
651 * Expressions:: Expressions with balanced parentheses.
652 * Moving by Parens:: Commands for moving up, down and across
653 in the structure of parentheses.
654 * Matching:: Insertion of a close-delimiter flashes matching open.
655 @end menu
656
657 @node Expressions
658 @subsection Expressions with Balanced Parentheses
659
660 @cindex sexp
661 @cindex expression
662 @cindex balanced expression
663 These commands deal with balanced expressions, also called
664 @dfn{sexps}@footnote{The word ``sexp'' is used to refer to an
665 expression in Lisp.}.
666
667 @table @kbd
668 @item C-M-f
669 Move forward over a balanced expression (@code{forward-sexp}).
670 @item C-M-b
671 Move backward over a balanced expression (@code{backward-sexp}).
672 @item C-M-k
673 Kill balanced expression forward (@code{kill-sexp}).
674 @item C-M-t
675 Transpose expressions (@code{transpose-sexps}).
676 @item C-M-@@
677 @itemx C-M-@key{SPC}
678 Put mark after following expression (@code{mark-sexp}).
679 @end table
680
681 Each programming language major mode customizes the definition of
682 balanced expressions to suit that language. Balanced expressions
683 typically include symbols, numbers, and string constants, as well as
684 any pair of matching delimiters and their contents. Some languages
685 have obscure forms of expression syntax that nobody has bothered to
686 implement in Emacs.
687
688 @cindex Control-Meta
689 By convention, the keys for these commands are all Control-Meta
690 characters. They usually act on expressions just as the corresponding
691 Meta characters act on words. For instance, the command @kbd{C-M-b}
692 moves backward over a balanced expression, just as @kbd{M-b} moves
693 back over a word.
694
695 @kindex C-M-f
696 @kindex C-M-b
697 @findex forward-sexp
698 @findex backward-sexp
699 To move forward over a balanced expression, use @kbd{C-M-f}
700 (@code{forward-sexp}). If the first significant character after point
701 is an opening delimiter (@samp{(} in Lisp; @samp{(}, @samp{[} or
702 @samp{@{} in C), @kbd{C-M-f} moves past the matching closing
703 delimiter. If the character begins a symbol, string, or number,
704 @kbd{C-M-f} moves over that.
705
706 The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
707 balanced expression. The detailed rules are like those above for
708 @kbd{C-M-f}, but with directions reversed. If there are prefix
709 characters (single-quote, backquote and comma, in Lisp) preceding the
710 expression, @kbd{C-M-b} moves back over them as well. The balanced
711 expression commands move across comments as if they were whitespace,
712 in most modes.
713
714 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the
715 specified number of times; with a negative argument, it moves in the
716 opposite direction.
717
718 @cindex killing expressions
719 @kindex C-M-k
720 @findex kill-sexp
721 Killing a whole balanced expression can be done with @kbd{C-M-k}
722 (@code{kill-sexp}). @kbd{C-M-k} kills the characters that @kbd{C-M-f}
723 would move over.
724
725 @cindex transposition of expressions
726 @kindex C-M-t
727 @findex transpose-sexps
728 A somewhat random-sounding command which is nevertheless handy is
729 @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous
730 balanced expression across the next one. An argument serves as a
731 repeat count, moving the previous expression over that many following
732 ones. A negative argument drags the previous balanced expression
733 backwards across those before it (thus canceling out the effect of
734 @kbd{C-M-t} with a positive argument). An argument of zero, rather
735 than doing nothing, transposes the balanced expressions ending at or
736 after point and the mark.
737
738 @kindex C-M-@@
739 @kindex C-M-@key{SPC}
740 @findex mark-sexp
741 To set the region around the next balanced expression in the buffer,
742 use @kbd{C-M-@key{SPC}} (@code{mark-sexp}), which sets mark at the
743 same place that @kbd{C-M-f} would move to. @kbd{C-M-@key{SPC}} treats
744 numeric arguments in the same way as @kbd{C-M-f}; in particular, a
745 negative argument puts the mark at the beginning of the previous
746 balanced expression. The alias @kbd{C-M-@@} is equivalent to
747 @kbd{C-M-@key{SPC}}. While the mark is active, each successive use of
748 @kbd{C-M-@key{SPC}} extends the region by shifting the mark by one
749 sexp.
750
751 In languages that use infix operators, such as C, it is not possible
752 to recognize all balanced expressions as such because there can be
753 multiple possibilities at a given position. For example, C mode does
754 not treat @samp{foo + bar} as a single expression, even though it
755 @emph{is} one C expression; instead, it recognizes @samp{foo} as one
756 expression and @samp{bar} as another, with the @samp{+} as punctuation
757 between them. Both @samp{foo + bar} and @samp{foo} are legitimate
758 choices for ``the expression following point'' when point is at the
759 @samp{f}, so the expression commands must perforce choose one or the
760 other to operate on. Note that @samp{(foo + bar)} is recognized as a
761 single expression in C mode, because of the parentheses.
762
763 @node Moving by Parens
764 @subsection Moving in the Parenthesis Structure
765
766 @cindex parenthetical groupings
767 @cindex parentheses, moving across
768 @cindex matching parenthesis and braces, moving to
769 @cindex braces, moving across
770 @cindex list commands
771
772 The Emacs commands for handling parenthetical groupings see nothing
773 except parentheses (or whatever characters must balance in the
774 language you are working with). They ignore strings and comments
775 (including any parentheses within them) and ignore parentheses quoted
776 by an escape character. They are mainly intended for editing
777 programs, but can be useful for editing any text that has parentheses.
778 They are sometimes called ``list'' commands because in Lisp these
779 groupings are lists.
780
781 These commands assume that the starting point is not inside a string
782 or a comment. Sometimes you can invoke them usefully from one of
783 these places (for example, when you have a parenthesised clause in a
784 comment) but this is unreliable.
785
786 @table @kbd
787 @item C-M-n
788 Move forward over a parenthetical group (@code{forward-list}).
789 @item C-M-p
790 Move backward over a parenthetical group (@code{backward-list}).
791 @item C-M-u
792 Move up in parenthesis structure (@code{backward-up-list}).
793 @item C-M-d
794 Move down in parenthesis structure (@code{down-list}).
795 @end table
796
797 @kindex C-M-n
798 @kindex C-M-p
799 @findex forward-list
800 @findex backward-list
801 The ``list'' commands @kbd{C-M-n} (@code{forward-list}) and
802 @kbd{C-M-p} (@code{backward-list}) move forward or backward over one
803 (or @var{n}) parenthetical groupings.
804
805 @kindex C-M-u
806 @findex backward-up-list
807 @kbd{C-M-n} and @kbd{C-M-p} try to stay at the same level in the
808 parenthesis structure. To move @emph{up} one (or @var{n}) levels, use
809 @kbd{C-M-u} (@code{backward-up-list}). @kbd{C-M-u} moves backward up
810 past one unmatched opening delimiter. A positive argument serves as a
811 repeat count; a negative argument reverses the direction of motion, so
812 that the command moves forward and up one or more levels.
813
814 @kindex C-M-d
815 @findex down-list
816 To move @emph{down} in the parenthesis structure, use @kbd{C-M-d}
817 (@code{down-list}). In Lisp mode, where @samp{(} is the only opening
818 delimiter, this is nearly the same as searching for a @samp{(}. An
819 argument specifies the number of levels to go down.
820
821 @node Matching
822 @subsection Automatic Display Of Matching Parentheses
823 @cindex matching parentheses
824 @cindex parentheses, displaying matches
825
826 The Emacs parenthesis-matching feature is designed to show
827 automatically how parentheses (and other matching delimiters) match in
828 the text. Whenever you type a self-inserting character that is a
829 closing delimiter, the cursor moves momentarily to the location of the
830 matching opening delimiter, provided that is on the screen. If it is
831 not on the screen, Emacs displays some of the text near it in the echo
832 area. Either way, you can tell which grouping you are closing off.
833
834 If the opening delimiter and closing delimiter are mismatched---such
835 as in @samp{[x)}---a warning message is displayed in the echo area.
836
837 @vindex blink-matching-paren
838 @vindex blink-matching-paren-distance
839 @vindex blink-matching-delay
840 Three variables control parenthesis match display:
841
842 @code{blink-matching-paren} turns the feature on or off: @code{nil}
843 disables it, but the default is @code{t} to enable match display.
844
845 @code{blink-matching-delay} says how many seconds to leave the
846 cursor on the matching opening delimiter, before bringing it back to
847 the real location of point; the default is 1, but on some systems it
848 is useful to specify a fraction of a second.
849
850 @code{blink-matching-paren-distance} specifies how many characters
851 back to search to find the matching opening delimiter. If the match
852 is not found in that distance, scanning stops, and nothing is displayed.
853 This is to prevent the scan for the matching delimiter from wasting
854 lots of time when there is no match. The default is 102400.
855
856 @cindex Show Paren mode
857 @cindex highlighting matching parentheses
858 @findex show-paren-mode
859 Show Paren mode provides a more powerful kind of automatic matching.
860 Whenever point is before an opening delimiter or after a closing
861 delimiter, both that delimiter and its opposite delimiter are
862 highlighted. Use the command @kbd{M-x show-paren-mode} to enable or
863 disable this mode.
864
865 Show Paren mode uses the faces @code{show-paren-match} and
866 @code{show-paren-mismatch} to highlight parentheses; you can customize
867 them to control how highlighting looks. @xref{Face Customization}.
868
869 @node Comments
870 @section Manipulating Comments
871 @cindex comments
872
873 Because comments are such an important part of programming, Emacs
874 provides special commands for editing and inserting comments. It can
875 also do spell checking on comments with Flyspell Prog mode
876 (@pxref{Spelling}).
877
878 @menu
879 * Comment Commands:: Inserting, killing, and aligning comments.
880 * Multi-Line Comments:: Commands for adding and editing multi-line comments.
881 * Options for Comments::Customizing the comment features.
882 @end menu
883
884 @node Comment Commands
885 @subsection Comment Commands
886 @cindex indentation for comments
887 @cindex alignment for comments
888
889 The commands in this table insert, kill and align comments:
890
891 @table @asis
892 @item @kbd{M-;}
893 Insert or realign comment on current line; alternatively, comment or
894 uncomment the region (@code{comment-dwim}).
895 @item @kbd{C-u M-;}
896 Kill comment on current line (@code{comment-kill}).
897 @item @kbd{C-x ;}
898 Set comment column (@code{comment-set-column}).
899 @item @kbd{C-M-j}
900 @itemx @kbd{M-j}
901 Like @key{RET} followed by inserting and aligning a comment
902 (@code{comment-indent-new-line}). @xref{Multi-Line Comments}.
903 @item @kbd{M-x comment-region}
904 @itemx @kbd{C-c C-c} (in C-like modes)
905 Add or remove comment delimiters on all the lines in the region.
906 @end table
907
908 @kindex M-;
909 @findex comment-dwim
910 The command to create or align a comment is @kbd{M-;}
911 (@code{comment-dwim}). The word ``dwim'' is an acronym for ``Do What
912 I Mean''; it indicates that this command can be used for many
913 different jobs relating to comments, depending on the situation where
914 you use it.
915
916 When a region is active, @kbd{M-;} either adds or removes comment
917 delimiters on each line of the region. @xref{Mark}. If every line in
918 the region is a comment, it removes comment delimiters from each;
919 otherwise, it adds comment delimiters to each. You can also use the
920 commands @code{comment-region} and @code{uncomment-region} to
921 explicitly comment or uncomment the text in the region
922 (@pxref{Multi-Line Comments}). If you supply a prefix argument to
923 @kbd{M-;} when a region is active, that specifies how many comment
924 delimiters to add or how many to delete.
925
926 If the region is not active, @kbd{M-;} inserts a new comment if
927 there is no comment already on the line. The new comment is normally
928 aligned at a specific column called the @dfn{comment column}; if the
929 text of the line extends past the comment column, @kbd{M-;} aligns the
930 comment start string to a suitable boundary (usually, at least one
931 space is inserted). The comment begins with the string Emacs thinks
932 comments should start with (the value of @code{comment-start}; see
933 below). Emacs places point after that string, so you can insert the
934 text of the comment right away. If the major mode has specified a
935 string to terminate comments, @kbd{M-;} inserts that string after
936 point, to keep the syntax valid.
937
938 You can also use @kbd{M-;} to align an existing comment. If a line
939 already contains the comment-start string, @kbd{M-;} realigns it to
940 the conventional alignment and moves point after it. (Exception:
941 comments starting in column 0 are not moved.) Even when an existing
942 comment is properly aligned, @kbd{M-;} is still useful for moving
943 directly to the start of the text inside the comment.
944
945 @findex comment-kill
946 @kindex C-u M-;
947 @kbd{C-u M-;} kills any comment on the current line, along with the
948 whitespace before it. To reinsert the comment on another line, move
949 to the end of that line, do @kbd{C-y}, and then do @kbd{M-;} to
950 realign it.
951
952 Note that @kbd{C-u M-;} is not a distinct key; it is @kbd{M-;}
953 (@code{comment-dwim}) with a prefix argument. That command is
954 programmed so that when it receives a prefix argument it calls
955 @code{comment-kill}. However, @code{comment-kill} is a valid command
956 in its own right, and you can bind it directly to a key if you wish.
957
958 Some major modes have special rules for aligning certain kinds of
959 comments in certain contexts. For example, in Lisp code, comments which
960 start with two semicolons are indented as if they were lines of code,
961 instead of at the comment column. Comments which start with three
962 semicolons are supposed to start at the left margin and are often used
963 for sectioning purposes. Emacs understands
964 these conventions by indenting a double-semicolon comment using @key{TAB},
965 and by not changing the indentation of a triple-semicolon comment at all.
966
967 @example
968 ;; This function is just an example.
969 ;;; Here either two or three semicolons are appropriate.
970 (defun foo (x)
971 ;;; And now, the first part of the function:
972 ;; The following line adds one.
973 (1+ x)) ; This line adds one.
974 @end example
975
976 For C-like modes, you can configure the exact effect of @kbd{M-;} by
977 setting the variables @code{c-indent-comment-alist} and
978 @code{c-indent-comments-syntactically-p}. For example, on a line
979 ending in a closing brace, @kbd{M-;} puts the comment one space after
980 the brace rather than at @code{comment-column}. For full details see
981 @ref{Comment Commands,,, ccmode, The CC Mode Manual}.
982
983 @node Multi-Line Comments
984 @subsection Multiple Lines of Comments
985
986 @kindex C-M-j
987 @kindex M-j
988 @cindex blank lines in programs
989 @findex comment-indent-new-line
990
991 If you are typing a comment and wish to continue it on another line,
992 you can use the command @kbd{C-M-j} or @kbd{M-j}
993 (@code{comment-indent-new-line}). If @code{comment-multi-line}
994 (@pxref{Options for Comments}) is non-@code{nil}, it moves to a new
995 line within the comment. Otherwise it closes the comment and starts a
996 new comment on a new line. When Auto Fill mode is on, going past the
997 fill column while typing a comment causes the comment to be continued
998 in just this fashion.
999
1000 @kindex C-c C-c (C mode)
1001 @findex comment-region
1002 To turn existing lines into comment lines, use the @kbd{M-x
1003 comment-region} command (or type @kbd{C-c C-c} in C-like modes). It
1004 adds comment delimiters to the lines that start in the region, thus
1005 commenting them out. With a negative argument, it does the
1006 opposite---it deletes comment delimiters from the lines in the region.
1007
1008 With a positive argument, @code{comment-region} duplicates the last
1009 character of the comment start sequence it adds; the argument
1010 specifies how many copies of the character to insert. Thus, in Lisp
1011 mode, @kbd{C-u 2 M-x comment-region} adds @samp{;;} to each line.
1012 Duplicating the comment delimiter is a way of calling attention to the
1013 comment. It can also affect how the comment is aligned or indented.
1014 In Lisp, for proper indentation, you should use an argument of two or
1015 three, if between defuns; if within a defun, it must be three.
1016
1017 You can configure C Mode such that when you type a @samp{/} at the
1018 start of a line in a multi-line block comment, this closes the
1019 comment. Enable the @code{comment-close-slash} clean-up for this.
1020 @xref{Clean-ups,,, ccmode, The CC Mode Manual}.
1021
1022 @node Options for Comments
1023 @subsection Options Controlling Comments
1024
1025 @vindex comment-column
1026 @kindex C-x ;
1027 @findex comment-set-column
1028 The @dfn{comment column}, the column at which Emacs tries to place
1029 comments, is stored in the variable @code{comment-column}. You can
1030 set it to a number explicitly. Alternatively, the command @kbd{C-x ;}
1031 (@code{comment-set-column}) sets the comment column to the column
1032 point is at. @kbd{C-u C-x ;} sets the comment column to match the
1033 last comment before point in the buffer, and then does a @kbd{M-;} to
1034 align the current line's comment under the previous one.
1035
1036 The variable @code{comment-column} is per-buffer: setting the variable
1037 in the normal fashion affects only the current buffer, but there is a
1038 default value which you can change with @code{setq-default}.
1039 @xref{Locals}. Many major modes initialize this variable for the
1040 current buffer.
1041
1042 @vindex comment-start-skip
1043 The comment commands recognize comments based on the regular
1044 expression that is the value of the variable @code{comment-start-skip}.
1045 Make sure this regexp does not match the null string. It may match more
1046 than the comment starting delimiter in the strictest sense of the word;
1047 for example, in C mode the value of the variable is
1048 @c This stops M-q from breaking the line inside that @code.
1049 @code{@w{"/\\*+ *\\|//+ *"}}, which matches extra stars and spaces
1050 after the @samp{/*} itself, and accepts C++ style comments also.
1051 (Note that @samp{\\} is needed in Lisp syntax to include a @samp{\} in
1052 the string, which is needed to deny the first star its special meaning
1053 in regexp syntax. @xref{Regexp Backslash}.)
1054
1055 @vindex comment-start
1056 @vindex comment-end
1057 When a comment command makes a new comment, it inserts the value of
1058 @code{comment-start} to begin it. The value of @code{comment-end} is
1059 inserted after point, so that it will follow the text that you will
1060 insert into the comment. When @code{comment-end} is non-empty, it
1061 should start with a space. For example, in C mode,
1062 @code{comment-start} has the value @w{@code{"/* "}} and
1063 @code{comment-end} has the value @w{@code{" */"}}.
1064
1065 @vindex comment-padding
1066 The variable @code{comment-padding} specifies how many spaces
1067 @code{comment-region} should insert on each line between the comment
1068 delimiter and the line's original text. The default is 1, to insert
1069 one space. @code{nil} means 0. Alternatively, @code{comment-padding}
1070 can hold the actual string to insert.
1071
1072 @vindex comment-multi-line
1073 The variable @code{comment-multi-line} controls how @kbd{C-M-j}
1074 (@code{indent-new-comment-line}) behaves when used inside a comment.
1075 Specifically, when @code{comment-multi-line} is @code{nil}, the
1076 command inserts a comment terminator, begins a new line, and finally
1077 inserts a comment starter. Otherwise it does not insert the
1078 terminator and starter, so it effectively continues the current
1079 comment across multiple lines. In languages that allow multi-line
1080 comments, the choice of value for this variable is a matter of taste.
1081 The default for this variable depends on the major mode.
1082
1083 @vindex comment-indent-function
1084 The variable @code{comment-indent-function} should contain a function
1085 that will be called to compute the alignment for a newly inserted
1086 comment or for aligning an existing comment. It is set differently by
1087 various major modes. The function is called with no arguments, but with
1088 point at the beginning of the comment, or at the end of a line if a new
1089 comment is to be inserted. It should return the column in which the
1090 comment ought to start. For example, in Lisp mode, the indent hook
1091 function bases its decision on how many semicolons begin an existing
1092 comment, and on the code in the preceding lines.
1093
1094 @node Documentation
1095 @section Documentation Lookup
1096
1097 Emacs provides several features you can use to look up the
1098 documentation of functions, variables and commands that you plan to
1099 use in your program.
1100
1101 @menu
1102 * Info Lookup:: Looking up library functions and commands
1103 in Info files.
1104 * Man Page:: Looking up man pages of library functions and commands.
1105 * Lisp Doc:: Looking up Emacs Lisp functions, etc.
1106 @end menu
1107
1108 @node Info Lookup
1109 @subsection Info Documentation Lookup
1110
1111 @findex info-lookup-symbol
1112 @findex info-lookup-file
1113 @kindex C-h S
1114 For major modes that apply to languages which have documentation in
1115 Info, you can use @kbd{C-h S} (@code{info-lookup-symbol}) to view the
1116 Info documentation for a symbol used in the program. You specify the
1117 symbol with the minibuffer; the default is the symbol appearing in the
1118 buffer at point. For example, in C mode this looks for the symbol in
1119 the C Library Manual. The command only works if the appropriate
1120 manual's Info files are installed.
1121
1122 The major mode determines where to look for documentation for the
1123 symbol---which Info files to look in, and which indices to search.
1124 You can also use @kbd{M-x info-lookup-file} to look for documentation
1125 for a file name.
1126
1127 If you use @kbd{C-h S} in a major mode that does not support it,
1128 it asks you to specify the ``symbol help mode.'' You should enter
1129 a command such as @code{c-mode} that would select a major
1130 mode which @kbd{C-h S} does support.
1131
1132 @node Man Page
1133 @subsection Man Page Lookup
1134
1135 @cindex manual page
1136 On Unix, the main form of on-line documentation was the @dfn{manual
1137 page} or @dfn{man page}. In the GNU operating system, we aim to
1138 replace man pages with better-organized manuals that you can browse
1139 with Info (@pxref{Misc Help}). This process is not finished, so it is
1140 still useful to read manual pages.
1141
1142 @findex manual-entry
1143 You can read the man page for an operating system command, library
1144 function, or system call, with the @kbd{M-x man} command. It
1145 runs the @code{man} program to format the man page; if the system
1146 permits, it runs @code{man} asynchronously, so that you can keep on
1147 editing while the page is being formatted. (On MS-DOS and MS-Windows
1148 3, you cannot edit while Emacs waits for @code{man} to finish.) The
1149 result goes in a buffer named @samp{*Man @var{topic}*}. These buffers
1150 use a special major mode, Man mode, that facilitates scrolling and
1151 jumping to other manual pages. For details, type @kbd{C-h m} while in
1152 a man page buffer.
1153
1154 @cindex sections of manual pages
1155 Each man page belongs to one of ten or more @dfn{sections}, each
1156 named by a digit or by a digit and a letter. Sometimes there are
1157 multiple man pages with the same name in different sections. To read
1158 a man page from a specific section, type
1159 @samp{@var{topic}(@var{section})} or @samp{@var{section} @var{topic}}
1160 when @kbd{M-x manual-entry} prompts for the topic. For example, to
1161 read the man page for the C library function @code{chmod} (as opposed
1162 to a command of the same name), type @kbd{M-x manual-entry @key{RET}
1163 chmod(2) @key{RET}}. (@code{chmod} is a system call, so it is in
1164 section @samp{2}.)
1165
1166 @vindex Man-switches
1167 If you do not specify a section, the results depend on how the
1168 @code{man} program works on your system. Some of them display only
1169 the first man page they find. Others display all man pages that have
1170 the specified name, so you can move between them with the @kbd{M-n}
1171 and @kbd{M-p} keys@footnote{On some systems, the @code{man} program
1172 accepts a @samp{-a} command-line option which tells it to display all
1173 the man pages for the specified topic. If you want this behavior, you
1174 can add this option to the value of the variable @code{Man-switches}.}.
1175 The mode line shows how many manual pages are present in the Man buffer.
1176
1177 @vindex Man-fontify-manpage-flag
1178 By default, Emacs highlights the text in man pages. For a long man
1179 page, highlighting can take substantial time. You can turn off
1180 highlighting of man pages by setting the variable
1181 @code{Man-fontify-manpage-flag} to @code{nil}.
1182
1183 @findex Man-fontify-manpage
1184 If you insert the text of a man page into an Emacs buffer in some
1185 other fashion, you can use the command @kbd{M-x Man-fontify-manpage} to
1186 perform the same conversions that @kbd{M-x manual-entry} does.
1187
1188 @findex woman
1189 @cindex manual pages, on MS-DOS/MS-Windows
1190 An alternative way of reading manual pages is the @kbd{M-x woman}
1191 command@footnote{The name of the command, @code{woman}, is an acronym
1192 for ``w/o (without) man,'' since it doesn't use the @code{man}
1193 program.}. Unlike @kbd{M-x man}, it does not run any external
1194 programs to format and display the man pages; instead it does the job
1195 in Emacs Lisp, so it works on systems such as MS-Windows, where the
1196 @code{man} program (and other programs it uses) are not generally
1197 available.
1198
1199 @kbd{M-x woman} prompts for a name of a manual page, and provides
1200 completion based on the list of manual pages that are installed on
1201 your machine; the list of available manual pages is computed
1202 automatically the first time you invoke @code{woman}. The word at
1203 point in the current buffer is used to suggest the default for the
1204 name of the manual page.
1205
1206 With a numeric argument, @kbd{M-x woman} recomputes the list of the
1207 manual pages used for completion. This is useful if you add or delete
1208 manual pages.
1209
1210 If you type a name of a manual page and @kbd{M-x woman} finds that
1211 several manual pages by the same name exist in different sections, it
1212 pops up a window with possible candidates asking you to choose one of
1213 them.
1214
1215 For more information about setting up and using @kbd{M-x woman}, see
1216 @ref{Top, WoMan, Browse UN*X Manual Pages WithOut Man, woman, The WoMan
1217 Manual}.
1218
1219 @node Lisp Doc
1220 @subsection Emacs Lisp Documentation Lookup
1221
1222 As you edit Lisp code to be run in Emacs, you can use the commands
1223 @kbd{C-h f} (@code{describe-function}) and @kbd{C-h v}
1224 (@code{describe-variable}) to view documentation of functions and
1225 variables that you want to use. These commands use the minibuffer to
1226 read the name of a function or variable to document, and display the
1227 documentation in a window. Their default arguments are based on the
1228 code in the neighborhood of point. For @kbd{C-h f}, the default is
1229 the function called in the innermost list containing point. @kbd{C-h
1230 v} uses the symbol name around or adjacent to point as its default.
1231
1232 @cindex Eldoc mode
1233 @findex eldoc-mode
1234 A more automatic but less powerful method is Eldoc mode. This minor
1235 mode constantly displays in the echo area the argument list for the
1236 function being called at point. (In other words, it finds the
1237 function call that point is contained in, and displays the argument
1238 list of that function.) If point is over a documented variable, it
1239 shows the first line of the variable's docstring. Eldoc mode applies
1240 in Emacs Lisp and Lisp Interaction modes, and perhaps a few others
1241 that provide special support for looking up doc strings. Use the
1242 command @kbd{M-x eldoc-mode} to enable or disable this feature.
1243
1244 @node Hideshow
1245 @section Hideshow minor mode
1246
1247 @findex hs-minor-mode
1248 Hideshow minor mode provides selective display of portions of a
1249 program, known as @dfn{blocks}. You can use @kbd{M-x hs-minor-mode}
1250 to enable or disable this mode, or add @code{hs-minor-mode} to the
1251 mode hook for certain major modes in order to enable it automatically
1252 for those modes.
1253
1254 Just what constitutes a block depends on the major mode. In C mode
1255 or C++ mode, they are delimited by braces, while in Lisp mode and
1256 similar modes they are delimited by parentheses. Multi-line comments
1257 also count as blocks.
1258
1259 @findex hs-hide-all
1260 @findex hs-hide-block
1261 @findex hs-show-all
1262 @findex hs-show-block
1263 @findex hs-show-region
1264 @findex hs-hide-level
1265 @findex hs-minor-mode
1266 @kindex C-c @@ C-h
1267 @kindex C-c @@ C-s
1268 @kindex C-c @@ C-M-h
1269 @kindex C-c @@ C-M-s
1270 @kindex C-c @@ C-r
1271 @kindex C-c @@ C-l
1272 @kindex S-Mouse-2
1273 @table @kbd
1274 @item C-c @@ C-h
1275 Hide the current block (@code{hs-hide-block}).
1276 @item C-c @@ C-s
1277 Show the current block (@code{hs-show-block}).
1278 @item C-c @@ C-c
1279 Either hide or show the current block (@code{hs-toggle-hiding}).
1280 @item S-Mouse-2
1281 Either hide or show the block you click on (@code{hs-mouse-toggle-hiding}).
1282 @item C-c @@ C-M-h
1283 Hide all top-level blocks (@code{hs-hide-all}).
1284 @item C-c @@ C-M-s
1285 Show everything in the buffer (@code{hs-show-all}).
1286 @item C-c @@ C-l
1287 Hide all blocks @var{n} levels below this block
1288 (@code{hs-hide-level}).
1289 @end table
1290
1291 @vindex hs-hide-comments-when-hiding-all
1292 @vindex hs-isearch-open
1293 @vindex hs-special-modes-alist
1294 These variables exist for customizing Hideshow mode.
1295
1296 @table @code
1297 @item hs-hide-comments-when-hiding-all
1298 Non-@code{nil} says that @kbd{hs-hide-all} should hide comments too.
1299
1300 @item hs-isearch-open
1301 Specifies what kind of hidden blocks incremental search should make
1302 visible. The value should be one of these four symbols:
1303
1304 @table @code
1305 @item code
1306 Open only code blocks.
1307 @item comment
1308 Open only comments.
1309 @item t
1310 Open both code blocks and comments.
1311 @item nil
1312 Open neither code blocks nor comments.
1313 @end table
1314
1315 @item hs-special-modes-alist
1316 A list of elements, each specifying how to initialize Hideshow
1317 variables for one major mode. See the variable's documentation string
1318 for more information.
1319 @end table
1320
1321 @node Symbol Completion
1322 @section Completion for Symbol Names
1323 @cindex completion (symbol names)
1324
1325 In Emacs, completion is something you normally do in the minibuffer
1326 (@pxref{Completion}). But one kind of completion is available in all
1327 buffers: completion for symbol names.
1328
1329 @kindex M-TAB
1330 The character @kbd{M-@key{TAB}} runs a command to complete the
1331 partial symbol before point against the set of meaningful symbol
1332 names. This command inserts at point any additional characters that
1333 it can determine from the partial name.
1334
1335 If your window manager defines @kbd{M-@key{TAB}} to switch windows,
1336 you can type @kbd{@key{ESC} @key{TAB}} or @kbd{C-M-i} instead.
1337 However, most window managers let you customize these shortcuts, so
1338 you can change any that interfere with the way you use Emacs.
1339
1340 If the partial name in the buffer has multiple possible completions
1341 that differ in the very next character, so that it is impossible to
1342 complete even one more character, @kbd{M-@key{TAB}} displays a list of
1343 all possible completions in another window.
1344
1345 @cindex tags-based completion
1346 @cindex Info index completion
1347 @findex complete-symbol
1348 In most programming language major modes, @kbd{M-@key{TAB}} runs the
1349 command @code{complete-symbol}, which provides two kinds of completion.
1350 Normally it does completion based on a tags table (@pxref{Tags}); with a
1351 numeric argument (regardless of the value), it does completion based on
1352 the names listed in the Info file indexes for your language. Thus, to
1353 complete the name of a symbol defined in your own program, use
1354 @kbd{M-@key{TAB}} with no argument; to complete the name of a standard
1355 library function, use @kbd{C-u M-@key{TAB}}. Of course, Info-based
1356 completion works only if there is an Info file for the standard library
1357 functions of your language, and only if it is installed at your site.
1358
1359 @cindex Lisp symbol completion
1360 @cindex completion (Lisp symbols)
1361 @findex lisp-complete-symbol
1362 In Emacs-Lisp mode, the name space for completion normally consists of
1363 nontrivial symbols present in Emacs---those that have function
1364 definitions, values or properties. However, if there is an
1365 open-parenthesis immediately before the beginning of the partial symbol,
1366 only symbols with function definitions are considered as completions.
1367 The command which implements this is @code{lisp-complete-symbol}.
1368
1369 In Text mode and related modes, @kbd{M-@key{TAB}} completes words
1370 based on the spell-checker's dictionary. @xref{Spelling}.
1371
1372 @node Glasses
1373 @section Glasses minor mode
1374 @cindex Glasses mode
1375 @cindex identifiers, making long ones readable
1376 @cindex StudlyCaps, making them readable
1377 @findex glasses-mode
1378
1379 Glasses minor mode makes @samp{unreadableIdentifiersLikeThis}
1380 readable by altering the way they display. It knows two different
1381 ways to do this: by displaying underscores between a lower-case letter
1382 and the following capital letter, and by emboldening the capital
1383 letters. It does not alter the buffer text, only the way they
1384 display, so you can use it even on read-only buffers. You can use the
1385 command @kbd{M-x glasses-mode} to enable or disable the mode in the
1386 current buffer; you can also add @code{glasses-mode} to the mode hook
1387 of the programming language major modes in which you normally want
1388 to use Glasses mode.
1389
1390 @node Semantic
1391 @section Semantic
1392 @cindex Semantic package
1393
1394 Semantic is a package that provides language-aware editing commands
1395 based on @code{source code parsers}. This section provides a brief
1396 description of Semantic;
1397 @ifnottex
1398 for full details, see @ref{Top, Semantic,, semantic, Semantic}.
1399 @end ifnottex
1400 @iftex
1401 for full details, type @kbd{C-h i} (@code{info}) and then select the
1402 Semantic manual.
1403 @end iftex
1404
1405 Most of the ``language aware'' features in Emacs, such as font lock
1406 (@pxref{Font Lock}), rely on ``rules of thumb''@footnote{Regular
1407 expressions and syntax tables.} that usually give good results but are
1408 never completely exact. In contrast, the parsers used by Semantic
1409 have an exact understanding of programming language syntax. This
1410 allows Semantic to provide search, navigation, and completion commands
1411 that are powerful and precise.
1412
1413 To begin using Semantic, type @kbd{M-x semantic-mode} or click on
1414 the menu item named @samp{Source Code Parsers (Semantic)} in the
1415 @samp{Tools} menu. This enables Semantic mode, a global minor mode.
1416
1417 When Semantic mode is enabled, Emacs automatically attempts to
1418 parses each file you visit. Currently, Semantic understands C, C++,
1419 Scheme, Javascript, Java, HTML, and Make. Within each parsed buffer,
1420 the following commands are available:
1421
1422 @table @kbd
1423 @item C-c , j
1424 @kindex C-c , j
1425 Prompt for the name of a function defined in the current file, and
1426 move point there (@code{semantic-complete-jump-local}).
1427
1428 @item C-c , J
1429 @kindex C-c , J
1430 Prompt for the name of a function defined in any file Emacs has
1431 parsed, and move point there (@code{semantic-complete-jump}).
1432
1433 @item C-c , @key{SPC}
1434 @kindex C-c , @key{SPC}
1435 Display a list of possible completions for the symbol at point
1436 (@code{semantic-complete-analyze-inline}). This also activates a set
1437 of special keybindings for choosing a completion: @key{RET} accepts
1438 the current completion, @kbd{M-n} and @kbd{M-p} cycle through possible
1439 completions, @key{TAB} completes as far as possible and then cycles,
1440 and @kbd{C-g} or any other key aborts completion.
1441
1442 @item C-c , l
1443 @kindex C-c , l
1444 Display a list of the possible completions of the symbol at point, in
1445 another window (@code{semantic-analyze-possible-completions}).
1446 @end table
1447
1448 @noindent
1449 In addition to the above commands, the Semantic package provides a
1450 variety of other ways to make use of parser information. For
1451 instance, you can use it to display a list of completions when Emacs
1452 is idle.
1453 @ifnottex
1454 @xref{Top, Semantic,, semantic, Semantic}, for details.
1455 @end ifnottex
1456
1457 @node Misc for Programs
1458 @section Other Features Useful for Editing Programs
1459
1460 A number of Emacs commands that aren't designed specifically for
1461 editing programs are useful for that nonetheless.
1462
1463 The Emacs commands that operate on words, sentences and paragraphs
1464 are useful for editing code. Most symbols names contain words
1465 (@pxref{Words}); sentences can be found in strings and comments
1466 (@pxref{Sentences}). Paragraphs in the strict sense can be found in
1467 program code (in long comments), but the paragraph commands are useful
1468 in other places too, because programming language major modes define
1469 paragraphs to begin and end at blank lines (@pxref{Paragraphs}).
1470 Judicious use of blank lines to make the program clearer will also
1471 provide useful chunks of text for the paragraph commands to work on.
1472 Auto Fill mode, if enabled in a programming language major mode,
1473 indents the new lines which it creates.
1474
1475 The selective display feature is useful for looking at the overall
1476 structure of a function (@pxref{Selective Display}). This feature
1477 hides the lines that are indented more than a specified amount.
1478 Programming modes often support Outline minor mode (@pxref{Outline
1479 Mode}). The Foldout package provides folding-editor features
1480 (@pxref{Foldout}).
1481
1482 The ``automatic typing'' features may be useful for writing programs.
1483 @xref{Top,,Autotyping, autotype, Autotyping}.
1484
1485 @node C Modes
1486 @section C and Related Modes
1487 @cindex C mode
1488 @cindex Java mode
1489 @cindex Pike mode
1490 @cindex IDL mode
1491 @cindex CORBA IDL mode
1492 @cindex Objective C mode
1493 @cindex C++ mode
1494 @cindex AWK mode
1495 @cindex mode, Java
1496 @cindex mode, C
1497 @cindex mode, C++
1498 @cindex mode, Objective C
1499 @cindex mode, CORBA IDL
1500 @cindex mode, Pike
1501 @cindex mode, AWK
1502
1503 This section gives a brief description of the special features
1504 available in C, C++, Objective-C, Java, CORBA IDL, Pike and AWK modes.
1505 (These are called ``C mode and related modes.'') @xref{Top, , CC Mode,
1506 ccmode, CC Mode}, for a more extensive description of these modes
1507 and their special features.
1508
1509 @menu
1510 * Motion in C:: Commands to move by C statements, etc.
1511 * Electric C:: Colon and other chars can automatically reindent.
1512 * Hungry Delete:: A more powerful DEL command.
1513 * Other C Commands:: Filling comments, viewing expansion of macros,
1514 and other neat features.
1515 @end menu
1516
1517 @node Motion in C
1518 @subsection C Mode Motion Commands
1519
1520 This section describes commands for moving point, in C mode and
1521 related modes.
1522
1523 @table @code
1524 @item M-x c-beginning-of-defun
1525 @itemx M-x c-end-of-defun
1526 @findex c-beginning-of-defun
1527 @findex c-end-of-defun
1528 Move point to the beginning or end of the current function or
1529 top-level definition. These are found by searching for the least
1530 enclosing braces. (By contrast, @code{beginning-of-defun} and
1531 @code{end-of-defun} search for braces in column zero.) If you are
1532 editing code where the opening brace of a function isn't placed in
1533 column zero, you may wish to bind @code{C-M-a} and @code{C-M-e} to
1534 these commands. @xref{Moving by Defuns}.
1535
1536 @item C-c C-u
1537 @kindex C-c C-u @r{(C mode)}
1538 @findex c-up-conditional
1539 Move point back to the containing preprocessor conditional, leaving the
1540 mark behind. A prefix argument acts as a repeat count. With a negative
1541 argument, move point forward to the end of the containing
1542 preprocessor conditional.
1543
1544 @samp{#elif} is equivalent to @samp{#else} followed by @samp{#if}, so
1545 the function will stop at a @samp{#elif} when going backward, but not
1546 when going forward.
1547
1548 @item C-c C-p
1549 @kindex C-c C-p @r{(C mode)}
1550 @findex c-backward-conditional
1551 Move point back over a preprocessor conditional, leaving the mark
1552 behind. A prefix argument acts as a repeat count. With a negative
1553 argument, move forward.
1554
1555 @item C-c C-n
1556 @kindex C-c C-n @r{(C mode)}
1557 @findex c-forward-conditional
1558 Move point forward across a preprocessor conditional, leaving the mark
1559 behind. A prefix argument acts as a repeat count. With a negative
1560 argument, move backward.
1561
1562 @item M-a
1563 @kindex M-a (C mode)
1564 @findex c-beginning-of-statement
1565 Move point to the beginning of the innermost C statement
1566 (@code{c-beginning-of-statement}). If point is already at the beginning
1567 of a statement, move to the beginning of the preceding statement. With
1568 prefix argument @var{n}, move back @var{n} @minus{} 1 statements.
1569
1570 In comments or in strings which span more than one line, this command
1571 moves by sentences instead of statements.
1572
1573 @item M-e
1574 @kindex M-e (C mode)
1575 @findex c-end-of-statement
1576 Move point to the end of the innermost C statement or sentence; like
1577 @kbd{M-a} except that it moves in the other direction
1578 (@code{c-end-of-statement}).
1579 @end table
1580
1581 @node Electric C
1582 @subsection Electric C Characters
1583
1584 In C mode and related modes, certain printing characters are
1585 @dfn{electric}---in addition to inserting themselves, they also
1586 reindent the current line, and optionally also insert newlines. The
1587 ``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#},
1588 @kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and
1589 @kbd{)}.
1590
1591 You might find electric indentation inconvenient if you are editing
1592 chaotically indented code. If you are new to CC Mode, you might find
1593 it disconcerting. You can toggle electric action with the command
1594 @kbd{C-c C-l}; when it is enabled, @samp{/l} appears in the mode line
1595 after the mode name:
1596
1597 @table @kbd
1598 @item C-c C-l
1599 @kindex C-c C-l @r{(C mode)}
1600 @findex c-toggle-electric-state
1601 Toggle electric action (@code{c-toggle-electric-state}). With a
1602 prefix argument, this command enables electric action if the argument
1603 is positive, disables it if it is negative.
1604 @end table
1605
1606 Electric characters insert newlines only when, in addition to the
1607 electric state, the @dfn{auto-newline} feature is enabled (indicated
1608 by @samp{/la} in the mode line after the mode name). You can turn
1609 this feature on or off with the command @kbd{C-c C-a}:
1610
1611 @table @kbd
1612 @item C-c C-a
1613 @kindex C-c C-a @r{(C mode)}
1614 @findex c-toggle-auto-newline
1615 Toggle the auto-newline feature (@code{c-toggle-auto-newline}). With a
1616 prefix argument, this command turns the auto-newline feature on if the
1617 argument is positive, and off if it is negative.
1618 @end table
1619
1620 Usually the CC Mode style configures the exact circumstances in
1621 which Emacs inserts auto-newlines. You can also configure this
1622 directly. @xref{Custom Auto-newlines,,, ccmode, The CC Mode Manual}.
1623
1624 @node Hungry Delete
1625 @subsection Hungry Delete Feature in C
1626 @cindex hungry deletion (C Mode)
1627
1628 If you want to delete an entire block of whitespace at point, you
1629 can use @dfn{hungry deletion}. This deletes all the contiguous
1630 whitespace either before point or after point in a single operation.
1631 @dfn{Whitespace} here includes tabs and newlines, but not comments or
1632 preprocessor commands.
1633
1634 @table @kbd
1635 @item C-c C-@key{DEL}
1636 @itemx C-c @key{DEL}
1637 @findex c-hungry-delete-backwards
1638 @kindex C-c C-@key{DEL} (C Mode)
1639 @kindex C-c @key{DEL} (C Mode)
1640 @code{c-hungry-delete-backwards}---Delete the entire block of whitespace
1641 preceding point.
1642
1643 @item C-c C-d
1644 @itemx C-c C-@key{DELETE}
1645 @itemx C-c @key{DELETE}
1646 @findex c-hungry-delete-forward
1647 @kindex C-c C-d (C Mode)
1648 @kindex C-c C-@key{DELETE} (C Mode)
1649 @kindex C-c @key{DELETE} (C Mode)
1650 @code{c-hungry-delete-forward}---Delete the entire block of whitespace
1651 following point.
1652 @end table
1653
1654 As an alternative to the above commands, you can enable @dfn{hungry
1655 delete mode}. When this feature is enabled (indicated by @samp{/h} in
1656 the mode line after the mode name), a single @key{DEL} deletes all
1657 preceding whitespace, not just one space, and a single @kbd{C-c C-d}
1658 (but @emph{not} plain @key{DELETE}) deletes all following whitespace.
1659
1660 @table @kbd
1661 @item M-x c-toggle-hungry-state
1662 @findex c-toggle-hungry-state
1663 Toggle the hungry-delete feature
1664 (@code{c-toggle-hungry-state})@footnote{This command had the binding
1665 @kbd{C-c C-d} in earlier versions of Emacs. @kbd{C-c C-d} is now
1666 bound to @code{c-hungry-delete-forward}.}. With a prefix argument,
1667 this command turns the hungry-delete feature on if the argument is
1668 positive, and off if it is negative.
1669 @end table
1670
1671 @vindex c-hungry-delete-key
1672 The variable @code{c-hungry-delete-key} controls whether the
1673 hungry-delete feature is enabled.
1674
1675 @node Other C Commands
1676 @subsection Other Commands for C Mode
1677
1678 @table @kbd
1679 @item C-c C-w
1680 @itemx M-x subword-mode
1681 @findex subword-mode
1682 Enable (or disable) @dfn{subword mode}. In subword mode, Emacs's word
1683 commands recognize upper case letters in
1684 @samp{StudlyCapsIdentifiers} as word boundaries. This is indicated by
1685 the flag @samp{/w} on the mode line after the mode name
1686 (e.g. @samp{C/law}). You can even use @kbd{M-x subword-mode} in
1687 non-CC Mode buffers.
1688
1689 In the GNU project, we recommend using underscores to separate words
1690 within an identifier in C or C++, rather than using case distinctions.
1691
1692 @item M-x c-context-line-break
1693 @findex c-context-line-break
1694 This command inserts a line break and indents the new line in a manner
1695 appropriate to the context. In normal code, it does the work of
1696 @kbd{C-j} (@code{newline-and-indent}), in a C preprocessor line it
1697 additionally inserts a @samp{\} at the line break, and within comments
1698 it's like @kbd{M-j} (@code{c-indent-new-comment-line}).
1699
1700 @code{c-context-line-break} isn't bound to a key by default, but it
1701 needs a binding to be useful. The following code will bind it to
1702 @kbd{C-j}. We use @code{c-initialization-hook} here to make sure
1703 the keymap is loaded before we try to change it.
1704
1705 @smallexample
1706 (defun my-bind-clb ()
1707 (define-key c-mode-base-map "\C-j" 'c-context-line-break))
1708 (add-hook 'c-initialization-hook 'my-bind-clb)
1709 @end smallexample
1710
1711 @item C-M-h
1712 Put mark at the end of a function definition, and put point at the
1713 beginning (@code{c-mark-function}).
1714
1715 @item M-q
1716 @kindex M-q @r{(C mode)}
1717 @findex c-fill-paragraph
1718 Fill a paragraph, handling C and C++ comments (@code{c-fill-paragraph}).
1719 If any part of the current line is a comment or within a comment, this
1720 command fills the comment or the paragraph of it that point is in,
1721 preserving the comment indentation and comment delimiters.
1722
1723 @item C-c C-e
1724 @cindex macro expansion in C
1725 @cindex expansion of C macros
1726 @findex c-macro-expand
1727 @kindex C-c C-e @r{(C mode)}
1728 Run the C preprocessor on the text in the region, and show the result,
1729 which includes the expansion of all the macro calls
1730 (@code{c-macro-expand}). The buffer text before the region is also
1731 included in preprocessing, for the sake of macros defined there, but the
1732 output from this part isn't shown.
1733
1734 When you are debugging C code that uses macros, sometimes it is hard to
1735 figure out precisely how the macros expand. With this command, you
1736 don't have to figure it out; you can see the expansions.
1737
1738 @item C-c C-\
1739 @findex c-backslash-region
1740 @kindex C-c C-\ @r{(C mode)}
1741 Insert or align @samp{\} characters at the ends of the lines of the
1742 region (@code{c-backslash-region}). This is useful after writing or
1743 editing a C macro definition.
1744
1745 If a line already ends in @samp{\}, this command adjusts the amount of
1746 whitespace before it. Otherwise, it inserts a new @samp{\}. However,
1747 the last line in the region is treated specially; no @samp{\} is
1748 inserted on that line, and any @samp{\} there is deleted.
1749
1750 @item M-x cpp-highlight-buffer
1751 @cindex preprocessor highlighting
1752 @findex cpp-highlight-buffer
1753 Highlight parts of the text according to its preprocessor conditionals.
1754 This command displays another buffer named @samp{*CPP Edit*}, which
1755 serves as a graphic menu for selecting how to display particular kinds
1756 of conditionals and their contents. After changing various settings,
1757 click on @samp{[A]pply these settings} (or go to that buffer and type
1758 @kbd{a}) to rehighlight the C mode buffer accordingly.
1759
1760 @item C-c C-s
1761 @findex c-show-syntactic-information
1762 @kindex C-c C-s @r{(C mode)}
1763 Display the syntactic information about the current source line
1764 (@code{c-show-syntactic-information}). This information directs how
1765 the line is indented.
1766
1767 @item M-x cwarn-mode
1768 @itemx M-x global-cwarn-mode
1769 @findex cwarn-mode
1770 @findex global-cwarn-mode
1771 @vindex global-cwarn-mode
1772 @cindex CWarn mode
1773 @cindex suspicious constructions in C, C++
1774 CWarn minor mode highlights certain suspicious C and C++ constructions:
1775
1776 @itemize @bullet{}
1777 @item
1778 Assignments inside expressions.
1779 @item
1780 Semicolon following immediately after @samp{if}, @samp{for}, and @samp{while}
1781 (except after a @samp{do @dots{} while} statement);
1782 @item
1783 C++ functions with reference parameters.
1784 @end itemize
1785
1786 @noindent
1787 You can enable the mode for one buffer with the command @kbd{M-x
1788 cwarn-mode}, or for all suitable buffers with the command @kbd{M-x
1789 global-cwarn-mode} or by customizing the variable
1790 @code{global-cwarn-mode}. You must also enable Font Lock mode to make
1791 it work.
1792
1793 @item M-x hide-ifdef-mode
1794 @findex hide-ifdef-mode
1795 @cindex Hide-ifdef mode
1796 @vindex hide-ifdef-shadow
1797 Hide-ifdef minor mode hides selected code within @samp{#if} and
1798 @samp{#ifdef} preprocessor blocks. If you change the variable
1799 @code{hide-ifdef-shadow} to @code{t}, Hide-ifdef minor mode
1800 ``shadows'' preprocessor blocks by displaying them with a less
1801 prominent face, instead of hiding them entirely. See the
1802 documentation string of @code{hide-ifdef-mode} for more information.
1803
1804 @item M-x ff-find-related-file
1805 @cindex related files
1806 @findex ff-find-related-file
1807 @vindex ff-related-file-alist
1808 Find a file ``related'' in a special way to the file visited by the
1809 current buffer. Typically this will be the header file corresponding
1810 to a C/C++ source file, or vice versa. The variable
1811 @code{ff-related-file-alist} specifies how to compute related file
1812 names.
1813 @end table
1814
1815 @node Asm Mode
1816 @section Asm Mode
1817
1818 @cindex Asm mode
1819 @cindex assembler mode
1820 Asm mode is a major mode for editing files of assembler code. It
1821 defines these commands:
1822
1823 @table @kbd
1824 @item @key{TAB}
1825 @code{tab-to-tab-stop}.
1826 @item C-j
1827 Insert a newline and then indent using @code{tab-to-tab-stop}.
1828 @item :
1829 Insert a colon and then remove the indentation from before the label
1830 preceding colon. Then do @code{tab-to-tab-stop}.
1831 @item ;
1832 Insert or align a comment.
1833 @end table
1834
1835 The variable @code{asm-comment-char} specifies which character
1836 starts comments in assembler syntax.
1837
1838 @ifnottex
1839 @include fortran-xtra.texi
1840 @end ifnottex