3 ;; This function is not translated well
4 (defun validate-interval-range (object begin end force
)
6 ;; /* If we are asked for a point, but from a subr which operates
7 ;; on a range, then return nothing. */
8 ;; if (EQ (*begin, *end) && begin != end)
9 ;; return NULL_INTERVAL;
11 ;; MOVITZ doesn't have psetf
18 (if (typep object
'buffer
)
20 (when (not (and (<= (buffer-min object
) begin
)
22 (<= end
(buffer-max object
))))
23 (signal 'args-out-of-range
))
24 (setf i
(intervals object
))
25 (when (= (buffer-min object
) (buffer-max object
))
26 (return-from validate-interval-range
(values nil begin end
)))
27 (setf searchpos begin
))
28 (let ((len (length (pstring-data object
))))
29 (when (not (and (<= 0 begin
)
32 (signal 'args-out-of-range
))
33 (setf i
(intervals object
))
35 (return-from validate-interval-range
(values nil begin end
)))
36 (setf searchpos begin
)))
38 (values (find-interval i searchpos
) begin end
)
40 (values (create-root-interval object
) begin end
)
41 (values i begin end
)))))
43 (defun set-text-properties (start end properties
&optional
(object (current-buffer)))
44 (let ((start-bk start
)
47 (setf properties
(validate-plist properties
))
48 ;; If we want no properties for a whole string, get rid of its
50 (when (and (null properties
)
51 (typep object
'pstring
)
53 (= end
(length (pstring-data object
))))
54 (when (null (intervals object
))
55 (return-from set-text-properties t
))
56 (setf (intervals object
) nil
)
57 (return-from set-text-properties t
))
58 (multiple-value-setq (i start end
)
59 (validate-interval-range object start end nil
))
61 (when (null properties
)
62 (return-from set-text-properties nil
))
63 ;; /* Restore the original START and END values because
64 ;; validate_interval_range increments them for strings. */
67 (multiple-value-setq (i start end
)
68 (validate-interval-range object start end t
))
69 ;; /* This can return if start == end. */
71 (return-from set-text-properties nil
)))
74 ;; (when (typep object 'buffer)
75 ;; ;; modify_region (XBUFFER (object), XINT (start), XINT (end));
76 (set-text-properties-1 start end properties object i
)
78 ;; if (BUFFERP (object) && !NILP (signal_after_change_p))
79 ;; signal_after_change (XINT (start), XINT (end) - XINT (start),
80 ;; XINT (end) - XINT (start));
83 (defun set-text-properties-1 (start end properties buffer i
)
84 (let ((len (- end start
))
88 (return-from set-text-properties-1
))
93 (setf i
(find-interval (intervals buffer
) start
)))
94 (when (/= (interval-pt i
) start
)
96 i
(split-interval-right unchanged
(- start
(interval-pt unchanged
))))
97 (when (> (interval-text-length i
) len
)
98 (copy-properties unchanged i
)
99 (setf i
(split-interval-left i len
))
100 (set-properties properties i buffer
)
101 (return-from set-text-properties-1
))
102 (set-properties properties i buffer
)
103 (when (= (interval-text-length i
) len
)
104 (return-from set-text-properties-1
))
105 (setf prev-changed i
)
106 (decf len
(interval-text-length i
))
107 (setf i
(next-interval i
)))
111 (when (>= (interval-text-length i
) len
)
112 (when (> (interval-text-length i
) len
)
113 (setf i
(split-interval-left i len
)))
114 (set-properties properties i buffer
)
116 (merge-interval-left i
))
117 (return-from set-text-properties-1
))
118 (decf len
(interval-text-length i
))
119 ;; We have to call set_properties even if we are going
120 ;; to merge the intervals, so as to make the undo
121 ;; records and cause redisplay to happen.
122 (set-properties properties i buffer
)
123 (if (null prev-changed
)
124 (setf prev-changed i
)
125 (setf prev-changed
(merge-interval-left i
)
127 (setf i
(next-interval i
)))))
129 (defun copy-properties (source target
)
130 (when (and (default-interval-p source
)
131 (default-interval-p target
))
132 (return-from copy-properties
))
133 (setf (interval-plist target
) (copy-list (interval-plist source
))))
135 (defun set-properties (properties interval object
)
136 (when (typep object
'buffer
)
139 (setf (interval-plist interval
) (copy-tree properties
)))
141 (defun add-properties (plist i object
)
142 "Add the properties in plist to interval I. OBJECT should be the
143 string of buffer containing the interval."
144 (declare (ignore object
))
146 (doplist (sym val plist changed
)
147 (let ((found (getf (interval-plist i
) sym
)))
150 ;; record-property-change
151 (when (not (eql found val
))
152 (setf (getf (interval-plist i
) sym
) val
155 ;; record-property-change
156 (setf (getf (interval-plist i
) sym
) val
159 (defun validate-plist (list)
160 "/* Validate LIST as a property list. If LIST is not a list, then
161 make one consisting of (LIST nil). Otherwise, verify that LIST is
162 even numbered and thus suitable as a plist. */"
163 (cond ((null list
) nil
)
165 (if (oddp (length list
))
166 (error "odd length property list")
168 (t (list (list list nil
)))))
170 (defun interval-has-all-properties (plist i
)
171 "/* Return nonzero if interval I has all the properties, with the same
172 values, of list PLIST. */"
173 (doplist (sym val plist t
)
174 (let ((found (getf (interval-plist i
) sym
)))
176 (when (not (eql found val
))
177 (return-from interval-has-all-properties nil
))
178 (return-from interval-has-all-properties nil
)))))
180 (defun add-text-properties (start end properties
&optional
(object (current-buffer)))
181 "Add properties to the text from START to END. The third argument
182 PROPERTIES is a property list specifying the property values to add.
183 If the optional fourth argument OBJECT is a buffer (or nil, which
184 means the current buffer), START and END are buffer positions
185 (integers or markers). If OBJECT is a string, START and END are
186 0-based indices into it. Return t if any property value actually
187 changed, nil otherwise."
188 (let ((len (- end start
))
191 (setf properties
(validate-plist properties
))
192 (when (null properties
)
193 (return-from add-text-properties nil
))
194 (multiple-value-setq (i start end
) (validate-interval-range object start end t
))
196 (return-from add-text-properties nil
))
197 ;; If we're not starting on an interval boundary, we have to split
199 (when (/= (interval-pt i
) start
)
200 (if (interval-has-all-properties properties i
)
201 (let ((got (- (interval-text-length i
) (- start
(interval-pt i
)))))
203 (return-from add-text-properties nil
))
205 (setf i
(next-interval i
)))
208 (setf i
(split-interval-right unchanged
(- start
(interval-pt unchanged
))))
209 (copy-properties unchanged i
))))
210 ;; if (BUFFERP (object))
211 ;; modify_region (XBUFFER (object), XINT (start), XINT (end));
213 ;; We are at the beginning of interval I, with LEN chars to scan.
217 (when (>= (interval-text-length i
) len
)
218 (when (interval-has-all-properties properties i
)
219 (return-from add-text-properties modified
))
220 (when (= (interval-text-length i
) len
)
221 (add-properties properties i object
)
222 (return-from add-text-properties t
))
224 i
(split-interval-left unchanged len
))
225 (copy-properties unchanged i
)
226 (add-properties properties i object
)
227 (return-from add-text-properties t
))
228 (decf len
(interval-text-length i
))
229 (setf modified
(add-properties properties i object
)
230 i
(next-interval i
)))))
232 (defun put-text-property (start end property value object
)
233 "Set one property of the text from START to END. The third and
234 fourth arguments PROPERTY and VALUE specify the property to add. If
235 the optional fifth argument OBJECT is a buffer (or nil, which means
236 the current buffer), START and END are buffer positions (integers or
237 markers). If OBJECT is a string, START and END are 0-based indices
239 (add-text-properties start end
(list property value
) object
))
241 (defun remove-properties (plist list i object
)
242 (declare (ignore object
))
243 (doplist (sym val plist
)
244 (declare (ignore val
))
245 (remf sym
(interval-plist i
)))
247 (remf sym
(interval-plist i
))))
249 (defun remove-text-properties (start end properties
&optional
(object (current-buffer)))
250 "Remove some properties from text from START to END. The third
251 argument PROPERTIES is a property list whose property names specify
252 the properties to remove. \(The values stored in PROPERTIES are
253 ignored.) If the optional fourth argument OBJECT is a buffer (or nil,
254 which means the current buffer), START and END are buffer positions
255 (integers or markers). If OBJECT is a string, START and END are
256 0-based indices into it. Return t if any property was actually
257 removed, nil otherwise.
259 Use set-text-properties if you want to remove all text properties."
260 (let (i unchanged len
(modified nil
))
261 (multiple-value-setq (i start end
)
262 (validate-interval-range object start end nil
))
264 (return-from remove-text-properties nil
))
265 (setf len
(- end start
))
266 (when (/= (interval-pt i
) start
)
267 (if (not (interval-has-all-properties properties i
))
268 (let ((got (- (interval-text-length i
) (- start
(interval-pt i
)))))
270 (return-from remove-text-properties nil
))
272 (setf i
(next-interval i
)))
275 i
(split-interval-right unchanged
(- start
(interval-pt unchanged
))))
276 (copy-properties unchanged i
))))
280 (when (>= (interval-text-length i
) len
)
281 (unless (interval-has-all-properties properties i
)
282 (return-from remove-text-properties modified
))
283 (when (= (interval-text-length i
) len
)
284 (remove-properties properties nil i object
)
285 (return-from remove-text-properties t
))
287 i
(split-interval-left i len
))
288 (copy-properties unchanged i
)
289 (remove-properties properties nil i object
)
290 (return-from remove-text-properties t
))
291 (decf len
(interval-text-length i
))
292 (setf modified
(remove-properties properties nil i object
)
293 i
(next-interval i
)))))
295 (defun next-single-char-property-change (position prop
&optional
(object (current-buffer)) limit
)
296 "/* Return the position of next text property or overlay change for a specific property.
297 Scans characters forward from POSITION till it finds
298 a change in the PROP property, then returns the position of the change.
299 If the optional third argument OBJECT is a buffer (or nil, which means
300 the current buffer), POSITION is a buffer position (integer or marker).
301 If OBJECT is a string, POSITION is a 0-based index into it.
303 The property values are compared with `eql' by default.
304 If the property is constant all the way to the end of OBJECT, return the
305 last valid position in OBJECT.
306 If the optional fourth argument LIMIT is non-nil, don't search
307 past position LIMIT; return LIMIT if nothing is found before LIMIT. */"
308 (if (typep object
'pstring
)
310 (setf position
(next-single-property-change position prop object limit
))
313 (setf position
(pstring-length object
))
314 (setf position limit
))))
315 (let ((initial-value (get-char-property position prop object
))
317 ;; (when (and (typep object 'buffer)
318 ;; (not (eq object (current-buffer))))
321 (setf limit
(buffer-max object
)))
323 (setf position
(next-char-property-change position limit object
))
324 (when (>= position limit
)
326 (setf value
(get-char-property position prop object
))
327 (unless (eq value initial-value
)
328 (return position
))))))
330 (defun text-properties-at (position &optional
(object (current-buffer)))
331 (multiple-value-bind (i position
) (validate-interval-range object position position t
)
333 ;; If POSITION is at the end of the interval,
334 ;; it means it's the end of OBJECT.
335 ;; There are no properties at the very end,
336 ;; since no character follows.
337 (unless (= position
(+ (interval-text-length i
) (interval-pt i
)))
338 (interval-plist i
)))))
340 (defun get-text-property (position prop
&optional
(object (current-buffer)))
341 (getf (text-properties-at position object
) prop
))
343 (defun get-char-property-and-overlay (position prop object overlay
)
344 (declare (ignore overlay
))
345 (get-text-property position prop object
))
347 (defun get-char-property (position prop
&optional
(object (current-buffer)))
348 (get-char-property-and-overlay position prop object
0))
350 (defun previous-single-char-property-change (position prop
&optional
(object (current-buffer)) limit
)
351 (cond ((typep object
'pstring
)
352 (setf position
(previous-single-property-change position prop object limit
))
353 (when (null position
)
354 (setf position
(or limit
355 (pstring-length object
)))))
358 (setf limit
(buffer-min object
)))
359 (if (<= position limit
)
360 (setf position limit
)
361 (let ((initial-value (get-char-property (1- position
) prop object
))
364 (setf position
(previous-char-property-change position limit object
))
365 (when (<= position limit
)
367 (setf value
(get-char-property (1- position
) prop object
))
368 (unless (eq value initial-value
)
369 (return position
))))))))
371 (defun next-property-change (position &optional object limit
)
372 "Return the position of next property change.
373 Scans characters forward from POSITION in OBJECT till it finds
374 a change in some text property, then returns the position of the change.
375 If the optional second argument OBJECT is a buffer (or nil, which means
376 the current buffer), POSITION is a buffer position (integer or marker).
377 If OBJECT is a string, POSITION is a 0-based index into it.
378 Return nil if the property is constant all the way to the end of OBJECT.
379 If the value is non-nil, it is a position greater than POSITION, never equal.
381 If the optional third argument LIMIT is non-nil, don't search
382 past position LIMIT; return LIMIT if nothing is found before LIMIT."
384 (multiple-value-setq (i position
) (validate-interval-range object position position nil
))
386 (setf next
(if (null i
)
389 (setf position
(if (null next
)
390 (cond ((typep object
'pstring
) (pstring-length object
))
391 ((typep object
'buffer
) (buffer-max object
)))
393 (return-from next-property-change position
))
396 (return-from next-property-change limit
))
397 (setf next
(next-interval i
))
399 (intervals-equal i next
)
401 (< (interval-pt next
)
403 (setf next
(next-interval next
)))
405 (return-from next-property-change limit
))
407 (setf limit
(cond ((typep object
'pstring
) (pstring-length object
))
408 ((typep object
'buffer
) (buffer-max object
)))))
409 (unless (< (interval-pt next
) limit
)
410 (return-from next-property-change limit
))
411 ;; FIXME: This is silly code.
412 (setf position
(interval-pt next
))
415 (defun next-char-property-change (position &optional limit
(buffer (current-buffer)))
416 "Return the position of next text property or overlay change.
417 This scans characters forward in the current buffer from POSITION till
418 it finds a change in some text property, or the beginning or end of an
419 overlay, and returns the position of that.
420 If none is found, the function returns (point-max).
422 If the optional third argument LIMIT is non-nil, don't search
423 past position LIMIT; return LIMIT if nothing is found before LIMIT."
424 ;; temp = Fnext_overlay_change (position);
425 (next-property-change position buffer
(or limit
(buffer-max buffer
))))
427 (defun previous-char-property-change (position &optional limit
(buffer (current-buffer)))
428 "Return the position of previous text property or overlay change.
429 Scans characters backward in the current buffer from POSITION till it
430 finds a change in some text property, or the beginning or end of an
431 overlay, and returns the position of that.
432 If none is found, the function returns (point-max).
434 If the optional third argument LIMIT is non-nil, don't search
435 past position LIMIT; return LIMIT if nothing is found before LIMIT."
436 (previous-property-change position buffer
(or limit
(buffer-min buffer
))))
438 (defun next-single-property-change (position prop
&optional
(object (current-buffer)) limit
)
439 (let (i next here-val
)
440 (multiple-value-setq (i position
)
441 (validate-interval-range object position position nil
))
443 (return-from next-single-property-change limit
))
444 (setf here-val
(getf (interval-plist i
) prop
)
445 next
(next-interval i
))
446 ;; walk the intervals til we find one with a different plist val
449 (eql here-val
(getf (interval-plist next
) prop
))
451 (< (interval-pt next
) limit
)))
452 (setf next
(next-interval next
)))
453 ;; FIXME: this code should be cleaned.
455 (return-from next-single-property-change limit
))
456 (setf limit
(or limit
457 (cond ((typep object
'pstring
) (pstring-length object
))
458 ((typep object
'buffer
) (buffer-max object
)))))
459 (when (>= (interval-pt next
) limit
)
460 (return-from next-single-property-change limit
))
463 (defun previous-single-property-change (position prop
&optional
(object (current-buffer)) limit
)
464 (let (i previous here-val
)
465 (multiple-value-setq (i position
) (validate-interval-range object position position nil
))
467 (= (interval-pt i
) position
))
468 (setf i
(previous-interval i
)))
470 (return-from previous-single-property-change limit
))
471 (setf here-val
(getf (interval-plist i
) prop
)
472 previous
(previous-interval i
))
474 (eql here-val
(getf (interval-plist previous
) prop
))
476 (> (+ (interval-pt previous
) (interval-text-length previous
))
478 (setf previous
(previous-interval previous
)))
479 ;; FIXME: this code should be cleaned.
480 (when (null previous
)
481 (return-from previous-single-property-change limit
))
482 (setf limit
(or limit
483 (cond ((typep object
'pstring
) 0)
484 ((typep object
'buffer
) (buffer-min object
)))))
485 (when (<= (+ (interval-pt previous
) (interval-text-length previous
))
487 (return-from previous-single-property-change limit
))
488 (+ (interval-pt previous
) (interval-text-length previous
))))
490 (defun previous-property-change (position &optional
(object (current-buffer)) limit
)
491 "Return the position of previous property change.
492 Scans characters backwards from POSITION in OBJECT till it finds
493 a change in some text property, then returns the position of the change.
494 If the optional second argument OBJECT is a buffer (or nil, which means
495 the current buffer), POSITION is a buffer position (integer or marker).
496 If OBJECT is a string, POSITION is a 0-based index into it.
497 Return nil if the property is constant all the way to the start of OBJECT.
498 If the value is non-nil, it is a position less than POSITION, never equal.
500 If the optional third argument LIMIT is non-nil, don't search
501 back past position LIMIT; return LIMIT if nothing is found until LIMIT."
503 (multiple-value-setq (i position
) (validate-interval-range object position position nil
))
505 (return-from previous-property-change limit
))
506 (when (= (interval-pt i
) position
)
507 (setf i
(previous-interval i
)))
508 (setf previous
(previous-interval i
))
510 (intervals-equal previous i
)
512 (> (+ (interval-pt previous
)
513 (interval-text-length previous
))
515 (setf previous
(previous-interval previous
)))
516 ;; FIXME: this code needs cleaning
517 (when (null previous
)
518 (return-from previous-property-change limit
))
519 (setf limit
(or limit
520 (cond ((typep object
'pstring
) 0)
521 ((typep object
'buffer
) (buffer-min object
)))))
522 (when (<= (+ (interval-pt previous
) (interval-text-length previous
))
524 (return-from previous-property-change limit
))
525 (+ (interval-pt previous
) (interval-text-length previous
))))
527 (defun text-property-stickiness (prop pos
&optional
(buffer (current-buffer)))
528 "Return the direction from which the text-property PROP would be
529 inherited by any new text inserted at POS: AFTER if it would be
530 inherited from the char after POS, BEFORE if it would be inherited from
531 the char before POS, and NIL if from neither.
532 BUFFER can be either a buffer or nil (meaning current buffer)."
533 (labels ((tmem (sym set
)
534 ;; Test for membership, allowing for t (actually any
535 ;; non-cons) to mean the universal set."
539 (let ((is-rear-sticky t
)
540 (is-front-sticky nil
)
541 prev-pos front-sticky
)
542 (when (> pos
(begv buffer
))
543 ;; Consider previous character.
544 (setf prev-pos
(1- pos
))
545 (let ((rear-non-sticky (get-text-property prev-pos
'rear-nonsticky buffer
)))
546 (when (tmem prop rear-non-sticky
)
547 ;; PROP is rear-non-sticky
548 (setf is-rear-sticky nil
))))
549 ;; Consider following character.
550 (setf front-sticky
(get-text-property pos
'front-sticky buffer
))
551 (when (or (eq front-sticky t
)
552 (and (consp front-sticky
)
553 (find prop front-sticky
)))
554 ;; PROP is inherited from after
555 (setf is-front-sticky t
))
558 ;; Simple cases, where the properties are consistent.
560 (not is-front-sticky
))
562 ((and (not is-rear-sticky
)
565 ((and (not is-rear-sticky
)
566 (not is-front-sticky
))
568 ((or (= pos
(begv buffer
))
569 (null (get-text-property prev-pos prop buffer
)))
574 (provide :lice-0.1
/textprop
)