From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#28390: 26.0.50; overlays-at actually sorts by increating priority Date: Fri, 08 Sep 2017 11:39:59 +0300 Message-ID: <83tw0dy468.fsf@gnu.org> References: <871snijgkk.fsf@lolita> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1504860114 16858 195.159.176.226 (8 Sep 2017 08:41:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 8 Sep 2017 08:41:54 +0000 (UTC) Cc: 28390@debbugs.gnu.org, monnier@iro.umontreal.ca To: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Sep 08 10:41:41 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dqEqg-0002hz-Lx for geb-bug-gnu-emacs@m.gmane.org; Fri, 08 Sep 2017 10:41:14 +0200 Original-Received: from localhost ([::1]:43904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqEqn-0001Kd-Jj for geb-bug-gnu-emacs@m.gmane.org; Fri, 08 Sep 2017 04:41:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqEqZ-0001Fg-AU for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:41:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqEqU-00017e-PV for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:41:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46579) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dqEqU-00017G-LV for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dqEqU-0000Au-F3 for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 08 Sep 2017 08:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28390 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28390-submit@debbugs.gnu.org id=B28390.1504860016611 (code B ref 28390); Fri, 08 Sep 2017 08:41:02 +0000 Original-Received: (at 28390) by debbugs.gnu.org; 8 Sep 2017 08:40:16 +0000 Original-Received: from localhost ([127.0.0.1]:55260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dqEpk-00009n-97 for submit@debbugs.gnu.org; Fri, 08 Sep 2017 04:40:16 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:44386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dqEpi-00009Z-JY for 28390@debbugs.gnu.org; Fri, 08 Sep 2017 04:40:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqEpY-00008E-UY for 28390@debbugs.gnu.org; Fri, 08 Sep 2017 04:40:09 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:43321) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqEpO-0008Ox-W1; Fri, 08 Sep 2017 04:39:55 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3289 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dqEpO-0003hg-Au; Fri, 08 Sep 2017 04:39:54 -0400 In-reply-to: <871snijgkk.fsf@lolita> (joaotavora@gmail.com) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:136676 Archived-At: > From: joaotavora@gmail.com (João Távora) > Date: Thu, 07 Sep 2017 23:21:15 +0100 > > Hi Stefan, maintainters > > I believe I found a rather easy glitch in the doc of overlays-at. It > says if SORTED in non-nil it sorts overlays by "decreasing" priority, > but actually the reverse is true. > > Line 3234 of buffer.c seems to confirm this: > > /* Sort the overlays into the proper order: increasing priority. */ > > and compare_overlays passed to qsort() as well: > > return s1->priority < s2->priority ? -1 : 1; > > I also did this test: > > (progn > (mapc #'delete-overlay (overlays-in (point-min) (point-max))) > (dotimes (i 4) (overlay-put (make-overlay 20 30) 'priority i)) > (mapcar (lambda (ov) (overlay-get ov 'priority)) (overlays-at 20 t))) > > this returns (0 1 2 3) > > This is a 3-year-old docbug, so I'm suspicious I might be missing > something. Anyway here's a docpatch. I think the doc string says what the implementation was supposed to do, so we need to change the implementation instead. If you look at the changeset where the SORTED argument was introduced, you will see that the old code sorted the list returned by overlays-at in descending order of priorities, i.e. overlays with the largest priority first. It used 'sort' like this: (sort (mapcar #'overlay-properties (overlays-at p)) (lambda (A B) (> (or (cadr (memq 'priority A)) 0) (or (cadr (memq 'priority B)) 0))))) The doc string of 'sort' says that its PREDICATE function should return non-nil if the first element passed to PREDICATE should sort _before_ the second. And the predicate above uses '>'. So I think we should rather reverse the list which overlays-at returns. Stefan?