From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Newsgroups: gmane.emacs.bugs Subject: bug#28390: 26.0.50; overlays-at actually sorts by increating priority Date: Fri, 08 Sep 2017 09:57:28 +0100 Message-ID: <87r2vhin47.fsf@lolita> References: <871snijgkk.fsf@lolita> <83tw0dy468.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1504861112 21075 195.159.176.226 (8 Sep 2017 08:58:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 8 Sep 2017 08:58:32 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 28390@debbugs.gnu.org, monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Sep 08 10:58:18 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 1dqF75-0004Zx-0S for geb-bug-gnu-emacs@m.gmane.org; Fri, 08 Sep 2017 10:58:11 +0200 Original-Received: from localhost ([::1]:43952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqF7C-00071R-BJ for geb-bug-gnu-emacs@m.gmane.org; Fri, 08 Sep 2017 04:58:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqF71-0006ye-8E for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:58:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqF6w-0008Ms-Hf for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:58:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46601) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dqF6w-0008Mm-D5 for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dqF6w-0002PP-5t for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2017 04:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 08 Sep 2017 08:58: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.15048610599229 (code B ref 28390); Fri, 08 Sep 2017 08:58:02 +0000 Original-Received: (at 28390) by debbugs.gnu.org; 8 Sep 2017 08:57:39 +0000 Original-Received: from localhost ([127.0.0.1]:55282 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dqF6Z-0002On-7r for submit@debbugs.gnu.org; Fri, 08 Sep 2017 04:57:39 -0400 Original-Received: from mail-wm0-f51.google.com ([74.125.82.51]:45380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dqF6X-0002OX-5c for 28390@debbugs.gnu.org; Fri, 08 Sep 2017 04:57:37 -0400 Original-Received: by mail-wm0-f51.google.com with SMTP id f199so814528wme.0 for <28390@debbugs.gnu.org>; Fri, 08 Sep 2017 01:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=JcF1KUwegq00H6xOkKfF0jIGQrf/rStq++1VEa7pCDs=; b=Qb6O16+kxXxoi2Bas9akFGyJzV5GhvqNPtkEvxhIVunYnI9dKCyuOAUQsXKUce96Pg VgAG13Y+GV/gJDzSk9ZXcACSMV3+Vh76xTx1o0b+o2YZNeJIzOtdyAb6+42Fj0UrpEBG 61AUP/6+ZeU19EOIvPZpSYQGd5lyWHlVywlMNzqplqYZNu4XOBrrRsE2GWm5ZavX5Jdi TzjLA8l1vxfXlLUXWoApiI7BiA4G2Nx37HgTIhXU4cUFMqPU2D5me6HxM2ljGblWwS4Y zbM4w10zQtzFJ45ctRJhpwRKLXbHEhmGAKf4lamTde2B7q18zpf4bjb699H0y0/m/h3P XwoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=JcF1KUwegq00H6xOkKfF0jIGQrf/rStq++1VEa7pCDs=; b=kCUnNVV38J2NOY2W4Csrr0y8R53hy6/N3IdEI0OKHDQPOs8Ed6YbXW4AYHlDzcYcva 8x5AT0y8ee74SoVKoLtzRCFgMAH18KnyeWiHSRgzFVlBZbkyaNbPvnUDM7e+Nva2vfkU e1F0GoQwei/xYLLiS/gyUXif5Y1+ekTbdHzvgXJReGSKi0lAgU3wf2LrN2DLuL0ASuLe ZBkLDwqGgi9Y7c0QlIUvqRA8XIaRA1RB7TUKP3BCHkqIxjhZXGE1SYidMxULhbPq7thp n1ZcSqwOqYq7YUoLk3RwnkRh3hVW4jZUVsck8OaUdkYleGLC6kanZGoHUmuSs1DdQdvi nx8g== X-Gm-Message-State: AHPjjUi23QYDFOySmlN9Pa8V2AsmbyzlyzxDvnjulWmp2i49Vmpylpym mF0eHWr/uZPsqO4du4Tg6x12tPCBomc= X-Google-Smtp-Source: AOwi7QCTRMwpElwXlIXLWv9E40wC1foLA2WTLTfBm1glCJShnVS6ugjyDOZUZrQ6cEBNSjnLnhWH1A== X-Received: by 10.28.152.4 with SMTP id a4mr147535wme.29.1504861051143; Fri, 08 Sep 2017 01:57:31 -0700 (PDT) Original-Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id p29sm872926wma.30.2017.09.08.01.57.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Sep 2017 01:57:30 -0700 (PDT) In-Reply-To: <83tw0dy468.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 08 Sep 2017 11:39:59 +0300") 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:136678 Archived-At: Eli Zaretskii writes: >> From: joaotavora@gmail.com (Jo=C3=A3o T=C3=A1vora) >> Date: Thu, 07 Sep 2017 23:21:15 +0100 >>=20 >> Hi Stefan, maintainters >>=20 >> 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. >>=20 >> Line 3234 of buffer.c seems to confirm this: >>=20 >> /* Sort the overlays into the proper order: increasing priority. */ >>=20 >> and compare_overlays passed to qsort() as well: >>=20 >> return s1->priority < s2->priority ? -1 : 1; >>=20 >> I also did this test: >>=20 >> (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)= )) >>=20 >> this returns (0 1 2 3) >>=20 >> 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. Really? Won't that ripple very paintuflly across the elisp ecosphere? > 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))))) I don't follow, where is the code that did this, or is this just an illustration? The optional SORTED to overlays-at is first introduced in buffer.c in Stefan's 20fa59a0 commit. Before that, I see no evidence of explicit sorting. DEFUN("overlays-at") calls sort_overlays(), which has always used qsort() with compare_overlays(), which in turn always returned negatives if prio1 < prio2. (always ~=3D since 1994) > 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 '>'. But where was sort() ever used before Stefan's 2014 change? Did overlays-at make any sort guarantee back then? I do agree that it should sort the other way, though. But it's too late for that, bugs will be features :-).