Subject: Re: bug#40821: Margin strings are displayed in reverse order of overlay priority (low-priority specs hide high-priority ones)

From: Eli Zaretskii <[email-masked]>
Date: Wed, 13 May 2020 19:25:15 +0300

> Cc: [email-masked]
> From: Clément Pit-Claudel <[email-masked]>
> Date: Wed, 13 May 2020 11:58:26 -0400
> 
> (with-current-buffer (get-buffer-create "overlay props")
>   (erase-buffer)
>   (delete-all-overlays)
>   (setq-local left-margin-width 5)
>   (save-excursion (insert "test\ntest\n"))
>   (let ((ov1 (make-overlay (point-min) (point-max)))
>         (ov2 (make-overlay (point-min) (point-at-eol))))
>     (overlay-put
>      ov1
>      'before-string
>      #("!" 0 1 (display
>                 ((margin left-margin) "c"))))
>     (overlay-put
>      ov2
>      'before-string
>      #("!" 0 1 (display
>                 ((margin left-margin) "3")))))
>   (display-buffer (current-buffer)))
> 
> In this example, moving the point back and forth between point-min and 1+ point-min causes the margins to display alternatively "c3" and "3c".
> Is this a bug?

It is not a bug.  You haven't defined any priorities, so the sorting
of the overlay strings is arbitrary, and the display engine processes
them in the sorted order.  IOW, this is unspecified behavior in
action.

(I can explain why the order changes technically, but it hardly
matters for the more general question.)