]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix display of 'display' strings in RTL paragraphs at window-start
authorEli Zaretskii <eliz@gnu.org>
Thu, 25 Jul 2024 18:26:08 +0000 (21:26 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 27 Jul 2024 12:03:06 +0000 (14:03 +0200)
* src/xdisp.c (handle_single_display_spec)
(get_overlay_strings_1, push_prefix_prop): Initialize bidi
paragraph direction if not yet done.  (Bug#72287)

(cherry picked from commit c22b4198b2e5a9d63109c5ceeb386fbb1904f5dc)

src/xdisp.c

index 45317cc9f5dd3c0402e17837fc7de76aced7abcf..a8f9f59b6549d094fd7d251646cf394336de544e 100644 (file)
@@ -6355,6 +6355,12 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
          return retval;
        }
 
+      /* We want the string to inherit the paragraph direction of the
+         parent object, so we need to calculate that if not yet done.  */
+      ptrdiff_t eob = (BUFFERP (object) ? ZV : it->end_charpos);
+      if (it->bidi_it.first_elt && it->bidi_it.charpos < eob)
+       bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true);
+
       /* Save current settings of IT so that we can restore them
         when we are finished with the glyph property value.  */
       push_it (it, position);
@@ -6387,9 +6393,10 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
          if (BUFFERP (object))
            *position = start_pos;
 
-         /* Force paragraph direction to be that of the parent
-            object.  If the parent object's paragraph direction is
-            not yet determined, default to L2R.  */
+         /* Force paragraph direction to be that of the parent object.
+            If the parent object's paragraph direction is not yet
+            determined (which shouldn not happen, since we called
+            bidi_paragraph_init above), default to L2R.  */
          if (it->bidi_p && it->bidi_it.paragraph_dir == R2L)
            it->paragraph_embedding = it->bidi_it.paragraph_dir;
          else
@@ -7044,6 +7051,11 @@ get_overlay_strings_1 (struct it *it, ptrdiff_t charpos, bool compute_stop_p)
         strings have been processed.  */
       eassert (!compute_stop_p || it->sp == 0);
 
+      /* We want the string to inherit the paragraph direction of the
+         parent object, so we need to calculate that if not yet done.  */
+      if (it->bidi_it.first_elt && it->bidi_it.charpos < ZV)
+       bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true);
+
       /* When called from handle_stop, there might be an empty display
          string loaded.  In that case, don't bother saving it.  But
          don't use this optimization with the bidi iterator, since we
@@ -7197,7 +7209,7 @@ iterate_out_of_display_property (struct it *it)
   eassert (eob >= CHARPOS (it->position) && CHARPOS (it->position) >= bob);
 
   /* Maybe initialize paragraph direction.  If we are at the beginning
-     of a new paragraph, next_element_from_buffer may not have a
+     of a new paragraph, next_element_from_buffer may not have had a
      chance to do that.  */
   if (it->bidi_it.first_elt && it->bidi_it.charpos < eob)
     bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true);
@@ -24415,6 +24427,12 @@ push_prefix_prop (struct it *it, Lisp_Object prop)
           || it->method == GET_FROM_STRING
           || it->method == GET_FROM_IMAGE);
 
+  /* We want the string to inherit the paragraph direction of the parent
+     object, so we need to calculate that if not yet done.  */
+  ptrdiff_t eob = (STRINGP (it->string) ? SCHARS (it->string) : ZV);
+  if (it->bidi_it.first_elt && it->bidi_it.charpos < eob)
+    bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true);
+
   /* We need to save the current buffer/string position, so it will be
      restored by pop_it, because iterate_out_of_display_property
      depends on that being set correctly, but some situations leave