Mercurial > emacs
comparison man/indent.texi @ 51145:4e1075214fa7
(Indentation): Explain the concepts.
(Just Spaces): Explain why preventing tabs for indentation might
be useful.
author | Kai Großjohann <kgrossjo@eu.uu.net> |
---|---|
date | Thu, 22 May 2003 14:53:58 +0000 |
parents | 23a1cea22d13 |
children | 229d922db4a3 |
comparison
equal
deleted
inserted
replaced
51144:29b535fc81e8 | 51145:4e1075214fa7 |
---|---|
33 (@code{tab-to-tab-stop}). | 33 (@code{tab-to-tab-stop}). |
34 @item M-x indent-relative | 34 @item M-x indent-relative |
35 Indent from point to under an indentation point in the previous line. | 35 Indent from point to under an indentation point in the previous line. |
36 @end table | 36 @end table |
37 | 37 |
38 Emacs supports four general categories of operations that could all | |
39 be called `indentation': | |
40 | |
41 @enumerate | |
42 @item | |
43 The most simple operation is to just insert a tab character. This | |
44 operation does not have a convenient key binding, because it is | |
45 subsumed by the more general operation described next. But you can use | |
46 @kbd{C-q @key{TAB}} to insert a literal tab character. | |
47 | |
48 A tab character is displayed as a stretch of whitespace which extends | |
49 to the next display tab stop position, and the default width of a tab | |
50 stop is eight. @xref{Display Custom}, for more details. | |
51 | |
52 @item | |
53 Emacs also supports tab stops. You can set them at arbitrary | |
54 positions, and then use @kbd{M-i} to advance to the next tab stop. The | |
55 default tab stop list contains positions (columns) that are a multiple | |
56 of eight, and so the effect of @kbd{M-i} is the same as that of | |
57 @kbd{C-q @key{TAB}} in the default case. | |
58 | |
59 You can set the tab stops with @kbd{M-x edit-tab-stops}. | |
60 | |
61 @item | |
62 You can align successive lines with each other. This is called | |
63 @dfn{relative indentation} in Emacs and is performed by the command | |
64 @kbd{M-x indent-relative}. The effect is best shown by an example: | |
65 @example | |
66 This shows the effect of relative indentation. | |
67 ^ ^ ^ ^ ^ ^ ^ | |
68 @end example | |
69 The positions for the @code{^} characters on the second line were | |
70 obtained using @kbd{M-x indent-relative}. | |
71 | |
72 In Fundamental mode and in Text mode, @key{TAB} runs the command | |
73 @code{indent-relative}. | |
74 | |
75 @item | |
76 The most sophisticated method is called @dfn{syntax-driven indentation} | |
77 and is the default behavior of the @key{TAB} key in Emacs. | |
78 | |
38 Most programming languages have some indentation convention. For Lisp | 79 Most programming languages have some indentation convention. For Lisp |
39 code, lines are indented according to their nesting in parentheses. The | 80 code, lines are indented according to their nesting in parentheses. The |
40 same general idea is used for C code, though many details are different. | 81 same general idea is used for C code, though many details are different. |
82 | |
83 For some languages, different kinds of indentation styles are | |
84 commonly used. Emacs accomodates this by allowing users to customize | |
85 the indentation. For example, see @ref{Customizing Indentation,,,ccmode}, | |
86 for a description of these facilities for the C language. | |
41 | 87 |
42 @kindex TAB | 88 @kindex TAB |
43 Whatever the language, to indent a line, use the @key{TAB} command. Each | 89 Whatever the language, to indent a line, use the @key{TAB} command. Each |
44 major mode defines this command to perform the sort of indentation | 90 major mode defines this command to perform the sort of indentation |
45 appropriate for the particular language. In Lisp mode, @key{TAB} aligns | 91 appropriate for the particular language. In Lisp mode, @key{TAB} aligns |
46 the line according to its depth in parentheses. No matter where in the | 92 the line according to its depth in parentheses. No matter where in the |
47 line you are when you type @key{TAB}, it aligns the line as a whole. In C | 93 line you are when you type @key{TAB}, it aligns the line as a whole. In C |
48 mode, @key{TAB} implements a subtle and sophisticated indentation style that | 94 mode, @key{TAB} implements a subtle and sophisticated indentation style that |
49 knows about many aspects of C syntax. | 95 knows about many aspects of C syntax. |
50 | 96 |
51 In Text mode, @key{TAB} runs the command @code{tab-to-tab-stop}, which | 97 @end enumerate |
52 indents to the next tab stop column. You can set the tab stops with | 98 |
53 @kbd{M-x edit-tab-stops}. | 99 Normally, all of the above methods insert an optimal mix of tabs and |
54 | 100 spaces for the needed indentation. @xref{Just Spaces}, for how to |
55 Normally, @key{TAB} inserts an optimal mix of tabs and spaces for | 101 prevent use of tabs. However, the first method (@kbd{C-q @key{TAB}}) |
56 the intended indentation. @xref{Just Spaces}, for how to prevent use | 102 always inserts a tab, even if you prevented their use. |
57 of tabs. | 103 |
104 @c In Text mode, @key{TAB} runs the command @code{tab-to-tab-stop}, which | |
105 @c indents to the next tab stop column. You can set the tab stops with | |
106 @c @kbd{M-x edit-tab-stops}. | |
107 | |
108 @c Normally, @key{TAB} inserts an optimal mix of tabs and spaces for | |
109 @c the intended indentation. @xref{Just Spaces}, for how to prevent use | |
110 @c of tabs. | |
58 | 111 |
59 @menu | 112 @menu |
60 * Indentation Commands:: Various commands and techniques for indentation. | 113 * Indentation Commands:: Various commands and techniques for indentation. |
61 * Tab Stops:: You can set arbitrary "tab stops" and then | 114 * Tab Stops:: You can set arbitrary "tab stops" and then |
62 indent to the next tab stop when you want to. | 115 indent to the next tab stop when you want to. |
206 this, set @code{indent-tabs-mode} to @code{nil}. This is a per-buffer | 259 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, | 260 variable, so altering the variable affects only the current buffer, |
208 but there is a default value which you can change as well. | 261 but there is a default value which you can change as well. |
209 @xref{Locals}. | 262 @xref{Locals}. |
210 | 263 |
264 A tab is not always displayed in the same way. By default, tabs are | |
265 eight columns wide, but some people like to customize their tools to | |
266 use a different tab width. So by using spaces only, you can make sure | |
267 that your file looks the same regardless of the tab width setting. | |
268 | |
211 @findex tabify | 269 @findex tabify |
212 @findex untabify | 270 @findex untabify |
213 There are also commands to convert tabs to spaces or vice versa, always | 271 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 | 272 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 | 273 region for sequences of spaces, and converts sequences of at least three |