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