]> code.delx.au - gnu-emacs/blob - doc/emacs/text.texi
Remove documentation for Refill and Longlines modes.
[gnu-emacs] / doc / emacs / text.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2011
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 This chapter describes Emacs commands that act on @dfn{text}, by
11 which we mean sequences of characters in a human language (as opposed
12 to, say, a computer programming language). These commands act in ways
13 that take into account the syntactic and stylistic conventions of
14 human languages: conventions involving words, sentences, paragraphs,
15 and capital letters. There are also commands for @dfn{filling}, which
16 means rearranging the lines of a paragraph to be approximately equal
17 in length. These commands, while intended primarily for editing text,
18 are also often useful for editing programs.
19
20 Emacs has several major modes for editing human-language text. If
21 the file contains ordinary text, use Text mode, which customizes Emacs
22 in small ways for the syntactic conventions of text. Outline mode
23 provides special commands for operating on text with an outline
24 structure.
25 @iftex
26 @xref{Outline Mode}.
27 @end iftex
28
29 @cindex nXML mode
30 @cindex mode, XML
31 @cindex mode, nXML
32 @findex nxml-mode
33 Emacs has other major modes for text which contains ``embedded''
34 commands, such as @TeX{} and La@TeX{} (@pxref{TeX Mode}); HTML and
35 SGML (@pxref{HTML Mode}); XML (@pxref{Top, nXML Mode,,nxml-mode, nXML
36 Mode}); and Groff and Nroff (@pxref{Nroff Mode}). In addition, you
37 can edit formatted text in WYSIWYG style (``what you see is what you
38 get''), using Enriched mode (@pxref{Formatted Text}).
39
40 @cindex ASCII art
41 If you need to edit pictures made out of text characters (commonly
42 referred to as ``ASCII art''), use Picture mode, a special major mode
43 for editing such pictures.
44 @iftex
45 @xref{Picture Mode,,, emacs-xtra, Specialized Emacs Features}.
46 @end iftex
47 @ifnottex
48 @xref{Picture Mode}.
49 @end ifnottex
50
51
52 @cindex skeletons
53 @cindex templates
54 @cindex autotyping
55 @cindex automatic typing
56 The ``automatic typing'' features may be useful when writing text.
57 @inforef{Top,, autotype}.
58
59 @menu
60 * Words:: Moving over and killing words.
61 * Sentences:: Moving over and killing sentences.
62 * Paragraphs:: Moving over paragraphs.
63 * Pages:: Moving over pages.
64 * Filling:: Filling or justifying text.
65 * Case:: Changing the case of text.
66 * Text Mode:: The major modes for editing text files.
67 * Outline Mode:: Editing outlines.
68 * TeX Mode:: Editing input to the formatter TeX.
69 * HTML Mode:: Editing HTML and SGML files.
70 * Nroff Mode:: Editing input to the formatter nroff.
71 * Formatted Text:: Editing formatted text directly in WYSIWYG fashion.
72 * Text Based Tables:: Editing text-based tables in WYSIWYG fashion.
73 @end menu
74
75 @node Words
76 @section Words
77 @cindex words
78 @cindex Meta commands and words
79
80 Emacs has commands for moving over or operating on words. By convention,
81 the keys for them are all Meta characters.
82
83 @table @kbd
84 @item M-f
85 Move forward over a word (@code{forward-word}).
86 @item M-b
87 Move backward over a word (@code{backward-word}).
88 @item M-d
89 Kill up to the end of a word (@code{kill-word}).
90 @item M-@key{DEL}
91 Kill back to the beginning of a word (@code{backward-kill-word}).
92 @item M-@@
93 Mark the end of the next word (@code{mark-word}).
94 @item M-t
95 Transpose two words or drag a word across others
96 (@code{transpose-words}).
97 @end table
98
99 Notice how these keys form a series that parallels the character-based
100 @kbd{C-f}, @kbd{C-b}, @kbd{C-d}, @key{DEL} and @kbd{C-t}. @kbd{M-@@} is
101 cognate to @kbd{C-@@}, which is an alias for @kbd{C-@key{SPC}}.
102
103 @kindex M-f
104 @kindex M-b
105 @findex forward-word
106 @findex backward-word
107 The commands @kbd{M-f} (@code{forward-word}) and @kbd{M-b}
108 (@code{backward-word}) move forward and backward over words. These
109 @key{Meta}-based key sequences are analogous to the key sequences
110 @kbd{C-f} and @kbd{C-b}, which move over single characters. The
111 analogy extends to numeric arguments, which serve as repeat counts.
112 @kbd{M-f} with a negative argument moves backward, and @kbd{M-b} with
113 a negative argument moves forward. Forward motion stops right after
114 the last letter of the word, while backward motion stops right before
115 the first letter.
116
117 @kindex M-d
118 @findex kill-word
119 @kbd{M-d} (@code{kill-word}) kills the word after point. To be
120 precise, it kills everything from point to the place @kbd{M-f} would
121 move to. Thus, if point is in the middle of a word, @kbd{M-d} kills
122 just the part after point. If some punctuation comes between point
123 and the next word, it is killed along with the word. (If you wish to
124 kill only the next word but not the punctuation before it, simply do
125 @kbd{M-f} to get the end, and kill the word backwards with
126 @kbd{M-@key{DEL}}.) @kbd{M-d} takes arguments just like @kbd{M-f}.
127
128 @findex backward-kill-word
129 @kindex M-DEL
130 @kbd{M-@key{DEL}} (@code{backward-kill-word}) kills the word before
131 point. It kills everything from point back to where @kbd{M-b} would
132 move to. For instance, if point is after the space in @w{@samp{FOO,
133 BAR}}, it kills @w{@samp{FOO, }}. If you wish to kill just
134 @samp{FOO}, and not the comma and the space, use @kbd{M-b M-d} instead
135 of @kbd{M-@key{DEL}}.
136
137 @c Don't index M-t and transpose-words here, they are indexed in
138 @c fixit.texi, in the node "Transpose".
139 @c @kindex M-t
140 @c @findex transpose-words
141 @kbd{M-t} (@code{transpose-words}) exchanges the word before or
142 containing point with the following word. The delimiter characters between
143 the words do not move. For example, @w{@samp{FOO, BAR}} transposes into
144 @w{@samp{BAR, FOO}} rather than @samp{@w{BAR FOO,}}. @xref{Transpose}, for
145 more on transposition.
146
147 @kindex M-@@
148 @findex mark-word
149 To operate on the next @var{n} words with an operation which acts on
150 the region, use the command @kbd{M-@@} (@code{mark-word}). This
151 command does not move point, but sets the mark where @kbd{M-f} would
152 move to. Once the mark is active, each additional @kbd{M-@@} advances
153 the mark by one additional word. @kbd{M-@@} also accepts a numeric
154 argument that says how many words to scan for the place to put the
155 mark.
156
157 The word commands' understanding of word boundaries is controlled
158 by the syntax table. Any character can, for example, be declared to
159 be a word delimiter. @xref{Syntax}.
160
161 @node Sentences
162 @section Sentences
163 @cindex sentences
164 @cindex manipulating sentences
165
166 The Emacs commands for manipulating sentences and paragraphs are mostly
167 on Meta keys, so as to be like the word-handling commands.
168
169 @table @kbd
170 @item M-a
171 Move back to the beginning of the sentence (@code{backward-sentence}).
172 @item M-e
173 Move forward to the end of the sentence (@code{forward-sentence}).
174 @item M-k
175 Kill forward to the end of the sentence (@code{kill-sentence}).
176 @item C-x @key{DEL}
177 Kill back to the beginning of the sentence (@code{backward-kill-sentence}).
178 @end table
179
180 @kindex M-a
181 @kindex M-e
182 @findex backward-sentence
183 @findex forward-sentence
184 The commands @kbd{M-a} and @kbd{M-e} (@code{backward-sentence} and
185 @code{forward-sentence}) move to the beginning and end of the current
186 sentence, respectively. They were chosen to resemble @kbd{C-a} and
187 @kbd{C-e}, which move to the beginning and end of a line. Unlike
188 them, @kbd{M-a} and @kbd{M-e} move over successive sentences if
189 repeated.
190
191 Moving backward over a sentence places point just before the first
192 character of the sentence; moving forward places point right after the
193 punctuation that ends the sentence. Neither one moves over the
194 whitespace at the sentence boundary.
195
196 @kindex M-k
197 @findex kill-sentence
198 Just as @kbd{C-a} and @kbd{C-e} have a kill command, @kbd{C-k}, to
199 go with them, @kbd{M-a} and @kbd{M-e} have a corresponding kill
200 command: @kbd{M-k} (@code{kill-sentence}) kills from point to the end
201 of the sentence. With a positive numeric argument @var{n}, it kills
202 the next @var{n} sentences; with a negative argument @minus{}@var{n},
203 it kills back to the beginning of the @var{n}th preceding sentence.
204
205 @kindex C-x DEL
206 @findex backward-kill-sentence
207 The @kbd{C-x @key{DEL}} (@code{backward-kill-sentence}) kills back
208 to the beginning of a sentence.
209
210 The sentence commands assume that you follow the American typist's
211 convention of putting two spaces at the end of a sentence; they consider
212 a sentence to end wherever there is a @samp{.}, @samp{?} or @samp{!}
213 followed by the end of a line or two spaces, with any number of
214 @samp{)}, @samp{]}, @samp{'}, or @samp{"} characters allowed in between.
215 A sentence also begins or ends wherever a paragraph begins or ends.
216 It is useful to follow this convention, because it makes a distinction
217 between periods that end a sentence and periods that indicate
218 abbreviations; that enables the Emacs sentence commands to distinguish,
219 too. These commands do not stop for periods that indicate abbreviations.
220
221 @vindex sentence-end-double-space
222 If you want to use just one space between sentences, you can set the
223 variable @code{sentence-end-double-space} to @code{nil} to make the
224 sentence commands stop for single spaces. However, this has a
225 drawback: there is no way to distinguish between periods that end
226 sentences and those that indicate abbreviations. For convenient and
227 reliable editing, we therefore recommend you follow the two-space
228 convention. The variable @code{sentence-end-double-space} also
229 affects filling (@pxref{Fill Commands}) in related ways.
230
231 @vindex sentence-end
232 The variable @code{sentence-end} controls how to recognize the end
233 of a sentence. If non-@code{nil}, its value should be a regular
234 expression, which is used to match the last few characters of a
235 sentence, together with the whitespace following the sentence
236 (@pxref{Regexps}). If the value is @code{nil}, the default, then
237 Emacs computes sentence ends according to various criteria such as the
238 value of @code{sentence-end-double-space}.
239
240 @vindex sentence-end-without-period
241 Some languages do not use periods to indicate the end of a sentence.
242 For example, sentences in Thai end with a double space but without a
243 period. Set the variable @code{sentence-end-without-period} to
244 @code{t} in such cases.
245
246 @node Paragraphs
247 @section Paragraphs
248 @cindex paragraphs
249 @cindex manipulating paragraphs
250 @kindex M-@{
251 @kindex M-@}
252 @findex backward-paragraph
253 @findex forward-paragraph
254
255 The Emacs commands for manipulating paragraphs are also on Meta keys.
256
257 @table @kbd
258 @item M-@{
259 Move back to previous paragraph beginning (@code{backward-paragraph}).
260 @item M-@}
261 Move forward to next paragraph end (@code{forward-paragraph}).
262 @item M-h
263 Put point and mark around this or next paragraph (@code{mark-paragraph}).
264 @end table
265
266 @kbd{M-@{} moves to the beginning of the current or previous
267 paragraph, while @kbd{M-@}} moves to the end of the current or next
268 paragraph. Blank lines and text-formatter command lines separate
269 paragraphs and are not considered part of any paragraph. If there is
270 a blank line before the paragraph, @kbd{M-@{} moves to the blank line,
271 because that is convenient in practice.
272
273 In Text mode, an indented line is not a paragraph break. If you
274 want indented lines to have this effect, use Paragraph-Indent Text
275 mode instead. @xref{Text Mode}.
276
277 In major modes for programs, paragraphs begin and end only at blank
278 lines. This makes the paragraph commands useful, even though there
279 are no paragraphs as such in a program.
280
281 When you have set a fill prefix, then paragraphs are delimited by
282 all lines which don't start with the fill prefix. @xref{Filling}.
283
284 @kindex M-h
285 @findex mark-paragraph
286 When you wish to operate on a paragraph, type @kbd{M-h}
287 (@code{mark-paragraph}) to set the region around it. For example,
288 @kbd{M-h C-w} kills the paragraph around or after point. @kbd{M-h}
289 puts point at the beginning and mark at the end of the paragraph point
290 was in. If point is between paragraphs (in a run of blank lines, or
291 at a boundary), the paragraph following point is surrounded by point
292 and mark. If there are blank lines preceding the first line of the
293 paragraph, one of these blank lines is included in the region. If the
294 region is already active, the command sets the mark without changing
295 point; furthermore, each subsequent @kbd{M-h} further advances the
296 mark by one paragraph.
297
298 @vindex paragraph-start
299 @vindex paragraph-separate
300 The precise definition of a paragraph boundary is controlled by the
301 variables @code{paragraph-separate} and @code{paragraph-start}. The
302 value of @code{paragraph-start} is a regexp that should match any line
303 that either starts or separates paragraphs. The value of
304 @code{paragraph-separate} is another regexp that should match only lines
305 that separate paragraphs without being part of any paragraph (for
306 example, blank lines). Lines that start a new paragraph and are
307 contained in it must match only @code{paragraph-start}, not
308 @code{paragraph-separate}. Each regular expression must match at the
309 left margin. For example, in Fundamental mode, @code{paragraph-start}
310 is @w{@code{"\f\\|[ \t]*$"}}, and @code{paragraph-separate} is
311 @w{@code{"[ \t\f]*$"}}.
312
313 Normally it is desirable for page boundaries to separate paragraphs.
314 The default values of these variables recognize the usual separator for
315 pages.
316
317 @node Pages
318 @section Pages
319
320 @cindex pages
321 @cindex formfeed character
322 Within some text files, text is divided into @dfn{pages}, which are
323 delimited by the @dfn{formfeed character} (@acronym{ASCII} code 12,
324 sometimes denoted as @key{control-L}). When you print hardcopy for a
325 file, the formfeed character forces a page break: each page of the
326 file goes on a separate page on paper. Most Emacs commands treat the
327 formfeed character just like any other character: you can insert it
328 with @kbd{C-q C-l}, and delete it with @key{DEL}. However, since
329 pages are often meaningful divisions of the file, Emacs provides
330 commands to move over them and operate on them.
331
332 @table @kbd
333 @item C-x [
334 Move point to previous page boundary (@code{backward-page}).
335 @item C-x ]
336 Move point to next page boundary (@code{forward-page}).
337 @item C-x C-p
338 Put point and mark around this page (or another page) (@code{mark-page}).
339 @item C-x l
340 Count the lines in this page (@code{count-lines-page}).
341 @end table
342
343 @kindex C-x [
344 @kindex C-x ]
345 @findex forward-page
346 @findex backward-page
347 The @kbd{C-x [} (@code{backward-page}) command moves point to immediately
348 after the previous page delimiter. If point is already right after a page
349 delimiter, it skips that one and stops at the previous one. A numeric
350 argument serves as a repeat count. The @kbd{C-x ]} (@code{forward-page})
351 command moves forward past the next page delimiter.
352
353 @kindex C-x C-p
354 @findex mark-page
355 The @kbd{C-x C-p} command (@code{mark-page}) puts point at the
356 beginning of the current page and the mark at the end. The page
357 delimiter at the end is included (the mark follows it). The page
358 delimiter at the front is excluded (point follows it).
359
360 @kbd{C-x C-p C-w} is a handy way to kill a page to move it
361 elsewhere. If you move to another page delimiter with @kbd{C-x [} and
362 @kbd{C-x ]}, then yank the killed page, all the pages will be properly
363 delimited once again. The reason @kbd{C-x C-p} includes only the
364 following page delimiter in the region is to ensure that.
365
366 A numeric argument to @kbd{C-x C-p} specifies which page to go to,
367 relative to the current one. Zero means the current page. One means
368 the next page, and @minus{}1 means the previous one.
369
370 @kindex C-x l
371 @findex count-lines-page
372 The @kbd{C-x l} command (@code{count-lines-page}) is good for deciding
373 where to break a page in two. It displays in the echo area the total number
374 of lines in the current page, and then divides it up into those preceding
375 the current line and those following, as in
376
377 @example
378 Page has 96 (72+25) lines
379 @end example
380
381 @noindent
382 Notice that the sum is off by one; this is correct if point is not at the
383 beginning of a line.
384
385 @vindex page-delimiter
386 The variable @code{page-delimiter} controls where pages begin. Its
387 value is a regular expression that matches the beginning of a line
388 that separates pages (@pxref{Regexps}). The normal value of this
389 variable is @code{"^\f"}, which matches a formfeed character at the
390 beginning of a line.
391
392 @node Filling
393 @section Filling Text
394 @cindex filling text
395
396 @dfn{Filling} text means breaking it up into lines that fit a
397 specified width. Emacs does filling in two ways. In Auto Fill mode,
398 inserting text with self-inserting characters also automatically fills
399 it. There are also explicit fill commands that you can use when editing
400 text leaves it unfilled. When you edit formatted text, you can specify
401 a style of filling for each portion of the text (@pxref{Formatted
402 Text}).
403
404 @menu
405 * Auto Fill:: Auto Fill mode breaks long lines automatically.
406 * Fill Commands:: Commands to refill paragraphs and center lines.
407 * Fill Prefix:: Filling paragraphs that are indented or in a comment, etc.
408 * Adaptive Fill:: How Emacs can determine the fill prefix automatically.
409 @end menu
410
411 @node Auto Fill
412 @subsection Auto Fill Mode
413 @cindex Auto Fill mode
414 @cindex mode, Auto Fill
415
416 @dfn{Auto Fill} mode is a minor mode in which lines are broken
417 automatically when they become too wide. Breaking happens only when
418 you type a @key{SPC} or @key{RET}.
419
420 @table @kbd
421 @item M-x auto-fill-mode
422 Enable or disable Auto Fill mode.
423 @item @key{SPC}
424 @itemx @key{RET}
425 In Auto Fill mode, break lines when appropriate.
426 @end table
427
428 @findex auto-fill-mode
429 @kbd{M-x auto-fill-mode} turns Auto Fill mode on if it was off, or off
430 if it was on. With a positive numeric argument it always turns Auto
431 Fill mode on, and with a negative argument always turns it off. You can
432 see when Auto Fill mode is in effect by the presence of the word
433 @samp{Fill} in the mode line, inside the parentheses. Auto Fill mode is
434 a minor mode which is enabled or disabled for each buffer individually.
435 @xref{Minor Modes}.
436
437 In Auto Fill mode, lines are broken automatically at spaces when they
438 get longer than the desired width. Line breaking and rearrangement
439 takes place only when you type @key{SPC} or @key{RET}. If you wish to
440 insert a space or newline without permitting line-breaking, type
441 @kbd{C-q @key{SPC}} or @kbd{C-q C-j} (recall that a newline is really a
442 control-J). Also, @kbd{C-o} inserts a newline without line breaking.
443
444 Auto Fill mode works well with programming-language modes, because it
445 indents new lines with @key{TAB}. If a line ending in a comment gets
446 too long, the text of the comment is split into two comment lines.
447 Optionally, new comment delimiters are inserted at the end of the first
448 line and the beginning of the second so that each line is a separate
449 comment; the variable @code{comment-multi-line} controls the choice
450 (@pxref{Comments}).
451
452 Adaptive filling (@pxref{Adaptive Fill}) works for Auto Filling as
453 well as for explicit fill commands. It takes a fill prefix
454 automatically from the second or first line of a paragraph.
455
456 Auto Fill mode does not refill entire paragraphs; it can break lines but
457 cannot merge lines. So editing in the middle of a paragraph can result in
458 a paragraph that is not correctly filled. The easiest way to make the
459 paragraph properly filled again is usually with the explicit fill commands.
460 @ifnottex
461 @xref{Fill Commands}.
462 @end ifnottex
463
464 Many users like Auto Fill mode and want to use it in all text files.
465 The section on init files says how to arrange this permanently for yourself.
466 @xref{Init File}.
467
468 @node Fill Commands
469 @subsection Explicit Fill Commands
470
471 @table @kbd
472 @item M-q
473 Fill current paragraph (@code{fill-paragraph}).
474 @item C-x f
475 Set the fill column (@code{set-fill-column}).
476 @item M-x fill-region
477 Fill each paragraph in the region (@code{fill-region}).
478 @item M-x fill-region-as-paragraph
479 Fill the region, considering it as one paragraph.
480 @item M-o M-s
481 Center a line.
482 @end table
483
484 @kindex M-q
485 @findex fill-paragraph
486 To refill a paragraph, use the command @kbd{M-q}
487 (@code{fill-paragraph}). This operates on the paragraph that point is
488 inside, or the one after point if point is between paragraphs.
489 Refilling works by removing all the line-breaks, then inserting new
490 ones where necessary. When there is an active region, this command
491 operates on the text within the region like @code{fill-region}.
492
493 @findex fill-region
494 To refill many paragraphs, use @kbd{M-x fill-region}, which
495 finds the paragraphs in the region and fills each of them.
496
497 @findex fill-region-as-paragraph
498 @kbd{M-q} and @code{fill-region} use the same criteria as @kbd{M-h}
499 for finding paragraph boundaries (@pxref{Paragraphs}). For more
500 control, you can use @kbd{M-x fill-region-as-paragraph}, which refills
501 everything between point and mark as a single paragraph. This command
502 deletes any blank lines within the region, so separate blocks of text
503 end up combined into one block.
504
505 @cindex justification
506 A numeric argument to @kbd{M-q} tells it to @dfn{justify} the text
507 as well as filling it. This means that extra spaces are inserted to
508 make the right margin line up exactly at the fill column. To remove
509 the extra spaces, use @kbd{M-q} with no argument. (Likewise for
510 @code{fill-region}.) Another way to control justification, and choose
511 other styles of filling, is with the @code{justification} text
512 property; see @ref{Format Justification}.
513
514 @kindex M-o M-s @r{(Text mode)}
515 @cindex centering
516 @findex center-line
517 The command @kbd{M-o M-s} (@code{center-line}) centers the current line
518 within the current fill column. With an argument @var{n}, it centers
519 @var{n} lines individually and moves past them. This binding is
520 made by Text mode and is available only in that and related modes
521 (@pxref{Text Mode}).
522
523 @vindex fill-column
524 @kindex C-x f
525 @findex set-fill-column
526 The maximum line width for filling is in the variable
527 @code{fill-column}. Altering the value of @code{fill-column} makes it
528 local to the current buffer; until that time, the default value is in
529 effect. The default is initially 70. @xref{Locals}. The easiest way
530 to set @code{fill-column} is to use the command @kbd{C-x f}
531 (@code{set-fill-column}). With a numeric argument, it uses that as the
532 new fill column. With just @kbd{C-u} as argument, it sets
533 @code{fill-column} to the current horizontal position of point.
534
535 Emacs commands normally consider a period followed by two spaces or by
536 a newline as the end of a sentence; a period followed by just one space
537 indicates an abbreviation and not the end of a sentence. To preserve
538 the distinction between these two ways of using a period, the fill
539 commands do not break a line after a period followed by just one space.
540
541 If the variable @code{sentence-end-double-space} is @code{nil}, the
542 fill commands expect and leave just one space at the end of a sentence.
543 Ordinarily this variable is @code{t}, so the fill commands insist on
544 two spaces for the end of a sentence, as explained above. @xref{Sentences}.
545
546 @vindex colon-double-space
547 If the variable @code{colon-double-space} is non-@code{nil}, the
548 fill commands put two spaces after a colon.
549
550 @vindex fill-nobreak-predicate
551 The variable @code{fill-nobreak-predicate} is a hook (an abnormal
552 hook, @pxref{Hooks}) specifying additional conditions where
553 line-breaking is not allowed. Each function is called with no
554 arguments, with point at a place where Emacs is considering breaking
555 the line. If a function returns a non-@code{nil} value, then that's
556 a bad place to break the line. Two standard functions you can use are
557 @code{fill-single-word-nobreak-p} (don't break after the first word of
558 a sentence or before the last) and @code{fill-french-nobreak-p} (don't
559 break after @samp{(} or before @samp{)}, @samp{:} or @samp{?}).
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 for the current buffer, move to a line that
588 starts with the desired prefix, put point at the end of the prefix,
589 and type @w{@kbd{C-x .}}@: (@code{set-fill-prefix}). (That's a period
590 after the @kbd{C-x}.) To turn off the fill prefix, specify an empty
591 prefix: type @w{@kbd{C-x .}}@: with point at the beginning of a line.
592
593 When a fill prefix is in effect, the fill commands remove the fill
594 prefix from each line of the paragraph before filling and insert it on
595 each line after filling. (The beginning of the first line of the
596 paragraph is left unchanged, since often that is intentionally
597 different.) Auto Fill mode also inserts the fill prefix automatically
598 when it makes a new line. The @kbd{C-o} command inserts the fill
599 prefix on new lines it creates, when you use it at the beginning of a
600 line (@pxref{Blank Lines}). Conversely, the command @kbd{M-^} deletes
601 the prefix (if it occurs) after the newline that it deletes
602 (@pxref{Indentation}).
603
604 For example, if @code{fill-column} is 40 and you set the fill prefix
605 to @samp{;; }, then @kbd{M-q} in the following text
606
607 @example
608 ;; This is an
609 ;; example of a paragraph
610 ;; inside a Lisp-style comment.
611 @end example
612
613 @noindent
614 produces this:
615
616 @example
617 ;; This is an example of a paragraph
618 ;; inside a Lisp-style comment.
619 @end example
620
621 Lines that do not start with the fill prefix are considered to start
622 paragraphs, both in @kbd{M-q} and the paragraph commands; this gives
623 good results for paragraphs with hanging indentation (every line
624 indented except the first one). Lines which are blank or indented once
625 the prefix is removed also separate or start paragraphs; this is what
626 you want if you are writing multi-paragraph comments with a comment
627 delimiter on each line.
628
629 @findex fill-individual-paragraphs
630 You can use @kbd{M-x fill-individual-paragraphs} to set the fill
631 prefix for each paragraph automatically. This command divides the
632 region into paragraphs, treating every change in the amount of
633 indentation as the start of a new paragraph, and fills each of these
634 paragraphs. Thus, all the lines in one ``paragraph'' have the same
635 amount of indentation. That indentation serves as the fill prefix for
636 that paragraph.
637
638 @findex fill-nonuniform-paragraphs
639 @kbd{M-x fill-nonuniform-paragraphs} is a similar command that divides
640 the region into paragraphs in a different way. It considers only
641 paragraph-separating lines (as defined by @code{paragraph-separate}) as
642 starting a new paragraph. Since this means that the lines of one
643 paragraph may have different amounts of indentation, the fill prefix
644 used is the smallest amount of indentation of any of the lines of the
645 paragraph. This gives good results with styles that indent a paragraph's
646 first line more or less that the rest of the paragraph.
647
648 @vindex fill-prefix
649 The fill prefix is stored in the variable @code{fill-prefix}. Its value
650 is a string, or @code{nil} when there is no fill prefix. This is a
651 per-buffer variable; altering the variable affects only the current buffer,
652 but there is a default value which you can change as well. @xref{Locals}.
653
654 The @code{indentation} text property provides another way to control
655 the amount of indentation paragraphs receive. @xref{Format Indentation}.
656
657 @node Adaptive Fill
658 @subsection Adaptive Filling
659
660 @cindex adaptive filling
661 The fill commands can deduce the proper fill prefix for a paragraph
662 automatically in certain cases: either whitespace or certain punctuation
663 characters at the beginning of a line are propagated to all lines of the
664 paragraph.
665
666 If the paragraph has two or more lines, the fill prefix is taken from
667 the paragraph's second line, but only if it appears on the first line as
668 well.
669
670 If a paragraph has just one line, fill commands @emph{may} take a
671 prefix from that line. The decision is complicated because there are
672 three reasonable things to do in such a case:
673
674 @itemize @bullet
675 @item
676 Use the first line's prefix on all the lines of the paragraph.
677
678 @item
679 Indent subsequent lines with whitespace, so that they line up under the
680 text that follows the prefix on the first line, but don't actually copy
681 the prefix from the first line.
682
683 @item
684 Don't do anything special with the second and following lines.
685 @end itemize
686
687 All three of these styles of formatting are commonly used. So the
688 fill commands try to determine what you would like, based on the prefix
689 that appears and on the major mode. Here is how.
690
691 @vindex adaptive-fill-first-line-regexp
692 If the prefix found on the first line matches
693 @code{adaptive-fill-first-line-regexp}, or if it appears to be a
694 comment-starting sequence (this depends on the major mode), then the
695 prefix found is used for filling the paragraph, provided it would not
696 act as a paragraph starter on subsequent lines.
697
698 Otherwise, the prefix found is converted to an equivalent number of
699 spaces, and those spaces are used as the fill prefix for the rest of the
700 lines, provided they would not act as a paragraph starter on subsequent
701 lines.
702
703 In Text mode, and other modes where only blank lines and page
704 delimiters separate paragraphs, the prefix chosen by adaptive filling
705 never acts as a paragraph starter, so it can always be used for filling.
706
707 @vindex adaptive-fill-mode
708 @vindex adaptive-fill-regexp
709 The variable @code{adaptive-fill-regexp} determines what kinds of line
710 beginnings can serve as a fill prefix: any characters at the start of
711 the line that match this regular expression are used. If you set the
712 variable @code{adaptive-fill-mode} to @code{nil}, the fill prefix is
713 never chosen automatically.
714
715 @vindex adaptive-fill-function
716 You can specify more complex ways of choosing a fill prefix
717 automatically by setting the variable @code{adaptive-fill-function} to a
718 function. This function is called with point after the left margin of a
719 line, and it should return the appropriate fill prefix based on that
720 line. If it returns @code{nil}, @code{adaptive-fill-regexp} gets
721 a chance to find a prefix.
722
723 @node Case
724 @section Case Conversion Commands
725 @cindex case conversion
726
727 Emacs has commands for converting either a single word or any arbitrary
728 range of text to upper case or to lower case.
729
730 @table @kbd
731 @item M-l
732 Convert following word to lower case (@code{downcase-word}).
733 @item M-u
734 Convert following word to upper case (@code{upcase-word}).
735 @item M-c
736 Capitalize the following word (@code{capitalize-word}).
737 @item C-x C-l
738 Convert region to lower case (@code{downcase-region}).
739 @item C-x C-u
740 Convert region to upper case (@code{upcase-region}).
741 @end table
742
743 @kindex M-l
744 @kindex M-u
745 @kindex M-c
746 @cindex words, case conversion
747 @cindex converting text to upper or lower case
748 @cindex capitalizing words
749 @findex downcase-word
750 @findex upcase-word
751 @findex capitalize-word
752 The word conversion commands are the most useful. @kbd{M-l}
753 (@code{downcase-word}) converts the word after point to lower case, moving
754 past it. Thus, repeating @kbd{M-l} converts successive words.
755 @kbd{M-u} (@code{upcase-word}) converts to all capitals instead, while
756 @kbd{M-c} (@code{capitalize-word}) puts the first letter of the word
757 into upper case and the rest into lower case. All these commands convert
758 several words at once if given an argument. They are especially convenient
759 for converting a large amount of text from all upper case to mixed case,
760 because you can move through the text using @kbd{M-l}, @kbd{M-u} or
761 @kbd{M-c} on each word as appropriate, occasionally using @kbd{M-f} instead
762 to skip a word.
763
764 When given a negative argument, the word case conversion commands apply
765 to the appropriate number of words before point, but do not move point.
766 This is convenient when you have just typed a word in the wrong case: you
767 can give the case conversion command and continue typing.
768
769 If a word case conversion command is given in the middle of a word,
770 it applies only to the part of the word which follows point. (This is
771 comparable to what @kbd{M-d} (@code{kill-word}) does.) With a
772 negative argument, case conversion applies only to the part of the
773 word before point.
774
775 @kindex C-x C-l
776 @kindex C-x C-u
777 @findex downcase-region
778 @findex upcase-region
779 The other case conversion commands are @kbd{C-x C-u}
780 (@code{upcase-region}) and @kbd{C-x C-l} (@code{downcase-region}), which
781 convert everything between point and mark to the specified case. Point and
782 mark do not move.
783
784 The region case conversion commands @code{upcase-region} and
785 @code{downcase-region} are normally disabled. This means that they ask
786 for confirmation if you try to use them. When you confirm, you may
787 enable the command, which means it will not ask for confirmation again.
788 @xref{Disabling}.
789
790 @node Text Mode
791 @section Text Mode
792 @cindex Text mode
793 @cindex mode, Text
794 @findex text-mode
795
796 When you edit files of text in a human language, it's more convenient
797 to use Text mode rather than Fundamental mode. To enter Text mode, type
798 @kbd{M-x text-mode}.
799
800 In Text mode, only blank lines and page delimiters separate
801 paragraphs. As a result, paragraphs can be indented, and adaptive
802 filling determines what indentation to use when filling a paragraph.
803 @xref{Adaptive Fill}.
804
805 @kindex TAB @r{(Text mode)}
806 Text mode defines @key{TAB} to run @code{indent-relative}
807 (@pxref{Indentation}), so that you can conveniently indent a line like
808 the previous line.
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
812 single-quotes are considered part of words. However, if a word starts
813 with single-quotes, these are treated as a prefix for purposes such as
814 capitalization. That is, @kbd{M-c} will convert @samp{'hello'} into
815 @samp{'Hello'}, as expected.
816
817 @cindex Paragraph-Indent Text mode
818 @cindex mode, Paragraph-Indent Text
819 @findex paragraph-indent-text-mode
820 @findex paragraph-indent-minor-mode
821 If you indent the first lines of paragraphs, then you should use
822 Paragraph-Indent Text mode rather than Text mode. In this mode, you
823 do not need to have blank lines between paragraphs, because the
824 first-line indentation is sufficient to start a paragraph; however
825 paragraphs in which every line is indented are not supported. Use
826 @kbd{M-x paragraph-indent-text-mode} to enter this mode. Use @kbd{M-x
827 paragraph-indent-minor-mode} to enable an equivalent minor mode in
828 situations where you can't change the major mode---in mail
829 composition, for instance.
830
831 @kindex M-TAB @r{(Text mode)}
832 Text mode, and all the modes based on it, define @kbd{M-@key{TAB}}
833 as the command @code{ispell-complete-word}, which performs completion
834 of the partial word in the buffer before point, using the spelling
835 dictionary as the space of possible words. @xref{Spelling}. If your
836 window manager defines @kbd{M-@key{TAB}} to switch windows, you can
837 type @kbd{@key{ESC} @key{TAB}} or @kbd{C-M-i}.
838
839 @vindex text-mode-hook
840 Entering Text mode runs the hook @code{text-mode-hook}. Other major
841 modes related to Text mode also run this hook, followed by hooks of
842 their own; this includes Paragraph-Indent Text mode, Nroff mode,
843 @TeX{} mode, Outline mode, and Message mode. Hook functions on
844 @code{text-mode-hook} can look at the value of @code{major-mode} to
845 see which of these modes is actually being entered. @xref{Hooks}.
846
847 @node Outline Mode
848 @section Outline Mode
849 @cindex Outline mode
850 @cindex mode, Outline
851 @cindex invisible lines
852
853 @findex outline-mode
854 @findex outline-minor-mode
855 @vindex outline-minor-mode-prefix
856 Outline mode is a major mode much like Text mode but intended for
857 editing outlines. It allows you to make parts of the text temporarily
858 invisible so that you can see the outline structure. Type @kbd{M-x
859 outline-mode} to switch to Outline mode as the major mode of the current
860 buffer.
861
862 When Outline mode makes a line invisible, the line does not appear
863 on the screen. The screen appears exactly as if the invisible line
864 were deleted, except that an ellipsis (three periods in a row) appears
865 at the end of the previous visible line. (Multiple consecutive
866 invisible lines produce just one ellipsis.)
867
868 Editing commands that operate on lines, such as @kbd{C-n} and
869 @kbd{C-p}, treat the text of the invisible line as part of the previous
870 visible line. Killing the ellipsis at the end of a visible line
871 really kills all the following invisible lines.
872
873 Outline minor mode provides the same commands as the major mode,
874 Outline mode, but you can use it in conjunction with other major modes.
875 Type @kbd{M-x outline-minor-mode} to enable the Outline minor mode in
876 the current buffer. You can also specify this in the text of a file,
877 with a file local variable of the form @samp{mode: outline-minor}
878 (@pxref{File Variables}).
879
880 @kindex C-c @@ @r{(Outline minor mode)}
881 The major mode, Outline mode, provides special key bindings on the
882 @kbd{C-c} prefix. Outline minor mode provides similar bindings with
883 @kbd{C-c @@} as the prefix; this is to reduce the conflicts with the
884 major mode's special commands. (The variable
885 @code{outline-minor-mode-prefix} controls the prefix used.)
886
887 @vindex outline-mode-hook
888 Entering Outline mode runs the hook @code{text-mode-hook} followed by
889 the hook @code{outline-mode-hook} (@pxref{Hooks}).
890
891 @menu
892 * Format: Outline Format. What the text of an outline looks like.
893 * Motion: Outline Motion. Special commands for moving through
894 outlines.
895 * Visibility: Outline Visibility. Commands to control what is visible.
896 * Views: Outline Views. Outlines and multiple views.
897 * Foldout:: Folding means zooming in on outlines.
898 @end menu
899
900 @node Outline Format
901 @subsection Format of Outlines
902
903 @cindex heading lines (Outline mode)
904 @cindex body lines (Outline mode)
905 Outline mode assumes that the lines in the buffer are of two types:
906 @dfn{heading lines} and @dfn{body lines}. A heading line represents a
907 topic in the outline. Heading lines start with one or more stars; the
908 number of stars determines the depth of the heading in the outline
909 structure. Thus, a heading line with one star is a major topic; all the
910 heading lines with two stars between it and the next one-star heading
911 are its subtopics; and so on. Any line that is not a heading line is a
912 body line. Body lines belong with the preceding heading line. Here is
913 an example:
914
915 @example
916 * Food
917 This is the body,
918 which says something about the topic of food.
919
920 ** Delicious Food
921 This is the body of the second-level header.
922
923 ** Distasteful Food
924 This could have
925 a body too, with
926 several lines.
927
928 *** Dormitory Food
929
930 * Shelter
931 Another first-level topic with its header line.
932 @end example
933
934 A heading line together with all following body lines is called
935 collectively an @dfn{entry}. A heading line together with all following
936 deeper heading lines and their body lines is called a @dfn{subtree}.
937
938 @vindex outline-regexp
939 You can customize the criterion for distinguishing heading lines by
940 setting the variable @code{outline-regexp}. (The recommended ways to
941 do this are in a major mode function or with a file local variable.)
942 Any line whose beginning has a match for this regexp is considered a
943 heading line. Matches that start within a line (not at the left
944 margin) do not count.
945
946 The length of the matching text determines the level of the heading;
947 longer matches make a more deeply nested level. Thus, for example, if
948 a text formatter has commands @samp{@@chapter}, @samp{@@section} and
949 @samp{@@subsection} to divide the document into chapters and sections,
950 you could make those lines count as heading lines by setting
951 @code{outline-regexp} to @samp{"@@chap\\|@@\\(sub\\)*section"}. Note
952 the trick: the two words @samp{chapter} and @samp{section} are equally
953 long, but by defining the regexp to match only @samp{chap} we ensure
954 that the length of the text matched on a chapter heading is shorter,
955 so that Outline mode will know that sections are contained in
956 chapters. This works as long as no other command starts with
957 @samp{@@chap}.
958
959 @vindex outline-level
960 You can explicitly specify a rule for calculating the level of a
961 heading line by setting the variable @code{outline-level}. The value
962 of @code{outline-level} should be a function that takes no arguments
963 and returns the level of the current heading. The recommended ways to
964 set this variable are in a major mode command or with a file local
965 variable.
966
967 @node Outline Motion
968 @subsection Outline Motion Commands
969
970 Outline mode provides special motion commands that move backward and
971 forward to heading lines.
972
973 @table @kbd
974 @item C-c C-n
975 Move point to the next visible heading line
976 (@code{outline-next-visible-heading}).
977 @item C-c C-p
978 Move point to the previous visible heading line
979 (@code{outline-previous-visible-heading}).
980 @item C-c C-f
981 Move point to the next visible heading line at the same level
982 as the one point is on (@code{outline-forward-same-level}).
983 @item C-c C-b
984 Move point to the previous visible heading line at the same level
985 (@code{outline-backward-same-level}).
986 @item C-c C-u
987 Move point up to a lower-level (more inclusive) visible heading line
988 (@code{outline-up-heading}).
989 @end table
990
991 @findex outline-next-visible-heading
992 @findex outline-previous-visible-heading
993 @kindex C-c C-n @r{(Outline mode)}
994 @kindex C-c C-p @r{(Outline mode)}
995 @kbd{C-c C-n} (@code{outline-next-visible-heading}) moves down to the next
996 heading line. @kbd{C-c C-p} (@code{outline-previous-visible-heading}) moves
997 similarly backward. Both accept numeric arguments as repeat counts. The
998 names emphasize that invisible headings are skipped, but this is not really
999 a special feature. All editing commands that look for lines ignore the
1000 invisible lines automatically.
1001
1002 @findex outline-up-heading
1003 @findex outline-forward-same-level
1004 @findex outline-backward-same-level
1005 @kindex C-c C-f @r{(Outline mode)}
1006 @kindex C-c C-b @r{(Outline mode)}
1007 @kindex C-c C-u @r{(Outline mode)}
1008 More powerful motion commands understand the level structure of headings.
1009 @kbd{C-c C-f} (@code{outline-forward-same-level}) and
1010 @kbd{C-c C-b} (@code{outline-backward-same-level}) move from one
1011 heading line to another visible heading at the same depth in
1012 the outline. @kbd{C-c C-u} (@code{outline-up-heading}) moves
1013 backward to another heading that is less deeply nested.
1014
1015 @node Outline Visibility
1016 @subsection Outline Visibility Commands
1017
1018 The other special commands of outline mode are used to make lines visible
1019 or invisible. Their names all start with @code{hide} or @code{show}.
1020 Most of them fall into pairs of opposites. They are not undoable; instead,
1021 you can undo right past them. Making lines visible or invisible is simply
1022 not recorded by the undo mechanism.
1023
1024 Many of these commands act on the ``current'' heading line. If
1025 point is on a heading line, that is the current heading line; if point
1026 is on a body line, the current heading line is the nearest preceding
1027 header line.
1028
1029 @table @kbd
1030 @item C-c C-c
1031 Make the current heading line's body invisible (@code{hide-entry}).
1032 @item C-c C-e
1033 Make the current heading line's body visible (@code{show-entry}).
1034 @item C-c C-d
1035 Make everything under the current heading invisible, not including the
1036 heading itself (@code{hide-subtree}).
1037 @item C-c C-s
1038 Make everything under the current heading visible, including body,
1039 subheadings, and their bodies (@code{show-subtree}).
1040 @item C-c C-l
1041 Make the body of the current heading line, and of all its subheadings,
1042 invisible (@code{hide-leaves}).
1043 @item C-c C-k
1044 Make all subheadings of the current heading line, at all levels,
1045 visible (@code{show-branches}).
1046 @item C-c C-i
1047 Make immediate subheadings (one level down) of the current heading
1048 line visible (@code{show-children}).
1049 @item C-c C-t
1050 Make all body lines in the buffer invisible (@code{hide-body}).
1051 @item C-c C-a
1052 Make all lines in the buffer visible (@code{show-all}).
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 apply
1068 to the body lines directly following the current heading line.
1069 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})
1077 and @kbd{C-c C-s} (@code{show-subtree}). Both apply to the current
1078 heading line's @dfn{subtree}: its body, all its subheadings, both
1079 direct and indirect, and all of their bodies. In other words, the
1080 subtree contains everything following the current heading line, up to
1081 and not including the next heading of the same or higher rank.
1082
1083 @findex hide-leaves
1084 @findex show-branches
1085 @kindex C-c C-l @r{(Outline mode)}
1086 @kindex C-c C-k @r{(Outline mode)}
1087 Intermediate between a visible subtree and an invisible one is having
1088 all the subheadings visible but none of the body. There are two
1089 commands for doing this, depending on whether you want to hide the
1090 bodies or make the subheadings visible. They are @kbd{C-c C-l}
1091 (@code{hide-leaves}) and @kbd{C-c C-k} (@code{show-branches}).
1092
1093 @kindex C-c C-i @r{(Outline mode)}
1094 @findex show-children
1095 A little weaker than @code{show-branches} is @kbd{C-c C-i}
1096 (@code{show-children}). It makes just the direct subheadings
1097 visible---those one level down. Deeper subheadings remain invisible, if
1098 they were invisible.
1099
1100 @findex hide-body
1101 @findex show-all
1102 @kindex C-c C-t @r{(Outline mode)}
1103 @kindex C-c C-a @r{(Outline mode)}
1104 Two commands have a blanket effect on the whole file. @kbd{C-c C-t}
1105 (@code{hide-body}) makes all body lines invisible, so that you see just
1106 the outline structure (as a special exception, it will not hide lines
1107 at the top of the file, preceding the first header line, even though
1108 these are technically body lines). @kbd{C-c C-a} (@code{show-all})
1109 makes all lines visible. These commands can be thought of as a pair
1110 of opposites even though @kbd{C-c C-a} applies to more than just body
1111 lines.
1112
1113 @findex hide-sublevels
1114 @kindex C-c C-q @r{(Outline mode)}
1115 The command @kbd{C-c C-q} (@code{hide-sublevels}) hides all but the
1116 top level headings. With a numeric argument @var{n}, it hides everything
1117 except the top @var{n} levels of heading lines.
1118
1119 @findex hide-other
1120 @kindex C-c C-o @r{(Outline mode)}
1121 The command @kbd{C-c C-o} (@code{hide-other}) hides everything except
1122 the heading and body text that point is in, plus its parents (the headers
1123 leading up from there to top level in the outline) and the top level
1124 headings.
1125
1126 @findex reveal-mode
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. You can also
1130 automatically make text visible as you navigate in it by using
1131 @kbd{M-x reveal-mode}.
1132
1133 @node Outline Views
1134 @subsection Viewing One Outline in Multiple Views
1135
1136 @cindex multiple views of outline
1137 @cindex views of an outline
1138 @cindex outline with multiple views
1139 @cindex indirect buffers and outlines
1140 You can display two views of a single outline at the same time, in
1141 different windows. To do this, you must create an indirect buffer using
1142 @kbd{M-x make-indirect-buffer}. The first argument of this command is
1143 the existing outline buffer name, and its second argument is the name to
1144 use for the new indirect buffer. @xref{Indirect Buffers}.
1145
1146 Once the indirect buffer exists, you can display it in a window in the
1147 normal fashion, with @kbd{C-x 4 b} or other Emacs commands. The Outline
1148 mode commands to show and hide parts of the text operate on each buffer
1149 independently; as a result, each buffer can have its own view. If you
1150 want more than two views on the same outline, create additional indirect
1151 buffers.
1152
1153 @node Foldout
1154 @subsection Folding Editing
1155
1156 @cindex folding editing
1157 The Foldout package extends Outline mode and Outline minor mode with
1158 ``folding'' commands. The idea of folding is that you zoom in on a
1159 nested portion of the outline, while hiding its relatives at higher
1160 levels.
1161
1162 Consider an Outline mode buffer with all the text and subheadings under
1163 level-1 headings hidden. To look at what is hidden under one of these
1164 headings, you could use @kbd{C-c C-e} (@kbd{M-x show-entry}) to expose
1165 the body, or @kbd{C-c C-i} to expose the child (level-2) headings.
1166
1167 @kindex C-c C-z
1168 @findex foldout-zoom-subtree
1169 With Foldout, you use @kbd{C-c C-z} (@kbd{M-x foldout-zoom-subtree}).
1170 This exposes the body and child subheadings, and narrows the buffer so
1171 that only the @w{level-1} heading, the body and the level-2 headings are
1172 visible. Now to look under one of the level-2 headings, position the
1173 cursor on it and use @kbd{C-c C-z} again. This exposes the level-2 body
1174 and its level-3 child subheadings and narrows the buffer again. Zooming
1175 in on successive subheadings can be done as much as you like. A string
1176 in the mode line shows how deep you've gone.
1177
1178 When zooming in on a heading, to see only the child subheadings specify
1179 a numeric argument: @kbd{C-u C-c C-z}. The number of levels of children
1180 can be specified too (compare @kbd{M-x show-children}), e.g.@: @kbd{M-2
1181 C-c C-z} exposes two levels of child subheadings. Alternatively, the
1182 body can be specified with a negative argument: @kbd{M-- C-c C-z}. The
1183 whole subtree can be expanded, similarly to @kbd{C-c C-s} (@kbd{M-x
1184 show-subtree}), by specifying a zero argument: @kbd{M-0 C-c C-z}.
1185
1186 While you're zoomed in, you can still use Outline mode's exposure and
1187 hiding functions without disturbing Foldout. Also, since the buffer is
1188 narrowed, ``global'' editing actions will only affect text under the
1189 zoomed-in heading. This is useful for restricting changes to a
1190 particular chapter or section of your document.
1191
1192 @kindex C-c C-x
1193 @findex foldout-exit-fold
1194 To unzoom (exit) a fold, use @kbd{C-c C-x} (@kbd{M-x foldout-exit-fold}).
1195 This hides all the text and subheadings under the top-level heading and
1196 returns you to the previous view of the buffer. Specifying a numeric
1197 argument exits that many levels of folds. Specifying a zero argument
1198 exits all folds.
1199
1200 To cancel the narrowing of a fold without hiding the text and
1201 subheadings, specify a negative argument. For example, @kbd{M--2 C-c
1202 C-x} exits two folds and leaves the text and subheadings exposed.
1203
1204 Foldout mode also provides mouse commands for entering and exiting
1205 folds, and for showing and hiding text:
1206
1207 @table @asis
1208 @item @kbd{C-M-Mouse-1} zooms in on the heading clicked on
1209 @itemize @w{}
1210 @item
1211 single click: expose body.
1212 @item
1213 double click: expose subheadings.
1214 @item
1215 triple click: expose body and subheadings.
1216 @item
1217 quad click: expose entire subtree.
1218 @end itemize
1219 @item @kbd{C-M-Mouse-2} exposes text under the heading clicked on
1220 @itemize @w{}
1221 @item
1222 single click: expose body.
1223 @item
1224 double click: expose subheadings.
1225 @item
1226 triple click: expose body and subheadings.
1227 @item
1228 quad click: expose entire subtree.
1229 @end itemize
1230 @item @kbd{C-M-Mouse-3} hides text under the heading clicked on or exits fold
1231 @itemize @w{}
1232 @item
1233 single click: hide subtree.
1234 @item
1235 double click: exit fold and hide text.
1236 @item
1237 triple click: exit fold without hiding text.
1238 @item
1239 quad click: exit all folds and hide text.
1240 @end itemize
1241 @end table
1242
1243 @vindex foldout-mouse-modifiers
1244 You can specify different modifier keys (instead of
1245 @kbd{Control-Meta-}) by setting @code{foldout-mouse-modifiers}; but if
1246 you have already loaded the @file{foldout.el} library, you must reload
1247 it in order for this to take effect.
1248
1249 To use the Foldout package, you can type @kbd{M-x load-library
1250 @key{RET} foldout @key{RET}}; or you can arrange for to do that
1251 automatically by putting this in your @file{.emacs} file:
1252
1253 @example
1254 (eval-after-load "outline" '(require 'foldout))
1255 @end example
1256
1257 @node TeX Mode
1258 @section @TeX{} Mode
1259 @cindex @TeX{} mode
1260 @cindex La@TeX{} mode
1261 @cindex Sli@TeX{} mode
1262 @cindex Doc@TeX{} mode
1263 @cindex mode, @TeX{}
1264 @cindex mode, La@TeX{}
1265 @cindex mode, Sli@TeX{}
1266 @cindex mode, Doc@TeX{}
1267 @findex tex-mode
1268 @findex plain-tex-mode
1269 @findex latex-mode
1270 @findex slitex-mode
1271 @findex doctex-mode
1272 @findex bibtex-mode
1273
1274 Emacs provides special major modes for editing files written in
1275 @TeX{} and its related formats. @TeX{} is a powerful text formatter
1276 written by Donald Knuth; like GNU Emacs, it is free software.
1277 La@TeX{} is a simplified input format for @TeX{}, implemented using
1278 @TeX{} macros. Doc@TeX{} is a special file format in which the
1279 La@TeX{} sources are written, combining sources with documentation.
1280 Sli@TeX{} is an obsolete special form of La@TeX{}.@footnote{It has
1281 been replaced by the @samp{slides} document class, which comes with
1282 La@TeX{}.}
1283
1284 @vindex tex-default-mode
1285 @TeX{} mode has four variants: Plain @TeX{} mode, La@TeX{} mode,
1286 Doc@TeX{} mode, and Sli@TeX{} mode. These distinct major modes differ
1287 only slightly, and are designed for editing the four different
1288 formats. Emacs selects the appropriate mode by looking at the
1289 contents of the buffer. (This is done by the @code{tex-mode} command,
1290 which is normally called automatically when you visit a @TeX{}-like
1291 file. @xref{Choosing Modes}.) If the contents are insufficient to
1292 determine this, Emacs chooses the mode specified by the variable
1293 @code{tex-default-mode}; its default value is @code{latex-mode}. If
1294 Emacs does not guess right, you can select the correct variant of
1295 @TeX{} mode using the command @kbd{M-x plain-tex-mode}, @kbd{M-x
1296 latex-mode}, @kbd{M-x slitex-mode}, or @kbd{doctex-mode}.
1297
1298 Emacs also provides Bib@TeX{} mode, a major mode for editing
1299 Bib@TeX{} files. Bib@TeX{} is a tool for storing and formatting
1300 bibliographic references, which is commonly used together with
1301 La@TeX{}. In addition, the Ref@TeX{} package provides a minor mode
1302 which can be used in conjunction with La@TeX{} mode to manage
1303 bibliographic references. @inforef{Top,, reftex}.
1304
1305 @menu
1306 * Editing: TeX Editing. Special commands for editing in TeX mode.
1307 * LaTeX: LaTeX Editing. Additional commands for LaTeX input files.
1308 * Printing: TeX Print. Commands for printing part of a file with TeX.
1309 * Misc: TeX Misc. Customization of TeX mode, and related features.
1310 @end menu
1311
1312 @node TeX Editing
1313 @subsection @TeX{} Editing Commands
1314
1315 @table @kbd
1316 @item "
1317 Insert, according to context, either @samp{``} or @samp{"} or
1318 @samp{''} (@code{tex-insert-quote}).
1319 @item C-j
1320 Insert a paragraph break (two newlines) and check the previous
1321 paragraph for unbalanced braces or dollar signs
1322 (@code{tex-terminate-paragraph}).
1323 @item M-x tex-validate-region
1324 Check each paragraph in the region for unbalanced braces or dollar signs.
1325 @item C-c @{
1326 Insert @samp{@{@}} and position point between them (@code{tex-insert-braces}).
1327 @item C-c @}
1328 Move forward past the next unmatched close brace (@code{up-list}).
1329 @end table
1330
1331 @findex tex-insert-quote
1332 @kindex " @r{(@TeX{} mode)}
1333 In @TeX{}, the character @samp{"} is not normally used; instead,
1334 quotations begin with @samp{``} and end with @samp{''}. For
1335 convenience, @TeX{} mode overrides the normal meaning of the key
1336 @kbd{"} with a command that inserts a pair of single-quotes or
1337 backquotes (@code{tex-insert-quote}). To be precise, it inserts
1338 @samp{``} after whitespace or an open brace, @samp{"} after a
1339 backslash, and @samp{''} after any other character.
1340
1341 As a special exception, if you type @kbd{"} when the text before
1342 point is either @samp{``} or @samp{''}, Emacs replaces that preceding
1343 text with a single @samp{"} character. You can therefore type
1344 @kbd{""} to insert @samp{"}, should you ever need to do so. (You can
1345 also use @kbd{C-q "} to insert this character.)
1346
1347 To disable the @kbd{"} expansion feature, eliminate that binding in
1348 the local map (@pxref{Key Bindings}).
1349
1350 In @TeX{} mode, @samp{$} has a special syntax code which attempts to
1351 understand the way @TeX{} math mode delimiters match. When you insert a
1352 @samp{$} that is meant to exit math mode, the position of the matching
1353 @samp{$} that entered math mode is displayed for a second. This is the
1354 same feature that displays the open brace that matches a close brace that
1355 is inserted. However, there is no way to tell whether a @samp{$} enters
1356 math mode or leaves it; so when you insert a @samp{$} that enters math
1357 mode, the previous @samp{$} position is shown as if it were a match, even
1358 though they are actually unrelated.
1359
1360 @findex tex-insert-braces
1361 @kindex C-c @{ @r{(@TeX{} mode)}
1362 @findex up-list
1363 @kindex C-c @} @r{(@TeX{} mode)}
1364 @TeX{} uses braces as delimiters that must match. Some users prefer
1365 to keep braces balanced at all times, rather than inserting them
1366 singly. Use @kbd{C-c @{} (@code{tex-insert-braces}) to insert a pair of
1367 braces. It leaves point between the two braces so you can insert the
1368 text that belongs inside. Afterward, use the command @kbd{C-c @}}
1369 (@code{up-list}) to move forward past the close brace.
1370
1371 @findex tex-validate-region
1372 @findex tex-terminate-paragraph
1373 @kindex C-j @r{(@TeX{} mode)}
1374 There are two commands for checking the matching of braces. @kbd{C-j}
1375 (@code{tex-terminate-paragraph}) checks the paragraph before point, and
1376 inserts two newlines to start a new paragraph. It outputs a message in
1377 the echo area if any mismatch is found. @kbd{M-x tex-validate-region}
1378 checks a region, paragraph by paragraph. The errors are listed in the
1379 @samp{*Occur*} buffer, and you can use @kbd{C-c C-c} or @kbd{Mouse-2} in
1380 that buffer to go to a particular mismatch.
1381
1382 Note that Emacs commands count square brackets and parentheses in
1383 @TeX{} mode, not just braces. This is not strictly correct for the
1384 purpose of checking @TeX{} syntax. However, parentheses and square
1385 brackets are likely to be used in text as matching delimiters, and it
1386 is useful for the various motion commands and automatic match display
1387 to work with them.
1388
1389 @node LaTeX Editing
1390 @subsection La@TeX{} Editing Commands
1391
1392 La@TeX{} mode (and its obsolete variant, Sli@TeX{} mode) provide a
1393 few extra features not applicable to plain @TeX{}:
1394
1395 @table @kbd
1396 @item C-c C-o
1397 Insert @samp{\begin} and @samp{\end} for La@TeX{} block and position
1398 point on a line between them (@code{tex-latex-block}).
1399 @item C-c C-e
1400 Close the innermost La@TeX{} block not yet closed
1401 (@code{tex-close-latex-block}).
1402 @end table
1403
1404 @findex tex-latex-block
1405 @kindex C-c C-o @r{(La@TeX{} mode)}
1406 @vindex latex-block-names
1407 In La@TeX{} input, @samp{\begin} and @samp{\end} commands are used to
1408 group blocks of text. To insert a @samp{\begin} and a matching
1409 @samp{\end} (on a new line following the @samp{\begin}), use @kbd{C-c
1410 C-o} (@code{tex-latex-block}). A blank line is inserted between the
1411 two, and point is left there. You can use completion when you enter the
1412 block type; to specify additional block type names beyond the standard
1413 list, set the variable @code{latex-block-names}. For example, here's
1414 how to add @samp{theorem}, @samp{corollary}, and @samp{proof}:
1415
1416 @example
1417 (setq latex-block-names '("theorem" "corollary" "proof"))
1418 @end example
1419
1420 @findex tex-close-latex-block
1421 @kindex C-c C-e @r{(La@TeX{} mode)}
1422 In La@TeX{} input, @samp{\begin} and @samp{\end} commands must
1423 balance. You can use @kbd{C-c C-e} (@code{tex-close-latex-block}) to
1424 insert automatically a matching @samp{\end} to match the last unmatched
1425 @samp{\begin}. It indents the @samp{\end} to match the corresponding
1426 @samp{\begin}. It inserts a newline after @samp{\end} if point is at
1427 the beginning of a line.
1428
1429 @node TeX Print
1430 @subsection @TeX{} Printing Commands
1431
1432 You can invoke @TeX{} as an inferior of Emacs on either the entire
1433 contents of the buffer or just a region at a time. Running @TeX{} in
1434 this way on just one chapter is a good way to see what your changes
1435 look like without taking the time to format the entire file.
1436
1437 @table @kbd
1438 @item C-c C-r
1439 Invoke @TeX{} on the current region, together with the buffer's header
1440 (@code{tex-region}).
1441 @item C-c C-b
1442 Invoke @TeX{} on the entire current buffer (@code{tex-buffer}).
1443 @item C-c @key{TAB}
1444 Invoke Bib@TeX{} on the current file (@code{tex-bibtex-file}).
1445 @item C-c C-f
1446 Invoke @TeX{} on the current file (@code{tex-file}).
1447 @item C-c C-l
1448 Recenter the window showing output from the inferior @TeX{} so that
1449 the last line can be seen (@code{tex-recenter-output-buffer}).
1450 @item C-c C-k
1451 Kill the @TeX{} subprocess (@code{tex-kill-job}).
1452 @item C-c C-p
1453 Print the output from the last @kbd{C-c C-r}, @kbd{C-c C-b}, or @kbd{C-c
1454 C-f} command (@code{tex-print}).
1455 @item C-c C-v
1456 Preview the output from the last @kbd{C-c C-r}, @kbd{C-c C-b}, or @kbd{C-c
1457 C-f} command (@code{tex-view}).
1458 @item C-c C-q
1459 Show the printer queue (@code{tex-show-print-queue}).
1460 @item C-c C-c
1461 Invoke some other compilation command on the entire current buffer
1462 (@code{tex-compile}).
1463 @end table
1464
1465 @findex tex-buffer
1466 @kindex C-c C-b @r{(@TeX{} mode)}
1467 @findex tex-print
1468 @kindex C-c C-p @r{(@TeX{} mode)}
1469 @findex tex-view
1470 @kindex C-c C-v @r{(@TeX{} mode)}
1471 @findex tex-show-print-queue
1472 @kindex C-c C-q @r{(@TeX{} mode)}
1473 You can pass the current buffer through an inferior @TeX{} by means of
1474 @kbd{C-c C-b} (@code{tex-buffer}). The formatted output appears in a
1475 temporary file; to print it, type @kbd{C-c C-p} (@code{tex-print}).
1476 Afterward, you can use @kbd{C-c C-q} (@code{tex-show-print-queue}) to
1477 view the progress of your output towards being printed. If your terminal
1478 has the ability to display @TeX{} output files, you can preview the
1479 output on the terminal with @kbd{C-c C-v} (@code{tex-view}).
1480
1481 @cindex @env{TEXINPUTS} environment variable
1482 @vindex tex-directory
1483 You can specify the directory to use for running @TeX{} by setting the
1484 variable @code{tex-directory}. @code{"."} is the default value. If
1485 your environment variable @env{TEXINPUTS} contains relative directory
1486 names, or if your files contains @samp{\input} commands with relative
1487 file names, then @code{tex-directory} @emph{must} be @code{"."} or you
1488 will get the wrong results. Otherwise, it is safe to specify some other
1489 directory, such as @code{"/tmp"}.
1490
1491 @vindex tex-run-command
1492 @vindex latex-run-command
1493 @vindex slitex-run-command
1494 @vindex tex-dvi-print-command
1495 @vindex tex-dvi-view-command
1496 @vindex tex-show-queue-command
1497 If you want to specify which shell commands are used in the inferior @TeX{},
1498 you can do so by setting the values of the variables @code{tex-run-command},
1499 @code{latex-run-command}, @code{slitex-run-command},
1500 @code{tex-dvi-print-command}, @code{tex-dvi-view-command}, and
1501 @code{tex-show-queue-command}. The default values may
1502 (or may not) be appropriate for your system.
1503
1504 Normally, the file name given to these commands comes at the end of
1505 the command string; for example, @samp{latex @var{filename}}. In some
1506 cases, however, the file name needs to be embedded in the command; an
1507 example is when you need to provide the file name as an argument to one
1508 command whose output is piped to another. You can specify where to put
1509 the file name with @samp{*} in the command string. For example,
1510
1511 @example
1512 (setq tex-dvi-print-command "dvips -f * | lpr")
1513 @end example
1514
1515 @findex tex-kill-job
1516 @kindex C-c C-k @r{(@TeX{} mode)}
1517 @findex tex-recenter-output-buffer
1518 @kindex C-c C-l @r{(@TeX{} mode)}
1519 The terminal output from @TeX{}, including any error messages, appears
1520 in a buffer called @samp{*tex-shell*}. If @TeX{} gets an error, you can
1521 switch to this buffer and feed it input (this works as in Shell mode;
1522 @pxref{Interactive Shell}). Without switching to this buffer you can
1523 scroll it so that its last line is visible by typing @kbd{C-c
1524 C-l}.
1525
1526 Type @kbd{C-c C-k} (@code{tex-kill-job}) to kill the @TeX{} process if
1527 you see that its output is no longer useful. Using @kbd{C-c C-b} or
1528 @kbd{C-c C-r} also kills any @TeX{} process still running.
1529
1530 @findex tex-region
1531 @kindex C-c C-r @r{(@TeX{} mode)}
1532 You can also pass an arbitrary region through an inferior @TeX{} by typing
1533 @kbd{C-c C-r} (@code{tex-region}). This is tricky, however, because most files
1534 of @TeX{} input contain commands at the beginning to set parameters and
1535 define macros, without which no later part of the file will format
1536 correctly. To solve this problem, @kbd{C-c C-r} allows you to designate a
1537 part of the file as containing essential commands; it is included before
1538 the specified region as part of the input to @TeX{}. The designated part
1539 of the file is called the @dfn{header}.
1540
1541 @cindex header (@TeX{} mode)
1542 To indicate the bounds of the header in Plain @TeX{} mode, you insert two
1543 special strings in the file. Insert @samp{%**start of header} before the
1544 header, and @samp{%**end of header} after it. Each string must appear
1545 entirely on one line, but there may be other text on the line before or
1546 after. The lines containing the two strings are included in the header.
1547 If @samp{%**start of header} does not appear within the first 100 lines of
1548 the buffer, @kbd{C-c C-r} assumes that there is no header.
1549
1550 In La@TeX{} mode, the header begins with @samp{\documentclass} or
1551 @samp{\documentstyle} and ends with @samp{\begin@{document@}}. These
1552 are commands that La@TeX{} requires you to use in any case, so nothing
1553 special needs to be done to identify the header.
1554
1555 @findex tex-file
1556 @kindex C-c C-f @r{(@TeX{} mode)}
1557 The commands (@code{tex-buffer}) and (@code{tex-region}) do all of their
1558 work in a temporary directory, and do not have available any of the auxiliary
1559 files needed by @TeX{} for cross-references; these commands are generally
1560 not suitable for running the final copy in which all of the cross-references
1561 need to be correct.
1562
1563 When you want the auxiliary files for cross references, use @kbd{C-c
1564 C-f} (@code{tex-file}) which runs @TeX{} on the current buffer's file,
1565 in that file's directory. Before running @TeX{}, it offers to save any
1566 modified buffers. Generally, you need to use (@code{tex-file}) twice to
1567 get the cross-references right.
1568
1569 @vindex tex-start-options
1570 The value of the variable @code{tex-start-options} specifies
1571 options for the @TeX{} run.
1572
1573 @vindex tex-start-commands
1574 The value of the variable @code{tex-start-commands} specifies @TeX{}
1575 commands for starting @TeX{}. The default value causes @TeX{} to run
1576 in nonstop mode. To run @TeX{} interactively, set the variable to
1577 @code{""}.
1578
1579 @vindex tex-main-file
1580 Large @TeX{} documents are often split into several files---one main
1581 file, plus subfiles. Running @TeX{} on a subfile typically does not
1582 work; you have to run it on the main file. In order to make
1583 @code{tex-file} useful when you are editing a subfile, you can set the
1584 variable @code{tex-main-file} to the name of the main file. Then
1585 @code{tex-file} runs @TeX{} on that file.
1586
1587 The most convenient way to use @code{tex-main-file} is to specify it
1588 in a local variable list in each of the subfiles. @xref{File
1589 Variables}.
1590
1591 @findex tex-bibtex-file
1592 @kindex C-c TAB @r{(@TeX{} mode)}
1593 @vindex tex-bibtex-command
1594 For La@TeX{} files, you can use Bib@TeX{} to process the auxiliary
1595 file for the current buffer's file. Bib@TeX{} looks up bibliographic
1596 citations in a data base and prepares the cited references for the
1597 bibliography section. The command @kbd{C-c @key{TAB}}
1598 (@code{tex-bibtex-file}) runs the shell command
1599 (@code{tex-bibtex-command}) to produce a @samp{.bbl} file for the
1600 current buffer's file. Generally, you need to do @kbd{C-c C-f}
1601 (@code{tex-file}) once to generate the @samp{.aux} file, then do
1602 @kbd{C-c @key{TAB}} (@code{tex-bibtex-file}), and then repeat @kbd{C-c C-f}
1603 (@code{tex-file}) twice more to get the cross-references correct.
1604
1605 @findex tex-compile
1606 @kindex C-c C-c @r{(@TeX{} mode)}
1607 To invoke some other compilation program on the current @TeX{}
1608 buffer, type @kbd{C-c C-c} (@code{tex-compile}). This command knows
1609 how to pass arguments to many common programs, including
1610 @file{pdflatex}, @file{yap}, @file{xdvi}, and @file{dvips}. You can
1611 select your desired compilation program using the standard completion
1612 keys (@pxref{Completion}).
1613
1614 @node TeX Misc
1615 @subsection @TeX{} Mode Miscellany
1616
1617 @vindex tex-shell-hook
1618 @vindex tex-mode-hook
1619 @vindex latex-mode-hook
1620 @vindex slitex-mode-hook
1621 @vindex plain-tex-mode-hook
1622 Entering any variant of @TeX{} mode runs the hooks
1623 @code{text-mode-hook} and @code{tex-mode-hook}. Then it runs either
1624 @code{plain-tex-mode-hook}, @code{latex-mode-hook}, or
1625 @code{slitex-mode-hook}, whichever is appropriate. Starting the
1626 @TeX{} shell runs the hook @code{tex-shell-hook}. @xref{Hooks}.
1627
1628 @findex iso-iso2tex
1629 @findex iso-tex2iso
1630 @findex iso-iso2gtex
1631 @findex iso-gtex2iso
1632 @cindex Latin-1 @TeX{} encoding
1633 @cindex @TeX{} encoding
1634 The commands @kbd{M-x iso-iso2tex}, @kbd{M-x iso-tex2iso}, @kbd{M-x
1635 iso-iso2gtex} and @kbd{M-x iso-gtex2iso} can be used to convert
1636 between Latin-1 encoded files and @TeX{}-encoded equivalents.
1637 @ignore
1638 @c Too cryptic to be useful, too cryptic for me to make it better -- rms.
1639 They
1640 are included by default in the @code{format-alist} variable, so they
1641 can be used with @kbd{M-x format-find-file}, for instance.
1642 @end ignore
1643
1644 @ignore @c Not worth documenting if it is only for Czech -- rms.
1645 @findex tildify-buffer
1646 @findex tildify-region
1647 @cindex ties, @TeX{}, inserting
1648 @cindex hard spaces, @TeX{}, inserting
1649 The commands @kbd{M-x tildify-buffer} and @kbd{M-x tildify-region}
1650 insert @samp{~} (@dfn{tie}) characters where they are conventionally
1651 required. This is set up for Czech---customize the group
1652 @samp{tildify} for other languages or for other sorts of markup.
1653 @end ignore
1654
1655 @cindex Ref@TeX{} package
1656 @cindex references, La@TeX{}
1657 @cindex La@TeX{} references
1658 For managing all kinds of references for La@TeX{}, you can use
1659 Ref@TeX{}. @inforef{Top,, reftex}.
1660
1661 @node HTML Mode
1662 @section SGML and HTML Modes
1663 @cindex SGML mode
1664 @cindex HTML mode
1665 @cindex mode, SGML
1666 @cindex mode, HTML
1667 @findex sgml-mode
1668 @findex html-mode
1669
1670 The major modes for SGML and HTML provide indentation support and
1671 commands for operating on tags. HTML mode is a slightly customized
1672 variant of SGML mode.
1673
1674 @table @kbd
1675 @item C-c C-n
1676 @kindex C-c C-n @r{(SGML mode)}
1677 @findex sgml-name-char
1678 Interactively specify a special character and insert the SGML
1679 @samp{&}-command for that character (@code{sgml-name-char}).
1680
1681 @item C-c C-t
1682 @kindex C-c C-t @r{(SGML mode)}
1683 @findex sgml-tag
1684 Interactively specify a tag and its attributes (@code{sgml-tag}).
1685 This command asks you for a tag name and for the attribute values,
1686 then inserts both the opening tag and the closing tag, leaving point
1687 between them.
1688
1689 With a prefix argument @var{n}, the command puts the tag around the
1690 @var{n} words already present in the buffer after point. Whenever a
1691 region is active, it puts the tag around the region (when Transient
1692 Mark mode is off, it does this when a numeric argument of @minus{}1 is
1693 supplied.)
1694
1695 @item C-c C-a
1696 @kindex C-c C-a @r{(SGML mode)}
1697 @findex sgml-attributes
1698 Interactively insert attribute values for the current tag
1699 (@code{sgml-attributes}).
1700
1701 @item C-c C-f
1702 @kindex C-c C-f @r{(SGML mode)}
1703 @findex sgml-skip-tag-forward
1704 Skip across a balanced tag group (which extends from an opening tag
1705 through its corresponding closing tag) (@code{sgml-skip-tag-forward}).
1706 A numeric argument acts as a repeat count.
1707
1708 @item C-c C-b
1709 @kindex C-c C-b @r{(SGML mode)}
1710 @findex sgml-skip-tag-backward
1711 Skip backward across a balanced tag group (which extends from an
1712 opening tag through its corresponding closing tag)
1713 (@code{sgml-skip-tag-backward}). A numeric argument acts as a repeat
1714 count.
1715
1716 @item C-c C-d
1717 @kindex C-c C-d @r{(SGML mode)}
1718 @findex sgml-delete-tag
1719 Delete the tag at or after point, and delete the matching tag too
1720 (@code{sgml-delete-tag}). If the tag at or after point is an opening
1721 tag, delete the closing tag too; if it is a closing tag, delete the
1722 opening tag too.
1723
1724 @item C-c ? @var{tag} @key{RET}
1725 @kindex C-c ? @r{(SGML mode)}
1726 @findex sgml-tag-help
1727 Display a description of the meaning of tag @var{tag}
1728 (@code{sgml-tag-help}). If the argument @var{tag} is empty, describe
1729 the tag at point.
1730
1731 @item C-c /
1732 @kindex C-c / @r{(SGML mode)}
1733 @findex sgml-close-tag
1734 Insert a close tag for the innermost unterminated tag
1735 (@code{sgml-close-tag}). If called from within a tag or a comment,
1736 close this element instead of inserting a close tag.
1737
1738 @item C-c 8
1739 @kindex C-c 8 @r{(SGML mode)}
1740 @findex sgml-name-8bit-mode
1741 Toggle a minor mode in which Latin-1 characters insert the
1742 corresponding SGML commands that stand for them, instead of the
1743 characters themselves (@code{sgml-name-8bit-mode}).
1744
1745 @item C-c C-v
1746 @kindex C-c C-v @r{(SGML mode)}
1747 @findex sgml-validate
1748 Run a shell command (which you must specify) to validate the current
1749 buffer as SGML (@code{sgml-validate}).
1750
1751 @item C-c TAB
1752 @kindex C-c TAB @r{(SGML mode)}
1753 @findex sgml-tags-invisible
1754 Toggle the visibility of existing tags in the buffer. This can be
1755 used as a cheap preview (@code{sgml-tags-invisible}).
1756 @end table
1757
1758 @cindex nXML mode
1759 @cindex mode, nXML
1760 @findex nxml-mode
1761 @cindex XML schema
1762 The default mode for editing XML documents is called nXML mode
1763 (@code{xml-mode} or @code{nxml-mode}). This is a powerful major mode
1764 that can recognize many existing XML schema and use them to provide
1765 completion of XML elements via @kbd{C-@key{RET}} or @kbd{M-@key{TAB}},
1766 as well as ``on-the-fly'' XML validation with error highlighting. It
1767 is described in its own manual. @xref{Top, nXML Mode,,nxml-mode, nXML
1768 Mode}.
1769
1770 @vindex sgml-xml-mode
1771 However, you can also use SGML mode to edit XML, since XML is a
1772 strict subset of SGML. In XML, every opening tag must have an
1773 explicit closing tag. When the variable @code{sgml-xml-mode} is
1774 non-@code{nil}, the tag insertion commands described above always
1775 insert explicit closing tags as well. When you visit a file in SGML
1776 mode, Emacs determines whether it is XML by examining the file
1777 contents, and sets @code{sgml-xml-mode} accordingly.
1778
1779 @node Nroff Mode
1780 @section Nroff Mode
1781
1782 @cindex nroff
1783 @findex nroff-mode
1784 Nroff mode is a mode like Text mode but modified to handle nroff commands
1785 present in the text. Invoke @kbd{M-x nroff-mode} to enter this mode. It
1786 differs from Text mode in only a few ways. All nroff command lines are
1787 considered paragraph separators, so that filling will never garble the
1788 nroff commands. Pages are separated by @samp{.bp} commands. Comments
1789 start with backslash-doublequote. Also, three special commands are
1790 provided that are not in Text mode:
1791
1792 @findex forward-text-line
1793 @findex backward-text-line
1794 @findex count-text-lines
1795 @kindex M-n @r{(Nroff mode)}
1796 @kindex M-p @r{(Nroff mode)}
1797 @kindex M-? @r{(Nroff mode)}
1798 @table @kbd
1799 @item M-n
1800 Move to the beginning of the next line that isn't an nroff command
1801 (@code{forward-text-line}). An argument is a repeat count.
1802 @item M-p
1803 Like @kbd{M-n} but move up (@code{backward-text-line}).
1804 @item M-?
1805 Displays in the echo area the number of text lines (lines that are not
1806 nroff commands) in the region (@code{count-text-lines}).
1807 @end table
1808
1809 @findex electric-nroff-mode
1810 The other feature of Nroff mode is that you can turn on Electric Nroff
1811 mode. This is a minor mode that you can turn on or off with @kbd{M-x
1812 electric-nroff-mode} (@pxref{Minor Modes}). When the mode is on, each
1813 time you use @key{RET} to end a line that contains an nroff command that
1814 opens a kind of grouping, the matching nroff command to close that
1815 grouping is automatically inserted on the following line. For example,
1816 if you are at the beginning of a line and type @kbd{.@: ( b @key{RET}},
1817 this inserts the matching command @samp{.)b} on a new line following
1818 point.
1819
1820 If you use Outline minor mode with Nroff mode (@pxref{Outline Mode}),
1821 heading lines are lines of the form @samp{.H} followed by a number (the
1822 header level).
1823
1824 @vindex nroff-mode-hook
1825 Entering Nroff mode runs the hook @code{text-mode-hook}, followed by
1826 the hook @code{nroff-mode-hook} (@pxref{Hooks}).
1827
1828 @node Formatted Text
1829 @section Editing Formatted Text
1830
1831 @cindex Enriched mode
1832 @cindex mode, Enriched
1833 @cindex formatted text
1834 @cindex WYSIWYG
1835 @cindex word processing
1836 @dfn{Enriched mode} is a minor mode for editing files that contain
1837 formatted text in WYSIWYG fashion, as in a word processor. Currently,
1838 formatted text in Enriched mode can specify fonts, colors, underlining,
1839 margins, and types of filling and justification. In the future, we plan
1840 to implement other formatting features as well.
1841
1842 Enriched mode is a minor mode (@pxref{Minor Modes}). It is
1843 typically used in conjunction with Text mode (@pxref{Text Mode}), but
1844 you can also use it with other major modes such as Outline mode and
1845 Paragraph-Indent Text mode.
1846
1847 @cindex text/enriched MIME format
1848 Potentially, Emacs can store formatted text files in various file
1849 formats. Currently, only one format is implemented: @dfn{text/enriched}
1850 format, which is defined by the MIME protocol. @xref{Format
1851 Conversion,, Format Conversion, elisp, the Emacs Lisp Reference Manual},
1852 for details of how Emacs recognizes and converts file formats.
1853
1854 The Emacs distribution contains a formatted text file that can serve as
1855 an example. Its name is @file{etc/enriched.doc}. It contains samples
1856 illustrating all the features described in this section. It also
1857 contains a list of ideas for future enhancements.
1858
1859 @menu
1860 * Requesting Formatted Text:: Entering and exiting Enriched mode.
1861 * Hard and Soft Newlines:: There are two different kinds of newlines.
1862 * Editing Format Info:: How to edit text properties.
1863 * Faces: Format Faces. Bold, italic, underline, etc.
1864 * Color: Format Colors. Changing the color of text.
1865 * Indent: Format Indentation. Changing the left and right margins.
1866 * Justification: Format Justification.
1867 Centering, setting text flush with the
1868 left or right margin, etc.
1869 * Special: Format Properties. The "special" text properties submenu.
1870 * Forcing Enriched Mode:: How to force use of Enriched mode.
1871 @end menu
1872
1873 @node Requesting Formatted Text
1874 @subsection Requesting to Edit Formatted Text
1875
1876 Whenever you visit a file that Emacs saved in the text/enriched
1877 format, Emacs automatically converts the formatting information in the
1878 file into Emacs's own internal format (known as @dfn{text
1879 properties}), and turns on Enriched mode.
1880
1881 @findex enriched-mode
1882 To create a new file of formatted text, first visit the nonexistent
1883 file, then type @kbd{M-x enriched-mode} before you start inserting text.
1884 This command turns on Enriched mode. Do this before you begin inserting
1885 text, to ensure that the text you insert is handled properly.
1886
1887 More generally, the command @code{enriched-mode} turns Enriched mode
1888 on if it was off, and off if it was on. With a prefix argument, this
1889 command turns Enriched mode on if the argument is positive, and turns
1890 the mode off otherwise.
1891
1892 When you save a buffer while Enriched mode is enabled in it, Emacs
1893 automatically converts the text to text/enriched format while writing it
1894 into the file. When you visit the file again, Emacs will automatically
1895 recognize the format, reconvert the text, and turn on Enriched mode
1896 again.
1897
1898 @vindex enriched-translations
1899 You can add annotations for saving additional text properties, which
1900 Emacs normally does not save, by adding to @code{enriched-translations}.
1901 Note that the text/enriched standard requires any non-standard
1902 annotations to have names starting with @samp{x-}, as in
1903 @samp{x-read-only}. This ensures that they will not conflict with
1904 standard annotations that may be added later.
1905
1906 @xref{Text Properties,,, elisp, the Emacs Lisp Reference Manual},
1907 for more information about text properties.
1908
1909 @node Hard and Soft Newlines
1910 @subsection Hard and Soft Newlines
1911 @cindex hard newline
1912 @cindex soft newline
1913 @cindex newlines, hard and soft
1914
1915 @cindex use-hard-newlines
1916 In formatted text, Emacs distinguishes between two different kinds of
1917 newlines, @dfn{hard} newlines and @dfn{soft} newlines. (You can enable
1918 or disable this feature separately in any buffer with the command
1919 @code{use-hard-newlines}.)
1920
1921 Hard newlines are used to separate paragraphs, or items in a list, or
1922 anywhere that there should always be a line break regardless of the
1923 margins. The @key{RET} command (@code{newline}) and @kbd{C-o}
1924 (@code{open-line}) insert hard newlines.
1925
1926 Soft newlines are used to make text fit between the margins. All the
1927 fill commands, including Auto Fill, insert soft newlines---and they
1928 delete only soft newlines.
1929
1930 Although hard and soft newlines look the same, it is important to bear
1931 the difference in mind. Do not use @key{RET} to break lines in the
1932 middle of filled paragraphs, or else you will get hard newlines that are
1933 barriers to further filling. Instead, let Auto Fill mode break lines,
1934 so that if the text or the margins change, Emacs can refill the lines
1935 properly. @xref{Auto Fill}.
1936
1937 On the other hand, in tables and lists, where the lines should always
1938 remain as you type them, you can use @key{RET} to end lines. For these
1939 lines, you may also want to set the justification style to
1940 @code{unfilled}. @xref{Format Justification}.
1941
1942 @node Editing Format Info
1943 @subsection Editing Format Information
1944
1945 There are two ways to alter the formatting information for a formatted
1946 text file: with keyboard commands, and with the mouse.
1947
1948 The easiest way to add properties to your document is with the Text
1949 Properties menu. You can get to this menu in two ways: from the Edit
1950 menu in the menu bar (use @kbd{@key{F10} e t} if you have no mouse),
1951 or with @kbd{C-Mouse-2} (hold the @key{CTRL} key and press the middle
1952 mouse button). There are also keyboard commands described in the
1953 following section.
1954
1955 These items in the Text Properties menu run commands directly:
1956
1957 @table @code
1958 @findex facemenu-remove-face-props
1959 @item Remove Face Properties
1960 Delete from the region all face and color text properties
1961 (@code{facemenu-remove-face-props}).
1962
1963 @findex facemenu-remove-all
1964 @item Remove Text Properties
1965 Delete @emph{all} text properties from the region
1966 (@code{facemenu-remove-all}).
1967
1968 @findex describe-text-properties
1969 @cindex text properties of characters
1970 @cindex overlays at character position
1971 @cindex widgets at buffer position
1972 @cindex buttons at buffer position
1973 @item Describe Properties
1974 List all the text properties, widgets, buttons, and overlays of the
1975 character following point (@code{describe-text-properties}).
1976
1977 @item Display Faces
1978 Display a list of all the defined faces (@code{list-faces-display}).
1979
1980 @item Display Colors
1981 Display a list of all the defined colors (@code{list-colors-display}).
1982 @end table
1983
1984 @ifinfo
1985 Other items in the Text Properties menu lead to submenus:
1986
1987 @menu
1988 * Faces: Format Faces. Bold, italic, underline, etc.
1989 * Color: Format Colors. Changing the color of text.
1990 * Indent: Format Indentation. Changing the left and right margins.
1991 * Justification: Format Justification.
1992 Centering, setting text flush with the
1993 left or right margin, etc.
1994 * Special: Format Properties. The "special" text properties submenu.
1995 @end menu
1996 @end ifinfo
1997 @ifnotinfo
1998 The rest lead to submenus which are described in the following sections.
1999 @end ifnotinfo
2000
2001 @node Format Faces
2002 @subsection Faces in Formatted Text
2003
2004 The Faces submenu under Text Properties lists various Emacs faces
2005 including @code{bold}, @code{italic}, and @code{underline}
2006 (@pxref{Faces}). These menu items operate on the region if it is
2007 active and nonempty. Otherwise, they specify to use that face for an
2008 immediately following self-inserting character. There is also an item
2009 @samp{Other} with which you can enter a face name through the
2010 minibuffer (@pxref{Standard Faces}).
2011
2012 Instead of the Faces submenu, you can use these keyboard commands:
2013
2014 @table @kbd
2015 @kindex M-o d @r{(Enriched mode)}
2016 @findex facemenu-set-default
2017 @item M-o d
2018 Remove all @code{face} properties from the region (which includes
2019 specified colors), or force the following inserted character to have no
2020 @code{face} property (@code{facemenu-set-default}).
2021 @kindex M-o b @r{(Enriched mode)}
2022 @findex facemenu-set-bold
2023 @item M-o b
2024 Add the face @code{bold} to the region or to the following inserted
2025 character (@code{facemenu-set-bold}).
2026 @kindex M-o i @r{(Enriched mode)}
2027 @findex facemenu-set-italic
2028 @item M-o i
2029 Add the face @code{italic} to the region or to the following inserted
2030 character (@code{facemenu-set-italic}).
2031 @kindex M-o l @r{(Enriched mode)}
2032 @findex facemenu-set-bold-italic
2033 @item M-o l
2034 Add the face @code{bold-italic} to the region or to the following
2035 inserted character (@code{facemenu-set-bold-italic}).
2036 @kindex M-o u @r{(Enriched mode)}
2037 @findex facemenu-set-underline
2038 @item M-o u
2039 Add the face @code{underline} to the region or to the following inserted
2040 character (@code{facemenu-set-underline}).
2041 @kindex M-o o @r{(Enriched mode)}
2042 @findex facemenu-set-face
2043 @item M-o o @var{face} @key{RET}
2044 Add the face @var{face} to the region or to the following inserted
2045 character (@code{facemenu-set-face}).
2046 @end table
2047
2048 With a prefix argument, all these commands apply to an immediately
2049 following self-inserting character, disregarding the region.
2050
2051 A self-inserting character normally inherits the @code{face}
2052 property (and most other text properties) from the preceding character
2053 in the buffer. If you use the above commands to specify face for the
2054 next self-inserting character, or the next section's commands to
2055 specify a foreground or background color for it, then it does not
2056 inherit the @code{face} property from the preceding character; instead
2057 it uses whatever you specified. It will still inherit other text
2058 properties, though.
2059
2060 Strictly speaking, these commands apply only to the first following
2061 self-inserting character that you type. But if you insert additional
2062 characters after it, they will inherit from the first one. So it
2063 appears that these commands apply to all of them.
2064
2065 Enriched mode defines two additional faces: @code{excerpt} and
2066 @code{fixed}. These correspond to codes used in the text/enriched file
2067 format.
2068
2069 The @code{excerpt} face is intended for quotations. This face is the
2070 same as @code{italic} unless you customize it (@pxref{Face Customization}).
2071
2072 The @code{fixed} face means, ``Use a fixed-width font for this part
2073 of the text.'' Applying the @code{fixed} face to a part of the text
2074 will cause that part of the text to appear in a fixed-width font, even
2075 if the default font is variable-width. This applies to Emacs and to
2076 other systems that display text/enriched format. So if you
2077 specifically want a certain part of the text to use a fixed-width
2078 font, you should specify the @code{fixed} face for that part.
2079
2080 By default, the @code{fixed} face looks the same as @code{bold}.
2081 This is an attempt to distinguish it from @code{default}. You may
2082 wish to customize @code{fixed} to some other fixed-width medium font.
2083 @xref{Face Customization}.
2084
2085 If your terminal cannot display different faces, you will not be
2086 able to see them, but you can still edit documents containing faces,
2087 and even add faces and colors to documents. The faces you specify
2088 will be visible when the file is viewed on a terminal that can display
2089 them.
2090
2091 @node Format Colors
2092 @subsection Colors in Formatted Text
2093
2094 You can specify foreground and background colors for portions of the
2095 text. Under Text Properties, there is a submenu for specifying the
2096 foreground color, and a submenu for specifying the background color.
2097 Each one lists all the colors that you have used in Enriched mode in
2098 the current Emacs session.
2099
2100 If the region is active, the command applies to the text in the
2101 region; otherwise, it applies to any immediately following
2102 self-inserting input. When Transient Mark mode is off
2103 (@pxref{Persistent Mark}), it always applies to the region unless a
2104 prefix argument is given, in which case it applies to the following
2105 input.
2106
2107 Each of the two color submenus contains one additional item:
2108 @samp{Other}. You can use this item to specify a color that is not
2109 listed in the menu; it reads the color name with the minibuffer. To
2110 display a list of available colors and their names, use the
2111 @samp{Display Colors} menu item in the Text Properties menu
2112 (@pxref{Editing Format Info}).
2113
2114 Any color that you specify in this way, or that is mentioned in a
2115 formatted text file that you read in, is added to the corresponding
2116 color menu for the duration of the Emacs session.
2117
2118 @findex facemenu-set-foreground
2119 @findex facemenu-set-background
2120 There are no predefined key bindings for specifying colors, but you can do so
2121 with the extended commands @kbd{M-x facemenu-set-foreground} and
2122 @kbd{M-x facemenu-set-background}. Both of these commands read the name
2123 of the color with the minibuffer.
2124
2125 @node Format Indentation
2126 @subsection Indentation in Formatted Text
2127
2128 When editing formatted text, you can specify different amounts of
2129 indentation for the right or left margin of an entire paragraph or a
2130 part of a paragraph. The margins you specify automatically affect the
2131 Emacs fill commands (@pxref{Filling}) and line-breaking commands.
2132
2133 The Indentation submenu of Text Properties provides a convenient
2134 interface for specifying these properties. The submenu contains four
2135 items:
2136
2137 @table @code
2138 @kindex C-x TAB @r{(Enriched mode)}
2139 @findex increase-left-margin
2140 @item Indent More
2141 Indent the region by 4 columns (@code{increase-left-margin}). In
2142 Enriched mode, this command is also available on @kbd{C-x @key{TAB}}; if
2143 you supply a numeric argument, that says how many columns to add to the
2144 margin (a negative argument reduces the number of columns).
2145
2146 @item Indent Less
2147 Remove 4 columns of indentation from the region.
2148
2149 @item Indent Right More
2150 Make the text narrower by indenting 4 columns at the right margin.
2151
2152 @item Indent Right Less
2153 Remove 4 columns of indentation from the right margin.
2154 @end table
2155
2156 You can use these commands repeatedly to increase or decrease the
2157 indentation.
2158
2159 The most common way to use them is to change the indentation of an
2160 entire paragraph. For other uses, the effects of refilling can be
2161 hard to predict, except in some special cases like the one described
2162 next.
2163
2164 The most common other use is to format paragraphs with @dfn{hanging
2165 indents}, which means that the first line is indented less than
2166 subsequent lines. To set up a hanging indent, increase the
2167 indentation of the region starting after the first word of the
2168 paragraph and running until the end of the paragraph.
2169
2170 Indenting the first line of a paragraph is easier. Set the margin for
2171 the whole paragraph where you want it to be for the body of the
2172 paragraph, then indent the first line by inserting extra spaces or tabs.
2173
2174 @vindex standard-indent
2175 The variable @code{standard-indent} specifies how many columns these
2176 commands should add to or subtract from the indentation. The default
2177 value is 4. The overall default right margin for Enriched mode is
2178 controlled by the variable @code{fill-column}, as usual.
2179
2180 @kindex C-c [ @r{(Enriched mode)}
2181 @kindex C-c ] @r{(Enriched mode)}
2182 @findex set-left-margin
2183 @findex set-right-margin
2184 There are also two commands for setting the left or right margin of
2185 the region absolutely: @code{set-left-margin} and
2186 @code{set-right-margin}. Enriched mode binds these commands to
2187 @kbd{C-c [} and @kbd{C-c ]}, respectively. You can specify the
2188 margin width either with a numeric argument or in the minibuffer.
2189
2190 Sometimes, as a result of editing, the filling of a paragraph becomes
2191 messed up---parts of the paragraph may extend past the left or right
2192 margins. When this happens, use @kbd{M-q} (@code{fill-paragraph}) to
2193 refill the paragraph.
2194
2195 The fill prefix, if any, works in addition to the specified paragraph
2196 indentation: @kbd{C-x .} does not include the specified indentation's
2197 whitespace in the new value for the fill prefix, and the fill commands
2198 look for the fill prefix after the indentation on each line. @xref{Fill
2199 Prefix}.
2200
2201 @node Format Justification
2202 @subsection Justification in Formatted Text
2203
2204 When editing formatted text, you can specify various styles of
2205 justification for a paragraph. The style you specify automatically
2206 affects the Emacs fill commands.
2207
2208 The Justification submenu of Text Properties provides a convenient
2209 interface for specifying the style. The submenu contains five items:
2210
2211 @table @code
2212 @item Left
2213 This is the most common style of justification (at least for English).
2214 Lines are aligned at the left margin but left uneven at the right.
2215
2216 @item Right
2217 This aligns each line with the right margin. Spaces and tabs are added
2218 on the left, if necessary, to make lines line up on the right.
2219
2220 @item Full
2221 This justifies the text, aligning both edges of each line. Justified
2222 text looks very nice in a printed book, where the spaces can all be
2223 adjusted equally, but it does not look as nice with a fixed-width font
2224 on the screen. Perhaps a future version of Emacs will be able to adjust
2225 the width of spaces in a line to achieve elegant justification.
2226
2227 @item Center
2228 This centers every line between the current margins.
2229
2230 @item Unfilled
2231 This turns off filling entirely. Each line will remain as you wrote it;
2232 the fill and auto-fill functions will have no effect on text which has
2233 this setting. You can, however, still indent the left margin. In
2234 unfilled regions, all newlines are treated as hard newlines (@pxref{Hard
2235 and Soft Newlines}) .
2236 @end table
2237
2238 In Enriched mode, you can also specify justification from the keyboard
2239 using the @kbd{M-j} prefix character:
2240
2241 @table @kbd
2242 @kindex M-j l @r{(Enriched mode)}
2243 @findex set-justification-left
2244 @item M-j l
2245 Make the region left-filled (@code{set-justification-left}).
2246 @kindex M-j r @r{(Enriched mode)}
2247 @findex set-justification-right
2248 @item M-j r
2249 Make the region right-filled (@code{set-justification-right}).
2250 @kindex M-j b @r{(Enriched mode)}
2251 @findex set-justification-full
2252 @item M-j b
2253 Make the region fully justified (@code{set-justification-full}).
2254 @kindex M-j c @r{(Enriched mode)}
2255 @kindex M-S @r{(Enriched mode)}
2256 @findex set-justification-center
2257 @item M-j c
2258 @itemx M-S
2259 Make the region centered (@code{set-justification-center}).
2260 @kindex M-j u @r{(Enriched mode)}
2261 @findex set-justification-none
2262 @item M-j u
2263 Make the region unfilled (@code{set-justification-none}).
2264 @end table
2265
2266 Justification styles apply to entire paragraphs. All the
2267 justification-changing commands operate on the paragraph containing
2268 point, or, if the region is active, on all paragraphs which overlap the
2269 region.
2270
2271 @vindex default-justification
2272 The default justification style is specified by the variable
2273 @code{default-justification}. Its value should be one of the symbols
2274 @code{left}, @code{right}, @code{full}, @code{center}, or @code{none}.
2275 This is a per-buffer variable. Setting the variable directly affects
2276 only the current buffer. However, customizing it in a Custom buffer
2277 sets (as always) the default value for buffers that do not override it.
2278 @xref{Locals}, and @ref{Easy Customization}.
2279
2280 @node Format Properties
2281 @subsection Setting Other Text Properties
2282
2283 The Special Properties submenu of Text Properties can add or remove
2284 three other useful text properties: @code{read-only}, @code{invisible}
2285 and @code{intangible}. The @code{intangible} property disallows
2286 moving point within the text, the @code{invisible} text property hides
2287 text from display, and the @code{read-only} property disallows
2288 alteration of the text.
2289
2290 Each of these special properties has a menu item to add it to the
2291 region. The last menu item, @samp{Remove Special}, removes all of these
2292 special properties from the text in the region.
2293
2294 Currently, the @code{invisible} and @code{intangible} properties are
2295 @emph{not} saved in the text/enriched format. The @code{read-only}
2296 property is saved, but it is not a standard part of the text/enriched
2297 format, so other editors may not respect it.
2298
2299 @node Forcing Enriched Mode
2300 @subsection Forcing Enriched Mode
2301
2302 Normally, Emacs knows when you are editing formatted text because it
2303 recognizes the special annotations used in the file that you visited.
2304 However, sometimes you must take special actions to convert file
2305 contents or turn on Enriched mode:
2306
2307 @itemize @bullet
2308 @item
2309 When you visit a file that was created with some other editor, Emacs may
2310 not recognize the file as being in the text/enriched format. In this
2311 case, when you visit the file you will see the formatting commands
2312 rather than the formatted text. Type @kbd{M-x format-decode-buffer} to
2313 translate it. This also automatically turns on Enriched mode.
2314
2315 @item
2316 When you @emph{insert} a file into a buffer, rather than visiting it,
2317 Emacs does the necessary conversions on the text which you insert, but
2318 it does not enable Enriched mode. If you wish to do that, type @kbd{M-x
2319 enriched-mode}.
2320 @end itemize
2321
2322 The command @code{format-decode-buffer} translates text in various
2323 formats into Emacs's internal format. It asks you to specify the format
2324 to translate from; however, normally you can type just @key{RET}, which
2325 tells Emacs to guess the format.
2326
2327 @findex format-find-file
2328 If you wish to look at a text/enriched file in its raw form, as a
2329 sequence of characters rather than as formatted text, use the @kbd{M-x
2330 find-file-literally} command. This visits a file, like
2331 @code{find-file}, but does not do format conversion. It also inhibits
2332 character code conversion (@pxref{Coding Systems}) and automatic
2333 uncompression (@pxref{Compressed Files}). To disable format conversion
2334 but allow character code conversion and/or automatic uncompression if
2335 appropriate, use @code{format-find-file} with suitable arguments.
2336
2337 @node Text Based Tables
2338 @section Editing Text-based Tables
2339 @cindex table mode
2340 @cindex text-based tables
2341
2342 Table mode provides an easy and intuitive way to create and edit WYSIWYG
2343 text-based tables. Here is an example of such a table:
2344
2345 @smallexample
2346 @group
2347 +-----------------+--------------------------------+-----------------+
2348 | Command | Description | Key Binding |
2349 +-----------------+--------------------------------+-----------------+
2350 | forward-char |Move point right N characters | C-f |
2351 | |(left if N is negative). | |
2352 | | | |
2353 | |On reaching end of buffer, stop | |
2354 | |and signal error. | |
2355 +-----------------+--------------------------------+-----------------+
2356 | backward-char |Move point left N characters | C-b |
2357 | |(right if N is negative). | |
2358 | | | |
2359 | |On attempt to pass beginning or | |
2360 | |end of buffer, stop and signal | |
2361 | |error. | |
2362 +-----------------+--------------------------------+-----------------+
2363 @end group
2364 @end smallexample
2365
2366 Table mode allows the contents of the table such as this one to be
2367 easily manipulated by inserting or deleting characters inside a cell.
2368 A cell is effectively a localized rectangular edit region and edits to
2369 a cell do not affect the contents of the surrounding cells. If the
2370 contents do not fit into a cell, then the cell is automatically
2371 expanded in the vertical and/or horizontal directions and the rest of
2372 the table is restructured and reformatted in accordance with the
2373 growth of the cell.
2374
2375 @menu
2376 * Table Definition:: What is a text based table.
2377 * Table Creation:: How to create a table.
2378 * Table Recognition:: How to activate and deactivate tables.
2379 * Cell Commands:: Cell-oriented commands in a table.
2380 * Cell Justification:: Justifying cell contents.
2381 * Row Commands:: Manipulating rows of table cell.
2382 * Column Commands:: Manipulating columns of table cell.
2383 * Fixed Width Mode:: Fixing cell width.
2384 * Table Conversion:: Converting between plain text and tables.
2385 * Measuring Tables:: Analyzing table dimension.
2386 * Table Misc:: Table miscellany.
2387 @end menu
2388
2389 @node Table Definition
2390 @subsection What is a Text-based Table?
2391
2392 Keep the following examples of valid tables in mind as a reference
2393 while you read this section:
2394
2395 @example
2396 +--+----+---+ +-+ +--+-----+
2397 | | | | | | | | |
2398 +--+----+---+ +-+ | +--+--+
2399 | | | | | | | |
2400 +--+----+---+ +--+--+ |
2401 | | |
2402 +-----+--+
2403 @end example
2404
2405 A table consists of a rectangular frame whose inside is divided into
2406 cells. Each cell must be at least one character wide and one
2407 character high, not counting its border lines. A cell can be
2408 subdivided into multiple rectangular cells, but cells cannot overlap.
2409
2410 The table frame and cell border lines are made of three special
2411 characters. These variables specify those characters:
2412
2413 @table @code
2414 @vindex table-cell-vertical-char
2415 @item table-cell-vertical-char
2416 Holds the character used for vertical lines. The default value is
2417 @samp{|}.
2418
2419 @vindex table-cell-horizontal-chars
2420 @item table-cell-horizontal-chars
2421 Holds the characters used for horizontal lines. The default value is
2422 @samp{"-="}.
2423
2424 @vindex table-cell-intersection-char
2425 @item table-cell-intersection-char
2426 Holds the character used at where horizontal line and vertical line
2427 meet. The default value is @samp{+}.
2428 @end table
2429
2430 @noindent
2431 Based on this definition, the following five tables are examples of invalid
2432 tables:
2433
2434 @example
2435 +-----+ +-----+ +--+ +-++--+ ++
2436 | | | | | | | || | ++
2437 | +-+ | | | | | | || |
2438 | | | | +--+ | +--+--+ +-++--+
2439 | +-+ | | | | | | | +-++--+
2440 | | | | | | | | | || |
2441 +-----+ +--+--+ +--+--+ +-++--+
2442 a b c d e
2443 @end example
2444
2445 From left to right:
2446
2447 @enumerate a
2448 @item
2449 Overlapped cells or non-rectangular cells are not allowed.
2450 @item
2451 Same as a.
2452 @item
2453 The border must be rectangular.
2454 @item
2455 Cells must have a minimum width/height of one character.
2456 @item
2457 Same as d.
2458 @end enumerate
2459
2460 @node Table Creation
2461 @subsection How to Create a Table?
2462 @cindex create a text-based table
2463 @cindex table creation
2464
2465 @findex table-insert
2466 The command to create a table is @code{table-insert}. When called
2467 interactively, it asks for the number of columns, number of rows, cell
2468 width and cell height. The number of columns is the number of cells
2469 horizontally side by side. The number of rows is the number of cells
2470 vertically within the table's height. The cell width is a number of
2471 characters that each cell holds, left to right. The cell height is a
2472 number of lines each cell holds. The cell width and the cell height
2473 can be either an integer (when the value is constant across the table)
2474 or a series of integer, separated by spaces or commas, where each
2475 number corresponds to the next cell within a row from left to right,
2476 or the next cell within a column from top to bottom.
2477
2478 @node Table Recognition
2479 @subsection Table Recognition
2480 @cindex table recognition
2481
2482 @findex table-recognize
2483 @findex table-unrecognize
2484 Table mode maintains special text properties in the buffer to allow
2485 editing in a convenient fashion. When a buffer with tables is saved
2486 to its file, these text properties are lost, so when you visit this
2487 file again later, Emacs does not see a table, but just formatted text.
2488 To resurrect the table text properties, issue the @kbd{M-x
2489 table-recognize} command. It scans the current buffer, recognizes
2490 valid table cells, and attaches appropriate text properties to allow
2491 for table editing. The converse command, @code{table-unrecognize}, is
2492 used to remove the special text properties and convert the buffer back
2493 to plain text.
2494
2495 Special commands exist to enable or disable tables within a region,
2496 enable or disable individual tables, and enable/disable individual
2497 cells. These commands are:
2498
2499 @table @kbd
2500 @findex table-recognize-region
2501 @item M-x table-recognize-region
2502 Recognize tables within the current region and activate them.
2503 @findex table-unrecognize-region
2504 @item M-x table-unrecognize-region
2505 Deactivate tables within the current region.
2506 @findex table-recognize-table
2507 @item M-x table-recognize-table
2508 Recognize the table under point and activate it.
2509 @findex table-unrecognize-table
2510 @item M-x table-unrecognize-table
2511 Deactivate the table under point.
2512 @findex table-recognize-cell
2513 @item M-x table-recognize-cell
2514 Recognize the cell under point and activate it.
2515 @findex table-unrecognize-cell
2516 @item M-x table-unrecognize-cell
2517 Deactivate the cell under point.
2518 @end table
2519
2520 For another way of converting text into tables, see @ref{Table
2521 Conversion}.
2522
2523 @node Cell Commands
2524 @subsection Commands for Table Cells
2525
2526 @findex table-forward-cell
2527 @findex table-backward-cell
2528 The commands @code{table-forward-cell} and
2529 @code{table-backward-cell} move point from the current cell to an
2530 adjacent cell forward and backward respectively. The order of the
2531 cells is cyclic: when point is in the last cell of a table, typing
2532 @kbd{M-x table-forward-cell} moves to the first cell in the table.
2533 Likewise @kbd{M-x table-backward-cell} from the first cell in a table
2534 moves to the last cell.
2535
2536 @findex table-span-cell
2537 The command @code{table-span-cell} merges the current cell with the
2538 adjacent cell in a specified direction---right, left, above or below.
2539 You specify the direction with the minibuffer. It does not allow
2540 merges which don't result in a legitimate cell layout.
2541
2542 @findex table-split-cell
2543 @cindex text-based tables, split a cell
2544 @cindex split table cell
2545 The command @code{table-split-cell} splits the current cell
2546 vertically or horizontally. This command is a wrapper to the
2547 direction specific commands @code{table-split-cell-vertically} and
2548 @code{table-split-cell-horizontally}. You specify the direction with
2549 a minibuffer argument.
2550
2551 @findex table-split-cell-vertically
2552 The command @code{table-split-cell-vertically} splits the current
2553 cell vertically and creates a pair of cells above and below where
2554 point is located. The content in the original cell is split as well.
2555
2556 @findex table-split-cell-horizontally
2557 The command @code{table-split-cell-horizontally} splits the current
2558 cell horizontally and creates a pair of cells right and left of where
2559 point is located. If the cell being split is not empty, this asks you
2560 how to handle the cell contents. The three options are: @code{split},
2561 @code{left}, or @code{right}. @code{split} splits the contents at
2562 point literally, while the @code{left} and @code{right} options move
2563 the entire contents into the left or right cell respectively.
2564
2565 @cindex enlarge a table cell
2566 @cindex shrink a table cell
2567 The next four commands enlarge or shrink a cell. They use numeric
2568 arguments (@pxref{Arguments}) to specify how many columns or rows to
2569 enlarge or shrink a particular table.
2570
2571 @table @kbd
2572 @findex table-heighten-cell
2573 @item M-x table-heighten-cell
2574 Enlarge the current cell vertically.
2575 @findex table-shorten-cell
2576 @item M-x table-shorten-cell
2577 Shrink the current cell vertically.
2578 @findex table-widen-cell
2579 @item M-x table-widen-cell
2580 Enlarge the current cell horizontally.
2581 @findex table-narrow-cell
2582 @item M-x table-narrow-cell
2583 Shrink the current cell horizontally.
2584 @end table
2585
2586 @node Cell Justification
2587 @subsection Cell Justification
2588 @cindex cell text justification
2589
2590 You can specify text justification for each cell. The justification
2591 is remembered independently for each cell and the subsequent editing
2592 of cell contents is subject to the specified justification.
2593
2594 @findex table-justify
2595 The command @code{table-justify} ask you to specify what to justify:
2596 a cell, a column, or a row. If you select cell justification, this
2597 command sets the justification only for the current cell. Selecting
2598 column or row justification sets the justification for all the cells
2599 within a column or row respectively. The command then ask you which
2600 kind of justification to apply: @code{left}, @code{center},
2601 @code{right}, @code{top}, @code{middle}, @code{bottom}, or
2602 @code{none}. Horizontal justification and vertical justification are
2603 specified independently. The options @code{left}, @code{center}, and
2604 @code{right} specify horizontal justification while the options
2605 @code{top}, @code{middle}, @code{bottom}, and @code{none} specify
2606 vertical justification. The vertical justification @code{none}
2607 effectively removes vertical justification. Horizontal justification
2608 must be one of @code{left}, @code{center}, or @code{right}.
2609
2610 @vindex table-detect-cell-alignment
2611 Justification information is stored in the buffer as a part of text
2612 property. Therefore, this information is ephemeral and does not
2613 survive through the loss of the buffer (closing the buffer and
2614 revisiting the buffer erase any previous text properties). To
2615 countermand for this, the command @code{table-recognize} and other
2616 recognition commands (@pxref{Table Recognition}) are equipped with a
2617 convenience feature (turned on by default). During table recognition,
2618 the contents of a cell are examined to determine which justification
2619 was originally applied to the cell and then applies this justification
2620 to the cell. This is a speculative algorithm and is therefore not
2621 perfect, however, the justification is deduced correctly most of the
2622 time. To disable this feature, customize the variable
2623 @code{table-detect-cell-alignment} and set it to @code{nil}.
2624
2625 @node Row Commands
2626 @subsection Commands for Table Rows
2627 @cindex table row commands
2628
2629 @cindex insert row in table
2630 @findex table-insert-row
2631 The command @code{table-insert-row} inserts a row of cells before
2632 the current row in a table. The current row where point is located is
2633 pushed down after the newly inserted row. A numeric prefix argument
2634 specifies the number of rows to insert. Note that in order to insert
2635 rows @emph{after} the last row at the bottom of a table, you must
2636 place point below the table---that is, outside the table---prior to
2637 invoking this command.
2638
2639 @cindex delete row in table
2640 @findex table-delete-row
2641 The command @code{table-delete-row} deletes a row of cells at point.
2642 A numeric prefix argument specifies the number of rows to delete.
2643
2644 @node Column Commands
2645 @subsection Commands for Table Columns
2646 @cindex table column commands
2647
2648 @cindex insert column in table
2649 @findex table-insert-column
2650 The command @code{table-insert-column} inserts a column of cells to
2651 the left of the current row in a table. This pushes the current
2652 column to the right. To insert a column to the right side of the
2653 rightmost column, place point to the right of the rightmost column,
2654 which is outside of the table, prior to invoking this command. A
2655 numeric prefix argument specifies the number of columns to insert.
2656
2657 @cindex delete column in table
2658 A command @code{table-delete-column} deletes a column of cells at
2659 point. A numeric prefix argument specifies the number of columns to
2660 delete.
2661
2662 @node Fixed Width Mode
2663 @subsection Fix Width of Cells
2664 @cindex fix width of table cells
2665
2666 @findex table-fixed-width-mode
2667 The command @code{table-fixed-width-mode} toggles fixed width mode
2668 on and off. When fixed width mode is turned on, editing inside a
2669 cell never changes the cell width; when it is off, the cell width
2670 expands automatically in order to prevent a word from being folded
2671 into multiple lines. By default, fixed width mode is disabled.
2672
2673 @node Table Conversion
2674 @subsection Conversion Between Plain Text and Tables
2675 @cindex text to table
2676 @cindex table to text
2677
2678 @findex table-capture
2679 The command @code{table-capture} captures plain text in a region and
2680 turns it into a table. Unlike @code{table-recognize} (@pxref{Table
2681 Recognition}), the original text does not have a table appearance but
2682 may hold a logical table structure. For example, some elements
2683 separated by known patterns form a two dimensional structure which can
2684 be turned into a table.
2685
2686 Here's an example of data that @code{table-capture} can operate on.
2687 The numbers are horizontally separated by a comma and vertically
2688 separated by a newline character.
2689
2690 @example
2691 1, 2, 3, 4
2692 5, 6, 7, 8
2693 , 9, 10
2694 @end example
2695
2696 @noindent
2697 Invoking @kbd{M-x table-capture} on that text produces this table:
2698
2699 @example
2700 +-----+-----+-----+-----+
2701 |1 |2 |3 |4 |
2702 +-----+-----+-----+-----+
2703 |5 |6 |7 |8 |
2704 +-----+-----+-----+-----+
2705 | |9 |10 | |
2706 +-----+-----+-----+-----+
2707 @end example
2708
2709 @noindent
2710 The conversion uses @samp{,} for the column delimiter and newline for
2711 a row delimiter, cells are left justified, and minimum cell width is
2712 5.
2713
2714 @findex table-release
2715 The command @code{table-release} does the opposite of
2716 @code{table-capture}. It releases a table by removing the table frame
2717 and cell borders. This leaves the table contents as plain text. One
2718 of the useful applications of @code{table-capture} and
2719 @code{table-release} is to edit a text in layout. Look at the
2720 following three paragraphs (the latter two are indented with header
2721 lines):
2722
2723 @example
2724 table-capture is a powerful command.
2725 Here are some things it can do:
2726
2727 Parse Cell Items By using column delimiter regular
2728 expression and raw delimiter regular
2729 expression, it parses the specified text
2730 area and extracts cell items from
2731 non-table text and then forms a table out
2732 of them.
2733
2734 Capture Text Area When no delimiters are specified it
2735 creates a single cell table. The text in
2736 the specified region is placed in that
2737 cell.
2738 @end example
2739
2740 @noindent
2741 Applying @code{table-capture} to a region containing the above three
2742 paragraphs, with empty strings for column delimiter regexp and row
2743 delimiter regexp, creates a table with a single cell like the
2744 following one.
2745
2746 @c The first line's right-hand frame in the following two examples
2747 @c sticks out to accommodate for the removal of @samp in the
2748 @c produced output!!
2749 @smallexample
2750 @group
2751 +-------------------------------------------------------------+
2752 |table-capture is a powerful command. |
2753 |Here are some things it can do: |
2754 | |
2755 |Parse Cell Items By using column delimiter regular |
2756 | expression and raw delimiter regular |
2757 | expression, it parses the specified text |
2758 | area and extracts cell items from |
2759 | non-table text and then forms a table out |
2760 | of them. |
2761 | |
2762 |Capture Text Area When no delimiters are specified it |
2763 | creates a single cell table. The text in |
2764 | the specified region is placed in that |
2765 | cell. |
2766 +-------------------------------------------------------------+
2767 @end group
2768 @end smallexample
2769
2770 @noindent
2771 By splitting the cell appropriately we now have a table consisting of
2772 paragraphs occupying its own cell. Each cell can now be edited
2773 independently without affecting the layout of other cells.
2774
2775 @smallexample
2776 +--------------------------------------------------------------+
2777 |table-capture is a powerful command. |
2778 |Here are some things it can do: |
2779 +------------------+-------------------------------------------+
2780 |Parse Cell Items |By using column delimiter regular |
2781 | |expression and raw delimiter regular |
2782 | |expression, it parses the specified text |
2783 | |area and extracts cell items from |
2784 | |non-table text and then forms a table out |
2785 | |of them. |
2786 +------------------+-------------------------------------------+
2787 |Capture Text Area |When no delimiters are specified it |
2788 | |creates a single cell table. The text in |
2789 | |the specified region is placed in that |
2790 | |cell. |
2791 +------------------+-------------------------------------------+
2792 @end smallexample
2793
2794 @noindent
2795 By applying @code{table-release}, which does the opposite process, the
2796 contents become once again plain text. @code{table-release} works as
2797 a companion command to @code{table-capture}.
2798
2799 @node Measuring Tables
2800 @subsection Analyzing Table Dimensions
2801 @cindex table dimensions
2802
2803 @findex table-query-dimension
2804 The command @code{table-query-dimension} analyzes a table structure
2805 and reports information regarding its dimensions. In case of the
2806 above example table, the @code{table-query-dimension} command displays
2807 in echo area:
2808
2809 @smallexample
2810 Cell: (21w, 6h), Table: (67w, 16h), Dim: (2c, 3r), Total Cells: 5
2811 @end smallexample
2812
2813 @noindent
2814 This indicates that the current cell is 21 character wide and 6 lines
2815 high, the entire table is 67 characters wide and 16 lines high. The
2816 table has 2 columns and 3 rows. It has a total of 5 cells, since the
2817 first row has a spanned cell.
2818
2819 @node Table Misc
2820 @subsection Table Miscellany
2821
2822 @cindex insert string into table cells
2823 @findex table-insert-sequence
2824 The command @code{table-insert-sequence} inserts a string into each
2825 cell. Each string is a part of a sequence i.e.@: a series of
2826 increasing integer numbers.
2827
2828 @cindex table in language format
2829 @cindex table for HTML and LaTeX
2830 @findex table-generate-source
2831 The command @code{table-generate-source} generates a table formatted
2832 for a specific markup language. It asks for a language (which must be
2833 one of @code{html}, @code{latex}, or @code{cals}), a destination
2834 buffer where to put the result, and the table caption (a string), and
2835 then inserts the generated table in the proper syntax into the
2836 destination buffer. The default destination buffer is
2837 @code{table.@var{lang}}, where @var{lang} is the language you
2838 specified.