From db63cada789bce562c80d9db3a941deb32cb4ef0 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Wed, 7 Jun 2006 21:51:00 +0000 Subject: Make emms-property-region bulletproof. darcs-hash:20060607215113-1bfb2-1d5710b9112fb1ed36d1a65d4ed432d643bdd863.gz --- emms.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/emms.el b/emms.el index 1b81888..bded095 100644 --- a/emms.el +++ b/emms.el @@ -1025,10 +1025,21 @@ ignore this." ;;; Helper functions (defun emms-property-region (pos prop) - "Return a pair of the beginning and end of the property PROP at POS." - ;; This +/-1 stuff DTRT, but _is_ it TRT? - (let ((begin (previous-single-property-change (+ pos 1) prop)) - (end (next-single-property-change (- pos 1) prop))) + "Return a pair of the beginning and end of the property PROP at POS. +If POS does not contain PROP, try to find PROP just before POS." + (let (begin end) + (if (and (> pos (point-min)) + (get-text-property (1- pos) prop)) + (setq begin (previous-single-property-change (1- pos) prop)) + (if (get-text-property pos prop) + (setq begin pos) + (error "Cannot find the %s property at the given position" prop))) + (if (get-text-property pos prop) + (setq end (next-single-property-change pos prop)) + (if (and (> pos (point-min)) + (get-text-property (1- pos) prop)) + (setq end pos) + (error "Cannot find the %s property at the given position" prop))) (cons (or begin (point-min)) (or end (point-max))))) -- cgit v1.2.3