From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#13648: 24.3.50; remove-overlays bugs Date: Thu, 07 Feb 2013 16:09:21 +0100 Message-ID: <8738x8b1pa.fsf@rosalinde.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1360249852 11937 80.91.229.3 (7 Feb 2013 15:10:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 7 Feb 2013 15:10:52 +0000 (UTC) To: 13648@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 07 16:11:13 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U3T84-0003HP-WD for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Feb 2013 16:11:13 +0100 Original-Received: from localhost ([::1]:38435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3T7m-0004yC-3k for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Feb 2013 10:10:54 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:58464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3T7g-0004xz-PH for bug-gnu-emacs@gnu.org; Thu, 07 Feb 2013 10:10:51 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U3T7X-00034c-PC for bug-gnu-emacs@gnu.org; Thu, 07 Feb 2013 10:10:48 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3T7X-00034Y-M7 for bug-gnu-emacs@gnu.org; Thu, 07 Feb 2013 10:10:39 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1U3T8r-0008Ml-Nc for bug-gnu-emacs@gnu.org; Thu, 07 Feb 2013 10:12:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Feb 2013 15:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13648 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.136024987932094 (code B ref -1); Thu, 07 Feb 2013 15:12:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Feb 2013 15:11:19 +0000 Original-Received: from localhost ([127.0.0.1]:42166 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U3T8A-0008La-Ix for submit@debbugs.gnu.org; Thu, 07 Feb 2013 10:11:19 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46863) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U3T86-0008LK-Kp for submit@debbugs.gnu.org; Thu, 07 Feb 2013 10:11:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U3T6g-0002gX-Mw for submit@debbugs.gnu.org; Thu, 07 Feb 2013 10:09:52 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:47890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3T6g-0002gS-Ja for submit@debbugs.gnu.org; Thu, 07 Feb 2013 10:09:46 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:58134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3T6Y-0004kP-GW for bug-gnu-emacs@gnu.org; Thu, 07 Feb 2013 10:09:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U3T6Q-0002b3-6d for bug-gnu-emacs@gnu.org; Thu, 07 Feb 2013 10:09:38 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]:55620) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3T6P-0002aN-PC for bug-gnu-emacs@gnu.org; Thu, 07 Feb 2013 10:09:30 -0500 Original-Received: from mailout-de.gmx.net ([10.1.76.32]) by mrigmx.server.lan (mrigmx002) with ESMTP (Nemesis) id 0Lefrs-1Ujjw236BK-00qVqM for ; Thu, 07 Feb 2013 16:09:24 +0100 Original-Received: (qmail invoked by alias); 07 Feb 2013 15:09:23 -0000 Original-Received: from i59F57850.versanet.de (EHLO rosalinde.fritz.box) [89.245.120.80] by mail.gmx.net (mp032) with SMTP; 07 Feb 2013 16:09:23 +0100 X-Authenticated: #20778731 X-Provags-ID: V01U2FsdGVkX19ANI9hHi5AhGG6/6xy+9JNQtiI2nbPRK4qL94tkX OvuW6OqUyBCU9v User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:70814 Archived-At: --=-=-= Content-Type: text/plain 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) --=-=-= Content-Type: text/x-patch Content-Disposition: inline Content-Description: remove-overlays patch === modified file 'lisp/subr.el' *** lisp/subr.el 2013-02-03 16:13:36 +0000 --- lisp/subr.el 2013-02-07 14:45:09 +0000 *************** *** 2579,2585 **** (defun remove-overlays (&optional beg end name val) "Clear BEG and END of overlays whose property NAME has value VAL. Overlays might be moved and/or split. ! BEG and END default respectively to the beginning and end of buffer." ;; This speeds up the loops over overlays. (unless beg (setq beg (point-min))) (unless end (setq end (point-max))) --- 2579,2589 ---- (defun remove-overlays (&optional beg end name val) "Clear BEG and END of overlays whose property NAME has value VAL. Overlays might be moved and/or split. ! ! BEG and END default respectively to the beginning and end of ! buffer. If VAL is nil and NAME is non-nil, clear all NAME ! overlays regardless of their values. If both NAME and VAL are ! nil, clear all overlays from BEG to END." ;; This speeds up the loops over overlays. (unless beg (setq beg (point-min))) (unless end (setq end (point-max))) *************** *** 2588,2607 **** (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))))))) ;;;; Miscellanea. --- 2592,2614 ---- (setq beg (prog1 end (setq end beg)))) (save-excursion (dolist (o (overlays-in beg end)) ! (let ((v (overlay-get o name))) ! ;; An overlay property value can be not just a symbol, ! ;; but also a string or a list. ! (when (if val (or (eq v val) (equal v val)) name) ! ;; 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)))))))) ;;;; Miscellanea. --=-=-= Content-Type: text/plain In GNU Emacs 24.3.50.6 (x86_64-suse-linux-gnu, GTK+ Version 3.4.4) of 2013-02-07 on rosalinde Bzr revision: 111689 michael.albinus@gmx.de-20130207085004-ztc6mdtkh756peam Windowing system distributor `The X.Org Foundation', version 11.0.11203000 System Description: openSUSE 12.2 (x86_64) Configured using: `configure --without-toolkit-scroll-bars CFLAGS=-g3 -O0 --no-create --no-recursion' Important settings: value of $LANG: en_US.UTF-8 value of $XMODIFIERS: @im=local locale-coding-system: utf-8-unix default enable-multibyte-characters: t --=-=-=--