all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: joaotavora@gmail.com (João Távora)
To: Eli Zaretskii <eliz@gnu.org>
Cc: 28390@debbugs.gnu.org, monnier@iro.umontreal.ca
Subject: bug#28390: 26.0.50; overlays-at actually sorts by increating priority
Date: Fri, 08 Sep 2017 09:57:28 +0100	[thread overview]
Message-ID: <87r2vhin47.fsf@lolita> (raw)
In-Reply-To: <83tw0dy468.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 08 Sep 2017 11:39:59 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

>> 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.

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 ~= 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 :-).





  reply	other threads:[~2017-09-08  8:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-07 22:21 bug#28390: 26.0.50; overlays-at actually sorts by increating priority João Távora
2017-09-08  8:39 ` Eli Zaretskii
2017-09-08  8:57   ` João Távora [this message]
2017-09-08  9:47     ` Eli Zaretskii
     [not found]       ` <CALDnm5103cjV6TNKiGiaVEcJRLMfnM+wCuW3LrySh8dEur7uwg@mail.gmail.com>
2017-09-08 19:30         ` bug#28390: Fwd: " João Távora
2017-09-10 13:53   ` Stefan Monnier
2017-09-16 10:04     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r2vhin47.fsf@lolita \
    --to=joaotavora@gmail.com \
    --cc=28390@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.