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