|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T t
Length: 59720 (0xe948) Types: TextFile Names: »text.texinfo«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦c06c473ab⟧ »./UNRELEASED/lispref.tar.Z« └─⟦1b57a2ffe⟧ └─⟦this⟧ »text.texinfo«
@setfilename ../info/text @node Text, Searching and Matching, Markers, Top @chapter Text @cindex text This chapter is about those functions that deal with the text of a buffer. Most of these functions insert or delete text in whichever buffer is current. Most of them are interactive functions and perform their changes either directly in front of or directly following point. Some text-related functions put text into the @dfn{kill ring}, others do not; but all the changes they make can be undone so long as the buffer has undo enabled (@xref{Undo}.) @cindex text region Many text-related functions operate on a region of text defined by two locations in the buffer, named @var{start} and @var{end}. These arguments should be either markers or or numeric character positions that count from the beginning of the buffer. @cindex region error @cindex args-out-of-range error Since text-related functions always operate on the text between the two locations, @var{start} and @var{end}, the order in which the locations are given is not important. For example, @code{(delete-region 1 10)} and @code{(delete-region 10 1)} perform identically. It is an @code{args-out-of-range} error if either location does not indicate an existing position in the buffer. @cindex buffer characters Throughout this chapter, `text' refers to the characters in the buffer. @menu * Insertion:: * Deletion:: * The Kill Ring:: * Undo:: * Auto Filling:: * Filling:: * Sorting:: * Indentation:: * Indent Tabs:: * Columns:: * Case Changes:: * Underlining:: * Registers:: @end menu @node Insertion, Deletion, Text, Text @section Insertion @cindex text insertion Insertion takes place at point; normally markers which pointed at point before the insertion end up pointing before the inserted text. Point may end up either before or after inserted text, depending on the function used. @defun insert &rest args This function inserts any number of strings or characters into the current buffer, at point, moving point forward. It is an error unless all @var{args} are either strings or characters. Any markers pointing after point are relocated. Any markers pointing at point or before are unchanged. @end defun @defun insert-before-markers &rest args This function inserts any number of strings or characters into the current buffer, at point, moving point forward. It is an error unless all @var{args} are either strings or characters. Unlike @code{insert}, any markers whose position equals point are relocated to come after the newly inserted text. @end defun @defun insert-char character count This function inserts @var{count} instances of @var{character} into the current buffer before the point. @var{count} must be a number, and @var{character} must be a character. @end defun @deffn Command copy-to-buffer to-buffer start end This function copies text from the current buffer to @var{to-buffer}. @var{to-buffer} is first erased (with no questions asked), and then the text in the region defined by @var{start} and @var{end} is inserted into that buffer. When called interactively, @var{to-buffer} is prompted for in the minibuffer, and @var{start} and @var{end} are bound to the value of the point and mark (i.e., to the values of the beginning and end of the region). @end deffn @defun insert-buffer-substring from-buffer-or-name start end This function inserts a substring of @var{from-buffer-or-name} (which must exist) into the current buffer before the point. The string is those characters in the region defined by @var{start} and @var{end}. In the example, the form is executed with buffer @samp{bar} as the current buffer. We assume that buffer @code{bar} is initially empty. @example ---------- Buffer: foo ---------- We hold these truths to be self-evident, that all ---------- Buffer: foo ---------- (insert-buffer-substring "foo" 1 20) @result{} nil ---------- Buffer: bar ---------- We hold these truth ---------- Buffer: bar ---------- @end example @end defun @defun insert-buffer from-buffer-or-name This function inserts the entire contents of @var{from-buffer-or-name} (which must exist) into the current buffer after the point. It leaves the mark after the inserted text. @end defun @deffn Command quoted-insert count @cindex octal to character This function reads the next input character verbatim and inserts it. It is primarily useful for inserting control characters. You may also type up to 3 octal digits, to insert a character with that code. @var{count} is the number of these characters to insert. It is an error if @var{count} is not a number, or if the current buffer is read-only. Programs rarely want to use this function, but might want to put it on a keymap. This function is primarily for interactive use. @end deffn @deffn Command self-insert-command count @cindex character insertion This function inserts the last character typed @var{count} times. This is the function that most printing characters are bound to. Programs rarely want to use this, but might want to put it on a keymap. This function calls @code{auto-fill-hook}. (In version 19, @code{auto-fill-function} has been renamed @code{auto-fill-function} since it is not called by the @code{run-hooks} function.) In everyday use, @code{self-insert-command} is the most frequently called function in Emacs! @end deffn @node Commands for Insertion @comment node-name, next, previous, up @subsection Commands for Insertion @deffn Command newline &optional number-of-newlines This function inserts newlines into the current buffer before the point. If @var{number-of-newlines} is supplied (and is a number), that many newline characters are inserted. @cindex newline in Auto Fill mode In Auto Fill mode, @code{newline} can break the preceding line if @var{count} is not supplied. When called interactively, @var{count} is the processed prefix argument. @end deffn @deffn Command split-line This function splits the current line, moving the portion of the line after point down vertically, so that it is on the next line directly below where it was before. Whitespace is inserted at the beginning of the lower line as needed by the @code{indent-to} function with a combination of tabs and spaces. @code{split-line} returns the position of point. In the example, point is located between the @kbd{t} and the @kbd{h} when @code{(split-line)} is called. The second line in the result contains one tab and one space before the @kbd{h}. Point is still located at the end of the first line, directly after the @kbd{t}. @example ---------- Buffer: foo ---------- This is t@point{}he line before ---------- Buffer: foo ---------- (split-line) @result{} 4433 ---------- Buffer: foo ---------- This is t@point{} he line before ---------- Buffer: foo ---------- @end example Programs hardly ever use this function. @end deffn @deffn Command open-line count This function inserts @var{count} newlines into the current buffer after point, leaving point where it was. When called interactively, @var{count} is the processed prefix argument. Programs hardly ever use this function. @end deffn @deffn Command overwrite-mode argument This function turns overwrite mode on and off. If @var{argument} is a positive number (greater than zero), then it is turned on, otherwise it is turned off. In overwrite mode, typed-in printable characters replace existing text character for character, and do not push the existing text to the right. This function only effects the self-insertion command. When called interactively, @var{argument} is set to the processed prefix argument. @end deffn @node Deletion, The Kill Ring, Insertion, Text @section Deletion All of the deletion functions operate on the current buffer, and they all return a value of @code{nil}. None of them put their deleted text into the kill ring unless otherwise noted. @cindex deletion vs killing In general, functions that have ``delete'' in their names do not put text into the kill ring, while corresponding functions with ``kill'' in their names do (compare: @code{delete-region} and @code{kill-region}). From programs, you will usually want to use a ``delete'' function as opposed to a ``kill'' function, since the kill ring is for the user. @defun erase-buffer @cindex buffer-read-only error This function deletes the entire text of the current buffer. If the buffer is read-only, it signals a @code{buffer-read-only} error. Otherwise it does not complain, even if erasing a buffer visiting a modified file. It does not kill the buffer. @end defun @deffn Command delete-region start end This function deletes the text in the current buffer in the region defined by @var{start} and @var{end}. @end deffn @deffn Command delete-horizontal-space @cindex delete whitespace This function deletes all spaces and tabs around point. In the examples, point is between the second and third characters on each of the lines when the function is called. @example ---------- Buffer: foo ---------- I @point{}thought I @point{} thought We@point{} thought Yo@point{}u thought ---------- Buffer: foo ---------- (delete-horizontal-space) @result{} nil ---------- Buffer: foo ---------- Ithought Ithought Wethought You thought ---------- Buffer: foo ---------- @end example @end deffn @deffn Command delete-indentation &optional join-following-p This function joins the line point is on to the previous line and deletes all the whitespace at the join, save for one space. If @var{join-following-p} is non-@code{nil}, @code{delete-indentation} joins this line to following line instead. In the example below, point is located on the line starting @samp{events}, and it makes no difference if there are trailing spaces. @example ---------- Buffer: foo ---------- When in the course of human @point{} events, it becomes necessary ---------- Buffer: foo ---------- (delete-indentation) @result{} nil ---------- Buffer: foo ---------- When in the course of human@point{} events, it becomes necessary ---------- Buffer: foo ---------- @end example @end deffn @defun fixup-whitespace This function replaces white space between the objects on either side of point with either one space or no space as appropriate. The function leaves one space if point is in the middle of a line that has printing characters somewhere before and after it (except in a few cases described below). When point is at the beginning or end of a line, this function leaves no spaces. @code{fixup-whitespace} does not leave any space when point is located directly after a character whose syntax class is ``open parenthesis'' @samp{(}, directly before a character whose syntax class is ``close parenthesis'' @samp{)}, or directly before a character whose syntax class is ``Expression Prefix Operator'' @samp{'}. In the example, point starts out at the beginning of the second line, when @code{fixup-whitespace} is called the first time. It is located directly after the @samp{(} for the second invocation. @example ---------- Buffer: foo ---------- This has too many spaces @point{} at the front of this line This has too many spaces at the start of (@point{} this list) ---------- Buffer: foo ---------- (fixup-whitespace) @result{} nil (fixup-whitespace) @result{} nil ---------- Buffer: foo ---------- This has too many spaces at the front of this line This has too many spaces at the start of (this list) ---------- Buffer: foo ---------- @end example @end defun @deffn Command just-one-space @comment !!SourceFile simple.el @cindex delete whitespace Delete all spaces and tabs around point, leaving one space. @end deffn @deffn Command delete-blank-lines This function deletes blank lines surrounding point. If point is on a blank line with one or more blank lines before or after it, then all but one of them are deleted. If point is on an isolated blank line, then it is deleted. If point is on a nonblank line, it deletes all blank lines following it. A blank line is defined as any line consisting of a newline and nothing else except tabs and spaces. @code{delete-blank-lines} returns @code{nil}. @end deffn @deffn Command delete-char count &optional killp This function deletes @var{count} characters directly after point (before, if @var{count} is negative). If @var{killp} is non-@code{nil}, then it saves the deleted characters in the kill ring. When called interactively, @var{count} is the processed prefix argument, and @var{killp} is set to @code{t} if @var{count} is greater than 1. @end deffn @deffn Command delete-backward-char count &optional killp @cindex delete previous char This function deletes @var{count} characters directly before point (after, if @var{count} is negative). If @var{killp} is non-@code{nil}, then it saves the deleted characters in the kill ring. When called interactively, @var{count} is the processed prefix argument, and @var{killp} is set to @code{t} if @var{count} is greater than 1. @end deffn @deffn Command backward-delete-char-untabify count &optional killp @cindex tab deletion This function deletes @var{count} characters backward, changing tabs into spaces. When changing tabs into spaces, a sufficient number of spaces are inserted into the buffer to keep point in the same column. These spaces are then deleted by @code{delete-backward-char}. If @var{count} is negative, then tabs are not changed to spaces, and the characters are deleted by calling @code{delete-backward-char} with @var{count}. If @var{killp} is non-@code{nil}, then it saves the deleted characters in the kill ring. When called interactively, @var{count} is the processed prefix argument, and @var{killp} is set to @code{t} if @var{count} is greater than 1. @end deffn @node The Kill Ring, Undo, Deletion, Text @section The Kill Ring @cindex kill ring Emacs keeps a number of the last sections of text that were deleted by the user. These sections of text are kept on a list called the @code{kill-ring}. Several functions manipulate this list; they treat it as a ring rather than as a list. The kill ring and its associated functions help the user move text around, make it easy to change his or her mind, and help him or her recover from accidents. Some people think use of the word `kill' in Emacs is unfortunate, since it refers to processes which specifically @emph{do not} destroy the entities `killed'. This is in sharp contrast to ordinary life, in which death is permanent, and `killed' entities seldom come back to life. A different metaphor might have been more intuitive. For example, the term `cut ring' makes sense to people who, in pre-computer days, used scissors and paste to cut up and rearrange manuscripts. Others most readily understand a metaphor incorporating concepts of `attic' or `closet'; and yet others, who think of text as being `clipped' from the buffer, prefer a term such as `clip ring'. @menu * Kill Ring Data Structures:: * Kill Functions:: * Yank Commands:: * Kill Ring Internals:: @end menu @node Kill Ring Data Structures, Kill Functions, The Kill Ring, The Kill Ring @comment node-name, next, previous, up @subsection Kill Ring Data Structures Killed text is kept as strings in a list. A short kill ring, for example, might look like this: @example ("some text" "a different piece of text" "yet more text") @end example Functions which push more text into the list first make a string of the text in question (using @code{buffer-substring}), and then look at the length of the list. If the length is longer than the value of @code{kill-ring-max}, the last entry in the list is dropped off when the new entry is put on. The @code{kill-ring-yank-pointer} global variable points to the kill ring entry that a @dfn{yank} function will copy. Several functions move this pointer from one entry to another, and a user can thereby specify which entry to copy. Here is a diagram that shows the variable @code{kill-ring-yank-pointer} pointing to the second entry in the kill ring @code{("some text" "a different piece of text" "yet more text")}. @group @example kill-ring kill-ring-yank-pointer | | | ___ ___ | ___ ___ ___ ___ --> | | | ---> | | | | | | |___|___|------> |___|___|--> |___|___|--> nil | | | | | | | | -->"yet more text" | | | --> "a different piece of text" | --> "some text" @end example @end group @noindent (This circumstance occurs when @kbd{C-y} (@code{yank}) is immediately followed by @kbd{M-y} (@code{yank-pop}).) Both @code{kill-ring} and @code{kill-ring-yank-pointer} are variables like other Lisp variables. Both are bound to lists. The word `pointer' is used in the name of the @code{kill-ring-yank-pointer} variable to tell human readers that the purpose of the variable is to point to the element of the list that will be copied to the buffer when the user gives a yank command. The functions that change the entry to which the @code{kill-ring-yank-pointer} points treat the kill ring (which is a list) as if it were a ring; that is to say, a change that would otherwise cause the pointer to point to an entry beyond the end of the list (which would be useless) instead causes the pointer to point to the first entry on the list. Hence, movement of the @code{kill-ring-yank-pointer} is called @dfn{rotation}. The @code{kill-ring-yank-pointer} variable can be moved in the `reverse' direction from the end of the list to the beginning; but only one step at a time; and it cannot be moved from the first entry to the last entry in the `reverse' direction. The ring is a one way rotary. Kill commands always place their new text in the beginning of @code{kill-ring}, and they always reset @code{kill-ring-yank-pointer} to point to the first entry of @code{kill-ring}. The first entry will be the new entry; consequently, the next @code{yank} command will copy the new entry into a buffer, as the user expects. After @code{kill-ring-yank-pointer} is reset to point to the first entry of @code{kill-ring}, @code{kill-ring} and @code{kill-ring-yank-pointer} are @code{eq} to each other. @code{kill-region} is the primary function for programs to use that kill text. Any command that calls this function is a ``kill command'' (and should contain the word ``kill'' in its name). When kill commands are interwoven with other commands, the killed portions of text are put into separate entries in the kill ring. But when two or more kill commands are executed in sequence, the text killed by the second (or third, etc.@:) kill command is appended to the text killed by the first command so as to make one entry in the kill ring. The @code{kill-region} function uses the @code{last-command} variable to keep track of whether the previous was a kill command, in which case, it appends the killed text to the current entry. @node Kill Functions, Yank Commands, Kill Ring Data Structures, The Kill Ring @comment node-name, next, previous, up @subsection Entry Points for Killing @deffn Command kill-region start end This function kills the text in the region defined by @var{start} and @var{end}. The text is deleted but saved in the kill ring. When called interactively, @var{start} and @var{end} are point and mark. @end deffn @deffn Command kill-line &optional count This function kills the rest of the line following point, not including the newline. If point is directly before a newline, or if there is only whitespace between point and the newline, then it kills the whitespace and newline. If @var{count} is supplied, then it kills that many lines (@emph{including} the newline). (This makes executing @code{(kill-line 2)} different from executing @code{(kill-line)} two times.) If @var{count} is negative, then @code{kill-line} kills lines backwards. When called interactively, @var{count} is the unprocessed prefix argument (which then gets processed if non-@code{nil}). @end deffn @deffn Command zap-to-char count character @cindex kill to character The Emacs Version 19 implementation of this function kills all text in the region from point up to and including @var{count} the next occurrence of @var{character}. Thus, if the cursor were at the beginning of this sentence and the character were @samp{s}, @samp{Thus} would be removed. If the argument were two, @samp{Thus, if the curs} would be removed, up to and including the @samp{s} in @samp{cursor}. The Emacs Version 18 implementation of the function removes the text from point up to @emph{but not including} the specified character. Thus, in the example shown in the previous paragraph, the @samp{s} would @emph{not} be removed. In addition, the Version 18 implementation will kill text to the end of the buffer if the specified character is not found; but the Version 19 implementation will simply generate an error (and not remove any text). The function zaps backward if @var{count} is negative. The killed text is put in the kill ring. @end deffn @deffn Command copy-region-as-kill start end This function saves the region defined by @var{start} and @var{end} on the kill ring, but does not delete the text from the buffer. When called interactively, @var{start} and @var{end} are point and mark. @end deffn @node Yank Commands, Kill Ring Internals, Kill Functions, The Kill Ring @comment node-name, next, previous, up @subsection Entry Points for Yanking @deffn Command yank &optional arg @cindex insert killed text This function inserts the text in the first entry in the kill ring directly before point. After the yank, the mark is positioned at the beginning and point is positioned after the end of the inserted text. If @var{arg} is a list (which as passed an an interactive argument when a user types must @kbd{C-u}), then @code{yank} inserts the text as described above, but puts point in front of the yanked text and the mark at the end of the yanked text. If @var{arg} is a number, then @code{yank} inserts the @var{arg}'th most recently killed text. @end deffn @deffn Command yank-pop arg This function replaces the just-yanked text with a different piece of killed text. This command is allowed only immediately after a @code{yank} or a @code{yank-pop}. At such a time, the region contains text that was just inserted by the previous @code{yank}. @code{yank-pop} deletes that text and inserts in its place a different stretch of killed text. If @var{arg} is @code{nil}, then the previously inserted text in the region is deleted (and not reinserted into the kill ring since it is already on the kill ring), and the previous element of the kill ring is inserted. If @var{arg} is numeric, then the @var{arg'th} previous kill is inserted. If @var{arg} is negative, then this is a more recent kill. The sequence of kills wraps around, so that after the oldest one comes the newest one. (However, the reverse wrap is not possible; you can step backward through the list, but not beyond the beginning.) @end deffn @node Kill Ring Internals, , Yank Commands, The Kill Ring @comment node-name, next, previous, up @subsection Internals of the Kill Ring @defvar kill-ring List of killed text sequences. @end defvar @defvar kill-ring-yank-pointer This global variable is the @sc{cdr} of the kill ring whose @sc{car} is the last thing yanked. The @code{yank-pop} and @code{rotate-yank-pointer} commands move this pointer around in the kill ring. A kill always resets this variable to point the beginning of the kill ring (that is, to bind the value of the variable to the whole kill ring). @end defvar @deffn Command rotate-yank-pointer count This function rotates @code{kill-ring-yank-pointer} @var{count} positions in the kill ring. In other words, it rebinds @code{kill-ring-yank-pointer} to a different @sc{cdr} of the kill ring, or to the whole kill ring. @end deffn @defopt kill-ring-max The value of this global variable is the maximum length to which the kill ring can grow, before elements are thrown away on a first-in, first-out basis. The default value for @code{kill-ring-max} is 30. @end defopt @node Undo, Auto Filling, The Kill Ring, Text @comment node-name, next, previous, up @section Undo @cindex redo Each buffer has its own private undo stack. Stack size is limited, so large changes or a large number of changes cannot be undone. @deffn Command undo &optional arg This function undoes some previous changes. By repeating this command you can undo more changes. A numeric argument serves as a repeat count. @end deffn @defun undo-boundary This function places a boundary between units of undo. Each undo command stops at such a boundary; and the next undo command will undo to the previous boundary. There is an implicit undo boundary between each key-stroke command, such as @code{kill-word}. Thus, each undo undoes the effects of one command. This function is used inside of @code{query-replace}, between each replacement, so that individual replacements can be undone one by one. @end defun @defun undo-more count This function is used to undo changes back @var{count} boundaries beyond what was already undone recently. @end defun @defun undo-start This function moves the undo-pointer to the beginning of the undo stack. This means that the next call to @code{undo-more} will undo the most recently made change. This function breaks a sequence of undo's, so a subsequent call to @code{undo-more} will undo a previous change that is itself the result of an undo. This is what you use to undo your undoing (i.e., redo). To prepare Emacs to undo a recent sequence of changes, call @code{undo-start}; then call @code{undo-more} one or more times to undo them. @end defun @deffn Command buffer-enable-undo &optional buffer-or-name This function starts keeping undo information for buffer @var{buffer-or-name}. If no argument is supplied, then the current buffer is used. If the buffer is already keeping undo information, then nothing is changed. This function returns @code{nil}. When called interactively, @var{buffer-or-name} is the current buffer. @end deffn @defun buffer-flush-undo buffer-or-name @cindex buffer disable undo This function makes the buffer @var{buffer-or-name} stop keeping undo information, and flushes the information it has kept thus far. If the buffer is not keeping undo information, then nothing is changed. This function returns @code{nil}. @end defun @node Auto Filling, Filling, Undo, Text @comment node-name, next, previous, up @section Auto Filling @cindex filling, auto @cindex Auto Fill mode @dfn{Filling} breaks text into lines that are no more than a specified number of columns wide. Lines end between words, and thus may be shorter than the maximum length, unless the line is @dfn{justified} in which case, spaces are inserted between words so that the last letter of the last word on the line is on the last column. In Auto Fill mode, Emacs fills lines automatically. This section describes the hook and the two variables used by Auto Fill mode. For a description of functions that you can call manually to fill and justify text, @pxref{Filling}. As a practical matter, if you are writing text that you hope other people will read, you should set the value of @code{fill-column} to no more than 70. Otherwise the line will be too long for people to read comfortably; and they will think your writing is clumsy even if it isn't! @defvar auto-fill-hook The value of this variable should be a function (of no arguments) to be called after self-inserting a space at a column beyond @code{fill-column}. It may be @code{nil}, in which case, nothing special is done. The default value for @code{auto-fill-function} is @code{do-auto-fill}. In version 18, @code{auto-fill-function} is called @code{auto-fill-hook}; but since @code{auto-fill-hook} is not called by the @code{run-hooks} function, it is being re-named @code{auto-fill-function} in Version 19. @end defvar @defopt fill-column This buffer-local variable controls how wide lines are filled. It should be an integer which is interpreted as a column. If automatic line-wrapping is turned on, then any text typed beyond this column is wrapped onto the next line. The command @code{fill-paragraph} adjusts the lines the paragraph which point is in so that it ends at this column. @end defopt @defvar default-fill-column The value of this variable is the default value for @code{fill-column} in buffers that do not override it. This is the same as @code{(default-value 'fill-column)}. The default value for @code{default-fill-column} is 70. @end defvar @node Filling, Sorting, Auto Filling, Text @comment node-name, next, previous, up @section Filling @dfn{Filling} means adjusting the lengths of lines so that line-breaks occur between rather than within words; and lines have a specified maximum length. If a line is justified as will as filled, then spaces are inserted between the words so that the last letter of the last word on the line is on the specified column. For ease of reading, lines should be no longer than 70 or so columns. Emacs has facilities for automatically filling text as you write it, but changes to existing text may leave it improperly filled. Then you must fill the text explicitly. @deffn Command fill-paragraph justify-flag @cindex filling a paragraph This function fills the paragraph at or after point. If @var{justify-flag} is non-@code{nil}, each line is justified as well. @end deffn @deffn Command fill-region start end &optional justify-flag This function fills each of the paragraphs in the region from start to end. The function justifies the paragraph if it is called interactively with a prefix argument, or if it is called from a program with a non-@code{nil} @var{justify-flag}. The function uses the value of @code{paragraph-separate} to distinguish paragraphs. @end deffn @deffn Command fill-individual-paragraphs start end &optional justifyp mailp This function fills each paragraph in the region according to its individual fill prefix. Thus, if the lines of a paragraph are indented with spaces, the filled paragraph will continue to be indented in the same fashion. The first two arguments, @var{start} and @var{end}, are the beginning and end of the region that will be filled. The third and fourth arguments, @var{justifyp} and @var{mailp}, are optional. If @var{justifyp} is non-@code{nil}, the paragraphs are justified as well as filled. If @var{mailp} is non-@code{nil}, the function is told that it is operating on a mail message and that it should not fill the header lines. @end deffn @deffn Command fill-region-as-paragraph start end &optional justify-flag This function considers a region of text as paragraph and fills it. If the region was made up of many paragraphs, the blank lines between paragraphs are removed. This function justifies the region when called interactively with a non-@code{nil} prefix argument, or when called from a program with a non-@code{nil} third argument. @end deffn @deffn Command justify-current-line This function inserts spaces between the words of the line point is in so that the line ends at @code{fill-column}. @end deffn @node Sorting, Indentation, Filling, Text @section Sorting @cindex sorting The sorting commands described in this section all rearrange text in a buffer. In contrast, the function @code{sort} rearranges the order of the elements of a list. (@xref{Rearrangement}.) @deffn Command sort-regexp-fields reverse record-regexp key start end This command sorts the region between @var{start} and @var{end} lexicographically as specified by @var{record-regexp} and @var{key}. `Lexicographic' means that the function compares the first characters of each field, the second characters, and so on. One field is less than a second field in the ordering when compared characters do not match; the firld whose character is less than the other is the lessor field. One character is considered to be less than another if its numerical value as a character is less than the other. Since Emacs uses the @sc{ASCII} character set, the ordering in that set determines lexicographic order. The value of the @var{record-regexp} argument specifies the textual units or @dfn{records} that should be sorted. For example, to sort lines, the value of @var{record-regexp} would be @samp{^.*$}, which matches lines with at least one character besides a newline. (@xref{Regular Expressions}, for a description of the syntax and meaning of regular expressions.) The value of the @var{key} argument specifies what of each record is to be used for sorting. The @var{key} could match the whole record, but it may be just a part of the record. In the latter case, the part of each record that is not used for sorting has no effect on the sort. The @var{key} argument can refer to match-fields within the regular expression for the record; or it can be a regular expression on its own. If @var{key} is: @table @asis @item @samp{\@var{digit}} The @var{digit}'th @samp{\(...\)} match field from @var{record-regexp} is used for sorting. @item @samp{\&} The whole record is used for sorting. @item a regular-expression The function searches for a matchfor the regular-expression within the record. If such a match is found, it is used for sorting. If a match for @var{key} is not found within a record then that record is ignored, which means its position in the buffer is not changed. @end table The @code{sort-regexp-fields} function sorts in reverse order when the first argument, @var{reverse}, is negative. Called interactively, it sorts in reverse order when passed by a negative prefix argument. For example, if you plan to sort all the lines in the region by the first word on each line starting with the letter @samp{f}, you should set @var{record-regexp} to @samp{^.*$} and set @var{key} to @samp{\<f\w*\>}. The resulting expression looks like this: @example (sort-regexp-fields nil "^.*$" "\\<f\\w*\\>" (region-beginning) (region-end)) @end example If you call @code{sort-regexp-fields} interactively, you are prompted for @var{record-regexp} and @var{key} and you can type them in without enclosing them in quotation marks and without inserting a second @samp{\} to quote each @code{\}. @end deffn @deffn Command sort-subr reverse nextrecfun endrecfun &optional startkeyfun endkeyfun This command is the general text sorting routine that divides a buffer into records and sorts them. The functions @code{sort-lines}, @code{sort-paragraphs}, @code{sort-pages}, @code{sort-fields}, and @code{sort-numeric-fields} all use @code{sort-subr}. To understand how @code{sort-subr} works, consider the whole accessible portion of the buffer as being divided into disjoint pieces called @dfn{sort records}. A portion of each sort record (perhaps all of it) is designated as the sort key. The records are rearranged in the buffer in order by their sort keys. The records may or may not be contiguous. Usually, the records are rearranged in order of ascending sort key. If the first argument to the @code{sort-subr} function, @var{reverse}, is non-@code{nil}, the sort records are rearranged in order of descending sort key. The next four arguments to @code{sort-subr} are functions that are called to move point across a sort record. They are called many times from within @code{sort-subr}. @enumerate @item @var{nextrecfun} is called with point at the end of the previous record. This function moves point to the start of the next record. The first record is assumed to start at the position of point when @code{sort-subr} is called. @item @var{endrecfun} is called with point within the record. It moves point to the end of the record. @item @var{startkeyfun} may move point from the start of the record to the start of the key. This argument is optional. It will either return a non-nil value that will be used as the key, or it will return @code{nil} and the key will be the substring between the values of point before and after @var{endkeyfun} is called. @item @var{endkeyfun} moves point from the start of the sort key to the end of the sort key. This argument is optional. @var{endkeyfun} may be @code{nil} if @var{startkeyfun} returns a value that will be used as the key or if the key continues to the end of the record. @end enumerate For an example of @code{sort-subr}, here is the complete function definition for @code{sort-lines}: @example (defun sort-lines (reverse beg end) "Sort lines in region alphabetically; argument means descending order. Called from a program, there are three arguments: REVERSE (non-nil means reverse order), BEG and END (region to sort)." (interactive "P\nr") (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (sort-subr reverse 'forward-line 'end-of-line))) @end example In the @code{sort-lines} function, @code{forward-line} moves point to the start of the next record, and @code{end-of-line} moves point to the end of record. The @code{sort-paragraphs} function is very much the same, except that its @code{sort-subr} call looks like this: @example (sort-subr reverse (function (lambda () (skip-chars-forward "\n \t\f"))) 'forward-paragraph))) @end example @end deffn @deffn Command sort-lines reverse start end This command sorts lines in the region between @var{start} and @var{end} alphabetically. If @var{reverse} is non-@code{nil}, the sort is in reverse order. @end deffn @deffn Command sort-paragraphs reverse start end This command sorts paragraphs in the region between @var{start} and @var{end} alphabetically. If @var{reverse} is non-@code{nil}, the sort is in reverse order. @end deffn @deffn Command sort-pages reverse start end This command sorts pages in the region between @var{start} and @var{end} alphabetically. If @var{reverse} is non-@code{nil}, the sort is in reverse order. @end deffn @deffn Command sort-fields field start end This command sorts lines in the region between @var{start} and @var{end} lexicographically by the @var{field}'th field of each line. Fields are separated by whitespace and numbered from @code{1} up. If @code{field} is negative, sorting is by the @w{@minus{}@var{field}'th} field, in reverse order. This command is useful for sorting tables. @end deffn @deffn Command sort-numeric-fields field start end This command sorts lines in the region between @var{start} and @var{end} numerically by the @var{field}'th field of each line. Fields are separated by whitespace and numbered from @code{1} up. Specified field must contain a number in each line of the region. If @code{field} is negative, sort by the @w{@minus{}@var{field}'th} field, in reverse order. This command is useful for sorting tables. @end deffn @deffn Command sort-columns reverse &optional beg end This command sorts lines in the region between @var{start} and @var{end} alphabetically by a certain range of columns. For the purpose of this command, the region includes the entire line that point is in and the entire line containing @var{end}. The column positions of @var{beg} and @var{end} bound the range of columns to sort on. If @var{reverse} is non-@code{nil}, the sort is in reverse order. Note that @code{sort-columns} uses the @file{sort} utility program and therefore cannot work properly on text containing @key{TAB} characters. (Use @kbd{M-x @code{untabify}} to convert tabs to spaces before sorting.) The @code{sort-columns} function cannot work in VMS. @end deffn @node Indentation, Indent Tabs, Sorting, Text @section Indentation @cindex indenting The indentation functions are used to examine, move to, and change whitespace that is at the beginning of a line. Some of the functions can also change whitespace elsewhere on a line. Indentation always counts from zero at the beginning of a line. @deffn Command back-to-indentation @comment !!SourceFile simple.el This command moves point to the first non-whitespace character in the the current line (which is the line in which point is located). @end deffn @deffn Command backward-to-indentation arg @comment !!SourceFile simple.el This command moves point backward @var{arg} lines and positions point at the first nonblank character. @end deffn @defun current-indentation @comment !!Type Primitive Function @comment !!SourceFile indent.c This function returns the indentation of the current line. This is the horizontal position of the character following any initial whitespace. @end defun @deffn Command forward-to-indentation arg @comment !!SourceFile simple.el This command moves point forward @var{arg} lines and positions it at the first nonblank character. @end deffn @deffn Command indent-according-to-mode @comment !!SourceFile indent.el This command indents the current line in the proper way for the current major mode. Thus, Lisp mode uses @code{lisp-indent-line} to indent the current line, C mode uses @code{c-indent-line}, and Fortran mode uses @code{fortran-indent-line}. @end deffn @deffn Command indent-for-tab-command @comment !!SourceFile indent.el This command indents the current line in the proper way for the current major mode, except that if the function for indenting lines is @code{indent-to-left-margin}, this function calls @code{insert-tab}. However, Lisp mode uses @code{lisp-indent-line} to indent the current line, and C mode uses @code{c-indent-line}. @end deffn @defvar indent-line-function This variable has a value which is the function that will be called to indent current line. The default value is @code{indent-to-left-margin}, and in Lisp mode it would be set to @code{lisp-indent-line} and in C mode it would be set to @code{c-indent-line}. A command such as @code{indent-according-to-mode} is no more than a @code{funcall} to this function. @end defvar @defvar left-margin This variable is the column to which the default default @code{indent-line-function} will indent. (That function is @code{indent-to-left-margin}.) In Fundamental mode, @key{LFD} indents to this column. This variable automatically becomes local when set in any fashion. @end defvar @defun indent-to-left-margin This is the default @code{indent-line-function}. It is used in Fundamental mode, Text mode, etc. Its effect is to make the indentation at the beginning of the current line exactly the amount specified by the variable @code{left-margin}. This may involve inserting additional indentation or deleting extra indentation. @end defun @deffn Command indent-region start end to-column This command indents each nonblank line starting between @var{start} (inclusive) and @var{end} (exclusive). If @var{to-column} is @code{nil}, @code{indent-region} indents each nonblank line according to the indentation function that is bound to @key{TAB} in that mode, such as @code{indent-to-left-margin} in Fundamental mode, @code{lisp-indent-line} in Lisp Interaction mode, and @code{c-indent-line} in C mode. If @var{to-column} is an integer, this function indents each line to that column. @end deffn @defvar indent-region-function The value of this variable is a function that can be used by @code{indent-region} as a short cut. It ought to produce the same results as indenting the lines of the region one by one, which is the definition of @code{indent-region} with argument @code{nil}. If the value is @code{nil}, there is no short cut, and @code{indent-region} actually works line by line. A short cut is useful in modes such as C mode and Lisp mode, where the @code{indent-line-function} must scan from the beginning of the function: applying it to each line would be quadratic in time. The short cut can update the scan information as it moves through the lines indenting them; this takes linear time. If indenting a line individually is fast, there is no need for a short cut. @code{indent-region} with a non-@code{nil} argument has a different definition and does not use this variable. @end defvar @deffn Command indent-relative &optional unindented-ok This function inserts whitespace at point, extending to the same column as the next @dfn{indent point} of the previous nonblank line. An indent point is a non-whitespace character following whitespace. If the previous nonblank line has no indent points beyond (that is, to the right of) the column from which point starts, this function calls @code{tab-to-tab-stop}; except that if the optional argument, @var{unindented-ok}, is non-@code{nil}, then, if the previous nonblank line has no indent points beyond the column at which point starts, this function does nothing. Thus, if point is underneath, but to the right of the last column of a short line of text, this function moves point to the next tab stop by inserting whitespace. If point is underneath and to the left of the first non-blank character of a line of text, point is moved to that column by inserting whitespace. In the first example, point is at the beginning of the third line. @example This line is indented twelve spaces. @point{}The quick brown fox jumped over the lazy dog. @end example @noindent Evaluation of the expression @code{(indent-relative nil)} produces the following: @example This line is indented twelve spaces. @point{}The quick brown fox jumped over the lazy dog. @end example In the next example, point is between the @samp{m} and @samp{p} of @samp{jumped}: @example This line is indented twelve spaces. The quick brown fox jum@point{}ped over the lazy dog. @end example @noindent Evaluation of the expression @code{(indent-relative nil)} produces the following: @example This line is indented twelve spaces. The quick brown fox jum @point{}ped over the lazy dog. @end example @end deffn @deffn Command indent-relative-maybe @comment !!SourceFile indent.el This command indents the line on which point is located like the previous nonblank line. The function consists of a call to @code{indent-relative} with a non-@code{nil} value passed to the @var{unindented-ok} optional argument. If the previous line is not indented, then the line on which point is located is given no indentation; and if the previous nonblank line has no indent points beyond the column at which point starts, this function does not do any indentation. @end deffn @deffn Command indent-rigidly start end count @comment !!SourceFile indent.el This command indents all lines starting between @var{start} (inclusive) and @var{end} (exclusive) sideways by @code{count} columns. Thus, if you wish to indent all lines in a region by 3 spaces, you execute this command with a @var{count} of 3. In Mail mode, @kbd{C-c C-y} (@code{mail-yank-original}) uses @code{indent-rigidly} to indent the text copied from the message being replied to. This command adds indentation to lines that are already indented; it `preserves the shape' of the indented region, moving it sideways as a single unit. Consequently, this command is useful not only for indenting regions of unindented text, but also for indenting regions of formatted code. @end deffn @defopt indent-tabs-mode @comment !!SourceFile indent.c If this user option is non-@code{nil}, indentation functions can insert tabs rather than spaces. Setting this variable automatically makes it local to the current buffer. @end defopt @deffn Command indent-to col &optional minimum @comment !!Type Primitive Function @comment !!SourceFile indent.c This function indents from point with tabs and spaces until @var{column} is reached. It always indents by at least @var{min} spaces even if that goes past @var{column}; by default, @var{min} is zero. @end deffn @deffn Command newline-and-indent @comment !!SourceFile simple.el This function inserts a newline, and then indents the new line according to the major mode. Indentation is done using the current @code{indent-line-function}. In programming language modes, this is the same as @key{TAB}. In some text modes, where @key{TAB} inserts a tab, @code{newline-and-indent} indents to the specified left-margin column. @end deffn @deffn Command reindent-then-newline-and-indent @comment !!SourceFile simple.el This command reindents current line, inserts a newline at point, and then indents the new line. Indentation of both lines is done according to the current major mode; this means that the current value of @code{indent-line-function} is called. In programming language modes, this is the same as @key{TAB}. In some text modes, where @key{TAB} inserts a tab, @code{reindent-then-newline-and-indent} indents to the specified left-margin column. @end deffn @node Indent Tabs, Columns, Indentation, Text @comment node-name, next, previous, up @section Tabs for Indentation @cindex tabs for indentation The following tab functions insert indentation in user specified amounts. They do not simply insert tab characters. @defun tab-to-tab-stop This function inserts spaces or tabs to the next defined @dfn{tab-stop} column. The variable @code{tab-stop-list} is a list of columns at which there are tab stops. The distance between tab stops need not be constant. This feature is convenient if you are making tables with columns of differing width. Use @kbd{M-x edit-tab-stops} to edit the location of tab stops interactively. @end defun @defopt tab-stop-list This variable is the list of tab stop positions used by @code{tab-to-tab-stops}. The tab stop positions need not be equally spaced. Note that @code{tab-stop-list} has nothing to do with the tab character and is not related to the @code{tab-width} variable. @end defopt @node Columns, Case Changes, Indent Tabs, Text @comment node-name, next, previous, up @section Columns The column functions do not take into account the width of windows, or the amount of horizontal scrolling. As a consequence, the value of @var{column} can be arbitrarily high. The first (or leftmost) column is numbered @code{0}. @defun current-column This function returns the horizontal position of point. The beginning of a line is column 0. The column is calculated by adding together the widths of all the displayed representations of the characters between the start of the current line and point. This means control characters will be counted as occupying 2 or 4 columns, depending upon the value of @code{ctl-arrow}, and tabs will be counted as occupying a number of columns that depends on the value of @code{tab-width}. The @code{current-column} function ignores the finite width of the screen, which means that this function may return values greater than @code{(screen-width)}. @end defun @defun move-to-column column @cindex character width @cindex tab character width @vindex ctl-arrow This function moves point to @var{column} in the current line. The calculation of @var{column} takes into account the widths of all the displayed representations of the characters between the start of the line and point. Thus control characters are calculated to occupy 2 or 4 columns, depending upon the setting of @code{ctl-arrow}, and tabs to occupy a number of columns that depends on the value of @code{tab-width}. The @code{move-to-column} function may be passed values greater than the value returned by @code{(screen-width)}. If the current line is not that wide, then point is moved to the end of the line. If @var{column} is negative, point is moved to the beginning of the line. @var{column} must be an integer. The result is the column number actually moved to. @end defun @node Case Changes, Underlining, Indent Tabs, Text @comment node-name, next, previous, up @section Case Changes @cindex case changes These case change commands work on text in the current buffer. @xref{Character Case}, for case conversion commands that work on strings and characters. @deffn Command capitalize-region start end This function capitalizes all words in the region defined by @var{start} and @var{end}. To `capitalize' means to convert each word's first character is upper case and convert the rest of each word to lower case. The function returns @code{nil}. When @code{capitalize-region} is called interactively, @var{start} and @var{end} are point and mark, smallest first. @example ---------- Buffer: foo ---------- This is the contents of the 5th foo. ---------- Buffer: foo ---------- (capitalize-region 1 44) @result{} nil ---------- Buffer: foo ---------- This Is The Contents Of The 5th Foo. ---------- Buffer: foo ---------- @end example @end deffn @deffn Command downcase-region start end This function converts all of the words in the region defined by @var{start} and @var{end} to lower case. The function returns @code{nil}. When @code{downcase-region} is called interactively, @var{start} and @var{end} are point and mark, smallest first. @end deffn @deffn Command upcase-region start end This function converts all of the words in the region defined by @var{start} and @var{end} to upper case. The function returns @code{nil}. When @code{downcase-region} is called interactively, @var{start} and @var{end} are point and mark, smallest first. @end deffn @deffn Command capitalize-word count This function capitalizes @var{count} words after point, moving point over as it does. To `capitalize' means to convert each word's first character is upper case and convert the rest of each word to lower case. If @var{count} is negative, the function capitalizes the @minus{}@var{count} previous words but does not move point. When @code{capitalize-word} is called interactively, @var{count} is set to the numeric prefix argument. @end deffn @deffn Command downcase-word count This function converts the @var{count} words after point to all lower case, moving point over as it does. If @var{count} is negative, it converts the @minus{}@var{count} previous words but does not move point. When @code{downcase-word} is called interactively, @var{count} is set to the numeric prefix argument. @end deffn @deffn Command upcase-word count This function converts the @var{count} words after point to all upper case, moving point over as it does. If @var{count} is negative, it converts the @minus{}@var{count} previous words but does not move point. When @code{upcase-word} is called interactively, @var{count} is set to the numeric prefix argument. @end deffn @node Underlining, Registers, Case Changes, Text @section Underlining @cindex underlining The underlining commands are somewhat obsolete. The @code{underline-region} function actually inserts @samp{_^H} before each appropriate character in the region. This command provides a minimal text formatting feature that might work on your printer; but you are encouraged to use more powerful text formatting facilities instead, such as Texinfo. @deffn Command underline-region start end This function underlines all nonblank characters in the region defined by @var{start} and @var{end}. That is, an underscore character and a backspace character are inserted just before each non-whitespace character in the region. However, the backspace characters are displayed by Emacs as either @samp{\010} or @samp{^H}, depending on the setting of @code{ctl-arrow}. @end deffn @deffn Command ununderline-region start end This function removes all underlining (overstruck underscores) in the region defined by @var{start} and @var{end}. @end deffn @node Registers, , Underlining, Text @section Registers @cindex registers A register is a user-level variable in emacs that can hold a marker, a string, or a rectangle. Emacs has 255 accessible registers (@kbd{C-g} cannot be used as the name of one). The registers include the @key{CTL} and @key{META} keys; each register is named by a character. @defvar register-alist This variable is an alist of elements in the form @code{(@var{name} . @var{contents})}. Normally, there is one element for each Emacs register that has been used. @var{name} is a character (a number), identifying the register. @var{contents} is a string, marker, or list. A list represents a rectangle; its elements are strings. @end defvar @deffn Command view-register reg This command displays what is contained in the register named @var{reg}. @var{reg} is a character. @end deffn @defun get-register reg This function returns the contents of the register named @var{reg}, or @code{nil} if it has no contents. The name of the register is a character. @end defun @defun set-register reg value This function sets the contents of the register named @var{reg} to @var{value}. A register can be set to any value; however, the various other register functions know only about strings, markers, and lists. @end defun @deffn Command point-to-register reg This command stores both the current location of point and the current buffer in a register as a marker. The argument @var{reg} must be a character, which names the register. @end deffn @deffn Command register-to-point reg @comment !!SourceFile register.el This command moves point to the location in the buffer that was stored in the register named by the argument. The argument must be a character. Since both the buffer and the location within the buffer are stored by the @code{point-to-register} function, this command can switch you to another buffer. @end deffn @deffn Command insert-register reg &optional beforep This command inserts contents of register @var{reg} into the current buffer. @var{reg} is a character that names the register. Normally, this command puts point before and mark after the inserted text. If the optional second argument, @var{beforep} is non-@code{nil}, the command puts mark before and point after. You can pass a non-@code{nil} second argument @code{beforep} to this function interactively by supplying it with a prefix argument. @end deffn @deffn Command copy-to-register reg start end &optional delete-flag This command copies the region from @var{start} to @var{end} into register @var{reg}. If @var{delete-flag} is non-@code{nil}, this command deletes the region from the buffer after copying it into the register. @end deffn @deffn Command prepend-to-register reg start end &optional delete-flag This command prepends the region from @var{start} to @var{end} into register @var{reg}. If @var{delete-flag} is non-@code{nil}, this command deletes the region from the buffer after copying it to the register. @end deffn @deffn Command append-to-register reg start end &optional delete-flag This command appends the region from @var{start} to @var{end} to the text already in register @var{reg}. If @var{delete-flag} is non-@code{nil}, this command deletes the region from the buffer after copying it to the register. @end deffn @deffn Command copy-rectangle-to-register reg start end &optional delete-flag This command copies a rectangular region from @var{start} to @var{end} into register @var{reg}. If @var{delete-flag} is non-@code{nil}, this command deletes the region from the buffer after copying it to the register. @end deffn