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