Mercurial > emacs
comparison man/indent.texi @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 23a1cea22d13 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 @c This is part of the Emacs manual. | 1 @c This is part of the Emacs manual. |
2 @c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997 Free Software Foundation, Inc. | 2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2002, 2003, |
3 @c 2004, 2005 Free Software Foundation, Inc. | |
3 @c See file emacs.texi for copying conditions. | 4 @c See file emacs.texi for copying conditions. |
4 @node Indentation, Text, Major Modes, Top | 5 @node Indentation, Text, Major Modes, Top |
5 @chapter Indentation | 6 @chapter Indentation |
6 @cindex indentation | 7 @cindex indentation |
7 @cindex columns (indentation) | 8 @cindex columns (indentation) |
14 Indent the current line ``appropriately'' in a mode-dependent fashion. | 15 Indent the current line ``appropriately'' in a mode-dependent fashion. |
15 @item @kbd{C-j} | 16 @item @kbd{C-j} |
16 Perform @key{RET} followed by @key{TAB} (@code{newline-and-indent}). | 17 Perform @key{RET} followed by @key{TAB} (@code{newline-and-indent}). |
17 @item M-^ | 18 @item M-^ |
18 Merge the previous and the current line (@code{delete-indentation}). | 19 Merge the previous and the current line (@code{delete-indentation}). |
19 This would cancel out the effect of @kbd{C-j}. | 20 This would cancel the effect of a preceding @kbd{C-j}. |
20 @item C-M-o | 21 @item C-M-o |
21 Split the current line at point; text on the line after point becomes a | 22 Split the current line at point; text on the line after point becomes a |
22 new line indented to the same column where point is located | 23 new line indented to the same column where point is located |
23 (@code{split-line}). | 24 (@code{split-line}). |
24 @item M-m | 25 @item M-m |
25 Move (forward or back) to the first nonblank character on the current | 26 Move (forward or back) to the first nonblank character on the current |
26 line (@code{back-to-indentation}). | 27 line (@code{back-to-indentation}). |
27 @item C-M-\ | 28 @item C-M-\ |
28 Indent several lines to the same column (@code{indent-region}). | 29 Indent lines in the region to the same column (@code{indent-region}). |
29 @item C-x @key{TAB} | 30 @item C-x @key{TAB} |
30 Shift a block of lines rigidly right or left (@code{indent-rigidly}). | 31 Shift lines in the region rigidly right or left (@code{indent-rigidly}). |
31 @item M-i | 32 @item M-i |
32 Indent from point to the next prespecified tab stop column | 33 Indent from point to the next prespecified tab stop column |
33 (@code{tab-to-tab-stop}). | 34 (@code{tab-to-tab-stop}). |
34 @item M-x indent-relative | 35 @item M-x indent-relative |
35 Indent from point to under an indentation point in the previous line. | 36 Indent from point to under an indentation point in the previous line. |
36 @end table | 37 @end table |
37 | 38 |
38 Most programming languages have some indentation convention. For Lisp | 39 Emacs supports four general categories of operations that could all |
39 code, lines are indented according to their nesting in parentheses. The | 40 be called `indentation': |
40 same general idea is used for C code, though many details are different. | 41 |
42 @enumerate | |
43 @item | |
44 Insert a tab character. You can type @kbd{C-q @key{TAB}} to do this. | |
45 | |
46 A tab character is displayed as a stretch of whitespace which extends | |
47 to the next display tab stop position, and the default width of a tab | |
48 stop is eight. @xref{Display Custom}, for more details. | |
49 | |
50 @item | |
51 Insert whitespace up to the next tab stop. You can set tab stops at | |
52 your choice of column positions, then type @kbd{M-i} to advance to the | |
53 next tab stop. The default tab stop settings have a tab stop every | |
54 eight columns, which means by default @kbd{M-i} inserts a tab | |
55 character. To set the tab stops, use @kbd{M-x edit-tab-stops}. | |
56 | |
57 @item | |
58 Align a line with the previous line. More precisely, the command | |
59 @kbd{M-x indent-relative} indents the current line under the beginning | |
60 of some word in the previous line. In Fundamental mode and in Text | |
61 mode, @key{TAB} runs the command @code{indent-relative}. | |
62 | |
63 @item | |
64 The most sophisticated method is @dfn{syntax-driven indentation}. | |
65 Most programming languages have an indentation convention. For Lisp | |
66 code, lines are indented according to their nesting in parentheses. C | |
67 code uses the same general idea, but many details are different. | |
41 | 68 |
42 @kindex TAB | 69 @kindex TAB |
43 Whatever the language, to indent a line, use the @key{TAB} command. Each | 70 Type @key{TAB} to do syntax-driven indentation, in a mode that |
44 major mode defines this command to perform the sort of indentation | 71 supports it. It realigns the current line according with the syntax |
45 appropriate for the particular language. In Lisp mode, @key{TAB} aligns | 72 of the preceding lines. No matter where in the line you are when you |
46 the line according to its depth in parentheses. No matter where in the | 73 type @key{TAB}, it aligns the line as a whole. |
47 line you are when you type @key{TAB}, it aligns the line as a whole. In C | 74 @end enumerate |
48 mode, @key{TAB} implements a subtle and sophisticated indentation style that | 75 |
49 knows about many aspects of C syntax. | 76 Normally, most of the above methods insert an optimal mix of tabs and |
50 | 77 spaces to align to the desired column. @xref{Just Spaces}, for how to |
51 In Text mode, @key{TAB} runs the command @code{tab-to-tab-stop}, which | 78 disable use of tabs. However, @kbd{C-q @key{TAB}} always inserts a |
52 indents to the next tab stop column. You can set the tab stops with | 79 tab, even when tabs are disabled for the indentation commands. |
53 @kbd{M-x edit-tab-stops}. | |
54 | |
55 Normally, @key{TAB} inserts an optimal mix of tabs and spaces for | |
56 the intended indentation. @xref{Just Spaces}, for how to prevent use | |
57 of tabs. | |
58 | 80 |
59 @menu | 81 @menu |
60 * Indentation Commands:: Various commands and techniques for indentation. | 82 * Indentation Commands:: Various commands and techniques for indentation. |
61 * Tab Stops:: You can set arbitrary "tab stops" and then | 83 * Tab Stops:: You can set arbitrary "tab stops" and then |
62 indent to the next tab stop when you want to. | 84 indent to the next tab stop when you want to. |
68 | 90 |
69 @kindex M-m | 91 @kindex M-m |
70 @findex back-to-indentation | 92 @findex back-to-indentation |
71 To move over the indentation on a line, do @kbd{M-m} | 93 To move over the indentation on a line, do @kbd{M-m} |
72 (@code{back-to-indentation}). This command, given anywhere on a line, | 94 (@code{back-to-indentation}). This command, given anywhere on a line, |
73 positions point at the first nonblank character on the line. | 95 positions point at the first nonblank character on the line, if any, |
96 or else at the end of the line. | |
74 | 97 |
75 To insert an indented line before the current line, do @kbd{C-a C-o | 98 To insert an indented line before the current line, do @kbd{C-a C-o |
76 @key{TAB}}. To make an indented line after the current line, use | 99 @key{TAB}}. To make an indented line after the current line, use |
77 @kbd{C-e C-j}. | 100 @kbd{C-e C-j}. |
78 | 101 |
107 @kindex C-M-\ | 130 @kindex C-M-\ |
108 @kindex C-x TAB | 131 @kindex C-x TAB |
109 @findex indent-region | 132 @findex indent-region |
110 @findex indent-rigidly | 133 @findex indent-rigidly |
111 There are also commands for changing the indentation of several lines | 134 There are also commands for changing the indentation of several lines |
112 at once. @kbd{C-M-\} (@code{indent-region}) applies to all the lines | 135 at once. They apply to all the lines that begin in the region. |
113 that begin in the region; it indents each line in the ``usual'' way, as | 136 @kbd{C-M-\} (@code{indent-region}) indents each line in the ``usual'' |
114 if you had typed @key{TAB} at the beginning of the line. A numeric | 137 way, as if you had typed @key{TAB} at the beginning of the line. A |
115 argument specifies the column to indent to, and each line is shifted | 138 numeric argument specifies the column to indent to, and each line is |
116 left or right so that its first nonblank character appears in that | 139 shifted left or right so that its first nonblank character appears in |
117 column. @kbd{C-x @key{TAB}} (@code{indent-rigidly}) moves all of the | 140 that column. @kbd{C-x @key{TAB}} (@code{indent-rigidly}) moves all of |
118 lines in the region right by its argument (left, for negative | 141 the lines in the region right by its argument (left, for negative |
119 arguments). The whole group of lines moves rigidly sideways, which is | 142 arguments). The whole group of lines moves rigidly sideways, which is |
120 how the command gets its name.@refill | 143 how the command gets its name.@refill |
121 | 144 |
122 @cindex remove indentation | 145 @cindex remove indentation |
123 If you want to remove all indentation from all of the line in the | 146 If you want to remove all indentation from all of the line in the |
125 such as -1000. | 148 such as -1000. |
126 | 149 |
127 @findex indent-relative | 150 @findex indent-relative |
128 @kbd{M-x indent-relative} indents at point based on the previous line | 151 @kbd{M-x indent-relative} indents at point based on the previous line |
129 (actually, the last nonempty line). It inserts whitespace at point, moving | 152 (actually, the last nonempty line). It inserts whitespace at point, moving |
130 point, until it is underneath an indentation point in the previous line. | 153 point, until it is underneath the next indentation point in the previous line. |
131 An indentation point is the end of a sequence of whitespace or the end of | 154 An indentation point is the end of a sequence of whitespace or the end of |
132 the line. If point is farther right than any indentation point in the | 155 the line. If point is farther right than any indentation point in the |
133 previous line, the whitespace before point is deleted and the first | 156 previous line, @code{indent-relative} runs @code{tab-to-tab-stop} |
134 indentation point then applicable is used. If no indentation point is | |
135 applicable even then, @code{indent-relative} runs @code{tab-to-tab-stop} | |
136 @ifinfo | 157 @ifinfo |
137 (@pxref{Tab Stops}), | 158 (@pxref{Tab Stops}), |
138 @end ifinfo | 159 @end ifinfo |
139 @iftex | 160 @iftex |
140 (see next section), | 161 (see next section), |
141 @end iftex | 162 @end iftex |
142 unless it is called with a numeric argument, in which case it does | 163 unless it is called with a numeric argument, in which case it does |
143 nothing. | 164 nothing. |
144 | 165 |
145 @code{indent-relative} is the definition of @key{TAB} in Indented Text | |
146 mode. @xref{Text}. | |
147 | |
148 @xref{Format Indentation}, for another way of specifying the | 166 @xref{Format Indentation}, for another way of specifying the |
149 indentation for part of your text. | 167 indentation for part of your text. |
150 | 168 |
151 @node Tab Stops, Just Spaces, Indentation Commands, Indentation | 169 @node Tab Stops, Just Spaces, Indentation Commands, Indentation |
152 @section Tab Stops | 170 @section Tab Stops |
154 @cindex tab stops | 172 @cindex tab stops |
155 @cindex using tab stops in making tables | 173 @cindex using tab stops in making tables |
156 @cindex tables, indentation for | 174 @cindex tables, indentation for |
157 @kindex M-i | 175 @kindex M-i |
158 @findex tab-to-tab-stop | 176 @findex tab-to-tab-stop |
159 For typing in tables, you can use Text mode's definition of @key{TAB}, | 177 For typing in tables, you can use @kbd{M-i} (@code{tab-to-tab-stop}). |
160 @code{tab-to-tab-stop}. This command inserts indentation before point, | 178 This command inserts indentation before point, enough to reach the |
161 enough to reach the next tab stop column. If you are not in Text mode, | 179 next tab stop column. |
162 this command can be found on the key @kbd{M-i}. | |
163 | 180 |
164 @findex edit-tab-stops | 181 @findex edit-tab-stops |
165 @findex edit-tab-stops-note-changes | 182 @findex edit-tab-stops-note-changes |
166 @kindex C-c C-c @r{(Edit Tab Stops)} | 183 @kindex C-c C-c @r{(Edit Tab Stops)} |
167 @vindex tab-stop-list | 184 @vindex tab-stop-list |
171 | 188 |
172 The convenient way to set the tab stops is with @kbd{M-x | 189 The convenient way to set the tab stops is with @kbd{M-x |
173 edit-tab-stops}, which creates and selects a buffer containing a | 190 edit-tab-stops}, which creates and selects a buffer containing a |
174 description of the tab stop settings. You can edit this buffer to | 191 description of the tab stop settings. You can edit this buffer to |
175 specify different tab stops, and then type @kbd{C-c C-c} to make those | 192 specify different tab stops, and then type @kbd{C-c C-c} to make those |
176 new tab stops take effect. @code{edit-tab-stops} records which buffer | 193 new tab stops take effect. The buffer uses Overwrite mode |
177 was current when you invoked it, and stores the tab stops back in that | 194 (@pxref{Minor Modes}). @code{edit-tab-stops} records which buffer was |
178 buffer; normally all buffers share the same tab stops and changing them | 195 current when you invoked it, and stores the tab stops back in that |
179 in one buffer affects all, but if you happen to make | 196 buffer; normally all buffers share the same tab stops and changing |
197 them in one buffer affects all, but if you happen to make | |
180 @code{tab-stop-list} local in one buffer then @code{edit-tab-stops} in | 198 @code{tab-stop-list} local in one buffer then @code{edit-tab-stops} in |
181 that buffer will edit the local settings. | 199 that buffer will edit the local settings. |
182 | 200 |
183 Here is what the text representing the tab stops looks like for ordinary | 201 Here is what the text representing the tab stops looks like for ordinary |
184 tab stops every eight columns. | 202 tab stops every eight columns. |
206 this, set @code{indent-tabs-mode} to @code{nil}. This is a per-buffer | 224 this, set @code{indent-tabs-mode} to @code{nil}. This is a per-buffer |
207 variable, so altering the variable affects only the current buffer, | 225 variable, so altering the variable affects only the current buffer, |
208 but there is a default value which you can change as well. | 226 but there is a default value which you can change as well. |
209 @xref{Locals}. | 227 @xref{Locals}. |
210 | 228 |
229 A tab is not always displayed in the same way. By default, tabs are | |
230 eight columns wide, but some people like to customize their tools to | |
231 use a different tab width. So by using spaces only, you can make sure | |
232 that your file looks the same regardless of the tab width setting. | |
233 | |
211 @findex tabify | 234 @findex tabify |
212 @findex untabify | 235 @findex untabify |
213 There are also commands to convert tabs to spaces or vice versa, always | 236 There are also commands to convert tabs to spaces or vice versa, always |
214 preserving the columns of all nonblank text. @kbd{M-x tabify} scans the | 237 preserving the columns of all nonblank text. @kbd{M-x tabify} scans the |
215 region for sequences of spaces, and converts sequences of at least three | 238 region for sequences of spaces, and converts sequences of at least two |
216 spaces to tabs if that can be done without changing indentation. @kbd{M-x | 239 spaces to tabs if that can be done without changing indentation. @kbd{M-x |
217 untabify} changes all tabs in the region to appropriate numbers of spaces. | 240 untabify} changes all tabs in the region to appropriate numbers of spaces. |
241 | |
242 @ignore | |
243 arch-tag: acc07de7-ae11-4ee8-a159-cb59c473f0fb | |
244 @end ignore |