How can I get the previous-or-equal single property change for a given property? For example, assume AAA
, BBB
, and CCC
below have different face
s.
AAABBBCCC
Here is the return value that I would like to get for each position:
AAABBBCCC
111444777
Contrast to what previous-single-char-property-change
returns:
AAABBBCCC
111144477
Essentially, the problem is that (previous-single-char-property-change (point-max) 'face)
returns 4
instead of 7
. I thought I could just use (previous-single-char-property-change (1+ (point) 'face)
instead, but that breaks on (point-max)
, unfortunately.
How can I achieve get the previous-or-equal single char property change, taking into account the starting position?
Here is some code to reproduce the example:
(with-current-buffer (get-buffer-create "*test*")
(erase-buffer)
(insert "AAABBBCCC")
(mapc #'delete-overlay (overlays-in (point-min) (point-max)))
(overlay-put (make-overlay 1 4) 'face '(:background "red"))
(overlay-put (make-overlay 4 7) 'face '(:background "blue"))
(overlay-put (make-overlay 7 10) 'face '(:background "green"))
(pop-to-buffer (current-buffer)))
Some background: for a major mode that I'm writing I need to read information from the overlay (if any) that precedes (and does not cover) the current point.
point-max
is the only place where you have a problem, can't you just make your own version of the function that does what you want and treats(eq (point) (point-max))
as a special case? – nispio Jun 15 '16 at 2:11(previous-single-char-property-change POSITION PROP &optional OBJECT LIMIT)
– lawlist Jun 15 '16 at 2:41ert
for testingfont-lock
rules) I had the same problem (but for forward searches). Effectively, the functionfaceup-next-property-change
returnspoint-min
if 1) nil was passed as the start position and 2) there were relevant text properties on the first character. Otherwise, the real next position was returned. – Lindydancer Jun 16 '16 at 8:04