Mercurial > emacs
annotate src/textprop.c @ 1911:d9fc49956cd8
* bytecode.c (Fbyte_code): Pass the correct number of arguments to
temp_output_buffer_show.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Mon, 22 Feb 1993 14:23:26 +0000 |
parents | 9d65dfc7bdb7 |
children | 1cdbdbe2f70a |
rev | line source |
---|---|
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 | |
1211 | 30 set_properties needs to deal with the interval property cache. |
31 | |
1029 | 32 It is assumed that for any interval plist, a property appears |
33 only once on the list. Although some code i.e., remove_properties (), | |
34 handles the more general case, the uniqueness of properties is | |
35 neccessary for the system to remain consistent. This requirement | |
36 is enforced by the subrs installing properties onto the intervals. */ | |
37 | |
1302
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
38 /* The rest of the file is within this conditional */ |
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
39 #ifdef USE_TEXT_PROPERTIES |
1029 | 40 |
41 /* Types of hooks. */ | |
42 Lisp_Object Qmouse_left; | |
43 Lisp_Object Qmouse_entered; | |
44 Lisp_Object Qpoint_left; | |
45 Lisp_Object Qpoint_entered; | |
46 Lisp_Object Qmodification; | |
47 | |
48 /* Visual properties text (including strings) may have. */ | |
49 Lisp_Object Qforeground, Qbackground, Qfont, Qunderline, Qstipple; | |
50 Lisp_Object Qinvisible, Qread_only; | |
51 | |
1055 | 52 /* Extract the interval at the position pointed to by BEGIN from |
53 OBJECT, a string or buffer. Additionally, check that the positions | |
54 pointed to by BEGIN and END are within the bounds of OBJECT, and | |
55 reverse them if *BEGIN is greater than *END. The objects pointed | |
56 to by BEGIN and END may be integers or markers; if the latter, they | |
57 are coerced to integers. | |
1029 | 58 |
59 Note that buffer points don't correspond to interval indices. | |
60 For example, point-max is 1 greater than the index of the last | |
61 character. This difference is handled in the caller, which uses | |
62 the validated points to determine a length, and operates on that. | |
63 Exceptions are Ftext_properties_at, Fnext_property_change, and | |
64 Fprevious_property_change which call this function with BEGIN == END. | |
65 Handle this case specially. | |
66 | |
67 If FORCE is soft (0), it's OK to return NULL_INTERVAL. Otherwise, | |
1055 | 68 create an interval tree for OBJECT if one doesn't exist, provided |
69 the object actually contains text. In the current design, if there | |
70 is no text, there can be no text properties. */ | |
1029 | 71 |
72 #define soft 0 | |
73 #define hard 1 | |
74 | |
75 static INTERVAL | |
76 validate_interval_range (object, begin, end, force) | |
77 Lisp_Object object, *begin, *end; | |
78 int force; | |
79 { | |
80 register INTERVAL i; | |
81 CHECK_STRING_OR_BUFFER (object, 0); | |
82 CHECK_NUMBER_COERCE_MARKER (*begin, 0); | |
83 CHECK_NUMBER_COERCE_MARKER (*end, 0); | |
84 | |
85 /* If we are asked for a point, but from a subr which operates | |
86 on a range, then return nothing. */ | |
87 if (*begin == *end && begin != end) | |
88 return NULL_INTERVAL; | |
89 | |
90 if (XINT (*begin) > XINT (*end)) | |
91 { | |
92 register int n; | |
93 n = XFASTINT (*begin); /* This is legit even if *begin is < 0 */ | |
94 *begin = *end; | |
95 XFASTINT (*end) = n; /* because this is all we do with n. */ | |
96 } | |
97 | |
98 if (XTYPE (object) == Lisp_Buffer) | |
99 { | |
100 register struct buffer *b = XBUFFER (object); | |
101 | |
102 /* If there's no text, there are no properties. */ | |
103 if (BUF_BEGV (b) == BUF_ZV (b)) | |
104 return NULL_INTERVAL; | |
105 | |
106 if (!(BUF_BEGV (b) <= XINT (*begin) && XINT (*begin) <= XINT (*end) | |
107 && XINT (*end) <= BUF_ZV (b))) | |
108 args_out_of_range (*begin, *end); | |
109 i = b->intervals; | |
110 | |
111 /* Special case for point-max: return the interval for the | |
112 last character. */ | |
113 if (*begin == *end && *begin == BUF_Z (b)) | |
114 *begin -= 1; | |
115 } | |
116 else | |
117 { | |
118 register struct Lisp_String *s = XSTRING (object); | |
119 | |
120 if (! (1 <= XINT (*begin) && XINT (*begin) <= XINT (*end) | |
121 && XINT (*end) <= s->size)) | |
122 args_out_of_range (*begin, *end); | |
123 i = s->intervals; | |
124 } | |
125 | |
126 if (NULL_INTERVAL_P (i)) | |
127 return (force ? create_root_interval (object) : i); | |
128 | |
129 return find_interval (i, XINT (*begin)); | |
130 } | |
131 | |
132 /* Validate LIST as a property list. If LIST is not a list, then | |
133 make one consisting of (LIST nil). Otherwise, verify that LIST | |
134 is even numbered and thus suitable as a plist. */ | |
135 | |
136 static Lisp_Object | |
137 validate_plist (list) | |
138 { | |
139 if (NILP (list)) | |
140 return Qnil; | |
141 | |
142 if (CONSP (list)) | |
143 { | |
144 register int i; | |
145 register Lisp_Object tail; | |
146 for (i = 0, tail = list; !NILP (tail); i++) | |
147 tail = Fcdr (tail); | |
148 if (i & 1) | |
149 error ("Odd length text property list"); | |
150 return list; | |
151 } | |
152 | |
153 return Fcons (list, Fcons (Qnil, Qnil)); | |
154 } | |
155 | |
156 #define set_properties(list,i) (i->plist = Fcopy_sequence (list)) | |
157 | |
158 /* Return nonzero if interval I has all the properties, | |
159 with the same values, of list PLIST. */ | |
160 | |
161 static int | |
162 interval_has_all_properties (plist, i) | |
163 Lisp_Object plist; | |
164 INTERVAL i; | |
165 { | |
166 register Lisp_Object tail1, tail2, sym1, sym2; | |
167 register int found; | |
168 | |
169 /* Go through each element of PLIST. */ | |
170 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1))) | |
171 { | |
172 sym1 = Fcar (tail1); | |
173 found = 0; | |
174 | |
175 /* Go through I's plist, looking for sym1 */ | |
176 for (tail2 = i->plist; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2))) | |
177 if (EQ (sym1, Fcar (tail2))) | |
178 { | |
179 /* Found the same property on both lists. If the | |
180 values are unequal, return zero. */ | |
181 if (! EQ (Fequal (Fcar (Fcdr (tail1)), Fcar (Fcdr (tail2))), | |
182 Qt)) | |
183 return 0; | |
184 | |
185 /* Property has same value on both lists; go to next one. */ | |
186 found = 1; | |
187 break; | |
188 } | |
189 | |
190 if (! found) | |
191 return 0; | |
192 } | |
193 | |
194 return 1; | |
195 } | |
196 | |
197 /* Return nonzero if the plist of interval I has any of the | |
198 properties of PLIST, regardless of their values. */ | |
199 | |
200 static INLINE int | |
201 interval_has_some_properties (plist, i) | |
202 Lisp_Object plist; | |
203 INTERVAL i; | |
204 { | |
205 register Lisp_Object tail1, tail2, sym; | |
206 | |
207 /* Go through each element of PLIST. */ | |
208 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1))) | |
209 { | |
210 sym = Fcar (tail1); | |
211 | |
212 /* Go through i's plist, looking for tail1 */ | |
213 for (tail2 = i->plist; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2))) | |
214 if (EQ (sym, Fcar (tail2))) | |
215 return 1; | |
216 } | |
217 | |
218 return 0; | |
219 } | |
220 | |
221 /* Add the properties of PLIST to the interval I, or set | |
222 the value of I's property to the value of the property on PLIST | |
223 if they are different. | |
224 | |
225 Return nonzero if this changes I (i.e., if any members of PLIST | |
226 are actually added to I's plist) */ | |
227 | |
228 static INLINE int | |
229 add_properties (plist, i) | |
230 Lisp_Object plist; | |
231 INTERVAL i; | |
232 { | |
233 register Lisp_Object tail1, tail2, sym1, val1; | |
234 register int changed = 0; | |
235 register int found; | |
236 | |
237 /* Go through each element of PLIST. */ | |
238 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1))) | |
239 { | |
240 sym1 = Fcar (tail1); | |
241 val1 = Fcar (Fcdr (tail1)); | |
242 found = 0; | |
243 | |
244 /* Go through I's plist, looking for sym1 */ | |
245 for (tail2 = i->plist; ! NILP (tail2); tail2 = Fcdr (Fcdr (tail2))) | |
246 if (EQ (sym1, Fcar (tail2))) | |
247 { | |
248 register Lisp_Object this_cdr = Fcdr (tail2); | |
249 | |
250 /* Found the property. Now check its value. */ | |
251 found = 1; | |
252 | |
253 /* The properties have the same value on both lists. | |
254 Continue to the next property. */ | |
255 if (Fequal (val1, Fcar (this_cdr))) | |
256 break; | |
257 | |
258 /* I's property has a different value -- change it */ | |
259 Fsetcar (this_cdr, val1); | |
260 changed++; | |
261 break; | |
262 } | |
263 | |
264 if (! found) | |
265 { | |
266 i->plist = Fcons (sym1, Fcons (val1, i->plist)); | |
267 changed++; | |
268 } | |
269 } | |
270 | |
271 return changed; | |
272 } | |
273 | |
274 /* For any members of PLIST which are properties of I, remove them | |
275 from I's plist. */ | |
276 | |
277 static INLINE int | |
278 remove_properties (plist, i) | |
279 Lisp_Object plist; | |
280 INTERVAL i; | |
281 { | |
282 register Lisp_Object tail1, tail2, sym; | |
283 register Lisp_Object current_plist = i->plist; | |
284 register int changed = 0; | |
285 | |
286 /* Go through each element of plist. */ | |
287 for (tail1 = plist; ! NILP (tail1); tail1 = Fcdr (Fcdr (tail1))) | |
288 { | |
289 sym = Fcar (tail1); | |
290 | |
291 /* First, remove the symbol if its at the head of the list */ | |
292 while (! NILP (current_plist) && EQ (sym, Fcar (current_plist))) | |
293 { | |
294 current_plist = Fcdr (Fcdr (current_plist)); | |
295 changed++; | |
296 } | |
297 | |
298 /* Go through i's plist, looking for sym */ | |
299 tail2 = current_plist; | |
300 while (! NILP (tail2)) | |
301 { | |
302 register Lisp_Object this = Fcdr (Fcdr (tail2)); | |
303 if (EQ (sym, Fcar (this))) | |
304 { | |
305 Fsetcdr (Fcdr (tail2), Fcdr (Fcdr (this))); | |
306 changed++; | |
307 } | |
308 tail2 = this; | |
309 } | |
310 } | |
311 | |
312 if (changed) | |
313 i->plist = current_plist; | |
314 return changed; | |
315 } | |
316 | |
317 /* Remove all properties from interval I. Return non-zero | |
318 if this changes the interval. */ | |
319 | |
320 static INLINE int | |
321 erase_properties (i) | |
322 INTERVAL i; | |
323 { | |
324 if (NILP (i->plist)) | |
325 return 0; | |
326 | |
327 i->plist = Qnil; | |
328 return 1; | |
329 } | |
330 | |
331 DEFUN ("text-properties-at", Ftext_properties_at, | |
332 Stext_properties_at, 1, 2, 0, | |
333 "Return the list of properties held by the character at POSITION\n\ | |
334 in optional argument OBJECT, a string or buffer. If nil, OBJECT\n\ | |
335 defaults to the current buffer.") | |
336 (pos, object) | |
337 Lisp_Object pos, object; | |
338 { | |
339 register INTERVAL i; | |
340 | |
341 if (NILP (object)) | |
342 XSET (object, Lisp_Buffer, current_buffer); | |
343 | |
344 i = validate_interval_range (object, &pos, &pos, soft); | |
345 if (NULL_INTERVAL_P (i)) | |
346 return Qnil; | |
347 | |
348 return i->plist; | |
349 } | |
350 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
351 DEFUN ("get-text-property", Fget_text_property, Sget_text_property, 2, 3, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
352 "Return the value of position POS's property PROP, in OBJECT. |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
353 OBJECT is optional and defaults to the current buffer.") |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
354 (pos, prop, object) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
355 Lisp_Object sym, object; |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
356 register Lisp_Object prop; |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
357 { |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
358 register INTERVAL i; |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
359 register Lisp_Object tail; |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
360 |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
361 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
362 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
363 |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
364 i = validate_interval_range (object, &pos, &pos, soft); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
365 if (NULL_INTERVAL_P (i)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
366 return Qnil; |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
367 |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
368 for (tail = i->plist; !NILP (tail); tail = Fcdr (Fcdr (tail))) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
369 { |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
370 register Lisp_Object tem; |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
371 tem = Fcar (tail); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
372 if (EQ (prop, tem)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
373 return Fcar (Fcdr (tail)); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
374 } |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
375 return Qnil; |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
376 } |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
377 |
1029 | 378 DEFUN ("next-property-change", Fnext_property_change, |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
379 Snext_property_change, 1, 2, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
380 "Return the position of next property change.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
381 Scans characters forward from POS in OBJECT till it finds\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
382 a change in some text property, then returns the position of the change.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
383 The optional second argument OBJECT is the string or buffer to scan.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
384 Return nil if the property is constant all the way to the end of OBJECT.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
385 If the value is non-nil, it is a position greater than POS, never equal.") |
1029 | 386 (pos, object) |
387 Lisp_Object pos, object; | |
388 { | |
389 register INTERVAL i, next; | |
390 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
391 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
392 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
393 |
1029 | 394 i = validate_interval_range (object, &pos, &pos, soft); |
395 if (NULL_INTERVAL_P (i)) | |
396 return Qnil; | |
397 | |
398 next = next_interval (i); | |
399 while (! NULL_INTERVAL_P (next) && intervals_equal (i, next)) | |
400 next = next_interval (next); | |
401 | |
402 if (NULL_INTERVAL_P (next)) | |
403 return Qnil; | |
404 | |
405 return next->position; | |
406 } | |
407 | |
1211 | 408 DEFUN ("next-single-property-change", Fnext_single_property_change, |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
409 Snext_single_property_change, 1, 3, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
410 "Return the position of next property change for a specific property.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
411 Scans characters forward from POS till it finds\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
412 a change in the PROP property, then returns the position of the change.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
413 The optional third argument OBJECT is the string or buffer to scan.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
414 Return nil if the property is constant all the way to the end of OBJECT.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
415 If the value is non-nil, it is a position greater than POS, never equal.") |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
416 (pos, prop, object) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
417 Lisp_Object pos, prop, object; |
1211 | 418 { |
419 register INTERVAL i, next; | |
420 register Lisp_Object here_val; | |
421 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
422 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
423 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
424 |
1211 | 425 i = validate_interval_range (object, &pos, &pos, soft); |
426 if (NULL_INTERVAL_P (i)) | |
427 return Qnil; | |
428 | |
429 here_val = Fget (prop, i->plist); | |
430 next = next_interval (i); | |
431 while (! NULL_INTERVAL_P (next) && EQ (here_val, Fget (prop, next->plist))) | |
432 next = next_interval (next); | |
433 | |
434 if (NULL_INTERVAL_P (next)) | |
435 return Qnil; | |
436 | |
437 return next->position; | |
438 } | |
439 | |
1029 | 440 DEFUN ("previous-property-change", Fprevious_property_change, |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
441 Sprevious_property_change, 1, 2, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
442 "Return the position of previous property change.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
443 Scans characters backwards from POS in OBJECT till it finds\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
444 a change in some text property, then returns the position of the change.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
445 The optional second argument OBJECT is the string or buffer to scan.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
446 Return nil if the property is constant all the way to the start of OBJECT.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
447 If the value is non-nil, it is a position less than POS, never equal.") |
1029 | 448 (pos, object) |
449 Lisp_Object pos, object; | |
450 { | |
451 register INTERVAL i, previous; | |
452 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
453 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
454 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
455 |
1029 | 456 i = validate_interval_range (object, &pos, &pos, soft); |
457 if (NULL_INTERVAL_P (i)) | |
458 return Qnil; | |
459 | |
460 previous = previous_interval (i); | |
461 while (! NULL_INTERVAL_P (previous) && intervals_equal (previous, i)) | |
462 previous = previous_interval (previous); | |
463 if (NULL_INTERVAL_P (previous)) | |
464 return Qnil; | |
465 | |
466 return previous->position + LENGTH (previous) - 1; | |
467 } | |
468 | |
1211 | 469 DEFUN ("previous-single-property-change", Fprevious_single_property_change, |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
470 Sprevious_single_property_change, 2, 3, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
471 "Return the position of previous property change for a specific property.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
472 Scans characters backward from POS till it finds\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
473 a change in the PROP property, then returns the position of the change.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
474 The optional third argument OBJECT is the string or buffer to scan.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
475 Return nil if the property is constant all the way to the start of OBJECT.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
476 If the value is non-nil, it is a position less than POS, never equal.") |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
477 (pos, prop, object) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
478 Lisp_Object pos, prop, object; |
1211 | 479 { |
480 register INTERVAL i, previous; | |
481 register Lisp_Object here_val; | |
482 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
483 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
484 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
485 |
1211 | 486 i = validate_interval_range (object, &pos, &pos, soft); |
487 if (NULL_INTERVAL_P (i)) | |
488 return Qnil; | |
489 | |
490 here_val = Fget (prop, i->plist); | |
491 previous = previous_interval (i); | |
492 while (! NULL_INTERVAL_P (previous) | |
493 && EQ (here_val, Fget (prop, previous->plist))) | |
494 previous = previous_interval (previous); | |
495 if (NULL_INTERVAL_P (previous)) | |
496 return Qnil; | |
497 | |
498 return previous->position + LENGTH (previous) - 1; | |
499 } | |
500 | |
1029 | 501 DEFUN ("add-text-properties", Fadd_text_properties, |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
502 Sadd_text_properties, 3, 4, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
503 "Add properties to the text from START to END.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
504 The third argument PROPS is a property list\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
505 specifying the property values to add.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
506 The optional fourth argument, OBJECT,\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
507 is the string or buffer containing the text.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
508 Return t if any property value actually changed, nil otherwise.") |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
509 (start, end, properties, object) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
510 Lisp_Object start, end, properties, object; |
1029 | 511 { |
512 register INTERVAL i, unchanged; | |
513 register int s, len, modified; | |
514 | |
515 properties = validate_plist (properties); | |
516 if (NILP (properties)) | |
517 return Qnil; | |
518 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
519 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
520 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
521 |
1029 | 522 i = validate_interval_range (object, &start, &end, hard); |
523 if (NULL_INTERVAL_P (i)) | |
524 return Qnil; | |
525 | |
526 s = XINT (start); | |
527 len = XINT (end) - s; | |
528 | |
529 /* If we're not starting on an interval boundary, we have to | |
530 split this interval. */ | |
531 if (i->position != s) | |
532 { | |
533 /* If this interval already has the properties, we can | |
534 skip it. */ | |
535 if (interval_has_all_properties (properties, i)) | |
536 { | |
537 int got = (LENGTH (i) - (s - i->position)); | |
538 if (got >= len) | |
539 return Qnil; | |
540 len -= got; | |
541 } | |
542 else | |
543 { | |
544 unchanged = i; | |
545 i = split_interval_right (unchanged, s - unchanged->position + 1); | |
546 copy_properties (unchanged, i); | |
547 if (LENGTH (i) > len) | |
548 { | |
549 i = split_interval_left (i, len + 1); | |
550 copy_properties (unchanged, i); | |
551 add_properties (properties, i); | |
552 return Qt; | |
553 } | |
554 | |
555 add_properties (properties, i); | |
556 modified = 1; | |
557 len -= LENGTH (i); | |
558 i = next_interval (i); | |
559 } | |
560 } | |
561 | |
562 /* We are at the beginning of an interval, with len to scan */ | |
563 while (1) | |
564 { | |
565 if (LENGTH (i) >= len) | |
566 { | |
567 if (interval_has_all_properties (properties, i)) | |
568 return modified ? Qt : Qnil; | |
569 | |
570 if (LENGTH (i) == len) | |
571 { | |
572 add_properties (properties, i); | |
573 return Qt; | |
574 } | |
575 | |
576 /* i doesn't have the properties, and goes past the change limit */ | |
577 unchanged = i; | |
578 i = split_interval_left (unchanged, len + 1); | |
579 copy_properties (unchanged, i); | |
580 add_properties (properties, i); | |
581 return Qt; | |
582 } | |
583 | |
584 len -= LENGTH (i); | |
585 modified += add_properties (properties, i); | |
586 i = next_interval (i); | |
587 } | |
588 } | |
589 | |
590 DEFUN ("set-text-properties", Fset_text_properties, | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
591 Sset_text_properties, 3, 4, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
592 "Completely replace properties of text from START to END.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
593 The third argument PROPS is the new property list.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
594 The optional fourth argument, OBJECT,\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
595 is the string or buffer containing the text.") |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
596 (start, end, props, object) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
597 Lisp_Object start, end, props, object; |
1029 | 598 { |
599 register INTERVAL i, unchanged; | |
1211 | 600 register INTERVAL prev_changed = NULL_INTERVAL; |
1029 | 601 register int s, len; |
602 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
603 props = validate_plist (props); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
604 if (NILP (props)) |
1029 | 605 return Qnil; |
606 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
607 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
608 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
609 |
1029 | 610 i = validate_interval_range (object, &start, &end, hard); |
611 if (NULL_INTERVAL_P (i)) | |
612 return Qnil; | |
613 | |
614 s = XINT (start); | |
615 len = XINT (end) - s; | |
616 | |
617 if (i->position != s) | |
618 { | |
619 unchanged = i; | |
620 i = split_interval_right (unchanged, s - unchanged->position + 1); | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
621 set_properties (props, i); |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
622 |
1029 | 623 if (LENGTH (i) > len) |
624 { | |
1211 | 625 i = split_interval_right (i, len); |
626 copy_properties (unchanged, i); | |
1029 | 627 return Qt; |
628 } | |
629 | |
1211 | 630 if (LENGTH (i) == len) |
631 return Qt; | |
632 | |
633 prev_changed = i; | |
1029 | 634 len -= LENGTH (i); |
635 i = next_interval (i); | |
636 } | |
637 | |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
638 /* We are starting at the beginning of an interval, I */ |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
639 while (len > 0) |
1029 | 640 { |
641 if (LENGTH (i) >= len) | |
642 { | |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
643 if (LENGTH (i) > len) |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
644 i = split_interval_left (i, len + 1); |
1029 | 645 |
1211 | 646 if (NULL_INTERVAL_P (prev_changed)) |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
647 set_properties (props, i); |
1211 | 648 else |
649 merge_interval_left (i); | |
1029 | 650 return Qt; |
651 } | |
652 | |
653 len -= LENGTH (i); | |
1211 | 654 if (NULL_INTERVAL_P (prev_changed)) |
655 { | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
656 set_properties (props, i); |
1211 | 657 prev_changed = i; |
658 } | |
659 else | |
660 prev_changed = i = merge_interval_left (i); | |
661 | |
1029 | 662 i = next_interval (i); |
663 } | |
664 | |
665 return Qt; | |
666 } | |
667 | |
668 DEFUN ("remove-text-properties", Fremove_text_properties, | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
669 Sremove_text_properties, 3, 4, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
670 "Remove some properties from text from START to END.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
671 The third argument PROPS is a property list\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
672 whose property names specify the properties to remove.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
673 \(The values stored in PROPS are ignored.)\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
674 The optional fourth argument, OBJECT,\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
675 is the string or buffer containing the text.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
676 Return t if any property was actually removed, nil otherwise.") |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
677 (start, end, props, object) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
678 Lisp_Object start, end, props, object; |
1029 | 679 { |
680 register INTERVAL i, unchanged; | |
681 register int s, len, modified; | |
682 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
683 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
684 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
685 |
1029 | 686 i = validate_interval_range (object, &start, &end, soft); |
687 if (NULL_INTERVAL_P (i)) | |
688 return Qnil; | |
689 | |
690 s = XINT (start); | |
691 len = XINT (end) - s; | |
1211 | 692 |
1029 | 693 if (i->position != s) |
694 { | |
695 /* No properties on this first interval -- return if | |
696 it covers the entire region. */ | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
697 if (! interval_has_some_properties (props, i)) |
1029 | 698 { |
699 int got = (LENGTH (i) - (s - i->position)); | |
700 if (got >= len) | |
701 return Qnil; | |
702 len -= got; | |
703 } | |
704 /* Remove the properties from this interval. If it's short | |
705 enough, return, splitting it if it's too short. */ | |
706 else | |
707 { | |
708 unchanged = i; | |
709 i = split_interval_right (unchanged, s - unchanged->position + 1); | |
710 copy_properties (unchanged, i); | |
711 if (LENGTH (i) > len) | |
712 { | |
713 i = split_interval_left (i, len + 1); | |
714 copy_properties (unchanged, i); | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
715 remove_properties (props, i); |
1029 | 716 return Qt; |
717 } | |
718 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
719 remove_properties (props, i); |
1029 | 720 modified = 1; |
721 len -= LENGTH (i); | |
722 i = next_interval (i); | |
723 } | |
724 } | |
725 | |
726 /* We are at the beginning of an interval, with len to scan */ | |
727 while (1) | |
728 { | |
729 if (LENGTH (i) >= len) | |
730 { | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
731 if (! interval_has_some_properties (props, i)) |
1029 | 732 return modified ? Qt : Qnil; |
733 | |
734 if (LENGTH (i) == len) | |
735 { | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
736 remove_properties (props, i); |
1029 | 737 return Qt; |
738 } | |
739 | |
740 /* i has the properties, and goes past the change limit */ | |
741 unchanged = split_interval_right (i, len + 1); | |
742 copy_properties (unchanged, i); | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
743 remove_properties (props, i); |
1029 | 744 return Qt; |
745 } | |
746 | |
747 len -= LENGTH (i); | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
748 modified += remove_properties (props, i); |
1029 | 749 i = next_interval (i); |
750 } | |
751 } | |
752 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
753 #if 0 /* You can use set-text-properties for this. */ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
754 |
1029 | 755 DEFUN ("erase-text-properties", Ferase_text_properties, |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
756 Serase_text_properties, 2, 3, 0, |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
757 "Remove all properties from the text from START to END.\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
758 The optional third argument, OBJECT,\n\ |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
759 is the string or buffer containing the text.") |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
760 (start, end, object) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
761 Lisp_Object start, end, object; |
1029 | 762 { |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
763 register INTERVAL i; |
1305 | 764 register INTERVAL prev_changed = NULL_INTERVAL; |
1029 | 765 register int s, len, modified; |
766 | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
767 if (NILP (object)) |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
768 XSET (object, Lisp_Buffer, current_buffer); |
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
769 |
1029 | 770 i = validate_interval_range (object, &start, &end, soft); |
771 if (NULL_INTERVAL_P (i)) | |
772 return Qnil; | |
773 | |
774 s = XINT (start); | |
775 len = XINT (end) - s; | |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
776 |
1029 | 777 if (i->position != s) |
778 { | |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
779 register int got; |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
780 register INTERVAL unchanged = i; |
1029 | 781 |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
782 /* If there are properties here, then this text will be modified. */ |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
783 if (! NILP (i->plist)) |
1029 | 784 { |
785 i = split_interval_right (unchanged, s - unchanged->position + 1); | |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
786 i->plist = Qnil; |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
787 modified++; |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
788 |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
789 if (LENGTH (i) > len) |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
790 { |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
791 i = split_interval_right (i, len + 1); |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
792 copy_properties (unchanged, i); |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
793 return Qt; |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
794 } |
1029 | 795 |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
796 if (LENGTH (i) == len) |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
797 return Qt; |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
798 |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
799 got = LENGTH (i); |
1029 | 800 } |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
801 /* If the text of I is without any properties, and contains |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
802 LEN or more characters, then we may return without changing |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
803 anything.*/ |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
804 else if (LENGTH (i) - (s - i->position) <= len) |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
805 return Qnil; |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
806 /* The amount of text to change extends past I, so just note |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
807 how much we've gotten. */ |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
808 else |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
809 got = LENGTH (i) - (s - i->position); |
1029 | 810 |
811 len -= got; | |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
812 prev_changed = i; |
1029 | 813 i = next_interval (i); |
814 } | |
815 | |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
816 /* We are starting at the beginning of an interval, I. */ |
1029 | 817 while (len > 0) |
818 { | |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
819 if (LENGTH (i) >= len) |
1029 | 820 { |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
821 /* If I has no properties, simply merge it if possible. */ |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
822 if (NILP (i->plist)) |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
823 { |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
824 if (! NULL_INTERVAL_P (prev_changed)) |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
825 merge_interval_left (i); |
1029 | 826 |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
827 return modified ? Qt : Qnil; |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
828 } |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
829 |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
830 if (LENGTH (i) > len) |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
831 i = split_interval_left (i, len + 1); |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
832 if (! NULL_INTERVAL_P (prev_changed)) |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
833 merge_interval_left (i); |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
834 else |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
835 i->plist = Qnil; |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
836 |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
837 return Qt; |
1029 | 838 } |
839 | |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
840 /* Here if we still need to erase past the end of I */ |
1029 | 841 len -= LENGTH (i); |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
842 if (NULL_INTERVAL_P (prev_changed)) |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
843 { |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
844 modified += erase_properties (i); |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
845 prev_changed = i; |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
846 } |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
847 else |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
848 { |
1283
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
849 modified += ! NILP (i->plist); |
6f4cbcc62eba
Minor optimizations of Fset_text_properties and Ferase_text_properties.
Joseph Arceneaux <jla@gnu.org>
parents:
1272
diff
changeset
|
850 /* Merging I will give it the properties of PREV_CHANGED. */ |
1272
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
851 prev_changed = i = merge_interval_left (i); |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
852 } |
bfd04f61eb16
Mods to Ferase_text_properties
Joseph Arceneaux <jla@gnu.org>
parents:
1211
diff
changeset
|
853 |
1029 | 854 i = next_interval (i); |
855 } | |
856 | |
857 return modified ? Qt : Qnil; | |
858 } | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
859 #endif /* 0 */ |
1029 | 860 |
861 void | |
862 syms_of_textprop () | |
863 { | |
864 DEFVAR_INT ("interval-balance-threshold", &interval_balance_threshold, | |
1715
cd23f7ef1bd0
* floatfns.c (Flog): Fix unescaped newline in string.
Jim Blandy <jimb@redhat.com>
parents:
1305
diff
changeset
|
865 "Threshold for rebalancing interval trees, expressed as the\n\ |
1029 | 866 percentage by which the left interval tree should not differ from the right."); |
867 interval_balance_threshold = 8; | |
868 | |
869 /* Common attributes one might give text */ | |
870 | |
871 staticpro (&Qforeground); | |
872 Qforeground = intern ("foreground"); | |
873 staticpro (&Qbackground); | |
874 Qbackground = intern ("background"); | |
875 staticpro (&Qfont); | |
876 Qfont = intern ("font"); | |
877 staticpro (&Qstipple); | |
878 Qstipple = intern ("stipple"); | |
879 staticpro (&Qunderline); | |
880 Qunderline = intern ("underline"); | |
881 staticpro (&Qread_only); | |
882 Qread_only = intern ("read-only"); | |
883 staticpro (&Qinvisible); | |
884 Qinvisible = intern ("invisible"); | |
885 | |
886 /* Properties that text might use to specify certain actions */ | |
887 | |
888 staticpro (&Qmouse_left); | |
889 Qmouse_left = intern ("mouse-left"); | |
890 staticpro (&Qmouse_entered); | |
891 Qmouse_entered = intern ("mouse-entered"); | |
892 staticpro (&Qpoint_left); | |
893 Qpoint_left = intern ("point-left"); | |
894 staticpro (&Qpoint_entered); | |
895 Qpoint_entered = intern ("point-entered"); | |
896 staticpro (&Qmodification); | |
897 Qmodification = intern ("modification"); | |
898 | |
899 defsubr (&Stext_properties_at); | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
900 defsubr (&Sget_text_property); |
1029 | 901 defsubr (&Snext_property_change); |
1211 | 902 defsubr (&Snext_single_property_change); |
1029 | 903 defsubr (&Sprevious_property_change); |
1211 | 904 defsubr (&Sprevious_single_property_change); |
1029 | 905 defsubr (&Sadd_text_properties); |
906 defsubr (&Sset_text_properties); | |
907 defsubr (&Sremove_text_properties); | |
1857
9d65dfc7bdb7
(Fadd_text_properties): Put OBJECT arg last. Make it optional.
Richard M. Stallman <rms@gnu.org>
parents:
1715
diff
changeset
|
908 /* defsubr (&Serase_text_properties); */ |
1029 | 909 } |
1302
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
910 |
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
911 #else |
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
912 |
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
913 lose -- this shouldn't be compiled if USE_TEXT_PROPERTIES isn't defined |
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
914 |
538cc0cd6d83
* textprop.c: Conditionalize all functions on
Joseph Arceneaux <jla@gnu.org>
parents:
1283
diff
changeset
|
915 #endif /* USE_TEXT_PROPERTIES */ |