Subject: Re: bug#50506: 28.0.50; display-line-numbers equivalent for linum-format?

From: Eli Zaretskii <[email-masked]>
Date: Wed, 15 Sep 2021 19:26:38 +0300

> From: Michael Gallagher - NOAA Affiliate <[email-masked]>
> Date: Wed, 15 Sep 2021 10:08:49 -0600
> Cc: Lars Ingebrigtsen <[email-masked]>, [email-masked]
> 
> 
> [1:text/plain Show]
> 
> 
> [2:text/html Hide Save:noname (5kB)]
> 
> The code as it stands displays correctly with TUTORIAL.he.

What is the value of bidi-paragraph-direction in the buffer where you
visit TUTORIAL.he for testing this feature?  It should be nil.

Your code does this:

  +  if (FIXNATP (Vdisplay_line_numbers_separator_character)
  +      && it->paragraph_embedding != L2R)
  +    {
  +      tem_it.c = tem_it.char_to_display = XFIXNAT (Vdisplay_line_numbers_separator_character);

That is, it treats any value of it->paragraph_embedding that is not
L2R as if it were R2L.  But that is incorrect, because the usual value
of it->paragraph_embedding is NEUTRAL_DIR, which corresponds to the
nil value of bidi-paragraph-direction, the default.  That nil value
means to determine the actual paragraph direction dynamically from the
contents of the paragraph.  It is this nil value that presents the
problem.  Your code treats that value as meaning right-to-left, but
that is wrong.

For example, all of the paragraphs on TUTORIAL.he are displayed
right-to-left (because they include right-to-left text), but the last
paragraph, the one which shows the file-local variables, is displayed
left-to-right.  Try turning on this feature and look at that last part
of the buffer to see if your code works correctly.

> I was confused about the relationship between paragraph_embedding and bidi-paragraph_direction.

bidi-paragraph-direction determines the value of it->paragraph_embedding.
However, the default value of bidi-paragraph-direction is nil, and
that is translated into NEUTRAL_DIR value of it->paragraph_embedding.

> I'm
> assuming you're saying there needs to be an additional check on the value of para_direction in the if
> statements?

I don't think you can base this on it->paragraph_embedding, because it
doesn't reflect the actual paragraph direction on display when
bidi-paragraph-direction is nil, the default.  The display code
computes the actual direction of each screen line dynamically in that
case, and stores it in the reversed_p flag of the glyph row.  The
problem is that when the code generates the line number of the first
screen line it needs to produce, that flag is not yet computed, it
will only be computed when the first character on the screen line, the
one after the line number, will be laid out.  And by that time, the
line number was already generated.  This is the problem that needs
fixing for this to work reliably with all scripts.

Thanks.