Mercurial > emacs
comparison man/programs.texi @ 38867:bd208373c5a8
Many clarifications.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 20 Aug 2001 03:57:13 +0000 |
parents | 6ed2cc05e016 |
children | 9cefdb98080f |
comparison
equal
deleted
inserted
replaced
38866:662d4bf4871a | 38867:bd208373c5a8 |
---|---|
5 @chapter Editing Programs | 5 @chapter Editing Programs |
6 @cindex Lisp editing | 6 @cindex Lisp editing |
7 @cindex C editing | 7 @cindex C editing |
8 @cindex program editing | 8 @cindex program editing |
9 | 9 |
10 Emacs provides many features to facilitate editing programs. These | 10 Emacs provides many features to facilitate editing programs. Some |
11 features can: | 11 of these features can |
12 | 12 |
13 @itemize @bullet | 13 @itemize @bullet |
14 @item | 14 @item |
15 Find or move over top-level definitions (@pxref{Defuns}). | 15 Find or move over top-level definitions (@pxref{Defuns}). |
16 @item | 16 @item |
21 @item | 21 @item |
22 Balance parentheses (@pxref{Parentheses}). | 22 Balance parentheses (@pxref{Parentheses}). |
23 @item | 23 @item |
24 Highlight program syntax (@pxref{Font Lock}). | 24 Highlight program syntax (@pxref{Font Lock}). |
25 @end itemize | 25 @end itemize |
26 | |
27 This chapter describes these features and many more. | |
26 | 28 |
27 @menu | 29 @menu |
28 * Program Modes:: Major modes for editing programs. | 30 * Program Modes:: Major modes for editing programs. |
29 * Defuns:: Commands to operate on major top-level parts | 31 * Defuns:: Commands to operate on major top-level parts |
30 of a program. | 32 of a program. |
48 | 50 |
49 Emacs has specialized major modes for various programming languages. | 51 Emacs has specialized major modes for various programming languages. |
50 @xref{Major Modes}. A programming language major mode typically | 52 @xref{Major Modes}. A programming language major mode typically |
51 specifies the syntax of expressions, the customary rules for | 53 specifies the syntax of expressions, the customary rules for |
52 indentation, how to do syntax highlighting for the language, and how | 54 indentation, how to do syntax highlighting for the language, and how |
53 to find the beginning of a function definition. They often provide | 55 to find the beginning of a function definition. It often customizes |
54 facilities for compiling and debugging programs as well. | 56 or provides facilities for compiling and debugging programs as well. |
55 | 57 |
56 Ideally, Emacs should provide a major mode for each programming | 58 Ideally, Emacs should provide a major mode for each programming |
57 language that you might want to edit; if it doesn't have a mode for | 59 language that you might want to edit; if it doesn't have a mode for |
58 your favorite language, you can contribute one. But often the mode | 60 your favorite language, you can contribute one. But often the mode |
59 for one language can serve for other syntactically similar languages. | 61 for one language can serve for other syntactically similar languages. |
60 The major mode for language @var{l} is called @code{@var{l}-mode}, | 62 The major mode for language @var{l} is called @code{@var{l}-mode}, |
61 and you can enable it by typing @kbd{M-x @var{l}-mode @key{RET}}. | 63 and you can select it by typing @kbd{M-x @var{l}-mode @key{RET}}. |
62 @xref{Choosing Modes}. | 64 @xref{Choosing Modes}. |
63 | 65 |
64 @cindex Perl mode | 66 @cindex Perl mode |
65 @cindex Icon mode | 67 @cindex Icon mode |
66 @cindex Awk mode | 68 @cindex Awk mode |
84 format), Icon, IDL (CORBA), IDLWAVE, Java, Metafont (@TeX{}'s | 86 format), Icon, IDL (CORBA), IDLWAVE, Java, Metafont (@TeX{}'s |
85 companion for font creation), Modula2, Objective-C, Octave, Pascal, | 87 companion for font creation), Modula2, Objective-C, Octave, Pascal, |
86 Perl, Pike, PostScript, Prolog, Simula, Tcl, and VHDL. There is | 88 Perl, Pike, PostScript, Prolog, Simula, Tcl, and VHDL. There is |
87 also a major mode for makefiles, called Makefile mode. An alternative | 89 also a major mode for makefiles, called Makefile mode. An alternative |
88 mode for Perl is called CPerl mode. Modes are available for the | 90 mode for Perl is called CPerl mode. Modes are available for the |
89 scripting languages of the common Unix shells, VMS DCL, and | 91 scripting languages of the common GNU and Unix shells, VMS DCL, and |
90 MS-DOS/MS-Windows @samp{BAT} files. There are also major modes for | 92 MS-DOS/MS-Windows @samp{BAT} files. There are also major modes for |
91 editing various sorts of configuration files. | 93 editing various sorts of configuration files. |
92 | 94 |
93 @kindex DEL @r{(programming modes)} | 95 @kindex DEL @r{(programming modes)} |
94 @findex c-electric-backspace | 96 @findex c-electric-backspace |
95 In most programming languages, indentation should vary from line to | 97 In most programming languages, indentation should vary from line to |
96 line to illustrate the structure of the program. So the major modes | 98 line to illustrate the structure of the program. So the major modes |
97 for program languages arrange for @key{TAB} to update the indentation | 99 for programming languages arrange for @key{TAB} to update the |
98 of the current line. They also rebind @key{DEL} to treat a tab as if | 100 indentation of the current line. They also rebind @key{DEL} to treat |
99 it were the equivalent number of spaces. This makes it possible to | 101 a tab as if it were the equivalent number of spaces; this lets you |
100 reduce indentation one column at a time without worrying whether it is | 102 delete one column of indentation without worrying whether the |
101 made up of spaces or tabs. Use @kbd{C-b C-d} to delete a tab | 103 whitespace consists of spaces or tabs. Use @kbd{C-b C-d} to delete a |
102 character before point, in these modes. | 104 tab character before point, in these modes. |
103 | 105 |
104 Separate manuals are available for the modes for Ada (@pxref{Top, , Ada | 106 Separate manuals are available for the modes for Ada (@pxref{Top, , Ada |
105 Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL | 107 Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL |
106 (@pxref{Top, , CC Mode, ccmode, CC Mode}) and the IDLWAVE modes | 108 (@pxref{Top, , CC Mode, ccmode, CC Mode}) and the IDLWAVE modes |
107 (@pxref{Top, , IDLWAVE, idlwave, IDLWAVE User Manual}). | 109 (@pxref{Top, , IDLWAVE, idlwave, IDLWAVE User Manual}). |
238 command while point is between defuns, it uses the following defun. | 240 command while point is between defuns, it uses the following defun. |
239 | 241 |
240 In C mode, @kbd{C-M-h} runs the function @code{c-mark-function}, | 242 In C mode, @kbd{C-M-h} runs the function @code{c-mark-function}, |
241 which is almost the same as @code{mark-defun}; the difference is that | 243 which is almost the same as @code{mark-defun}; the difference is that |
242 it backs up over the argument declarations, function name and returned | 244 it backs up over the argument declarations, function name and returned |
243 data type so that the entire C function is inside the region. | 245 data type so that the entire C function is inside the region. This is |
244 @xref{Marking Objects}. This is an example of how major modes adjust | 246 an example of how major modes adjust the standard key bindings so that |
245 the standard key bindings so that they do their standard jobs in a way | 247 they do their standard jobs in a way better fitting a particular |
246 better fitting a particular language. Other major modes may adjust | 248 language. Other major modes may replace any or all of these key |
247 any or all of these key bindings for that purpose. | 249 bindings for that purpose. |
248 | 250 |
249 @node Imenu | 251 @node Imenu |
250 @subsection Imenu | 252 @subsection Imenu |
251 @cindex indexes of buffer contents | 253 @cindex index of buffer definitions |
252 @cindex buffer content indexes | 254 @cindex buffer definitions index |
253 @cindex tags | 255 @cindex tags |
254 | 256 |
255 The Imenu facility offers a way to find the the major definitions in | 257 The Imenu facility offers a way to find the the major definitions in |
256 a file by name. It is also useful in text formatter major modes, | 258 a file by name. It is also useful in text formatter major modes, |
257 where it treats each chapter, section, etc., as a definition. | 259 where it treats each chapter, section, etc., as a definition. |
258 (@pxref{Tags}, for a more powerful feature that handles multiple files | 260 (@xref{Tags}, for a more powerful feature that handles multiple files |
259 together.) | 261 together.) |
260 | 262 |
261 @findex imenu | 263 @findex imenu |
262 If you type @kbd{M-x imenu}, it reads the name of a definition using | 264 If you type @kbd{M-x imenu}, it reads the name of a definition using |
263 the minibuffer, then goes to that definition. You can use completion | 265 the minibuffer, then moves point to that definition. You can use |
264 to specify the name, and a complete list of possible names is always | 266 completion to specify the name; the command always displays the whole |
265 displayed. | 267 list of valid names. |
266 | 268 |
267 @findex imenu-add-menubar-index | 269 @findex imenu-add-menubar-index |
268 Alternatively, you can bind the command @code{imenu} to a mouse | 270 Alternatively, you can bind the command @code{imenu} to a mouse |
269 click. Then it displays mouse menus for you to select the definition | 271 click. Then it displays mouse menus for you to select a definition |
270 you want. You can also add the buffer's index to the menu bar by | 272 name. You can also add the buffer's index to the menu bar by calling |
271 calling @code{imenu-add-menubar-index}. If you want to have this | 273 @code{imenu-add-menubar-index}. If you want to have this menu bar |
272 menu bar item available for all buffers in a certain major mode, you | 274 item available for all buffers in a certain major mode, you can do |
273 can do this by adding @code{imenu-add-menubar-index} to its mode | 275 this by adding @code{imenu-add-menubar-index} to its mode hook. But |
274 hook. But then you will have to wait for the buffer to be searched | 276 if you have done that, you will have to wait each time you visit a |
275 for definitions, each time you visit a file which uses that mode. | 277 file in that mode, while Emacs finds all the definitions in that |
278 buffer. | |
276 | 279 |
277 @vindex imenu-auto-rescan | 280 @vindex imenu-auto-rescan |
278 When you change the contents of a buffer, if you add or delete | 281 When you change the contents of a buffer, if you add or delete |
279 definitions, you can update the buffer's index to correspond to the | 282 definitions, you can update the buffer's index based on the |
280 new contents by invoking the @samp{*Rescan*} item in the menu. | 283 new contents by invoking the @samp{*Rescan*} item in the menu. |
281 Rescanning happens automatically if @code{imenu-auto-rescan} is | 284 Rescanning happens automatically you set @code{imenu-auto-rescan} to a |
282 non-@code{nil}. There is no need to rescan because of small changes | 285 non-@code{nil} value. There is no need to rescan because of small |
283 in the text. | 286 changes in the text. |
284 | 287 |
285 @vindex imenu-sort-function | 288 @vindex imenu-sort-function |
286 You can customize the way the menus are sorted by setting the | 289 You can customize the way the menus are sorted by setting the |
287 variable @code{imenu-sort-function}. By default names are ordered as | 290 variable @code{imenu-sort-function}. By default, names are ordered as |
288 they occur in the buffer; if you want alphabetic sorting, use the | 291 they occur in the buffer; if you want alphabetic sorting, use the |
289 symbol @code{imenu--sort-by-name} as the value. You can also | 292 symbol @code{imenu--sort-by-name} as the value. You can also |
290 define your own comparison function by writing Lisp code. | 293 define your own comparison function by writing Lisp code. |
291 | 294 |
292 Imenu provides the information to guide Which Function mode | 295 Imenu provides the information to guide Which Function mode |
307 | 310 |
308 @findex which-function-mode | 311 @findex which-function-mode |
309 @vindex which-func-modes | 312 @vindex which-func-modes |
310 To enable (or disable) Which Function mode, use the command @kbd{M-x | 313 To enable (or disable) Which Function mode, use the command @kbd{M-x |
311 which-function-mode}. This command is global; it applies to all | 314 which-function-mode}. This command is global; it applies to all |
312 buffers, both existing ones and those yet to be created. However, this | 315 buffers, both existing ones and those yet to be created. However, |
313 only affects certain major modes, those listed in the value of | 316 it only takes effect in certain major modes, those listed in the value of |
314 @code{which-func-modes}. If the value is @code{t}, then Which Function | 317 @code{which-func-modes}. If the value is @code{t}, then Which |
315 mode applies to all major modes that know how to support it---which are | 318 Function mode applies to all major modes that know how to support |
316 the major modes that support Imenu. | 319 it---in other words, all the major modes that support Imenu. |
317 | 320 |
318 @node Program Indent | 321 @node Program Indent |
319 @section Indentation for Programs | 322 @section Indentation for Programs |
320 @cindex indentation for programs | 323 @cindex indentation for programs |
321 | 324 |
346 @item @key{TAB} | 349 @item @key{TAB} |
347 Adjust indentation of current line. | 350 Adjust indentation of current line. |
348 @item C-j | 351 @item C-j |
349 Equivalent to @key{RET} followed by @key{TAB} (@code{newline-and-indent}). | 352 Equivalent to @key{RET} followed by @key{TAB} (@code{newline-and-indent}). |
350 @item @key{LINEFEED} | 353 @item @key{LINEFEED} |
351 This key is a way to enter @kbd{C-j}, on some keyboards. | 354 This key, if the keyboard has it, is another way to enter @kbd{C-j}. |
352 @end table | 355 @end table |
353 | 356 |
354 @kindex TAB @r{(programming modes)} | 357 @kindex TAB @r{(programming modes)} |
355 @findex c-indent-command | 358 @findex c-indent-command |
356 @findex indent-line-function | 359 @findex indent-line-function |
403 you have several commands available. | 406 you have several commands available. |
404 | 407 |
405 @table @kbd | 408 @table @kbd |
406 @item C-M-q | 409 @item C-M-q |
407 Reindent all the lines within one parenthetical grouping(@code{indent-sexp}). | 410 Reindent all the lines within one parenthetical grouping(@code{indent-sexp}). |
411 @item C-M-\ | |
412 Reindent all lines in the region (@code{indent-region}). | |
408 @item C-u @key{TAB} | 413 @item C-u @key{TAB} |
409 Shift an entire parenthetical grouping rigidly sideways so that its | 414 Shift an entire parenthetical grouping rigidly sideways so that its |
410 first line is properly indented. | 415 first line is properly indented. |
411 @item C-M-\ | |
412 Reindent all lines in the region (@code{indent-region}). | |
413 @item M-x indent-code-rigidly | 416 @item M-x indent-code-rigidly |
414 Shift all the lines in the region rigidly sideways, but do not alter | 417 Shift all the lines in the region rigidly sideways, but do not alter |
415 lines that start inside comments and strings. | 418 lines that start inside comments and strings. |
416 @end table | 419 @end table |
417 | 420 |
423 bound to other suitable commands in other modes). The indentation of | 426 bound to other suitable commands in other modes). The indentation of |
424 the line where the grouping starts is not changed; therefore, this | 427 the line where the grouping starts is not changed; therefore, this |
425 changes only the relative indentation within the grouping, not its | 428 changes only the relative indentation within the grouping, not its |
426 overall indentation. To correct that as well, type @key{TAB} first. | 429 overall indentation. To correct that as well, type @key{TAB} first. |
427 | 430 |
431 Another way to specify the range to be reindented is with the | |
432 region. The command @kbd{C-M-\} (@code{indent-region}) applies | |
433 @key{TAB} to every line whose first character is between point and | |
434 mark. | |
435 | |
428 @kindex C-u TAB | 436 @kindex C-u TAB |
429 If you like the relative indentation within a grouping, but not the | 437 If you like the relative indentation within a grouping, but not the |
430 indentation of its first line, you can type @kbd{C-u @key{TAB}} to | 438 indentation of its first line, you can type @kbd{C-u @key{TAB}} to |
431 reindent the whole grouping as a rigid unit. (This works in Lisp | 439 reindent the whole grouping as a rigid unit. (This works in Lisp |
432 modes and C and related modes.) @key{TAB} with a numeric argument | 440 modes and C and related modes.) @key{TAB} with a numeric argument |
434 all the lines in the parenthetical grouping starting on the current | 442 all the lines in the parenthetical grouping starting on the current |
435 line. It is clever, though, and does not alter lines that start | 443 line. It is clever, though, and does not alter lines that start |
436 inside strings, or C preprocessor lines when in C mode. | 444 inside strings, or C preprocessor lines when in C mode. |
437 | 445 |
438 @findex indent-code-rigidly | 446 @findex indent-code-rigidly |
439 Another way to specify the range to be reindented is with the region. | 447 You can also perform this operation on the region, using the command |
440 The command @kbd{C-M-\} (@code{indent-region}) applies @key{TAB} to | 448 @kbd{M-x indent-code-rigidly}. It rigidly shifts all the lines in the |
441 every line whose first character is between point and mark. The command | 449 region sideways, like @code{indent-rigidly} does (@pxref{Indentation |
442 @kbd{M-x indent-code-rigidly} rigidly shifts all the lines in the region | 450 Commands}). It doesn't alter the indentation of lines that start |
443 sideways, like @code{indent-rigidly} does (@pxref{Indentation | 451 inside a comment or a string, unless the region starts inside that |
444 Commands}), except that it doesn't alter the indentation of lines that | |
445 start inside a comment or a string, unless the region starts inside that | |
446 comment or string. | 452 comment or string. |
447 | 453 |
448 @node Lisp Indent | 454 @node Lisp Indent |
449 @subsection Customizing Lisp Indentation | 455 @subsection Customizing Lisp Indentation |
450 @cindex customizing Lisp indentation | 456 @cindex customizing Lisp indentation |
480 @table @asis | 486 @table @asis |
481 @item @code{nil} | 487 @item @code{nil} |
482 This is the same as no property---use the standard indentation pattern. | 488 This is the same as no property---use the standard indentation pattern. |
483 @item @code{defun} | 489 @item @code{defun} |
484 Handle this function like a @samp{def} construct: treat the second | 490 Handle this function like a @samp{def} construct: treat the second |
485 line the start of a @dfn{body}. | 491 line as the start of a @dfn{body}. |
486 @item a number, @var{number} | 492 @item a number, @var{number} |
487 The first @var{number} arguments of the function are | 493 The first @var{number} arguments of the function are |
488 @dfn{distinguished} arguments; the rest are considered the body | 494 @dfn{distinguished} arguments; the rest are considered the body |
489 of the expression. A line in the expression is indented according to | 495 of the expression. A line in the expression is indented according to |
490 whether the first argument on it is distinguished or not. If the | 496 whether the first argument on it is distinguished or not. If the |
591 @findex c-set-style | 597 @findex c-set-style |
592 To choose a style for the current buffer, use the command @kbd{M-x | 598 To choose a style for the current buffer, use the command @kbd{M-x |
593 c-set-style}. Specify a style name as an argument (case is not | 599 c-set-style}. Specify a style name as an argument (case is not |
594 significant). This command affects the current buffer only, and it | 600 significant). This command affects the current buffer only, and it |
595 affects only future invocations of the indentation commands; it does | 601 affects only future invocations of the indentation commands; it does |
596 not change the indentation of the code in the buffer. To reindent the | 602 not reindent the code in the buffer. To reindent the whole buffer in |
597 whole buffer in the new style, you can type @kbd{C-x h C-M-\}. | 603 the new style, you can type @kbd{C-x h C-M-\}. |
598 | 604 |
599 @vindex c-default-style | 605 @vindex c-default-style |
600 You can also set the variable @code{c-default-style} to specify the | 606 You can also set the variable @code{c-default-style} to specify the |
601 default style for various major modes. Its value should be an alist, | 607 default style for various major modes. Its value should be an alist, |
602 in which each element specifies one major mode and which indentation | 608 in which each element specifies one major mode and which indentation |
608 @end example | 614 @end example |
609 | 615 |
610 @noindent | 616 @noindent |
611 specifies an explicit choice for Java mode, and the default @samp{gnu} | 617 specifies an explicit choice for Java mode, and the default @samp{gnu} |
612 style for the other C-like modes. This variable takes effect when you | 618 style for the other C-like modes. This variable takes effect when you |
613 switch to one of the C-like major modes; thus, if you specify a new | 619 select one of the C-like major modes; thus, if you specify a new |
614 default style for Java mode, you can make it take effect in an | 620 default style for Java mode, you can make it take effect in an |
615 existing Java mode buffer by typing @kbd{M-x java-mode} there. | 621 existing Java mode buffer by typing @kbd{M-x java-mode} there. |
616 | 622 |
617 The @code{gnu} style specifies the formatting recommended by the GNU | 623 The @code{gnu} style specifies the formatting recommended by the GNU |
618 Project for C; it is the default, so as to encourage use of our | 624 Project for C; it is the default, so as to encourage use of our |
619 recommended style. | 625 recommended style. |
620 | 626 |
621 @xref{Customizing Indentation,, cc-mode, the CC Mode Manual}, for | 627 @xref{Customizing Indentation,,, cc-mode, the CC Mode Manual}, for |
622 more information on customizing indentation for C and related modes, | 628 more information on customizing indentation for C and related modes, |
623 including how to override parts of an existing style and how to define | 629 including how to override parts of an existing style and how to define |
624 your own styles. | 630 your own styles. |
625 | 631 |
626 @node Parentheses | 632 @node Parentheses |
632 of the parenthesis structure in a program, or help you keep it | 638 of the parenthesis structure in a program, or help you keep it |
633 balanced. | 639 balanced. |
634 | 640 |
635 When talking about these facilities, the term ``parenthesis'' also | 641 When talking about these facilities, the term ``parenthesis'' also |
636 includes braces, brackets, or whatever delimiters are defined to match | 642 includes braces, brackets, or whatever delimiters are defined to match |
637 in pairs. This is controlled by the major mode, through the syntax | 643 in pairs. The major mode controls which delimiters are significant, |
638 table (@pxref{Syntax}). In Lisp, only parentheses count; in C, these | 644 through the syntax table (@pxref{Syntax}). In Lisp, only parentheses |
639 commands apply to braces and brackets too. | 645 count; in C, these commands apply to braces and brackets too. |
640 | 646 |
641 You can use @kbd{M-x check-parens} to find any unbalanced | 647 You can use @kbd{M-x check-parens} to find any unbalanced |
642 parentheses and unbalanced string quotes in the buffer. | 648 parentheses and unbalanced string quotes in the buffer. |
643 | 649 |
644 @menu | 650 @menu |
674 @end table | 680 @end table |
675 | 681 |
676 Each programming language major mode customizes the definition of | 682 Each programming language major mode customizes the definition of |
677 balanced expressions to suit that language. Balanced expressions | 683 balanced expressions to suit that language. Balanced expressions |
678 typically include symbols, numbers, and string constants, as well as | 684 typically include symbols, numbers, and string constants, as well as |
679 anything contained in parentheses, brackets or braces. Some languages | 685 any pair of matching delimiters and their contents. Some languages |
680 have obscure forms of expression syntax that nobody has bothered to | 686 have obscure forms of expression syntax that nobody has bothered to |
681 implement in Emacs. | 687 implement in Emacs. |
682 | 688 |
683 @cindex Control-Meta | 689 @cindex Control-Meta |
684 By convention, the keys for these commands are always Control-Meta | 690 By convention, the keys for these commands are all Control-Meta |
685 characters. They usually act like the corresponding Meta characters, | 691 characters. They usually act on expressions just as the corresponding |
686 except that they take note of parentheses and their contents. For | 692 Meta characters act on words. For instance, the command @kbd{C-M-b} |
687 instance, the command @kbd{C-M-b} moves backward over a balanced | 693 moves backward over a balanced expression, just as @kbd{M-b} moves |
688 expression, just as @kbd{M-b} moves back over a word. | 694 back over a word. |
689 | 695 |
690 @kindex C-M-f | 696 @kindex C-M-f |
691 @kindex C-M-b | 697 @kindex C-M-b |
692 @findex forward-sexp | 698 @findex forward-sexp |
693 @findex backward-sexp | 699 @findex backward-sexp |
729 @kindex C-M-t | 735 @kindex C-M-t |
730 @findex transpose-sexps | 736 @findex transpose-sexps |
731 A somewhat random-sounding command which is nevertheless handy is | 737 A somewhat random-sounding command which is nevertheless handy is |
732 @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous | 738 @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous |
733 balanced expression across the next one. An argument serves as a | 739 balanced expression across the next one. An argument serves as a |
734 repeat count, and a negative argument drags backwards (thus canceling | 740 repeat count, and a negative argument drags the previous balanced |
735 out the effect of @kbd{C-M-t} with a positive argument). An argument | 741 expression backwards across those before it (thus canceling out the |
736 of zero, rather than doing nothing, transposes the balanced | 742 effect of @kbd{C-M-t} with a positive argument). An argument of zero, |
737 expressions ending after point and the mark. | 743 rather than doing nothing, transposes the balanced expressions ending |
744 at or after point and the mark. | |
738 | 745 |
739 @kindex C-M-@@ | 746 @kindex C-M-@@ |
740 @findex mark-sexp | 747 @findex mark-sexp |
741 To set the region around the next balanced expression in the buffer, | 748 To set the region around the next balanced expression in the buffer, |
742 use @kbd{C-M-@@} (@code{mark-sexp}), which sets mark at the same place | 749 use @kbd{C-M-@@} (@code{mark-sexp}), which sets mark at the same place |
750 not treat @samp{foo + bar} as a single expression, even though it | 757 not treat @samp{foo + bar} as a single expression, even though it |
751 @emph{is} one C expression; instead, it recognizes @samp{foo} as one | 758 @emph{is} one C expression; instead, it recognizes @samp{foo} as one |
752 expression and @samp{bar} as another, with the @samp{+} as punctuation | 759 expression and @samp{bar} as another, with the @samp{+} as punctuation |
753 between them. Both @samp{foo + bar} and @samp{foo} are legitimate | 760 between them. Both @samp{foo + bar} and @samp{foo} are legitimate |
754 choices for ``the expression following point'' when point is at the | 761 choices for ``the expression following point'' when point is at the |
755 @samp{f}. Note that @samp{(foo + bar)} does act as a single | 762 @samp{f}, so the expression commands must perforce choose one or the |
756 expression in C mode. | 763 other to operate on. Note that @samp{(foo + bar)} is recognized as a |
764 single expression in C mode, because of the parentheses. | |
757 | 765 |
758 @node Moving by Parens | 766 @node Moving by Parens |
759 @subsection Moving in the Parenthesis Structure | 767 @subsection Moving in the Parenthesis Structure |
760 | 768 |
761 @cindex parenthetical groupings | 769 @cindex parenthetical groupings |
815 The Emacs parenthesis-matching feature is designed to show | 823 The Emacs parenthesis-matching feature is designed to show |
816 automatically how parentheses (and other matching delimiters) match in | 824 automatically how parentheses (and other matching delimiters) match in |
817 the text. Whenever you type a self-inserting character that is a | 825 the text. Whenever you type a self-inserting character that is a |
818 closing delimiter, the cursor moves momentarily to the location of the | 826 closing delimiter, the cursor moves momentarily to the location of the |
819 matching opening delimiter, provided that is on the screen. If it is | 827 matching opening delimiter, provided that is on the screen. If it is |
820 not on the screen, Emacs displays some text near it in the echo area. | 828 not on the screen, Emacs displays some of the text near it in the echo |
821 Either way, you can tell what grouping you are closing off. | 829 area. Either way, you can tell which grouping you are closing off. |
822 | 830 |
823 If the opening delimiter and closing delimiter are mismatched---such | 831 If the opening delimiter and closing delimiter are mismatched---such |
824 as in @samp{[x)}---a warning message is displayed in the echo area. | 832 as in @samp{[x)}---a warning message is displayed in the echo area. |
825 | 833 |
826 @vindex blink-matching-paren | 834 @vindex blink-matching-paren |
1100 typically available with the appropriate GNU package. | 1108 typically available with the appropriate GNU package. |
1101 | 1109 |
1102 @node Man Page | 1110 @node Man Page |
1103 @subsection Man Page Lookup | 1111 @subsection Man Page Lookup |
1104 | 1112 |
1105 Eventually the GNU project hopes to replace most man pages in the | 1113 @cindex manual page |
1106 GNU operating system with better-organized manuals that you can browse | 1114 On Unix, the main form of on-line documentation was the @dfn{manual |
1107 with Info (@pxref{Misc Help}). Since this process is not finished, it | 1115 page} or @dfn{man page}. In the GNU operating system, we hope to |
1108 is still useful to read manual pages. | 1116 replace man pages with better-organized manuals that you can browse |
1117 with Info (@pxref{Misc Help}). This process is not finished, so it is | |
1118 still useful to read manual pages. | |
1109 | 1119 |
1110 @findex manual-entry | 1120 @findex manual-entry |
1111 @cindex manual pages | 1121 You can read the man page for an operating system command, library |
1112 You can read the ``man page'' for an operating system command, | 1122 function, or system call, with the @kbd{M-x manual-entry} command. It |
1113 library function, or system call, with the @kbd{M-x manual-entry} | 1123 runs the @code{man} program to format the man page; if the system |
1114 command. It runs the @code{man} program to format the man page, and | 1124 permits, it runs @code{man} asynchronously, so that you can keep on |
1115 runs it asynchronously if your system permits, so that you can keep on | 1125 editing while the page is being formatted. (On MS-DOS and MS-Windows |
1116 editing while the page is being formatted. (MS-DOS and MS-Windows 3 | 1126 3, you cannot edit while Emacs waits for @code{man} to finish.) The |
1117 do not permit asynchronous subprocesses, so on these systems you | 1127 result goes in a buffer named @samp{*Man @var{topic}*}. These buffers |
1118 cannot edit while Emacs waits for @code{man} to finish.) The result | 1128 use a special major mode, Man mode, that facilitates scrolling and |
1119 goes in a buffer named @samp{*Man @var{topic}*}. These buffers use a | 1129 jumping to other manual pages. For details, type @kbd{C-h m} while in |
1120 special major mode, Man mode, that facilitates scrolling and jumping | 1130 a man page buffer. |
1121 to other manual pages. For details, type @kbd{C-h m} while in a man | |
1122 page buffer. | |
1123 | 1131 |
1124 @cindex sections of manual pages | 1132 @cindex sections of manual pages |
1125 Each man page belongs to one of around ten @dfn{sections}; sometimes | 1133 Each man page belongs to one of ten or more @dfn{sections}, each |
1126 there are multiple man pages with the same name in different sections. | 1134 named by a digit or by a digit and a letter. Sometimes there are |
1127 To read a man page from a specific section, type | 1135 multiple man pages with the same name in different sections. To read |
1136 a man page from a specific section, type | |
1128 @samp{@var{topic}(@var{section})} or @samp{@var{section} @var{topic}} | 1137 @samp{@var{topic}(@var{section})} or @samp{@var{section} @var{topic}} |
1129 when @kbd{M-x manual-entry} prompts for the topic. For example, to | 1138 when @kbd{M-x manual-entry} prompts for the topic. For example, to |
1130 read the man page for the C library function @code{chmod} (as opposed | 1139 read the man page for the C library function @code{chmod} (as opposed |
1131 to a command by the same name), type @kbd{M-x manual-entry @key{RET} | 1140 to a command of the same name), type @kbd{M-x manual-entry @key{RET} |
1132 chmod(2v) @key{RET}} (assuming @code{chmod} is in section @samp{2v}). | 1141 chmod(2) @key{RET}} (@code{chmod} is a system call, so it is in |
1142 section @samp{2}). | |
1133 | 1143 |
1134 @vindex Man-switches | 1144 @vindex Man-switches |
1135 If you do not specify a section, the results depend on how the | 1145 If you do not specify a section, the results depend on how the |
1136 @code{man} program works on your system. Some of them display only | 1146 @code{man} program works on your system. Some of them display only |
1137 the first man page they find. Others display all man pages that have | 1147 the first man page they find. Others display all man pages that have |
1141 the man pages for the specified topic. If you want this behavior, you | 1151 the man pages for the specified topic. If you want this behavior, you |
1142 can add this option to the value of the variable @code{Man-switches}.}. | 1152 can add this option to the value of the variable @code{Man-switches}.}. |
1143 The mode line shows how many manual pages are present in the Man buffer. | 1153 The mode line shows how many manual pages are present in the Man buffer. |
1144 | 1154 |
1145 @vindex Man-fontify-manpage-flag | 1155 @vindex Man-fontify-manpage-flag |
1146 By default, Emacs uses faces in man pages if Emacs can display | 1156 By default, Emacs highlights the text in man pages. For a long man |
1147 different fonts or colors. For a long man page, setting the faces | 1157 page, highlighting can take substantial time. You can turn off |
1148 properly can take substantial time. You can turn off use of faces in | 1158 highlighting of man pages by setting the variable |
1149 man pages by setting the variable @code{Man-fontify-manpage-flag} to | 1159 @code{Man-fontify-manpage-flag} to @code{nil}. |
1150 @code{nil}. | |
1151 | 1160 |
1152 @findex Man-fontify-manpage | 1161 @findex Man-fontify-manpage |
1153 If you insert the text of a man page into an Emacs buffer in some | 1162 If you insert the text of a man page into an Emacs buffer in some |
1154 other fashion, you can use the command @kbd{M-x Man-fontify-manpage} to | 1163 other fashion, you can use the command @kbd{M-x Man-fontify-manpage} to |
1155 perform the same conversions that @kbd{M-x manual-entry} does. | 1164 perform the same conversions that @kbd{M-x manual-entry} does. |
1184 @vindex woman-manpath | 1193 @vindex woman-manpath |
1185 By default, @kbd{M-x woman} looks for manual pages in the | 1194 By default, @kbd{M-x woman} looks for manual pages in the |
1186 directories specified in the @code{MANPATH} environment variable. (If | 1195 directories specified in the @code{MANPATH} environment variable. (If |
1187 @code{MANPATH} is not set, @code{woman} uses a suitable default value, | 1196 @code{MANPATH} is not set, @code{woman} uses a suitable default value, |
1188 which can be customized.) More precisely, @code{woman} looks for | 1197 which can be customized.) More precisely, @code{woman} looks for |
1189 subdirectories that match the shell wildcard @file{man*} in each one | 1198 subdirectories that match the shell wildcard pattern @file{man*} in each one |
1190 of these directories, and tries to find the manual pages in those | 1199 of these directories, and tries to find the manual pages in those |
1191 subdirectories. When first invoked, @kbd{M-x woman} converts the | 1200 subdirectories. When first invoked, @kbd{M-x woman} converts the |
1192 value of @code{MANPATH} to a list of directory names and stores that | 1201 value of @code{MANPATH} to a list of directory names and stores that |
1193 list in the @code{woman-manpath} variable. Changing the value of this | 1202 list in the @code{woman-manpath} variable. Changing the value of this |
1194 variable is another way to control the list of directories used. | 1203 variable is another way to control the list of directories used. |
1314 @item nil | 1323 @item nil |
1315 Open neither blocks nor comments. | 1324 Open neither blocks nor comments. |
1316 @end table | 1325 @end table |
1317 | 1326 |
1318 @item hs-special-modes-alist | 1327 @item hs-special-modes-alist |
1319 A list of elements, each Specifying how to initialize Hideshow | 1328 A list of elements, each specifying how to initialize Hideshow |
1320 variables for one major mode. See the variable's documentation string | 1329 variables for one major mode. See the variable's documentation string |
1321 for more information. | 1330 for more information. |
1322 @end table | 1331 @end table |
1323 | 1332 |
1324 @node Symbol Completion | 1333 @node Symbol Completion |
1325 @section Completion for Symbol Names | 1334 @section Completion for Symbol Names |
1326 @cindex completion (symbol names) | 1335 @cindex completion (symbol names) |
1327 | 1336 |
1328 Usually completion happens in the minibuffer. But one kind of completion | 1337 In Emacs, completion is something you normally do in the minibuffer. |
1329 is available in all buffers: completion for symbol names. | 1338 But one kind of completion is available in all buffers: completion for |
1339 symbol names. | |
1330 | 1340 |
1331 @kindex M-TAB | 1341 @kindex M-TAB |
1332 The character @kbd{M-@key{TAB}} runs a command to complete the partial | 1342 The character @kbd{M-@key{TAB}} runs a command to complete the |
1333 symbol before point against the set of meaningful symbol names. Any | 1343 partial symbol before point against the set of meaningful symbol |
1334 additional characters determined by the partial name are inserted at | 1344 names. This command inserts at point any additional characters that |
1335 point. | 1345 it can determine from the partial name. |
1336 | 1346 |
1337 If the partial name in the buffer has more than one possible completion | 1347 If the partial name in the buffer has multiple possible completions |
1338 and they have no additional characters in common, a list of all possible | 1348 that differ in the very next character, so that it is impossible to |
1339 completions is displayed in another window. | 1349 complete even one more character, @kbd{M-@key{TAB}} displays a list of |
1350 all possible completions in another window. | |
1340 | 1351 |
1341 @cindex tags-based completion | 1352 @cindex tags-based completion |
1342 @cindex Info index completion | 1353 @cindex Info index completion |
1343 @findex complete-symbol | 1354 @findex complete-symbol |
1344 In most programming language major modes, @kbd{M-@key{TAB}} runs the | 1355 In most programming language major modes, @kbd{M-@key{TAB}} runs the |
1371 @cindex identifiers, making long ones readable | 1382 @cindex identifiers, making long ones readable |
1372 @cindex StudlyCaps, making them readable | 1383 @cindex StudlyCaps, making them readable |
1373 @findex glasses-mode | 1384 @findex glasses-mode |
1374 | 1385 |
1375 Glasses minor mode makes @samp{unreadableIdentifiersLikeThis} | 1386 Glasses minor mode makes @samp{unreadableIdentifiersLikeThis} |
1376 readable by altering the display. It knows two different ways to do | 1387 readable by altering the way they display. It knows two different |
1377 this: by displaying underscores between a lower-case letter and the | 1388 ways to do this: by displaying underscores between a lower-case letter |
1378 following capital letter, or by emboldening the capital letters. It | 1389 and the following capital letter, and by emboldening the capital |
1379 does not alter the buffer text, only the way they display, so you can | 1390 letters. It does not alter the buffer text, only the way they |
1380 use it even on read-only buffers. You can use the command @kbd{M-x | 1391 display, so you can use it even on read-only buffers. You can use the |
1381 glasses-mode} to enable or disable the mode; you can also add | 1392 command @kbd{M-x glasses-mode} to enable or disable the mode in the |
1382 @code{glasses-mode} to the mode hook of appropriate programming | 1393 current buffer; you can also add @code{glasses-mode} to the mode hook |
1383 language major modes. | 1394 of the programming language major modes in which you normally want |
1395 to use Glasses mode. | |
1384 | 1396 |
1385 @node Misc for Programs | 1397 @node Misc for Programs |
1386 @section Other Features Useful for Editing Programs | 1398 @section Other Features Useful for Editing Programs |
1387 | 1399 |
1388 A number of Emacs commands that aren't designed specifically for | 1400 A number of Emacs commands that aren't designed specifically for |
1389 editing programs are useful for it nonetheless. | 1401 editing programs are useful for that nonetheless. |
1390 | 1402 |
1391 The Emacs commands that operate on words, sentences and paragraphs | 1403 The Emacs commands that operate on words, sentences and paragraphs |
1392 are useful for editing code. Most symbols names contain words | 1404 are useful for editing code. Most symbols names contain words |
1393 (@pxref{Words}); sentences can be found in strings and comments | 1405 (@pxref{Words}); sentences can be found in strings and comments |
1394 (@pxref{Sentences}). Paragraphs in the strict sense may be found in | 1406 (@pxref{Sentences}). Paragraphs in the strict sense can be found in |
1395 program code (in long comments), but the paragraph commands are useful | 1407 program code (in long comments), but the paragraph commands are useful |
1396 in other places too, because programming language major modes define | 1408 in other places too, because programming language major modes define |
1397 paragraphs to begin and end at blank lines (@pxref{Paragraphs}). | 1409 paragraphs to begin and end at blank lines (@pxref{Paragraphs}). |
1398 Judicious use of blank lines to make the program clearer will also | 1410 Judicious use of blank lines to make the program clearer will also |
1399 provide useful chunks of text for the paragraph commands to work on. | 1411 provide useful chunks of text for the paragraph commands to work on. |