void
adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length)
{
- /* After an insertion, the lists are still sorted properly,
- but we may need to update the value of the overlay center. */
- if (! current_buffer->overlays)
- return;
- itree_insert_gap (current_buffer->overlays, pos, length);
+ if (!current_buffer->indirections)
+ itree_insert_gap (current_buffer->overlays, pos, length);
+ else
+ {
+ struct buffer *base = current_buffer->base_buffer
+ ? current_buffer->base_buffer
+ : current_buffer;
+ Lisp_Object tail, other;
+ itree_insert_gap (base->overlays, pos, length);
+ FOR_EACH_LIVE_BUFFER (tail, other)
+ if (XBUFFER (other)->base_buffer == base)
+ itree_insert_gap (XBUFFER (other)->overlays, pos, length);
+ }
}
void
adjust_overlays_for_delete (ptrdiff_t pos, ptrdiff_t length)
{
- if (! current_buffer->overlays)
- return;
- itree_delete_gap (current_buffer->overlays, pos, length);
+ if (!current_buffer->indirections)
+ itree_delete_gap (current_buffer->overlays, pos, length);
+ else
+ {
+ struct buffer *base = current_buffer->base_buffer
+ ? current_buffer->base_buffer
+ : current_buffer;
+ Lisp_Object tail, other;
+ itree_delete_gap (base->overlays, pos, length);
+ FOR_EACH_LIVE_BUFFER (tail, other)
+ if (XBUFFER (other)->base_buffer == base)
+ itree_delete_gap (XBUFFER (other)->overlays, pos, length);
+ }
}
\f
itree_insert_gap (struct itree_tree *tree,
ptrdiff_t pos, ptrdiff_t length)
{
- if (length <= 0 || tree->root == NULL)
+ if (!tree || length <= 0 || tree->root == NULL)
return;
uintmax_t ootick = tree->otick;
itree_delete_gap (struct itree_tree *tree,
ptrdiff_t pos, ptrdiff_t length)
{
- if (length <= 0 || tree->root == NULL)
+ if (!tree || length <= 0 || tree->root == NULL)
return;
/* FIXME: Don't allocate stack anew every time. */
(with-temp-buffer
(should (eq (buffer-base-buffer (current-buffer)) nil))))
+(ert-deftest buffer-tests--overlays-indirect-bug58928 ()
+ (with-temp-buffer
+ (insert "hello world")
+ (let* ((base (current-buffer))
+ (ol1 (make-overlay (+ 2 (point-min)) (+ 8 (point-min))))
+ (ib (make-indirect-buffer
+ base (generate-new-buffer-name "bug58928")))
+ (ol2 (with-current-buffer ib
+ (make-overlay (+ 2 (point-min)) (+ 8 (point-min))))))
+ (should (equal (overlay-start ol1) (overlay-start ol2)))
+ (should (equal (overlay-end ol1) (overlay-end ol2)))
+ (goto-char (+ 3 (point-min)))
+ (insert "a") (delete-char 2)
+ (should (equal (overlay-start ol1) (overlay-start ol2)))
+ (should (equal (overlay-end ol1) (overlay-end ol2)))
+ (with-current-buffer ib
+ (goto-char (+ 4 (point-min)))
+ (insert "a") (delete-char 2))
+ (should (equal (overlay-start ol1) (overlay-start ol2)))
+ (should (equal (overlay-end ol1) (overlay-end ol2))))))
+
(ert-deftest overlay-evaporation-after-killed-buffer ()
(let* ((ols (with-temp-buffer
(insert "toto")