1029
|
1 /* Interface code for dealing with text properties.
|
|
2 Copyright (C) 1992 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of GNU Emacs.
|
|
5
|
|
6 GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 1, or (at your option)
|
|
9 any later version.
|
|
10
|
|
11 GNU Emacs is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
19
|
|
20 #include "config.h"
|
|
21 #include "lisp.h"
|
|
22 #include "intervals.h"
|
|
23 #include "buffer.h"
|
|
24
|
|
25
|
|
26 /* NOTES: previous- and next- property change will have to skip
|
|
27 zero-length intervals if they are implemented. This could be done
|
|
28 inside next_interval and previous_interval.
|
|
29
|
|
30 It is assumed that for any interval plist, a property appears
|
|
31 only once on the list. Although some code i.e., remove_properties (),
|
|
32 handles the more general case, the uniqueness of properties is
|
|
33 neccessary for the system to remain consistent. This requirement
|
|
34 is enforced by the subrs installing properties onto the intervals. */
|
|
35
|
|
36
|
|
37 /* Types of hooks. */
|
|
38 Lisp_Object Qmouse_left;
|
|
39 Lisp_Object Qmouse_entered;
|
|
40 Lisp_Object Qpoint_left;
|
|
41 Lisp_Object Qpoint_entered;
|
|
42 Lisp_Object Qmodification;
|
|
43
|
|
44 /* Visual properties text (including strings) may have. */
|
|
45 Lisp_Object Qforeground, Qbackground, Qfont, Qunderline, Qstipple;
|
|
46 Lisp_Object Qinvisible, Qread_only;
|
|
47
|
1055
|
48 /* Extract the interval at the position pointed to by BEGIN from
|
|
49 OBJECT, a string or buffer. Additionally, check that the positions
|
|
50 pointed to by BEGIN and END are within the bounds of OBJECT, and
|
|
51 reverse them if *BEGIN is greater than *END. The objects pointed
|
|
52 to by BEGIN and END may be integers or markers; if the latter, they
|
|
53 are coerced to integers.
|
1029
|
54
|
|
55 Note that buffer points don't correspond to interval indices.
|
|
56 For example, point-max is 1 greater than the index of the last
|
|
57 character. This difference is handled in the caller, which uses
|
|
58 the validated points to determine a length, and operates on that.
|
|
59 Exceptions are Ftext_properties_at, Fnext_property_change, and
|
|
60 Fprevious_property_change which call this function with BEGIN == END.
|
|
61 Handle this case specially.
|
|
62
|
|
63 If FORCE is soft (0), it's OK to return NULL_INTERVAL. Otherwise,
|
1055
|
64 create an interval tree for OBJECT if one doesn't exist, provided
|
|
65 the object actually contains text. In the current design, if there
|
|
66 is no text, there can be no text properties. */
|
1029
|
67
|
|
68 #define soft 0
|
|
69 #define hard 1
|
|
70
|
|
71 static INTERVAL
|
|
72 validate_interval_range (object, begin, end, force)
|
|
73 Lisp_Object object, *begin, *end;
|
|
74 int force;
|
|
75 {
|
|
76 register INTERVAL i;
|
|
77 CHECK_STRING_OR_BUFFER (object, 0);
|
|
78 CHECK_NUMBER_COERCE_MARKER (*begin, 0);
|
|
79 CHECK_NUMBER_COERCE_MARKER (*end, 0);
|
|
80
|
|
81 /* If we are asked for a point, but from a subr which operates
|
|
82 on a range, then return nothing. */
|
|
83 if (*begin == *end && begin != end)
|
|
84 return NULL_INTERVAL;
|
|
85
|
|
86 if (XINT (*begin) > XINT (*end))
|
|
87 {
|
|
88 register int n;
|
|
89 n = XFASTINT (*begin); /* This is legit even if *begin is < 0 */
|
|
90 *begin = *end;
|
|
91 XFASTINT (*end) = n; /* because this is all we do with n. */
|
|
92 }
|
|
93
|
|
94 if (XTYPE (object) == Lisp_Buffer)
|
|
95 {
|
|
96 register struct buffer *b = XBUFFER (object);
|
|
97
|
|
98 /* If there's no text, there are no properties. */
|
|
99 if (BUF_BEGV (b) == BUF_ZV (b))
|
|
100 return NULL_INTERVAL;
|
|
101
|
|
102 if (!(BUF_BEGV (b) <= XINT (*begin) && XINT (*begin) <= XINT (*end)
|
|
103 && XINT (*end) <= BUF_ZV (b)))
|
|
104 args_out_of_range (*begin, *end);
|
|
105 i = b->intervals;
|
|
106
|
|
107 /* Special case for point-max: return the interval for the
|
|
108 last character. */
|
|
109 if (*begin == *end && *begin == BUF_Z (b))
|
|
110 *begin -= 1;
|
|
111 }
|
|
112 else
|
|
113 {
|
|
114 register struct Lisp_String *s = XSTRING (object);
|
|
115
|
|
116 if (! (1 <= XINT (*begin) && XINT (*begin) <= XINT (*end)
|
|
117 && XINT (*end) <= s->size))
|
|
118 args_out_of_range (*begin, *end);
|
|
119 i = s->intervals;
|
|
120 }
|
|
121
|
|
122 if (NULL_INTERVAL_P (i))
|
|
123 return (force ? create_root_interval (object) : i);
|
|
124
|
|
125 return find_interval (i, XINT (*begin));
|
|
126 }
|
|
127
|
|
128 /* Validate LIST as a property list. If LIST is not a list, then
|
|
129 make one consisting of (LIST nil). Otherwise, verify that LIST
|
|
130 is even numbered and thus suitable as a plist. */
|
|
131
|
|
132 static Lisp_Object
|
|
133 validate_plist (list)
|
|
134 {
|
|
135 if (NILP (list))
|
|
136 return Qnil;
|
|
137
|
|
138 if (CONSP (list))
|
|
139 {
|
|
140 register int i;
|
|
141 register Lisp_Object tail;
|
|
142 for (i = 0, tail = list; !NILP (tail); i++)
|
|
143 tail = Fcdr (tail);
|
|
144 if (i & 1)
|
|
145 error ("Odd length text property list");
|
|
146 return list;
|
|
147 }
|
|
148
|
|
149 return Fcons (list, Fcons (Qnil, Qnil));
|
|
150 }
|
|
151
|
|
152 #define set_properties(list,i) (i->plist = Fcopy_sequence (list))
|
|
153
|
|
154 /* Return nonzero if interval I has all the properties,
|
|
155 with the same values, of list PLIST. */
|
|
156
|
|
157 static int
|
|
158 interval_has_all_properties (plist, i)
|
|
159 Lisp_Object plist;
|
|
160 INTERVAL i;
|
|
161 {
|
|
162 register Lisp_Object tail1, tail2, sym1, sym2;
|
|
163 register int found;
|
|
164
|
|
165 /* Go through each element of PLIST. */
|
|
166 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1)))
|
|
167 {
|
|
168 sym1 = Fcar (tail1);
|
|
169 found = 0;
|
|
170
|
|
171 /* Go through I's plist, looking for sym1 */
|
|
172 for (tail2 = i->plist; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2)))
|
|
173 if (EQ (sym1, Fcar (tail2)))
|
|
174 {
|
|
175 /* Found the same property on both lists. If the
|
|
176 values are unequal, return zero. */
|
|
177 if (! EQ (Fequal (Fcar (Fcdr (tail1)), Fcar (Fcdr (tail2))),
|
|
178 Qt))
|
|
179 return 0;
|
|
180
|
|
181 /* Property has same value on both lists; go to next one. */
|
|
182 found = 1;
|
|
183 break;
|
|
184 }
|
|
185
|
|
186 if (! found)
|
|
187 return 0;
|
|
188 }
|
|
189
|
|
190 return 1;
|
|
191 }
|
|
192
|
|
193 /* Return nonzero if the plist of interval I has any of the
|
|
194 properties of PLIST, regardless of their values. */
|
|
195
|
|
196 static INLINE int
|
|
197 interval_has_some_properties (plist, i)
|
|
198 Lisp_Object plist;
|
|
199 INTERVAL i;
|
|
200 {
|
|
201 register Lisp_Object tail1, tail2, sym;
|
|
202
|
|
203 /* Go through each element of PLIST. */
|
|
204 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1)))
|
|
205 {
|
|
206 sym = Fcar (tail1);
|
|
207
|
|
208 /* Go through i's plist, looking for tail1 */
|
|
209 for (tail2 = i->plist; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2)))
|
|
210 if (EQ (sym, Fcar (tail2)))
|
|
211 return 1;
|
|
212 }
|
|
213
|
|
214 return 0;
|
|
215 }
|
|
216
|
|
217 /* Add the properties of PLIST to the interval I, or set
|
|
218 the value of I's property to the value of the property on PLIST
|
|
219 if they are different.
|
|
220
|
|
221 Return nonzero if this changes I (i.e., if any members of PLIST
|
|
222 are actually added to I's plist) */
|
|
223
|
|
224 static INLINE int
|
|
225 add_properties (plist, i)
|
|
226 Lisp_Object plist;
|
|
227 INTERVAL i;
|
|
228 {
|
|
229 register Lisp_Object tail1, tail2, sym1, val1;
|
|
230 register int changed = 0;
|
|
231 register int found;
|
|
232
|
|
233 /* Go through each element of PLIST. */
|
|
234 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1)))
|
|
235 {
|
|
236 sym1 = Fcar (tail1);
|
|
237 val1 = Fcar (Fcdr (tail1));
|
|
238 found = 0;
|
|
239
|
|
240 /* Go through I's plist, looking for sym1 */
|
|
241 for (tail2 = i->plist; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2)))
|
|
242 if (EQ (sym1, Fcar (tail2)))
|
|
243 {
|
|
244 register Lisp_Object this_cdr = Fcdr (tail2);
|
|
245
|
|
246 /* Found the property. Now check its value. */
|
|
247 found = 1;
|
|
248
|
|
249 /* The properties have the same value on both lists.
|
|
250 Continue to the next property. */
|
|
251 if (Fequal (val1, Fcar (this_cdr)))
|
|
252 break;
|
|
253
|
|
254 /* I's property has a different value -- change it */
|
|
255 Fsetcar (this_cdr, val1);
|
|
256 changed++;
|
|
257 break;
|
|
258 }
|
|
259
|
|
260 if (! found)
|
|
261 {
|
|
262 i->plist = Fcons (sym1, Fcons (val1, i->plist));
|
|
263 changed++;
|
|
264 }
|
|
265 }
|
|
266
|
|
267 return changed;
|
|
268 }
|
|
269
|
|
270 /* For any members of PLIST which are properties of I, remove them
|
|
271 from I's plist. */
|
|
272
|
|
273 static INLINE int
|
|
274 remove_properties (plist, i)
|
|
275 Lisp_Object plist;
|
|
276 INTERVAL i;
|
|
277 {
|
|
278 register Lisp_Object tail1, tail2, sym;
|
|
279 register Lisp_Object current_plist = i->plist;
|
|
280 register int changed = 0;
|
|
281
|
|
282 /* Go through each element of plist. */
|
|
283 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1)))
|
|
284 {
|
|
285 sym = Fcar (tail1);
|
|
286
|
|
287 /* First, remove the symbol if its at the head of the list */
|
|
288 while (! NILP (current_plist) && EQ (sym, Fcar (current_plist)))
|
|
289 {
|
|
290 current_plist = Fcdr (Fcdr (current_plist));
|
|
291 changed++;
|
|
292 }
|
|
293
|
|
294 /* Go through i's plist, looking for sym */
|
|
295 tail2 = current_plist;
|
|
296 while (! NILP (tail2))
|
|
297 {
|
|
298 register Lisp_Object this = Fcdr (Fcdr (tail2));
|
|
299 if (EQ (sym, Fcar (this)))
|
|
300 {
|
|
301 Fsetcdr (Fcdr (tail2), Fcdr (Fcdr (this)));
|
|
302 changed++;
|
|
303 }
|
|
304 tail2 = this;
|
|
305 }
|
|
306 }
|
|
307
|
|
308 if (changed)
|
|
309 i->plist = current_plist;
|
|
310 return changed;
|
|
311 }
|
|
312
|
|
313 /* Remove all properties from interval I. Return non-zero
|
|
314 if this changes the interval. */
|
|
315
|
|
316 static INLINE int
|
|
317 erase_properties (i)
|
|
318 INTERVAL i;
|
|
319 {
|
|
320 if (NILP (i->plist))
|
|
321 return 0;
|
|
322
|
|
323 i->plist = Qnil;
|
|
324 return 1;
|
|
325 }
|
|
326
|
|
327
|
|
328 DEFUN ("text-properties-at", Ftext_properties_at,
|
|
329 Stext_properties_at, 1, 2, 0,
|
|
330 "Return the list of properties held by the character at POSITION\n\
|
|
331 in optional argument OBJECT, a string or buffer. If nil, OBJECT\n\
|
|
332 defaults to the current buffer.")
|
|
333 (pos, object)
|
|
334 Lisp_Object pos, object;
|
|
335 {
|
|
336 register INTERVAL i;
|
|
337 register int p;
|
|
338
|
|
339 if (NILP (object))
|
|
340 XSET (object, Lisp_Buffer, current_buffer);
|
|
341
|
|
342 i = validate_interval_range (object, &pos, &pos, soft);
|
|
343 if (NULL_INTERVAL_P (i))
|
|
344 return Qnil;
|
|
345
|
|
346 return i->plist;
|
|
347 }
|
|
348
|
|
349 DEFUN ("next-property-change", Fnext_property_change,
|
|
350 Snext_property_change, 2, 2, 0,
|
|
351 "Return the position after POSITION in OBJECT which has properties\n\
|
|
352 different from those at POSITION. OBJECT may be a string or buffer.\n\
|
|
353 Returns nil if unsuccessful.")
|
|
354 (pos, object)
|
|
355 Lisp_Object pos, object;
|
|
356 {
|
|
357 register INTERVAL i, next;
|
|
358
|
|
359 i = validate_interval_range (object, &pos, &pos, soft);
|
|
360 if (NULL_INTERVAL_P (i))
|
|
361 return Qnil;
|
|
362
|
|
363 next = next_interval (i);
|
|
364 while (! NULL_INTERVAL_P (next) && intervals_equal (i, next))
|
|
365 next = next_interval (next);
|
|
366
|
|
367 if (NULL_INTERVAL_P (next))
|
|
368 return Qnil;
|
|
369
|
|
370 return next->position;
|
|
371 }
|
|
372
|
|
373 DEFUN ("previous-property-change", Fprevious_property_change,
|
|
374 Sprevious_property_change, 2, 2, 0,
|
|
375 "Return the position before POSITION in OBJECT which has properties\n\
|
|
376 different from those at POSITION. OBJECT may be a string or buffer.\n\
|
|
377 Returns nil if unsuccessful.")
|
|
378 (pos, object)
|
|
379 Lisp_Object pos, object;
|
|
380 {
|
|
381 register INTERVAL i, previous;
|
|
382
|
|
383 i = validate_interval_range (object, &pos, &pos, soft);
|
|
384 if (NULL_INTERVAL_P (i))
|
|
385 return Qnil;
|
|
386
|
|
387 previous = previous_interval (i);
|
|
388 while (! NULL_INTERVAL_P (previous) && intervals_equal (previous, i))
|
|
389 previous = previous_interval (previous);
|
|
390 if (NULL_INTERVAL_P (previous))
|
|
391 return Qnil;
|
|
392
|
|
393 return previous->position + LENGTH (previous) - 1;
|
|
394 }
|
|
395
|
|
396 DEFUN ("add-text-properties", Fadd_text_properties,
|
|
397 Sadd_text_properties, 4, 4, 0,
|
|
398 "Add the PROPERTIES (a property list) to the text of OBJECT\n\
|
|
399 (a string or buffer) in the range START to END. Returns t if any change\n\
|
|
400 was made, nil otherwise.")
|
|
401 (object, start, end, properties)
|
|
402 Lisp_Object object, start, end, properties;
|
|
403 {
|
|
404 register INTERVAL i, unchanged;
|
|
405 register int s, len, modified;
|
|
406
|
|
407 properties = validate_plist (properties);
|
|
408 if (NILP (properties))
|
|
409 return Qnil;
|
|
410
|
|
411 i = validate_interval_range (object, &start, &end, hard);
|
|
412 if (NULL_INTERVAL_P (i))
|
|
413 return Qnil;
|
|
414
|
|
415 s = XINT (start);
|
|
416 len = XINT (end) - s;
|
|
417
|
|
418 /* If we're not starting on an interval boundary, we have to
|
|
419 split this interval. */
|
|
420 if (i->position != s)
|
|
421 {
|
|
422 /* If this interval already has the properties, we can
|
|
423 skip it. */
|
|
424 if (interval_has_all_properties (properties, i))
|
|
425 {
|
|
426 int got = (LENGTH (i) - (s - i->position));
|
|
427 if (got >= len)
|
|
428 return Qnil;
|
|
429 len -= got;
|
|
430 }
|
|
431 else
|
|
432 {
|
|
433 unchanged = i;
|
|
434 i = split_interval_right (unchanged, s - unchanged->position + 1);
|
|
435 copy_properties (unchanged, i);
|
|
436 if (LENGTH (i) > len)
|
|
437 {
|
|
438 i = split_interval_left (i, len + 1);
|
|
439 copy_properties (unchanged, i);
|
|
440 add_properties (properties, i);
|
|
441 return Qt;
|
|
442 }
|
|
443
|
|
444 add_properties (properties, i);
|
|
445 modified = 1;
|
|
446 len -= LENGTH (i);
|
|
447 i = next_interval (i);
|
|
448 }
|
|
449 }
|
|
450
|
|
451 /* We are at the beginning of an interval, with len to scan */
|
|
452 while (1)
|
|
453 {
|
|
454 if (LENGTH (i) >= len)
|
|
455 {
|
|
456 if (interval_has_all_properties (properties, i))
|
|
457 return modified ? Qt : Qnil;
|
|
458
|
|
459 if (LENGTH (i) == len)
|
|
460 {
|
|
461 add_properties (properties, i);
|
|
462 return Qt;
|
|
463 }
|
|
464
|
|
465 /* i doesn't have the properties, and goes past the change limit */
|
|
466 unchanged = i;
|
|
467 i = split_interval_left (unchanged, len + 1);
|
|
468 copy_properties (unchanged, i);
|
|
469 add_properties (properties, i);
|
|
470 return Qt;
|
|
471 }
|
|
472
|
|
473 len -= LENGTH (i);
|
|
474 modified += add_properties (properties, i);
|
|
475 i = next_interval (i);
|
|
476 }
|
|
477 }
|
|
478
|
|
479 DEFUN ("set-text-properties", Fset_text_properties,
|
|
480 Sset_text_properties, 4, 4, 0,
|
|
481 "Make the text of OBJECT (a string or buffer) have precisely\n\
|
|
482 PROPERTIES (a list of properties) in the range START to END.\n\
|
|
483 \n\
|
|
484 If called with a valid property list, return t (text was changed).\n\
|
|
485 Otherwise return nil.")
|
|
486 (object, start, end, properties)
|
|
487 Lisp_Object object, start, end, properties;
|
|
488 {
|
|
489 register INTERVAL i, unchanged;
|
|
490 register int s, len;
|
|
491
|
|
492 properties = validate_plist (properties);
|
|
493 if (NILP (properties))
|
|
494 return Qnil;
|
|
495
|
|
496 i = validate_interval_range (object, &start, &end, hard);
|
|
497 if (NULL_INTERVAL_P (i))
|
|
498 return Qnil;
|
|
499
|
|
500 s = XINT (start);
|
|
501 len = XINT (end) - s;
|
|
502
|
|
503 if (i->position != s)
|
|
504 {
|
|
505 unchanged = i;
|
|
506 i = split_interval_right (unchanged, s - unchanged->position + 1);
|
|
507 copy_properties (unchanged, i);
|
|
508 if (LENGTH (i) > len)
|
|
509 {
|
|
510 i = split_interval_left (i, len);
|
|
511 set_properties (properties, i);
|
|
512 return Qt;
|
|
513 }
|
|
514
|
|
515 set_properties (properties, i);
|
|
516 len -= LENGTH (i);
|
|
517 i = next_interval (i);
|
|
518 }
|
|
519
|
|
520 while (1)
|
|
521 {
|
|
522 if (LENGTH (i) >= len)
|
|
523 {
|
|
524 if (LENGTH (i) == len)
|
|
525 {
|
|
526 set_properties (properties, i);
|
|
527 return Qt;
|
|
528 }
|
|
529
|
|
530 i = split_interval_left (i, len + 1);
|
|
531 set_properties (properties, i);
|
|
532 return Qt;
|
|
533 }
|
|
534
|
|
535 len -= LENGTH (i);
|
|
536 set_properties (properties, i);
|
|
537 i = next_interval (i);
|
|
538 }
|
|
539
|
|
540 return Qt;
|
|
541 }
|
|
542
|
|
543 DEFUN ("remove-text-properties", Fremove_text_properties,
|
|
544 Sremove_text_properties, 4, 4, 0,
|
|
545 "Remove the PROPERTIES (a property list) from the text of OBJECT\n\
|
|
546 (a string or buffer) in the range START to END. Returns t if any change\n\
|
|
547 was made, nil otherwise.")
|
|
548 (object, start, end, properties)
|
|
549 Lisp_Object object, start, end, properties;
|
|
550 {
|
|
551 register INTERVAL i, unchanged;
|
|
552 register int s, len, modified;
|
|
553
|
|
554 i = validate_interval_range (object, &start, &end, soft);
|
|
555 if (NULL_INTERVAL_P (i))
|
|
556 return Qnil;
|
|
557
|
|
558 s = XINT (start);
|
|
559 len = XINT (end) - s;
|
|
560 if (i->position != s)
|
|
561 {
|
|
562 /* No properties on this first interval -- return if
|
|
563 it covers the entire region. */
|
|
564 if (! interval_has_some_properties (properties, i))
|
|
565 {
|
|
566 int got = (LENGTH (i) - (s - i->position));
|
|
567 if (got >= len)
|
|
568 return Qnil;
|
|
569 len -= got;
|
|
570 }
|
|
571 /* Remove the properties from this interval. If it's short
|
|
572 enough, return, splitting it if it's too short. */
|
|
573 else
|
|
574 {
|
|
575 unchanged = i;
|
|
576 i = split_interval_right (unchanged, s - unchanged->position + 1);
|
|
577 copy_properties (unchanged, i);
|
|
578 if (LENGTH (i) > len)
|
|
579 {
|
|
580 i = split_interval_left (i, len + 1);
|
|
581 copy_properties (unchanged, i);
|
|
582 remove_properties (properties, i);
|
|
583 return Qt;
|
|
584 }
|
|
585
|
|
586 remove_properties (properties, i);
|
|
587 modified = 1;
|
|
588 len -= LENGTH (i);
|
|
589 i = next_interval (i);
|
|
590 }
|
|
591 }
|
|
592
|
|
593 /* We are at the beginning of an interval, with len to scan */
|
|
594 while (1)
|
|
595 {
|
|
596 if (LENGTH (i) >= len)
|
|
597 {
|
|
598 if (! interval_has_some_properties (properties, i))
|
|
599 return modified ? Qt : Qnil;
|
|
600
|
|
601 if (LENGTH (i) == len)
|
|
602 {
|
|
603 remove_properties (properties, i);
|
|
604 return Qt;
|
|
605 }
|
|
606
|
|
607 /* i has the properties, and goes past the change limit */
|
|
608 unchanged = split_interval_right (i, len + 1);
|
|
609 copy_properties (unchanged, i);
|
|
610 remove_properties (properties, i);
|
|
611 return Qt;
|
|
612 }
|
|
613
|
|
614 len -= LENGTH (i);
|
|
615 modified += remove_properties (properties, i);
|
|
616 i = next_interval (i);
|
|
617 }
|
|
618 }
|
|
619
|
|
620 DEFUN ("erase-text-properties", Ferase_text_properties,
|
|
621 Serase_text_properties, 3, 3, 0,
|
|
622 "Remove all text properties from OBJECT (a string or buffer), in the\n\
|
|
623 range START to END. Returns t if any change was made, nil otherwise.")
|
|
624 (object, start, end)
|
|
625 Lisp_Object object, start, end;
|
|
626 {
|
|
627 register INTERVAL i, unchanged;
|
|
628 register int s, len, modified;
|
|
629
|
|
630 i = validate_interval_range (object, &start, &end, soft);
|
|
631 if (NULL_INTERVAL_P (i))
|
|
632 return Qnil;
|
|
633
|
|
634 s = XINT (start);
|
|
635 len = XINT (end) - s;
|
|
636 if (i->position != s)
|
|
637 {
|
|
638 int got = LENGTH (i) - (s - i->position);
|
|
639
|
|
640 if (got > len)
|
|
641 {
|
|
642 if (NILP (i->plist))
|
|
643 return Qnil;
|
|
644
|
|
645 unchanged = i;
|
|
646 i = split_interval_right (unchanged, s - unchanged->position + 1);
|
|
647 i = split_interval_right (i, len + 1);
|
|
648 copy_properties (unchanged, i);
|
|
649 return Qt;
|
|
650 }
|
|
651
|
|
652 if (! NILP (i->plist))
|
|
653 {
|
|
654 i = split_interval_right (i, s - i->position + 1);
|
|
655 modified++;
|
|
656 }
|
|
657
|
|
658 len -= got;
|
|
659 i = next_interval (i);
|
|
660 }
|
|
661
|
|
662 /* We are starting at the beginning of an interval */
|
|
663 while (len > 0)
|
|
664 {
|
|
665 if (LENGTH (i) > len)
|
|
666 {
|
|
667 if (NILP (i->plist))
|
|
668 return modified ? Qt : Qnil;
|
|
669
|
|
670 i = split_interval_left (i, len + 1);
|
|
671 return Qt;
|
|
672 }
|
|
673
|
|
674 len -= LENGTH (i);
|
|
675 modified += erase_properties (i);
|
|
676 i = next_interval (i);
|
|
677 }
|
|
678
|
|
679 return modified ? Qt : Qnil;
|
|
680 }
|
|
681
|
|
682 void
|
|
683 syms_of_textprop ()
|
|
684 {
|
|
685 DEFVAR_INT ("interval-balance-threshold", &interval_balance_threshold,
|
|
686 "Threshold for rebalancing interval trees, expressed as the
|
|
687 percentage by which the left interval tree should not differ from the right.");
|
|
688 interval_balance_threshold = 8;
|
|
689
|
|
690 /* Common attributes one might give text */
|
|
691
|
|
692 staticpro (&Qforeground);
|
|
693 Qforeground = intern ("foreground");
|
|
694 staticpro (&Qbackground);
|
|
695 Qbackground = intern ("background");
|
|
696 staticpro (&Qfont);
|
|
697 Qfont = intern ("font");
|
|
698 staticpro (&Qstipple);
|
|
699 Qstipple = intern ("stipple");
|
|
700 staticpro (&Qunderline);
|
|
701 Qunderline = intern ("underline");
|
|
702 staticpro (&Qread_only);
|
|
703 Qread_only = intern ("read-only");
|
|
704 staticpro (&Qinvisible);
|
|
705 Qinvisible = intern ("invisible");
|
|
706
|
|
707 /* Properties that text might use to specify certain actions */
|
|
708
|
|
709 staticpro (&Qmouse_left);
|
|
710 Qmouse_left = intern ("mouse-left");
|
|
711 staticpro (&Qmouse_entered);
|
|
712 Qmouse_entered = intern ("mouse-entered");
|
|
713 staticpro (&Qpoint_left);
|
|
714 Qpoint_left = intern ("point-left");
|
|
715 staticpro (&Qpoint_entered);
|
|
716 Qpoint_entered = intern ("point-entered");
|
|
717 staticpro (&Qmodification);
|
|
718 Qmodification = intern ("modification");
|
|
719
|
|
720 defsubr (&Stext_properties_at);
|
|
721 defsubr (&Snext_property_change);
|
|
722 defsubr (&Sprevious_property_change);
|
|
723 defsubr (&Sadd_text_properties);
|
|
724 defsubr (&Sset_text_properties);
|
|
725 defsubr (&Sremove_text_properties);
|
|
726 defsubr (&Serase_text_properties);
|
|
727 }
|