unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Dmitry <dgutov@yandex.ru>
Cc: 18285@debbugs.gnu.org
Subject: bug#18285: 24.3.92; A combination of `display' on text and `invisible' and	`before/after-string' leads to the before/after string being	displayed twice
Date: Mon, 18 Aug 2014 18:07:15 +0300	[thread overview]
Message-ID: <83k365defw.fsf@gnu.org> (raw)
In-Reply-To: <86d2bypwx1.fsf@yandex.ru>

> From: Dmitry <dgutov@yandex.ru>
> Date: Mon, 18 Aug 2014 02:35:06 +0400
> 
> (let ((pt (point)))
>   (insert (propertize "a" 'display "bbb"))
>   (let ((o (make-overlay pt (point))))
>     (overlay-put o 'invisible t)
>     (overlay-put o 'after-string "foo\nbar")))
> 
> The result looks like this:
> 
> foo
> barbbbfoo
> bar

Believe it or not, but this is how the code was written 14 years ago,
although perhaps this particular consequence wasn't intended.  But it
follows logically from how the display engine works.

The fundamental issue here is that the 'invisible' property makes all
the character positions between the start and the end of the overlay
indistinguishable.  Therefore, the display engine considers the
'before-string' and 'after-string' of an overlay that spans invisible
text to be applicable to both the start and the end of the overlay,
something it wouldn't do if the 'invisible' property were not present.

So what happens is this:

 . we find the 'display' property and arrange for it to be displayed

 . before displaying the 'display' property string, we check for
   overlay strings, and find the 'after-string' whose overlay starts
   at the same position; since its overlay has the 'invisible'
   property, we consider the 'after-string' in effect for the start of
   the overlay, and display that string

 . we display the 'display' string

 . we are going to continue display of the buffer starting at the
   position where the 'display' property ends

 . we check for overlays at that position, and again find the same
   'after-string' because its overlay _ends_ at that buffer position,
   so we display that string again

So you are actually shooting yourself in the foot by using the
'invisible' property here.  Doing that is redundant here, because the
'display' property already makes the text it "covers" invisible.

I think it's not worth to try to fix this (by complicating the heck
out of the display engine) on the account of this use case.

If you have other similar use cases, where simply refraining from
using 'invisible' won't help, please show them.

> It's the same if I use `before-string' instead of `after-string', but
> not `display'.
> 
> If I don't set the `invisible' property, it's just
> 
> bbbfoo
> bar

My crystal ball says you get

 bbbfoo
 bar

only with 'after-string'.  With 'before-string', you should get

 foo
 barbbb

instead.  IOW, without the 'invisible' property getting in the way,
the 'before-string' is displayed before the display property, and
the 'after-string' is displayed after it.

Btw, there was a discussion of a similar issue starting at

  http://lists.gnu.org/archive/html/emacs-devel/2011-04/msg00674.html

It was inconclusive.





  parent reply	other threads:[~2014-08-18 15:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-17 22:35 bug#18285: 24.3.92; A combination of `display' on text and `invisible' and `before/after-string' leads to the before/after string being displayed twice Dmitry
     [not found] ` <handler.18285.B.140831493931056.ack@debbugs.gnu.org>
2014-08-18  1:06   ` bug#18285: Acknowledgement (24.3.92; A combination of `display' on text and `invisible' and `before/after-string' leads to the before/after string being displayed twice) Dmitry Gutov
2014-08-18 15:07 ` Eli Zaretskii [this message]
2014-08-21 14:07   ` bug#18285: 24.3.92; A combination of `display' on text and `invisible' and `before/after-string' leads to the before/after string being displayed twice Dmitry Gutov
2014-08-21 14:57     ` Eli Zaretskii
2014-08-21 15:40       ` Dmitry Gutov
2014-08-21 16:06         ` Eli Zaretskii
2014-08-22  0:58           ` Dmitry Gutov
2014-08-22  6:41             ` Eli Zaretskii
2014-08-22 11:41               ` Dmitry Gutov
2014-08-22 13:31                 ` Eli Zaretskii
2014-08-22 20:01                   ` Dmitry Gutov
2014-08-22 20:55                     ` Eli Zaretskii
2014-08-24  1:28                       ` Dmitry Gutov
2014-08-24  2:44                         ` Eli Zaretskii
2014-08-23 23:21     ` Dmitry Gutov
2014-08-24  2:40       ` Eli Zaretskii
2014-08-24  2:48         ` Dmitry Gutov
2022-04-18 11:39   ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=83k365defw.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=18285@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).