Fix tp-intervals to handle 1-based buffer positions correctly

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-01-04 13:10:55 +00:00
parent b58065293b
commit 93f61e5ba0

20
tp.el
View File

@ -185,16 +185,24 @@ FORMAT-STRING and ARGS are passed to `format'."
(defun tp-intervals (start end &optional object)
"Return list of property intervals from START to END in OBJECT.
Each element is (START END PROPERTIES). OBJECT defaults to current buffer."
(let ((intervals (object-intervals (or object (current-buffer)))))
Each element is (START END PROPERTIES). OBJECT defaults to current buffer.
For buffers, returns positions relative to START (0-based offsets).
For strings, returns absolute positions."
(let* ((intervals (object-intervals (or object (current-buffer))))
;; For buffers, object-intervals returns 0-based positions
;; but buffer positions are 1-based, so we need to adjust
(offset (if (stringp object) 0 (1- start)))
;; Filter bounds in 0-based terms for buffers
(filter-start (if (stringp object) start offset))
(filter-end (if (stringp object) end (1- end))))
(mapcar (lambda (tp)
(let* ((tp-start (- (nth 0 tp) (if (stringp object) 0 start)))
(tp-end (- (nth 1 tp) (if (stringp object) 0 start)))
(let* ((tp-start (- (nth 0 tp) offset))
(tp-end (- (nth 1 tp) offset))
(tp-props (nth 2 tp)))
(list tp-start tp-end tp-props)))
(seq-filter (lambda (tp)
(and (< (nth 0 tp) (if (stringp object) end (+ start end)))
(> (nth 1 tp) (if (stringp object) start 0))))
(and (< (nth 0 tp) filter-end)
(> (nth 1 tp) filter-start)))
intervals))))
(defun tp-empty-p (&optional object)