comparison man/programs.texi @ 67683:6fc6fd3c71cd

(Electric C): Delete the info about newline control. (Other C Commands): Minor cleanup. (Left Margin Paren): Minor cleanup.
author Richard M. Stallman <rms@gnu.org>
date Tue, 20 Dec 2005 02:49:00 +0000
parents 76931aba1936
children 60492fe37343 7beb78bc1f8e
comparison
equal deleted inserted replaced
67682:7b7fe29be670 67683:6fc6fd3c71cd
164 164
165 @defvar open-paren-in-column-0-is-defun-start 165 @defvar open-paren-in-column-0-is-defun-start
166 If this user option is set to @code{t} (the default), opening 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 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 168 @code{nil}, defuns are found by searching for parens or braces at the
169 outermost level. 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}
170 @end defvar 172 @end defvar
171 173
172 In buffers where @code{open-paren-in-column-0-is-defun-start} is 174 In modes where @code{open-paren-in-column-0-is-defun-start} is
173 @code{t}, @strong{don't put an opening delimiter at the left margin 175 @code{t}, @strong{don't put an opening delimiter at the left margin
174 unless it is a defun start}. For instance, never put an 176 unless it is a defun start}. For instance, never put an
175 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
176 start of a top-level list. 178 start of a top-level list.
177 179
195 @end example 197 @end example
196 198
197 To help you catch violations of this convention, Font Lock mode 199 To help you catch violations of this convention, Font Lock mode
198 highlights confusing opening delimiters (those that ought to be 200 highlights confusing opening delimiters (those that ought to be
199 quoted) in bold red. 201 quoted) in bold red.
200
201 Some major modes, including C and related modes, set
202 @code{open-paren-in-column-0-is-defun-start} buffer-locally to
203 @code{nil}, thus freeing you from all these restrictions. This makes
204 some commands run more slowly, though.
205 202
206 In the earliest days, the original Emacs found defuns by moving 203 In the earliest days, the original Emacs found defuns by moving
207 upward a level of parentheses or braces until there were no more 204 upward a level of parentheses or braces until there were no more
208 levels to go up. This always required scanning all the way back to 205 levels to go up. This always required scanning all the way back to
209 the beginning of the buffer, even for a small function. To speed up 206 the beginning of the buffer, even for a small function. To speed up
210 the operation, we changed Emacs to assume that any opening delimiter 207 the operation, we changed Emacs to assume that any opening delimiter
211 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
212 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
213 buffer. However, now that modern computers are so powerful, this 210 buffer. However, now that modern computers are so powerful, this
214 scanning is rarely slow enough to annoy, so we've given you a way to 211 scanning is rarely slow enough to annoy, so we've provided a way to
215 disable the heuristic. 212 disable the heuristic.
216 213
217 @node Moving by Defuns 214 @node Moving by Defuns
218 @subsection Moving by Defuns 215 @subsection Moving by Defuns
219 @cindex defuns 216 @cindex defuns
983 @cindex blank lines in programs 980 @cindex blank lines in programs
984 @findex comment-indent-new-line 981 @findex comment-indent-new-line
985 982
986 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,
987 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}
988 (@code{comment-indent-new-line}). This terminates the comment you are 985 (@code{comment-indent-new-line}). If @code{comment-multi-line}
989 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
990 indented under the old one. Or, if the language syntax permits 987 line within the comment. Otherwise it closes the comment and starts a
991 comments to extend beyond ends of lines, it may instead continue the 988 new comment on a new line. When Auto Fill mode is on, going past the
992 existing comment on the new blank line---this is controlled by the 989 fill column while typing a comment causes the comment to be continued
993 setting of @code{comment-multi-line} (@pxref{Options for Comments}). 990 in just this fashion.
994 If point is not at the end of the line when you type the command, the
995 text on the rest of the line becomes part of the new comment line.
996 When Auto Fill mode is on, going past the fill column while typing a
997 comment causes the comment to be continued in just this fashion.
998 991
999 @kindex C-c C-c (C mode) 992 @kindex C-c C-c (C mode)
1000 @findex comment-region 993 @findex comment-region
1001 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
1002 comment-region} command (or type @kbd{C-c C-c} in C-like buffers). It 995 comment-region} command (or type @kbd{C-c C-c} in C-like buffers). It
1566 In C mode and related modes, certain printing characters are 1559 In C mode and related modes, certain printing characters are
1567 @dfn{electric}---in addition to inserting themselves, they also 1560 @dfn{electric}---in addition to inserting themselves, they also
1568 reindent the current line, and optionally also insert newlines. The 1561 reindent the current line, and optionally also insert newlines. The
1569 ``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#}, 1562 ``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#},
1570 @kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and 1563 @kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and
1571 @kbd{)}. @xref{Electric Keys,,, ccmode, The CC Mode Manual}. 1564 @kbd{)}.
1572 1565
1573 You might find electric indentation inconvenient if you are editing 1566 You might find electric indentation inconvenient if you are editing
1574 chaotically indented code. If you are new to CC Mode, you might find 1567 chaotically indented code. If you are new to CC Mode, you might find
1575 it disconcerting. You can toggle electric action with the command 1568 it disconcerting. You can toggle electric action with the command
1576 @kbd{C-c C-l}; when it is enabled, @samp{/l} appears in the mode line 1569 @kbd{C-c C-l}; when it is enabled, @samp{/l} appears in the mode line
1597 Toggle the auto-newline feature (@code{c-toggle-auto-newline}). With a 1590 Toggle the auto-newline feature (@code{c-toggle-auto-newline}). With a
1598 prefix argument, this command turns the auto-newline feature on if the 1591 prefix argument, this command turns the auto-newline feature on if the
1599 argument is positive, and off if it is negative. 1592 argument is positive, and off if it is negative.
1600 @end table 1593 @end table
1601 1594
1602 Usually the CC Mode style system (@pxref{Styles,,, ccmode, The CC 1595 Usually the CC Mode style configures the exact circumstances in
1603 Mode Manual}) configures the exact circumstances in which Emacs 1596 which Emacs inserts auto-newlines. You can also configure this
1604 inserts auto-newlines, but you can configure this directly instead. 1597 directly. @xref{Custom Auto-newlines,,, ccmode, The CC Mode Manual}.
1605 Full details are at @ref{Custom Auto-newlines,,, ccmode, The CC Mode
1606 Manual}, but there is a short summary below.
1607
1608 The colon character is electric because that is appropriate for a
1609 single colon. But when you want to insert a double colon in C++, the
1610 electric behavior of colon is inconvenient. You can insert a double
1611 colon with no reindentation or newlines by typing @kbd{C-c :}:
1612
1613 @table @kbd
1614 @item C-c :
1615 @ifinfo
1616 @c This uses ``colon'' instead of a literal `:' because Info cannot
1617 @c cope with a `:' in a menu
1618 @kindex C-c @key{colon} @r{(C mode)}
1619 @end ifinfo
1620 @ifnotinfo
1621 @kindex C-c : @r{(C mode)}
1622 @end ifnotinfo
1623 @findex c-scope-operator
1624 Insert a double colon scope operator at point, without reindenting the
1625 line or adding any newlines (@code{c-scope-operator}).
1626 @end table
1627
1628 @vindex c-electric-pound-behavior
1629 The electric @kbd{#} key reindents the line if it appears to be the
1630 beginning of a preprocessor directive. This happens when the value of
1631 @code{c-electric-pound-behavior} is @code{(alignleft)}. You can turn
1632 this feature off by setting @code{c-electric-pound-behavior} to
1633 @code{nil}.
1634
1635 @vindex c-hanging-braces-alist
1636 The variable @code{c-hanging-braces-alist} controls the insertion of
1637 newlines before and after inserted braces. It is an association list
1638 with elements of the following form: @code{(@var{syntactic-symbol}
1639 . @var{nl-list})}. Most of the syntactic symbols that appear in
1640 @code{c-offsets-alist} are meaningful here as well.
1641
1642 The list @var{nl-list} may contain either of the symbols
1643 @code{before} or @code{after}, or both; or it may be @code{nil}. When a
1644 brace is inserted, the syntactic context it defines is looked up in
1645 @code{c-hanging-braces-alist}; if it is found, the @var{nl-list} is used
1646 to determine where newlines are inserted: either before the brace,
1647 after, or both. If not found, the default is to insert a newline both
1648 before and after braces.
1649
1650 @vindex c-hanging-colons-alist
1651 The variable @code{c-hanging-colons-alist} controls the insertion of
1652 newlines before and after inserted colons. It is an association list
1653 with elements of the following form: @code{(@var{syntactic-symbol}
1654 . @var{nl-list})}. The list @var{nl-list} may contain either of the
1655 symbols @code{before} or @code{after}, or both; or it may be @code{nil}.
1656
1657 When a colon is inserted, the syntactic symbol it defines is looked
1658 up in this list, and if found, the @var{nl-list} is used to determine
1659 where newlines are inserted: either before the brace, after, or both.
1660 If the syntactic symbol is not found in this list, no newlines are
1661 inserted.
1662
1663 @vindex c-cleanup-list
1664 Electric characters can also delete newlines automatically when the
1665 auto-newline feature is enabled. This feature makes auto-newline more
1666 acceptable, by deleting the newlines in the most common cases where
1667 you do not want them. Emacs can recognize several cases in which
1668 deleting a newline might be desirable; by setting the variable
1669 @code{c-cleanup-list}, you can specify @emph{which} of these cases
1670 that should happen. @xref{Clean-ups,,, ccmode, The CC Mode Manual}.
1671 The variable's value is a list of symbols, each describing one case
1672 for possible deletion of a newline. Here is a summary of the
1673 meaningful symbols and their meanings:
1674
1675 @table @code
1676 @item brace-catch-brace
1677 Clean up @samp{@} catch (@var{condition}) @{} constructs by placing the
1678 entire construct on a single line. The clean-up occurs when you type
1679 the @samp{@{}, if there is nothing between the braces aside from
1680 @code{catch} and @var{condition}.
1681
1682 @item brace-else-brace
1683 Clean up @samp{@} else @{} constructs by placing the entire construct on
1684 a single line. The clean-up occurs when you type the @samp{@{} after
1685 the @code{else}, but only if there is nothing but white space between
1686 the braces and the @code{else}.
1687
1688 @item brace-elseif-brace
1689 Clean up @samp{@} else if (@dots{}) @{} constructs by placing the entire
1690 construct on a single line. The clean-up occurs when you type the
1691 @samp{@{}, if there is nothing but white space between the @samp{@}} and
1692 @samp{@{} aside from the keywords and the @code{if}-condition.
1693
1694 @item empty-defun-braces
1695 Clean up empty defun braces by placing the braces on the same
1696 line. Clean-up occurs when you type the closing brace.
1697
1698 @item defun-close-semi
1699 Clean up the semicolon after a @code{struct} or similar type
1700 declaration, by placing the semicolon on the same line as the closing
1701 brace. Clean-up occurs when you type the semicolon.
1702
1703 @item list-close-comma
1704 Clean up commas following braces in array and aggregate
1705 initializers. Clean-up occurs when you type the comma.
1706
1707 @item one-line-defun
1708 Remove space and newlines from a defun if this would leave it short
1709 enough to fit on a single line. This is useful for AWK pattern/action
1710 pairs. ``Short enough'' means not longer than the value of the user
1711 option @code{c-max-one-liner-length}. Clean-up occurs when you type
1712 the closing brace.
1713
1714 @item scope-operator
1715 Clean up double colons which may designate a C++ scope operator, by
1716 placing the colons together. Clean-up occurs when you type the second
1717 colon, but only when the two colons are separated by nothing but
1718 whitespace.
1719 @end table
1720 1598
1721 @node Hungry Delete 1599 @node Hungry Delete
1722 @subsection Hungry Delete Feature in C 1600 @subsection Hungry Delete Feature in C
1723 @cindex hungry deletion (C Mode) 1601 @cindex hungry deletion (C Mode)
1724 1602
1774 1652
1775 @table @kbd 1653 @table @kbd
1776 @item C-c C-w 1654 @item C-c C-w
1777 @itemx M-x c-subword-mode 1655 @itemx M-x c-subword-mode
1778 @findex c-subword-mode 1656 @findex c-subword-mode
1779 Enable (or disable) @dfn{subword mode} - Emacs's word commands then 1657 Enable (or disable) @dfn{subword mode}. In subword mode, Emacs's word
1780 recognize upper case letters in @samp{StudlyCapsIdentifiers} as word 1658 commands then recognize upper case letters in
1781 boundaries. This is indicated by the flag @samp{/w} on the mode line 1659 @samp{StudlyCapsIdentifiers} as word boundaries. This is indicated by
1782 after the mode name (e.g. @samp{C/law}). You can even use @kbd{M-x 1660 the flag @samp{/w} on the mode line after the mode name
1783 c-subword-mode} in non-CC Mode buffers. 1661 (e.g. @samp{C/law}). You can even use @kbd{M-x c-subword-mode} in
1662 non-CC Mode buffers.
1784 1663
1785 @item M-x c-context-line-break 1664 @item M-x c-context-line-break
1786 @findex c-context-line-break 1665 @findex c-context-line-break
1787 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
1788 appropriate to the context. In normal code, it does the work of 1667 appropriate to the context. In normal code, it does the work of