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