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