]> code.delx.au - gnu-emacs/blob - man/text.texi
Delete some index entries.
[gnu-emacs] / man / text.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 86, 87, 93, 94, 95, 97, 2000
3 @c Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Text, Programs, Indentation, Top
6 @chapter Commands for Human Languages
7 @cindex text
8 @cindex manipulating text
9
10 The term @dfn{text} has two widespread meanings in our area of the
11 computer field. One is data that is a sequence of characters. Any file
12 that you edit with Emacs is text, in this sense of the word. The other
13 meaning is more restrictive: a sequence of characters in a human language
14 for humans to read (possibly after processing by a text formatter), as
15 opposed to a program or commands for a program.
16
17 Human languages have syntactic/stylistic conventions that can be
18 supported or used to advantage by editor commands: conventions involving
19 words, sentences, paragraphs, and capital letters. This chapter
20 describes Emacs commands for all of these things. There are also
21 commands for @dfn{filling}, which means rearranging the lines of a
22 paragraph to be approximately equal in length. The commands for moving
23 over and killing words, sentences and paragraphs, while intended
24 primarily for editing text, are also often useful for editing programs.
25
26 Emacs has several major modes for editing human-language text. If the
27 file contains text pure and simple, use Text mode, which customizes
28 Emacs in small ways for the syntactic conventions of text. Outline mode
29 provides special commands for operating on text with an outline
30 structure.
31 @iftex
32 @xref{Outline Mode}.
33 @end iftex
34
35 For text which contains embedded commands for text formatters, Emacs
36 has other major modes, each for a particular text formatter. Thus, for
37 input to @TeX{}, you would use @TeX{}
38 @iftex
39 mode (@pxref{TeX Mode}).
40 @end iftex
41 @ifinfo
42 mode.
43 @end ifinfo
44 For input to nroff, use Nroff mode.
45
46 Instead of using a text formatter, you can edit formatted text in
47 WYSIWYG style (``what you see is what you get''), with Enriched mode.
48 Then the formatting appears on the screen in Emacs while you edit.
49 @iftex
50 @xref{Formatted Text}.
51 @end iftex
52
53 The ``automatic typing'' features may be useful when writing text.
54 @xref{Top, Autotyping, autotype, Features for Automatic Typing}.
55
56 @menu
57 * Words:: Moving over and killing words.
58 * Sentences:: Moving over and killing sentences.
59 * Paragraphs:: Moving over paragraphs.
60 * Pages:: Moving over pages.
61 * Filling:: Filling or justifying text.
62 * Case:: Changing the case of text.
63 * Text Mode:: The major modes for editing text files.
64 * Outline Mode:: Editing outlines.
65 * TeX Mode:: Editing input to the formatter TeX.
66 * Nroff Mode:: Editing input to the formatter nroff.
67 * Formatted Text:: Editing formatted text directly in WYSIWYG fashion.
68 @end menu
69
70 @node Words
71 @section Words
72 @cindex words
73 @cindex Meta commands and words
74
75 Emacs has commands for moving over or operating on words. By convention,
76 the keys for them are all Meta characters.
77
78 @c widecommands
79 @table @kbd
80 @item M-f
81 Move forward over a word (@code{forward-word}).
82 @item M-b
83 Move backward over a word (@code{backward-word}).
84 @item M-d
85 Kill up to the end of a word (@code{kill-word}).
86 @item M-@key{DEL}
87 Kill back to the beginning of a word (@code{backward-kill-word}).
88 @item M-@@
89 Mark the end of the next word (@code{mark-word}).
90 @item M-t
91 Transpose two words or drag a word across other words
92 (@code{transpose-words}).
93 @end table
94
95 Notice how these keys form a series that parallels the character-based
96 @kbd{C-f}, @kbd{C-b}, @kbd{C-d}, @key{DEL} and @kbd{C-t}. @kbd{M-@@} is
97 cognate to @kbd{C-@@}, which is an alias for @kbd{C-@key{SPC}}.
98
99 @kindex M-f
100 @kindex M-b
101 @findex forward-word
102 @findex backward-word
103 The commands @kbd{M-f} (@code{forward-word}) and @kbd{M-b}
104 (@code{backward-word}) move forward and backward over words. These
105 Meta characters are thus analogous to the corresponding control
106 characters, @kbd{C-f} and @kbd{C-b}, which move over single characters
107 in the text. The analogy extends to numeric arguments, which serve as
108 repeat counts. @kbd{M-f} with a negative argument moves backward, and
109 @kbd{M-b} with a negative argument moves forward. Forward motion
110 stops right after the last letter of the word, while backward motion
111 stops right before the first letter.@refill
112
113 @kindex M-d
114 @findex kill-word
115 @kbd{M-d} (@code{kill-word}) kills the word after point. To be
116 precise, it kills everything from point to the place @kbd{M-f} would
117 move to. Thus, if point is in the middle of a word, @kbd{M-d} kills
118 just the part after point. If some punctuation comes between point and the
119 next word, it is killed along with the word. (If you wish to kill only the
120 next word but not the punctuation before it, simply do @kbd{M-f} to get
121 the end, and kill the word backwards with @kbd{M-@key{DEL}}.)
122 @kbd{M-d} takes arguments just like @kbd{M-f}.
123
124 @findex backward-kill-word
125 @kindex M-DEL
126 @kbd{M-@key{DEL}} (@code{backward-kill-word}) kills the word before
127 point. It kills everything from point back to where @kbd{M-b} would
128 move to. If point is after the space in @w{@samp{FOO, BAR}}, then
129 @w{@samp{FOO, }} is killed. (If you wish to kill just @samp{FOO}, and
130 not the comma and the space, use @kbd{M-b M-d} instead of
131 @kbd{M-@key{DEL}}.)
132
133 @kindex M-t
134 @findex transpose-words
135 @kbd{M-t} (@code{transpose-words}) exchanges the word before or
136 containing point with the following word. The delimiter characters between
137 the words do not move. For example, @w{@samp{FOO, BAR}} transposes into
138 @w{@samp{BAR, FOO}} rather than @samp{@w{BAR FOO,}}. @xref{Transpose}, for
139 more on transposition and on arguments to transposition commands.
140
141 @kindex M-@@
142 @findex mark-word
143 To operate on the next @var{n} words with an operation which applies
144 between point and mark, you can either set the mark at point and then move
145 over the words, or you can use the command @kbd{M-@@} (@code{mark-word})
146 which does not move point, but sets the mark where @kbd{M-f} would move
147 to. @kbd{M-@@} accepts a numeric argument that says how many words to
148 scan for the place to put the mark. In Transient Mark mode, this command
149 activates the mark.
150
151 The word commands' understanding of syntax is completely controlled by
152 the syntax table. Any character can, for example, be declared to be a word
153 delimiter. @xref{Syntax}.
154
155 @node Sentences
156 @section Sentences
157 @cindex sentences
158 @cindex manipulating sentences
159
160 The Emacs commands for manipulating sentences and paragraphs are mostly
161 on Meta keys, so as to be like the word-handling commands.
162
163 @table @kbd
164 @item M-a
165 Move back to the beginning of the sentence (@code{backward-sentence}).
166 @item M-e
167 Move forward to the end of the sentence (@code{forward-sentence}).
168 @item M-k
169 Kill forward to the end of the sentence (@code{kill-sentence}).
170 @item C-x @key{DEL}
171 Kill back to the beginning of the sentence (@code{backward-kill-sentence}).
172 @end table
173
174 @kindex M-a
175 @kindex M-e
176 @findex backward-sentence
177 @findex forward-sentence
178 The commands @kbd{M-a} and @kbd{M-e} (@code{backward-sentence} and
179 @code{forward-sentence}) move to the beginning and end of the current
180 sentence, respectively. They were chosen to resemble @kbd{C-a} and
181 @kbd{C-e}, which move to the beginning and end of a line. Unlike them,
182 @kbd{M-a} and @kbd{M-e} if repeated or given numeric arguments move over
183 successive sentences.
184
185 Moving backward over a sentence places point just before the first
186 character of the sentence; moving forward places point right after the
187 punctuation that ends the sentence. Neither one moves over the
188 whitespace at the sentence boundary.
189
190 @kindex M-k
191 @kindex C-x DEL
192 @findex kill-sentence
193 @findex backward-kill-sentence
194 Just as @kbd{C-a} and @kbd{C-e} have a kill command, @kbd{C-k}, to go
195 with them, so @kbd{M-a} and @kbd{M-e} have a corresponding kill command
196 @kbd{M-k} (@code{kill-sentence}) which kills from point to the end of
197 the sentence. With minus one as an argument it kills back to the
198 beginning of the sentence. Larger arguments serve as a repeat count.
199 There is also a command, @kbd{C-x @key{DEL}}
200 (@code{backward-kill-sentence}), for killing back to the beginning of a
201 sentence. This command is useful when you change your mind in the
202 middle of composing text.@refill
203
204 The sentence commands assume that you follow the American typist's
205 convention of putting two spaces at the end of a sentence; they consider
206 a sentence to end wherever there is a @samp{.}, @samp{?} or @samp{!}
207 followed by the end of a line or two spaces, with any number of
208 @samp{)}, @samp{]}, @samp{'}, or @samp{"} characters allowed in between.
209 A sentence also begins or ends wherever a paragraph begins or ends.
210
211 @vindex sentence-end
212 The variable @code{sentence-end} controls recognition of the end of a
213 sentence. It is a regexp that matches the last few characters of a
214 sentence, together with the whitespace following the sentence. Its
215 normal value is
216
217 @example
218 "[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*"
219 @end example
220
221 @noindent
222 This example is explained in the section on regexps. @xref{Regexps}.
223
224 If you want to use just one space between sentences, you should
225 set @code{sentence-end} to this value:
226
227 @example
228 "[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*"
229 @end example
230
231 @noindent
232 You should also set the variable @code{sentence-end-double-space} to
233 @code{nil} so that the fill commands expect and leave just one space at
234 the end of a sentence. Note that this makes it impossible to
235 distinguish between periods that end sentences and those that indicate
236 abbreviations.
237
238 @node Paragraphs
239 @section Paragraphs
240 @cindex paragraphs
241 @cindex manipulating paragraphs
242 @kindex M-@{
243 @kindex M-@}
244 @findex backward-paragraph
245 @findex forward-paragraph
246
247 The Emacs commands for manipulating paragraphs are also Meta keys.
248
249 @table @kbd
250 @item M-@{
251 Move back to previous paragraph beginning (@code{backward-paragraph}).
252 @item M-@}
253 Move forward to next paragraph end (@code{forward-paragraph}).
254 @item M-h
255 Put point and mark around this or next paragraph (@code{mark-paragraph}).
256 @end table
257
258 @kbd{M-@{} moves to the beginning of the current or previous
259 paragraph, while @kbd{M-@}} moves to the end of the current or next
260 paragraph. Blank lines and text-formatter command lines separate
261 paragraphs and are not considered part of any paragraph. In Fundamental
262 mode, but not in Text mode, an indented line also starts a new
263 paragraph. (If a paragraph is preceded by a blank line, these commands
264 treat that blank line as the beginning of the paragraph.)
265
266 In major modes for programs, paragraphs begin and end only at blank
267 lines. This makes the paragraph commands continue to be useful even
268 though there are no paragraphs per se.
269
270 When there is a fill prefix, then paragraphs are delimited by all lines
271 which don't start with the fill prefix. @xref{Filling}.
272
273 @kindex M-h
274 @findex mark-paragraph
275 When you wish to operate on a paragraph, you can use the command
276 @kbd{M-h} (@code{mark-paragraph}) to set the region around it. Thus,
277 for example, @kbd{M-h C-w} kills the paragraph around or after point.
278 The @kbd{M-h} command puts point at the beginning and mark at the end of
279 the paragraph point was in. In Transient Mark mode, it activates the
280 mark. If point is between paragraphs (in a run of blank lines, or at a
281 boundary), the paragraph following point is surrounded by point and
282 mark. If there are blank lines preceding the first line of the
283 paragraph, one of these blank lines is included in the region.
284
285 @vindex paragraph-start
286 @vindex paragraph-separate
287 The precise definition of a paragraph boundary is controlled by the
288 variables @code{paragraph-separate} and @code{paragraph-start}. The
289 value of @code{paragraph-start} is a regexp that should match any line
290 that either starts or separates paragraphs. The value of
291 @code{paragraph-separate} is another regexp that should match only lines
292 that separate paragraphs without being part of any paragraph (for
293 example, blank lines). Lines that start a new paragraph and are
294 contained in it must match only @code{paragraph-start}, not
295 @code{paragraph-separate}. For example, in Fundamental mode,
296 @code{paragraph-start} is @code{"[ @t{\}t@t{\}n@t{\}f]"} and
297 @code{paragraph-separate} is @code{"[ @t{\}t@t{\}f]*$"}.@refill
298
299 Normally it is desirable for page boundaries to separate paragraphs.
300 The default values of these variables recognize the usual separator for
301 pages.
302
303 @node Pages
304 @section Pages
305
306 @cindex pages
307 @cindex formfeed
308 Files are often thought of as divided into @dfn{pages} by the
309 @dfn{formfeed} character (ASCII control-L, octal code 014). When you
310 print hardcopy for a file, this character forces a page break; thus,
311 each page of the file goes on a separate page on paper. Most Emacs
312 commands treat the page-separator character just like any other
313 character: you can insert it with @kbd{C-q C-l}, and delete it with
314 @key{DEL}. Thus, you are free to paginate your file or not. However,
315 since pages are often meaningful divisions of the file, Emacs provides
316 commands to move over them and operate on them.
317
318 @c WideCommands
319 @table @kbd
320 @item C-x [
321 Move point to previous page boundary (@code{backward-page}).
322 @item C-x ]
323 Move point to next page boundary (@code{forward-page}).
324 @item C-x C-p
325 Put point and mark around this page (or another page) (@code{mark-page}).
326 @item C-x l
327 Count the lines in this page (@code{count-lines-page}).
328 @end table
329
330 @kindex C-x [
331 @kindex C-x ]
332 @findex forward-page
333 @findex backward-page
334 The @kbd{C-x [} (@code{backward-page}) command moves point to immediately
335 after the previous page delimiter. If point is already right after a page
336 delimiter, it skips that one and stops at the previous one. A numeric
337 argument serves as a repeat count. The @kbd{C-x ]} (@code{forward-page})
338 command moves forward past the next page delimiter.
339
340 @kindex C-x C-p
341 @findex mark-page
342 The @kbd{C-x C-p} command (@code{mark-page}) puts point at the
343 beginning of the current page and the mark at the end. The page
344 delimiter at the end is included (the mark follows it). The page
345 delimiter at the front is excluded (point follows it). @kbd{C-x C-p
346 C-w} is a handy way to kill a page to move it elsewhere. If you move to
347 another page delimiter with @kbd{C-x [} and @kbd{C-x ]}, then yank the
348 killed page, all the pages will be properly delimited once again. The
349 reason @kbd{C-x C-p} includes only the following page delimiter in the
350 region is to ensure that.
351
352 A numeric argument to @kbd{C-x C-p} is used to specify which page to go
353 to, relative to the current one. Zero means the current page. One means
354 the next page, and @minus{}1 means the previous one.
355
356 @kindex C-x l
357 @findex count-lines-page
358 The @kbd{C-x l} command (@code{count-lines-page}) is good for deciding
359 where to break a page in two. It prints in the echo area the total number
360 of lines in the current page, and then divides it up into those preceding
361 the current line and those following, as in
362
363 @example
364 Page has 96 (72+25) lines
365 @end example
366
367 @noindent
368 Notice that the sum is off by one; this is correct if point is not at the
369 beginning of a line.
370
371 @vindex page-delimiter
372 The variable @code{page-delimiter} controls where pages begin. Its
373 value is a regexp that matches the beginning of a line that separates
374 pages. The normal value of this variable is @code{"^@t{\}f"}, which
375 matches a formfeed character at the beginning of a line.
376
377 @node Filling
378 @section Filling Text
379 @cindex filling text
380
381 @dfn{Filling} text means breaking it up into lines that fit a
382 specified width. Emacs does filling in two ways. In Auto Fill mode,
383 inserting text with self-inserting characters also automatically fills
384 it. There are also explicit fill commands that you can use when editing
385 text leaves it unfilled. When you edit formatted text, you can specify
386 a style of filling for each portion of the text (@pxref{Formatted
387 Text}).
388
389 @menu
390 * Auto Fill:: Auto Fill mode breaks long lines automatically.
391 * Refill:: Keeping paragraphs filled.
392 * Fill Commands:: Commands to refill paragraphs and center lines.
393 * Fill Prefix:: Filling paragraphs that are indented
394 or in a comment, etc.
395 * Adaptive Fill:: How Emacs can determine the fill prefix automatically.
396 @end menu
397
398 @node Auto Fill
399 @subsection Auto Fill Mode
400 @cindex Auto Fill mode
401 @cindex mode, Auto Fill
402 @cindex word wrap
403
404 @dfn{Auto Fill} mode is a minor mode in which lines are broken
405 automatically when they become too wide. Breaking happens only when
406 you type a @key{SPC} or @key{RET}.
407
408 @table @kbd
409 @item M-x auto-fill-mode
410 Enable or disable Auto Fill mode.
411 @item @key{SPC}
412 @itemx @key{RET}
413 In Auto Fill mode, break lines when appropriate.
414 @end table
415
416 @findex auto-fill-mode
417 @kbd{M-x auto-fill-mode} turns Auto Fill mode on if it was off, or off
418 if it was on. With a positive numeric argument it always turns Auto
419 Fill mode on, and with a negative argument always turns it off. You can
420 see when Auto Fill mode is in effect by the presence of the word
421 @samp{Fill} in the mode line, inside the parentheses. Auto Fill mode is
422 a minor mode which is enabled or disabled for each buffer individually.
423 @xref{Minor Modes}.
424
425 In Auto Fill mode, lines are broken automatically at spaces when they
426 get longer than the desired width. Line breaking and rearrangement
427 takes place only when you type @key{SPC} or @key{RET}. If you wish to
428 insert a space or newline without permitting line-breaking, type
429 @kbd{C-q @key{SPC}} or @kbd{C-q C-j} (recall that a newline is really a
430 control-J). Also, @kbd{C-o} inserts a newline without line breaking.
431
432 Auto Fill mode works well with programming-language modes, because it
433 indents new lines with @key{TAB}. If a line ending in a comment gets
434 too long, the text of the comment is split into two comment lines.
435 Optionally, new comment delimiters are inserted at the end of the first
436 line and the beginning of the second so that each line is a separate
437 comment; the variable @code{comment-multi-line} controls the choice
438 (@pxref{Comments}).
439
440 Adaptive filling (see the following section) works for Auto Filling as
441 well as for explicit fill commands. It takes a fill prefix
442 automatically from the second or first line of a paragraph.
443
444 Auto Fill mode does not refill entire paragraphs; it can break lines but
445 cannot merge lines. So editing in the middle of a paragraph can result in
446 a paragraph that is not correctly filled. The easiest way to make the
447 paragraph properly filled again is usually with the explicit fill commands.
448 @ifinfo
449 @xref{Fill Commands}.
450 @end ifinfo
451
452 Many users like Auto Fill mode and want to use it in all text files.
453 The section on init files says how to arrange this permanently for yourself.
454 @xref{Init File}.
455
456 @node Refill
457 @subsection Refill Mode
458 @cindex refilling text, word processor style
459 @cindex modes, Refill
460 @cindex Refill minor mode
461
462 Refill minor mode provides support for keeping paragraphs filled as
463 you type or modify them in other ways. It provides an effect similar
464 to typical word processor behaviour. This works by running a
465 paragraph-filling command at suitable times.
466
467 When you are typing text, only characters which normally trigger
468 auto filling, like the space character, will trigger refilling. This
469 is to avoid making it too slow. Apart from self-inserting characters,
470 other commands which modify the text cause refilling.
471
472 The current implementation is preliminary and probably not robust.
473 We expect to improve on it.
474
475 @node Fill Commands
476 @subsection Explicit Fill Commands
477
478 @table @kbd
479 @item M-q
480 Fill current paragraph (@code{fill-paragraph}).
481 @item C-x f
482 Set the fill column (@code{set-fill-column}).
483 @item M-x fill-region
484 Fill each paragraph in the region (@code{fill-region}).
485 @item M-x fill-region-as-paragraph
486 Fill the region, considering it as one paragraph.
487 @item M-s
488 Center a line.
489 @end table
490
491 @kindex M-q
492 @findex fill-paragraph
493 To refill a paragraph, use the command @kbd{M-q}
494 (@code{fill-paragraph}). This operates on the paragraph that point is
495 inside, or the one after point if point is between paragraphs.
496 Refilling works by removing all the line-breaks, then inserting new ones
497 where necessary.
498
499 @findex fill-region
500 To refill many paragraphs, use @kbd{M-x fill-region}, which
501 divides the region into paragraphs and fills each of them.
502
503 @findex fill-region-as-paragraph
504 @kbd{M-q} and @code{fill-region} use the same criteria as @kbd{M-h}
505 for finding paragraph boundaries (@pxref{Paragraphs}). For more
506 control, you can use @kbd{M-x fill-region-as-paragraph}, which refills
507 everything between point and mark. This command deletes any blank lines
508 within the region, so separate blocks of text end up combined into one
509 block.@refill
510
511 @cindex justification
512 A numeric argument to @kbd{M-q} causes it to @dfn{justify} the text as
513 well as filling it. This means that extra spaces are inserted to make
514 the right margin line up exactly at the fill column. To remove the
515 extra spaces, use @kbd{M-q} with no argument. (Likewise for
516 @code{fill-region}.) Another way to control justification, and choose
517 other styles of filling, is with the @code{justification} text property;
518 see @ref{Format Justification}.
519
520 @kindex M-s @r{(Text mode)}
521 @cindex centering
522 @findex center-line
523 The command @kbd{M-s} (@code{center-line}) centers the current line
524 within the current fill column. With an argument @var{n}, it centers
525 @var{n} lines individually and moves past them.
526
527 @vindex fill-column
528 @kindex C-x f
529 @findex set-fill-column
530 The maximum line width for filling is in the variable
531 @code{fill-column}. Altering the value of @code{fill-column} makes it
532 local to the current buffer; until that time, the default value is in
533 effect. The default is initially 70. @xref{Locals}. The easiest way
534 to set @code{fill-column} is to use the command @kbd{C-x f}
535 (@code{set-fill-column}). With a numeric argument, it uses that as the
536 new fill column. With just @kbd{C-u} as argument, it sets
537 @code{fill-column} to the current horizontal position of point.
538
539 Emacs commands normally consider a period followed by two spaces or by
540 a newline as the end of a sentence; a period followed by just one space
541 indicates an abbreviation and not the end of a sentence. To preserve
542 the distinction between these two ways of using a period, the fill
543 commands do not break a line after a period followed by just one space.
544
545 @vindex sentence-end-double-space
546 If the variable @code{sentence-end-double-space} is @code{nil}, the
547 fill commands expect and leave just one space at the end of a sentence.
548 Ordinarily this variable is @code{t}, so the fill commands insist on
549 two spaces for the end of a sentence, as explained above. @xref{Sentences}.
550
551 @vindex colon-double-space
552 If the variable @code{colon-double-space} is non-@code{nil}, the
553 fill commands put two spaces after a colon.
554
555 @vindex sentence-end-without-period
556 Some languages do not use period to indicate end of sentence. For
557 example, a sentence in Thai text ends with double space but without a
558 period. Set the variable @code{sentence-end-without-period} to
559 @code{t} to tell the sentence commands that a period is not necessary.
560
561 @node Fill Prefix
562 @subsection The Fill Prefix
563
564 @cindex fill prefix
565 To fill a paragraph in which each line starts with a special marker
566 (which might be a few spaces, giving an indented paragraph), you can use
567 the @dfn{fill prefix} feature. The fill prefix is a string that Emacs
568 expects every line to start with, and which is not included in filling.
569 You can specify a fill prefix explicitly; Emacs can also deduce the
570 fill prefix automatically (@pxref{Adaptive Fill}).
571
572 @table @kbd
573 @item C-x .
574 Set the fill prefix (@code{set-fill-prefix}).
575 @item M-q
576 Fill a paragraph using current fill prefix (@code{fill-paragraph}).
577 @item M-x fill-individual-paragraphs
578 Fill the region, considering each change of indentation as starting a
579 new paragraph.
580 @item M-x fill-nonuniform-paragraphs
581 Fill the region, considering only paragraph-separator lines as starting
582 a new paragraph.
583 @end table
584
585 @kindex C-x .
586 @findex set-fill-prefix
587 To specify a fill prefix, move to a line that starts with the desired
588 prefix, put point at the end of the prefix, and give the command
589 @w{@kbd{C-x .}}@: (@code{set-fill-prefix}). That's a period after the
590 @kbd{C-x}. To turn off the fill prefix, specify an empty prefix: type
591 @w{@kbd{C-x .}}@: with point at the beginning of a line.@refill
592
593 When a fill prefix is in effect, the fill commands remove the fill
594 prefix from each line before filling and insert it on each line after
595 filling. Auto Fill mode also inserts the fill prefix automatically when
596 it makes a new line. The @kbd{C-o} command inserts the fill prefix on
597 new lines it creates, when you use it at the beginning of a line
598 (@pxref{Blank Lines}). Conversely, the command @kbd{M-^} deletes the
599 prefix (if it occurs) after the newline that it deletes
600 (@pxref{Indentation}).
601
602 For example, if @code{fill-column} is 40 and you set the fill prefix
603 to @samp{;; }, then @kbd{M-q} in the following text
604
605 @example
606 ;; This is an
607 ;; example of a paragraph
608 ;; inside a Lisp-style comment.
609 @end example
610
611 @noindent
612 produces this:
613
614 @example
615 ;; This is an example of a paragraph
616 ;; inside a Lisp-style comment.
617 @end example
618
619 Lines that do not start with the fill prefix are considered to start
620 paragraphs, both in @kbd{M-q} and the paragraph commands; this gives
621 good results for paragraphs with hanging indentation (every line
622 indented except the first one). Lines which are blank or indented once
623 the prefix is removed also separate or start paragraphs; this is what
624 you want if you are writing multi-paragraph comments with a comment
625 delimiter on each line.
626
627 @findex fill-individual-paragraphs
628 You can use @kbd{M-x fill-individual-paragraphs} to set the fill
629 prefix for each paragraph automatically. This command divides the
630 region into paragraphs, treating every change in the amount of
631 indentation as the start of a new paragraph, and fills each of these
632 paragraphs. Thus, all the lines in one ``paragraph'' have the same
633 amount of indentation. That indentation serves as the fill prefix for
634 that paragraph.
635
636 @findex fill-nonuniform-paragraphs
637 @kbd{M-x fill-nonuniform-paragraphs} is a similar command that divides
638 the region into paragraphs in a different way. It considers only
639 paragraph-separating lines (as defined by @code{paragraph-separate}) as
640 starting a new paragraph. Since this means that the lines of one
641 paragraph may have different amounts of indentation, the fill prefix
642 used is the smallest amount of indentation of any of the lines of the
643 paragraph. This gives good results with styles that indent a paragraph's
644 first line more or less that the rest of the paragraph.
645
646 @vindex fill-prefix
647 The fill prefix is stored in the variable @code{fill-prefix}. Its value
648 is a string, or @code{nil} when there is no fill prefix. This is a
649 per-buffer variable; altering the variable affects only the current buffer,
650 but there is a default value which you can change as well. @xref{Locals}.
651
652 The @code{indentation} text property provides another way to control
653 the amount of indentation paragraphs receive. @xref{Format Indentation}.
654
655 @node Adaptive Fill
656 @subsection Adaptive Filling
657
658 @cindex adaptive filling
659 The fill commands can deduce the proper fill prefix for a paragraph
660 automatically in certain cases: either whitespace or certain punctuation
661 characters at the beginning of a line are propagated to all lines of the
662 paragraph.
663
664 If the paragraph has two or more lines, the fill prefix is taken from
665 the paragraph's second line, but only if it appears on the first line as
666 well.
667
668 If a paragraph has just one line, fill commands @emph{may} take a
669 prefix from that line. The decision is complicated because there are
670 three reasonable things to do in such a case:
671
672 @itemize @bullet
673 @item
674 Use the first line's prefix on all the lines of the paragraph.
675
676 @item
677 Indent subsequent lines with whitespace, so that they line up under the
678 text that follows the prefix on the first line, but don't actually copy
679 the prefix from the first line.
680
681 @item
682 Don't do anything special with the second and following lines.
683 @end itemize
684
685 All three of these styles of formatting are commonly used. So the
686 fill commands try to determine what you would like, based on the prefix
687 that appears and on the major mode. Here is how.
688
689 @vindex adaptive-fill-first-line-regexp
690 If the prefix found on the first line matches
691 @code{adaptive-fill-first-line-regexp}, or if it appears to be a
692 comment-starting sequence (this depends on the major mode), then the
693 prefix found is used for filling the paragraph, provided it would not
694 act as a paragraph starter on subsequent lines.
695
696 Otherwise, the prefix found is converted to an equivalent number of
697 spaces, and those spaces are used as the fill prefix for the rest of the
698 lines, provided they would not act as a paragraph starter on subsequent
699 lines.
700
701 In Text mode, and other modes where only blank lines and page
702 delimiters separate paragraphs, the prefix chosen by adaptive filling
703 never acts as a paragraph starter, so it can always be used for filling.
704
705 @vindex adaptive-fill-mode
706 @vindex adaptive-fill-regexp
707 The variable @code{adaptive-fill-regexp} determines what kinds of line
708 beginnings can serve as a fill prefix: any characters at the start of
709 the line that match this regular expression are used. If you set the
710 variable @code{adaptive-fill-mode} to @code{nil}, the fill prefix is
711 never chosen automatically.
712
713 @vindex adaptive-fill-function
714 You can specify more complex ways of choosing a fill prefix
715 automatically by setting the variable @code{adaptive-fill-function} to a
716 function. This function is called with point after the left margin of a
717 line, and it should return the appropriate fill prefix based on that
718 line. If it returns @code{nil}, that means it sees no fill prefix in
719 that line.
720
721 @node Case
722 @section Case Conversion Commands
723 @cindex case conversion
724
725 Emacs has commands for converting either a single word or any arbitrary
726 range of text to upper case or to lower case.
727
728 @c WideCommands
729 @table @kbd
730 @item M-l
731 Convert following word to lower case (@code{downcase-word}).
732 @item M-u
733 Convert following word to upper case (@code{upcase-word}).
734 @item M-c
735 Capitalize the following word (@code{capitalize-word}).
736 @item C-x C-l
737 Convert region to lower case (@code{downcase-region}).
738 @item C-x C-u
739 Convert region to upper case (@code{upcase-region}).
740 @end table
741
742 @kindex M-l
743 @kindex M-u
744 @kindex M-c
745 @cindex words, case conversion
746 @cindex converting text to upper or lower case
747 @cindex capitalizing words
748 @findex downcase-word
749 @findex upcase-word
750 @findex capitalize-word
751 The word conversion commands are the most useful. @kbd{M-l}
752 (@code{downcase-word}) converts the word after point to lower case, moving
753 past it. Thus, repeating @kbd{M-l} converts successive words.
754 @kbd{M-u} (@code{upcase-word}) converts to all capitals instead, while
755 @kbd{M-c} (@code{capitalize-word}) puts the first letter of the word
756 into upper case and the rest into lower case. All these commands convert
757 several words at once if given an argument. They are especially convenient
758 for converting a large amount of text from all upper case to mixed case,
759 because you can move through the text using @kbd{M-l}, @kbd{M-u} or
760 @kbd{M-c} on each word as appropriate, occasionally using @kbd{M-f} instead
761 to skip a word.
762
763 When given a negative argument, the word case conversion commands apply
764 to the appropriate number of words before point, but do not move point.
765 This is convenient when you have just typed a word in the wrong case: you
766 can give the case conversion command and continue typing.
767
768 If a word case conversion command is given in the middle of a word, it
769 applies only to the part of the word which follows point. This is just
770 like what @kbd{M-d} (@code{kill-word}) does. With a negative argument,
771 case conversion applies only to the part of the word before point.
772
773 @kindex C-x C-l
774 @kindex C-x C-u
775 @findex downcase-region
776 @findex upcase-region
777 The other case conversion commands are @kbd{C-x C-u}
778 (@code{upcase-region}) and @kbd{C-x C-l} (@code{downcase-region}), which
779 convert everything between point and mark to the specified case. Point and
780 mark do not move.
781
782 The region case conversion commands @code{upcase-region} and
783 @code{downcase-region} are normally disabled. This means that they ask
784 for confirmation if you try to use them. When you confirm, you may
785 enable the command, which means it will not ask for confirmation again.
786 @xref{Disabling}.
787
788 @node Text Mode
789 @section Text Mode
790 @cindex Text mode
791 @cindex mode, Text
792 @findex text-mode
793
794 When you edit files of text in a human language, it's more convenient
795 to use Text mode rather than Fundamental mode. To enter Text mode, type
796 @kbd{M-x text-mode}.
797
798 In Text mode, only blank lines and page delimiters separate
799 paragraphs. As a result, paragraphs can be indented, and adaptive
800 filling determines what indentation to use when filling a paragraph.
801 @xref{Adaptive Fill}.
802
803 @kindex TAB @r{(Text mode)}
804 Text mode defines @key{TAB} to run @code{indent-relative}
805 (@pxref{Indentation}), so that you can conveniently indent a line like
806 the previous line. When the previous line is not indented,
807 @code{indent-relative} runs @code{tab-to-tab-stop}, which uses Emacs tab
808 stops that you can set (@pxref{Tab Stops}).
809
810 Text mode turns off the features concerned with comments except when
811 you explicitly invoke them. It changes the syntax table so that periods
812 are not considered part of a word, while apostrophes, backspaces and
813 underlines are considered part of words.
814
815 @cindex Paragraph-Indent Text mode
816 @cindex mode, Paragraph-Indent Text
817 @findex paragraph-indent-text-mode
818 @findex paragraph-indent-minor-mode
819 If you indent the first lines of paragraphs, then you should use
820 Paragraph-Indent Text mode rather than Text mode. In this mode, you do
821 not need to have blank lines between paragraphs, because the first-line
822 indentation is sufficient to start a paragraph; however paragraphs in
823 which every line is indented are not supported. Use @kbd{M-x
824 paragraph-indent-text-mode} to enter this mode. Use @kbd{M-x
825 paragraph-indent-minor-mode} to enter an equivalent minor mode, for
826 instance during mail composition.
827
828 @kindex M-TAB @r{(Text mode)}
829 Text mode, and all the modes based on it, define @kbd{M-@key{TAB}} as
830 the command @code{ispell-complete-word}, which performs completion of
831 the partial word in the buffer before point, using the spelling
832 dictionary as the space of possible words. @xref{Spelling}.
833
834 @vindex text-mode-hook
835 Entering Text mode runs the hook @code{text-mode-hook}. Other major
836 modes related to Text mode also run this hook, followed by hooks of
837 their own; this includes Paragraph-Indent Text mode, Nroff mode, @TeX{}
838 mode, Outline mode, and Mail mode. Hook functions on
839 @code{text-mode-hook} can look at the value of @code{major-mode} to see
840 which of these modes is actually being entered. @xref{Hooks}.
841
842 @ifinfo
843 Emacs provides two other modes for editing text that is to be passed
844 through a text formatter to produce fancy formatted printed output.
845 @xref{Nroff Mode}, for editing input to the formatter nroff.
846 @xref{TeX Mode}, for editing input to the formatter TeX.
847
848 Another mode is used for editing outlines. It allows you to view the
849 text at various levels of detail. You can view either the outline
850 headings alone or both headings and text; you can also hide some of the
851 headings at lower levels from view to make the high level structure more
852 visible. @xref{Outline Mode}.
853 @end ifinfo
854
855 @node Outline Mode
856 @section Outline Mode
857 @cindex Outline mode
858 @cindex mode, Outline
859 @cindex selective display
860 @cindex invisible lines
861
862 @findex outline-mode
863 @findex outline-minor-mode
864 @vindex outline-minor-mode-prefix
865 Outline mode is a major mode much like Text mode but intended for
866 editing outlines. It allows you to make parts of the text temporarily
867 invisible so that you can see the outline structure. Type @kbd{M-x
868 outline-mode} to switch to Outline mode as the major mode of the current
869 buffer.
870
871 When Outline mode makes a line invisible, the line does not appear on
872 the screen. The screen appears exactly as if the invisible line were
873 deleted, except that an ellipsis (three periods in a row) appears at the
874 end of the previous visible line (only one ellipsis no matter how many
875 invisible lines follow).
876
877 Editing commands that operate on lines, such as @kbd{C-n} and
878 @kbd{C-p}, treat the text of the invisible line as part of the previous
879 visible line. Killing an entire visible line, including its terminating
880 newline, really kills all the following invisible lines along with it.
881
882 Outline minor mode provides the same commands as the major mode,
883 Outline mode, but you can use it in conjunction with other major modes.
884 Type @kbd{M-x outline-minor-mode} to enable the Outline minor mode in
885 the current buffer. You can also specify this in the text of a file,
886 with a file local variable of the form @samp{mode: outline-minor}
887 (@pxref{File Variables}).
888
889 @kindex C-c @@ @r{(Outline minor mode)}
890 The major mode, Outline mode, provides special key bindings on the
891 @kbd{C-c} prefix. Outline minor mode provides similar bindings with
892 @kbd{C-c @@} as the prefix; this is to reduce the conflicts with the
893 major mode's special commands. (The variable
894 @code{outline-minor-mode-prefix} controls the prefix used.)
895
896 @vindex outline-mode-hook
897 Entering Outline mode runs the hook @code{text-mode-hook} followed by
898 the hook @code{outline-mode-hook} (@pxref{Hooks}).
899
900 @menu
901 * Format: Outline Format. What the text of an outline looks like.
902 * Motion: Outline Motion. Special commands for moving through
903 outlines.
904 * Visibility: Outline Visibility. Commands to control what is visible.
905 * Views: Outline Views. Outlines and multiple views.
906 * Foldout:: Folding editing.
907 @end menu
908
909 @node Outline Format
910 @subsection Format of Outlines
911
912 @cindex heading lines (Outline mode)
913 @cindex body lines (Outline mode)
914 Outline mode assumes that the lines in the buffer are of two types:
915 @dfn{heading lines} and @dfn{body lines}. A heading line represents a
916 topic in the outline. Heading lines start with one or more stars; the
917 number of stars determines the depth of the heading in the outline
918 structure. Thus, a heading line with one star is a major topic; all the
919 heading lines with two stars between it and the next one-star heading
920 are its subtopics; and so on. Any line that is not a heading line is a
921 body line. Body lines belong with the preceding heading line. Here is
922 an example:
923
924 @example
925 * Food
926 This is the body,
927 which says something about the topic of food.
928
929 ** Delicious Food
930 This is the body of the second-level header.
931
932 ** Distasteful Food
933 This could have
934 a body too, with
935 several lines.
936
937 *** Dormitory Food
938
939 * Shelter
940 Another first-level topic with its header line.
941 @end example
942
943 A heading line together with all following body lines is called
944 collectively an @dfn{entry}. A heading line together with all following
945 deeper heading lines and their body lines is called a @dfn{subtree}.
946
947 @vindex outline-regexp
948 You can customize the criterion for distinguishing heading lines
949 by setting the variable @code{outline-regexp}. Any line whose
950 beginning has a match for this regexp is considered a heading line.
951 Matches that start within a line (not at the left margin) do not count.
952 The length of the matching text determines the level of the heading;
953 longer matches make a more deeply nested level. Thus, for example,
954 if a text formatter has commands @samp{@@chapter}, @samp{@@section}
955 and @samp{@@subsection} to divide the document into chapters and
956 sections, you could make those lines count as heading lines by
957 setting @code{outline-regexp} to @samp{"@@chap\\|@@\\(sub\\)*section"}.
958 Note the trick: the two words @samp{chapter} and @samp{section} are equally
959 long, but by defining the regexp to match only @samp{chap} we ensure
960 that the length of the text matched on a chapter heading is shorter,
961 so that Outline mode will know that sections are contained in chapters.
962 This works as long as no other command starts with @samp{@@chap}.
963
964 @vindex outline-level
965 You can change the rule for calculating the level of a heading line
966 by setting the variable @code{outline-level}. The value of
967 @code{outline-level} should be a function that takes no arguments and
968 returns the level of the current heading. Some major modes such as C,
969 Nroff, and Emacs Lisp mode set this variable and @code{outline-regexp}
970 in order to work with Outline minor mode.
971
972 @node Outline Motion
973 @subsection Outline Motion Commands
974
975 Outline mode provides special motion commands that move backward and
976 forward to heading lines.
977
978 @table @kbd
979 @item C-c C-n
980 Move point to the next visible heading line
981 (@code{outline-next-visible-heading}).
982 @item C-c C-p
983 Move point to the previous visible heading line
984 (@code{outline-previous-visible-heading}).
985 @item C-c C-f
986 Move point to the next visible heading line at the same level
987 as the one point is on (@code{outline-forward-same-level}).
988 @item C-c C-b
989 Move point to the previous visible heading line at the same level
990 (@code{outline-backward-same-level}).
991 @item C-c C-u
992 Move point up to a lower-level (more inclusive) visible heading line
993 (@code{outline-up-heading}).
994 @end table
995
996 @findex outline-next-visible-heading
997 @findex outline-previous-visible-heading
998 @kindex C-c C-n @r{(Outline mode)}
999 @kindex C-c C-p @r{(Outline mode)}
1000 @kbd{C-c C-n} (@code{outline-next-visible-heading}) moves down to the next
1001 heading line. @kbd{C-c C-p} (@code{outline-previous-visible-heading}) moves
1002 similarly backward. Both accept numeric arguments as repeat counts. The
1003 names emphasize that invisible headings are skipped, but this is not really
1004 a special feature. All editing commands that look for lines ignore the
1005 invisible lines automatically.@refill
1006
1007 @findex outline-up-heading
1008 @findex outline-forward-same-level
1009 @findex outline-backward-same-level
1010 @kindex C-c C-f @r{(Outline mode)}
1011 @kindex C-c C-b @r{(Outline mode)}
1012 @kindex C-c C-u @r{(Outline mode)}
1013 More powerful motion commands understand the level structure of headings.
1014 @kbd{C-c C-f} (@code{outline-forward-same-level}) and
1015 @kbd{C-c C-b} (@code{outline-backward-same-level}) move from one
1016 heading line to another visible heading at the same depth in
1017 the outline. @kbd{C-c C-u} (@code{outline-up-heading}) moves
1018 backward to another heading that is less deeply nested.
1019
1020 @node Outline Visibility
1021 @subsection Outline Visibility Commands
1022
1023 The other special commands of outline mode are used to make lines visible
1024 or invisible. Their names all start with @code{hide} or @code{show}.
1025 Most of them fall into pairs of opposites. They are not undoable; instead,
1026 you can undo right past them. Making lines visible or invisible is simply
1027 not recorded by the undo mechanism.
1028
1029 @table @kbd
1030 @item C-c C-t
1031 Make all body lines in the buffer invisible (@code{hide-body}).
1032 @item C-c C-a
1033 Make all lines in the buffer visible (@code{show-all}).
1034 @item C-c C-d
1035 Make everything under this heading invisible, not including this
1036 heading itself (@code{hide-subtree}).
1037 @item C-c C-s
1038 Make everything under this heading visible, including body,
1039 subheadings, and their bodies (@code{show-subtree}).
1040 @item C-c C-l
1041 Make the body of this heading line, and of all its subheadings,
1042 invisible (@code{hide-leaves}).
1043 @item C-c C-k
1044 Make all subheadings of this heading line, at all levels, visible
1045 (@code{show-branches}).
1046 @item C-c C-i
1047 Make immediate subheadings (one level down) of this heading line
1048 visible (@code{show-children}).
1049 @item C-c C-c
1050 Make this heading line's body invisible (@code{hide-entry}).
1051 @item C-c C-e
1052 Make this heading line's body visible (@code{show-entry}).
1053 @item C-c C-q
1054 Hide everything except the top @var{n} levels of heading lines
1055 (@code{hide-sublevels}).
1056 @item C-c C-o
1057 Hide everything except for the heading or body that point is in, plus
1058 the headings leading up from there to the top level of the outline
1059 (@code{hide-other}).
1060 @end table
1061
1062 @findex hide-entry
1063 @findex show-entry
1064 @kindex C-c C-c @r{(Outline mode)}
1065 @kindex C-c C-e @r{(Outline mode)}
1066 Two commands that are exact opposites are @kbd{C-c C-c}
1067 (@code{hide-entry}) and @kbd{C-c C-e} (@code{show-entry}). They are
1068 used with point on a heading line, and apply only to the body lines of
1069 that heading. Subheadings and their bodies are not affected.
1070
1071 @findex hide-subtree
1072 @findex show-subtree
1073 @kindex C-c C-s @r{(Outline mode)}
1074 @kindex C-c C-d @r{(Outline mode)}
1075 @cindex subtree (Outline mode)
1076 Two more powerful opposites are @kbd{C-c C-d} (@code{hide-subtree}) and
1077 @kbd{C-c C-s} (@code{show-subtree}). Both expect to be used when point is
1078 on a heading line, and both apply to all the lines of that heading's
1079 @dfn{subtree}: its body, all its subheadings, both direct and indirect, and
1080 all of their bodies. In other words, the subtree contains everything
1081 following this heading line, up to and not including the next heading of
1082 the same or higher rank.@refill
1083
1084 @findex hide-leaves
1085 @findex show-branches
1086 @kindex C-c C-l @r{(Outline mode)}
1087 @kindex C-c C-k @r{(Outline mode)}
1088 Intermediate between a visible subtree and an invisible one is having
1089 all the subheadings visible but none of the body. There are two
1090 commands for doing this, depending on whether you want to hide the
1091 bodies or make the subheadings visible. They are @kbd{C-c C-l}
1092 (@code{hide-leaves}) and @kbd{C-c C-k} (@code{show-branches}).
1093
1094 @kindex C-c C-i @r{(Outline mode)}
1095 @findex show-children
1096 A little weaker than @code{show-branches} is @kbd{C-c C-i}
1097 (@code{show-children}). It makes just the direct subheadings
1098 visible---those one level down. Deeper subheadings remain invisible, if
1099 they were invisible.@refill
1100
1101 @findex hide-body
1102 @findex show-all
1103 @kindex C-c C-t @r{(Outline mode)}
1104 @kindex C-c C-a @r{(Outline mode)}
1105 Two commands have a blanket effect on the whole file. @kbd{C-c C-t}
1106 (@code{hide-body}) makes all body lines invisible, so that you see just
1107 the outline structure. @kbd{C-c C-a} (@code{show-all}) makes all lines
1108 visible. These commands can be thought of as a pair of opposites even
1109 though @kbd{C-c C-a} applies to more than just body lines.
1110
1111 @findex hide-sublevels
1112 @kindex C-c C-q @r{(Outline mode)}
1113 The command @kbd{C-c C-q} (@code{hide-sublevels}) hides all but the
1114 top level headings. With a numeric argument @var{n}, it hides everything
1115 except the top @var{n} levels of heading lines.
1116
1117 @findex hide-other
1118 @kindex C-c C-o @r{(Outline mode)}
1119 The command @kbd{C-c C-o} (@code{hide-other}) hides everything except
1120 the heading or body text that point is in, plus its parents (the headers
1121 leading up from there to top level in the outline).
1122
1123 You can turn off the use of ellipses at the ends of visible lines by
1124 setting @code{selective-display-ellipses} to @code{nil}. Then there is
1125 no visible indication of the presence of invisible lines.
1126
1127 When incremental search finds text that is hidden by Outline mode,
1128 it makes that part of the buffer visible. If you exit the search
1129 at that position, the text remains visible.
1130
1131 @node Outline Views
1132 @subsection Viewing One Outline in Multiple Views
1133
1134 @cindex multiple views of outline
1135 @cindex views of an outline
1136 @cindex outline with multiple views
1137 @cindex indirect buffers and outlines
1138 You can display two views of a single outline at the same time, in
1139 different windows. To do this, you must create an indirect buffer using
1140 @kbd{M-x make-indirect-buffer}. The first argument of this command is
1141 the existing outline buffer name, and its second argument is the name to
1142 use for the new indirect buffer. @xref{Indirect Buffers}.
1143
1144 Once the indirect buffer exists, you can display it in a window in the
1145 normal fashion, with @kbd{C-x 4 b} or other Emacs commands. The Outline
1146 mode commands to show and hide parts of the text operate on each buffer
1147 independently; as a result, each buffer can have its own view. If you
1148 want more than two views on the same outline, create additional indirect
1149 buffers.
1150
1151 @node Foldout
1152 @subsection Folding Editing
1153
1154 @cindex folding editing
1155 The Foldout package extends Outline mode and Outline minor mode with
1156 ``folding'' commands. The idea of folding is that you zoom in on a
1157 nested portion of the outline, while hiding its relatives at higher
1158 levels.
1159
1160 Consider an Outline mode buffer all the text and subheadings under
1161 level-1 headings hidden. To look at what is hidden under one of these
1162 headings, you could use @kbd{C-c C-e} (@kbd{M-x show-entry}) to expose
1163 the body, or @kbd{C-c C-i} to expose the child (level-2) headings.
1164
1165 @kindex C-c C-z
1166 @findex foldout-zoom-subtree
1167 With Foldout, you use @kbd{C-c C-z} (@kbd{M-x foldout-zoom-subtree}).
1168 This exposes the body and child subheadings, and narrows the buffer so
1169 that only the level-1 heading, the body and the level-2 headings are
1170 visible. Now to look under one of the level-2 headings, position the
1171 cursor on it and use @kbd{C-c C-z} again. This exposes the level-2 body
1172 and its level-3 child subheadings and narrows the buffer again. Zooming
1173 in on successive subheadings can be done as much as you like. A string
1174 in the modeline shows how deep you've gone.
1175
1176 When zooming in on a heading, to see only the child subheadings specify
1177 a numeric argument: @kbd{C-u C-c C-z}. The number of levels of children
1178 can be specified too (compare @kbd{M-x show-children}), e.g.@: @kbd{M-2
1179 C-c C-z} exposes two levels of child subheadings. Alternatively, the
1180 body can be spcified with a negative argument: @kbd{M-- C-c C-z}. The
1181 whole subtree can be expanded, similarly to @kbd{C-c C-s} (@kbd{M-x
1182 show-subtree}), by specifying a zero argument: @kbd{M-0 C-c C-z}.
1183
1184 While you're zoomed in, you can still use Outline mode's exposure and
1185 hiding functions without disturbing Foldout. Also, since the buffer is
1186 narrowed, ``global'' editing actions will only affect text under the
1187 zoomed-in heading. This is useful for restricting changes to a
1188 particular chapter or section of your document.
1189
1190 @kindex C-c C-x
1191 @findex foldout-exit-fold
1192 To unzoom (exit) a fold, use @kbd{C-c C-x} (@kbd{M-x foldout-exit-fold}).
1193 This hides all the text and subheadings under the top-level heading and
1194 returns you to the previous view of the buffer. Specifying a numeric
1195 argument exits that many levels of folds. Specifying a zero argument exits all
1196 folds.
1197
1198 To cancel the narrowing of a fold without hiding the text and
1199 subheadings, specify a negative argument. For example, @kbd{M--2 C-c
1200 C-x} exits two folds and leaves the text and subheadings exposed.
1201
1202 Foldout mode also provides mouse commands for entering and exiting
1203 folds, and for showing and hiding text:
1204
1205 @table @asis
1206 @item @kbd{M-C-Mouse-1} zooms in on the heading clicked on
1207 @table @asis
1208 @item single click
1209 expose body.
1210 @item double click
1211 expose subheadings.
1212 @item triple click
1213 expose body and subheadings.
1214 @item quad click
1215 expose entire subtree.
1216 @end table
1217 @item @kbd{M-C-Mouse-2} exposes text under the heading clicked on
1218 @table @r
1219 @item single click
1220 expose body.
1221 @item double click
1222 expose subheadings.
1223 @item triple click
1224 expose body and subheadings.
1225 @item quad click
1226 expose entire subtree.
1227 @end table
1228 @item @kbd{M-C-Mouse-3} hides text under the heading clicked on or exits fold
1229 @table @r
1230 @item single click
1231 hide subtree.
1232 @item double click
1233 exit fold and hide text.
1234 @item triple click
1235 exit fold without hiding text.
1236 @item quad click
1237 exit all folds and hide text.
1238 @end table
1239 @end table
1240
1241 @vindex foldout-mouse-modifiers
1242 You can specify different modifier keys (instead of
1243 @kbd{Control-Meta-}) by setting @code{foldout-mouse-modifiers}; but if
1244 you have already loaded the @file{foldout.el} library, you must reload
1245 it in order for this to take effect.
1246
1247 To use the Foldout package, you can type @kbd{M-x load-library
1248 @key{RET} foldout @key{RET}}; or you can arrange for to do that
1249 automatically by putting this in your @file{.emacs} file:
1250
1251 @example
1252 (eval-after-load "outline" '(require 'foldout))
1253 @end example
1254
1255 @node TeX Mode, Nroff Mode, Outline Mode, Text
1256 @section @TeX{} Mode
1257 @cindex @TeX{} mode
1258 @cindex La@TeX{} mode
1259 @cindex Sli@TeX{} mode
1260 @cindex mode, @TeX{}
1261 @cindex mode, La@TeX{}
1262 @cindex mode, Sli@TeX{}
1263 @findex tex-mode
1264 @findex plain-tex-mode
1265 @findex latex-mode
1266 @findex slitex-mode
1267
1268 @TeX{} is a powerful text formatter written by Donald Knuth; it is also
1269 free, like GNU Emacs. La@TeX{} is a simplified input format for @TeX{},
1270 implemented by @TeX{} macros; it comes with @TeX{}. Sli@TeX{} is a special
1271 form of La@TeX{}.@footnote{Sli@TeX{} is obsoleted by the @samp{slides}
1272 document class in recent La@TeX{} versions.}
1273
1274 Emacs has a special @TeX{} mode for editing @TeX{} input files.
1275 It provides facilities for checking the balance of delimiters and for
1276 invoking @TeX{} on all or part of the file.
1277
1278 @vindex tex-default-mode
1279 @TeX{} mode has three variants, Plain @TeX{} mode, La@TeX{} mode, and
1280 Sli@TeX{} mode (these three distinct major modes differ only slightly).
1281 They are designed for editing the three different formats. The command
1282 @kbd{M-x tex-mode} looks at the contents of the buffer to determine
1283 whether the contents appear to be either La@TeX{} input or Sli@TeX{}
1284 input; if so, it selects the appropriate mode. If the file contents do
1285 not appear to be La@TeX{} or Sli@TeX{}, it selects Plain @TeX{} mode.
1286 If the contents are insufficient to determine this, the variable
1287 @code{tex-default-mode} controls which mode is used.
1288
1289 When @kbd{M-x tex-mode} does not guess right, you can use the commands
1290 @kbd{M-x plain-tex-mode}, @kbd{M-x latex-mode}, and @kbd{M-x
1291 slitex-mode} to select explicitly the particular variants of @TeX{}
1292 mode.
1293
1294 @menu
1295 * Editing: TeX Editing. Special commands for editing in TeX mode.
1296 * LaTeX: LaTeX Editing. Additional commands for LaTeX input files.
1297 * Printing: TeX Print. Commands for printing part of a file with TeX.
1298 * Misc: TeX Misc. Customization of TeX mode, and related features.
1299 @end menu
1300
1301 @node TeX Editing
1302 @subsection @TeX{} Editing Commands
1303
1304 Here are the special commands provided in @TeX{} mode for editing the
1305 text of the file.
1306
1307 @table @kbd
1308 @item "
1309 Insert, according to context, either @samp{``} or @samp{"} or
1310 @samp{''} (@code{tex-insert-quote}).
1311 @item C-j
1312 Insert a paragraph break (two newlines) and check the previous
1313 paragraph for unbalanced braces or dollar signs
1314 (@code{tex-terminate-paragraph}).
1315 @item M-x tex-validate-region
1316 Check each paragraph in the region for unbalanced braces or dollar signs.
1317 @item C-c @{
1318 Insert @samp{@{@}} and position point between them (@code{tex-insert-braces}).
1319 @item C-c @}
1320 Move forward past the next unmatched close brace (@code{up-list}).
1321 @end table
1322
1323 @findex tex-insert-quote
1324 @kindex " @r{(@TeX{} mode)}
1325 In @TeX{}, the character @samp{"} is not normally used; we use
1326 @samp{``} to start a quotation and @samp{''} to end one. To make
1327 editing easier under this formatting convention, @TeX{} mode overrides
1328 the normal meaning of the key @kbd{"} with a command that inserts a pair
1329 of single-quotes or backquotes (@code{tex-insert-quote}). To be
1330 precise, this command inserts @samp{``} after whitespace or an open
1331 brace, @samp{"} after a backslash, and @samp{''} after any other
1332 character.
1333
1334 If you need the character @samp{"} itself in unusual contexts, use
1335 @kbd{C-q} to insert it. Also, @kbd{"} with a numeric argument always
1336 inserts that number of @samp{"} characters. You can turn off the
1337 feature of @kbd{"} expansion by eliminating that binding in the local
1338 map (@pxref{Key Bindings}).
1339
1340 In @TeX{} mode, @samp{$} has a special syntax code which attempts to
1341 understand the way @TeX{} math mode delimiters match. When you insert a
1342 @samp{$} that is meant to exit math mode, the position of the matching
1343 @samp{$} that entered math mode is displayed for a second. This is the
1344 same feature that displays the open brace that matches a close brace that
1345 is inserted. However, there is no way to tell whether a @samp{$} enters
1346 math mode or leaves it; so when you insert a @samp{$} that enters math
1347 mode, the previous @samp{$} position is shown as if it were a match, even
1348 though they are actually unrelated.
1349
1350 @findex tex-insert-braces
1351 @kindex C-c @{ @r{(@TeX{} mode)}
1352 @findex up-list
1353 @kindex C-c @} @r{(@TeX{} mode)}
1354 @TeX{} uses braces as delimiters that must match. Some users prefer
1355 to keep braces balanced at all times, rather than inserting them
1356 singly. Use @kbd{C-c @{} (@code{tex-insert-braces}) to insert a pair of
1357 braces. It leaves point between the two braces so you can insert the
1358 text that belongs inside. Afterward, use the command @kbd{C-c @}}
1359 (@code{up-list}) to move forward past the close brace.
1360
1361 @findex tex-validate-region
1362 @findex tex-terminate-paragraph
1363 @kindex C-j @r{(@TeX{} mode)}
1364 There are two commands for checking the matching of braces. @kbd{C-j}
1365 (@code{tex-terminate-paragraph}) checks the paragraph before point, and
1366 inserts two newlines to start a new paragraph. It prints a message in
1367 the echo area if any mismatch is found. @kbd{M-x tex-validate-region}
1368 checks a region, paragraph by paragraph. The errors are listed in the
1369 @samp{*Occur*} buffer, and you can use @kbd{C-c C-c} or @kbd{Mouse-2} in
1370 that buffer to go to a particular mismatch.
1371
1372 Note that Emacs commands count square brackets and parentheses in
1373 @TeX{} mode, not just braces. This is not strictly correct for the
1374 purpose of checking @TeX{} syntax. However, parentheses and square
1375 brackets are likely to be used in text as matching delimiters and it is
1376 useful for the various motion commands and automatic match display to
1377 work with them.
1378
1379 @node LaTeX Editing
1380 @subsection La@TeX{} Editing Commands
1381
1382 La@TeX{} mode, and its variant, Sli@TeX{} mode, provide a few extra
1383 features not applicable to plain @TeX{}.
1384
1385 @table @kbd
1386 @item C-c C-o
1387 Insert @samp{\begin} and @samp{\end} for La@TeX{} block and position
1388 point on a line between them (@code{tex-latex-block}).
1389 @item C-c C-e
1390 Close the innermost La@TeX{} block not yet closed
1391 (@code{tex-close-latex-block}).
1392 @end table
1393
1394 @findex tex-latex-block
1395 @kindex C-c C-o @r{(La@TeX{} mode)}
1396 @vindex latex-block-names
1397 In La@TeX{} input, @samp{\begin} and @samp{\end} commands are used to
1398 group blocks of text. To insert a @samp{\begin} and a matching
1399 @samp{\end} (on a new line following the @samp{\begin}), use @kbd{C-c
1400 C-o} (@code{tex-latex-block}). A blank line is inserted between the
1401 two, and point is left there. You can use completion when you enter the
1402 block type; to specify additional block type names beyond the standard
1403 list, set the variable @code{latex-block-names}. For example, here's
1404 how to add @samp{theorem}, @samp{corollary}, and @samp{proof}:
1405
1406 @example
1407 (setq latex-block-names '("theorem" "corollary" "proof"))
1408 @end example
1409
1410 @findex tex-close-latex-block
1411 @kindex C-c C-e @r{(La@TeX{} mode)}
1412 In La@TeX{} input, @samp{\begin} and @samp{\end} commands must
1413 balance. You can use @kbd{C-c C-e} (@code{tex-close-latex-block}) to
1414 insert automatically a matching @samp{\end} to match the last unmatched
1415 @samp{\begin}. It indents the @samp{\end} to match the corresponding
1416 @samp{\begin}. It inserts a newline after @samp{\end} if point is at
1417 the beginning of a line.
1418
1419 @node TeX Print
1420 @subsection @TeX{} Printing Commands
1421
1422 You can invoke @TeX{} as an inferior of Emacs on either the entire
1423 contents of the buffer or just a region at a time. Running @TeX{} in
1424 this way on just one chapter is a good way to see what your changes
1425 look like without taking the time to format the entire file.
1426
1427 @table @kbd
1428 @item C-c C-r
1429 Invoke @TeX{} on the current region, together with the buffer's header
1430 (@code{tex-region}).
1431 @item C-c C-b
1432 Invoke @TeX{} on the entire current buffer (@code{tex-buffer}).
1433 @item C-c @key{TAB}
1434 Invoke Bib@TeX{} on the current file (@code{tex-bibtex-file}).
1435 @item C-c C-f
1436 Invoke @TeX{} on the current file (@code{tex-file}).
1437 @item C-c C-l
1438 Recenter the window showing output from the inferior @TeX{} so that
1439 the last line can be seen (@code{tex-recenter-output-buffer}).
1440 @item C-c C-k
1441 Kill the @TeX{} subprocess (@code{tex-kill-job}).
1442 @item C-c C-p
1443 Print the output from the last @kbd{C-c C-r}, @kbd{C-c C-b}, or @kbd{C-c
1444 C-f} command (@code{tex-print}).
1445 @item C-c C-v
1446 Preview the output from the last @kbd{C-c C-r}, @kbd{C-c C-b}, or @kbd{C-c
1447 C-f} command (@code{tex-view}).
1448 @item C-c C-q
1449 Show the printer queue (@code{tex-show-print-queue}).
1450 @end table
1451
1452 @findex tex-buffer
1453 @kindex C-c C-b @r{(@TeX{} mode)}
1454 @findex tex-print
1455 @kindex C-c C-p @r{(@TeX{} mode)}
1456 @findex tex-view
1457 @kindex C-c C-v @r{(@TeX{} mode)}
1458 @findex tex-show-print-queue
1459 @kindex C-c C-q @r{(@TeX{} mode)}
1460 You can pass the current buffer through an inferior @TeX{} by means of
1461 @kbd{C-c C-b} (@code{tex-buffer}). The formatted output appears in a
1462 temporary file; to print it, type @kbd{C-c C-p} (@code{tex-print}).
1463 Afterward, you can use @kbd{C-c C-q} (@code{tex-show-print-queue}) to
1464 view the progress of your output towards being printed. If your terminal
1465 has the ability to display @TeX{} output files, you can preview the
1466 output on the terminal with @kbd{C-c C-v} (@code{tex-view}).
1467
1468 @cindex @env{TEXINPUTS} environment variable
1469 @vindex tex-directory
1470 You can specify the directory to use for running @TeX{} by setting the
1471 variable @code{tex-directory}. @code{"."} is the default value. If
1472 your environment variable @env{TEXINPUTS} contains relative directory
1473 names, or if your files contains @samp{\input} commands with relative
1474 file names, then @code{tex-directory} @emph{must} be @code{"."} or you
1475 will get the wrong results. Otherwise, it is safe to specify some other
1476 directory, such as @code{"/tmp"}.
1477
1478 @vindex tex-run-command
1479 @vindex latex-run-command
1480 @vindex slitex-run-command
1481 @vindex tex-dvi-print-command
1482 @vindex tex-dvi-view-command
1483 @vindex tex-show-queue-command
1484 If you want to specify which shell commands are used in the inferior @TeX{},
1485 you can do so by setting the values of the variables @code{tex-run-command},
1486 @code{latex-run-command}, @code{slitex-run-command},
1487 @code{tex-dvi-print-command}, @code{tex-dvi-view-command}, and
1488 @code{tex-show-queue-command}. You @emph{must} set the value of
1489 @code{tex-dvi-view-command} for your particular terminal; this variable
1490 has no default value. The other variables have default values that may
1491 (or may not) be appropriate for your system.
1492
1493 Normally, the file name given to these commands comes at the end of
1494 the command string; for example, @samp{latex @var{filename}}. In some
1495 cases, however, the file name needs to be embedded in the command; an
1496 example is when you need to provide the file name as an argument to one
1497 command whose output is piped to another. You can specify where to put
1498 the file name with @samp{*} in the command string. For example,
1499
1500 @example
1501 (setq tex-dvi-print-command "dvips -f * | lpr")
1502 @end example
1503
1504 @findex tex-kill-job
1505 @kindex C-c C-k @r{(@TeX{} mode)}
1506 @findex tex-recenter-output-buffer
1507 @kindex C-c C-l @r{(@TeX{} mode)}
1508 The terminal output from @TeX{}, including any error messages, appears
1509 in a buffer called @samp{*tex-shell*}. If @TeX{} gets an error, you can
1510 switch to this buffer and feed it input (this works as in Shell mode;
1511 @pxref{Interactive Shell}). Without switching to this buffer you can
1512 scroll it so that its last line is visible by typing @kbd{C-c
1513 C-l}.
1514
1515 Type @kbd{C-c C-k} (@code{tex-kill-job}) to kill the @TeX{} process if
1516 you see that its output is no longer useful. Using @kbd{C-c C-b} or
1517 @kbd{C-c C-r} also kills any @TeX{} process still running.@refill
1518
1519 @findex tex-region
1520 @kindex C-c C-r @r{(@TeX{} mode)}
1521 You can also pass an arbitrary region through an inferior @TeX{} by typing
1522 @kbd{C-c C-r} (@code{tex-region}). This is tricky, however, because most files
1523 of @TeX{} input contain commands at the beginning to set parameters and
1524 define macros, without which no later part of the file will format
1525 correctly. To solve this problem, @kbd{C-c C-r} allows you to designate a
1526 part of the file as containing essential commands; it is included before
1527 the specified region as part of the input to @TeX{}. The designated part
1528 of the file is called the @dfn{header}.
1529
1530 @cindex header (@TeX{} mode)
1531 To indicate the bounds of the header in Plain @TeX{} mode, you insert two
1532 special strings in the file. Insert @samp{%**start of header} before the
1533 header, and @samp{%**end of header} after it. Each string must appear
1534 entirely on one line, but there may be other text on the line before or
1535 after. The lines containing the two strings are included in the header.
1536 If @samp{%**start of header} does not appear within the first 100 lines of
1537 the buffer, @kbd{C-c C-r} assumes that there is no header.
1538
1539 In La@TeX{} mode, the header begins with @samp{\documentclass} or
1540 @samp{\documentstyle} and ends with @samp{\begin@{document@}}. These
1541 are commands that La@TeX{} requires you to use in any case, so nothing
1542 special needs to be done to identify the header.
1543
1544 @findex tex-file
1545 @kindex C-c C-f @r{(@TeX{} mode)}
1546 The commands (@code{tex-buffer}) and (@code{tex-region}) do all of their
1547 work in a temporary directory, and do not have available any of the auxiliary
1548 files needed by @TeX{} for cross-references; these commands are generally
1549 not suitable for running the final copy in which all of the cross-references
1550 need to be correct.
1551
1552 When you want the auxiliary files for cross references, use @kbd{C-c
1553 C-f} (@code{tex-file}) which runs @TeX{} on the current buffer's file,
1554 in that file's directory. Before running @TeX{}, it offers to save any
1555 modified buffers. Generally, you need to use (@code{tex-file}) twice to
1556 get the cross-references right.
1557
1558 @vindex tex-start-options-string
1559 The value of the variable @code{tex-start-options-string} specifies
1560 options for the @TeX{} run. The default value causes @TeX{} to run in
1561 nonstopmode. To run @TeX{} interactively, set the variable to @code{""}.
1562
1563 @vindex tex-main-file
1564 Large @TeX{} documents are often split into several files---one main
1565 file, plus subfiles. Running @TeX{} on a subfile typically does not
1566 work; you have to run it on the main file. In order to make
1567 @code{tex-file} useful when you are editing a subfile, you can set the
1568 variable @code{tex-main-file} to the name of the main file. Then
1569 @code{tex-file} runs @TeX{} on that file.
1570
1571 The most convenient way to use @code{tex-main-file} is to specify it
1572 in a local variable list in each of the subfiles. @xref{File
1573 Variables}.
1574
1575 @findex tex-bibtex-file
1576 @kindex C-c TAB @r{(@TeX{} mode)}
1577 @vindex tex-bibtex-command
1578 For La@TeX{} files, you can use Bib@TeX{} to process the auxiliary
1579 file for the current buffer's file. Bib@TeX{} looks up bibliographic
1580 citations in a data base and prepares the cited references for the
1581 bibliography section. The command @kbd{C-c TAB}
1582 (@code{tex-bibtex-file}) runs the shell command
1583 (@code{tex-bibtex-command}) to produce a @samp{.bbl} file for the
1584 current buffer's file. Generally, you need to do @kbd{C-c C-f}
1585 (@code{tex-file}) once to generate the @samp{.aux} file, then do
1586 @kbd{C-c TAB} (@code{tex-bibtex-file}), and then repeat @kbd{C-c C-f}
1587 (@code{tex-file}) twice more to get the cross-references correct.
1588
1589 @node TeX Misc
1590 @subsection @TeX{} Mode Miscellany
1591
1592 @vindex tex-shell-hook
1593 @vindex tex-mode-hook
1594 @vindex latex-mode-hook
1595 @vindex slitex-mode-hook
1596 @vindex plain-tex-mode-hook
1597 Entering any variant of @TeX{} mode runs the hooks
1598 @code{text-mode-hook} and @code{tex-mode-hook}. Then it runs either
1599 @code{plain-tex-mode-hook}, @code{latex-mode-hook}, or
1600 @code{slitex-mode-hook}, whichever is appropriate. Starting the
1601 @TeX{} shell runs the hook @code{tex-shell-hook}. @xref{Hooks}.
1602
1603 @findex iso-iso2tex
1604 @findex iso-tex2iso
1605 @findex iso-iso2gtex
1606 @findex iso-gtex2iso
1607 @cindex Latin-1 @TeX{} encoding
1608 @TeX{} encoding
1609 The commands @kbd{M-x iso-iso2tex}, @kbd{M-x iso-tex2iso}, @kbd{M-x
1610 iso-iso2gtex} and @kbd{M-x iso-gtex2iso} can be used to convert
1611 between Latin-1 encoded files and @TeX{}-encoded equivalents.
1612 @ignore
1613 @c Too cryptic to be useful, too cryptic for me to make it better -- rms.
1614 They
1615 are included by default in the @code{format-alist} variable, so they
1616 can be used with @kbd{M-x format-find-file}, for instance.
1617 @end ignore
1618
1619 @ignore @c Not worth documenting if it is only for Czech -- rms.
1620 @findex tildify-buffer
1621 @findex tildify-region
1622 @cindex ties, @TeX{}, inserting
1623 @cindex hard spaces, @TeX{}, inserting
1624 @cindex SGML
1625 @cindex HTML
1626 The commands @kbd{M-x tildify-buffer} and @kbd{M-x tildify-region}
1627 insert @samp{~} (@dfn{tie}) characters where they are conventionally
1628 required. This is set up for Czech---customize the group
1629 @samp{tildify} for other languages or for other sorts of markup.
1630 @end ignore
1631
1632 @cindex Ref@TeX{} package
1633 @cindex references, La@TeX{}
1634 @cindex La@TeX{} references
1635 For managing all kinds of references for La@TeX{}, you can use
1636 Ref@TeX{}. @xref{Top, , RefTeX, reftex}.
1637
1638 @node Nroff Mode
1639 @section Nroff Mode
1640
1641 @cindex nroff
1642 @findex nroff-mode
1643 Nroff mode is a mode like Text mode but modified to handle nroff commands
1644 present in the text. Invoke @kbd{M-x nroff-mode} to enter this mode. It
1645 differs from Text mode in only a few ways. All nroff command lines are
1646 considered paragraph separators, so that filling will never garble the
1647 nroff commands. Pages are separated by @samp{.bp} commands. Comments
1648 start with backslash-doublequote. Also, three special commands are
1649 provided that are not in Text mode:
1650
1651 @findex forward-text-line
1652 @findex backward-text-line
1653 @findex count-text-lines
1654 @kindex M-n @r{(Nroff mode)}
1655 @kindex M-p @r{(Nroff mode)}
1656 @kindex M-? @r{(Nroff mode)}
1657 @table @kbd
1658 @item M-n
1659 Move to the beginning of the next line that isn't an nroff command
1660 (@code{forward-text-line}). An argument is a repeat count.
1661 @item M-p
1662 Like @kbd{M-n} but move up (@code{backward-text-line}).
1663 @item M-?
1664 Prints in the echo area the number of text lines (lines that are not
1665 nroff commands) in the region (@code{count-text-lines}).
1666 @end table
1667
1668 @findex electric-nroff-mode
1669 The other feature of Nroff mode is that you can turn on Electric Nroff
1670 mode. This is a minor mode that you can turn on or off with @kbd{M-x
1671 electric-nroff-mode} (@pxref{Minor Modes}). When the mode is on, each
1672 time you use @key{RET} to end a line that contains an nroff command that
1673 opens a kind of grouping, the matching nroff command to close that
1674 grouping is automatically inserted on the following line. For example,
1675 if you are at the beginning of a line and type @kbd{.@: ( b @key{RET}},
1676 this inserts the matching command @samp{.)b} on a new line following
1677 point.
1678
1679 If you use Outline minor mode with Nroff mode (@pxref{Outline Mode}),
1680 heading lines are lines of the form @samp{.H} followed by a number (the
1681 header level).
1682
1683 @vindex nroff-mode-hook
1684 Entering Nroff mode runs the hook @code{text-mode-hook}, followed by
1685 the hook @code{nroff-mode-hook} (@pxref{Hooks}).
1686
1687 @node Formatted Text
1688 @section Editing Formatted Text
1689
1690 @cindex Enriched mode
1691 @cindex mode, Enriched
1692 @cindex formatted text
1693 @cindex WYSIWYG
1694 @cindex word processing
1695 @dfn{Enriched mode} is a minor mode for editing files that contain
1696 formatted text in WYSIWYG fashion, as in a word processor. Currently,
1697 formatted text in Enriched mode can specify fonts, colors, underlining,
1698 margins, and types of filling and justification. In the future, we plan
1699 to implement other formatting features as well.
1700
1701 Enriched mode is a minor mode (@pxref{Minor Modes}). Typically it is
1702 used in conjunction with Text mode (@pxref{Text Mode}). However, you
1703 can also use it with other major modes such as Outline mode and
1704 Paragraph-Indent Text mode.
1705
1706 @cindex text/enriched MIME format
1707 Potentially, Emacs can store formatted text files in various file
1708 formats. Currently, only one format is implemented: @dfn{text/enriched}
1709 format, which is defined by the MIME protocol. @xref{Format
1710 Conversion,, Format Conversion, elisp, the Emacs Lisp Reference Manual},
1711 for details of how Emacs recognizes and converts file formats.
1712
1713 The Emacs distribution contains a formatted text file that can serve as
1714 an example. Its name is @file{etc/enriched.doc}. It contains samples
1715 illustrating all the features described in this section. It also
1716 contains a list of ideas for future enhancements.
1717
1718 @menu
1719 * Requesting Formatted Text:: Entering and exiting Enriched mode.
1720 * Hard and Soft Newlines:: There are two different kinds of newlines.
1721 * Editing Format Info:: How to edit text properties.
1722 * Faces: Format Faces. Bold, italic, underline, etc.
1723 * Color: Format Colors. Changing the color of text.
1724 * Indent: Format Indentation. Changing the left and right margins.
1725 * Justification: Format Justification.
1726 Centering, setting text flush with the
1727 left or right margin, etc.
1728 * Other: Format Properties. The "special" text properties submenu.
1729 * Forcing Enriched Mode:: How to force use of Enriched mode.
1730 @end menu
1731
1732 @node Requesting Formatted Text
1733 @subsection Requesting to Edit Formatted Text
1734
1735 Whenever you visit a file that Emacs saved in the text/enriched format,
1736 Emacs automatically converts the formatting information in the file into
1737 Emacs's own internal format (text properties), and turns on Enriched
1738 mode.
1739
1740 @findex enriched-mode
1741 To create a new file of formatted text, first visit the nonexistent
1742 file, then type @kbd{M-x enriched-mode} before you start inserting text.
1743 This command turns on Enriched mode. Do this before you begin inserting
1744 text, to ensure that the text you insert is handled properly.
1745
1746 More generally, the command @code{enriched-mode} turns Enriched mode
1747 on if it was off, and off if it was on. With a prefix argument, this
1748 command turns Enriched mode on if the argument is positive, and turns
1749 the mode off otherwise.
1750
1751 When you save a buffer while Enriched mode is enabled in it, Emacs
1752 automatically converts the text to text/enriched format while writing it
1753 into the file. When you visit the file again, Emacs will automatically
1754 recognize the format, reconvert the text, and turn on Enriched mode
1755 again.
1756
1757 @vindex enriched-fill-after-visiting
1758 Normally, after visiting a file in text/enriched format, Emacs refills
1759 each paragraph to fit the specified right margin. You can turn off this
1760 refilling, to save time, by setting the variable
1761 @code{enriched-fill-after-visiting} to @code{nil} or to @code{ask}.
1762
1763 However, when visiting a file that was saved from Enriched mode, there
1764 is no need for refilling, because Emacs saves the right margin settings
1765 along with the text.
1766
1767 @vindex enriched-translations
1768 You can add annotations for saving additional text properties, which
1769 Emacs normally does not save, by adding to @code{enriched-translations}.
1770 Note that the text/enriched standard requires any non-standard
1771 annotations to have names starting with @samp{x-}, as in
1772 @samp{x-read-only}. This ensures that they will not conflict with
1773 standard annotations that may be added later.
1774
1775 @node Hard and Soft Newlines
1776 @subsection Hard and Soft Newlines
1777 @cindex hard newline
1778 @cindex soft newline
1779 @cindex newlines, hard and soft
1780
1781 In formatted text, Emacs distinguishes between two different kinds of
1782 newlines, @dfn{hard} newlines and @dfn{soft} newlines.
1783
1784 Hard newlines are used to separate paragraphs, or items in a list, or
1785 anywhere that there should always be a line break regardless of the
1786 margins. The @key{RET} command (@code{newline}) and @kbd{C-o}
1787 (@code{open-line}) insert hard newlines.
1788
1789 Soft newlines are used to make text fit between the margins. All the
1790 fill commands, including Auto Fill, insert soft newlines---and they
1791 delete only soft newlines.
1792
1793 Although hard and soft newlines look the same, it is important to bear
1794 the difference in mind. Do not use @key{RET} to break lines in the
1795 middle of filled paragraphs, or else you will get hard newlines that are
1796 barriers to further filling. Instead, let Auto Fill mode break lines,
1797 so that if the text or the margins change, Emacs can refill the lines
1798 properly. @xref{Auto Fill}.
1799
1800 On the other hand, in tables and lists, where the lines should always
1801 remain as you type them, you can use @key{RET} to end lines. For these
1802 lines, you may also want to set the justification style to
1803 @code{unfilled}. @xref{Format Justification}.
1804
1805 @node Editing Format Info
1806 @subsection Editing Format Information
1807
1808 There are two ways to alter the formatting information for a formatted
1809 text file: with keyboard commands, and with the mouse.
1810
1811 The easiest way to add properties to your document is by using the Text
1812 Properties menu. You can get to this menu in two ways: from the Edit
1813 menu in the menu bar, or with @kbd{C-Mouse-2} (hold the @key{CTRL} key
1814 and press the middle mouse button).
1815
1816 Most of the items in the Text Properties menu lead to other submenus.
1817 These are described in the sections that follow. Some items run
1818 commands directly:
1819
1820 @table @code
1821 @findex facemenu-remove-props
1822 @item Remove Properties
1823 Delete from the region all the text properties that the Text Properties
1824 menu works with (@code{facemenu-remove-props}).
1825
1826 @findex facemenu-remove-all
1827 @item Remove All
1828 Delete @emph{all} text properties from the region
1829 (@code{facemenu-remove-all}).
1830
1831 @findex list-text-properties-at
1832 @item List Properties
1833 List all the text properties of the character following point
1834 (@code{list-text-properties-at}).
1835
1836 @item Display Faces
1837 Display a list of all the defined faces.
1838
1839 @item Display Colors
1840 Display a list of all the defined colors.
1841 @end table
1842
1843 @node Format Faces
1844 @subsection Faces in Formatted Text
1845
1846 The Faces submenu lists various Emacs faces including @code{bold},
1847 @code{italic}, and @code{underline}. Selecting one of these adds the
1848 chosen face to the region. @xref{Faces}. You can also specify a face
1849 with these keyboard commands:
1850
1851 @table @kbd
1852 @kindex M-g d @r{(Enriched mode)}
1853 @findex facemenu-set-default
1854 @item M-g d
1855 Set the region, or the next inserted character, to the @code{default} face
1856 (@code{facemenu-set-default}).
1857 @kindex M-g b @r{(Enriched mode)}
1858 @findex facemenu-set-bold
1859 @item M-g b
1860 Set the region, or the next inserted character, to the @code{bold} face
1861 (@code{facemenu-set-bold}).
1862 @kindex M-g i @r{(Enriched mode)}
1863 @findex facemenu-set-italic
1864 @item M-g i
1865 Set the region, or the next inserted character, to the @code{italic} face
1866 (@code{facemenu-set-italic}).
1867 @kindex M-g l @r{(Enriched mode)}
1868 @findex facemenu-set-bold-italic
1869 @item M-g l
1870 Set the region, or the next inserted character, to the @code{bold-italic} face
1871 (@code{facemenu-set-bold-italic}).
1872 @kindex M-g u @r{(Enriched mode)}
1873 @findex facemenu-set-underline
1874 @item M-g u
1875 Set the region, or the next inserted character, to the @code{underline} face
1876 (@code{facemenu-set-underline}).
1877 @kindex M-g o @r{(Enriched mode)}
1878 @findex facemenu-set-face
1879 @item M-g o @var{face} @key{RET}
1880 Set the region, or the next inserted character, to the face @var{face}
1881 (@code{facemenu-set-face}).
1882 @end table
1883
1884 If you use these commands with a prefix argument---or, in Transient Mark
1885 mode, if the region is not active---then these commands specify a face
1886 to use for your next self-inserting input. @xref{Transient Mark}. This
1887 applies to both the keyboard commands and the menu commands.
1888
1889 Enriched mode defines two additional faces: @code{excerpt} and
1890 @code{fixed}. These correspond to codes used in the text/enriched file
1891 format.
1892
1893 The @code{excerpt} face is intended for quotations. This face is the
1894 same as @code{italic} unless you customize it (@pxref{Face Customization}).
1895
1896 The @code{fixed} face is meant to say, ``Use a fixed-width font for this
1897 part of the text.'' Emacs currently supports only fixed-width fonts;
1898 therefore, the @code{fixed} annotation is not necessary now. However,
1899 we plan to support variable width fonts in future Emacs versions, and
1900 other systems that display text/enriched format may not use a
1901 fixed-width font as the default. So if you specifically want a certain
1902 part of the text to use a fixed-width font, you should specify the
1903 @code{fixed} face for that part.
1904
1905 The @code{fixed} face is normally defined to use a different font from
1906 the default. However, different systems have different fonts installed,
1907 so you may need to customize this.
1908
1909 If your terminal cannot display different faces, you will not be able
1910 to see them, but you can still edit documents containing faces. You can
1911 even add faces and colors to documents. They will be visible when the
1912 file is viewed on a terminal that can display them.
1913
1914 @node Format Colors
1915 @subsection Colors in Formatted Text
1916
1917 You can specify foreground and background colors for portions of the
1918 text. There is a menu for specifying the foreground color and a menu
1919 for specifying the background color. Each color menu lists all the
1920 colors that you have used in Enriched mode in the current Emacs session.
1921
1922 If you specify a color with a prefix argument---or, in Transient Mark
1923 mode, if the region is not active---then it applies to your next
1924 self-inserting input. @xref{Transient Mark}. Otherwise, the command
1925 applies to the region.
1926
1927 Each color menu contains one additional item: @samp{Other}. You can use
1928 this item to specify a color that is not listed in the menu; it reads
1929 the color name with the minibuffer. To display list of available colors
1930 and their names, use the @samp{Display Colors} menu item in the Text
1931 Properties menu (@pxref{Editing Format Info}).
1932
1933 Any color that you specify in this way, or that is mentioned in a
1934 formatted text file that you read in, is added to both color menus for
1935 the duration of the Emacs session.
1936
1937 @findex facemenu-set-foreground
1938 @findex facemenu-set-background
1939 There are no key bindings for specifying colors, but you can do so
1940 with the extended commands @kbd{M-x facemenu-set-foreground} and
1941 @kbd{M-x facemenu-set-background}. Both of these commands read the name
1942 of the color with the minibuffer.
1943
1944 @node Format Indentation
1945 @subsection Indentation in Formatted Text
1946
1947 When editing formatted text, you can specify different amounts of
1948 indentation for the right or left margin of an entire paragraph or a
1949 part of a paragraph. The margins you specify automatically affect the
1950 Emacs fill commands (@pxref{Filling}) and line-breaking commands.
1951
1952 The Indentation submenu provides a convenient interface for specifying
1953 these properties. The submenu contains four items:
1954
1955 @table @code
1956 @kindex C-x TAB @r{(Enriched mode)}
1957 @findex increase-left-margin
1958 @item Indent More
1959 Indent the region by 4 columns (@code{increase-left-margin}). In
1960 Enriched mode, this command is also available on @kbd{C-x @key{TAB}}; if
1961 you supply a numeric argument, that says how many columns to add to the
1962 margin (a negative argument reduces the number of columns).
1963
1964 @item Indent Less
1965 Remove 4 columns of indentation from the region.
1966
1967 @item Indent Right More
1968 Make the text narrower by indenting 4 columns at the right margin.
1969
1970 @item Indent Right Less
1971 Remove 4 columns of indentation from the right margin.
1972 @end table
1973
1974 You can use these commands repeatedly to increase or decrease the
1975 indentation.
1976
1977 The most common way to use these commands is to change the indentation
1978 of an entire paragraph. However, that is not the only use. You can
1979 change the margins at any point; the new values take effect at the end
1980 of the line (for right margins) or the beginning of the next line (for
1981 left margins).
1982
1983 This makes it possible to format paragraphs with @dfn{hanging indents},
1984 which means that the first line is indented less than subsequent lines.
1985 To set up a hanging indent, increase the indentation of the region
1986 starting after the first word of the paragraph and running until the end
1987 of the paragraph.
1988
1989 Indenting the first line of a paragraph is easier. Set the margin for
1990 the whole paragraph where you want it to be for the body of the
1991 paragraph, then indent the first line by inserting extra spaces or tabs.
1992
1993 Sometimes, as a result of editing, the filling of a paragraph becomes
1994 messed up---parts of the paragraph may extend past the left or right
1995 margins. When this happens, use @kbd{M-q} (@code{fill-paragraph}) to
1996 refill the paragraph.
1997
1998 @vindex standard-indent
1999 The variable @code{standard-indent} specifies how many columns these
2000 commands should add to or subtract from the indentation. The default
2001 value is 4. The overall default right margin for Enriched mode is
2002 controlled by the variable @code{fill-column}, as usual.
2003
2004 The fill prefix, if any, works in addition to the specified paragraph
2005 indentation: @kbd{C-x .} does not include the specified indentation's
2006 whitespace in the new value for the fill prefix, and the fill commands
2007 look for the fill prefix after the indentation on each line. @xref{Fill
2008 Prefix}.
2009
2010 @node Format Justification
2011 @subsection Justification in Formatted Text
2012
2013 When editing formatted text, you can specify various styles of
2014 justification for a paragraph. The style you specify automatically
2015 affects the Emacs fill commands.
2016
2017 The Justification submenu provides a convenient interface for specifying
2018 the style. The submenu contains five items:
2019
2020 @table @code
2021 @item Flush Left
2022 This is the most common style of justification (at least for English).
2023 Lines are aligned at the left margin but left uneven at the right.
2024
2025 @item Flush Right
2026 This aligns each line with the right margin. Spaces and tabs are added
2027 on the left, if necessary, to make lines line up on the right.
2028
2029 @item Full
2030 This justifies the text, aligning both edges of each line. Justified
2031 text looks very nice in a printed book, where the spaces can all be
2032 adjusted equally, but it does not look as nice with a fixed-width font
2033 on the screen. Perhaps a future version of Emacs will be able to adjust
2034 the width of spaces in a line to achieve elegant justification.
2035
2036 @item Center
2037 This centers every line between the current margins.
2038
2039 @item None
2040 This turns off filling entirely. Each line will remain as you wrote it;
2041 the fill and auto-fill functions will have no effect on text which has
2042 this setting. You can, however, still indent the left margin. In
2043 unfilled regions, all newlines are treated as hard newlines (@pxref{Hard
2044 and Soft Newlines}) .
2045 @end table
2046
2047 In Enriched mode, you can also specify justification from the keyboard
2048 using the @kbd{M-j} prefix character:
2049
2050 @table @kbd
2051 @kindex M-j l @r{(Enriched mode)}
2052 @findex set-justification-left
2053 @item M-j l
2054 Make the region left-filled (@code{set-justification-left}).
2055 @kindex M-j r @r{(Enriched mode)}
2056 @findex set-justification-right
2057 @item M-j r
2058 Make the region right-filled (@code{set-justification-right}).
2059 @kindex M-j f @r{(Enriched mode)}
2060 @findex set-justification-full
2061 @item M-j f
2062 Make the region fully-justified (@code{set-justification-full}).
2063 @kindex M-j c @r{(Enriched mode)}
2064 @kindex M-S @r{(Enriched mode)}
2065 @findex set-justification-center
2066 @item M-j c
2067 @itemx M-S
2068 Make the region centered (@code{set-justification-center}).
2069 @kindex M-j u @r{(Enriched mode)}
2070 @findex set-justification-none
2071 @item M-j u
2072 Make the region unfilled (@code{set-justification-none}).
2073 @end table
2074
2075 Justification styles apply to entire paragraphs. All the
2076 justification-changing commands operate on the paragraph containing
2077 point, or, if the region is active, on all paragraphs which overlap the
2078 region.
2079
2080 @vindex default-justification
2081 The default justification style is specified by the variable
2082 @code{default-justification}. Its value should be one of the symbols
2083 @code{left}, @code{right}, @code{full}, @code{center}, or @code{none}.
2084
2085 @node Format Properties
2086 @subsection Setting Other Text Properties
2087
2088 The Other Properties menu lets you add or remove three other useful text
2089 properties: @code{read-only}, @code{invisible} and @code{intangible}.
2090 The @code{intangible} property disallows moving point within the text,
2091 the @code{invisible} text property hides text from display, and the
2092 @code{read-only} property disallows alteration of the text.
2093
2094 Each of these special properties has a menu item to add it to the
2095 region. The last menu item, @samp{Remove Special}, removes all of these
2096 special properties from the text in the region.
2097
2098 Currently, the @code{invisible} and @code{intangible} properties are
2099 @emph{not} saved in the text/enriched format. The @code{read-only}
2100 property is saved, but it is not a standard part of the text/enriched
2101 format, so other editors may not respect it.
2102
2103 @node Forcing Enriched Mode
2104 @subsection Forcing Enriched Mode
2105
2106 Normally, Emacs knows when you are editing formatted text because it
2107 recognizes the special annotations used in the file that you visited.
2108 However, there are situations in which you must take special actions
2109 to convert file contents or turn on Enriched mode:
2110
2111 @itemize @bullet
2112 @item
2113 When you visit a file that was created with some other editor, Emacs may
2114 not recognize the file as being in the text/enriched format. In this
2115 case, when you visit the file you will see the formatting commands
2116 rather than the formatted text. Type @kbd{M-x format-decode-buffer} to
2117 translate it.
2118
2119 @item
2120 When you @emph{insert} a file into a buffer, rather than visiting it.
2121 Emacs does the necessary conversions on the text which you insert, but
2122 it does not enable Enriched mode. If you wish to do that, type @kbd{M-x
2123 enriched-mode}.
2124 @end itemize
2125
2126 The command @code{format-decode-buffer} translates text in various
2127 formats into Emacs's internal format. It asks you to specify the format
2128 to translate from; however, normally you can type just @key{RET}, which
2129 tells Emacs to guess the format.
2130
2131 @findex format-find-file
2132 If you wish to look at text/enriched file in its raw form, as a
2133 sequence of characters rather than as formatted text, use the @kbd{M-x
2134 find-file-literally} command. This visits a file, like
2135 @code{find-file}, but does not do format conversion. It also inhibits
2136 character code conversion (@pxref{Coding Systems}) and automatic
2137 uncompression (@pxref{Compressed Files}). To disable format conversion
2138 but allow character code conversion and/or automatic uncompression if
2139 appropriate, use @code{format-find-file} with suitable arguments.
2140