Function: remove-overlays

remove-overlays is a byte-compiled function defined in subr.el.gz.

Signature

(remove-overlays &optional BEG END NAME VAL)

Documentation

Remove overlays between BEG and END that have property NAME with value VAL.

Overlays might be moved and/or split. If any targeted overlays start before BEG, the overlays will be altered so that they end at BEG. Likewise, if the targeted overlays end after END, they will be altered so that they start at END. Overlays that start at or after BEG and end before END will be removed completely.

BEG and END default respectively to the beginning and end of the buffer. Values are compared with eq. If either NAME or VAL are specified, both should be specified.

Probably introduced at or before Emacs version 22.1.

Aliases

bubbles--remove-overlays (obsolete since 28.1)

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun remove-overlays (&optional beg end name val)
  "Remove overlays between BEG and END that have property NAME with value VAL.
Overlays might be moved and/or split.  If any targeted overlays
start before BEG, the overlays will be altered so that they end
at BEG.  Likewise, if the targeted overlays end after END, they
will be altered so that they start at END.  Overlays that start
at or after BEG and end before END will be removed completely.

BEG and END default respectively to the beginning and end of the
buffer.
Values are compared with `eq'.
If either NAME or VAL are specified, both should be specified."
  ;; This speeds up the loops over overlays.
  (unless beg (setq beg (point-min)))
  (unless end (setq end (point-max)))
  (overlay-recenter end)
  (if (< end beg)
      (setq beg (prog1 end (setq end beg))))
  (save-excursion
    (dolist (o (overlays-in beg end))
      (when (eq (overlay-get o name) val)
	;; Either push this overlay outside beg...end
	;; or split it to exclude beg...end
	;; or delete it entirely (if it is contained in beg...end).
	(if (< (overlay-start o) beg)
	    (if (> (overlay-end o) end)
		(progn
		  (move-overlay (copy-overlay o)
				(overlay-start o) beg)
		  (move-overlay o end (overlay-end o)))
	      (move-overlay o (overlay-start o) beg))
	  (if (> (overlay-end o) end)
	      (move-overlay o end (overlay-end o))
	    (delete-overlay o)))))))