Subject: bug#32978: 26.1; newline-and-indent duplicates displayed image

From: Eli Zaretskii <[email-masked]>
Date: Sun, 14 Oct 2018 17:38:02 +0300

> From: Markus Triska <[email-masked]>
> Date: Sun, 07 Oct 2018 23:14:56 +0200
> 
> 
>     $ emacs -Q --eval='(progn (insert-image-file "test.png")
>                               (forward-char)
>                               (newline-and-indent))'
> 
> As a result, test.png is displayed twice, both in line 1 and in line 2.
> 
> In this case, I expect test.png to be displayed only in line 1.

Not sure why you expected that.  Perhaps you thought that forward-char
will move to after the image?  But that is a feature of the command
loop, and happens only after a command finishes, and Emacs is back to
the command loop.  It doesn't happen in the middle of a Lisp program.
So what your program did is insert a newline character in the middle
of text covered by a 'display' text property, and then the behavior
you observe is expected, right?

If I modify your program as follows:

  (let ((inserted (cadr (insert-image-file "test.png"))))
    (goto-char (1+ inserted))
    (newline-and-indent))

then only one image is displayed, on line 1.

If what forward-char does in this case is not the reason for your
expectations, please tell more about your reasoning.