Lisp_Object *copy;
ptrdiff_t i;
- if (size)
- {
- Lisp_Object ovl
- = XVECTOR (last_overlay_modification_hooks)->contents[1];
-
- /* If the buffer of the first overlay in the array doesn't
- match the current buffer, then these modification hooks
- should not be run in this buffer. This could happen when
- some code calls some insdel functions, such as del_range_1,
- with the PREPARE argument false -- in that case this
- function is never called to record the overlay modification
- hook functions in the last_overlay_modification_hooks
- array, so anything we find there is not ours. */
- if (XMARKER (OVERLAY_START (ovl))->buffer != current_buffer)
- return;
- }
-
USE_SAFE_ALLOCA;
SAFE_ALLOCA_LISP (copy, size);
memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
Lisp_Object prop_i, overlay_i;
prop_i = copy[i++];
overlay_i = copy[i++];
- call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3);
+ /* It is possible that the recorded overlay has been deleted
+ (which makes it's markers' buffers be nil), or that (due to
+ some bug) it belongs to a different buffer. Only run this
+ hook if the overlay belongs to the current buffer. */
+ if (XMARKER (OVERLAY_START (overlay_i))->buffer == current_buffer)
+ call_overlay_mod_hooks (prop_i, overlay_i, after, arg1, arg2, arg3);
}
SAFE_FREE ();
(should (eq buf (current-buffer))))
(when msg-ov (delete-overlay msg-ov))))))
+(ert-deftest overlay-modification-hooks-deleted-overlay ()
+ "Test for bug#30823."
+ (let ((check-point nil)
+ (ov-delete nil)
+ (ov-set nil))
+ (with-temp-buffer
+ (insert "abc")
+ (setq ov-set (make-overlay 1 3))
+ (overlay-put ov-set 'modification-hooks
+ (list (lambda (_o after &rest _args)
+ (and after (setq check-point t)))))
+ (setq ov-delete (make-overlay 1 3))
+ (overlay-put ov-delete 'modification-hooks
+ (list (lambda (o after &rest _args)
+ (and (not after) (delete-overlay o)))))
+ (goto-char 2)
+ (insert "1")
+ (should (eq check-point t)))))
+
(ert-deftest test-generate-new-buffer-name-bug27966 ()
(should-not (string-equal "nil"
(progn (get-buffer-create "nil")