0. emacs -Q 1. Evaluate the following sexp: (progn (switch-to-buffer (get-buffer-create "*test*")) (insert "one two three") (setq ov1 (make-overlay 1 4)) (setq ov2 (make-overlay 5 9)) (setq ov3 (make-overlay 9 14)) (sit-for 1) (overlay-put ov1 'display "two") (overlay-put ov2 'display "") (overlay-put ov3 'after-string " four") (sit-for 1) (remove-overlays nil nil 'display "two") (remove-overlays nil nil 'display "") (sit-for 1) (remove-overlays nil nil 'after-string)) In buffer *test* you see the following: 1. First: one two three 2. Then after one second: two three four 3. Then after another second: two two three four 4. Finally, after one more second: one two three four I think the last two displays demonstrate buggy behavior. In the third, remove-overlays has failed to clear the display string "two" but has cleared the empty string. In the fourth, the remove-overlays call specified the after-string property, yet what has been cleared is the display overlay "two" but not the after-string overlay "four". The reason for the first problem is that remove-overlays tests the overlay value with eq, which fails for all strings except the empty string. Hence, both the display overlay "two" and the after-string overlay "four" are not cleared by the second and third calls of remove-overlays, respectively. But the third call does remove "two" because overlay-get tries to get the value of the overlay's after-string property, but it only has a display property, so overlay-get returns nil, and since the fourth argument of remove-overlays is also nil here, they are eq, so the overlay is cleared. The general problem here, I believe, is that, although all the arguments of remove-overlays are optional (so the last invocation of remove-overlays is legitimate), the logic of the code is that the NAME and VAL arguments are either both nil or both non-nil, which conflicts with the semantics of the &optional keyword. I think the easiest and best fix is to make the NAME and VAL arguments conform to the &optional semantics by allowing independent values. This means that the last call of remove-overlays in the above sexp would clear any after-string overlays, regardless of their value. I think this would be useful, and it is backward compatible, because all uses of remove-overlays in Emacs have either both or neither of the NAME and VAL arguments (and any third-party code that only has the NAME argument is either buggy, like the above sexp, or works by chance). The patch below implements this, and also fixes the first problem by testing with equal if the eq test fails. 2013-02-07 Stephen Berman * subr.el (remove-overlays): Handle string and list values of overlay properties. If the property argument is non-nil and the value argument is nil, clear all overlays with that property regardless of their values. (Bug#XXXXX)