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