I have this example function:
(defun enumerate-foo ()
(interactive)
(save-excursion
(let ((counter 0))
(goto-char (point-min))
(while (search-forward-regexp "\\<foo\\>" nil t)
(setq counter (1+ counter))
(let* ((b (copy-marker (match-beginning 0)))
(e (copy-marker (match-end 0)))
(foo-counter-overlay (make-overlay b e))
(overlay-counter
(propertize (format "[%d]" counter)
'face '(:background "DarkGoldenrod4")))
(overlay-string (concat "foo " overlay-counter)))
(overlay-put foo-counter-overlay 'display overlay-string)
(overlay-put foo-counter-overlay 'evaporate t))))))
If I use it in a buffer that conteins:
foo
foo
foo
foo
I get:
Now if I run (query-replace "foo" "bar" nil (point-min) (point-max))
the buffer "looks" unmodified:
My question is: How can I use the modification-hooks
overlay property to delete the overlay "if any character within the overlay is changed"?
I know I can use text-properties
instead but in my specific case I'd prefer to use overlays because I find easier to create toggle
specific functions.
insert-in-front-hooks
. I made some tests and it works. – Gabriele Dec 04 '23 at 10:06modification-hooks-before-string
variable into the 'closure environment' – dalanicolai Dec 04 '23 at 11:41