comparison lispref/display.texi @ 76301:fec7d780a786

(Finding Overlays): Write better example.
author Richard M. Stallman <rms@gnu.org>
date Sun, 04 Mar 2007 18:00:37 +0000
parents bdb0a4edf3b9
children adfa1b509013 91bf6e05918b
comparison
equal deleted inserted replaced
76300:656132bca5c0 76301:fec7d780a786
1525 This function returns the buffer position of the previous beginning or 1525 This function returns the buffer position of the previous beginning or
1526 end of an overlay, before @var{pos}. If there is none, it returns 1526 end of an overlay, before @var{pos}. If there is none, it returns
1527 @code{(point-min)}. 1527 @code{(point-min)}.
1528 @end defun 1528 @end defun
1529 1529
1530 Here's a function which uses @code{next-overlay-change} to search 1530 As an example, here's a simplified (and inefficient) version of the
1531 for the next character which gets a given property @code{prop} from 1531 primitive function @code{next-single-char-property-change}
1532 either its overlays or its text properties (@pxref{Property Search}): 1532 (@pxref{Property Search}). It searches forward from position
1533 @var{pos} for the next position where the value of a given property
1534 @code{prop}, as obtained from either overlays or text properties,
1535 changes.
1533 1536
1534 @smallexample 1537 @smallexample
1535 (defun find-overlay-prop (prop) 1538 (defun next-single-char-property-change (position prop)
1536 (save-excursion 1539 (save-excursion
1537 (while (and (not (eobp)) 1540 (goto-char position)
1538 (not (get-char-property (point) prop))) 1541 (let ((propval (get-char-property (point) prop)))
1539 (goto-char (min (next-overlay-change (point)) 1542 (while (and (not (eobp))
1540 (next-single-property-change (point) prop)))) 1543 (eq (get-char-property (point) prop) propval))
1544 (goto-char (min (next-overlay-change (point))
1545 (next-single-property-change (point) prop)))))
1541 (point))) 1546 (point)))
1542 @end smallexample
1543
1544 Now you can search for a @code{happy} property like this:
1545
1546 @smallexample
1547 (find-overlay-prop 'happy)
1548 @end smallexample 1547 @end smallexample
1549 1548
1550 @node Width 1549 @node Width
1551 @section Width 1550 @section Width
1552 1551