Mercurial > hg > xemacs-beta
comparison man/xemacs/programs.texi @ 2522:52dc9b940348
[xemacs-hg @ 2005-01-28 00:12:32 by ben]
cc-mode patch from Shyamal Prasad
xemacs/programs.texi: Updated it to reflect
current status of programming modes.
xemacs/programs.texi: New section introduces CC
Mode. Introduces customization with reference to CC Mode
manual. Also introduce C/AWK modes in prog-modes package
xemacs/programs.texi: Removed - it was
obsolete. prog-modes package documentation now contains
indentation description for old C mode
xemacs/major.texi: Add description of major mode
hooks. Cleaned up and updated programming mode descriptions.
xemacs/xemacs.texi: Updated Detailed Node listing for new
CC Mode section in programs.texi
author | ben |
---|---|
date | Fri, 28 Jan 2005 00:12:39 +0000 |
parents | 1df7a5cfb04a |
children | 6b0000935adc |
comparison
equal
deleted
inserted
replaced
2521:67a2797862bc | 2522:52dc9b940348 |
---|---|
1 | 1 |
2 @node Programs, Running, Text, Top | 2 @node Programs, Running, Text, Top |
3 @chapter Editing Programs | 3 @chapter Editing Programs |
4 @cindex Programming Languages | |
4 @cindex Lisp | 5 @cindex Lisp |
5 @cindex C | 6 |
6 | 7 XEmacs provides specialized support for editing source files for many |
7 Emacs has many commands designed to understand the syntax of programming | 8 different programming languages. For example it is possible to |
8 languages such as Lisp and C. These commands can: | |
9 | 9 |
10 @itemize @bullet | 10 @itemize @bullet |
11 @item | |
12 Follow the usual indentation conventions of the language | |
13 (@pxref{Grinding}). | |
11 @item | 14 @item |
12 Move over or kill balanced expressions or @dfn{sexps} (@pxref{Lists}). | 15 Move over or kill balanced expressions or @dfn{sexps} (@pxref{Lists}). |
13 @item | 16 @item |
14 Move over or mark top-level balanced expressions (@dfn{defuns}, in Lisp; | 17 Move over or mark top-level balanced expressions (@dfn{defuns}, in Lisp; |
15 functions, in C). | 18 functions, in C). |
16 @item | 19 @item |
17 Show how parentheses balance (@pxref{Matching}). | 20 Show how parentheses balance (@pxref{Matching}). |
18 @item | 21 @item |
19 Insert, kill, or align comments (@pxref{Comments}). | 22 Insert, kill, or align comments (@pxref{Comments}). |
20 @item | 23 @item |
21 Follow the usual indentation conventions of the language | 24 Find functions and symbols in program by name (@pxref{Tags}). |
22 (@pxref{Grinding}). | |
23 @end itemize | 25 @end itemize |
24 | 26 |
25 The commands available for words, sentences, and paragraphs are useful in | 27 The commands available for words, sentences, and paragraphs are useful in |
26 editing code even though their canonical application is for editing human | 28 editing code even though their canonical application is for editing human |
27 language text. Most symbols contain words (@pxref{Words}); sentences can | 29 language text. Most symbols contain words (@pxref{Words}); sentences can |
50 * Lisp Completion:: Completion on symbol names in Lisp code. | 52 * Lisp Completion:: Completion on symbol names in Lisp code. |
51 * Documentation:: Getting documentation of functions you plan to call. | 53 * Documentation:: Getting documentation of functions you plan to call. |
52 * Change Log:: Maintaining a change history for your program. | 54 * Change Log:: Maintaining a change history for your program. |
53 * Tags:: Go direct to any function in your program in one | 55 * Tags:: Go direct to any function in your program in one |
54 command. Tags remembers which file it is in. | 56 command. Tags remembers which file it is in. |
57 * CC Mode:: Modes for C, C++, Java and similar languages | |
55 * Fortran:: Fortran mode and its special features. | 58 * Fortran:: Fortran mode and its special features. |
56 * Asm Mode:: Asm mode and its special features. | 59 * Asm Mode:: Asm mode and its special features. |
57 @end menu | 60 @end menu |
58 | 61 |
59 @node Program Modes, Lists, Programs, Programs | 62 @node Program Modes, Lists, Programs, Programs |
60 @section Major Modes for Programming Languages | 63 @section Major Modes for Programming Languages |
61 | 64 |
62 @cindex Lisp mode | 65 @cindex Lisp mode |
63 @cindex C mode | 66 Emacs has several major modes (@pxref{Major Modes}) to support |
64 @cindex Scheme mode | 67 programming languages. These major modes will typically understand |
65 Emacs has several major modes for the programming languages Lisp, Scheme (a | 68 language syntax, provide automatic indentation features, syntax based |
66 variant of Lisp), C, Fortran, and Muddle. Ideally, a major mode should be | 69 highlighting of text, and will often provide interfaces to the |
67 implemented for each programming language you might want to edit with | 70 programming environment to assist in compiling, executing and debugging |
68 Emacs; but often the mode for one language can serve for other | 71 programs. |
69 syntactically similar languages. The language modes that exist are those | 72 |
70 that someone decided to take the trouble to write. | 73 A language mode exist when someone decides to take the trouble to |
71 | 74 write it. At this time many widely used programming languages are |
72 There are several variants of Lisp mode, which differ in the way they | 75 supported by XEmacs. Examples include Ada, Awk, C, C++, CORBA (IDL), |
73 interface to Lisp execution. @xref{Lisp Modes}. | 76 Fortran, Java, Lisp, Modula 2, Objective-C, Perl, Pike, Prolog, Python, |
74 | 77 Ruby, Scheme, Simula, SQL, Tcl, Unix Shell scripts, and VHDL. Some of |
75 Each of the programming language modes defines the @key{TAB} key to run | 78 these language have seperate manuals, and some times more than one mode |
76 an indentation function that knows the indentation conventions of that | 79 may be available for a language. For example, there are several |
77 language and updates the current line's indentation accordingly. For | 80 variants of Lisp mode, which differ in the way they interface to Lisp |
78 example, in C mode @key{TAB} is bound to @code{c-indent-line}. @key{LFD} | 81 execution. @xref{Lisp Modes}. |
79 is normally defined to do @key{RET} followed by @key{TAB}; thus it, too, | 82 |
80 indents in a mode-specific fashion. | 83 Major modes for programming language support are distributed in |
84 optional XEmacs packages (@pxref{Packages}) that must be installed | |
85 before use. A notable exception to this rule is that a Lisp Mode is | |
86 integral to XEmacs. The Programming Mode Package (@file{prog-modes}) | |
87 contains many such modes. Some languages are supported by packages of | |
88 their own; prominent examples of such packages include @file{cc-mode} | |
89 for C, C++, Java, Objective C etc.@:, @file{python-modes} for Python, | |
90 and @file{scheme} for Scheme. | |
91 | |
92 For a language named @var{lang} the major mode for the language will | |
93 typically be named @code{@var{lang}-mode}. For example, the mode for C | |
94 is called @code{c-mode}, that for Bourne shell scripts is called | |
95 @code{sh-mode} and so on. These modes will invoke the functions listed | |
96 in the corresponding hook variables as a last step. @xref{Mode Hooks}. | |
97 | |
98 A mode can be invoked by typing @kbd{M-x @var{lang}-mode | |
99 @key{RET}}. However this step is not normally required. If the package | |
100 for a language mode is installed XEmacs usually knows when to | |
101 automatically invoke the mode. This is normally done based on examining | |
102 the file name to determine the language. @ref{Choosing Modes}. | |
103 | |
104 Each of the programming language modes defines the @key{TAB} key to | |
105 run an indentation function that knows the indentation conventions of | |
106 that language and updates the current line's indentation accordingly. | |
107 @key{LFD} is normally defined to do @key{RET} followed by @key{TAB}; | |
108 thus it, too, indents in a mode-specific fashion. | |
81 | 109 |
82 @kindex DEL | 110 @kindex DEL |
83 @findex backward-delete-char-untabify | 111 @findex backward-delete-char-untabify |
84 In most programming languages, indentation is likely to vary from line to | 112 In most programming languages, indentation is likely to vary from line to |
85 line. So the major modes for those languages rebind @key{DEL} to treat a | 113 line. So the major modes for those languages rebind @key{DEL} to treat a |
91 | 119 |
92 Programming language modes define paragraphs to be separated only by | 120 Programming language modes define paragraphs to be separated only by |
93 blank lines, so that the paragraph commands remain useful. Auto Fill mode, | 121 blank lines, so that the paragraph commands remain useful. Auto Fill mode, |
94 if enabled in a programming language major mode, indents the new lines | 122 if enabled in a programming language major mode, indents the new lines |
95 which it creates. | 123 which it creates. |
96 | |
97 @cindex mode hook | |
98 @vindex c-mode-hook | |
99 @vindex lisp-mode-hook | |
100 @vindex emacs-lisp-mode-hook | |
101 @vindex lisp-interaction-mode-hook | |
102 @vindex scheme-mode-hook | |
103 @vindex muddle-mode-hook | |
104 Turning on a major mode calls a user-supplied function called the | |
105 @dfn{mode hook}, which is the value of a Lisp variable. For example, | |
106 turning on C mode calls the value of the variable @code{c-mode-hook} if | |
107 that value exists and is non-@code{nil}. Mode hook variables for other | |
108 programming language modes include @code{lisp-mode-hook}, | |
109 @code{emacs-lisp-mode-hook}, @code{lisp-interaction-mode-hook}, | |
110 @code{scheme-mode-hook}, and @code{muddle-mode-hook}. The mode hook | |
111 function receives no arguments.@refill | |
112 | 124 |
113 @node Lists, Defuns, Program Modes, Programs | 125 @node Lists, Defuns, Program Modes, Programs |
114 @section Lists and Sexps | 126 @section Lists and Sexps |
115 | 127 |
116 @cindex Control-Meta | 128 @cindex Control-Meta |
196 | 208 |
197 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the | 209 @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the |
198 specified number of times; with a negative argument, it moves in the | 210 specified number of times; with a negative argument, it moves in the |
199 opposite direction. | 211 opposite direction. |
200 | 212 |
201 In languages such as C where the comment-terminator can be recognized, | |
202 the sexp commands move across comments as if they were whitespace. In | |
203 Lisp and other languages where comments run until the end of a line, it | |
204 is very difficult to ignore comments when parsing backwards; therefore, | |
205 in such languages the sexp commands treat the text of comments as if it | |
206 were code. | |
207 | |
208 @kindex C-M-k | 213 @kindex C-M-k |
209 @findex kill-sexp | 214 @findex kill-sexp |
210 Killing an sexp at a time can be done with @kbd{C-M-k} (@code{kill-sexp}). | 215 Killing an sexp at a time can be done with @kbd{C-M-k} (@code{kill-sexp}). |
211 @kbd{C-M-k} kills the characters that @kbd{C-M-f} would move over. | 216 @kbd{C-M-k} kills the characters that @kbd{C-M-f} would move over. |
212 | 217 |
336 | 341 |
337 @menu | 342 @menu |
338 * Basic Indent:: | 343 * Basic Indent:: |
339 * Multi-line Indent:: Commands to reindent many lines at once. | 344 * Multi-line Indent:: Commands to reindent many lines at once. |
340 * Lisp Indent:: Specifying how each Lisp function should be indented. | 345 * Lisp Indent:: Specifying how each Lisp function should be indented. |
341 * C Indent:: Choosing an indentation style for C code. | |
342 @end menu | 346 @end menu |
343 | 347 |
344 @node Basic Indent, Multi-line Indent, Grinding, Grinding | 348 @node Basic Indent, Multi-line Indent, Grinding, Grinding |
345 @subsection Basic Program Indentation Commands | 349 @subsection Basic Program Indentation Commands |
346 | 350 |
432 @findex indent-region | 436 @findex indent-region |
433 Another way to specify a range to be re-indented is with point and | 437 Another way to specify a range to be re-indented is with point and |
434 mark. The command @kbd{C-M-\} (@code{indent-region}) applies @key{TAB} | 438 mark. The command @kbd{C-M-\} (@code{indent-region}) applies @key{TAB} |
435 to every line whose first character is between point and mark. | 439 to every line whose first character is between point and mark. |
436 | 440 |
437 @node Lisp Indent, C Indent, Multi-line Indent, Grinding | 441 @node Lisp Indent, , Multi-line Indent, Grinding |
438 @subsection Customizing Lisp Indentation | 442 @subsection Customizing Lisp Indentation |
439 @cindex customization | 443 @cindex customization |
440 | 444 |
441 The indentation pattern for a Lisp expression can depend on the function | 445 The indentation pattern for a Lisp expression can depend on the function |
442 called by the expression. For each Lisp function, you can choose among | 446 called by the expression. For each Lisp function, you can choose among |
506 indentation is computed by @kbd{C-M-q}; if the value is a number, | 510 indentation is computed by @kbd{C-M-q}; if the value is a number, |
507 @kbd{C-M-q} need not recalculate indentation for the following lines | 511 @kbd{C-M-q} need not recalculate indentation for the following lines |
508 until the end of the list. | 512 until the end of the list. |
509 @end table | 513 @end table |
510 | 514 |
511 @node C Indent, , Lisp Indent, Grinding | |
512 @subsection Customizing C Indentation | |
513 | |
514 Two variables control which commands perform C indentation and when. | |
515 | |
516 @vindex c-auto-newline | |
517 If @code{c-auto-newline} is non-@code{nil}, newlines are inserted both | |
518 before and after braces that you insert and after colons and semicolons. | |
519 Correct C indentation is done on all the lines that are made this way. | |
520 | |
521 @vindex c-tab-always-indent | |
522 If @code{c-tab-always-indent} is non-@code{nil}, the @key{TAB} command | |
523 in C mode does indentation only if point is at the left margin or within | |
524 the line's indentation. If there is non-whitespace to the left of point, | |
525 @key{TAB} just inserts a tab character in the buffer. Normally, | |
526 this variable is @code{nil}, and @key{TAB} always reindents the current line. | |
527 | |
528 C does not have anything analogous to particular function names for which | |
529 special forms of indentation are desirable. However, it has a different | |
530 need for customization facilities: many different styles of C indentation | |
531 are in common use. | |
532 | |
533 There are six variables you can set to control the style that Emacs C | |
534 mode will use. | |
535 | |
536 @table @code | |
537 @item c-indent-level | |
538 Indentation of C statements within surrounding block. The surrounding | |
539 block's indentation is the indentation of the line on which the | |
540 open-brace appears. | |
541 @item c-continued-statement-offset | |
542 Extra indentation given to a substatement, such as the then-clause of | |
543 an @code{if} or body of a @code{while}. | |
544 @item c-brace-offset | |
545 Extra indentation for lines that start with an open brace. | |
546 @item c-brace-imaginary-offset | |
547 An open brace following other text is treated as if it were this far | |
548 to the right of the start of its line. | |
549 @item c-argdecl-indent | |
550 Indentation level of declarations of C function arguments. | |
551 @item c-label-offset | |
552 Extra indentation for a line that is a label, case, or default. | |
553 @end table | |
554 | |
555 @vindex c-indent-level | |
556 The variable @code{c-indent-level} controls the indentation for C | |
557 statements with respect to the surrounding block. In the example: | |
558 | |
559 @example | |
560 @{ | |
561 foo (); | |
562 @end example | |
563 | |
564 @noindent | |
565 the difference in indentation between the lines is @code{c-indent-level}. | |
566 Its standard value is 2. | |
567 | |
568 If the open-brace beginning the compound statement is not at the beginning | |
569 of its line, the @code{c-indent-level} is added to the indentation of the | |
570 line, not the column of the open-brace. For example, | |
571 | |
572 @example | |
573 if (losing) @{ | |
574 do_this (); | |
575 @end example | |
576 | |
577 @noindent | |
578 One popular indentation style is that which results from setting | |
579 @code{c-indent-level} to 8 and putting open-braces at the end of a line | |
580 in this way. Another popular style prefers to put the open-brace on a | |
581 separate line. | |
582 | |
583 @vindex c-brace-imaginary-offset | |
584 In fact, the value of the variable @code{c-brace-imaginary-offset} is | |
585 also added to the indentation of such a statement. Normally this variable | |
586 is zero. Think of this variable as the imaginary position of the open | |
587 brace, relative to the first non-blank character on the line. By setting | |
588 the variable to 4 and @code{c-indent-level} to 0, you can get this style: | |
589 | |
590 @example | |
591 if (x == y) @{ | |
592 do_it (); | |
593 @} | |
594 @end example | |
595 | |
596 When @code{c-indent-level} is zero, the statements inside most braces | |
597 line up exactly under the open brace. An exception are braces in column | |
598 zero, like those surrounding a function's body. The statements inside | |
599 those braces are not placed at column zero. Instead, | |
600 @code{c-brace-offset} and @code{c-continued-statement-offset} (see | |
601 below) are added to produce a typical offset between brace levels, and | |
602 the statements are indented that far. | |
603 | |
604 @vindex c-continued-statement-offset | |
605 @code{c-continued-statement-offset} controls the extra indentation for | |
606 a line that starts within a statement (but not within parentheses or | |
607 brackets). These lines are usually statements inside other statements, | |
608 like the then-clauses of @code{if} statements and the bodies of | |
609 @code{while} statements. The @code{c-continued-statement-offset} | |
610 parameter determines the difference in indentation between the two lines in: | |
611 | |
612 @example | |
613 if (x == y) | |
614 do_it (); | |
615 @end example | |
616 | |
617 @noindent | |
618 The default value for @code{c-continued-statement-offset} is 2. Some | |
619 popular indentation styles correspond to a value of zero for | |
620 @code{c-continued-statement-offset}. | |
621 | |
622 @vindex c-brace-offset | |
623 @code{c-brace-offset} is the extra indentation given to a line that | |
624 starts with an open-brace. Its standard value is zero; | |
625 compare: | |
626 | |
627 @example | |
628 if (x == y) | |
629 @{ | |
630 @end example | |
631 | |
632 @noindent | |
633 with: | |
634 | |
635 @example | |
636 if (x == y) | |
637 do_it (); | |
638 @end example | |
639 | |
640 @noindent | |
641 If you set @code{c-brace-offset} to 4, the first example becomes: | |
642 | |
643 @example | |
644 if (x == y) | |
645 @{ | |
646 @end example | |
647 | |
648 @vindex c-argdecl-indent | |
649 @code{c-argdecl-indent} controls the indentation of declarations of the | |
650 arguments of a C function. It is absolute: argument declarations receive | |
651 exactly @code{c-argdecl-indent} spaces. The standard value is 5 and | |
652 results in code like this: | |
653 | |
654 @example | |
655 char * | |
656 index (string, char) | |
657 char *string; | |
658 int char; | |
659 @end example | |
660 | |
661 @vindex c-label-offset | |
662 @code{c-label-offset} is the extra indentation given to a line that | |
663 contains a label, a case statement, or a @code{default:} statement. Its | |
664 standard value is @minus{}2 and results in code like this: | |
665 | |
666 @example | |
667 switch (c) | |
668 @{ | |
669 case 'x': | |
670 @end example | |
671 | |
672 @noindent | |
673 If @code{c-label-offset} were zero, the same code would be indented as: | |
674 | |
675 @example | |
676 switch (c) | |
677 @{ | |
678 case 'x': | |
679 @end example | |
680 | |
681 @noindent | |
682 This example assumes that the other variables above also have their | |
683 default values. | |
684 | |
685 Using the indentation style produced by the default settings of the | |
686 variables just discussed and putting open braces on separate lines | |
687 produces clear and readable files. For an example, look at any of the C | |
688 source files of XEmacs. | |
689 | 515 |
690 @node Matching, Comments, Grinding, Programs | 516 @node Matching, Comments, Grinding, Programs |
691 @section Automatic Display of Matching Parentheses | 517 @section Automatic Display of Matching Parentheses |
692 @cindex matching parentheses | 518 @cindex matching parentheses |
693 @cindex parentheses | 519 @cindex parentheses |
1001 permanently. If display_text_line sets point position wrong | 827 permanently. If display_text_line sets point position wrong |
1002 (case where line is killed, point is at eob and that line is | 828 (case where line is killed, point is at eob and that line is |
1003 not displayed), set it again in final compute_motion. | 829 not displayed), set it again in final compute_motion. |
1004 @end smallexample | 830 @end smallexample |
1005 | 831 |
1006 @node Tags, Fortran, Change Log, Programs | 832 @node Tags, CC Mode, Change Log, Programs |
1007 @section Tags Tables | 833 @section Tags Tables |
1008 @cindex tags table | 834 @cindex tags table |
1009 | 835 |
1010 A @dfn{tags table} is a description of how a multi-file program is | 836 A @dfn{tags table} is a description of how a multi-file program is |
1011 broken up into files. It lists the names of the component files and the | 837 broken up into files. It lists the names of the component files and the |
1708 @findex tags-apropos | 1534 @findex tags-apropos |
1709 @kbd{M-x tags-apropos} is like @code{apropos} for tags. It reads a regexp, | 1535 @kbd{M-x tags-apropos} is like @code{apropos} for tags. It reads a regexp, |
1710 then finds all the tags in the selected tags table whose entries match that | 1536 then finds all the tags in the selected tags table whose entries match that |
1711 regexp, and displays the tag names found. | 1537 regexp, and displays the tag names found. |
1712 | 1538 |
1713 @node Fortran, Asm Mode, Tags, Programs | 1539 @node CC Mode, Fortran, Tags, Programs |
1540 @section Modes for C, C++, Java and similar languages | |
1541 @cindex C Mode | |
1542 @cindex C++ Mode | |
1543 @cindex Java Mode | |
1544 @cindex AWK Mode | |
1545 @cindex Objective C Mode | |
1546 @cindex CORBA IDL Mode | |
1547 @findex c-mode | |
1548 @findex c++-mode | |
1549 @findex java-mode | |
1550 @findex idl-mode | |
1551 @findex awk-mode | |
1552 @findex pike-mode | |
1553 @findex objc-mode | |
1554 @vindex c-mode-hook | |
1555 @vindex c++-mode-hook | |
1556 @vindex java-mode-hook | |
1557 @vindex idl-mode-hook | |
1558 @vindex awk-mode-hook | |
1559 @vindex pike-mode-hook | |
1560 @vindex objc-mode-hook | |
1561 @vindex c-mode-common-hook | |
1562 @vindex c-initialization-hook | |
1563 | |
1564 The recommended means for supporting the ``C--like'' programming | |
1565 languages in XEmacs is the @file{cc-mode} package. CC Mode is not | |
1566 included in the basic XEmacs distribution but is available as an | |
1567 optional package. If loading a file whose names ends in the @file{.cc} | |
1568 extension does not automatically invoke a C++ Mode then the | |
1569 @file{cc-mode} package is probably not yet installed. @xref{Packages}. | |
1570 | |
1571 CC Mode provides modes for editing source files in Awk | |
1572 (@code{awk-mode}), C (@code{c-mode}), C++ (@code{c++-mode}), CORBA IDL | |
1573 (@code{idl-mode}), Java (@code{java-mode}), Objective C | |
1574 (@code{objc-mode}), and Pike (@code{pike-mode}). All these languages are | |
1575 supported with an sophisticated ``indentation engine'' that is feature | |
1576 rich, customizable and quite efficient. | |
1577 | |
1578 Each language major mode runs hooks in the conventionally named hook | |
1579 variables (@pxref{Mode Hooks}). In addition to this conventional | |
1580 behavior all the CC Mode major modes will also run hooks in | |
1581 @code{c-mode-common-hook} @emph{before} invoking the major mode specific | |
1582 hook. | |
1583 | |
1584 CC Mode runs any hooks in @code{c-initialization-hook} exactly once | |
1585 when it is first loaded. | |
1586 | |
1587 CC Mode is a very comprehensive and flexible system and full | |
1588 description of its capabilities is beyond the scope of this manual. It | |
1589 is strongly recommended that the reader consult the CC Mode | |
1590 documentation for details once the package has been | |
1591 installed. @xref{Top,CC Mode,,cc-mode, The CC Mode Manual}. | |
1592 | |
1593 @menu | |
1594 * Older Modes:: Older Modes for C and AWK | |
1595 * Customizing CC Mode:: An Introduction to Customizing CC Mode. | |
1596 @end menu | |
1597 | |
1598 | |
1599 @node Older Modes, Customizing CC Mode, CC Mode, CC Mode | |
1600 @subsection Older Modes for C and AWK | |
1601 @cindex Old C Mode | |
1602 @cindex Old AWK Mode | |
1603 @cindex C Mode without CC Mode | |
1604 @cindex AWK Mode without CC Mode | |
1605 @cindex old-c-mode | |
1606 | |
1607 XEmacs provides older versions of a C Mode and an AWK Mode in the | |
1608 @file{prog-modes} package. These older modes do not share the | |
1609 indentation engine in CC Mode have have their own specific means of | |
1610 customizing indentation. To use these modes the @file{prog-modes} | |
1611 package must be installed. | |
1612 | |
1613 This older C mode is known simply as the ``Old C Mode''. It supports | |
1614 only the C language and it lacks many of the features of CC Mode. | |
1615 However the old C mode offers modest space requirements and very fast | |
1616 operation. Old C Mode might be useful in space constrained | |
1617 environments, on slow machines, or for editing very large files. This | |
1618 old C mode is available in the @file{old-c-mode} | |
1619 library. @xref{old-c-mode,Old C Mode,old-c-mode,prog-modes,The | |
1620 Programming Modes Package Manual}. | |
1621 | |
1622 The old AWK mode exists for similar reasons. It is available in the | |
1623 @file{awk-mode} library. @xref{awk-mode,Old AWK | |
1624 Mode,awk-mode,prog-modes,The Programming Modes Package Manual}. | |
1625 | |
1626 Note that the prog-modes package will never automatically invoke these | |
1627 older modes for a user. However installing the @file{cc-mode} package | |
1628 @emph{will} make CC Mode's versions available automatically. As a | |
1629 result a user who wants to use these older modes must explicitly load | |
1630 the old libraries to use them. | |
1631 | |
1632 @node Customizing CC Mode, , Older Modes, CC Mode | |
1633 @subsection Customizing Indentation in CC Mode | |
1634 | |
1635 A very brief introduction is included here on customizing CC Mode. CC | |
1636 Mode has many features, including useful minor modes, that are | |
1637 completely documented in its own manual. | |
1638 | |
1639 CC Mode implements several different ``styles'' for C code (and the | |
1640 other languages supported by CC Mode). If you need to change the | |
1641 indentation style for CC Mode it is recommended that you first see if an | |
1642 existing style meets your requirements. The style chosen will affect the | |
1643 placement of language elements like braces, function declarations and | |
1644 comments. You can choose a style interactively by typing @kbd{C-c .} and | |
1645 pressing the space bar at the prompt to get a list of supported | |
1646 styles. @kbd{C-c .} runs the function @code{c-set-style} which applies | |
1647 to all CC Mode language modes though its name might suggest otherwise. A | |
1648 few of the the supported styles are listed below. | |
1649 | |
1650 @itemize @bullet | |
1651 @item | |
1652 ``gnu'' --- The recommeded style from the Free Software Foundation for | |
1653 GNU software. | |
1654 @item | |
1655 ``k&r'' --- The classic style from Kernighan and Ritchie. | |
1656 @item | |
1657 ``linux'' --- The style recommended for code in the Linux kernel. | |
1658 @item | |
1659 ``bsd'' --- The style recommended for software developed in BSD. | |
1660 @item | |
1661 ``java --- The ``traditional'' Java style. | |
1662 @end itemize | |
1663 | |
1664 The default style in XEmacs is ``gnu'' except for Java mode where it | |
1665 is the ``java'' style (this is governed by the variable | |
1666 @code{c-default-style}). | |
1667 | |
1668 The styles included in CC Mode all use a buffer local variable called | |
1669 @code{c-basic-offset} as the basic indentation level (this buffer local | |
1670 variable is used in all CC Mode language modes though its name might | |
1671 suggest otherwise). All indentation is, by default, expressed in | |
1672 multiples of @code{c-basic-offset}. | |
1673 | |
1674 Each style defines a default value for @code{c-basic-offset}, for the | |
1675 ``gnu'' style sets it to 2. A very common customization scenario is | |
1676 where a user wants to use an existing style but with a different basic | |
1677 offset value. An easy way to do this is to set @code{c-basic-offset} in | |
1678 the language mode hook after selecting the chosen style. | |
1679 | |
1680 For example, a user might want to follow a local coding convention of | |
1681 using the ``k&r'' style for C code with indentation in two columns | |
1682 multiples (instead of the five column default provided by the CC Mode | |
1683 ``k&r'' style). This can be achieved with the following code in the | |
1684 initialization file (@pxref{Init File}) | |
1685 | |
1686 @example | |
1687 (defun my-c-mode-hook () | |
1688 (c-set-style "k&r") | |
1689 (setq c-basic-offset 2)) | |
1690 (add-hook 'c-mode-hook 'my-c-mode-hook) | |
1691 @end example | |
1692 | |
1693 Most customizations for indentation in various CC modes can be | |
1694 accomplished by choosing a style and then choosing value for | |
1695 @code{c-basic-offset} that meets the local coding convention. CC Mode | |
1696 has a very customizable indentation engine and a furthur discussion is | |
1697 really beyond the scope of this manual. @xref{Indentation | |
1698 Engine,,,cc-mode,The CC Mode Manual}. | |
1699 | |
1700 | |
1701 @node Fortran, Asm Mode, CC Mode, Programs | |
1714 @section Fortran Mode | 1702 @section Fortran Mode |
1715 @cindex Fortran mode | 1703 @cindex Fortran mode |
1716 | 1704 |
1717 Fortran mode provides special motion commands for Fortran statements and | 1705 Fortran mode provides special motion commands for Fortran statements and |
1718 subprograms, and indentation commands that understand Fortran conventions | 1706 subprograms, and indentation commands that understand Fortran conventions |