all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: joaotavora@gmail.com (João Távora)
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 11:39:59 +0300	[thread overview]
Message-ID: <83tw0dy468.fsf@gnu.org> (raw)
In-Reply-To: <871snijgkk.fsf@lolita> (joaotavora@gmail.com)

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





  reply	other threads:[~2017-09-08  8:39 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 [this message]
2017-09-08  8:57   ` João Távora
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=83tw0dy468.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=28390@debbugs.gnu.org \
    --cc=joaotavora@gmail.com \
    --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.