all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Chong Yidong <cyd@stupidchicken.com>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: bidi-display-reordering is now non-nil by default
Date: Thu, 18 Aug 2011 11:21:03 +0300	[thread overview]
Message-ID: <83liurruz4.fsf@gnu.org> (raw)
In-Reply-To: <87ippvwtwx.fsf@stupidchicken.com>

> From: Chong Yidong <cyd@stupidchicken.com>
> Date: Wed, 17 Aug 2011 18:32:46 -0400
> Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > I'm afraid making the reordering engine aware of all text properties
> > will considerably slow down redisplay, due to the need to check
> > character properties very frequently.  It also runs a high risk of
> > completely blending the reordering code with the display engine, which
> > will make them both very hard to maintain; currently, they are clearly
> > separated.
> 
> No, the lookup would be done at the redisplay engine level, not the
> reordering engine level: add a new entry in it_props[] for handling a
> (say) `bidi-override' text property.  Emacs would process this during
> the step in redisplay where it handles other properties (like faces and
> invisibility), and record the information into the iterator.  The bidi
> code would take it from there.

This won't work, not with the way the reordering engine is currently
integrated with redisplay.  The reason is that above the reordering
level, the iteration through buffer text is non-linear.  Your
suggestion assumes that the redisplay iterator will bump into this new
text property _before_ it processes the text which follows it.  But
this assumption is false because of the non-linear scanning of the
buffer text.

Let me show an example to illustrate how the bidirectional display
handles text properties.  Suppose you have the following buffer text
(as usual, capital letters mean R2L characters):

   000000111110000
   abcde ABCDE xyz
         ^    ^

The number above each character shows the text properties of the
characters; 0 means no properties, 1 means some specific property.
This example shows only one property, spanning only the R2L
characters; the real-life examples can be much more complex.  The '^'
characters below show the "stop positions" computed by the iterator --
those are the buffer positions where display engine should process the
text property by calling one or more handlers in the it_props[] array,
filling the iterator with attributes necessary for displaying the text
until the next "stop position".

To move from the blank character between `e' and `A' to the next
character in visual order, the display iterator calls the reordering
engine.  When it does that, the first (leftmost) "stop position" was
not yet acted upon, because the current iterator position is smaller
than that stop.  When the call to the reordering engine returns, it
sets the iterator position at `E', since the ABCDE part should be
displayed as EDCBA on the screen.  Oops! we just missed the "stop
position".  What happens next is the redisplay engine realizes that
the stop position was missed, so it scans back to find the last "stop
position" preceding `E' (since there could be other text properties or
overlays in-between), and then handles it using the handlers in
it_props[]; see handle_stop_backwards for how this is done.  Then it
can deliver `E' with the right attributes, and continue delivering all
the successive characters, until it crosses some "stop position"
again, either going forward or backward.

This is why it won't work to control reordering with text properties:
by the time the redisplay engine realizes that there's another text
property to apply, a crucial part of reordering has already happened.
The bidi_it structure that is part of the iterator already has all the
information about reordering of "ABCDE", having scanned it all inside
a single call to bidi_move_to_visually_next.  That scan entirely
ignores all text properties except one: the `display' property, and
then only if its value will cause the covered text to be replaced by
something else, like an image or a string.

It would be possible, of course, to have the handler of the
`bidi-override' property to toss all the reordering information,
reposition to before `A' and start anew.  But that's a terrible waste
of cycles, especially if the text covered by that property is not so
short.  The waste is not only in that we will have to throw away
information we already gathered at some cost, but also because
repositioning the iterator to an arbitrary place means we need to
restart the bidi iteration from the beginning of the line in order to
have the correct state of the bidi iterator needed to continue from
that place; see get_visually_first_element for the details.

> >> Then it should be easy to exploit font-lock to give reasonably correct
> >> bidi segmentation, e.g. by treating font-lock-comment-face and
> >> font-lock-string-face boundaries as bidi segmentation boundaries.
> >
> > We should be very careful with reusing font-lock as basis for
> > reordering, because the user has too much knobs to control font-lock.
> > For example, few of the font-lock features speed up redisplay by
> > deferring fontification to a later time.  With font-lock, this just
> > displays text in the default face; with reordering, it will flush
> > incorrectly rendered text for a perceptible amount of time.  I'm not
> > sure it's a good idea.
> 
> The fundamental issue is that correctly segmenting source code requires
> knowledge of the underlying syntax.  Sure, it's possible to come up with
> some hacks that "mostly" work, but font lock is already there, so we
> ought to try to use it first.

Font-lock just uses regexps and syntax tables.  Everything else in
font-lock is meant to avoid the annoyingly long delay it takes to
fully fontify a large buffer.  What I'm saying is that, apart from
using regexps and syntax tables, the considerations and trade-offs
that are valid for font-lock are not necessarily valid for
bidirectional display.

> For this reason, I'm not about concerned about the deferred
> fontification issue: if you want Emacs to segment properly, you'd want
> it to do an amount of work equivalent to font-lock anyway.

Amount of work is the least of my concerns in this regard.  I'm
worried about the effect the temporarily incorrect display will have
on users.



  reply	other threads:[~2011-08-18  8:21 UTC|newest]

Thread overview: 245+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15  8:04 bidi-display-reordering is now non-nil by default Andrey Paramonov
2011-08-15  9:10 ` Eli Zaretskii
2011-08-15  9:24   ` David Kastrup
2011-08-15 10:20     ` Eli Zaretskii
2011-08-15 10:46       ` David Kastrup
2011-08-15 11:10         ` Eli Zaretskii
2011-08-15 11:27           ` David Kastrup
2011-08-15 11:56             ` Eli Zaretskii
2011-08-15 12:56               ` David Kastrup
2011-08-15 13:07                 ` Eli Zaretskii
2011-08-15 13:59     ` Stefan Monnier
2011-08-15 14:18       ` David Kastrup
2011-08-15 16:57         ` Stefan Monnier
2011-08-15 17:12         ` Eli Zaretskii
2011-08-15 16:55       ` Eli Zaretskii
2011-08-15 18:13         ` Stefan Monnier
2011-08-17 20:34           ` Lars Magne Ingebrigtsen
2011-08-18 16:14           ` Eli Zaretskii
2011-08-22  6:02             ` Eli Zaretskii
2011-08-22 19:35               ` Stefan Monnier
2011-08-23  8:05                 ` Eli Zaretskii
2011-08-23 18:19                   ` Stefan Monnier
2011-08-23 19:03                     ` Eli Zaretskii
2011-08-23 19:17                       ` Stefan Monnier
2011-08-24  6:35                         ` Eli Zaretskii
2011-08-24  9:02                         ` Eli Zaretskii
2011-08-24 14:51                           ` Stefan Monnier
2011-08-24 16:55                             ` Eli Zaretskii
2011-08-25  4:38                               ` Stefan Monnier
2011-08-25  6:12                                 ` Eli Zaretskii
2011-08-26  3:55                                   ` Stefan Monnier
2011-08-26  7:31                                     ` Eli Zaretskii
2011-08-27  2:53                                       ` Stefan Monnier
2011-08-27  8:16                                         ` Eli Zaretskii
2011-08-28  2:52                                           ` Stefan Monnier
2011-08-28  6:03                                             ` Eli Zaretskii
2011-08-29 14:46                                               ` Stefan Monnier
2011-08-25 10:50                                 ` Eli Zaretskii
2011-08-22 19:37               ` Stefan Monnier
2011-08-22 21:35                 ` Štěpán Němec
2011-08-23  1:13                   ` Stefan Monnier
2011-08-23  9:58                     ` Štěpán Němec
2011-08-23 15:29                       ` use of `mouse-face' to delimit text zones [was: bidi-display-reordering is now non-nil by default] Drew Adams
2011-08-23 16:15                         ` Eli Zaretskii
2011-08-23 18:34                           ` Stefan Monnier
2011-08-23 18:45                             ` use of `mouse-face' to delimit text zones Eli Zaretskii
2011-08-23 19:17                               ` Štěpán Němec
2011-08-23 19:22                               ` Stefan Monnier
2011-08-23 18:24                       ` bidi-display-reordering is now non-nil by default Stefan Monnier
2011-08-23 19:14                         ` Štěpán Němec
2011-08-23  8:40                 ` Eli Zaretskii
2011-08-15 18:28         ` Chong Yidong
2011-08-15 20:41           ` Eli Zaretskii
2011-08-16  1:11             ` Stefan Monnier
2011-08-16  2:02             ` Chong Yidong
2011-08-16  6:47               ` Eli Zaretskii
2011-08-16  7:07                 ` David Kastrup
2011-08-16  9:25                   ` Eli Zaretskii
2011-08-16 10:01                     ` David Kastrup
2011-08-16 10:37                       ` Eli Zaretskii
2011-08-16  7:40                 ` Andreas Schwab
2011-08-16  7:54                   ` David Kastrup
2011-08-16  9:20                     ` Eli Zaretskii
2011-08-16  9:40                       ` David Kastrup
2011-08-16 10:01                         ` Eli Zaretskii
2011-08-16 14:10                           ` Stefan Monnier
2011-08-16  9:03                   ` Eli Zaretskii
2011-08-16  9:10                     ` Andreas Schwab
2011-08-16  9:55                       ` Eli Zaretskii
2011-08-16  9:03                   ` Eli Zaretskii
2011-08-16 14:03                 ` Stefan Monnier
2011-08-16 14:48                   ` Eli Zaretskii
2011-08-16 15:48                 ` Chong Yidong
2011-08-16 17:50                   ` Eli Zaretskii
2011-08-16 22:24                     ` Chong Yidong
2011-08-17  6:30                       ` Eli Zaretskii
2011-08-17  9:34                         ` Juri Linkov
2011-08-17 10:05                           ` Eli Zaretskii
2011-08-17 22:32                         ` Chong Yidong
2011-08-18  8:21                           ` Eli Zaretskii [this message]
2011-08-18 17:13                             ` Chong Yidong
2011-08-18 17:45                               ` Eli Zaretskii
2011-08-18 22:44                                 ` Chong Yidong
2011-08-19  3:16                                   ` Stefan Monnier
2011-08-19  7:25                                     ` Eli Zaretskii
2011-08-19 20:00                                       ` Chong Yidong
2011-08-20  8:14                                         ` bidi reordering in program source buffers (was: bidi-display-reordering is now non-nil by default) Eli Zaretskii
2011-08-20  9:28                                           ` Andreas Schwab
2011-08-20 10:53                                             ` Eli Zaretskii
2011-08-25 13:51                                               ` Ehud Karni
2011-08-25 17:28                                                 ` bidi reordering in program source buffers Eli Zaretskii
2011-08-25 20:01                                                   ` Ehud Karni
2011-08-25 21:09                                                     ` Eli Zaretskii
2011-08-19 19:29                                     ` bidi-display-reordering is now non-nil by default Chong Yidong
2011-08-19  7:13                                   ` Eli Zaretskii
2011-08-19 19:43                                     ` Chong Yidong
2011-08-20  7:39                                       ` Eli Zaretskii
2011-08-19 14:51                                   ` Lars Magne Ingebrigtsen
2011-08-19 15:12                                     ` Eli Zaretskii
2011-08-15  9:27   ` Andrey Paramonov
  -- strict thread matches above, loose matches on Subject: below --
2011-08-16 10:02 Andrey Paramonov
2011-08-16 10:40 ` Eli Zaretskii
2011-08-16 11:27   ` Andrey Paramonov
2011-07-28 17:21 Eli Zaretskii
2011-07-28 18:51 ` David Kastrup
2011-07-28 20:35   ` Juanma Barranquero
2011-07-30 22:55 ` Werner LEMBERG
2011-07-31  3:06   ` Eli Zaretskii
2011-07-31  6:21     ` Werner LEMBERG
2011-07-31  6:29       ` Eli Zaretskii
2011-07-31  6:44         ` Werner LEMBERG
2011-07-31  7:01           ` Eli Zaretskii
2011-07-31  7:36             ` Werner LEMBERG
2011-07-31  6:17   ` Eli Zaretskii
2011-07-31  6:27     ` Werner LEMBERG
2011-07-31  6:40       ` Eli Zaretskii
2011-07-31  6:51         ` Werner LEMBERG
2011-07-31  7:59           ` David Kastrup
2011-07-31  9:03             ` Eli Zaretskii
2011-07-31  9:15               ` David Kastrup
2011-07-31  9:34                 ` Eli Zaretskii
2011-07-31  9:54                   ` David Kastrup
2011-07-31 10:18                     ` Eli Zaretskii
2011-07-31 10:35                       ` David Kastrup
2011-07-31 12:01                         ` Eli Zaretskii
2011-07-31 13:23                           ` David Kastrup
2011-07-31 13:43                             ` Eli Zaretskii
2011-07-31 11:07                   ` Lars Magne Ingebrigtsen
2011-07-31 12:22                     ` Eli Zaretskii
2011-07-31 13:25                       ` David Kastrup
2011-07-31 13:38                         ` Lars Magne Ingebrigtsen
2011-07-31 13:54                           ` David Kastrup
2011-07-31 13:59                             ` Eli Zaretskii
2011-07-31 14:26                               ` David Kastrup
2011-07-31 15:44                                 ` Eli Zaretskii
2011-08-01  1:14                                   ` Mohsen BANAN
2011-08-01  2:54                                     ` Eli Zaretskii
2011-08-03  2:39                                       ` Mohsen BANAN
2011-08-03  8:56                                         ` Eli Zaretskii
2011-08-01 15:51                                     ` Lars Ingebrigtsen
2011-08-03  2:56                                       ` Mohsen BANAN
2011-08-03 18:45                                         ` Lars Magne Ingebrigtsen
2011-08-03 19:30                                           ` Eli Zaretskii
2011-08-04  3:23                                             ` Stephen J. Turnbull
2011-08-04  5:16                                               ` Eli Zaretskii
2011-08-04  6:55                                                 ` Kenichi Handa
2011-08-04 10:12                                                   ` Eli Zaretskii
2011-08-09  6:11                                                     ` Kenichi Handa
2011-08-09  7:00                                                       ` Eli Zaretskii
2011-08-04 10:04                                                 ` Stephen J. Turnbull
2011-08-04 10:36                                                   ` Eli Zaretskii
2011-08-04 13:55                                                     ` Stephen J. Turnbull
2011-08-04 14:04                                                       ` David Kastrup
2011-08-04 14:59                                                         ` Eli Zaretskii
2011-08-04 14:53                                                       ` Eli Zaretskii
2011-08-04 16:55                                                         ` Stephen J. Turnbull
2011-08-04 17:07                                                           ` Stephen J. Turnbull
2011-08-04 17:43                                                           ` Eli Zaretskii
2011-08-05  3:38                                                             ` Stephen J. Turnbull
2011-08-05  5:46                                                               ` David Kastrup
2011-08-05  6:40                                                               ` Eli Zaretskii
2011-08-05  8:00                                                                 ` Stephen J. Turnbull
2011-08-04 13:59                                                 ` Stefan Monnier
2011-08-04 14:56                                                   ` Eli Zaretskii
2011-08-05  3:41                                             ` Michael Welsh Duggan
2011-08-05  6:56                                               ` Eli Zaretskii
2011-08-05 17:56                                             ` Chong Yidong
2011-08-05 18:10                                               ` Eli Zaretskii
2011-08-05 18:45                                                 ` Chong Yidong
2011-08-05 20:30                                                   ` Eli Zaretskii
2011-08-05 21:54                                                     ` Chong Yidong
2011-08-06  2:01                                                       ` Jason Rumney
2011-08-06  7:07                                                       ` Eli Zaretskii
2011-08-07 17:21                                                         ` Chong Yidong
2011-08-07 19:32                                                           ` Eli Zaretskii
2011-08-09 16:07                                                             ` Chong Yidong
2011-08-09 16:23                                                               ` Eli Zaretskii
2011-08-09 16:30                                                                 ` David Kastrup
2011-08-09 17:12                                                                   ` Eli Zaretskii
2011-08-09 17:26                                                                     ` David Kastrup
2011-08-09 17:34                                                                       ` Eli Zaretskii
2011-08-09 18:00                                                                         ` David Kastrup
2011-08-10  0:24                                                                           ` Richard Stallman
2011-08-11  5:38                                                                         ` Stephen J. Turnbull
2011-08-09 22:26                                                                 ` Chong Yidong
2011-08-10  1:03                                                                   ` Stefan Monnier
2011-08-10  1:14                                                                     ` David Kastrup
2011-08-10  4:50                                                                       ` Eli Zaretskii
2011-08-10 16:07                                                                         ` Chong Yidong
2011-08-10 16:40                                                                           ` Eli Zaretskii
2011-08-10 16:52                                                                             ` Chong Yidong
2011-08-10 17:13                                                                               ` Eli Zaretskii
2011-08-11  2:45                                                                               ` Mohsen BANAN
2011-08-10  3:07                                                                     ` Eli Zaretskii
2011-08-10 13:20                                                                       ` Stefan Monnier
2011-08-10 13:39                                                                         ` Eli Zaretskii
2011-08-10  3:04                                                                   ` Eli Zaretskii
2011-08-10  5:36                                                                     ` David Kastrup
2011-08-10 13:22                                                                     ` Stefan Monnier
2011-08-17 22:21                                                           ` Lars Magne Ingebrigtsen
2011-08-17 22:25                                                             ` Lars Magne Ingebrigtsen
2011-08-17 23:14                                                               ` Lars Magne Ingebrigtsen
2011-08-18  7:23                                                                 ` Eli Zaretskii
2011-08-18  7:00                                                               ` Eli Zaretskii
2011-09-10 19:11                                                                 ` Lars Magne Ingebrigtsen
2011-09-10 19:30                                                                   ` Eli Zaretskii
2011-09-10 19:33                                                                     ` Lars Magne Ingebrigtsen
2011-08-06 15:51                                                       ` Lars Magne Ingebrigtsen
2011-08-06 16:16                                                         ` David Kastrup
2011-08-06 16:17                                                         ` Eli Zaretskii
2011-08-06 19:21                                                       ` Mohsen BANAN
2011-07-31 13:54                         ` Eli Zaretskii
2011-08-02 15:34                           ` Stefan Monnier
2011-08-02 16:09                             ` Lars Magne Ingebrigtsen
2011-08-02 16:42                               ` David Kastrup
2011-08-02 16:48                                 ` Lars Magne Ingebrigtsen
2011-08-02 18:27                                 ` James Cloos
2011-08-02 16:50                               ` Eli Zaretskii
2011-08-02 17:01                             ` Eli Zaretskii
2011-08-01 15:45         ` Chong Yidong
2011-08-01 17:44           ` Eli Zaretskii
2011-08-01 20:33             ` Lars Ingebrigtsen
2011-08-02  5:06               ` Eli Zaretskii
2011-08-02  7:20                 ` David Kastrup
2011-08-02  7:43                   ` Eli Zaretskii
2011-08-02 10:27                     ` Štěpán Němec
2011-08-02 11:33                       ` Eli Zaretskii
2011-08-02 13:37                 ` Lars Magne Ingebrigtsen
2011-08-02 17:10                   ` Eli Zaretskii
2011-08-02 17:35                     ` Lars Magne Ingebrigtsen
2011-08-02 19:44                       ` Eli Zaretskii
2011-08-03  3:04                         ` محسن بنان
2011-08-03  5:11                           ` James Cloos
2011-08-03  5:52                             ` Mohsen BANAN
2011-08-03  9:28                             ` Eli Zaretskii
2011-08-03 12:08                               ` James Cloos
2011-08-03 12:57                                 ` Eli Zaretskii
2011-08-03 13:06                                   ` James Cloos
2011-08-03 13:48                                     ` Eli Zaretskii
2011-08-03 14:10                                       ` James Cloos
2011-08-03 16:08                                         ` Eli Zaretskii
2011-08-03 17:20                                           ` Mohsen BANAN
2011-08-03  8:42                           ` Eli Zaretskii
2011-08-03 19:26                             ` main
2011-08-02 15:43           ` Stefan Monnier

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=83liurruz4.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@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.