Initial git import
[sxemacs] / info / lispref / extents.texi
1 @c -*-texinfo-*-
2 @c This is part of the SXEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 @c Copyright (C) 1996 Ben Wing.
5 @c Copyright (C) 2005 Sebastian Freundt <hroptatyr@sxemacs.org>
6 @c See the file lispref.texi for copying conditions.
7 @setfilename ../../info/extents.info
8
9 @node Extents, Specifiers, Abbrevs, top
10 @chapter Extents
11 @cindex extent
12
13   An @dfn{extent} is somewhat the generalisation of a marker object
14 within the text.
15
16   To be precise, An extent is a region of text (a start position and 
17 an end position) that is displayed in a particular face and can have 
18 certain other properties such as being read-only.  Extents can overlap 
19 each other.  SXEmacs efficiently handles buffers with large numbers of
20 extents in them.
21
22 @defun extentp object
23 This returns @code{t} if @var{object} is an extent.
24 @end defun
25
26 @menu
27 * Intro to Extents::       Extents are regions over a buffer or string.
28 * Creating and Modifying Extents::
29                            Basic extent functions.
30 * Extent Endpoints::       Accessing and setting the bounds of an extent.
31 * Finding Extents::        Determining which extents are in an object.
32 * Mapping Over Extents::   More sophisticated functions for extent scanning.
33 * Extent Properties::      Extents have built-in and user-definable properties.
34 * Detached Extents::       Extents that are not in a buffer.
35 * Extent Parents::         Inheriting properties from another extent.
36 * Duplicable Extents::     Extents can be marked to be copied into strings.
37 * Extents and Events::     Extents can interact with the keyboard and mouse.
38 * Atomic Extents::         Treating a block of text as a single entity.
39 @end menu
40
41
42 @node Intro to Extents
43 @section Introduction to Extents
44 @cindex extent priority
45 @cindex priority of an extent
46
47   An extent is a region of text within a buffer or string that has
48 certain properties associated with it.  The properties of an extent
49 primarily affect the way the text contained in the extent is displayed.
50 Extents can freely overlap each other in a buffer or string.  Extents
51 are invisible to functions that merely examine the text of a buffer or
52 string.
53
54   @emph{Please note:} An alternative way to add properties to a buffer or
55 string is to use text properties.  @xref{Text Properties}.
56
57   An extent is logically a Lisp object consisting of a start position,
58 an end position, a buffer or string to which these positions refer, and
59 a property list.  As text is inserted into a buffer, the start and end
60 positions of the extent are automatically adjusted as necessary to keep
61 the extent referring to the same text in the buffer.  If text is
62 inserted at the boundary of an extent, the extent's @code{start-open}
63 and @code{end-open} properties control whether the text is included as
64 part of the extent.  If the text bounded by an extent is deleted, the
65 extent becomes @dfn{detached}; its start and end positions are no longer
66 meaningful, but it maintains all its other properties and can later be
67 reinserted into a buffer. (None of these considerations apply to strings,
68 because text cannot be inserted into or deleted from a string.)
69
70   Each extent has a face or list of faces associated with it, which
71 controls the way in which the text bounded by the extent is displayed.
72 If an extent's face is @code{nil} or its properties are partially
73 undefined, the corresponding properties from the default face for the
74 frame is used.  If two or more extents overlap, or if a list of more
75 than one face is specified for a particular extent, the corresponding
76 faces are merged to determine the text's displayed properties.  Every
77 extent has a @dfn{priority} that determines which face takes precedence
78 if the faces conflict. (If two extents have the same priority, the one
79 that comes later in the display order takes precedence.  @xref{Extent
80 Endpoints, display order}.) Higher-numbered priority values correspond
81 to a higher priority, and priority values can be negative.  Every extent
82 is created with a priority of 0, but this can be changed with
83 @code{set-extent-priority}.  Within a single extent with a list of faces,
84 faces earlier in the list have a higher priority than faces later in
85 the list.
86
87   Extents can be set to respond specially to key and mouse events within
88 the extent.  An extent's @code{keymap} property controls the effect of
89 key and mouse strokes within the extent's text, and the @code{mouse-face}
90 property controls whether the extent is highlighted when the mouse moves
91 over it.  @xref{Extents and Events}.
92
93   An extent can optionally have a @dfn{begin-glyph} or @dfn{end-glyph}
94 associated with it.  A begin-glyph or end-glyph is a pixmap or string
95 that will be displayed either at the start or end of an extent or in the
96 margin of the line that the start or end of the extent lies in,
97 depending on the extent's layout policy.  Begin-glyphs and end-glyphs
98 are used to implement annotations, and you should use the annotation API
99 functions in preference to the lower-level extent functions.  For more
100 information, @xref{Annotations}.
101
102   If an extent has its @code{detachable} property set, it will become
103 @dfn{detached} (i.e. no longer in the buffer) when all its text is
104 deleted.  Otherwise, it will simply shrink down to zero-length and
105 sit in the same place in the buffer.  By default, the @code{detachable}
106 property is set on newly-created extents.  @xref{Detached Extents}.
107
108   If an extent has its @code{duplicable} property set, it will be
109 remembered when a string is created from text bounded by the extent.
110 When the string is re-inserted into a buffer, the extent will also
111 be re-inserted.  This mechanism is used in the kill, yank, and undo
112 commands.  @xref{Duplicable Extents}.
113
114
115 @node Creating and Modifying Extents
116 @section Creating and Modifying Extents
117
118 @defun make-extent from to &optional buffer-or-string
119 This function makes an extent for the range [@var{from}, @var{to}) in
120 @var{buffer-or-string} (a buffer or string).  @var{buffer-or-string}
121 defaults to the current buffer.  Insertions at point @var{to} will be
122 outside of the extent; insertions at @var{from} will be inside the
123 extent, causing the extent to grow (@pxref{Extent Endpoints}).  This is
124 the same way that markers behave.  The extent is initially detached if
125 both @var{from} and @var{to} are @code{nil}, and in this case
126 @var{buffer-or-string} defaults to @code{nil}, meaning the extent is in
127 no buffer or string (@pxref{Detached Extents}).
128 @end defun
129
130 @defun delete-extent extent
131 This function removes @var{extent} from its buffer and destroys it.
132 This does not modify the buffer's text, only its display properties.
133 The extent cannot be used thereafter.  To remove an extent in such
134 a way that it can be re-inserted later, use @code{detach-extent}.
135 @xref{Detached Extents}.
136 @end defun
137
138 @defun extent-object extent
139 This function returns the buffer or string that @var{extent} is in.  If
140 the return value is @code{nil}, this means that the extent is detached;
141 however, a detached extent will not necessarily return a value of
142 @code{nil}.
143 @end defun
144
145 @defun extent-live-p object
146 This function returns @code{t} if @var{object} is an extent that has not
147 been deleted, and @code{nil} otherwise.
148 @end defun
149
150
151 @node Extent Endpoints
152 @section Extent Endpoints
153 @cindex extent endpoint
154 @cindex extent start position
155 @cindex extent end position
156 @cindex zero-length extent
157 @cindex display order
158 @cindex extent order
159 @cindex order of extents
160
161   Every extent has a start position and an end position, and logically
162 affects the characters between those positions.  Normally the start and
163 end positions must both be valid positions in the extent's buffer or
164 string.  However, both endpoints can be @code{nil}, meaning the extent
165 is detached.  @xref{Detached Extents}.
166
167   Whether the extent overlaps its endpoints is governed by its
168 @code{start-open} and @code{end-open} properties.  Insertion of a
169 character at a closed endpoint will expand the extent to include that
170 character; insertion at an open endpoint will not.  Similarly, functions
171 such as @code{extent-at} that scan over all extents overlapping a
172 particular position will include extents with a closed endpoint at that
173 position, but not extents with an open endpoint.
174
175   Note that the @code{start-closed} and @code{end-closed} properties are
176 equivalent to @code{start-open} and @code{end-open} with the opposite
177 sense.
178
179   Both endpoints can be equal, in which case the extent includes no
180 characters but still exists in the buffer or string.  Zero-length
181 extents are used to represent annotations (@pxref{Annotations}) and can
182 be used as a more powerful form of a marker.  Deletion of all the
183 characters in an extent may or may not result in a zero-length extent;
184 this depends on the @code{detachable} property (@pxref{Detached
185 Extents}).
186
187   Insertion at the position of a zero-length extent expands the extent
188 if both endpoints are closed; goes before the extent if it has the
189 @code{start-open} property; and goes after the extent if it has the
190 @code{end-open} property.  Zero-length extents with both the
191 @code{start-open} and @code{end-open} properties are treated as if their
192 starting point were closed.
193
194   Deletion of a character on a side of a zero-length extent whose
195 corresponding endpoint is closed causes the extent to be detached if its
196 @code{detachable} property is set; if the corresponding endpoint is
197 open, the extent remains in the buffer, moving as necessary.
198
199   Extents are ordered within a buffer or string by increasing start
200 position, and then by decreasing end position (this is called the
201 @dfn{display order}).
202
203 @defun extent-start-position extent
204 This function returns the start position of @var{extent}.
205 @end defun
206
207 @defun extent-end-position extent
208 This function returns the end position of @var{extent}.
209 @end defun
210
211 @defun extent-length extent
212 This function returns the length of @var{extent} in characters.  If
213 the extent is detached, this returns @code{0}.  If the extent is not
214 detached, this is equivalent to
215 @example
216 (- (extent-end-position @var{extent}) (extent-start-position @var{extent}))
217 @end example
218 @end defun
219
220 @defun set-extent-endpoints extent start end &optional buffer-or-string
221 This function sets the start and end position of @var{extent} to
222 @var{start} and @var{end}.  If both are @code{nil}, this is equivalent
223 to @code{detach-extent}.
224
225 @var{buffer-or-string} specifies the new buffer or string that the
226 extent should be in, and defaults to @var{extent}'s buffer or
227 string. (If @code{nil}, and @var{extent} is in no buffer and no string,
228 it defaults to the current buffer.)
229
230 See documentation on @code{detach-extent} for a discussion of undo
231 recording.
232 @end defun
233
234
235 @node Finding Extents
236 @section Finding Extents
237 @cindex extents, locating
238
239   The following functions provide a simple way of determining the
240 extents in a buffer or string.  A number of more sophisticated
241 primitives for mapping over the extents in a range of a buffer or string
242 are also provided (@pxref{Mapping Over Extents}).  When reading through
243 this section, keep in mind the way that extents are ordered
244 (@pxref{Extent Endpoints}).
245
246 @defun extent-list &optional buffer-or-string from to flags property value
247 This function returns a list of the extents in @var{buffer-or-string}.
248 @var{buffer-or-string} defaults to the current buffer if omitted.
249 @var{from} and @var{to} can be used to limit the range over which
250 extents are returned; if omitted, all extents in the buffer or string
251 are returned.
252
253   More specifically, if a range is specified using @var{from} and
254 @var{to}, only extents that overlap the range (i.e. begin or end inside
255 of the range) are included in the list.  @var{from} and @var{to} default
256 to the beginning and end of @var{buffer-or-string}, respectively.
257
258   @var{flags} controls how end cases are treated.  For a discussion of
259 this, and exactly what ``overlap'' means, see @code{map-extents}.
260
261 The optional arguments @var{property} and @var{value} can be used to
262 further restrict which extents are returned.  They have the same meaning
263 as for @code{map-extents}.
264
265 If you want to map a function over the extents in a buffer or string,
266 consider using @code{map-extents} or @code{mapcar-extents} instead.
267
268 See also the function @code{extents-at}.
269 @end defun
270
271   Functions that create extents must be prepared for the possibility
272 that there are other extents in the same area, created by other
273 functions.  To deal with this, functions typically mark their own
274 extents by setting a particular property on them.  The following
275 function makes it easier to locate those extents.
276
277 @defun extent-at pos &optional object property before at-flag
278 This function finds the ``smallest'' extent (i.e., the last one in the
279 display order) at (i.e., overlapping) @var{pos} in @var{object} (a
280 buffer or string) having @var{property} set.  @var{object} defaults to
281 the current buffer.  @var{property} defaults to @code{nil}, meaning that
282 any extent will do.  Returns @code{nil} if there is no matching extent
283 at @var{pos}.  If the fourth argument @var{before} is not @code{nil}, it
284 must be an extent; any returned extent will precede that extent.  This
285 feature allows @code{extent-at} to be used by a loop over extents.
286
287 @var{at-flag} controls how end cases are handled (i.e. what ``at''
288 really means), and should be one of:
289
290 @table @code
291 @item nil
292 @item after
293 An extent is at @var{pos} if it covers the character after @var{pos}.
294 This is consistent with the way that text properties work.
295 @item before
296 An extent is at @var{pos} if it covers the character before @var{pos}.
297 @item at
298 An extent is at @var{pos} if it overlaps or abuts @var{pos}.  This
299 includes all zero-length extents at @var{pos}.
300 @end table
301
302   Note that in all cases, the start-openness and end-openness of the
303 extents considered is ignored.  If you want to pay attention to those
304 properties, you should use @code{map-extents}, which gives you more
305 control.
306 @end defun
307
308   The following low-level functions are provided for explicitly
309 traversing the extents in a buffer according to the display order.
310 These functions are mostly intended for debugging---in normal
311 operation, you should probably use @code{mapcar-extents} or
312 @code{map-extents}, or loop using the @var{before} argument to
313 @code{extent-at}, rather than creating a loop using @code{next-extent}.
314
315 @defun next-extent extent
316 Given an extent @var{extent}, this function returns the next extent in
317 the buffer or string's display order.  If @var{extent} is a buffer or
318 string, this returns the first extent in the buffer or string.
319 @end defun
320
321 @defun previous-extent extent
322 Given an extent @var{extent}, this function returns the previous extent
323 in the buffer or string's display order.  If @var{extent} is a buffer or
324 string, this returns the last extent in the buffer or string.
325 @end defun
326
327
328 @node Mapping Over Extents
329 @section Mapping Over Extents
330 @cindex extents, mapping
331
332   The most basic and general function for mapping over extents is called
333 @code{map-extents}.  You should read through the definition of this
334 function to familiarize yourself with the concepts and optional
335 arguments involved.  However, in practice you may find it more
336 convenient to use the function @code{mapcar-extents} or to create a loop
337 using the @code{before} argument to @code{extent-at} (@pxref{Finding
338 Extents}).
339
340 @defun map-extents function &optional object from to maparg flags property value
341   This function maps @var{function} over the extents which overlap a
342 region in @var{object}.  @var{object} is normally a buffer or string but
343 could be an extent (see below).  The region is normally bounded by
344 [@var{from}, @var{to}) (i.e. the beginning of the region is closed and
345 the end of the region is open), but this can be changed with the
346 @var{flags} argument (see below for a complete discussion).
347
348   @var{function} is called with the arguments (extent, @var{maparg}).
349 The arguments @var{object}, @var{from}, @var{to}, @var{maparg}, and
350 @var{flags} are all optional and default to the current buffer, the
351 beginning of @var{object}, the end of @var{object}, @code{nil}, and
352 @code{nil}, respectively.  @code{map-extents} returns the first
353 non-@code{nil} result produced by @var{function}, and no more calls to
354 @var{function} are made after it returns non-@code{nil}.
355
356   If @var{object} is an extent, @var{from} and @var{to} default to the
357 extent's endpoints, and the mapping omits that extent and its
358 predecessors.  This feature supports restarting a loop based on
359 @code{map-extents}.  Note: @var{object} must be attached to a buffer or
360 string, and the mapping is done over that buffer or string.
361
362   An extent overlaps the region if there is any point in the extent that
363 is also in the region. (For the purpose of overlap, zero-length extents
364 and regions are treated as closed on both ends regardless of their
365 endpoints' specified open/closedness.) Note that the endpoints of an
366 extent or region are considered to be in that extent or region if and
367 only if the corresponding end is closed.  For example, the extent [5,7]
368 overlaps the region [2,5] because 5 is in both the extent and the
369 region.  However, (5,7] does not overlap [2,5] because 5 is not in the
370 extent, and neither [5,7] nor (5,7] overlaps the region [2,5) because 5
371 is not in the region.
372
373   The optional @var{flags} can be a symbol or a list of one or more
374 symbols, modifying the behavior of @code{map-extents}.  Allowed symbols
375 are:
376
377 @table @code
378 @item end-closed
379 The region's end is closed.
380
381 @item start-open
382 The region's start is open.
383
384 @item all-extents-closed
385 Treat all extents as closed on both ends for the purpose of determining
386 whether they overlap the region, irrespective of their actual open- or
387 closedness.
388 @item all-extents-open
389 Treat all extents as open on both ends.
390 @item all-extents-closed-open
391 Treat all extents as start-closed, end-open.
392 @item all-extents-open-closed
393 Treat all extents as start-open, end-closed.
394
395 @item start-in-region
396 In addition to the above conditions for extent overlap, the extent's
397 start position must lie within the specified region.  Note that, for
398 this condition, open start positions are treated as if 0.5 was added to
399 the endpoint's value, and open end positions are treated as if 0.5 was
400 subtracted from the endpoint's value.
401 @item end-in-region
402 The extent's end position must lie within the region.
403 @item start-and-end-in-region
404 Both the extent's start and end positions must lie within the region.
405 @item start-or-end-in-region
406 Either the extent's start or end position must lie within the region.
407
408 @item negate-in-region
409 The condition specified by a @code{*-in-region} flag must @emph{not}
410 hold for the extent to be considered.
411 @end table
412
413   At most one of @code{all-extents-closed}, @code{all-extents-open},
414 @code{all-extents-closed-open}, and @code{all-extents-open-closed} may
415 be specified.
416
417   At most one of @code{start-in-region}, @code{end-in-region},
418 @code{start-and-end-in-region}, and @code{start-or-end-in-region} may be
419 specified.
420
421   If optional arg @var{property} is non-@code{nil}, only extents with
422 that property set on them will be visited.  If optional arg @var{value}
423 is non-@code{nil}, only extents whose value for that property is
424 @code{eq} to @var{value} will be visited.
425 @end defun
426
427   If you want to map over extents and accumulate a list of results,
428 the following function may be more convenient than @code{map-extents}.
429
430 @defun mapcar-extents function &optional predicate buffer-or-string from to flags property value
431 This function applies @var{function} to all extents which overlap a
432 region in @var{buffer-or-string}.  The region is delimited by
433 @var{from} and @var{to}.  @var{function} is called with one argument,
434 the extent.  A list of the values returned by @var{function} is
435 returned.  An optional @var{predicate} may be used to further limit the
436 extents over which @var{function} is mapped.  The optional arguments
437 @var{flags}, @var{property}, and @var{value} may also be used to control
438 the extents passed to @var{predicate} or @var{function}, and have the
439 same meaning as in @code{map-extents}.
440 @end defun
441
442 @defun map-extent-children function &optional object from to maparg flags property value
443 This function is similar to @code{map-extents}, but differs in that:
444
445 @itemize @bullet
446 @item
447 It only visits extents which start in the given region.
448 @item
449 After visiting an extent @var{e}, it skips all other extents which start
450 inside @var{e} but end before @var{e}'s end.
451 @end itemize
452
453 Thus, this function may be used to walk a tree of extents in a buffer:
454 @example
455 (defun walk-extents (buffer &optional ignore)
456   (map-extent-children 'walk-extents buffer))
457 @end example
458 @end defun
459
460 @defun extent-in-region-p extent &optional from to flags
461 This function returns @code{t} if @code{map-extents} would visit
462 @var{extent} if called with the given arguments.
463 @end defun
464
465
466 @node Extent Properties
467 @section Properties of Extents
468 @cindex extent property
469 @cindex property of an extent
470
471   Each extent has a property list associating property names with
472 values.  Some property names have predefined meanings, and can usually
473 only assume particular values.  Assigning other values to such a
474 property either cause the value to be converted into a legal value
475 (e.g., assigning anything but @code{nil} to a Boolean property will
476 cause the value of @code{t} to be assigned to the property) or will
477 cause an error.  Property names without predefined meanings can be
478 assigned any value.  An undefined property is equivalent to a property
479 with a value of @code{nil}, or with a particular default value in the
480 case of properties with predefined meanings.  Note that, when an extent
481 is created, the @code{end-open} and @code{detachable} properties are set
482 on it.
483
484   If an extent has a parent, all of its properties actually derive
485 from that parent (or from the root ancestor if the parent in turn
486 has a parent), and setting a property of the extent actually sets
487 that property on the parent.  @xref{Extent Parents}.
488
489 @defun extent-property extent property &optional default
490 This function returns @var{extent}'s value for @var{property}, or
491 @var{default} if no such property exists.
492 @end defun
493
494 @defun extent-properties extent
495 This function returns a list of all of @var{extent}'s properties that do
496 not have the value of @code{nil} (or the default value, for properties
497 with predefined meanings).
498 @end defun
499
500 @defun set-extent-property extent property value
501 This function sets @var{property} to @var{value} in @var{extent}. (If
502 @var{property} has a predefined meaning, only certain values are
503 allowed, and some values may be converted to others before being
504 stored.)
505 @end defun
506
507 @defun set-extent-properties extent plist
508 Change some properties of @var{extent}.  @var{plist} is a property
509 list.  This is useful to change many extent properties at once.
510 @end defun
511
512 The following table lists the properties with predefined meanings, along
513 with their allowable values.
514
515 @table @code
516 @item detached
517 (Boolean) Whether the extent is detached.   Setting this is the same
518 as calling @code{detach-extent}.  @xref{Detached Extents}.
519
520 @item destroyed
521 (Boolean) Whether the extent has been deleted.  Setting this is the same
522 as calling @code{delete-extent}.
523
524 @item priority
525 (integer) The extent's redisplay priority.  Defaults to 0.  @xref{Intro
526 to Extents, priority}.  This property can also be set with
527 @code{set-extent-priority} and accessed with @code{extent-priority}.
528
529 @item start-open
530 (Boolean) Whether the start position of the extent is open, meaning that
531 characters inserted at that position go outside of the extent.
532 @xref{Extent Endpoints}.
533
534 @item start-closed
535 (Boolean) Same as @code{start-open} but with the opposite sense.  Setting
536 this property clears @code{start-open} and vice-versa.
537
538 @item end-open
539 (Boolean) Whether the end position of the extent is open, meaning that
540 characters inserted at that position go outside of the extent.  This is
541 @code{t} by default.
542 @xref{Extent Endpoints}.
543
544 @item end-closed
545 (Boolean) Same as @code{end-open} but with the opposite sense.  Setting
546 this property clears @code{end-open} and vice-versa.
547
548 @item read-only
549 (Boolean) Whether text within this extent will be unmodifiable.
550
551 @item face
552 (face, face name, list of faces or face names, or @code{nil}) The face
553 in which to display the extent's text.  This property can also be set
554 with @code{set-extent-face} and accessed with @code{extent-face}.
555 Note that if a list of faces is specified, the faces are merged together,
556 with faces earlier in the list having priority over faces later in the
557 list.
558
559 @item mouse-face
560 (face, face name, list of faces or face names, or @code{nil}) The face
561 used to display the extent when the mouse moves over it.  This property
562 can also be set with @code{set-extent-mouse-face} and accessed with
563 @code{extent-mouse-face}.  Note that if a list of faces is specified,
564 the faces are merged together, with faces earlier in the list having
565 priority over faces later in the list.  @xref{Extents and Events}.
566
567 @item pointer
568 (pointer glyph)  The glyph used as the pointer when the mouse moves over
569 the extent.  This takes precedence over the @code{text-pointer-glyph}
570 and @code{nontext-pointer-glyph} variables.  If for any reason this
571 glyph is an invalid pointer, the standard glyphs will be used as
572 fallbacks.  @xref{External Glyphs}.
573
574 @item detachable
575 (Boolean) Whether this extent becomes detached when all of the text it
576 covers is deleted.  This is @code{t} by default.  @xref{Detached
577 Extents}.
578
579 @item duplicable
580 (Boolean) Whether this extent should be copied into strings, so that
581 kill, yank, and undo commands will restore or copy it.  @xref{Duplicable
582 Extents}.
583
584 @item unique
585 (Boolean) Meaningful only in conjunction with @code{duplicable}.
586 When this is set, there may be only one instance of
587 this extent attached at a time.  @xref{Duplicable Extents}.
588
589 @item invisible
590 (Boolean) If @code{t}, text under this extent will not be displayed --
591 it will look as if the text and the begin-glyph is not there at all.
592 The end-glyph will still be displayed.
593
594 @item keymap
595 (keymap or @code{nil}) This keymap is consulted for mouse clicks on this
596 extent or keypresses made while @code{point} is within the extent.
597 @xref{Extents and Events}.
598
599 @item copy-function
600 This is a hook that is run when a duplicable extent is about to be
601 copied from a buffer to a string (or the kill ring).  @xref{Duplicable
602 Extents}.
603
604 @item paste-function
605 This is a hook that is run when a duplicable extent is about to be
606 copied from a string (or the kill ring) into a buffer.  @xref{Duplicable
607 Extents}.
608
609 @item begin-glyph
610 (glyph or @code{nil}) This extent's begin glyph.
611 @xref{Annotations}.
612
613 @item end-glyph
614 (glyph or @code{nil}) This extent's end glyph.
615 @xref{Annotations}.
616
617 @item begin-glyph-layout
618 (@code{text}, @code{whitespace}, @code{inside-margin}, or
619 @code{outside-margin}) The layout policy for this extent's begin glyph.
620 Defaults to @code{text}.  @xref{Annotations}.
621
622 @item end-glyph-layout
623 (@code{text}, @code{whitespace}, @code{inside-margin}, or
624 @code{outside-margin}) The layout policy for this extent's end glyph.
625 Defaults to @code{text}.  @xref{Annotations}.
626
627 @item initial-redisplay-function
628 (any funcallable object) The function to be called the first time (a
629 part of) the extent is redisplayed.  It will be called with the extent
630 as its argument.
631
632 This is used by @code{lazy-shot} to implement lazy font-locking.  The
633 functionality is still experimental, and may change without further
634 notice.
635 @end table
636
637 The following convenience functions are provided for accessing
638 particular properties of an extent.
639
640 @defun extent-face extent
641 This function returns the @code{face} property of @var{extent}.  This
642 might also return a list of face names.  Do not modify this list
643 directly!  Instead, use @code{set-extent-face}.
644
645 Note that you can use @code{eq} to compare lists of faces as returned
646 by @code{extent-face}.  In other words, if you set the face of two
647 different extents to two lists that are @code{equal} but not @code{eq},
648 then the return value of @code{extent-face} on the two extents will
649 return the identical list.
650 @end defun
651
652 @defun extent-mouse-face extent
653 This function returns the @code{mouse-face} property of @var{extent}.
654 This might also return a list of face names.  Do not modify this list
655 directly!  Instead, use @code{set-extent-mouse-face}.
656
657 Note that you can use @code{eq} to compare lists of faces as returned
658 by @code{extent-mouse-face}, just like for @code{extent-face}.
659 @end defun
660
661 @defun extent-priority extent
662 This function returns the @code{priority} property of @var{extent}.
663 @end defun
664
665 @defun extent-keymap extent
666 This function returns the @code{keymap} property of @var{extent}.
667 @end defun
668
669 @defun extent-begin-glyph-layout extent
670 This function returns the @code{begin-glyph-layout} property of
671 @var{extent}, i.e. the layout policy associated with the @var{extent}'s
672 begin glyph.
673 @end defun
674
675 @defun extent-end-glyph-layout extent
676 This function returns the @code{end-glyph-layout} property of
677 @var{extent}, i.e. the layout policy associated with the @var{extent}'s
678 end glyph.
679 @end defun
680
681 @defun extent-begin-glyph extent
682 This function returns the @code{begin-glyph} property of @var{extent},
683 i.e. the glyph object displayed at the beginning of @var{extent}.  If
684 there is none, @code{nil} is returned.
685 @end defun
686
687 @defun extent-end-glyph extent
688 This function returns the @code{end-glyph} property of @var{extent},
689 i.e. the glyph object displayed at the end of @var{extent}.  If
690 there is none, @code{nil} is returned.
691 @end defun
692
693 The following convenience functions are provided for setting particular
694 properties of an extent.
695
696 @defun set-extent-priority extent priority
697 This function sets the @code{priority} property of @var{extent} to
698 @var{priority}.
699 @end defun
700
701 @defun set-extent-face extent face
702 This function sets the @code{face} property of @var{extent} to
703 @var{face}.
704 @end defun
705
706 @defun set-extent-mouse-face extent face
707 This function sets the @code{mouse-face} property of @var{extent} to
708 @var{face}.
709 @end defun
710
711 @defun set-extent-keymap extent keymap
712 This function sets the @code{keymap} property of @var{extent} to
713 @var{keymap}.  @var{keymap} must be either a keymap object, or
714 @code{nil}.
715 @end defun
716
717 @defun set-extent-begin-glyph-layout extent layout
718 This function sets the @code{begin-glyph-layout} property of
719 @var{extent} to @var{layout}.
720 @end defun
721
722 @defun set-extent-end-glyph-layout extent layout
723 This function sets the @code{end-glyph-layout} property of
724 @var{extent} to @var{layout}.
725 @end defun
726
727 @defun set-extent-begin-glyph extent begin-glyph &optional layout
728 This function sets the @code{begin-glyph} and @code{glyph-layout}
729 properties of @var{extent} to @var{begin-glyph} and @var{layout},
730 respectively. (@var{layout} defaults to @code{text} if not specified.)
731 @end defun
732
733 @defun set-extent-end-glyph extent end-glyph &optional layout
734 This function sets the @code{end-glyph} and @code{glyph-layout}
735 properties of @var{extent} to @var{end-glyph} and @var{layout},
736 respectively. (@var{layout} defaults to @code{text} if not specified.)
737 @end defun
738
739 @defun set-extent-initial-redisplay-function extent function
740 This function sets the @code{initial-redisplay-function} property of the
741 extent to @var{function}.
742 @end defun
743
744
745 @node Detached Extents
746 @section Detached Extents
747 @cindex detached extent
748
749 A detached extent is an extent that is not attached to a buffer or
750 string but can be re-inserted.  Detached extents have a start position
751 and end position of @code{nil}.  Extents can be explicitly detached
752 using @code{detach-extent}.
753
754 An extent is also detached when all of its characters are all killed by
755 a deletion, if its @code{detachable} property is set; if this property
756 is not set, the extent becomes a zero-length extent.  Zero-length
757 extents with the @code{detachable} property set behave specially.
758 @xref{Extent Endpoints, zero-length extents}.
759
760 @defun detach-extent extent
761 This function detaches @var{extent} from its buffer or string.  If
762 @var{extent} has the @code{duplicable} property, its detachment is
763 tracked by the undo mechanism.  @xref{Duplicable Extents}.
764 @end defun
765
766 @defun extent-detached-p extent
767 This function returns @code{nil} if @var{extent} is detached, and
768 @code{t} otherwise.
769 @end defun
770
771 @defun copy-extent extent &optional object
772 This function makes a copy of @var{extent}.  It is initially detached.
773 Optional argument @var{object} defaults to @var{extent}'s object
774 (normally a buffer or string, but could be @code{nil}).
775 @end defun
776
777 @defun insert-extent extent &optional start end no-hooks object
778 This function inserts @var{extent} from @var{start} to @var{end} in
779 @var{object} (a buffer or string).  If @var{extent} is detached from a
780 different buffer or string, or in most cases when @var{extent} is
781 already attached, the extent will first be copied as if with
782 @code{copy-extent}.  This function operates the same as if @code{insert}
783 were called on a string whose extent data calls for @var{extent} to be
784 inserted, except that if @var{no-hooks} is non-@code{nil},
785 @var{extent}'s @code{paste-function} will not be invoked.
786 @xref{Duplicable Extents}.
787 @end defun
788
789
790 @node Extent Parents
791 @section Extent Parents
792 @cindex extent parent
793 @cindex extent children
794 @cindex parent, of extent
795 @cindex children, of extent
796
797   An extent can have a parent extent set for it.  If this is the case,
798 the extent derives all its properties from that extent and has no
799 properties of its own.  The only ``properties'' that the extent keeps
800 are the buffer or string it refers to and the start and end points.
801 More correctly, the extent's own properties are shadowed.  If you
802 later change the extent to have no parent, its own properties will
803 become visible again.
804
805   It is possible for an extent's parent to itself have a parent,
806 and so on.  Through this, a whole tree of extents can be created,
807 all deriving their properties from one root extent.  Note, however,
808 that you cannot create an inheritance loop---this is explicitly
809 disallowed.
810
811   Parent extents are used to implement the extents over the modeline.
812
813 @defun set-extent-parent extent parent
814 This function sets the parent of @var{extent} to @var{parent}.
815 If @var{parent} is @code{nil}, the extent is set to have no parent.
816 @end defun
817
818 @defun extent-parent extent
819 This function return the parents (if any) of @var{extent}, or
820 @code{nil}.
821 @end defun
822
823 @defun extent-children extent
824 This function returns a list of the children (if any) of @var{extent}.
825 The children of an extent are all those extents whose parent is that
826 extent.  This function does not recursively trace children of children.
827 @end defun
828
829 @defun extent-descendants extent
830 This function returns a list of all descendants of @var{extent},
831 including @var{extent}.  This recursively applies @code{extent-children}
832 to any children of @var{extent}, until no more children can be found.
833 @end defun
834
835
836 @node Duplicable Extents
837 @section Duplicable Extents
838 @cindex duplicable extent
839 @cindex unique extents
840 @cindex extent replica
841 @cindex extent, duplicable
842 @cindex extent, unique
843
844   If an extent has the @code{duplicable} property, it will be copied into
845 strings, so that kill, yank, and undo commands will restore or copy it.
846
847 Specifically:
848
849 @itemize @bullet
850 @item
851 When a string is created using @code{buffer-substring} or
852 @code{buffer-string}, any duplicable extents in the region corresponding
853 to the string will be copied into the string (@pxref{Buffer
854 Contents}).  When the string is inserted into a buffer using
855 @code{insert}, @code{insert-before-markers}, @code{insert-buffer} or
856 @code{insert-buffer-substring}, the extents in the string will be copied
857 back into the buffer (@pxref{Insertion}).  The extents in a string can,
858 of course, be retrieved explicitly using the standard extent primitives
859 over the string.
860
861 @item
862 Similarly, when text is copied or cut into the kill ring, any duplicable
863 extents will be remembered and reinserted later when the text is pasted
864 back into a buffer.
865
866 @item
867 When @code{concat} is called on strings, the extents in the strings are
868 copied into the resulting string.
869
870 @item
871 When @code{substring} is called on a string, the relevant extents
872 are copied into the resulting string.
873
874 @item
875 When a duplicable extent is detached by @code{detach-extent} or string
876 deletion, or inserted by @code{insert-extent} or string insertion, the
877 action is recorded by the undo mechanism so that it can be undone later.
878 Note that if an extent gets detached and then a later undo causes the
879 extent to get reinserted, the new extent will not be `eq' to the original
880 extent.
881
882 @item
883 Extent motion, face changes, and attachment via @code{make-extent} are
884 not recorded by the undo mechanism.  This means that extent changes
885 which are to be undo-able must be performed by character editing, or by
886 insertion and detachment of duplicable extents.
887
888 @item
889 A duplicable extent's @code{copy-function} property, if non-@code{nil},
890 should be a function, and will be run when a duplicable extent is about
891 to be copied from a buffer to a string (or the kill ring).  It is called
892 with three arguments: the extent and the buffer positions within it
893 which are being copied.  If this function returns @code{nil}, then the
894 extent will not be copied; otherwise it will.
895
896 @item
897 A duplicable extent's @code{paste-function} property, if non-@code{nil},
898 should be a function, and will be run when a duplicable extent is about
899 to be copied from a string (or the kill ring) into a buffer.  It is
900 called with three arguments: the original extent and the buffer
901 positions which the copied extent will occupy. (This hook is run after
902 the corresponding text has already been inserted into the buffer.) Note
903 that the extent argument may be detached when this function is run.  If
904 this function returns @code{nil}, no extent will be inserted.
905 Otherwise, there will be an extent covering the range in question.
906
907   Note: if the extent to be copied is already attached to the buffer and
908 overlaps the new range, the extent will simply be extended and the
909 @code{paste-function} will not be called.
910 @end itemize
911
912
913 @node Extents and Events
914 @section Interaction of Extents with Keyboard and Mouse Events
915
916   If an extent has the @code{mouse-face} property set, it will be
917 highlighted when the mouse passes over it.  This includes the
918 begin-glyph, but not the end-glyph.  Highlighting is accomplished by
919 merging the extent's face with the face or faces specified by the
920 @code{mouse-face} property.  The effect is as if a pseudo-extent with
921 the @code{mouse-face} face were inserted after the extent in the display
922 order (@pxref{Extent Endpoints}, display order).
923
924 @defvar mouse-highlight-priority
925 This variable holds the priority to use when merging in the highlighting
926 pseudo-extent.  The default is 1000.  This is purposely set very high
927 so that the highlighting pseudo-extent shows up even if there are other
928 extents with various priorities at the same location.
929 @end defvar
930
931   You can also explicitly cause an extent to be highlighted.  Only one
932 extent at a time can be highlighted in this fashion, and any other
933 highlighted extent will be de-highlighted.
934
935 @defun highlight-extent extent &optional highlight-p
936 This function highlights (if @var{highlight-p} is non-@code{nil}) or
937 de-highlights (if @var{highlight-p} is @code{nil}) @var{extent}, if
938 @var{extent} has the @code{mouse-face} property. (Nothing happens if
939 @var{extent} does not have the @code{mouse-face} property.)
940 @end defun
941
942 @defun force-highlight-extent extent &optional highlight-p
943 This function is similar to @code{highlight-extent} but highlights
944 or de-highlights the extent regardless of whether it has the
945 @code{mouse-face} property.
946 @end defun
947
948   If an extent has a @code{keymap} property, this keymap will be
949 consulted for mouse clicks on the extent and keypresses made while
950 @code{point} is within the extent.  The behavior of mouse clicks and
951 keystrokes not defined in the keymap is as normal for the buffer.
952
953
954 @node Atomic Extents
955 @section Atomic Extents
956 @cindex atomic extent
957
958   If the Lisp file @file{atomic-extents} is loaded, then the atomic
959 extent facility is available.  An @dfn{atomic extent} is an extent for
960 which @code{point} cannot be positioned anywhere within it.  This
961 ensures that when selecting text, either all or none of the extent is
962 selected.
963
964   To make an extent atomic, set its @code{atomic} property.