changeset 76301:fec7d780a786

(Finding Overlays): Write better example.
author Richard M. Stallman <rms@gnu.org>
date Sun, 04 Mar 2007 18:00:37 +0000
parents 656132bca5c0
children 41d7e08e95b7
files lispref/display.texi
diffstat 1 files changed, 13 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lispref/display.texi	Sun Mar 04 17:55:23 2007 +0000
+++ b/lispref/display.texi	Sun Mar 04 18:00:37 2007 +0000
@@ -1527,26 +1527,25 @@
 @code{(point-min)}.
 @end defun
 
-  Here's a function which uses @code{next-overlay-change} to search
-for the next character which gets a given property @code{prop} from
-either its overlays or its text properties (@pxref{Property Search}):
+  As an example, here's a simplified (and inefficient) version of the
+primitive function @code{next-single-char-property-change}
+(@pxref{Property Search}).  It searches forward from position
+@var{pos} for the next position where the value of a given property
+@code{prop}, as obtained from either overlays or text properties,
+changes.
 
 @smallexample
-(defun find-overlay-prop (prop)
+(defun next-single-char-property-change (position prop)
   (save-excursion
-    (while (and (not (eobp))
-                (not (get-char-property (point) prop)))
-      (goto-char (min (next-overlay-change (point))
-                      (next-single-property-change (point) prop))))
+    (goto-char position)
+    (let ((propval (get-char-property (point) prop)))
+      (while (and (not (eobp))
+                  (eq (get-char-property (point) prop) propval))
+        (goto-char (min (next-overlay-change (point))
+                        (next-single-property-change (point) prop)))))
     (point)))
 @end smallexample
 
-  Now you can search for a @code{happy} property like this:
-
-@smallexample
-(find-overlay-prop 'happy)
-@end smallexample
-
 @node Width
 @section Width