diff options
| author | Karoly Lorentey | 2005-12-26 03:16:59 +0000 |
|---|---|---|
| committer | Karoly Lorentey | 2005-12-26 03:16:59 +0000 |
| commit | feba0cd6405ebb80af743e2f978442d9c837bcd2 (patch) | |
| tree | 1cb964aa641bee514d9cda2eafe27a0a97e65ad1 /man/programs.texi | |
| parent | 30663b475e57197c9896a252e1d4ca31c579fa2b (diff) | |
| parent | 7a32e81fb608282314e27db21a00138aaa91f29a (diff) | |
| download | emacs-feba0cd6405ebb80af743e2f978442d9c837bcd2.tar.gz emacs-feba0cd6405ebb80af743e2f978442d9c837bcd2.zip | |
Merged from miles@gnu.org--gnu-2005 (patch 677)
Patches applied:
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-677
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-463
Diffstat (limited to 'man/programs.texi')
| -rw-r--r-- | man/programs.texi | 396 |
1 files changed, 187 insertions, 209 deletions
diff --git a/man/programs.texi b/man/programs.texi index 6444a3a6a47..e1806488150 100644 --- a/man/programs.texi +++ b/man/programs.texi | |||
| @@ -128,17 +128,19 @@ place to set up customizations for that major mode. @xref{Hooks}. | |||
| 128 | @node Defuns | 128 | @node Defuns |
| 129 | @section Top-Level Definitions, or Defuns | 129 | @section Top-Level Definitions, or Defuns |
| 130 | 130 | ||
| 131 | In Emacs, a major definition at the top level in the buffer is | 131 | In Emacs, a major definition at the top level in the buffer, |
| 132 | called a @dfn{defun}. The name comes from Lisp, but in Emacs we use | 132 | something like a function, is called a @dfn{defun}. The name comes |
| 133 | it for all languages. | 133 | from Lisp, but in Emacs we use it for all languages. |
| 134 | 134 | ||
| 135 | In most programming language modes, Emacs assumes that a defun is | 135 | In many programming language modes, Emacs assumes that a defun is |
| 136 | any pair of parentheses (or braces, if the language uses braces this | 136 | any pair of parentheses (or braces, if the language uses braces this |
| 137 | way) that starts at the left margin. For example, in C, the body of a | 137 | way) that starts at the left margin. For example, in C, the body of a |
| 138 | function definition is normally a defun, because the open-brace that | 138 | function definition is a defun, usually recognized as an open-brace |
| 139 | begins it is normally at the left margin. A variable's initializer | 139 | that begins at the left margin@footnote{Alternatively, you can set up |
| 140 | can also count as a defun, if the open-brace that begins the | 140 | C Mode to recognize a defun at an opening brace at the outermost |
| 141 | initializer is at the left margin. | 141 | level. @xref{Movement Commands,,, ccmode, the CC Mode Manual}.}. A |
| 142 | variable's initializer can also count as a defun, if the open-brace | ||
| 143 | that begins the initializer is at the left margin. | ||
| 142 | 144 | ||
| 143 | However, some language modes provide their own code for recognizing | 145 | However, some language modes provide their own code for recognizing |
| 144 | defuns in a way that suits the language syntax and conventions better. | 146 | defuns in a way that suits the language syntax and conventions better. |
| @@ -156,14 +158,24 @@ defuns in a way that suits the language syntax and conventions better. | |||
| 156 | 158 | ||
| 157 | @cindex open-parenthesis in leftmost column | 159 | @cindex open-parenthesis in leftmost column |
| 158 | @cindex ( in leftmost column | 160 | @cindex ( in leftmost column |
| 159 | In most major modes, Emacs assumes that any opening delimiter found | 161 | Emacs assumes by default that any opening delimiter found at the |
| 160 | at the left margin is the start of a top-level definition, or defun. | 162 | left margin is the start of a top-level definition, or defun. You can |
| 161 | Therefore, @strong{never put an opening delimiter at the left margin | 163 | override this default by setting this user option: |
| 162 | unless it should have that significance.} For instance, never put an | 164 | |
| 165 | @defvar open-paren-in-column-0-is-defun-start | ||
| 166 | If this user option is set to @code{t} (the default), opening | ||
| 167 | parentheses or braces at column zero always start defuns. When it's | ||
| 168 | @code{nil}, defuns are found by searching for parens or braces at the | ||
| 169 | outermost level. Some major modes, including C and related modes, set | ||
| 170 | @code{open-paren-in-column-0-is-defun-start} buffer-locally to | ||
| 171 | @code{nil} | ||
| 172 | @end defvar | ||
| 173 | |||
| 174 | In modes where @code{open-paren-in-column-0-is-defun-start} is | ||
| 175 | @code{t}, @strong{don't put an opening delimiter at the left margin | ||
| 176 | unless it is a defun start}. For instance, never put an | ||
| 163 | open-parenthesis at the left margin in a Lisp file unless it is the | 177 | open-parenthesis at the left margin in a Lisp file unless it is the |
| 164 | start of a top-level list. Never put an open-brace or other opening | 178 | start of a top-level list. |
| 165 | delimiter at the beginning of a line of C code unless it is at top | ||
| 166 | level. | ||
| 167 | 179 | ||
| 168 | If you don't follow this convention, not only will you have trouble | 180 | If you don't follow this convention, not only will you have trouble |
| 169 | when you explicitly use the commands for motion by defuns; other | 181 | when you explicitly use the commands for motion by defuns; other |
| @@ -173,10 +185,10 @@ mode (@pxref{Font Lock}). | |||
| 173 | 185 | ||
| 174 | The most likely problem case is when you want an opening delimiter | 186 | The most likely problem case is when you want an opening delimiter |
| 175 | at the start of a line inside a string. To avoid trouble, put an | 187 | at the start of a line inside a string. To avoid trouble, put an |
| 176 | escape character (@samp{\}, in C and Emacs Lisp, @samp{/} in some | 188 | escape character (@samp{\}, in Emacs Lisp, @samp{/} in some other Lisp |
| 177 | other Lisp dialects) before the opening delimiter. This will not | 189 | dialects) before the opening delimiter. This will not affect the |
| 178 | affect the contents of the string, but will prevent that opening | 190 | contents of the string, but will prevent that opening delimiter from |
| 179 | delimiter from starting a defun. Here's an example: | 191 | starting a defun. Here's an example: |
| 180 | 192 | ||
| 181 | @example | 193 | @example |
| 182 | (insert "Foo: | 194 | (insert "Foo: |
| @@ -195,8 +207,9 @@ the beginning of the buffer, even for a small function. To speed up | |||
| 195 | the operation, we changed Emacs to assume that any opening delimiter | 207 | the operation, we changed Emacs to assume that any opening delimiter |
| 196 | at the left margin is the start of a defun. This heuristic is nearly | 208 | at the left margin is the start of a defun. This heuristic is nearly |
| 197 | always right, and avoids the need to scan back to the beginning of the | 209 | always right, and avoids the need to scan back to the beginning of the |
| 198 | buffer. However, it mandates following the convention described | 210 | buffer. However, now that modern computers are so powerful, this |
| 199 | above. | 211 | scanning is rarely slow enough to annoy, so we've provided a way to |
| 212 | disable the heuristic. | ||
| 200 | 213 | ||
| 201 | @node Moving by Defuns | 214 | @node Moving by Defuns |
| 202 | @subsection Moving by Defuns | 215 | @subsection Moving by Defuns |
| @@ -399,13 +412,14 @@ behavior is convenient in cases where you have overridden the standard | |||
| 399 | result of @key{TAB} because you find it unaesthetic for a particular | 412 | result of @key{TAB} because you find it unaesthetic for a particular |
| 400 | line. | 413 | line. |
| 401 | 414 | ||
| 402 | Remember that an open-parenthesis, open-brace or other opening delimiter | 415 | By default, an open-parenthesis, open-brace or other opening |
| 403 | at the left margin is assumed by Emacs (including the indentation routines) | 416 | delimiter at the left margin is assumed by Emacs (including the |
| 404 | to be the start of a function. Therefore, you must never have an opening | 417 | indentation routines) to be the start of a function. This speeds up |
| 405 | delimiter in column zero that is not the beginning of a function, not even | 418 | indentation commands. If you will be editing text which contains |
| 406 | inside a string. This restriction is vital for making the indentation | 419 | opening delimiters in column zero that aren't the beginning of a |
| 407 | commands fast; you must simply accept it. @xref{Left Margin Paren}, | 420 | functions, even inside strings or comments, you must set |
| 408 | for more information on this. | 421 | @code{open-paren-in-column-0-is-defun-start}. @xref{Left Margin |
| 422 | Paren}, for more information on this. | ||
| 409 | 423 | ||
| 410 | Normally, lines are indented with tabs and spaces. If you want Emacs | 424 | Normally, lines are indented with tabs and spaces. If you want Emacs |
| 411 | to use spaces only, see @ref{Just Spaces}. | 425 | to use spaces only, see @ref{Just Spaces}. |
| @@ -560,16 +574,16 @@ onto the indentation of the @dfn{anchor statement}. | |||
| 560 | Select a predefined style @var{style} (@code{c-set-style}). | 574 | Select a predefined style @var{style} (@code{c-set-style}). |
| 561 | @end table | 575 | @end table |
| 562 | 576 | ||
| 563 | A @dfn{style} is a named collection of customizations that can | 577 | A @dfn{style} is a named collection of customizations that can be |
| 564 | be used in C mode and the related modes. Emacs comes with several | 578 | used in C mode and the related modes. @ref{Styles,,, ccmode, The CC |
| 579 | Mode Manual}, for a complete description. Emacs comes with several | ||
| 565 | predefined styles, including @code{gnu}, @code{k&r}, @code{bsd}, | 580 | predefined styles, including @code{gnu}, @code{k&r}, @code{bsd}, |
| 566 | @code{stroustrup}, @code{linux}, @code{python}, @code{java}, | 581 | @code{stroustrup}, @code{linux}, @code{python}, @code{java}, |
| 567 | @code{whitesmith}, @code{ellemtel}, @code{cc-mode}, and @code{user}. | 582 | @code{whitesmith}, @code{ellemtel}, and @code{awk}. Some of these |
| 568 | Some of these styles are primarily intended for one language, but any | 583 | styles are primarily intended for one language, but any of them can be |
| 569 | of them can be used with any of the languages supported by these | 584 | used with any of the languages supported by these modes. To find out |
| 570 | modes. To find out what a style looks like, select it and reindent | 585 | what a style looks like, select it and reindent some code, e.g., by |
| 571 | some code, e.g., by typing @key{C-M-q} at the start of a function | 586 | typing @key{C-M-q} at the start of a function definition. |
| 572 | definition. | ||
| 573 | 587 | ||
| 574 | @kindex C-c . @r{(C mode)} | 588 | @kindex C-c . @r{(C mode)} |
| 575 | @findex c-set-style | 589 | @findex c-set-style |
| @@ -577,8 +591,8 @@ definition. | |||
| 577 | .}. Specify a style name as an argument (case is not significant). | 591 | .}. Specify a style name as an argument (case is not significant). |
| 578 | This command affects the current buffer only, and it affects only | 592 | This command affects the current buffer only, and it affects only |
| 579 | future invocations of the indentation commands; it does not reindent | 593 | future invocations of the indentation commands; it does not reindent |
| 580 | the code in the buffer. To reindent the whole buffer in the new | 594 | the code already in the buffer. To reindent the whole buffer in the |
| 581 | style, you can type @kbd{C-x h C-M-\}. | 595 | new style, you can type @kbd{C-x h C-M-\}. |
| 582 | 596 | ||
| 583 | @vindex c-default-style | 597 | @vindex c-default-style |
| 584 | You can also set the variable @code{c-default-style} to specify the | 598 | You can also set the variable @code{c-default-style} to specify the |
| @@ -589,23 +603,24 @@ example, | |||
| 589 | 603 | ||
| 590 | @example | 604 | @example |
| 591 | (setq c-default-style | 605 | (setq c-default-style |
| 592 | '((java-mode . "java") (other . "gnu"))) | 606 | '((java-mode . "java") (awk-mode . "awk") (other . "gnu"))) |
| 593 | @end example | 607 | @end example |
| 594 | 608 | ||
| 595 | @noindent | 609 | @noindent |
| 596 | specifies an explicit choice for Java mode, and the default @samp{gnu} | 610 | specifies explicit choices for Java and AWK modes, and the default |
| 597 | style for the other C-like modes. (These settings are actually the | 611 | @samp{gnu} style for the other C-like modes. (These settings are |
| 598 | defaults.) This variable takes effect when you select one of the | 612 | actually the defaults.) This variable takes effect when you select |
| 599 | C-like major modes; thus, if you specify a new default style for Java | 613 | one of the C-like major modes; thus, if you specify a new default |
| 600 | mode, you can make it take effect in an existing Java mode buffer by | 614 | style for Java mode, you can make it take effect in an existing Java |
| 601 | typing @kbd{M-x java-mode} there. | 615 | mode buffer by typing @kbd{M-x java-mode} there. |
| 602 | 616 | ||
| 603 | The @code{gnu} style specifies the formatting recommended by the GNU | 617 | The @code{gnu} style specifies the formatting recommended by the GNU |
| 604 | Project for C; it is the default, so as to encourage use of our | 618 | Project for C; it is the default, so as to encourage use of our |
| 605 | recommended style. | 619 | recommended style. |
| 606 | 620 | ||
| 607 | @xref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for | 621 | @xref{Indentation Engine Basics,,, ccmode, the CC Mode Manual}, and |
| 608 | more information on customizing indentation for C and related modes, | 622 | @ref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for more |
| 623 | information on customizing indentation for C and related modes, | ||
| 609 | including how to override parts of an existing style and how to define | 624 | including how to override parts of an existing style and how to define |
| 610 | your own styles. | 625 | your own styles. |
| 611 | 626 | ||
| @@ -708,11 +723,12 @@ would move over. | |||
| 708 | A somewhat random-sounding command which is nevertheless handy is | 723 | A somewhat random-sounding command which is nevertheless handy is |
| 709 | @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous | 724 | @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous |
| 710 | balanced expression across the next one. An argument serves as a | 725 | balanced expression across the next one. An argument serves as a |
| 711 | repeat count, and a negative argument drags the previous balanced | 726 | repeat count, moving the previous expression over that many following |
| 712 | expression backwards across those before it (thus canceling out the | 727 | ones. A negative argument drags the previous balanced expression |
| 713 | effect of @kbd{C-M-t} with a positive argument). An argument of zero, | 728 | backwards across those before it (thus canceling out the effect of |
| 714 | rather than doing nothing, transposes the balanced expressions ending | 729 | @kbd{C-M-t} with a positive argument). An argument of zero, rather |
| 715 | at or after point and the mark. | 730 | than doing nothing, transposes the balanced expressions ending at or |
| 731 | after point and the mark. | ||
| 716 | 732 | ||
| 717 | @kindex C-M-@@ | 733 | @kindex C-M-@@ |
| 718 | @kindex C-M-@key{SPC} | 734 | @kindex C-M-@key{SPC} |
| @@ -722,9 +738,9 @@ use @kbd{C-M-@@} (@code{mark-sexp}), which sets mark at the same place | |||
| 722 | that @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like | 738 | that @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like |
| 723 | @kbd{C-M-f}. In particular, a negative argument is useful for putting | 739 | @kbd{C-M-f}. In particular, a negative argument is useful for putting |
| 724 | the mark at the beginning of the previous balanced expression. The | 740 | the mark at the beginning of the previous balanced expression. The |
| 725 | alias @kbd{C-M-@key{SPC}} is equivalent to @kbd{C-M-@@}. If you use | 741 | alias @kbd{C-M-@key{SPC}} is equivalent to @kbd{C-M-@@}. When you |
| 726 | this command repeatedly, or in Transient Mark mode whenever the mark | 742 | repeat this command, or use it in Transient Mark mode when the mark is |
| 727 | is active, it extends the region by one sexp each time. | 743 | active, it extends the region by one sexp each time. |
| 728 | 744 | ||
| 729 | In languages that use infix operators, such as C, it is not possible | 745 | In languages that use infix operators, such as C, it is not possible |
| 730 | to recognize all balanced expressions as such because there can be | 746 | to recognize all balanced expressions as such because there can be |
| @@ -875,7 +891,7 @@ Set comment column (@code{comment-set-column}). | |||
| 875 | @item @kbd{C-M-j} | 891 | @item @kbd{C-M-j} |
| 876 | @itemx @kbd{M-j} | 892 | @itemx @kbd{M-j} |
| 877 | Like @key{RET} followed by inserting and aligning a comment | 893 | Like @key{RET} followed by inserting and aligning a comment |
| 878 | (@code{comment-indent-new-line}). | 894 | (@code{comment-indent-new-line}). @xref{Multi-Line Comments}. |
| 879 | @item @kbd{M-x comment-region} | 895 | @item @kbd{M-x comment-region} |
| 880 | @itemx @kbd{C-c C-c} (in C-like modes) | 896 | @itemx @kbd{C-c C-c} (in C-like modes) |
| 881 | Add or remove comment delimiters on all the lines in the region. | 897 | Add or remove comment delimiters on all the lines in the region. |
| @@ -948,8 +964,13 @@ and by not changing the indentation of a triple-semicolon comment at all. | |||
| 948 | (1+ x)) ; This line adds one. | 964 | (1+ x)) ; This line adds one. |
| 949 | @end example | 965 | @end example |
| 950 | 966 | ||
| 951 | In C code, a comment preceded on its line by nothing but whitespace | 967 | For C-like buffers, you can configure the exact effect of @kbd{M-;} |
| 952 | is indented like a line of code. | 968 | more flexibly than for most buffers by setting the user options |
| 969 | @code{c-indent-comment-alist} and | ||
| 970 | @code{c-indent-comments-syntactically-p}. For example, on a line | ||
| 971 | ending in a closing brace, @kbd{M-;} puts the comment one space after | ||
| 972 | the brace rather than at @code{comment-column}. For full details see | ||
| 973 | @ref{Comment Commands,,, ccmode, The CC Mode Manual}. | ||
| 953 | 974 | ||
| 954 | @node Multi-Line Comments | 975 | @node Multi-Line Comments |
| 955 | @subsection Multiple Lines of Comments | 976 | @subsection Multiple Lines of Comments |
| @@ -958,23 +979,23 @@ is indented like a line of code. | |||
| 958 | @kindex M-j | 979 | @kindex M-j |
| 959 | @cindex blank lines in programs | 980 | @cindex blank lines in programs |
| 960 | @findex comment-indent-new-line | 981 | @findex comment-indent-new-line |
| 982 | |||
| 961 | If you are typing a comment and wish to continue it on another line, | 983 | If you are typing a comment and wish to continue it on another line, |
| 962 | you can use the command @kbd{C-M-j} or @kbd{M-j} | 984 | you can use the command @kbd{C-M-j} or @kbd{M-j} |
| 963 | (@code{comment-indent-new-line}). This terminates the comment you are | 985 | (@code{comment-indent-new-line}). If @code{comment-multi-line} |
| 964 | typing, creates a new blank line afterward, and begins a new comment | 986 | (@pxref{Options for Comments}) is non-@code{nil}, it moves to a new |
| 965 | indented under the old one. When Auto Fill mode is on, going past the | 987 | line within the comment. Otherwise it closes the comment and starts a |
| 988 | new comment on a new line. When Auto Fill mode is on, going past the | ||
| 966 | fill column while typing a comment causes the comment to be continued | 989 | fill column while typing a comment causes the comment to be continued |
| 967 | in just this fashion. If point is not at the end of the line when you | 990 | in just this fashion. |
| 968 | type the command, the text on the rest of the line becomes part of the | ||
| 969 | new comment line. | ||
| 970 | 991 | ||
| 971 | @kindex C-c C-c (C mode) | 992 | @kindex C-c C-c (C mode) |
| 972 | @findex comment-region | 993 | @findex comment-region |
| 973 | To turn existing lines into comment lines, use the @kbd{M-x | 994 | To turn existing lines into comment lines, use the @kbd{M-x |
| 974 | comment-region} command. It adds comment delimiters to the lines that start | 995 | comment-region} command (or type @kbd{C-c C-c} in C-like buffers). It |
| 975 | in the region, thus commenting them out. With a negative argument, it | 996 | adds comment delimiters to the lines that start in the region, thus |
| 976 | does the opposite---it deletes comment delimiters from the lines in the | 997 | commenting them out. With a negative argument, it does the |
| 977 | region. | 998 | opposite---it deletes comment delimiters from the lines in the region. |
| 978 | 999 | ||
| 979 | With a positive argument, @code{comment-region} duplicates the last | 1000 | With a positive argument, @code{comment-region} duplicates the last |
| 980 | character of the comment start sequence it adds; the argument specifies | 1001 | character of the comment start sequence it adds; the argument specifies |
| @@ -985,6 +1006,11 @@ can also affect how the comment is indented. In Lisp, for proper | |||
| 985 | indentation, you should use an argument of two or three, if between defuns; | 1006 | indentation, you should use an argument of two or three, if between defuns; |
| 986 | if within a defun, it must be three. | 1007 | if within a defun, it must be three. |
| 987 | 1008 | ||
| 1009 | You can configure C Mode such that when you type a @samp{/} at the | ||
| 1010 | start of a line in a multi-line block comment, this closes the | ||
| 1011 | comment. Enable the @code{comment-close-slash} clean-up for this. | ||
| 1012 | @xref{Clean-ups,,, ccmode, The CC Mode Manual}. | ||
| 1013 | |||
| 988 | @node Options for Comments | 1014 | @node Options for Comments |
| 989 | @subsection Options Controlling Comments | 1015 | @subsection Options Controlling Comments |
| 990 | 1016 | ||
| @@ -1038,13 +1064,13 @@ can hold the actual string to insert. | |||
| 1038 | @vindex comment-multi-line | 1064 | @vindex comment-multi-line |
| 1039 | The variable @code{comment-multi-line} controls how @kbd{C-M-j} | 1065 | The variable @code{comment-multi-line} controls how @kbd{C-M-j} |
| 1040 | (@code{indent-new-comment-line}) behaves when used inside a comment. | 1066 | (@code{indent-new-comment-line}) behaves when used inside a comment. |
| 1041 | Specifically, when @code{comment-multi-line} is @code{nil} (the | 1067 | Specifically, when @code{comment-multi-line} is @code{nil}, the |
| 1042 | default value), the command inserts a comment terminator, begins a new | 1068 | command inserts a comment terminator, begins a new line, and finally |
| 1043 | line, and finally inserts a comment starter. Otherwise it does not | 1069 | inserts a comment starter. Otherwise it does not insert the |
| 1044 | insert the terminator and starter, so it effectively continues the | 1070 | terminator and starter, so it effectively continues the current |
| 1045 | current comment across multiple lines. In languages that allow | 1071 | comment across multiple lines. In languages that allow multi-line |
| 1046 | multi-line comments, the choice of value for this variable is a matter | 1072 | comments, the choice of value for this variable is a matter of taste. |
| 1047 | of taste. | 1073 | The default for this variable depends on the major mode. |
| 1048 | 1074 | ||
| 1049 | @vindex comment-indent-function | 1075 | @vindex comment-indent-function |
| 1050 | The variable @code{comment-indent-function} should contain a function | 1076 | The variable @code{comment-indent-function} should contain a function |
| @@ -1510,11 +1536,13 @@ Move point to the end of the innermost C statement or sentence; like | |||
| 1510 | 1536 | ||
| 1511 | @item M-x c-backward-into-nomenclature | 1537 | @item M-x c-backward-into-nomenclature |
| 1512 | @findex c-backward-into-nomenclature | 1538 | @findex c-backward-into-nomenclature |
| 1513 | Move point backward to beginning of a C++ nomenclature section or word. | 1539 | Move point backward to beginning of a C++ nomenclature section or |
| 1514 | With prefix argument @var{n}, move @var{n} times. If @var{n} is | 1540 | word. With prefix argument @var{n}, move @var{n} times. If @var{n} |
| 1515 | negative, move forward. C++ nomenclature means a symbol name in the | 1541 | is negative, move forward. C++ nomenclature means a symbol name in |
| 1516 | style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital letter | 1542 | the style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital |
| 1517 | begins a section or word. | 1543 | letter begins a section or word. Rather than this command, you might |
| 1544 | well prefer the newer ``Subword Mode'', which does the same thing | ||
| 1545 | better. @xref{Other C Commands}. | ||
| 1518 | 1546 | ||
| 1519 | In the GNU project, we recommend using underscores to separate words | 1547 | In the GNU project, we recommend using underscores to separate words |
| 1520 | within an identifier in C or C++, rather than using case distinctions. | 1548 | within an identifier in C or C++, rather than using case distinctions. |
| @@ -1529,154 +1557,90 @@ With prefix argument @var{n}, move @var{n} times. | |||
| 1529 | @subsection Electric C Characters | 1557 | @subsection Electric C Characters |
| 1530 | 1558 | ||
| 1531 | In C mode and related modes, certain printing characters are | 1559 | In C mode and related modes, certain printing characters are |
| 1532 | ``electric''---in addition to inserting themselves, they also reindent | 1560 | @dfn{electric}---in addition to inserting themselves, they also |
| 1533 | the current line, and optionally also insert newlines. The | 1561 | reindent the current line, and optionally also insert newlines. The |
| 1534 | ``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#}, | 1562 | ``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#}, |
| 1535 | @kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and | 1563 | @kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and |
| 1536 | @kbd{)}. | 1564 | @kbd{)}. |
| 1537 | 1565 | ||
| 1538 | Electric characters insert newlines only when the @dfn{auto-newline} | 1566 | You might find electric indentation inconvenient if you are editing |
| 1539 | feature is enabled (indicated by @samp{/a} in the mode line after the | 1567 | chaotically indented code. If you are new to CC Mode, you might find |
| 1540 | mode name). This feature is controlled by the variable | 1568 | it disconcerting. You can toggle electric action with the command |
| 1541 | @code{c-auto-newline}. You can turn this feature on or off with the | 1569 | @kbd{C-c C-l}; when it is enabled, @samp{/l} appears in the mode line |
| 1542 | command @kbd{C-c C-a}: | 1570 | after the mode name: |
| 1543 | 1571 | ||
| 1544 | @table @kbd | 1572 | @table @kbd |
| 1545 | @item C-c C-a | 1573 | @item C-c C-l |
| 1546 | @kindex C-c C-a @r{(C mode)} | 1574 | @kindex C-c C-l @r{(C mode)} |
| 1547 | @findex c-toggle-auto-state | 1575 | @findex c-toggle-electric-state |
| 1548 | Toggle the auto-newline feature (@code{c-toggle-auto-state}). With a | 1576 | Toggle electric action (@code{c-toggle-electric-state}). With a |
| 1549 | prefix argument, this command turns the auto-newline feature on if the | 1577 | prefix argument, this command enables electric action if the argument |
| 1550 | argument is positive, and off if it is negative. | 1578 | is positive, disables it if it is negative. |
| 1551 | @end table | 1579 | @end table |
| 1552 | 1580 | ||
| 1553 | The colon character is electric because that is appropriate for a | 1581 | Electric characters insert newlines only when, in addition to the |
| 1554 | single colon. But when you want to insert a double colon in C++, the | 1582 | electric state, the @dfn{auto-newline} feature is enabled (indicated |
| 1555 | electric behavior of colon is inconvenient. You can insert a double | 1583 | by @samp{/la} in the mode line after the mode name). You can turn |
| 1556 | colon with no reindentation or newlines by typing @kbd{C-c :}: | 1584 | this feature on or off with the command @kbd{C-c C-a}: |
| 1557 | 1585 | ||
| 1558 | @table @kbd | 1586 | @table @kbd |
| 1559 | @item C-c : | 1587 | @item C-c C-a |
| 1560 | @ifinfo | 1588 | @kindex C-c C-a @r{(C mode)} |
| 1561 | @c This uses ``colon'' instead of a literal `:' because Info cannot | 1589 | @findex c-toggle-auto-newline |
| 1562 | @c cope with a `:' in a menu | 1590 | Toggle the auto-newline feature (@code{c-toggle-auto-newline}). With a |
| 1563 | @kindex C-c @key{colon} @r{(C mode)} | 1591 | prefix argument, this command turns the auto-newline feature on if the |
| 1564 | @end ifinfo | 1592 | argument is positive, and off if it is negative. |
| 1565 | @ifnotinfo | ||
| 1566 | @kindex C-c : @r{(C mode)} | ||
| 1567 | @end ifnotinfo | ||
| 1568 | @findex c-scope-operator | ||
| 1569 | Insert a double colon scope operator at point, without reindenting the | ||
| 1570 | line or adding any newlines (@code{c-scope-operator}). | ||
| 1571 | @end table | 1593 | @end table |
| 1572 | 1594 | ||
| 1573 | @vindex c-electric-pound-behavior | 1595 | Usually the CC Mode style configures the exact circumstances in |
| 1574 | The electric @kbd{#} key reindents the line if it appears to be the | 1596 | which Emacs inserts auto-newlines. You can also configure this |
| 1575 | beginning of a preprocessor directive. This happens when the value of | 1597 | directly. @xref{Custom Auto-newlines,,, ccmode, The CC Mode Manual}. |
| 1576 | @code{c-electric-pound-behavior} is @code{(alignleft)}. You can turn | ||
| 1577 | this feature off by setting @code{c-electric-pound-behavior} to | ||
| 1578 | @code{nil}. | ||
| 1579 | |||
| 1580 | @vindex c-hanging-braces-alist | ||
| 1581 | The variable @code{c-hanging-braces-alist} controls the insertion of | ||
| 1582 | newlines before and after inserted braces. It is an association list | ||
| 1583 | with elements of the following form: @code{(@var{syntactic-symbol} | ||
| 1584 | . @var{nl-list})}. Most of the syntactic symbols that appear in | ||
| 1585 | @code{c-offsets-alist} are meaningful here as well. | ||
| 1586 | |||
| 1587 | The list @var{nl-list} may contain either of the symbols | ||
| 1588 | @code{before} or @code{after}, or both; or it may be @code{nil}. When a | ||
| 1589 | brace is inserted, the syntactic context it defines is looked up in | ||
| 1590 | @code{c-hanging-braces-alist}; if it is found, the @var{nl-list} is used | ||
| 1591 | to determine where newlines are inserted: either before the brace, | ||
| 1592 | after, or both. If not found, the default is to insert a newline both | ||
| 1593 | before and after braces. | ||
| 1594 | |||
| 1595 | @vindex c-hanging-colons-alist | ||
| 1596 | The variable @code{c-hanging-colons-alist} controls the insertion of | ||
| 1597 | newlines before and after inserted colons. It is an association list | ||
| 1598 | with elements of the following form: @code{(@var{syntactic-symbol} | ||
| 1599 | . @var{nl-list})}. The list @var{nl-list} may contain either of the | ||
| 1600 | symbols @code{before} or @code{after}, or both; or it may be @code{nil}. | ||
| 1601 | |||
| 1602 | When a colon is inserted, the syntactic symbol it defines is looked | ||
| 1603 | up in this list, and if found, the @var{nl-list} is used to determine | ||
| 1604 | where newlines are inserted: either before the brace, after, or both. | ||
| 1605 | If the syntactic symbol is not found in this list, no newlines are | ||
| 1606 | inserted. | ||
| 1607 | |||
| 1608 | @vindex c-cleanup-list | ||
| 1609 | Electric characters can also delete newlines automatically when the | ||
| 1610 | auto-newline feature is enabled. This feature makes auto-newline more | ||
| 1611 | acceptable, by deleting the newlines in the most common cases where you | ||
| 1612 | do not want them. Emacs can recognize several cases in which deleting a | ||
| 1613 | newline might be desirable; by setting the variable | ||
| 1614 | @code{c-cleanup-list}, you can specify @emph{which} of these cases that | ||
| 1615 | should happen. The variable's value is a list of symbols, each | ||
| 1616 | describing one case for possible deletion of a newline. Here are the | ||
| 1617 | meaningful symbols, and their meanings: | ||
| 1618 | |||
| 1619 | @table @code | ||
| 1620 | @item brace-catch-brace | ||
| 1621 | Clean up @samp{@} catch (@var{condition}) @{} constructs by placing the | ||
| 1622 | entire construct on a single line. The clean-up occurs when you type | ||
| 1623 | the @samp{@{}, if there is nothing between the braces aside from | ||
| 1624 | @code{catch} and @var{condition}. | ||
| 1625 | |||
| 1626 | @item brace-else-brace | ||
| 1627 | Clean up @samp{@} else @{} constructs by placing the entire construct on | ||
| 1628 | a single line. The clean-up occurs when you type the @samp{@{} after | ||
| 1629 | the @code{else}, but only if there is nothing but white space between | ||
| 1630 | the braces and the @code{else}. | ||
| 1631 | |||
| 1632 | @item brace-elseif-brace | ||
| 1633 | Clean up @samp{@} else if (@dots{}) @{} constructs by placing the entire | ||
| 1634 | construct on a single line. The clean-up occurs when you type the | ||
| 1635 | @samp{@{}, if there is nothing but white space between the @samp{@}} and | ||
| 1636 | @samp{@{} aside from the keywords and the @code{if}-condition. | ||
| 1637 | |||
| 1638 | @item empty-defun-braces | ||
| 1639 | Clean up empty defun braces by placing the braces on the same | ||
| 1640 | line. Clean-up occurs when you type the closing brace. | ||
| 1641 | |||
| 1642 | @item defun-close-semi | ||
| 1643 | Clean up the semicolon after a @code{struct} or similar type | ||
| 1644 | declaration, by placing the semicolon on the same line as the closing | ||
| 1645 | brace. Clean-up occurs when you type the semicolon. | ||
| 1646 | |||
| 1647 | @item list-close-comma | ||
| 1648 | Clean up commas following braces in array and aggregate | ||
| 1649 | initializers. Clean-up occurs when you type the comma. | ||
| 1650 | |||
| 1651 | @item scope-operator | ||
| 1652 | Clean up double colons which may designate a C++ scope operator, by | ||
| 1653 | placing the colons together. Clean-up occurs when you type the second | ||
| 1654 | colon, but only when the two colons are separated by nothing but | ||
| 1655 | whitespace. | ||
| 1656 | @end table | ||
| 1657 | 1598 | ||
| 1658 | @node Hungry Delete | 1599 | @node Hungry Delete |
| 1659 | @subsection Hungry Delete Feature in C | 1600 | @subsection Hungry Delete Feature in C |
| 1660 | @cindex hungry deletion (C Mode) | 1601 | @cindex hungry deletion (C Mode) |
| 1661 | 1602 | ||
| 1662 | When the @dfn{hungry-delete} feature is enabled (indicated by | 1603 | If you want to delete an entire block of whitespace at point, you |
| 1663 | @samp{/h} or @samp{/ah} in the mode line after the mode name), a single | 1604 | can use @dfn{hungry deletion}. This deletes all the contiguous |
| 1664 | @key{DEL} command deletes all preceding whitespace, not just one space. | 1605 | whitespace either before point or after point in a single operation. |
| 1665 | To turn this feature on or off, use @kbd{C-c C-d}: | 1606 | @dfn{Whitespace} here includes tabs and newlines, but not comments or |
| 1607 | preprocessor commands. | ||
| 1666 | 1608 | ||
| 1667 | @table @kbd | 1609 | @table @kbd |
| 1610 | @item C-c C-@key{BS} | ||
| 1611 | @itemx C-c @key{BS} | ||
| 1612 | @findex c-hungry-backspace | ||
| 1613 | @kindex C-c C-@key{BS} (C Mode) | ||
| 1614 | @kindex C-c @key{BS} (C Mode) | ||
| 1615 | @code{c-hungry-backspace}---Delete the entire block of whitespace | ||
| 1616 | preceding point. | ||
| 1617 | |||
| 1668 | @item C-c C-d | 1618 | @item C-c C-d |
| 1669 | @kindex C-c C-d @r{(C mode)} | 1619 | @itemx C-c C-@key{DEL} |
| 1670 | @findex c-toggle-hungry-state | 1620 | @itemx C-c @key{DEL} |
| 1671 | Toggle the hungry-delete feature (@code{c-toggle-hungry-state}). With a | 1621 | @findex c-hungry-delete-forward |
| 1672 | prefix argument, this command turns the hungry-delete feature on if the | 1622 | @kindex C-c C-d (C Mode) |
| 1673 | argument is positive, and off if it is negative. | 1623 | @kindex C-c C-@key{DEL} (C Mode) |
| 1624 | @kindex C-c @key{DEL} (C Mode) | ||
| 1625 | @code{c-hungry-delete-forward}---Delete the entire block of whitespace | ||
| 1626 | following point. | ||
| 1627 | @end table | ||
| 1674 | 1628 | ||
| 1675 | @item C-c C-t | 1629 | As an alternative to the above commands, you can enable @dfn{hungry |
| 1676 | @kindex C-c C-t @r{(C mode)} | 1630 | delete mode}. When this feature is enabled (indicated by @samp{/h} in |
| 1677 | @findex c-toggle-auto-hungry-state | 1631 | the mode line after the mode name), a single @key{BS} command deletes |
| 1678 | Toggle the auto-newline and hungry-delete features, both at once | 1632 | all preceding whitespace, not just one space, and a single @kbd{C-c |
| 1679 | (@code{c-toggle-auto-hungry-state}). | 1633 | C-d} (but @emph{not} @key{delete}) deletes all following whitespace. |
| 1634 | |||
| 1635 | @table @kbd | ||
| 1636 | @item M-x c-toggle-hungry-state | ||
| 1637 | @findex c-toggle-hungry-state | ||
| 1638 | Toggle the hungry-delete feature | ||
| 1639 | (@code{c-toggle-hungry-state})@footnote{This command had the binding | ||
| 1640 | @kbd{C-c C-d} in earlier versions of Emacs. @kbd{C-c C-d} is now | ||
| 1641 | bound to @code{c-hungry-delete-forward}.}. With a prefix argument, | ||
| 1642 | this command turns the hungry-delete feature on if the argument is | ||
| 1643 | positive, and off if it is negative. | ||
| 1680 | @end table | 1644 | @end table |
| 1681 | 1645 | ||
| 1682 | @vindex c-hungry-delete-key | 1646 | @vindex c-hungry-delete-key |
| @@ -1687,6 +1651,16 @@ hungry-delete feature is enabled. | |||
| 1687 | @subsection Other Commands for C Mode | 1651 | @subsection Other Commands for C Mode |
| 1688 | 1652 | ||
| 1689 | @table @kbd | 1653 | @table @kbd |
| 1654 | @item C-c C-w | ||
| 1655 | @itemx M-x c-subword-mode | ||
| 1656 | @findex c-subword-mode | ||
| 1657 | Enable (or disable) @dfn{subword mode}. In subword mode, Emacs's word | ||
| 1658 | commands then recognize upper case letters in | ||
| 1659 | @samp{StudlyCapsIdentifiers} as word boundaries. This is indicated by | ||
| 1660 | the flag @samp{/w} on the mode line after the mode name | ||
| 1661 | (e.g. @samp{C/law}). You can even use @kbd{M-x c-subword-mode} in | ||
| 1662 | non-CC Mode buffers. | ||
| 1663 | |||
| 1690 | @item M-x c-context-line-break | 1664 | @item M-x c-context-line-break |
| 1691 | @findex c-context-line-break | 1665 | @findex c-context-line-break |
| 1692 | This command inserts a line break and indents the new line in a manner | 1666 | This command inserts a line break and indents the new line in a manner |
| @@ -1697,9 +1671,13 @@ it's like @kbd{M-j} (@code{c-indent-new-comment-line}). | |||
| 1697 | 1671 | ||
| 1698 | @code{c-context-line-break} isn't bound to a key by default, but it | 1672 | @code{c-context-line-break} isn't bound to a key by default, but it |
| 1699 | needs a binding to be useful. The following code will bind it to | 1673 | needs a binding to be useful. The following code will bind it to |
| 1700 | @kbd{C-j}. | 1674 | @kbd{C-j}. We use @code{c-initialization-hook} here to make sure |
| 1675 | the keymap is loaded before we try to change it. | ||
| 1676 | |||
| 1701 | @example | 1677 | @example |
| 1702 | (define-key c-mode-base-map "\C-j" 'c-context-line-break) | 1678 | (defun my-bind-clb () |
| 1679 | (define-key c-mode-base-map "\C-j" 'c-context-line-break)) | ||
| 1680 | (add-hook 'c-initialization-hook 'my-bind-clb) | ||
| 1703 | @end example | 1681 | @end example |
| 1704 | 1682 | ||
| 1705 | @item C-M-h | 1683 | @item C-M-h |