Question

I have about 20 overlays that are marked differently with a t -- e.g., 'ov-one; 'ov-two; 'ov-three. I'm looking for some assistance please to delete an entire list of overlays, instead of having a different mapc entry for each overlay. The current method is as follows:

(defun delete-the-overlays ()

  (mapc #'(lambda (o) (when (overlay-get o 'ov-one)
    (delete-overlay o))) (overlays-in (window-start) (window-end)))

  (mapc #'(lambda (o) (when (overlay-get o 'ov-two)
    (delete-overlay o))) (overlays-in (window-start) (window-end)))

  (mapc #'(lambda (o) (when (overlay-get o 'ov-three)
    (delete-overlay o))) (overlays-in (window-start) (window-end))) )

It would be cleaner to have a variable list and mapcar / dolist through it, but I haven't found any examples.

(defvar list-of-overlays '(ov-one ov-two ov-three))
Was it helpful?

Solution

A simple way to accomplish what (I think) you want is to add an additional overlay property, e.g., my-overlay, to each of the set of overlays. Then you need test only for that property, since all of them will have it. No need to test each overlay separately for a different property.

E.g., a given overlay would have, say, property ov-two, but it would also have property my-overlay. Another overlay would have, say, property ov-three, but it too would also have property my-overlay.

This is a pretty standard approach, IMO.

Note that if you do this you do not also need to keep a separate list of your overlays. (But nothing precludes you from doing that also.) Just as creating a list is one way to record a set, so is putting properties on an object a way to record a set: namely, the objects that have that property.

OTHER TIPS

How 'bout

(defun delete-the-overlays ()
  (dolist (o (overlays-in (window-start) (window-end)))
    (when (or (overlay-get o 'ov-one)
              (overlay-get o 'ov-two)
              (overlay-get o 'ov-three))
      (delete-overlay o))))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top