1 @node Text, Programs, Indentation, Top
2 @chapter Commands for Human Languages
5 The term @dfn{text} has two widespread meanings in our area of the
6 computer field. One is data that is a sequence of characters. In this
7 sense of the word any file that you edit with Emacs is text. The other
8 meaning is more restrictive: a sequence of characters in a human
9 language for humans to read (possibly after processing by a text
10 formatter), as opposed to a program or commands for a program.
12 Human languages have syntactic and stylistic conventions that editor
13 commands should support or use to advantage: conventions involving
14 words, sentences, paragraphs, and capital letters. This chapter describes
15 Emacs commands for all these things. There are also commands for
16 @dfn{filling}, or rearranging paragraphs into lines of approximately equal
17 length. The commands for moving over and killing words, sentences,
18 and paragraphs, while intended primarily for editing text, are also often
19 useful for editing programs.
21 Emacs has several major modes for editing human language text.
22 If a file contains plain text, use Text mode, which customizes
23 Emacs in small ways for the syntactic conventions of text. For text which
24 contains embedded commands for text formatters, Emacs has other major modes,
25 each for a particular text formatter. Thus, for input to @TeX{}, you can
26 use @TeX{} mode; for input to nroff, Nroff mode.
29 * Text Mode:: The major modes for editing text files.
30 * Nroff Mode:: The major mode for editing input to the formatter nroff.
31 * TeX Mode:: The major modes for editing input to the formatter TeX.
32 * Outline Mode:: The major mode for editing outlines.
33 * Words:: Moving over and killing words.
34 * Sentences:: Moving over and killing sentences.
35 * Paragraphs:: Moving over paragraphs.
36 * Pages:: Moving over pages.
37 * Filling:: Filling or justifying text
38 * Case:: Changing the case of text
41 @node Text Mode, Words, Text, Text
44 @findex tab-to-tab-stop
45 @findex edit-tab-stops
49 You should use Text mode---rather than Fundamental or Lisp mode---to
50 edit files of text in a human language. Invoke @kbd{M-x text-mode} to
51 enter Text mode. In Text mode, @key{TAB} runs the function
52 @code{tab-to-tab-stop}, which allows you to use arbitrary tab stops set
53 with @kbd{M-x edit-tab-stops} (@pxref{Tab Stops}). Features concerned
54 with comments in programs are turned off unless they are explicitly invoked.
55 The syntax table is changed so that periods are not considered part of a
56 word, while apostrophes, backspaces and underlines are.
58 @findex indented-text-mode
59 A similar variant mode is Indented Text mode, intended for editing
60 text in which most lines are indented. This mode defines @key{TAB} to
61 run @code{indent-relative} (@pxref{Indentation}), and makes Auto Fill
62 indent the lines it creates. As a result, a line made by Auto Filling,
63 or by @key{LFD}, is normally indented just like the previous line. Use
64 @kbd{M-x indented-text-mode} to select this mode.
66 @vindex text-mode-hook
67 Entering Text mode or Indented Text mode calls the value of the
68 variable @code{text-mode-hook} with no arguments, if that value exists
69 and is not @code{nil}. This value is also called when modes related to
70 Text mode are entered; this includes Nroff mode, @TeX{} mode, Outline
71 mode, and Mail mode. Your hook can look at the value of
72 @code{major-mode} to see which of these modes is actually being entered.
74 Two modes similar to Text mode are of use for editing text that is to
75 be passed through a text formatter before achieving its final readable form.
78 * Nroff Mode:: The major mode for editing input to the formatter nroff.
79 * TeX Mode:: The major modes for editing input to the formatter TeX.
82 Another similar mode is used for editing outlines. It allows you
83 to view the text at various levels of detail. You can view either
84 the outline headings alone or both headings and text; you can also
85 hide some of the headings at lower levels from view to make the high
86 level structure more visible.
89 * Outline Mode:: The major mode for editing outlines.
92 @node Nroff Mode, TeX Mode, Text Mode, Text Mode
93 @subsection Nroff Mode
97 Nroff mode is a mode like Text mode but modified to handle nroff
98 commands present in the text. Invoke @kbd{M-x nroff-mode} to enter this
99 mode. Nroff mode differs from Text mode in only a few ways. All nroff
100 command lines are considered paragraph separators, so that filling never
101 garbles the nroff commands. Pages are separated by @samp{.bp} commands.
102 Comments start with backslash-doublequote. There are also three special
103 commands that are not available in Text mode:
105 @findex forward-text-line
106 @findex backward-text-line
107 @findex count-text-lines
113 Move to the beginning of the next line that isn't an nroff command
114 (@code{forward-text-line}). An argument is a repeat count.
116 Like @kbd{M-n} but move up (@code{backward-text-line}).
118 Prints in the echo area the number of text lines (lines that are not
119 nroff commands) in the region (@code{count-text-lines}).
122 @findex electric-nroff-mode
123 The other feature of Nroff mode is Electric Nroff newline mode.
124 This is a minor mode that you can turn on or off with
125 @kbd{M-x electric-nroff-mode} (@pxref{Minor Modes}). When the mode is
126 on and you use @key{RET} to end a line containing an nroff command
127 that opens a kind of grouping, Emacs automatically inserts the matching
128 nroff command to close that grouping on the following line. For
129 example, if you are at the beginning of a line and type @kbd{.@:(b
130 @key{RET}}, the matching command @samp{.)b} will be inserted on a new
131 line following point.
133 @vindex nroff-mode-hook
134 Entering Nroff mode calls the value of the variable
135 @code{text-mode-hook} with no arguments, if that value exists and is not
136 @code{nil}; then it does the same with the variable
137 @code{nroff-mode-hook}.
139 @node TeX Mode, Outline Mode, Nroff Mode, Text Mode
140 @subsection @TeX{} Mode
145 @findex plain-tex-mode
147 @findex plain-TeX-mode
150 @TeX{} is a powerful text formatter written by Donald Knuth; like GNU
151 Emacs, it is free. La@TeX{} is a simplified input format for @TeX{},
152 implemented by @TeX{} macros. It is part of @TeX{}.@refill
154 Emacs has a special @TeX{} mode for editing @TeX{} input files.
155 It provides facilities for checking the balance of delimiters and for
156 invoking @TeX{} on all or part of the file.
158 @TeX{} mode has two variants, Plain @TeX{} mode and La@TeX{} mode,
159 which are two distinct major modes that differ only slightly. These
160 modes are designed for editing the two different input formats. The
161 command @kbd{M-x tex-mode} looks at the contents of a buffer to
162 determine whether it appears to be La@TeX{} input or not; it then
163 selects the appropriate mode. If it can't tell which is right (e.g.,
164 the buffer is empty), the variable @code{tex-default-mode} controls
167 The commands @kbd{M-x plain-tex-mode} and @kbd{M-x latex-mode}
168 explicitly select one of the variants of @TeX{} mode. Use these
169 commands when @kbd{M-x tex-mode} does not guess right.@refill
172 * Editing: TeX Editing. Special commands for editing in TeX mode.
173 * Printing: TeX Print. Commands for printing part of a file with TeX.
176 @TeX{} for Unix systems can be obtained from the University of Washington
177 for a distribution fee.
179 To order a full distribution, send $140.00 for a 1/2 inch
180 9-track tape, $165.00 for two 4-track 1/4 inch cartridge tapes
181 (foreign sites $150.00, for 1/2 inch, $175.00 for 1/4 inch, to cover
182 the extra postage) payable to the University of Washington to:
186 Northwest Computer Support Group, DW-10
187 University of Washington
188 Seattle, Washington 98195
192 Purchase orders are acceptable, but there is an extra charge of
193 $10.00 to pay for processing charges. (The total cost comes to $150
194 for domestic sites, $175 for foreign sites).
196 The normal distribution is a tar tape, blocked 20, 1600 bpi, on an
197 industry standard 2400 foot half-inch reel. The physical format for
198 the 1/4 inch streamer cartridges uses QIC-11, 8000 bpi, 4-track
199 serpentine recording for the SUN. Also, SystemV tapes can be written
200 in cpio format, blocked 5120 bytes, ASCII headers.
202 @node TeX Editing,TeX Print,TeX Mode,TeX Mode
203 @subsubsection @TeX{} Editing Commands
205 Here are the special commands provided in @TeX{} mode for editing the
210 Insert, according to context, either @samp{``} or @samp{"} or
211 @samp{''} (@code{TeX-insert-quote}).
213 Insert a paragraph break (two newlines) and check the previous
214 paragraph for unbalanced braces or dollar signs
215 (@code{tex-terminate-@*paragraph}).
216 @item M-x validate-tex-buffer
217 Check each paragraph in the buffer for unbalanced braces or dollar signs.
219 Insert @samp{@{@}} and position point between them (@code{tex-insert-braces}).
221 Move forward past the next unmatched close brace (@code{up-list}).
223 Close a block for La@TeX{} (@code{tex-close-latex-block}).
226 @findex tex-insert-quote
228 In @TeX{}, the character @samp{"} is not normally used; you use @samp{``}
229 to start a quotation and @samp{''} to end one. @TeX{} mode defines the key
230 @kbd{"} to insert @samp{``} after whitespace or an open brace, @samp{"}
231 after a backslash, or @samp{''} otherwise. This is done by the command
232 @code{tex-insert-quote}. If you need the character @samp{"} itself in
233 unusual contexts, use @kbd{C-q} to insert it. Also, @kbd{"} with a
234 numeric argument always inserts that number of @samp{"} characters.
236 In @TeX{} mode, @samp{$} has a special syntax code which attempts to
237 understand the way @TeX{} math mode delimiters match. When you insert a
238 @samp{$} that is meant to exit math mode, the position of the matching
239 @samp{$} that entered math mode is displayed for a second. This is the
240 same feature that displays the open brace that matches a close brace that
241 is inserted. However, there is no way to tell whether a @samp{$} enters
242 math mode or leaves it; so when you insert a @samp{$} that enters math
243 mode, the previous @samp{$} position is shown as if it were a match, even
244 though they are actually unrelated.
246 @findex tex-insert-braces
247 @kindex C-c @{ (TeX mode)
249 @kindex C-c @} (TeX mode)
250 If you prefer to keep braces balanced at all times, you can use @kbd{C-c @{}
251 (@code{tex-insert-braces}) to insert a pair of braces. It leaves point
252 between the two braces so you can insert the text that belongs inside.
253 Afterward, use the command @kbd{C-c @}} (@code{up-list}) to move forward
254 past the close brace.
256 @findex validate-tex-buffer
257 @findex tex-terminate-paragraph
258 @kindex LFD (TeX mode)
259 There are two commands for checking the matching of braces. @key{LFD}
260 (@code{tex-terminate-paragraph}) checks the paragraph before point, and
261 inserts two newlines to start a new paragraph. It prints a message in the
262 echo area if any mismatch is found. @kbd{M-x validate-tex-buffer} checks
263 the entire buffer, paragraph by paragraph. When it finds a paragraph that
264 contains a mismatch, it displays point at the beginning of the paragraph
265 for a few seconds and pushes a mark at that spot. Scanning continues
266 until the whole buffer has been checked or until you type another key.
267 The positions of the last several paragraphs with mismatches can be
268 found in the mark ring (@pxref{Mark Ring}).
270 Note that square brackets and parentheses, not just braces, are
271 matched in @TeX{} mode. This is wrong if you want to check @TeX{} syntax.
272 However, parentheses and square brackets are likely to be used in text as
273 matching delimiters and it is useful for the various motion commands and
274 automatic match display to work with them.
276 @findex tex-close-latex-block
277 @kindex C-c C-f (LaTeX mode)
278 In La@TeX{} input, @samp{\begin} and @samp{\end} commands must balance.
279 After you insert a @samp{\begin}, use @kbd{C-c C-f}
280 (@code{tex-close-latex-block}) to insert automatically a matching
281 @samp{\end} (on a new line following the @samp{\begin}). A blank line is
282 inserted between the two, and point is left there.@refill
284 @node TeX Print,,TeX Editing,TeX Mode
285 @subsubsection @TeX{} Printing Commands
287 You can invoke @TeX{} as an inferior of Emacs on either the entire
288 contents of the buffer or just a region at a time. Running @TeX{} in
289 this way on just one chapter is a good way to see what your changes
290 look like without taking the time to format the entire file.
294 Invoke @TeX{} on the current region, plus the buffer's header
297 Invoke @TeX{} on the entire current buffer (@code{tex-buffer}).
299 Recenter the window showing output from the inferior @TeX{} so that
300 the last line can be seen (@code{tex-recenter-output-buffer}).
302 Kill the inferior @TeX{} (@code{tex-kill-job}).
304 Print the output from the last @kbd{C-c C-r} or @kbd{C-c C-b} command
307 Show the printer queue (@code{tex-show-print-queue}).
311 @kindex C-c C-b (TeX mode)
313 @kindex C-c C-p (TeX mode)
314 @findex tex-show-print-queue
315 @kindex C-c C-q (TeX mode)
316 You can pass the current buffer through an inferior @TeX{} using
317 @kbd{C-c C-b} (@code{tex-buffer}). The formatted output appears in a file
318 in @file{/tmp}; to print it, type @kbd{C-c C-p} (@code{tex-print}).
319 Afterward use @kbd{C-c C-q} (@code{tex-show-print-queue}) to view the
320 progress of your output towards being printed.
323 @kindex C-c C-k (TeX mode)
324 @findex tex-recenter-output-buffer
325 @kindex C-c C-l (TeX mode)
326 The console output from @TeX{}, including any error messages, appears in a
327 buffer called @samp{*TeX-shell*}. If @TeX{} gets an error, you can switch
328 to this buffer and feed it input (this works as in Shell mode;
329 @pxref{Interactive Shell}). Without switching to this buffer, you can scroll
330 it so that its last line is visible by typing @kbd{C-c C-l}.
332 Type @kbd{C-c C-k} (@code{tex-kill-job}) to kill the @TeX{} process if
333 you see that its output is no longer useful. Using @kbd{C-c C-b} or
334 @kbd{C-c C-r} also kills any @TeX{} process still running.@refill
337 @kindex C-c C-r (TeX mode)
338 You can pass an arbitrary region through an inferior @TeX{} by typing
339 @kbd{C-c C-r} (@code{tex-region}). This is tricky, however, because
340 most files of @TeX{} input contain commands at the beginning to set
341 parameters and define macros. Without them, no later part of the file
342 will format correctly. To solve this problem, @kbd{C-c C-r} allows you
343 to designate a part of the file as containing essential commands; it is
344 included before the specified region as part of the input to @TeX{}.
345 The designated part of the file is called the @dfn{header}.
347 @cindex header (TeX mode)
348 To indicate the bounds of the header in Plain @TeX{} mode, insert two
349 special strings in the file: @samp{%**start of header} before the
350 header, and @samp{%**end of header} after it. Each string must appear
351 entirely on one line, but there may be other text on the line before or
352 after. The lines containing the two strings are included in the header.
353 If @samp{%**start of header} does not appear within the first 100 lines of
354 the buffer, @kbd{C-c C-r} assumes there is no header.
356 In La@TeX{} mode, the header begins with @samp{\documentstyle} and ends
357 with @*@samp{\begin@{document@}}. These are commands that La@TeX{} requires
358 you to use, so you don't need to do anything special to identify the
361 @vindex TeX-mode-hook
362 @vindex LaTeX-mode-hook
363 @vindex plain-TeX-mode-hook
364 When you enter either kind of @TeX{} mode, Emacs calls with no
365 arguments the value of the variable @code{text-mode-hook}, if that value
366 exists and is not @code{nil}. Emacs then calls the variable
367 @code{TeX-mode-hook} and either @code{plain-TeX-mode-hook} or
368 @code{LaTeX-mode-hook} under the same conditions.
370 @node Outline Mode,, TeX Mode, Text Mode
371 @subsection Outline Mode
373 @cindex selective display
374 @cindex invisible lines
376 Outline mode is a major mode similar to Text mode but intended for editing
377 outlines. It allows you to make parts of the text temporarily invisible
378 so that you can see just the overall structure of the outline. Type
379 @kbd{M-x outline-mode} to turn on Outline mode in the current buffer.
381 @vindex outline-mode-hook
382 When you enter Outline mode, Emacs calls with no arguments the value
383 of the variable @code{text-mode-hook}, if that value exists and is not
384 @code{nil}; then it does the same with the variable
385 @code{outline-mode-hook}.
387 When a line is invisible in outline mode, it does not appear on the
388 screen. The screen appears exactly as if the invisible line
389 were deleted, except that an ellipsis (three periods in a row) appears
390 at the end of the previous visible line (only one ellipsis no matter
391 how many invisible lines follow).
393 All editing commands treat the text of the invisible line as part of the
394 previous visible line. For example, @kbd{C-n} moves onto the next visible
395 line. Killing an entire visible line, including its terminating newline,
396 really kills all the following invisible lines as well; yanking
397 everything back yanks the invisible lines and they remain invisible.
400 * Format: Outline Format. What the text of an outline looks like.
401 * Motion: Outline Motion. Special commands for moving through outlines.
402 * Visibility: Outline Visibility. Commands to control what is visible.
405 @node Outline Format,Outline Motion,Outline Mode, Outline Mode
406 @subsubsection Format of Outlines
408 @cindex heading lines (Outline mode)
409 @cindex body lines (Outline mode)
410 Outline mode assumes that the lines in the buffer are of two types:
411 @dfn{heading lines} and @dfn{body lines}. A heading line represents a
412 topic in the outline. Heading lines start with one or more stars; the
413 number of stars determines the depth of the heading in the outline
414 structure. Thus, a heading line with one star is a major topic; all the
415 heading lines with two stars between it and the next one-star heading
416 are its subtopics; and so on. Any line that is not a heading line is a
417 body line. Body lines belong to the preceding heading line. Here is an
424 which says something about the topic of food.
428 This is the body of the second-level header.
440 A second first-level topic with its header line.
443 A heading line together with all following body lines is called
444 collectively an @dfn{entry}. A heading line together with all following
445 deeper heading lines and their body lines is called a @dfn{subtree}.
447 @vindex outline-regexp
448 You can customize the criterion for distinguishing heading lines by
449 setting the variable @code{outline-regexp}. Any line whose beginning
450 has a match for this regexp is considered a heading line. Matches that
451 start within a line (not at the beginning) do not count. The length of
452 the matching text determines the level of the heading; longer matches
453 make a more deeply nested level. Thus, for example, if a text formatter
454 has commands @samp{@@chapter}, @samp{@@section} and @samp{@@subsection}
455 to divide the document into chapters and sections, you can make those
456 lines count as heading lines by setting @code{outline-regexp} to
457 @samp{"@@chap\\|@@\\(sub\\)*section"}. Note the trick: the two words
458 @samp{chapter} and @samp{section} are the same length, but by defining
459 the regexp to match only @samp{chap} we ensure that the length of the
460 text matched on a chapter heading is shorter, so that Outline mode will
461 know that sections are contained in chapters. This works as long as no
462 other command starts with @samp{@@chap}.
464 Outline mode makes a line invisible by changing the newline before it
465 into an ASCII Control-M (code 015). Most editing commands that work on
466 lines treat an invisible line as part of the previous line because,
467 strictly speaking, it @i{is} part of that line, since there is no longer a
468 newline in between. When you save the file in Outline mode, Control-M
469 characters are saved as newlines, so the invisible lines become ordinary
470 lines in the file. Saving does not change the visibility status of a
473 @node Outline Motion,Outline Visibility,Outline Format,Outline Mode
474 @subsubsection Outline Motion Commands
476 Some special commands in Outline mode move backward and forward to
481 Move point to the next visible heading line
482 (@code{outline-next-visible-heading}).
484 Move point to the previous visible heading line @*
485 (@code{outline-previous-visible-heading}).
487 Move point to the next visible heading line at the same level
488 as the one point is on (@code{outline-forward-same-level}).
490 Move point to the previous visible heading line at the same level
491 (@code{outline-backward-same-level}).
493 Move point up to a lower-level (more inclusive) visible heading line
494 (@code{outline-up-heading}).
497 @findex outline-next-visible-heading
498 @findex outline-previous-visible-heading
499 @kindex C-c C-n (Outline mode)
500 @kindex C-c C-p (Outline mode)
501 @kbd{C-c C-n} (@code{next-visible-heading}) moves down to the next
502 heading line. @kbd{C-c C-p} (@code{previous-visible-heading}) moves
503 similarly backward. Both accept numeric arguments as repeat counts. The
504 names emphasize that invisible headings are skipped, but this is not really
505 a special feature. All editing commands that look for lines ignore the
506 invisible lines automatically.@refill
508 @findex outline-up-heading
509 @findex outline-forward-same-level
510 @findex outline-backward-same-level
511 @kindex C-c C-f (Outline mode)
512 @kindex C-c C-b (Outline mode)
513 @kindex C-c C-u (Outline mode)
514 More advanced motion commands understand the levels of headings.
515 The commands @kbd{C-c C-f} (@code{outline-forward-same-level}) and
516 @kbd{C-c C-b} (@code{outline-backward-same-level}) move from one
517 heading line to another visible heading at the same depth in
518 the outline. @kbd{C-c C-u} (@code{outline-up-heading}) moves
519 backward to another heading that is less deeply nested.
521 @node Outline Visibility,,Outline Motion,Outline Mode
522 @subsubsection Outline Visibility Commands
524 The other special commands of outline mode are used to make lines visible
525 or invisible. Their names all start with @code{hide} or @code{show}.
526 Most of them exist as pairs of opposites. They are not undoable; instead,
527 you can undo right past them. Making lines visible or invisible is simply
528 not recorded by the undo mechanism.
532 Make all body lines in the buffer invisible.
534 Make all lines in the buffer visible.
536 Make everything under this heading invisible, not including this
537 heading itself (@code{hide-subtree}).
539 Make everything under this heading visible, including body,
540 subheadings, and their bodies (@code{show-subtree}).
541 @item M-x hide-leaves
542 Make the body of this heading line, and of all its subheadings,
544 @item M-x show-branches
545 Make all subheadings of this heading line, at all levels, visible.
547 Make immediate subheadings (one level down) of this heading line
548 visible (@code{show-children}).
550 Make this heading line's body invisible.
552 Make this heading line's body visible.
557 Two commands that are exact opposites are @kbd{M-x hide-entry} and
558 @kbd{M-x show-entry}. They are used with point on a heading line, and
559 apply only to the body lines of that heading. The subtopics and their
560 bodies are not affected.
564 @kindex C-c C-d (Outline mode)
565 @kindex C-c C-h (Outline mode)
566 @cindex subtree (Outline mode)
567 Two more powerful opposites are @kbd{C-c C-d} (@code{hide-subtree}) and
568 @kbd{C-c C-s} (@code{show-subtree}). Both should be used when point is
569 on a heading line, and both apply to all the lines of that heading's
570 @dfn{subtree}: its body, all its subheadings, both direct and indirect, and
571 all of their bodies. In other words, the subtree contains everything
572 following this heading line, up to and not including the next heading of
573 the same or higher rank.@refill
576 @findex show-branches
577 Intermediate between a visible subtree and an invisible one is having
578 all the subheadings visible but none of the body. There are two commands
579 for doing this, one that hides the bodies and one that
580 makes the subheadings visible. They are @kbd{M-x hide-leaves} and
581 @kbd{M-x show-branches}.
583 @kindex C-c C-i (Outline mode)
584 @findex show-children
585 A little weaker than @code{show-branches} is @kbd{C-c C-i}
586 (@code{show-children}). It makes just the direct subheadings
587 visible---those one level down. Deeper subheadings remain
592 Two commands have a blanket effect on the whole file. @kbd{M-x
593 hide-body} makes all body lines invisible, so that you see just the
594 outline structure. @kbd{M-x show-all} makes all lines visible. You can
595 think of these commands as a pair of opposites even though @kbd{M-x
596 show-all} applies to more than just body lines.
598 @vindex selective-display-ellipses
599 You can turn off the use of ellipses at the ends of visible lines by
600 setting @code{selective-display-ellipses} to @code{nil}. The result is
601 no visible indication of the presence of invisible lines.
603 @node Words, Sentences, Text Mode, Text
608 Emacs has commands for moving over or operating on words. By convention,
609 the keys for them are all @kbd{Meta-} characters.
614 Move forward over a word (@code{forward-word}).
616 Move backward over a word (@code{backward-word}).
618 Kill up to the end of a word (@code{kill-word}).
620 Kill back to the beginning of a word (@code{backward-kill-word}).
622 Mark the end of the next word (@code{mark-word}).
624 Transpose two words; drag a word forward
625 or backward across other words (@code{transpose-words}).
628 Notice how these keys form a series that parallels the
629 character-based @kbd{C-f}, @kbd{C-b}, @kbd{C-d}, @kbd{C-t} and
630 @key{DEL}. @kbd{M-@@} is related to @kbd{C-@@}, which is an alias for
631 @kbd{C-@key{SPC}}.@refill
636 @findex backward-word
637 The commands @kbd{Meta-f} (@code{forward-word}) and @kbd{Meta-b}
638 (@code{backward-word}) move forward and backward over words. They are
639 analogous to @kbd{Control-f} and @kbd{Control-b}, which move over single
640 characters. Like their @kbd{Control-} analogues, @kbd{Meta-f} and
641 @kbd{Meta-b} move several words if given an argument. @kbd{Meta-f} with a
642 negative argument moves backward, and @kbd{Meta-b} with a negative argument
643 moves forward. Forward motion stops after the last letter of the
644 word, while backward motion stops before the first letter.@refill
648 @kbd{Meta-d} (@code{kill-word}) kills the word after point. To be
649 precise, it kills everything from point to the place @kbd{Meta-f} would
650 move to. Thus, if point is in the middle of a word, @kbd{Meta-d} kills
651 just the part after point. If some punctuation comes between point and the
652 next word, it is killed along with the word. (To kill only the
653 next word but not the punctuation before it, simply type @kbd{Meta-f} to get
654 to the end and kill the word backwards with @kbd{Meta-@key{DEL}}.)
655 @kbd{Meta-d} takes arguments just like @kbd{Meta-f}.
657 @findex backward-kill-word
659 @kbd{Meta-@key{DEL}} (@code{backward-kill-word}) kills the word before
660 point. It kills everything from point back to where @kbd{Meta-b} would
661 move to. If point is after the space in @w{@samp{FOO, BAR}}, then
662 @w{@samp{FOO, }} is killed. To kill just @samp{FOO}, type
663 @kbd{Meta-b Meta-d} instead of @kbd{Meta-@key{DEL}}.
665 @cindex transposition
667 @findex transpose-words
668 @kbd{Meta-t} (@code{transpose-words}) exchanges the word before or
669 containing point with the following word. The delimiter characters
670 between the words do not move. For example, transposing @w{@samp{FOO,
671 BAR}} results in @w{@samp{BAR, FOO}} rather than @samp{@w{BAR FOO,}}.
672 @xref{Transpose}, for more on transposition and on arguments to
673 transposition commands.
677 To operate on the next @var{n} words with an operation which applies
678 between point and mark, you can either set the mark at point and then move
679 over the words, or you can use the command @kbd{Meta-@@} (@code{mark-word})
680 which does not move point but sets the mark where @kbd{Meta-f} would move
681 to. It can be given arguments just like @kbd{Meta-f}.
684 The word commands' understanding of syntax is completely controlled by
685 the syntax table. For example, any character can be declared to be a word
686 delimiter. @xref{Syntax}.
688 @node Sentences, Paragraphs, Words, Text
692 The Emacs commands for manipulating sentences and paragraphs are mostly
693 on @kbd{Meta-} keys, and therefore are like the word-handling commands.
697 Move back to the beginning of the sentence (@code{backward-sentence}).
699 Move forward to the end of the sentence (@code{forward-sentence}).
701 Kill forward to the end of the sentence (@code{kill-sentence}).
703 Kill back to the beginning of the sentence @*(@code{backward-kill-sentence}).
708 @findex backward-sentence
709 @findex forward-sentence
710 The commands @kbd{Meta-a} and @kbd{Meta-e} (@code{backward-sentence}
711 and @code{forward-sentence}) move to the beginning and end of the
712 current sentence, respectively. They resemble @kbd{Control-a} and
713 @kbd{Control-e}, which move to the beginning and end of a line. Unlike
714 their counterparts, @kbd{Meta-a} and @kbd{Meta-e} move over successive
715 sentences if repeated or given numeric arguments. Emacs assumes
716 the typist's convention is followed, and thus considers a sentence to
717 end wherever there is a @samp{.}, @samp{?}, or @samp{!} followed by the
718 end of a line or two spaces, with any number of @samp{)}, @samp{]},
719 @samp{'}, or @samp{"} characters allowed in between. A sentence also
720 begins or ends wherever a paragraph begins or ends.@refill
722 Neither @kbd{M-a} nor @kbd{M-e} moves past the newline or spaces beyond
723 the sentence edge at which it is stopping.
727 @findex kill-sentence
728 @findex backward-kill-sentence
729 @kbd{M-a} and @kbd{M-e} have a corresponding kill command, just like
730 @kbd{C-a} and @kbd{C-e} have @kbd{C-k}. The command is @kbd{M-k}
731 (@code{kill-sentence}) which kills from point to the end of the
732 sentence. With minus one as an argument it kills back to the beginning
733 of the sentence. Larger arguments serve as repeat counts.@refill
735 There is a special command, @kbd{C-x @key{DEL}}
736 (@code{backward-kill-sentence}), for killing back to the beginning of a
737 sentence, which is useful when you change your mind in the middle of
738 composing text.@refill
741 The variable @code{sentence-end} controls recognition of the end of a
742 sentence. It is a regexp that matches the last few characters of a
743 sentence, together with the whitespace following the sentence. Its
747 "[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*"
751 This example is explained in the section on regexps. @xref{Regexps}.
753 @node Paragraphs, Pages, Sentences, Text
758 @findex backward-paragraph
759 @findex forward-paragraph
761 The Emacs commands for manipulating paragraphs are also @kbd{Meta-}
766 Move back to previous paragraph beginning @*(@code{backward-paragraph}).
768 Move forward to next paragraph end (@code{forward-paragraph}).
770 Put point and mark around this or next paragraph (@code{mark-paragraph}).
773 @kbd{Meta-@{} moves to the beginning of the current or previous paragraph,
774 while @kbd{Meta-@}} moves to the end of the current or next paragraph.
775 Blank lines and text formatter command lines separate paragraphs and are
776 not part of any paragraph. An indented line starts a new paragraph.
778 In major modes for programs (as opposed to Text mode), paragraphs begin
779 and end only at blank lines. As a result, the paragraph commands continue to
780 be useful even though there are no paragraphs per se.
782 When there is a fill prefix, paragraphs are delimited by all lines
783 which don't start with the fill prefix. @xref{Filling}.
786 @findex mark-paragraph
787 To operate on a paragraph, you can use the command
788 @kbd{Meta-h} (@code{mark-paragraph}) to set the region around it. This
789 command puts point at the beginning and mark at the end of the paragraph
790 point was in. If point is between paragraphs (in a run of blank lines or
791 at a boundary), the paragraph following point is surrounded by point and
792 mark. If there are blank lines preceding the first line of the paragraph,
793 one of the blank lines is included in the region. Thus, for example,
794 @kbd{M-h C-w} kills the paragraph around or after point.
796 @vindex paragraph-start
797 @vindex paragraph-separate
798 The precise definition of a paragraph boundary is controlled by the
799 variables @code{paragraph-separate} and @code{paragraph-start}. The value
800 of @code{paragraph-start} is a regexp that matches any line that
801 either starts or separates paragraphs. The value of
802 @code{paragraph-separate} is another regexp that matches only lines
803 that separate paragraphs without being part of any paragraph. Lines that
804 start a new paragraph and are contained in it must match both regexps. For
805 example, normally @code{paragraph-start} is @code{"^[ @t{\}t@t{\}n@t{\}f]"}
806 and @code{paragraph-separate} is @code{"^[ @t{\}t@t{\}f]*$"}.@refill
808 Normally it is desirable for page boundaries to separate paragraphs.
809 The default values of these variables recognize the usual separator for
812 @node Pages, Filling, Paragraphs, Text
817 Files are often thought of as divided into @dfn{pages} by the
818 @dfn{formfeed} character (ASCII Control-L, octal code 014). For
819 example, if a file is printed on a line printer, each ``page'' of the
820 file starts on a new page of paper. Emacs treats a page-separator
821 character just like any other character. It can be inserted with
822 @kbd{C-q C-l} or deleted with @key{DEL}. You are free to
823 paginate your file or not. However, since pages are often meaningful
824 divisions of the file, commands are provided to move over them and
830 Move point to previous page boundary (@code{backward-page}).
832 Move point to next page boundary (@code{forward-page}).
834 Put point and mark around this page (or another page) (@code{mark-page}).
836 Count the lines in this page (@code{count-lines-page}).
842 @findex backward-page
843 The @kbd{C-x [} (@code{backward-page}) command moves point to
844 immediately after the previous page delimiter. If point is already
845 right after a page delimiter, the command skips that one and stops at
846 the previous one. A numeric argument serves as a repeat count. The
847 @kbd{C-x ]} (@code{forward-page}) command moves forward past the next
852 The @kbd{C-x C-p} command (@code{mark-page}) puts point at the beginning
853 of the current page and the mark at the end. The page delimiter at the end
854 is included (the mark follows it). The page delimiter at the front is
855 excluded (point follows it). You can follow this command by @kbd{C-w} to
856 kill a page you want to move elsewhere. If you insert the page after a page
857 delimiter, at a place where @kbd{C-x ]} or @kbd{C-x [} would take you,
858 the page will be properly delimited before and after once again.
860 A numeric argument to @kbd{C-x C-p} is used to specify which page to go
861 to, relative to the current one. Zero means the current page. One means
862 the next page, and @minus{}1 means the previous one.
865 @findex count-lines-page
866 The @kbd{C-x l} command (@code{count-lines-page}) can help you decide
867 where to break a page in two. It prints the total number of lines in
868 the current page in the echo area, then divides the lines into those
869 preceding the current line and those following it, for example
872 Page has 96 (72+25) lines
876 Notice that the sum is off by one; this is correct if point is not at the
879 @vindex page-delimiter
880 The variable @code{page-delimiter} should have as its value a regexp that
881 matches the beginning of a line that separates pages. This defines
882 where pages begin. The normal value of this variable is @code{"^@t{\}f"},
883 which matches a formfeed character at the beginning of a line.
885 @node Filling, Case, Pages, Text
886 @section Filling Text
889 If you use Auto Fill mode, Emacs @dfn{fills} text (breaks it up into
890 lines that fit in a specified width) as you insert it. When you alter
891 existing text it is often no longer be properly filled afterwards and
892 you can use explicit commands for filling.
895 * Auto Fill:: Auto Fill mode breaks long lines automatically.
896 * Fill Commands:: Commands to refill paragraphs and center lines.
897 * Fill Prefix:: Filling when every line is indented or in a comment, etc.
900 @node Auto Fill, Fill Commands, Filling, Filling
901 @subsection Auto Fill Mode
903 @cindex Auto Fill mode
905 @dfn{Auto Fill} mode is a minor mode in which lines are broken
906 automatically when they become too wide. Breaking happens only when
907 you type a @key{SPC} or @key{RET}.
910 @item M-x auto-fill-mode
911 Enable or disable Auto Fill mode.
914 In Auto Fill mode, break lines when appropriate.
917 @findex auto-fill-mode
918 @kbd{M-x auto-fill-mode} turns Auto Fill mode on if it was off, or off
919 if it was on. With a positive numeric argument the command always turns
920 Auto Fill mode on, and with a negative argument it always turns it off.
921 The presence of the word @samp{Fill} in the mode line, inside the
922 parentheses, indicates that Auto Fill mode is in effect. Auto Fill mode
923 is a minor mode; you can turn it on or off for each buffer individually.
926 In Auto Fill mode, lines are broken automatically at spaces when they get
927 longer than desired. Line breaking and rearrangement takes place
928 only when you type @key{SPC} or @key{RET}. To insert a space
929 or newline without permitting line-breaking, type @kbd{C-q @key{SPC}} or
930 @kbd{C-q @key{LFD}} (recall that a newline is really a linefeed).
931 @kbd{C-o} inserts a newline without line breaking.
933 Auto Fill mode works well with Lisp mode: when it makes a new line in
934 Lisp mode, it indents that line with @key{TAB}. If a line ending in a
935 Lisp comment gets too long, the text of the comment is split into two
936 comment lines. Optionally, new comment delimiters are inserted at the
937 end of the first line and the beginning of the second, so that each line
938 is a separate comment. The variable @code{comment-multi-line} controls
939 the choice (@pxref{Comments}).
941 Auto Fill mode does not refill entire paragraphs. It can break lines but
942 cannot merge lines. Editing in the middle of a paragraph can result in
943 a paragraph that is not correctly filled. The easiest way to make the
944 paragraph properly filled again is using an explicit fill commands.
946 Many users like Auto Fill mode and want to use it in all text files.
947 The section on init files explains how you can arrange this
948 permanently for yourself. @xref{Init File}.
950 @node Fill Commands, Fill Prefix, Auto Fill, Filling
951 @subsection Explicit Fill Commands
955 Fill current paragraph (@code{fill-paragraph}).
957 Fill each paragraph in the region (@code{fill-region}).
959 Set the fill column (@code{set-fill-column}).
960 @item M-x fill-region-as-paragraph
961 Fill the region, considering it as one paragraph.
967 @findex fill-paragraph
968 To refill a paragraph, use the command @kbd{Meta-q}
969 (@code{fill-paragraph}). It causes the paragraph containing point, or
970 the one after point if point is between paragraphs, to be refilled. All
971 line breaks are removed, and new ones are inserted where necessary.
972 @kbd{M-q} can be undone with @kbd{C-_}. @xref{Undo}.@refill
976 To refill many paragraphs, use @kbd{M-g} (@code{fill-region}), which
977 divides the region into paragraphs and fills each of them.
979 @findex fill-region-as-paragraph
980 @kbd{Meta-q} and @kbd{Meta-g} use the same criteria as @kbd{Meta-h} for
981 finding paragraph boundaries (@pxref{Paragraphs}). For more control, you
982 can use @kbd{M-x fill-region-as-paragraph}, which refills everything
983 between point and mark. This command recognizes only blank lines as
984 paragraph separators.@refill
986 @cindex justification
987 A numeric argument to @kbd{M-g} or @kbd{M-q} causes it to
988 @dfn{justify} the text as well as filling it. Extra spaces are inserted
989 to make the right margin line up exactly at the fill column. To remove
990 the extra spaces, use @kbd{M-q} or @kbd{M-g} with no argument.@refill
992 @vindex auto-fill-inhibit-regexp
993 The variable @code{auto-fill-inhibit-regexp} takes as a value a regexp to
994 match lines that should not be auto-filled.
999 The command @kbd{Meta-s} (@code{center-line}) centers the current line
1000 within the current fill column. With an argument, it centers several lines
1001 individually and moves past them.
1004 The maximum line width for filling is in the variable
1005 @code{fill-column}. Altering the value of @code{fill-column} makes it
1006 local to the current buffer; until then, the default value---initially
1007 70---is in effect. @xref{Locals}.
1010 @findex set-fill-column
1011 The easiest way to set @code{fill-column} is to use the command @kbd{C-x
1012 f} (@code{set-fill-column}). With no argument, it sets @code{fill-column}
1013 to the current horizontal position of point. With a numeric argument, it
1014 uses that number as the new fill column.
1016 @node Fill Prefix,, Fill Commands, Filling
1017 @subsection The Fill Prefix
1020 To fill a paragraph in which each line starts with a special marker
1021 (which might be a few spaces, giving an indented paragraph), use the
1022 @dfn{fill prefix} feature. The fill prefix is a string which is not
1023 included in filling. Emacs expects every line to start with a fill
1028 Set the fill prefix (@code{set-fill-prefix}).
1030 Fill a paragraph using current fill prefix (@code{fill-paragraph}).
1031 @item M-x fill-individual-paragraphs
1032 Fill the region, considering each change of indentation as starting a
1037 @findex set-fill-prefix
1038 To specify a fill prefix, move to a line that starts with the desired
1039 prefix, put point at the end of the prefix, and give the command
1040 @w{@kbd{C-x .}}@: (@code{set-fill-prefix}). That's a period after the
1041 @kbd{C-x}. To turn off the fill prefix, specify an empty prefix: type
1042 @w{@kbd{C-x .}}@: with point at the beginning of a line.@refill
1044 When a fill prefix is in effect, the fill commands remove the fill
1045 prefix from each line before filling and insert it on each line after
1046 filling. Auto Fill mode also inserts the fill prefix inserted on new
1047 lines it creates. Lines that do not start with the fill prefix are
1048 considered to start paragraphs, both in @kbd{M-q} and the paragraph
1049 commands; this is just right if you are using paragraphs with hanging
1050 indentation (every line indented except the first one). Lines which are
1051 blank or indented once the prefix is removed also separate or start
1052 paragraphs; this is what you want if you are writing multi-paragraph
1053 comments with a comment delimiter on each line.
1056 The fill prefix is stored in the variable @code{fill-prefix}. Its value
1057 is a string, or @code{nil} when there is no fill prefix. This is a
1058 per-buffer variable; altering the variable affects only the current buffer,
1059 but there is a default value which you can change as well. @xref{Locals}.
1061 @findex fill-individual-paragraphs
1062 Another way to use fill prefixes is through @kbd{M-x
1063 fill-individual-paragraphs}. This function divides the region into groups
1064 of consecutive lines with the same amount and kind of indentation and fills
1065 each group as a paragraph, using its indentation as a fill prefix.
1067 @node Case,, Filling, Text
1068 @section Case Conversion Commands
1069 @cindex case conversion
1071 Emacs has commands for converting either a single word or any arbitrary
1072 range of text to upper case or to lower case.
1077 Convert following word to lower case (@code{downcase-word}).
1079 Convert following word to upper case (@code{upcase-word}).
1081 Capitalize the following word (@code{capitalize-word}).
1083 Convert region to lower case (@code{downcase-region}).
1085 Convert region to upper case (@code{upcase-region}).
1092 @findex downcase-word
1094 @findex capitalize-word
1095 The word conversion commands are used most frequently. @kbd{Meta-l}
1096 (@code{downcase-word}) converts the word after point to lower case,
1097 moving past it. Thus, repeating @kbd{Meta-l} converts successive words.
1098 @kbd{Meta-u} (@code{upcase-word}) converts to all capitals instead,
1099 while @kbd{Meta-c} (@code{capitalize-word}) puts the first letter of the
1100 word into upper case and the rest into lower case. The word conversion
1101 commands convert several words at once if given an argument. They are
1102 especially convenient for converting a large amount of text from all
1103 upper case to mixed case: you can move through the text using
1104 @kbd{M-l}, @kbd{M-u}, or @kbd{M-c} on each word as appropriate,
1105 occasionally using @kbd{M-f} instead to skip a word.
1107 When given a negative argument, the word case conversion commands apply
1108 to the appropriate number of words before point, but do not move point.
1109 This is convenient when you have just typed a word in the wrong case: you
1110 can give the case conversion command and continue typing.
1112 If a word case conversion command is given in the middle of a word, it
1113 applies only to the part of the word which follows point. This is just
1114 like what @kbd{Meta-d} (@code{kill-word}) does. With a negative argument,
1115 case conversion applies only to the part of the word before point.
1120 @findex downcase-region
1121 @findex upcase-region
1122 The other case conversion commands are @kbd{C-x C-u}
1123 (@code{upcase-region}) and @kbd{C-x C-l} (@code{downcase-region}), which
1124 convert everything between point and mark to the specified case. Point and
1125 mark do not move.@refill