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