annotate man/lispref/text.texi @ 5252:378a34562cbe

Fix style, documentation for rounding functions and multiple values. src/ChangeLog addition: 2010-08-30 Aidan Kehoe <kehoea@parhasard.net> * floatfns.c (ceiling_one_mundane_arg, floor_one_mundane_arg) (round_one_mundane_arg, truncate_one_mundane_arg): INTEGERP is always available, no need to wrap calls to it with #ifdef HAVE_BIGNUM. (Fceiling, Ffloor, Fround, Ftruncate, Ffceiling, Fffloor) (Ffround, Fftruncate): Correct some code formatting here. * doprnt.c (emacs_doprnt_1): Remove some needless #ifdef WITH_NUMBER_TYPES, now number.h is always #included. man/ChangeLog addition: 2010-08-30 Aidan Kehoe <kehoea@parhasard.net> * lispref/eval.texi (Evaluation, Multiple values): Document our implementation of multiple values; point the reader to the CLTL or the Hyperspec for details of exactly when values are discarded. * lispref/numbers.texi (Numeric Conversions): Document the optional DIVISOR arguments to the rounding functions, and document that they all return multiple values. (Rounding Operations): Ditto. * cl.texi (Multiple Values): Document that we've moved the multiple values implementation to core code, and cross-reference to the Lispref. (Numerical Functions): The various rounding functions are now identical to the built-in rounding functions, with the exception that they return lists, not multiple values; document this.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 30 Aug 2010 15:23:42 +0100
parents 99f8ebc082d9
children 9fae6227ede5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/text.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Text, Searching and Matching, Markers, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 This chapter describes the functions that deal with the text in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 buffer. Most examine, insert, or delete text in the current buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 often in the vicinity of point. Many are interactive. All the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 functions that change the text provide for undoing the changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 (@pxref{Undo}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 Many text-related functions operate on a region of text defined by two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 buffer positions passed in arguments named @var{start} and @var{end}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 These arguments should be either markers (@pxref{Markers}) or numeric
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 character positions (@pxref{Positions}). The order of these arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 does not matter; it is all right for @var{start} to be the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 region and @var{end} the beginning. For example, @code{(delete-region 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 10)} and @code{(delete-region 10 1)} are equivalent. An
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 @code{args-out-of-range} error is signaled if either @var{start} or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 @var{end} is outside the accessible portion of the buffer. In an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 interactive call, point and the mark are used for these arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 @cindex buffer contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 Throughout this chapter, ``text'' refers to the characters in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 buffer, together with their properties (when relevant).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 * Near Point:: Examining text in the vicinity of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 * Buffer Contents:: Examining text in a general fashion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 * Comparing Text:: Comparing substrings of buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 * Insertion:: Adding new text to a buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 * Commands for Insertion:: User-level commands to insert text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 * Deletion:: Removing text from a buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 * User-Level Deletion:: User-level commands to delete text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 * The Kill Ring:: Where removed text sometimes is saved for later use.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 * Undo:: Undoing changes to the text of a buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 * Maintaining Undo:: How to enable and disable undo information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 How to control how much information is kept.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 * Filling:: Functions for explicit filling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 * Margins:: How to specify margins for filling commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 * Auto Filling:: How auto-fill mode is implemented to break lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 * Sorting:: Functions for sorting parts of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 * Columns:: Computing horizontal positions, and using them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 * Indentation:: Functions to insert or adjust indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 * Case Changes:: Case conversion of parts of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 * Text Properties:: Assigning Lisp property lists to text characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 * Substitution:: Replacing a given character wherever it appears.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 * Registers:: How registers are implemented. Accessing the text or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 position stored in a register.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 * Transposition:: Swapping two portions of a buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 * Change Hooks:: Supplying functions to be run when text is changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 * Transformations:: MD5 and base64 support.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 @node Near Point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 @section Examining Text Near Point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Many functions are provided to look at the characters around point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 Several simple functions are described here. See also @code{looking-at}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 in @ref{Regexp Search}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 Many of these functions take an optional @var{buffer} argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 In all such cases, the current buffer will be used if this argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 is omitted. (In FSF Emacs, and earlier versions of XEmacs, these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 functions usually did not have these optional @var{buffer} arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 and always operated on the current buffer.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
73 @defun char-after &optional position buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 This function returns the character in the buffer at (i.e.,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 immediately after) position @var{position}. If @var{position} is out of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 range for this purpose, either before the beginning of the buffer, or at
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
77 or beyond the end, then the value is @code{nil}. The default for
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
78 @var{position} is point. If optional argument @var{buffer} is
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
79 @code{nil}, the current buffer is assumed.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 In the following example, assume that the first character in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 buffer is @samp{@@}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (char-to-string (char-after 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 @result{} "@@"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
92 @defun char-before &optional position buffer
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
93 This function returns the character in the current buffer immediately
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
94 before position @var{position}. If @var{position} is out of range for
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
95 this purpose, either at or before the beginning of the buffer, or beyond
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
96 the end, then the value is @code{nil}. The default for
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
97 @var{position} is point. If optional argument @var{buffer} is
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
98 @code{nil}, the current buffer is assumed.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
99 @end defun
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
100
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 @defun following-char &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 This function returns the character following point in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 This is similar to @code{(char-after (point))}. However, if point is at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 the end of the buffer, then the result of @code{following-char} is 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 If optional argument @var{buffer} is @code{nil}, the current buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 Remember that point is always between characters, and the terminal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 cursor normally appears over the character following point. Therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 the character returned by @code{following-char} is the character the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 cursor is over.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 In this example, point is between the @samp{a} and the @samp{c}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 Gentlemen may cry ``Pea@point{}ce! Peace!,''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 but there is no peace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 (char-to-string (preceding-char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 @result{} "a"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (char-to-string (following-char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 @result{} "c"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 @defun preceding-char &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 This function returns the character preceding point in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 See above, under @code{following-char}, for an example. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 point is at the beginning of the buffer, @code{preceding-char} returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 0. If optional argument @var{buffer} is @code{nil}, the current buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 @defun bobp &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 This function returns @code{t} if point is at the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 buffer. If narrowing is in effect, this means the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 accessible portion of the text. If optional argument @var{buffer} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 @code{nil}, the current buffer is assumed. See also @code{point-min} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 @ref{Point}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 @defun eobp &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 This function returns @code{t} if point is at the end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 If narrowing is in effect, this means the end of accessible portion of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 the text. If optional argument @var{buffer} is @code{nil}, the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 buffer is assumed. See also @code{point-max} in @xref{Point}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 @defun bolp &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 This function returns @code{t} if point is at the beginning of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 If optional argument @var{buffer} is @code{nil}, the current buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 assumed. @xref{Text Lines}. The beginning of the buffer (or its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 accessible portion) always counts as the beginning of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 @defun eolp &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 This function returns @code{t} if point is at the end of a line. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 end of the buffer is always considered the end of a line. If optional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 argument @var{buffer} is @code{nil}, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 The end of the buffer (or of its accessible portion) is always considered
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 the end of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 @node Buffer Contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 @section Examining Buffer Contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 This section describes two functions that allow a Lisp program to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 convert any portion of the text in the buffer into a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 @defun buffer-substring start end &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @defunx buffer-string start end &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 These functions are equivalent and return a string containing a copy of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 the text of the region defined by positions @var{start} and @var{end} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 the buffer. If the arguments are not positions in the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 portion of the buffer, @code{buffer-substring} signals an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 @code{args-out-of-range} error. If optional argument @var{buffer} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 @code{nil}, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 @c XEmacs feature.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 If the region delineated by @var{start} and @var{end} contains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 duplicable extents, they will be remembered in the string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 @xref{Duplicable Extents}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 It is not necessary for @var{start} to be less than @var{end}; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 arguments can be given in either order. But most often the smaller
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 argument is written first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 This is the contents of buffer foo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (buffer-substring 1 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 @result{} "This is t"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (buffer-substring (point-max) 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 @result{} "he contents of buffer foo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 @ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 @c `equal' in XEmacs does not compare text properties on strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 @defun buffer-substring-without-properties start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 This is like @code{buffer-substring}, except that it does not copy text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 properties, just the characters themselves. @xref{Text Properties}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 Here's an example of using this function to get a word to look up in an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 alist:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (setq flammable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (assoc (buffer-substring start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 '(("wood" . t) ("paper" . t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 ("steel" . nil) ("asbestos" . nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 If this were written using @code{buffer-substring} instead, it would not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 work reliably; any text properties that happened to be in the word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 copied from the buffer would make the comparisons fail.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 @node Comparing Text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 @section Comparing Text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 @cindex comparing buffer text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 This function lets you compare portions of the text in a buffer, without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 copying them into strings first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 @defun compare-buffer-substrings buffer1 start1 end1 buffer2 start2 end2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 This function lets you compare two substrings of the same buffer or two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 different buffers. The first three arguments specify one substring,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 giving a buffer and two positions within the buffer. The last three
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 arguments specify the other substring in the same way. You can use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 @code{nil} for @var{buffer1}, @var{buffer2}, or both to stand for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 The value is negative if the first substring is less, positive if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 first is greater, and zero if they are equal. The absolute value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 the result is one plus the index of the first differing characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 within the substrings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 This function ignores case when comparing characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 if @code{case-fold-search} is non-@code{nil}. It always ignores
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 text properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 Suppose the current buffer contains the text @samp{foobarbar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 haha!rara!}; then in this example the two substrings are @samp{rbar }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 and @samp{rara!}. The value is 2 because the first substring is greater
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 at the second character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (compare-buffer-substring nil 6 11 nil 16 21)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 @result{} 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 @node Insertion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 @section Inserting Text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 @cindex insertion of text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 @cindex text insertion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 @dfn{Insertion} means adding new text to a buffer. The inserted text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 goes at point---between the character before point and the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 Insertion relocates markers that point at positions after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 insertion point, so that they stay with the surrounding text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (@pxref{Markers}). When a marker points at the place of insertion,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 insertion normally doesn't relocate the marker, so that it points to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 beginning of the inserted text; however, certain special functions such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 as @code{insert-before-markers} relocate such markers to point after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 @cindex insertion before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 @cindex before point, insertion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 Some insertion functions leave point before the inserted text, while
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 other functions leave it after. We call the former insertion @dfn{after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 point} and the latter insertion @dfn{before point}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 @c XEmacs feature.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 If a string with non-@code{nil} extent data is inserted, the remembered
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 extents will also be inserted. @xref{Duplicable Extents}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 Insertion functions signal an error if the current buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 read-only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 These functions copy text characters from strings and buffers along
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 with their properties. The inserted characters have exactly the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 properties as the characters they were copied from. By contrast,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 characters specified as separate arguments, not part of a string or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 buffer, inherit their text properties from the neighboring text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 @defun insert &rest args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 This function inserts the strings and/or characters @var{args} into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 current buffer, at point, moving point forward. In other words, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 inserts the text before point. An error is signaled unless all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 @var{args} are either strings or characters. The value is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 @defun insert-before-markers &rest args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 This function inserts the strings and/or characters @var{args} into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 current buffer, at point, moving point forward. An error is signaled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 unless all @var{args} are either strings or characters. The value is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 This function is unlike the other insertion functions in that it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 relocates markers initially pointing at the insertion point, to point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 after the inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 @defun insert-string string &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 This function inserts @var{string} into @var{buffer} before point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 @var{buffer} defaults to the current buffer if omitted. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 function is chiefly useful if you want to insert a string in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 a buffer other than the current one (otherwise you could just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 use @code{insert}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
332 @defun insert-char character &optional count ignored buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 This function inserts @var{count} instances of @var{character} into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 @var{buffer} before point. @var{count} must be a number, and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
335 @var{character} must be a character.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
336
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
337 If optional argument @var{buffer} is @code{nil}, the current buffer is
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
338 assumed. (In FSF Emacs, the third argument is called @var{inherit} and
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
339 refers to text properties. In XEmacs, it is always ignored.)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
340
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
341 This function always returns @code{nil}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 @defun insert-buffer-substring from-buffer-or-name &optional start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 This function inserts a portion of buffer @var{from-buffer-or-name}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (which must already exist) into the current buffer before point. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 text inserted is the region from @var{start} and @var{end}. (These
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 arguments default to the beginning and end of the accessible portion of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 that buffer.) This function returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 In this example, the form is executed with buffer @samp{bar} as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 current buffer. We assume that buffer @samp{bar} is initially empty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 We hold these truths to be self-evident, that all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (insert-buffer-substring "foo" 1 20)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 ---------- Buffer: bar ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 We hold these truth@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ---------- Buffer: bar ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 @node Commands for Insertion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 @section User-Level Insertion Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 This section describes higher-level commands for inserting text,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 commands intended primarily for the user but useful also in Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 @deffn Command insert-buffer from-buffer-or-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 This command inserts the entire contents of @var{from-buffer-or-name}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (which must exist) into the current buffer after point. It leaves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 the mark after the inserted text. The value is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 @deffn Command self-insert-command count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 @cindex character insertion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 @cindex self-insertion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 This command inserts the last character typed; it does so @var{count}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 times, before point, and returns @code{nil}. Most printing characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 are bound to this command. In routine use, @code{self-insert-command}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 is the most frequently called function in XEmacs, but programs rarely use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 it except to install it on a keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 In an interactive call, @var{count} is the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 This command calls @code{auto-fill-function} whenever that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 non-@code{nil} and the character inserted is a space or a newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (@pxref{Auto Filling}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 @c Cross refs reworded to prevent overfull hbox. --rjc 15mar92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 This command performs abbrev expansion if Abbrev mode is enabled and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 the inserted character does not have word-constituent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 syntax. (@xref{Abbrevs}, and @ref{Syntax Class Table}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 This is also responsible for calling @code{blink-paren-function} when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 the inserted character has close parenthesis syntax (@pxref{Blinking}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
409 @deffn Command newline &optional count
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 This command inserts newlines into the current buffer before point.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
411 If @var{count} is supplied, that many newline characters
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 are inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 @cindex newline and Auto Fill mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 This function calls @code{auto-fill-function} if the current column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 number is greater than the value of @code{fill-column} and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
417 @var{count} is @code{nil}. Typically what
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 @code{auto-fill-function} does is insert a newline; thus, the overall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 result in this case is to insert two newlines at different places: one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 at point, and another earlier in the line. @code{newline} does not
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
421 auto-fill if @var{count} is non-@code{nil}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 This command indents to the left margin if that is not zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 @xref{Margins}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 The value returned is @code{nil}. In an interactive call, @var{count}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 is the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 @deffn Command split-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 This command splits the current line, moving the portion of the line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 after point down vertically so that it is on the next line directly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 below where it was before. Whitespace is inserted as needed at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 beginning of the lower line, using the @code{indent-to} function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 @code{split-line} returns the position of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 Programs hardly ever use this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 @defvar overwrite-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 This variable controls whether overwrite mode is in effect: a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 non-@code{nil} value enables the mode. It is automatically made
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 buffer-local when set in any fashion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 @node Deletion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 @section Deleting Text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 @cindex deletion vs killing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 Deletion means removing part of the text in a buffer, without saving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 it in the kill ring (@pxref{The Kill Ring}). Deleted text can't be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 yanked, but can be reinserted using the undo mechanism (@pxref{Undo}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 Some deletion functions do save text in the kill ring in some special
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 cases.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 All of the deletion functions operate on the current buffer, and all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 return a value of @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
459 @deffn Command erase-buffer &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 This function deletes the entire text of @var{buffer}, leaving it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 empty. If the buffer is read-only, it signals a @code{buffer-read-only}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 error. Otherwise, it deletes the text without asking for any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 confirmation. It returns @code{nil}. @var{buffer} defaults to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 Normally, deleting a large amount of text from a buffer inhibits further
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 auto-saving of that buffer ``because it has shrunk''. However,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 @code{erase-buffer} does not do this, the idea being that the future
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 text is not really related to the former text, and its size should not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 be compared with that of the former text.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
471 @end deffn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 @deffn Command delete-region start end &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 This command deletes the text in @var{buffer} in the region defined by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 @var{start} and @var{end}. The value is @code{nil}. If optional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 argument @var{buffer} is @code{nil}, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
479 @deffn Command delete-char &optional count killp
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 This command deletes @var{count} characters directly after point, or
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
481 before point if @var{count} is negative. @var{count} defaults to @code{1}.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
482 If @var{killp} is non-@code{nil}, then it saves the deleted characters
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
483 in the kill ring.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 In an interactive call, @var{count} is the numeric prefix argument, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 @var{killp} is the unprocessed prefix argument. Therefore, if a prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 argument is supplied, the text is saved in the kill ring. If no prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 argument is supplied, then one character is deleted, but not saved in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 The value returned is always @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
494 @deffn Command delete-backward-char &optional count killp
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 @cindex delete previous char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 This command deletes @var{count} characters directly before point, or
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
497 after point if @var{count} is negative. @var{count} defaults to 1.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
498 If @var{killp} is non-@code{nil}, then it saves the deleted characters
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
499 in the kill ring.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 In an interactive call, @var{count} is the numeric prefix argument, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 @var{killp} is the unprocessed prefix argument. Therefore, if a prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 argument is supplied, the text is saved in the kill ring. If no prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 argument is supplied, then one character is deleted, but not saved in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 The value returned is always @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 @deffn Command backward-delete-char-untabify count &optional killp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 @cindex tab deletion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 This command deletes @var{count} characters backward, changing tabs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 into spaces. When the next character to be deleted is a tab, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 first replaced with the proper number of spaces to preserve alignment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 and then one of those spaces is deleted instead of the tab. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 @var{killp} is non-@code{nil}, then the command saves the deleted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 characters in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 Conversion of tabs to spaces happens only if @var{count} is positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 If it is negative, exactly @minus{}@var{count} characters after point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 are deleted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 In an interactive call, @var{count} is the numeric prefix argument, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 @var{killp} is the unprocessed prefix argument. Therefore, if a prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 argument is supplied, the text is saved in the kill ring. If no prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 argument is supplied, then one character is deleted, but not saved in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 The value returned is always @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 @node User-Level Deletion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 @section User-Level Deletion Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 This section describes higher-level commands for deleting text,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 commands intended primarily for the user but useful also in Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 @deffn Command delete-horizontal-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 @cindex deleting whitespace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 This function deletes all spaces and tabs around point. It returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 In the following examples, we call @code{delete-horizontal-space} four
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 times, once on each line, with point between the second and third
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 characters on the line each time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 I @point{}thought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 I @point{} thought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 We@point{} thought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 Yo@point{}u thought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (delete-horizontal-space) ; @r{Four times.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 Ithought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 Ithought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 Wethought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 You thought
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
572 @deffn Command delete-indentation &optional join-following-p
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 This function joins the line point is on to the previous line, deleting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 any whitespace at the join and in some cases replacing it with one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 space. If @var{join-following-p} is non-@code{nil},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 @code{delete-indentation} joins this line to the following line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 instead. The value is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 If there is a fill prefix, and the second of the lines being joined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 starts with the prefix, then @code{delete-indentation} deletes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 fill prefix before joining the lines. @xref{Margins}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 In the example below, point is located on the line starting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 @samp{events}, and it makes no difference if there are trailing spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 in the preceding line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 When in the course of human
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 @point{} events, it becomes necessary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (delete-indentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 When in the course of human@point{} events, it becomes necessary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 After the lines are joined, the function @code{fixup-whitespace} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 responsible for deciding whether to leave a space at the junction.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
609 @deffn Command fixup-whitespace
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 This function replaces all the white space surrounding point with either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 one space or no space, according to the context. It returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 At the beginning or end of a line, the appropriate amount of space is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 none. Before a character with close parenthesis syntax, or after a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 character with open parenthesis or expression-prefix syntax, no space is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 also appropriate. Otherwise, one space is appropriate. @xref{Syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 Class Table}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 In the example below, @code{fixup-whitespace} is called the first time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 with point before the word @samp{spaces} in the first line. For the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 second invocation, point is directly after the @samp{(}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 This has too many @point{}spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 This has too many spaces at the start of (@point{} this list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (fixup-whitespace)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (fixup-whitespace)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 This has too many spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 This has too many spaces at the start of (this list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 @end smallexample
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
645 @end deffn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 @deffn Command just-one-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 @comment !!SourceFile simple.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 This command replaces any spaces and tabs around point with a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 space. It returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 @deffn Command delete-blank-lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 This function deletes blank lines surrounding point. If point is on a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 blank line with one or more blank lines before or after it, then all but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 one of them are deleted. If point is on an isolated blank line, then it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 is deleted. If point is on a nonblank line, the command deletes all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 blank lines following it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 A blank line is defined as a line containing only tabs and spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 @code{delete-blank-lines} returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 @node The Kill Ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 @section The Kill Ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 @cindex kill ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 @dfn{Kill} functions delete text like the deletion functions, but save
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 it so that the user can reinsert it by @dfn{yanking}. Most of these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 functions have @samp{kill-} in their name. By contrast, the functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 whose names start with @samp{delete-} normally do not save text for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 yanking (though they can still be undone); these are ``deletion''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 Most of the kill commands are primarily for interactive use, and are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 not described here. What we do describe are the functions provided for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 use in writing such commands. You can use these functions to write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 commands for killing text. When you need to delete text for internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 purposes within a Lisp function, you should normally use deletion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 functions, so as not to disturb the kill ring contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 @xref{Deletion}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 Killed text is saved for later yanking in the @dfn{kill ring}. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 is a list that holds a number of recent kills, not just the last text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 kill. We call this a ``ring'' because yanking treats it as having
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 elements in a cyclic order. The list is kept in the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @code{kill-ring}, and can be operated on with the usual functions for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 lists; there are also specialized functions, described in this section,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 that treat it as a ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 Some people think this use of the word ``kill'' is unfortunate, since
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 it refers to operations that specifically @emph{do not} destroy the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 entities ``killed''. This is in sharp contrast to ordinary life, in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 which death is permanent and ``killed'' entities do not come back to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 life. Therefore, other metaphors have been proposed. For example, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 term ``cut ring'' makes sense to people who, in pre-computer days, used
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 scissors and paste to cut up and rearrange manuscripts. However, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 would be difficult to change the terminology now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 * Kill Ring Concepts:: What text looks like in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 * Kill Functions:: Functions that kill text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 * Yank Commands:: Commands that access the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 * Low-Level Kill Ring:: Functions and variables for kill ring access.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 * Internals of Kill Ring:: Variables that hold kill-ring data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 @node Kill Ring Concepts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 @subsection Kill Ring Concepts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 The kill ring records killed text as strings in a list, most recent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 first. A short kill ring, for example, might look like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 ("some text" "a different piece of text" "even older text")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 When the list reaches @code{kill-ring-max} entries in length, adding a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 new entry automatically deletes the last entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 When kill commands are interwoven with other commands, each kill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 command makes a new entry in the kill ring. Multiple kill commands in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 succession build up a single entry in the kill ring, which would be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 yanked as a unit; the second and subsequent consecutive kill commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 add text to the entry made by the first one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 For yanking, one entry in the kill ring is designated the ``front'' of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 the ring. Some yank commands ``rotate'' the ring by designating a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 different element as the ``front.'' But this virtual rotation doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 change the list itself---the most recent entry always comes first in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 @node Kill Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 @subsection Functions for Killing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 @code{kill-region} is the usual subroutine for killing text. Any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 command that calls this function is a ``kill command'' (and should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 probably have @samp{kill} in its name). @code{kill-region} puts the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 newly killed text in a new element at the beginning of the kill ring or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 adds it to the most recent element. It uses the @code{last-command}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 variable to determine whether the previous command was a kill command,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 and if so appends the killed text to the most recent entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
746 @deffn Command kill-region start end &optional verbose
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 This function kills the text in the region defined by @var{start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 @var{end}. The text is deleted but saved in the kill ring, along with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 its text properties. The value is always @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 In an interactive call, @var{start} and @var{end} are point and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 If the buffer is read-only, @code{kill-region} modifies the kill ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 just the same, then signals an error without modifying the buffer. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 is convenient because it lets the user use all the kill commands to copy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 text into the kill ring from a read-only buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 @deffn Command copy-region-as-kill start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 This command saves the region defined by @var{start} and @var{end} on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 the kill ring (including text properties), but does not delete the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 from the buffer. It returns @code{nil}. It also indicates the extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 of the text copied by moving the cursor momentarily, or by displaying a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 message in the echo area.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 The command does not set @code{this-command} to @code{kill-region}, so a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 subsequent kill command does not append to the same kill ring entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 Don't call @code{copy-region-as-kill} in Lisp programs unless you aim to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 support Emacs 18. For Emacs 19, it is better to use @code{kill-new} or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 @code{kill-append} instead. @xref{Low-Level Kill Ring}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 @node Yank Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 @subsection Functions for Yanking
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 @dfn{Yanking} means reinserting an entry of previously killed text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 from the kill ring. The text properties are copied too.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 @deffn Command yank &optional arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 @cindex inserting killed text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 This command inserts before point the text in the first entry in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 kill ring. It positions the mark at the beginning of that text, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 point at the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 If @var{arg} is a list (which occurs interactively when the user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 types @kbd{C-u} with no digits), then @code{yank} inserts the text as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 described above, but puts point before the yanked text and puts the mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 If @var{arg} is a number, then @code{yank} inserts the @var{arg}th most
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 recently killed text---the @var{arg}th element of the kill ring list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 @code{yank} does not alter the contents of the kill ring or rotate it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 It returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 @deffn Command yank-pop arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 This command replaces the just-yanked entry from the kill ring with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 different entry from the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 This is allowed only immediately after a @code{yank} or another
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 @code{yank-pop}. At such a time, the region contains text that was just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 inserted by yanking. @code{yank-pop} deletes that text and inserts in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 its place a different piece of killed text. It does not add the deleted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 text to the kill ring, since it is already in the kill ring somewhere.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 If @var{arg} is @code{nil}, then the replacement text is the previous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 element of the kill ring. If @var{arg} is numeric, the replacement is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 the @var{arg}th previous kill. If @var{arg} is negative, a more recent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 kill is the replacement.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 The sequence of kills in the kill ring wraps around, so that after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 oldest one comes the newest one, and before the newest one goes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 oldest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 The value is always @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 @node Low-Level Kill Ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 @subsection Low-Level Kill Ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 These functions and variables provide access to the kill ring at a lower
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 level, but still convenient for use in Lisp programs. They take care of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 interaction with X Window selections. They do not exist in Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 version 18.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
830 @defun current-kill count &optional do-not-move
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 The function @code{current-kill} rotates the yanking pointer which
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
832 designates the ``front'' of the kill ring by @var{count} places (from newer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 kills to older ones), and returns the text at that place in the ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 If the optional second argument @var{do-not-move} is non-@code{nil},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 then @code{current-kill} doesn't alter the yanking pointer; it just
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
837 returns the @var{count}th kill, counting from the current yanking pointer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
838
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
839 If @var{count} is zero, indicating a request for the latest kill,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 @code{current-kill} calls the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 @code{interprogram-paste-function} (documented below) before consulting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
845 @defun kill-new string &optional replace
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
846 This function makes the text @var{string} the latest entry in the kill
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
847 ring, and sets @code{kill-ring-yank-pointer} to point to it.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
848
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
849 Normally, @var{string} is added to the front of the kill ring as a new
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
850 entry. However, if optional argument @var{replace} is non-@code{nil},
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
851 the entry previously at the front of the kill ring is discarded, and
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
852 @var{string} replaces it.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
853
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
854 This function runs the functions on @code{kill-hooks}, and also invokes
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
855 the value of @code{interprogram-cut-function} (see below).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 @defun kill-append string before-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 This function appends the text @var{string} to the first entry in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 kill ring. Normally @var{string} goes at the end of the entry, but if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 @var{before-p} is non-@code{nil}, it goes at the beginning. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 function also invokes the value of @code{interprogram-cut-function} (see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 below).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 @defvar interprogram-paste-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 This variable provides a way of transferring killed text from other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 programs, when you are using a window system. Its value should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 @code{nil} or a function of no arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 If the value is a function, @code{current-kill} calls it to get the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 ``most recent kill''. If the function returns a non-@code{nil} value,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 then that value is used as the ``most recent kill''. If it returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 @code{nil}, then the first element of @code{kill-ring} is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 The normal use of this hook is to get the X server's primary selection
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 as the most recent kill, even if the selection belongs to another X
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 client. @xref{X Selections}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 @defvar interprogram-cut-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 This variable provides a way of communicating killed text to other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 programs, when you are using a window system. Its value should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 @code{nil} or a function of one argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 If the value is a function, @code{kill-new} and @code{kill-append} call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 it with the new first element of the kill ring as an argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 The normal use of this hook is to set the X server's primary selection
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 to the newly killed text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 @node Internals of Kill Ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 @subsection Internals of the Kill Ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 The variable @code{kill-ring} holds the kill ring contents, in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 form of a list of strings. The most recent kill is always at the front
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
898 of the list.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 The @code{kill-ring-yank-pointer} variable points to a link in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 kill ring list, whose @sc{car} is the text to yank next. We say it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 identifies the ``front'' of the ring. Moving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 @code{kill-ring-yank-pointer} to a different link is called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 @dfn{rotating the kill ring}. We call the kill ring a ``ring'' because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 the functions that move the yank pointer wrap around from the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 list to the beginning, or vice-versa. Rotation of the kill ring is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 virtual; it does not change the value of @code{kill-ring}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 Both @code{kill-ring} and @code{kill-ring-yank-pointer} are Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 variables whose values are normally lists. The word ``pointer'' in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 name of the @code{kill-ring-yank-pointer} indicates that the variable's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 purpose is to identify one element of the list for use by the next yank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 The value of @code{kill-ring-yank-pointer} is always @code{eq} to one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 of the links in the kill ring list. The element it identifies is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 @sc{car} of that link. Kill commands, which change the kill ring, also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 set this variable to the value of @code{kill-ring}. The effect is to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 rotate the ring so that the newly killed text is at the front.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 Here is a diagram that shows the variable @code{kill-ring-yank-pointer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 pointing to the second entry in the kill ring @code{("some text" "a
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
923 different piece of text" "yet older text")}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 kill-ring kill-ring-yank-pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 | ___ ___ ---> ___ ___ ___ ___
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 --> |___|___|------> |___|___|--> |___|___|--> nil
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
931 | | |
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
932 | | |
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
933 | | -->"yet older text"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 | |
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
935 | --> "a different piece of text"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 --> "some text"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 This state of affairs might occur after @kbd{C-y} (@code{yank})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 immediately followed by @kbd{M-y} (@code{yank-pop}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 @defvar kill-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 This variable holds the list of killed text sequences, most recently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 killed first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 @defvar kill-ring-yank-pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 This variable's value indicates which element of the kill ring is at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 ``front'' of the ring for yanking. More precisely, the value is a tail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 of the value of @code{kill-ring}, and its @sc{car} is the kill string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 that @kbd{C-y} should yank.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 @defopt kill-ring-max
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 The value of this variable is the maximum length to which the kill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 ring can grow, before elements are thrown away at the end. The default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 value for @code{kill-ring-max} is 30.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 @node Undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 @section Undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 @cindex redo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 Most buffers have an @dfn{undo list}, which records all changes made
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 to the buffer's text so that they can be undone. (The buffers that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 don't have one are usually special-purpose buffers for which XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 assumes that undoing is not useful.) All the primitives that modify the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 text in the buffer automatically add elements to the front of the undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 list, which is in the variable @code{buffer-undo-list}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 @defvar buffer-undo-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 This variable's value is the undo list of the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 A value of @code{t} disables the recording of undo information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 Here are the kinds of elements an undo list can have:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 @item @var{integer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 This kind of element records a previous value of point. Ordinary cursor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 motion does not get any sort of undo record, but deletion commands use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 these entries to record where point was before the command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
987 @item (@var{start} . @var{end})
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 This kind of element indicates how to delete text that was inserted.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
989 Upon insertion, the text occupied the range @var{start}--@var{end} in the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 @item (@var{text} . @var{position})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 This kind of element indicates how to reinsert text that was deleted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 The deleted text itself is the string @var{text}. The place to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 reinsert it is @code{(abs @var{position})}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 @item (t @var{high} . @var{low})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 This kind of element indicates that an unmodified buffer became
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 modified. The elements @var{high} and @var{low} are two integers, each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 recording 16 bits of the visited file's modification time as of when it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 was previously visited or saved. @code{primitive-undo} uses those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 values to determine whether to mark the buffer as unmodified once again;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 it does so only if the file's modification time matches those numbers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1005 @item (nil @var{property} @var{value} @var{start} . @var{end})
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 This kind of element records a change in a text property.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 Here's how you might undo the change:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 @example
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1010 (put-text-property @var{start} @var{end} @var{property} @var{value})
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 @item @var{position}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 This element indicates where point was at an earlier time. Undoing this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 element sets point to @var{position}. Deletion normally creates an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 element of this kind as well as a reinsertion element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 @item nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 This element is a boundary. The elements between two boundaries are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 called a @dfn{change group}; normally, each change group corresponds to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 one keyboard command, and undo commands normally undo an entire group as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 a unit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 @defun undo-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 This function places a boundary element in the undo list. The undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 command stops at such a boundary, and successive undo commands undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 to earlier and earlier boundaries. This function returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 The editor command loop automatically creates an undo boundary before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 each key sequence is executed. Thus, each undo normally undoes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 effects of one command. Self-inserting input characters are an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 exception. The command loop makes a boundary for the first such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 character; the next 19 consecutive self-inserting input characters do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 not make boundaries, and then the 20th does, and so on as long as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 self-inserting characters continue.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 All buffer modifications add a boundary whenever the previous undoable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 change was made in some other buffer. This way, a command that modifies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 several buffers makes a boundary in each buffer it changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 Calling this function explicitly is useful for splitting the effects of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 a command into more than one unit. For example, @code{query-replace}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 calls @code{undo-boundary} after each replacement, so that the user can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 undo individual replacements one by one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 @defun primitive-undo count list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 This is the basic function for undoing elements of an undo list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 It undoes the first @var{count} elements of @var{list}, returning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 the rest of @var{list}. You could write this function in Lisp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 but it is convenient to have it in C.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 @code{primitive-undo} adds elements to the buffer's undo list when it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 changes the buffer. Undo commands avoid confusion by saving the undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 list value at the beginning of a sequence of undo operations. Then the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 undo operations use and update the saved value. The new elements added
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 by undoing are not part of this saved value, so they don't interfere with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 continuing to undo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 @node Maintaining Undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 @section Maintaining Undo Lists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 This section describes how to enable and disable undo information for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 a given buffer. It also explains how the undo list is truncated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 automatically so it doesn't get too big.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 Recording of undo information in a newly created buffer is normally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 enabled to start with; but if the buffer name starts with a space, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 undo recording is initially disabled. You can explicitly enable or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 disable undo recording with the following two functions, or by setting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 @code{buffer-undo-list} yourself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 @deffn Command buffer-enable-undo &optional buffer-or-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 This command enables recording undo information for buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 @var{buffer-or-name}, so that subsequent changes can be undone. If no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 argument is supplied, then the current buffer is used. This function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 does nothing if undo recording is already enabled in the buffer. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 In an interactive call, @var{buffer-or-name} is the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 You cannot specify any other buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1086 @deffn Command buffer-disable-undo &optional buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1087 @deffnx Command buffer-flush-undo &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 @cindex disable undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 This function discards the undo list of @var{buffer}, and disables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 further recording of undo information. As a result, it is no longer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 possible to undo either previous changes or any subsequent changes. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 the undo list of @var{buffer} is already disabled, this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 has no effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 This function returns @code{nil}. It cannot be called interactively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 The name @code{buffer-flush-undo} is not considered obsolete, but the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 preferred name @code{buffer-disable-undo} is new as of Emacs versions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 19.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1100 @end deffn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 As editing continues, undo lists get longer and longer. To prevent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 them from using up all available memory space, garbage collection trims
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 them back to size limits you can set. (For this purpose, the ``size''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 of an undo list measures the cons cells that make up the list, plus the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 strings of deleted text.) Two variables control the range of acceptable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 sizes: @code{undo-limit} and @code{undo-strong-limit}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 @defvar undo-limit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 This is the soft limit for the acceptable size of an undo list. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 change group at which this size is exceeded is the last one kept.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 @defvar undo-strong-limit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 This is the upper limit for the acceptable size of an undo list. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 change group at which this size is exceeded is discarded itself (along
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 with all older change groups). There is one exception: the very latest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 change group is never discarded no matter how big it is.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 @node Filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 @section Filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 @cindex filling, explicit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 @dfn{Filling} means adjusting the lengths of lines (by moving the line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 breaks) so that they are nearly (but no greater than) a specified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 maximum width. Additionally, lines can be @dfn{justified}, which means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 inserting spaces to make the left and/or right margins line up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 precisely. The width is controlled by the variable @code{fill-column}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 For ease of reading, lines should be no longer than 70 or so columns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 You can use Auto Fill mode (@pxref{Auto Filling}) to fill text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 automatically as you insert it, but changes to existing text may leave
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 it improperly filled. Then you must fill the text explicitly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 Most of the commands in this section return values that are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 meaningful. All the functions that do filling take note of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 left margin, current right margin, and current justification style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (@pxref{Margins}). If the current justification style is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 @code{none}, the filling functions don't actually do anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 Several of the filling functions have an argument @var{justify}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 If it is non-@code{nil}, that requests some kind of justification. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 can be @code{left}, @code{right}, @code{full}, or @code{center}, to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 request a specific style of justification. If it is @code{t}, that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 means to use the current justification style for this part of the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 (see @code{current-justification}, below).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 When you call the filling functions interactively, using a prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 argument implies the value @code{full} for @var{justify}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 @deffn Command fill-paragraph justify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 @cindex filling a paragraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 This command fills the paragraph at or after point. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 @var{justify} is non-@code{nil}, each line is justified as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 It uses the ordinary paragraph motion commands to find paragraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 boundaries. @xref{Paragraphs,,, xemacs, The XEmacs User's Manual}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 @deffn Command fill-region start end &optional justify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 This command fills each of the paragraphs in the region from @var{start}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 to @var{end}. It justifies as well if @var{justify} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 non-@code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 The variable @code{paragraph-separate} controls how to distinguish
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 paragraphs. @xref{Standard Regexps}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 @deffn Command fill-individual-paragraphs start end &optional justify mail-flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 This command fills each paragraph in the region according to its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 individual fill prefix. Thus, if the lines of a paragraph were indented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 with spaces, the filled paragraph will remain indented in the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 fashion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 The first two arguments, @var{start} and @var{end}, are the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 and end of the region to be filled. The third and fourth arguments,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 @var{justify} and @var{mail-flag}, are optional. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 @var{justify} is non-@code{nil}, the paragraphs are justified as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 well as filled. If @var{mail-flag} is non-@code{nil}, it means the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 function is operating on a mail message and therefore should not fill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 the header lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 Ordinarily, @code{fill-individual-paragraphs} regards each change in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 indentation as starting a new paragraph. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 @code{fill-individual-varying-indent} is non-@code{nil}, then only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 separator lines separate paragraphs. That mode can handle indented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 paragraphs with additional indentation on the first line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 @defopt fill-individual-varying-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 This variable alters the action of @code{fill-individual-paragraphs} as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 described above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 @deffn Command fill-region-as-paragraph start end &optional justify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 This command considers a region of text as a paragraph and fills it. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 the region was made up of many paragraphs, the blank lines between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 paragraphs are removed. This function justifies as well as filling when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 @var{justify} is non-@code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 In an interactive call, any prefix argument requests justification.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 In Adaptive Fill mode, which is enabled by default,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 @code{fill-region-as-paragraph} on an indented paragraph when there is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 no fill prefix uses the indentation of the second line of the paragraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 as the fill prefix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 @deffn Command justify-current-line how eop nosqueeze
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 This command inserts spaces between the words of the current line so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 that the line ends exactly at @code{fill-column}. It returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 The argument @var{how}, if non-@code{nil} specifies explicitly the style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 of justification. It can be @code{left}, @code{right}, @code{full},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 @code{center}, or @code{none}. If it is @code{t}, that means to do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 follow specified justification style (see @code{current-justification},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 below). @code{nil} means to do full justification.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 If @var{eop} is non-@code{nil}, that means do left-justification when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 @code{current-justification} specifies full justification. This is used
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 for the last line of a paragraph; even if the paragraph as a whole is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 fully justified, the last line should not be.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 If @var{nosqueeze} is non-@code{nil}, that means do not change interior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 @defopt default-justification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 This variable's value specifies the style of justification to use for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 text that doesn't specify a style with a text property. The possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 values are @code{left}, @code{right}, @code{full}, @code{center}, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 @code{none}. The default value is @code{left}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 @defun current-justification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 This function returns the proper justification style to use for filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 the text around point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 @defvar fill-paragraph-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 This variable provides a way for major modes to override the filling of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 paragraphs. If the value is non-@code{nil}, @code{fill-paragraph} calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 this function to do the work. If the function returns a non-@code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 value, @code{fill-paragraph} assumes the job is done, and immediately
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 returns that value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 The usual use of this feature is to fill comments in programming
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 language modes. If the function needs to fill a paragraph in the usual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 way, it can do so as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 (let ((fill-paragraph-function nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (fill-paragraph arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 @defvar use-hard-newlines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 If this variable is non-@code{nil}, the filling functions do not delete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 newlines that have the @code{hard} text property. These ``hard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 newlines'' act as paragraph separators.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 @node Margins
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 @section Margins for Filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 @defopt fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 This variable specifies a string of text that appears at the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 of normal text lines and should be disregarded when filling them. Any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 line that fails to start with the fill prefix is considered the start of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 a paragraph; so is any line that starts with the fill prefix followed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 additional whitespace. Lines that start with the fill prefix but no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 additional whitespace are ordinary text lines that can be filled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 together. The resulting filled lines also start with the fill prefix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 The fill prefix follows the left margin whitespace, if any.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 @defopt fill-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 This buffer-local variable specifies the maximum width of filled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 lines. Its value should be an integer, which is a number of columns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 All the filling, justification and centering commands are affected by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 this variable, including Auto Fill mode (@pxref{Auto Filling}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 As a practical matter, if you are writing text for other people to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 read, you should set @code{fill-column} to no more than 70. Otherwise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 the line will be too long for people to read comfortably, and this can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 make the text seem clumsy.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 @defvar default-fill-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 The value of this variable is the default value for @code{fill-column} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 buffers that do not override it. This is the same as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 @code{(default-value 'fill-column)}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 The default value for @code{default-fill-column} is 70.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 @deffn Command set-left-margin from to margin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 This sets the @code{left-margin} property on the text from @var{from} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 @var{to} to the value @var{margin}. If Auto Fill mode is enabled, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 command also refills the region to fit the new margin.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 @deffn Command set-right-margin from to margin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 This sets the @code{right-margin} property on the text from @var{from}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 to @var{to} to the value @var{margin}. If Auto Fill mode is enabled,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 this command also refills the region to fit the new margin.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 @defun current-left-margin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 This function returns the proper left margin value to use for filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 the text around point. The value is the sum of the @code{left-margin}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 property of the character at the start of the current line (or zero if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 none), and the value of the variable @code{left-margin}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 @defun current-fill-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 This function returns the proper fill column value to use for filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 the text around point. The value is the value of the @code{fill-column}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 variable, minus the value of the @code{right-margin} property of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 character after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 @deffn Command move-to-left-margin &optional n force
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 This function moves point to the left margin of the current line. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 column moved to is determined by calling the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 @code{current-left-margin}. If the argument @var{n} is non-@code{nil},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 @code{move-to-left-margin} moves forward @var{n}@minus{}1 lines first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 If @var{force} is non-@code{nil}, that says to fix the line's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 indentation if that doesn't match the left margin value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1335 @defun delete-to-left-margin &optional from to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 This function removes left margin indentation from the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 between @var{from} and @var{to}. The amount of indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 to delete is determined by calling @code{current-left-margin}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 In no case does this function delete non-whitespace.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1340
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1341 The arguments @var{from} and @var{to} are optional; the default is the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1342 whole buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 @defun indent-to-left-margin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 This is the default @code{indent-line-function}, used in Fundamental
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 mode, Text mode, etc. Its effect is to adjust the indentation at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 beginning of the current line to the value specified by the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 @code{left-margin}. This may involve either inserting or deleting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 @defvar left-margin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 This variable specifies the base left margin column. In Fundamental
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 mode, @key{LFD} indents to this column. This variable automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 becomes buffer-local when set in any fashion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 @node Auto Filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 @section Auto Filling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 @cindex filling, automatic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 @cindex Auto Fill mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 Auto Fill mode is a minor mode that fills lines automatically as text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 is inserted. This section describes the hook used by Auto Fill mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 For a description of functions that you can call explicitly to fill and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 justify existing text, see @ref{Filling}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 Auto Fill mode also enables the functions that change the margins and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 justification style to refill portions of the text. @xref{Margins}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 @defvar auto-fill-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 The value of this variable should be a function (of no arguments) to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 called after self-inserting a space or a newline. It may be @code{nil},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 in which case nothing special is done in that case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 The value of @code{auto-fill-function} is @code{do-auto-fill} when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 Auto-Fill mode is enabled. That is a function whose sole purpose is to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 implement the usual strategy for breaking a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 @quotation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 In older Emacs versions, this variable was named @code{auto-fill-hook},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 but since it is not called with the standard convention for hooks, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 was renamed to @code{auto-fill-function} in version 19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 @end quotation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 @node Sorting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 @section Sorting Text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 @cindex sorting text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 The sorting functions described in this section all rearrange text in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 a buffer. This is in contrast to the function @code{sort}, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 rearranges the order of the elements of a list (@pxref{Rearrangement}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 The values returned by these functions are not meaningful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 @defun sort-subr reverse nextrecfun endrecfun &optional startkeyfun endkeyfun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 This function is the general text-sorting routine that divides a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 into records and sorts them. Most of the commands in this section use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 To understand how @code{sort-subr} works, consider the whole accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 portion of the buffer as being divided into disjoint pieces called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 @dfn{sort records}. The records may or may not be contiguous; they may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 not overlap. A portion of each sort record (perhaps all of it) is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 designated as the sort key. Sorting rearranges the records in order by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 their sort keys.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 Usually, the records are rearranged in order of ascending sort key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 If the first argument to the @code{sort-subr} function, @var{reverse},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 is non-@code{nil}, the sort records are rearranged in order of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 descending sort key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 The next four arguments to @code{sort-subr} are functions that are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 called to move point across a sort record. They are called many times
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 from within @code{sort-subr}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 @enumerate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 @var{nextrecfun} is called with point at the end of a record. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 function moves point to the start of the next record. The first record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 is assumed to start at the position of point when @code{sort-subr} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 called. Therefore, you should usually move point to the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 the buffer before calling @code{sort-subr}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 This function can indicate there are no more sort records by leaving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 point at the end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 @var{endrecfun} is called with point within a record. It moves point to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 the end of the record.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 @var{startkeyfun} is called to move point from the start of a record to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 the start of the sort key. This argument is optional; if it is omitted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 the whole record is the sort key. If supplied, the function should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 either return a non-@code{nil} value to be used as the sort key, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 return @code{nil} to indicate that the sort key is in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 starting at point. In the latter case, @var{endkeyfun} is called to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 find the end of the sort key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 @var{endkeyfun} is called to move point from the start of the sort key
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 to the end of the sort key. This argument is optional. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 @var{startkeyfun} returns @code{nil} and this argument is omitted (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 @code{nil}), then the sort key extends to the end of the record. There
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 is no need for @var{endkeyfun} if @var{startkeyfun} returns a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 non-@code{nil} value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 @end enumerate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 As an example of @code{sort-subr}, here is the complete function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 definition for @code{sort-lines}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 ;; @r{Note that the first two lines of doc string}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 ;; @r{are effectively one line when viewed by a user.}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1458 (defun sort-lines (reverse start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 "Sort lines in region alphabetically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 Called from a program, there are three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 REVERSE (non-nil means reverse order),
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1464 and START and END (the region to sort)."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (interactive "P\nr")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 (save-restriction
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1467 (narrow-to-region start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 (sort-subr reverse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 'forward-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 'end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 Here @code{forward-line} moves point to the start of the next record,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 and @code{end-of-line} moves point to the end of record. We do not pass
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 the arguments @var{startkeyfun} and @var{endkeyfun}, because the entire
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 record is used as the sort key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 The @code{sort-paragraphs} function is very much the same, except that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 its @code{sort-subr} call looks like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (sort-subr reverse
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1486 (function
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1487 (lambda ()
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 (skip-chars-forward "\n \t\f")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 'forward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 @deffn Command sort-regexp-fields reverse record-regexp key-regexp start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 This command sorts the region between @var{start} and @var{end}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 alphabetically as specified by @var{record-regexp} and @var{key-regexp}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 If @var{reverse} is a negative integer, then sorting is in reverse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 Alphabetical sorting means that two sort keys are compared by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 comparing the first characters of each, the second characters of each,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 and so on. If a mismatch is found, it means that the sort keys are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 unequal; the sort key whose character is less at the point of first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 mismatch is the lesser sort key. The individual characters are compared
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 according to their numerical values. Since Emacs uses the @sc{ascii}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 character set, the ordering in that set determines alphabetical order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 @c version 19 change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 The value of the @var{record-regexp} argument specifies how to divide
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 the buffer into sort records. At the end of each record, a search is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 done for this regular expression, and the text that matches it is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 next record. For example, the regular expression @samp{^.+$}, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 matches lines with at least one character besides a newline, would make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 each such line into a sort record. @xref{Regular Expressions}, for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 description of the syntax and meaning of regular expressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 The value of the @var{key-regexp} argument specifies what part of each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 record is the sort key. The @var{key-regexp} could match the whole
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 record, or only a part. In the latter case, the rest of the record has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 no effect on the sorted order of records, but it is carried along when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 the record moves to its new position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 The @var{key-regexp} argument can refer to the text matched by a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 subexpression of @var{record-regexp}, or it can be a regular expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 on its own.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 If @var{key-regexp} is:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 @item @samp{\@var{digit}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 then the text matched by the @var{digit}th @samp{\(...\)} parenthesis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 grouping in @var{record-regexp} is the sort key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 @item @samp{\&}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 then the whole record is the sort key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 @item a regular expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 then @code{sort-regexp-fields} searches for a match for the regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 expression within the record. If such a match is found, it is the sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 key. If there is no match for @var{key-regexp} within a record then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 that record is ignored, which means its position in the buffer is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 changed. (The other records may move around it.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 For example, if you plan to sort all the lines in the region by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 first word on each line starting with the letter @samp{f}, you should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 set @var{record-regexp} to @samp{^.*$} and set @var{key-regexp} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 @samp{\<f\w*\>}. The resulting expression looks like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (sort-regexp-fields nil "^.*$" "\\<f\\w*\\>"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 (region-beginning)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 If you call @code{sort-regexp-fields} interactively, it prompts for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 @var{record-regexp} and @var{key-regexp} in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 @deffn Command sort-lines reverse start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 This command alphabetically sorts lines in the region between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 @var{start} and @var{end}. If @var{reverse} is non-@code{nil}, the sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 is in reverse order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 @deffn Command sort-paragraphs reverse start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 This command alphabetically sorts paragraphs in the region between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 @var{start} and @var{end}. If @var{reverse} is non-@code{nil}, the sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 is in reverse order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 @deffn Command sort-pages reverse start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 This command alphabetically sorts pages in the region between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 @var{start} and @var{end}. If @var{reverse} is non-@code{nil}, the sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 is in reverse order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 @deffn Command sort-fields field start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 This command sorts lines in the region between @var{start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 @var{end}, comparing them alphabetically by the @var{field}th field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 of each line. Fields are separated by whitespace and numbered starting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 from 1. If @var{field} is negative, sorting is by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 @w{@minus{}@var{field}th} field from the end of the line. This command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 is useful for sorting tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 @deffn Command sort-numeric-fields field start end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 This command sorts lines in the region between @var{start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 @var{end}, comparing them numerically by the @var{field}th field of each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 line. The specified field must contain a number in each line of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 region. Fields are separated by whitespace and numbered starting from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 1. If @var{field} is negative, sorting is by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 @w{@minus{}@var{field}th} field from the end of the line. This command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 is useful for sorting tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1599 @deffn Command sort-columns reverse &optional start end
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1600 This command sorts the lines in the region between @var{start} and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 @var{end}, comparing them alphabetically by a certain range of columns.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1602 The column positions of @var{start} and @var{end} bound the range of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 columns to sort on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 If @var{reverse} is non-@code{nil}, the sort is in reverse order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 One unusual thing about this command is that the entire line
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1608 containing position @var{start}, and the entire line containing position
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 @var{end}, are included in the region sorted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 Note that @code{sort-columns} uses the @code{sort} utility program,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 and so cannot work properly on text containing tab characters. Use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 @kbd{M-x @code{untabify}} to convert tabs to spaces before sorting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 @node Columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 @comment node-name, next, previous, up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 @section Counting Columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 @cindex columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 @cindex counting columns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 @cindex horizontal position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 The column functions convert between a character position (counting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 characters from the beginning of the buffer) and a column position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 (counting screen characters from the beginning of a line).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 A character counts according to the number of columns it occupies on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 the screen. This means control characters count as occupying 2 or 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 columns, depending upon the value of @code{ctl-arrow}, and tabs count as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 occupying a number of columns that depends on the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 @code{tab-width} and on the column where the tab begins. @xref{Usual Display}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 Column number computations ignore the width of the window and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 amount of horizontal scrolling. Consequently, a column value can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 arbitrarily high. The first (or leftmost) column is numbered 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1637 @defun current-column &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 This function returns the horizontal position of point, measured in
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1639 columns, counting from 0 at the left margin.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1640
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1641 This is calculated by adding together the widths of all the displayed
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1642 representations of the character between the start of the previous line
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1643 and point. (e.g. control characters will have a width of 2 or 4, tabs
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1644 will have a variable width.)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1645
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1646 Ignores the finite width of frame displaying the buffer, which means
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1647 that this function may return values greater than
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1648 @code{(frame-width)}.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1649
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1650 Whether the line is visible (if @code{selective-display} is t) has no effect;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1651 however, ^M is treated as end of line when @code{selective-display} is t.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1652
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1653 If @var{buffer} is nil, the current buffer is assumed.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 For an example of using @code{current-column}, see the description of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 @code{count-lines} in @ref{Text Lines}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1659 @defun move-to-column column &optional force buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 This function moves point to @var{column} in the current line. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 calculation of @var{column} takes into account the widths of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 displayed representations of the characters between the start of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 line and point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 If column @var{column} is beyond the end of the line, point moves to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 end of the line. If @var{column} is negative, point moves to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 beginning of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 If it is impossible to move to column @var{column} because that is in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 the middle of a multicolumn character such as a tab, point moves to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 end of that character. However, if @var{force} is non-@code{nil}, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 @var{column} is in the middle of a tab, then @code{move-to-column}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 converts the tab into spaces so that it can move precisely to column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 @var{column}. Other multicolumn characters can cause anomalies despite
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 @var{force}, since there is no way to split them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 The argument @var{force} also has an effect if the line isn't long
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1678 enough to reach column @var{column}; in that case, unless the value of
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1679 @var{force} is the special value @code{coerce}, it says to add
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 whitespace at the end of the line to reach that column.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 2256
diff changeset
1682 If @var{column} is not a non-negative fixnum, an error is signaled.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 The return value is the column number actually moved to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 @node Indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 @section Indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 @cindex indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 The indentation functions are used to examine, move to, and change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 whitespace that is at the beginning of a line. Some of the functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 can also change whitespace elsewhere on a line. Columns and indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 count from zero at the left margin.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 * Primitive Indent:: Functions used to count and insert indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 * Mode-Specific Indent:: Customize indentation for different modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 * Region Indent:: Indent all the lines in a region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 * Relative Indent:: Indent the current line based on previous lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 * Indent Tabs:: Adjustable, typewriter-like tab stops.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 * Motion by Indent:: Move to first non-blank character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 @node Primitive Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 @subsection Indentation Primitives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 This section describes the primitive functions used to count and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 insert indentation. The functions in the following sections use these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 primitives.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1712 @defun current-indentation &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 @comment !!Type Primitive Function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 @comment !!SourceFile indent.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 This function returns the indentation of the current line, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 the horizontal position of the first nonblank character. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 contents are entirely blank, then this is the horizontal position of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 end of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1721 @deffn Command indent-to column &optional minimum buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 @comment !!Type Primitive Function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 @comment !!SourceFile indent.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 This function indents from point with tabs and spaces until @var{column}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 is reached. If @var{minimum} is specified and non-@code{nil}, then at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 least that many spaces are inserted even if this requires going beyond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 @var{column}. Otherwise the function does nothing if point is already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 beyond @var{column}. The value is the column at which the inserted
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1729 indentation ends. If @var{buffer} is @code{nil}, the current buffer is assumed.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 @defopt indent-tabs-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 @comment !!SourceFile indent.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 If this variable is non-@code{nil}, indentation functions can insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 tabs as well as spaces. Otherwise, they insert only spaces. Setting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 this variable automatically makes it local to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 @node Mode-Specific Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 @subsection Indentation Controlled by Major Mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 An important function of each major mode is to customize the @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 key to indent properly for the language being edited. This section
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 describes the mechanism of the @key{TAB} key and how to control it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 The functions in this section return unpredictable values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 @defvar indent-line-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 This variable's value is the function to be used by @key{TAB} (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 various commands) to indent the current line. The command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 @code{indent-according-to-mode} does no more than call this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 In Lisp mode, the value is the symbol @code{lisp-indent-line}; in C
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 mode, @code{c-indent-line}; in Fortran mode, @code{fortran-indent-line}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 In Fundamental mode, Text mode, and many other modes with no standard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 for indentation, the value is @code{indent-to-left-margin} (which is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 default value).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 @deffn Command indent-according-to-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 This command calls the function in @code{indent-line-function} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 indent the current line in a way appropriate for the current major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1764 @deffn Command indent-for-tab-command &optional prefix-arg
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 This command calls the function in @code{indent-line-function} to indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 the current line; except that if that function is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 @code{indent-to-left-margin}, it calls @code{insert-tab} instead. (That
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 is a trivial command that inserts a tab character.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 @deffn Command newline-and-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 @comment !!SourceFile simple.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 This function inserts a newline, then indents the new line (the one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 following the newline just inserted) according to the major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 It does indentation by calling the current @code{indent-line-function}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 In programming language modes, this is the same thing @key{TAB} does,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 but in some text modes, where @key{TAB} inserts a tab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 @code{newline-and-indent} indents to the column specified by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 @code{left-margin}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 @deffn Command reindent-then-newline-and-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 @comment !!SourceFile simple.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 This command reindents the current line, inserts a newline at point,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 and then reindents the new line (the one following the newline just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 inserted).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 This command does indentation on both lines according to the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 major mode, by calling the current value of @code{indent-line-function}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 In programming language modes, this is the same thing @key{TAB} does,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 but in some text modes, where @key{TAB} inserts a tab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 @code{reindent-then-newline-and-indent} indents to the column specified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 by @code{left-margin}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 @node Region Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 @subsection Indenting an Entire Region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 This section describes commands that indent all the lines in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 region. They return unpredictable values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 @deffn Command indent-region start end to-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 This command indents each nonblank line starting between @var{start}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 (inclusive) and @var{end} (exclusive). If @var{to-column} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 @code{nil}, @code{indent-region} indents each nonblank line by calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 the current mode's indentation function, the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 @code{indent-line-function}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 If @var{to-column} is non-@code{nil}, it should be an integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 specifying the number of columns of indentation; then this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 gives each line exactly that much indentation, by either adding or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 deleting whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 If there is a fill prefix, @code{indent-region} indents each line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 by making it start with the fill prefix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 @defvar indent-region-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 The value of this variable is a function that can be used by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 @code{indent-region} as a short cut. You should design the function so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 that it will produce the same results as indenting the lines of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 region one by one, but presumably faster.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 If the value is @code{nil}, there is no short cut, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 @code{indent-region} actually works line by line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 A short-cut function is useful in modes such as C mode and Lisp mode,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 where the @code{indent-line-function} must scan from the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 the function definition: applying it to each line would be quadratic in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 time. The short cut can update the scan information as it moves through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 the lines indenting them; this takes linear time. In a mode where
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 indenting a line individually is fast, there is no need for a short cut.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 @code{indent-region} with a non-@code{nil} argument @var{to-column} has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 a different meaning and does not use this variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 @deffn Command indent-rigidly start end count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 @comment !!SourceFile indent.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 This command indents all lines starting between @var{start}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 (inclusive) and @var{end} (exclusive) sideways by @var{count} columns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 This ``preserves the shape'' of the affected region, moving it as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 rigid unit. Consequently, this command is useful not only for indenting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 regions of unindented text, but also for indenting regions of formatted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 For example, if @var{count} is 3, this command adds 3 columns of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 indentation to each of the lines beginning in the region specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 In Mail mode, @kbd{C-c C-y} (@code{mail-yank-original}) uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 @code{indent-rigidly} to indent the text copied from the message being
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 replied to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1856 @deffn Command indent-code-rigidly start end columns &optional nochange-regexp
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 This is like @code{indent-rigidly}, except that it doesn't alter lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 that start within strings or comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 In addition, it doesn't alter a line if @var{nochange-regexp} matches at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 the beginning of the line (if @var{nochange-regexp} is non-@code{nil}).
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1862 @end deffn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 @node Relative Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 @subsection Indentation Relative to Previous Lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 This section describes two commands that indent the current line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 based on the contents of previous lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 @deffn Command indent-relative &optional unindented-ok
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 This command inserts whitespace at point, extending to the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 column as the next @dfn{indent point} of the previous nonblank line. An
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 indent point is a non-whitespace character following whitespace. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 next indent point is the first one at a column greater than the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 column of point. For example, if point is underneath and to the left of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 the first non-blank character of a line of text, it moves to that column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 by inserting whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 If the previous nonblank line has no next indent point (i.e., none at a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 great enough column position), @code{indent-relative} either does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 nothing (if @var{unindented-ok} is non-@code{nil}) or calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 @code{tab-to-tab-stop}. Thus, if point is underneath and to the right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 of the last column of a short line of text, this command ordinarily
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 moves point to the next tab stop by inserting whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 The return value of @code{indent-relative} is unpredictable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 In the following example, point is at the beginning of the second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 line:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 This line is indented twelve spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 @point{}The quick brown fox jumped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 Evaluation of the expression @code{(indent-relative nil)} produces the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 following:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 This line is indented twelve spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 @point{}The quick brown fox jumped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 In this example, point is between the @samp{m} and @samp{p} of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 @samp{jumped}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 This line is indented twelve spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 The quick brown fox jum@point{}ped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 Evaluation of the expression @code{(indent-relative nil)} produces the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 following:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 This line is indented twelve spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 The quick brown fox jum @point{}ped.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 @deffn Command indent-relative-maybe
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 @comment !!SourceFile indent.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 This command indents the current line like the previous nonblank line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 It calls @code{indent-relative} with @code{t} as the @var{unindented-ok}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 argument. The return value is unpredictable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 If the previous nonblank line has no indent points beyond the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 column, this command does nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 @node Indent Tabs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 @subsection Adjustable ``Tab Stops''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 @cindex tabs stops for indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 This section explains the mechanism for user-specified ``tab stops''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 and the mechanisms that use and set them. The name ``tab stops'' is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 used because the feature is similar to that of the tab stops on a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 typewriter. The feature works by inserting an appropriate number of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 spaces and tab characters to reach the next tab stop column; it does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 affect the display of tab characters in the buffer (@pxref{Usual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 Display}). Note that the @key{TAB} character as input uses this tab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 stop feature only in a few major modes, such as Text mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 @deffn Command tab-to-tab-stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 This command inserts spaces or tabs up to the next tab stop column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 defined by @code{tab-stop-list}. It searches the list for an element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 greater than the current column number, and uses that element as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 column to indent to. It does nothing if no such element is found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 @defopt tab-stop-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 This variable is the list of tab stop columns used by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 @code{tab-to-tab-stops}. The elements should be integers in increasing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 order. The tab stop columns need not be evenly spaced.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 Use @kbd{M-x edit-tab-stops} to edit the location of tab stops
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 interactively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 @node Motion by Indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 @subsection Indentation-Based Motion Commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 These commands, primarily for interactive use, act based on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 indentation in the text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
1976 @deffn Command back-to-indentation
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 @comment !!SourceFile simple.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 This command moves point to the first non-whitespace character in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 current line (which is the line in which point is located). It returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 @deffn Command backward-to-indentation arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 @comment !!SourceFile simple.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 This command moves point backward @var{arg} lines and then to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 first nonblank character on that line. It returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 @deffn Command forward-to-indentation arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 @comment !!SourceFile simple.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 This command moves point forward @var{arg} lines and then to the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 nonblank character on that line. It returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 @node Case Changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 @section Case Changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 @cindex case changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 The case change commands described here work on text in the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 buffer. @xref{Character Case}, for case conversion commands that work
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 on strings and characters. @xref{Case Tables}, for how to customize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 which characters are upper or lower case and how to convert them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2004 @deffn Command capitalize-region start end &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 This function capitalizes all words in the region defined by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 @var{start} and @var{end}. To capitalize means to convert each word's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 first character to upper case and convert the rest of each word to lower
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 case. The function returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 If one end of the region is in the middle of a word, the part of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 word within the region is treated as an entire word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 When @code{capitalize-region} is called interactively, @var{start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 @var{end} are point and the mark, with the smallest first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 This is the contents of the 5th foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 (capitalize-region 1 44)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 This Is The Contents Of The 5th Foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2034 @deffn Command downcase-region start end &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 This function converts all of the letters in the region defined by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 @var{start} and @var{end} to lower case. The function returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 When @code{downcase-region} is called interactively, @var{start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 @var{end} are point and the mark, with the smallest first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2043 @deffn Command upcase-region start end &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 This function converts all of the letters in the region defined by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 @var{start} and @var{end} to upper case. The function returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 When @code{upcase-region} is called interactively, @var{start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 @var{end} are point and the mark, with the smallest first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2052 @deffn Command capitalize-word count &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 This function capitalizes @var{count} words after point, moving point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 over as it does. To capitalize means to convert each word's first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 character to upper case and convert the rest of each word to lower case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 If @var{count} is negative, the function capitalizes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 @minus{}@var{count} previous words but does not move point. The value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 If point is in the middle of a word, the part of the word before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 is ignored when moving forward. The rest is treated as an entire word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 When @code{capitalize-word} is called interactively, @var{count} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 set to the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2067 @deffn Command downcase-word count &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 This function converts the @var{count} words after point to all lower
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 case, moving point over as it does. If @var{count} is negative, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 converts the @minus{}@var{count} previous words but does not move point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 The value is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 When @code{downcase-word} is called interactively, @var{count} is set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 to the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2077 @deffn Command upcase-word count &optional buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 This function converts the @var{count} words after point to all upper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 case, moving point over as it does. If @var{count} is negative, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 converts the @minus{}@var{count} previous words but does not move point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 The value is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 When @code{upcase-word} is called interactively, @var{count} is set to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 @node Text Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 @section Text Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 @cindex text properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 @cindex attributes of text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 @cindex properties of text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 Text properties are an alternative interface to extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 (@pxref{Extents}), and are built on top of them. They are useful when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 you want to view textual properties as being attached to the characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 themselves rather than to intervals of characters. The text property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 interface is compatible with FSF Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 Each character position in a buffer or a string can have a @dfn{text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 property list}, much like the property list of a symbol (@pxref{Property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 Lists}). The properties belong to a particular character at a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 particular place, such as, the letter @samp{T} at the beginning of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 sentence or the first @samp{o} in @samp{foo}---if the same character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 occurs in two different places, the two occurrences generally have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 different properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 Each property has a name and a value. Both of these can be any Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 object, but the name is normally a symbol. The usual way to access the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 property list is to specify a name and ask what value corresponds to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 @ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 If a character has a @code{category} property, we call it the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 @dfn{category} of the character. It should be a symbol. The properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 of the symbol serve as defaults for the properties of the character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 Note that FSF Emacs also looks at the @code{category} property to find
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 defaults for text properties. We consider this too bogus to implement.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 Copying text between strings and buffers preserves the properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 along with the characters; this includes such diverse functions as
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
2121 @code{subseq}, @code{insert}, and @code{buffer-substring}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 * Examining Properties:: Looking at the properties of one character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 * Changing Properties:: Setting the properties of a range of text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 * Property Search:: Searching for where a property changes value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 * Special Properties:: Particular properties with special meanings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 * Saving Properties:: Saving text properties in files, and reading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 them back.
2256
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2130 * Fields:: Emacs-compatible text fields.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 @node Examining Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 @subsection Examining Text Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 The simplest way to examine text properties is to ask for the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 a particular property of a particular character. For that, use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 @code{get-text-property}. Use @code{text-properties-at} to get the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 entire property list of a character. @xref{Property Search}, for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 functions to examine the properties of a number of characters at once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 These functions handle both strings and buffers. (Keep in mind that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 positions in a string start from 0, whereas positions in a buffer start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 from 1.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2146 @defun get-text-property pos prop &optional object at-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 This function returns the value of the @var{prop} property of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 character after position @var{pos} in @var{object} (a buffer or string).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 The argument @var{object} is optional and defaults to the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 @ignore @c Bogus as hell!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 If there is no @var{prop} property strictly speaking, but the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 has a category that is a symbol, then @code{get-text-property} returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 the @var{prop} property of that symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2158 @defun get-char-property pos prop &optional object at-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 This function is like @code{get-text-property}, except that it checks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 all extents, not just text-property extents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 @ignore Does not apply in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 The argument @var{object} may be a string, a buffer, or a window. If it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 is a window, then the buffer displayed in that window is used for text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 properties and overlays, but only the overlays active for that window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 are considered. If @var{object} is a buffer, then all overlays in that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 buffer are considered, as well as text properties. If @var{object} is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 string, only text properties are considered, since strings never have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 overlays.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 @defun text-properties-at position &optional object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 This function returns the entire property list of the character at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 @var{position} in the string or buffer @var{object}. If @var{object} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 @code{nil}, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 @defvar default-text-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 This variable holds a property list giving default values for text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 properties. Whenever a character does not specify a value for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 property, the value stored in this list is used instead. Here is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 an example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 (setq default-text-properties '(foo 69))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 ;; @r{Make sure character 1 has no properties of its own.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 (set-text-properties 1 2 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 ;; @r{What we get, when we ask, is the default value.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (get-text-property 1 'foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 @result{} 69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 @node Changing Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 @subsection Changing Text Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 The primitives for changing properties apply to a specified range of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 text. The function @code{set-text-properties} (see end of section) sets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 the entire property list of the text in that range; more often, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 useful to add, change, or delete just certain properties specified by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 Since text properties are considered part of the buffer's contents, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 can affect how the buffer looks on the screen, any change in the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 properties is considered a buffer modification. Buffer text property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 changes are undoable (@pxref{Undo}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 @defun put-text-property start end prop value &optional object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 This function sets the @var{prop} property to @var{value} for the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 between @var{start} and @var{end} in the string or buffer @var{object}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 If @var{object} is @code{nil}, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 @defun add-text-properties start end props &optional object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 This function modifies the text properties for the text between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 @var{start} and @var{end} in the string or buffer @var{object}. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 @var{object} is @code{nil}, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 The argument @var{props} specifies which properties to change. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 should have the form of a property list (@pxref{Property Lists}): a list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 whose elements include the property names followed alternately by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 corresponding values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 The return value is @code{t} if the function actually changed some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 property's value; @code{nil} otherwise (if @var{props} is @code{nil} or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 its values agree with those in the text).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 For example, here is how to set the @code{comment} and @code{face}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 properties of a range of text:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 (add-text-properties @var{start} @var{end}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 '(comment t face highlight))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 @defun remove-text-properties start end props &optional object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 This function deletes specified text properties from the text between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 @var{start} and @var{end} in the string or buffer @var{object}. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 @var{object} is @code{nil}, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 The argument @var{props} specifies which properties to delete. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 should have the form of a property list (@pxref{Property Lists}): a list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 whose elements are property names alternating with corresponding values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 But only the names matter---the values that accompany them are ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 For example, here's how to remove the @code{face} property.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 (remove-text-properties @var{start} @var{end} '(face nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 The return value is @code{t} if the function actually changed some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 property's value; @code{nil} otherwise (if @var{props} is @code{nil} or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 if no character in the specified text had any of those properties).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 @defun set-text-properties start end props &optional object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 This function completely replaces the text property list for the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 between @var{start} and @var{end} in the string or buffer @var{object}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 If @var{object} is @code{nil}, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 The argument @var{props} is the new property list. It should be a list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 whose elements are property names alternating with corresponding values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 After @code{set-text-properties} returns, all the characters in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 specified range have identical properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 If @var{props} is @code{nil}, the effect is to get rid of all properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 from the specified range of text. Here's an example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 (set-text-properties @var{start} @var{end} nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 See also the function @code{buffer-substring-without-properties}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 (@pxref{Buffer Contents}) which copies text from the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 but does not copy its properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 @node Property Search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 @subsection Property Search Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 In typical use of text properties, most of the time several or many
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 consecutive characters have the same value for a property. Rather than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 writing your programs to examine characters one by one, it is much
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 faster to process chunks of text that have the same property value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 Here are functions you can use to do this. They use @code{eq} for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 comparing property values. In all cases, @var{object} defaults to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 For high performance, it's very important to use the @var{limit}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 argument to these functions, especially the ones that search for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 single property---otherwise, they may spend a long time scanning to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 end of the buffer, if the property you are interested in does not change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 Remember that a position is always between two characters; the position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 returned by these functions is between two characters with different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 @defun next-property-change pos &optional object limit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 The function scans the text forward from position @var{pos} in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 string or buffer @var{object} till it finds a change in some text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 property, then returns the position of the change. In other words, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 returns the position of the first character beyond @var{pos} whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 properties are not identical to those of the character just after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 @var{pos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 If @var{limit} is non-@code{nil}, then the scan ends at position
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2311 @var{limit}. If there is no property change before that point,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 @code{next-property-change} returns @var{limit}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 The value is @code{nil} if the properties remain unchanged all the way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 to the end of @var{object} and @var{limit} is @code{nil}. If the value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 is non-@code{nil}, it is a position greater than or equal to @var{pos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 The value equals @var{pos} only when @var{limit} equals @var{pos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 Here is an example of how to scan the buffer by chunks of text within
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 which all properties are constant:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 (let ((plist (text-properties-at (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 (next-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 (or (next-property-change (point) (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 @r{Process text from point to @var{next-change}@dots{}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 (goto-char next-change)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 @defun next-single-property-change pos prop &optional object limit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 The function scans the text forward from position @var{pos} in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 string or buffer @var{object} till it finds a change in the @var{prop}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 property, then returns the position of the change. In other words, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 returns the position of the first character beyond @var{pos} whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 @var{prop} property differs from that of the character just after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 @var{pos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 If @var{limit} is non-@code{nil}, then the scan ends at position
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2342 @var{limit}. If there is no property change before that point,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 @code{next-single-property-change} returns @var{limit}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 The value is @code{nil} if the property remains unchanged all the way to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 the end of @var{object} and @var{limit} is @code{nil}. If the value is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 non-@code{nil}, it is a position greater than or equal to @var{pos}; it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 equals @var{pos} only if @var{limit} equals @var{pos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 @defun previous-property-change pos &optional object limit
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2352 This is like @code{next-property-change}, but scans backward from @var{pos}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 instead of forward. If the value is non-@code{nil}, it is a position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 less than or equal to @var{pos}; it equals @var{pos} only if @var{limit}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 equals @var{pos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 @defun previous-single-property-change pos prop &optional object limit
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2359 This is like @code{next-single-property-change}, but scans backward from
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 @var{pos} instead of forward. If the value is non-@code{nil}, it is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 position less than or equal to @var{pos}; it equals @var{pos} only if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 @var{limit} equals @var{pos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 @defun text-property-any start end prop value &optional object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 This function returns non-@code{nil} if at least one character between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 @var{start} and @var{end} has a property @var{prop} whose value is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 @var{value}. More precisely, it returns the position of the first such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 character. Otherwise, it returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 The optional fifth argument, @var{object}, specifies the string or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 buffer to scan. Positions are relative to @var{object}. The default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 for @var{object} is the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 @defun text-property-not-all start end prop value &optional object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 This function returns non-@code{nil} if at least one character between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 @var{start} and @var{end} has a property @var{prop} whose value differs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 from @var{value}. More precisely, it returns the position of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 first such character. Otherwise, it returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 The optional fifth argument, @var{object}, specifies the string or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 buffer to scan. Positions are relative to @var{object}. The default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 for @var{object} is the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 @node Special Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 @subsection Properties with Special Meanings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 The predefined properties are the same as those for extents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 @xref{Extent Properties}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 @ignore Changed in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 (deleted section describing FSF Emacs special text properties)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 @node Saving Properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 @subsection Saving Text Properties in Files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 @cindex text properties in files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 @cindex saving text properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 You can save text properties in files, and restore text properties
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2403 when inserting the files, using these two hooks:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 @defvar write-region-annotate-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 This variable's value is a list of functions for @code{write-region} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 run to encode text properties in some fashion as annotations to the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 being written in the file. @xref{Writing to Files}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 Each function in the list is called with two arguments: the start and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 end of the region to be written. These functions should not alter the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 contents of the buffer. Instead, they should return lists indicating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 annotations to write in the file in addition to the text in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 Each function should return a list of elements of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 @code{(@var{position} . @var{string})}, where @var{position} is an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 integer specifying the relative position in the text to be written, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 @var{string} is the annotation to add there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 Each list returned by one of these functions must be already sorted in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 increasing order by @var{position}. If there is more than one function,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 @code{write-region} merges the lists destructively into one sorted list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 When @code{write-region} actually writes the text from the buffer to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 file, it intermixes the specified annotations at the corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 positions. All this takes place without modifying the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 @defvar after-insert-file-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 This variable holds a list of functions for @code{insert-file-contents}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 to call after inserting a file's contents. These functions should scan
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 the inserted text for annotations, and convert them to the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 properties they stand for.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 Each function receives one argument, the length of the inserted text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 point indicates the start of that text. The function should scan that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 text for annotations, delete them, and create the text properties that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 the annotations specify. The function should return the updated length
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 of the inserted text, as it stands after those changes. The value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 returned by one function becomes the argument to the next function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 These functions should always return with point at the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 the inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 The intended use of @code{after-insert-file-functions} is for converting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 some sort of textual annotations into actual text properties. But other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 uses may be possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 We invite users to write Lisp programs to store and retrieve text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 properties in files, using these hooks, and thus to experiment with
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2453 various data formats and find good ones. Eventually we hope users
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 will produce good, general extensions we can install in Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 We suggest not trying to handle arbitrary Lisp objects as property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 names or property values---because a program that general is probably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 difficult to write, and slow. Instead, choose a set of possible data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 types that are reasonably flexible, and not too hard to encode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 @xref{Format Conversion}, for a related feature.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462
2256
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2463 @node Fields
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2464 @subsection Fields
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2465 @cindex text fields
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2466 @cindex fields
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2467
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2468 Emacs supplies a notion of a @emph{text field}, which is a region of
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2469 text where every character has the same value of the @code{field}
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2470 property. It is used to identify regions of a buffer used for
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2471 communicating with an external process, for example. XEmacs supplies a
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2472 compatible interface. In XEmacs, the @code{field} property can be set
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2473 as either an extent property or a text property, mirroring the Emacs
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2474 capability of using either overlays or text properties.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2475
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2476 The field manipulating functions take a buffer position as the
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2477 field-identifying argument, defaulting to point. This really means the
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2478 field containing that buffer position. Consecutive buffer positions
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2479 with no @code{field} property are considered an ``empty'' field. There
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2480 is some ambiguity when a specified buffer position falls at the very
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2481 beginning or the very end of a field: does it belong to the preceding or
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2482 the following field? The answer depends on the openness or closedness
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2483 of the corresponding extents (@pxref{Extent Endpoints}). A buffer
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2484 position corresponds to the field whose property would be inherited by a
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2485 character inserted at that position. If the buffer position is between
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2486 an end-open and a start-open extent, then it corresponds to an empty
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2487 field at that position, since an inserted character will belong to
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2488 neither extent.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2489
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2490 @defvar inhibit-field-text-motion
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2491 This variable controls whether the text motion commands notice fields or
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2492 not. When it is nil (the default), commands such as beginning-of-line
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2493 will try to move only within fields.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2494 @end defvar
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2495
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2496 @defun make-field value from to &optional buffer
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2497 There is no Emacs counterpart to this function. The default open and
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2498 closedness of extents in XEmacs is opposite to the default for Emacs
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2499 overlays. Hence, fields based on extents in XEmacs behave differently
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2500 from the equivalent fields based on overlays in Emacs. This function
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2501 creates a field with value @var{value} over the region @var{from} to
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2502 @var{to} in @var{buffer}, which defaults to the current buffer, with the
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2503 default Emacs open and closedness.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2504 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2505
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2506 @defun find-field &optional pos merge-at-boundary beg-limit end-limit
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2507 There is no (Lisp-visible) Emacs counterpart to this function. It is
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2508 the workhorse for the other functions. It returns a dotted pair
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2509 @code{(start . stop)} holding the endpoints of the field matching a
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2510 specification. If @var{pos} is non-@code{nil}, it specifies a buffer
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2511 position whose enclosing field should be found; otherwise, the value of
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2512 point is used.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2513
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2514 If @var{merge-at-boundary} is non-@code{nil}, then two changes are made
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2515 to the search algorithm. First, if @var{pos} is at the very first
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2516 position of a field, then the beginning of the previous field is
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2517 returned instead of the beginning of @var{pos}'s field. Second, if the
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2518 value of the @code{field} property at @var{pos} is the symbol
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2519 @code{boundary}, then the beginning of the field before the boundary
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2520 field and the end of the field after the boundary field are returned.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2521
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2522 If @var{beg-limit} is a buffer position, and the start position that
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2523 would be returned is less than @var{beg-limit}, then @var{beg-limit} is
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2524 returned instead. Likewise, if @var{end-limit} is a buffer position,
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2525 and the stop position that would be returned is greater than
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2526 @var{end-limit}, then @var{end-limit} is returned instead.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2527 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2528
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2529 @defun delete-field &optional pos
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2530 Delete the text of the field at @var{pos}.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2531 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2532
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2533 @defun field-string &optional pos
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2534 Return the contents of the field at @var{pos} as a string.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2535 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2536
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2537 @defun field-string-no-properties &optional pos
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2538 Return the contents of the field at @var{pos} as a string, without text
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2539 properties.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2540 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2541
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2542 @defun field-beginning &optional pos escape-from-edge limit
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2543 Return the beginning of the field at @var{pos}. If
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2544 @var{escape-from-edge} is non-nil and @var{pos} is at the beginning of a
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2545 field, then the beginning of the field that ends at @var{pos} is
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2546 returned instead. If @var{limit} is a buffer position and the returned
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2547 value would be less than @var{limit}, then @var{limit} is returned
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2548 instead.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2549 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2550
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2551 @defun field-end &optional pos escape-from-edge limit
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2552 Return the end of the field at @var{pos}. If @var{escape-from-edge} is
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2553 non-nil and @var{pos} is at the end of a field, then the end of the
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2554 field that begins at @var{pos} is returned instead. If @var{limit} is a
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2555 buffer position and the returned value would be greater than
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2556 @var{limit}, then @var{limit} is returned instead.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2557 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2558
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2559 @defun constrain-to-field new-pos old-pos &optional escape-from-edge only-in-line inhibit-capture-property
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2560 Return the position closest to @var{new-pos} that is in the same field
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2561 as @var{old-pos}. If @var{new-pos} is @code{nil}, then the value of
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2562 point is used instead @emph{and} point is set to the value that is
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2563 returned.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2564
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2565 If @var{escape-from-edge} is non-@code{nil} and @var{old-pos} is at the
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2566 boundary of two fields, then the two adjacent fields are considered one
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2567 field. Furthermore, if @var{new-pos} is in a field whose @code{field}
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2568 property is the symbol @code{boundary}, then the preceding field, the
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2569 boundary field, and the following field are considered one field.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2570
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2571 If @var{only-in-line} is non-@code{nil} and the returned position would
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2572 be on a different line than @var{new-pos}, return @var{new-pos} instead.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2573
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2574 If @var{inhibit-capture-property} is non-@code{nil} and the character at
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2575 @var{old-pos} has a property of the same name as the value of
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2576 @var{inhibit-capture-property}, then all field boundaries are ignored;
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2577 i.e., @var{new-pos} is returned.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2578
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2579 If @var{inhibit-field-text-motion} is non-@code{nil}, then all field
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2580 boundaries are ignored and this function always returns @var{new-pos}.
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2581 @end defun
6ffd69eff907 [xemacs-hg @ 2004-09-08 17:40:14 by james]
james
parents: 901
diff changeset
2582
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 @node Substitution
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 @section Substituting for a Character Code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 The following functions replace characters within a specified region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 based on their character codes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 @defun subst-char-in-region start end old-char new-char &optional noundo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 @cindex replace characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 This function replaces all occurrences of the character @var{old-char}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 with the character @var{new-char} in the region of the current buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 defined by @var{start} and @var{end}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 @cindex Outline mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 @cindex undo avoidance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 If @var{noundo} is non-@code{nil}, then @code{subst-char-in-region} does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 not record the change for undo and does not mark the buffer as modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 This feature is used for controlling selective display (@pxref{Selective
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 Display}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 @code{subst-char-in-region} does not move point and returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 This is the contents of the buffer before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 (subst-char-in-region 1 20 ?i ?X)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 ThXs Xs the contents of the buffer before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 @defun translate-region start end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 This function applies a translation table to the characters in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 buffer between positions @var{start} and @var{end}. The translation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 table @var{table} can be either a string, a vector, or a char-table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2628 If @var{table} is a string, its @var{n}th element is the mapping for the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 character with code @var{n}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 If @var{table} is a vector, its @var{n}th element is the mapping for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 character with code @var{n}. Legal mappings are characters, strings, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 @code{nil} (meaning don't replace.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 If @var{table} is a char-table, its elements describe the mapping
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 between characters and their replacements. The char-table should be of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 type @code{char} or @code{generic}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 When the @var{table} is a string or vector and its length is less than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 the total number of characters (256 without Mule), any characters with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 codes larger than the length of @var{table} are not altered by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 translation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 The return value of @code{translate-region} is the number of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 characters that were actually changed by the translation. This does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 not count characters that were mapped into themselves in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 translation table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 @strong{NOTE}: Prior to XEmacs 21.2, the @var{table} argument was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 allowed only to be a string. This is still the case in FSF Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 The following example creates a char-table that is passed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 @code{translate-region}, which translates character @samp{a} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 @samp{the letter a}, removes character @samp{b}, and translates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 character @samp{c} to newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 Here is a sentence in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 (let ((table (make-char-table 'generic)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 (put-char-table ?a "the letter a" table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 (put-char-table ?b "" table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 (put-char-table ?c ?\n table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 (translate-region (point-min) (point-max) table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 @result{} 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 Here is the letter a senten
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 e in the uffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 @node Registers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 @section Registers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 @cindex registers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 A register is a sort of variable used in XEmacs editing that can hold a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 marker, a string, a rectangle, a window configuration (of one frame), or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 a frame configuration (of all frames). Each register is named by a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 single character. All characters, including control and meta characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 (but with the exception of @kbd{C-g}), can be used to name registers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 Thus, there are 255 possible registers. A register is designated in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 Emacs Lisp by a character that is its name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 The functions in this section return unpredictable values unless
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 otherwise stated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 @c Will change in version 19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 @defvar register-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 This variable is an alist of elements of the form @code{(@var{name} .
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 @var{contents})}. Normally, there is one element for each XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 register that has been used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 2256
diff changeset
2701 The object @var{name} is a character identifying the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 register. The object @var{contents} is a string, marker, or list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 representing the register contents. A string represents text stored in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 the register. A marker represents a position. A list represents a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 rectangle; its elements are strings, one per line of the rectangle.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2708 @defun get-register register
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 This function returns the contents of the register
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2710 @var{register}, or @code{nil} if it has no contents.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2713 @defun set-register register value
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2714 This function sets the contents of register @var{register} to @var{value}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 A register can be set to any value, but the other register functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 expect only certain data types. The return value is @var{value}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2719 @deffn Command view-register register
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2720 This command displays what is contained in register @var{register}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 @ignore
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2724 @deffn Command point-to-register register
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 This command stores both the current location of point and the current
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2726 buffer in register @var{register} as a marker.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2729 @deffn Command jump-to-register register
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2730 @deffnx Command register-to-point register
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 @comment !!SourceFile register.el
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2732 This command restores the status recorded in register @var{register}.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2733
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2734 If @var{register} contains a marker, it moves point to the position
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2735 stored in the marker. Since both the buffer and the location within the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2736 buffer are stored by the @code{point-to-register} function, this command
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2737 can switch you to another buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2738
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2739 If @var{register} contains a window configuration or a frame configuration.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 @code{jump-to-register} restores that configuration.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2744 @deffn Command insert-register register &optional beforep
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2745 This command inserts contents of register @var{register} into the current
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 Normally, this command puts point before the inserted text, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 mark after it. However, if the optional second argument @var{beforep}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 is non-@code{nil}, it puts the mark before and point after.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 You can pass a non-@code{nil} second argument @var{beforep} to this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 function interactively by supplying any prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 If the register contains a rectangle, then the rectangle is inserted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 with its upper left corner at point. This means that text is inserted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 in the current line and underneath it on successive lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 If the register contains something other than saved text (a string) or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 a rectangle (a list), currently useless things happen. This may be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 changed in the future.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 @ignore
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2764 @deffn Command copy-to-register register start end &optional delete-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 This command copies the region from @var{start} to @var{end} into
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2766 register @var{register}. If @var{delete-flag} is non-@code{nil}, it deletes
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 the region from the buffer after copying it into the register.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2770 @deffn Command prepend-to-register register start end &optional delete-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 This command prepends the region from @var{start} to @var{end} into
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2772 register @var{register}. If @var{delete-flag} is non-@code{nil}, it deletes
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 the region from the buffer after copying it to the register.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2776 @deffn Command append-to-register register start end &optional delete-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 This command appends the region from @var{start} to @var{end} to the
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2778 text already in register @var{register}. If @var{delete-flag} is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 non-@code{nil}, it deletes the region from the buffer after copying it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 to the register.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2783 @deffn Command copy-rectangle-to-register register start end &optional delete-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 This command copies a rectangular region from @var{start} to @var{end}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2785 into register @var{register}. If @var{delete-flag} is non-@code{nil}, it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 deletes the region from the buffer after copying it to the register.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2789 @deffn Command window-configuration-to-register register
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 This function stores the window configuration of the selected frame in
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2791 register @var{register}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2794 @deffn Command frame-configuration-to-register register
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 This function stores the current frame configuration in register
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2796 @var{register}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 @node Transposition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 @section Transposition of Text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 This subroutine is used by the transposition commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 @defun transpose-regions start1 end1 start2 end2 &optional leave-markers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 This function exchanges two nonoverlapping portions of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 Arguments @var{start1} and @var{end1} specify the bounds of one portion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 and arguments @var{start2} and @var{end2} specify the bounds of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 other portion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 Normally, @code{transpose-regions} relocates markers with the transposed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 text; a marker previously positioned within one of the two transposed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 portions moves along with that portion, thus remaining between the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 two characters in their new position. However, if @var{leave-markers}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 is non-@code{nil}, @code{transpose-regions} does not do this---it leaves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 all markers unrelocated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 @node Change Hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 @section Change Hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 @cindex change hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 @cindex hooks for text changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 These hook variables let you arrange to take notice of all changes in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 all buffers (or in a particular buffer, if you make them buffer-local).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 @ignore Not in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 See also @ref{Special Properties}, for how to detect changes to specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 parts of the text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 The functions you use in these hooks should save and restore the match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 data if they do anything that uses regular expressions; otherwise, they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 will interfere in bizarre ways with the editing operations that call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 Buffer changes made while executing the following hooks don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 themselves cause any change hooks to be invoked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 @defvar before-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 This variable holds a list of a functions to call before any buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 modification. Each function gets two arguments, the beginning and end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 of the region that is about to change, represented as integers. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 buffer that is about to change is always the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 @defvar after-change-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 This variable holds a list of a functions to call after any buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 modification. Each function receives three arguments: the beginning and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 end of the region just changed, and the length of the text that existed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 before the change. (To get the current length, subtract the region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 beginning from the region end.) All three arguments are integers. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 buffer that's about to change is always the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 @defvar before-change-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 This obsolete variable holds one function to call before any buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 modification (or @code{nil} for no function). It is called just like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 the functions in @code{before-change-functions}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 @defvar after-change-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 This obsolete variable holds one function to call after any buffer modification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 (or @code{nil} for no function). It is called just like the functions in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 @code{after-change-functions}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 @defvar first-change-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 This variable is a normal hook that is run whenever a buffer is changed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 that was previously in the unmodified state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 @node Transformations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 @section Textual transformations---MD5 and base64 support
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 @cindex MD5 digests
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 @cindex base64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 Some textual operations inherently require examining each character in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 turn, and performing arithmetic operations on them. Such operations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 can, of course, be implemented in Emacs Lisp, but tend to be very slow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 for large portions of text or data. This is why some of them are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 implemented in C, with an appropriate interface for Lisp programmers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 Examples of algorithms thus provided are MD5 and base64 support.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 MD5 is an algorithm for calculating message digests, as described in
901
37e56e920ac5 [xemacs-hg @ 2002-07-05 20:35:47 by adrian]
adrian
parents: 446
diff changeset
2885 rfc1321. Given a message of arbitrary length, MD5 produces a 128-bit
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 ``fingerprint'' (``message digest'') corresponding to that message. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 is considered computationally infeasible to produce two messages having
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 the same MD5 digest, or to produce a message having a prespecified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 target digest. MD5 is used heavily by various authentication schemes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 Emacs Lisp interface to MD5 consists of a single function @code{md5}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2893 @defun md5 object &optional start end coding noerror
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 This function returns the MD5 message digest of @var{object}, a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 or string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 Optional arguments @var{start} and @var{end} denote positions for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 computing the digest of a portion of @var{object}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2900 The optional @var{coding} argument specifies the coding system the text
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2901 is to be represented in while computing the digest. If unspecified, it
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2902 defaults to the current format of the data, or is guessed.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2903
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2904 If @var{noerror} is non-@code{nil}, silently assume binary coding if the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2905 guesswork fails. Normally, an error is signaled in such case.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2906
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2907 @var{coding} and @var{noerror} arguments are meaningful only in XEmacsen
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2908 with file-coding or Mule support. Otherwise, they are ignored. Some
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2909 examples of usage:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 ;; @r{Calculate the digest of the entire buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 (md5 (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 @result{} "8842b04362899b1cda8d2d126dc11712"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 ;; @r{Calculate the digest of the current line}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (md5 (current-buffer) (point-at-bol) (point-at-eol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 @result{} "60614d21e9dee27dfdb01fa4e30d6d00"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 ;; @r{Calculate the digest of your name and email address}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 (md5 (concat (format "%s <%s>" (user-full-name) user-mail-address)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 @result{} "0a2188c40fd38922d941fe6032fce516"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 Base64 is a portable encoding for arbitrary sequences of octets, in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 form that need not be readable by humans. It uses a 65-character subset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 of US-ASCII, as described in rfc2045. Base64 is used by MIME to encode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 binary bodies, and to encode binary characters in message headers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 The Lisp interface to base64 consists of four functions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2939 @deffn Command base64-encode-region start end &optional no-line-break
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2940 This function encodes the region between @var{start} and @var{end} of the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2941 current buffer to base64 format. This means that the original region is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 deleted, and replaced with its base64 equivalent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 Normally, encoded base64 output is multi-line, with 76-character lines.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2945 If @var{no-line-break} is non-@code{nil}, newlines will not be inserted,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 resulting in single-line output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 Mule note: you should make sure that you convert the multibyte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 characters (those that do not fit into 0--255 range) to something else,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 because they cannot be meaningfully converted to base64. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 @code{base64-encode-region} encounters such characters, it will signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 @code{base64-encode-region} returns the length of the encoded text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 ;; @r{Encode the whole buffer in base64}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 (base64-encode-region (point-min) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 The function can also be used interactively, in which case it works on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 the currently active region.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2965 @end deffn
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2966
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2967 @defun base64-encode-string string &optional no-line-break
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 This function encodes @var{string} to base64, and returns the encoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2971 Normally, encoded base64 output is multi-line, with 76-character lines.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2972 If @var{no-line-break} is non-@code{nil}, newlines will not be inserted,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2973 resulting in single-line output.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2974
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 For Mule, the same considerations apply as for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 @code{base64-encode-region}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 (base64-encode-string "fubar")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 @result{} "ZnViYXI="
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2986 @deffn Command base64-decode-region start end
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2987 This function decodes the region between @var{start} and @var{end} of the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 current buffer. The region should be in base64 encoding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 If the region was decoded correctly, @code{base64-decode-region} returns
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
2991 the length of the decoded region. If the decoding failed, @code{nil} is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 ;; @r{Decode a base64 buffer, and replace it with the decoded version}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 (base64-decode-region (point-min) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 @end example
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 434
diff changeset
3000 @end deffn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 @defun base64-decode-string string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 This function decodes @var{string} to base64, and returns the decoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 string. @var{string} should be valid base64-encoded text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 If encoding was not possible, @code{nil} is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 (base64-decode-string "ZnViYXI=")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 @result{} "fubar"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 (base64-decode-string "totally bogus")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 @end defun