changeset 107584:e0df0337f248

Retrospective commit from 2009-08-15. Start of work on bidi Emacs 23/24. bidi.c (bidi_initialize): Fix initialization of bidi_type_table. xdisp.c (set_iterator_to_next): Fix position setting after call to bidi_get_next_char_visually. bidi.c: Include stdio.h unconditionally. Fix and elaborate commentary. Add Copyright blurb.
author Eli Zaretskii <eliz@gnu.org>
date Thu, 31 Dec 2009 15:04:11 -0500
parents f35e7896a0fe
children 35abfc7649e1
files src/ChangeLog.bidi src/Makefile.in src/bidi.c src/buffer.c src/buffer.h src/dispextern.h src/dispnew.c src/xdisp.c
diffstat 8 files changed, 58 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog.bidi	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/ChangeLog.bidi	Thu Dec 31 15:04:11 2009 -0500
@@ -1,3 +1,10 @@
+2009-08-15  Eli Zaretskii  <eliz@gnu.org>
+
+	* bidi.c (bidi_initialize): Fix initialization of bidi_type_table.
+
+	* xdisp.c (set_iterator_to_next): Fix position setting after call
+	to bidi_get_next_char_visually.
+
 2005-12-03  Eli Zaretskii  <eliz@gnu.org>
 
 	* bidi.c: Include stdio.h unconditionally.  Fix and elaborate
@@ -11,7 +18,8 @@
 
 2004-03-04  Kenichi Handa  <handa@m17n.org>
 
-	The following changes are to support bidirectional text display.
+	The following changes are to support for bi-directional text
+	display.
 
 	* Makefile.in (obj): Include bidi.o.
 	(bidi.o): New target.
--- a/src/Makefile.in	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/Makefile.in	Thu Dec 31 15:04:11 2009 -0500
@@ -560,8 +560,7 @@
 /* lastfile must follow all files
    whose initialized data areas should be dumped as pure by dump-emacs.  */
 obj=    dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
-	bidi.o \
-	charset.o coding.o category.o ccl.o character.o chartab.o \
+	charset.o coding.o category.o ccl.o character.o chartab.o bidi.o \
 	cm.o term.o terminal.o xfaces.o $(XOBJ) $(GTK_OBJ) $(DBUS_OBJ) \
 	emacs.o keyboard.o macros.o keymap.o sysdep.o \
 	buffer.o filelock.o insdel.o marker.o \
@@ -1053,7 +1052,7 @@
 
 atimer.o: atimer.c atimer.h syssignal.h systime.h lisp.h blockinput.h \
  $(config_h)
-bidi.o: bidi.c buffer.h character.h
+bidi.o: bidi.c buffer.h character.h dispextern.h
 buffer.o: buffer.c buffer.h region-cache.h commands.h window.h \
    $(INTERVALS_H) blockinput.h atimer.h systime.h character.h \
    indent.h keyboard.h coding.h keymap.h frame.h lisp.h $(config_h)
--- a/src/bidi.c	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/bidi.c	Thu Dec 31 15:04:11 2009 -0500
@@ -155,6 +155,7 @@
 
 bidi_dir_t bidi_overriding_paragraph_direction = NEUTRAL_DIR;
 
+/* FIXME: Unused? */
 #define ASCII_BIDI_TYPE_SET(STR, TYPE)			\
   do {							\
     unsigned char *p;					\
@@ -448,7 +449,8 @@
   bidi_type_table = Fmake_char_table (Qnil, make_number (STRONG_L));
 
   for (i = 0; i < sizeof bidi_type / sizeof bidi_type[0]; i++)
-    char_table_set_range (bidi_type_table, bidi_type[i].from, bidi_type[i].to,
+    char_table_set_range (bidi_type_table, bidi_type[i].from,
+			  bidi_type[i].to ? bidi_type[i].to : bidi_type[i].from,
 			  make_number (bidi_type[i].type));
   bidi_initialized = 1;
 }
--- a/src/buffer.c	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/buffer.c	Thu Dec 31 15:04:11 2009 -0500
@@ -5186,8 +5186,8 @@
   buffer_defaults.truncate_lines = Qnil;
   buffer_defaults.word_wrap = Qnil;
   buffer_defaults.ctl_arrow = Qt;
-  buffer_defaults.enable_bidi_display = Qnil;
-  buffer_defaults.orientation_reversed = Qnil;
+  buffer_defaults.bidi_display_reordering = Qnil;
+  buffer_defaults.direction_reversed = Qnil;
   buffer_defaults.cursor_type = Qt;
   buffer_defaults.extra_line_spacing = Qnil;
   buffer_defaults.cursor_in_non_selected_windows = Qt;
@@ -5272,8 +5272,8 @@
   XSETFASTINT (buffer_local_flags.syntax_table, idx); ++idx;
   XSETFASTINT (buffer_local_flags.cache_long_line_scans, idx); ++idx;
   XSETFASTINT (buffer_local_flags.category_table, idx); ++idx;
-  XSETFASTINT (buffer_local_flags.enable_bidi_display, idx); ++idx;
-  XSETFASTINT (buffer_local_flags.orientation_reversed, idx); ++idx;
+  XSETFASTINT (buffer_local_flags.bidi_display_reordering, idx); ++idx;
+  XSETFASTINT (buffer_local_flags.direction_reversed, idx); ++idx;
   XSETFASTINT (buffer_local_flags.buffer_file_coding_system, idx);
   /* Make this one a permanent local.  */
   buffer_permanent_local_flags[idx++] = 1;
@@ -5530,15 +5530,15 @@
 		     doc: /* Default value of `ctl-arrow' for buffers that do not override it.
 This is the same as (default-value 'ctl-arrow).  */);
 
-    DEFVAR_LISP_NOPRO ("default-enable-bidi-display",
-		      &buffer_defaults.enable_bidi_display,
-		      doc: /* *Default value of `enable-bidi-display' for buffers not overriding it.
-This is the same as (default-value 'enable-bidi-display).  */);
-
-  DEFVAR_LISP_NOPRO ("default-orientation-reversed",
-		     &buffer_defaults.orientation_reversed,
-		     doc: /* *Default value of `orientation-reversed' for buffers that do not override it.
-This is the same as (default-value 'orientation-reversed).  */);
+  DEFVAR_LISP_NOPRO ("default-bidi-display-reordering",
+	      &buffer_defaults.bidi_display_reordering,
+	      doc: /* *Default value of `bidi-display-reordering' for buffers not overriding it.
+This is the same as (default-value 'bidi-display-reordering).  */);
+
+  DEFVAR_LISP_NOPRO ("default-direction-reversed",
+                     &buffer_defaults.direction_reversed,
+                     doc: /* Default value of `direction-reversed' for buffers that do not override it.
+This is the same as (default-value 'direction-reversed).  */);
 
   DEFVAR_LISP_NOPRO ("default-enable-multibyte-characters",
                      &buffer_defaults.enable_multibyte_characters,
@@ -5796,15 +5796,15 @@
 
 This variable is never applied to a way of decoding a file while reading it.  */);
 
-  DEFVAR_PER_BUFFER ("orientation-reversed",
-		     &current_buffer->orientation_reversed, Qnil,
-		     doc: /* Non-nil means set beginning of lines at the right end of the window.
-See also the variable `enable-bidi-display'.  */);
-
-  DEFVAR_PER_BUFFER ("enable-bidi-display",
-		     &current_buffer->enable_bidi_display, Qnil,
-		     doc: /*Non-nil means display bidi text in correct visual order.
-See also the variable `orientation-reversed'.  */);
+  DEFVAR_PER_BUFFER ("direction-reversed",
+		     &current_buffer->direction_reversed, Qnil,
+		     doc: /* Non-nil means set beginning of lines at the right edge of the window.
+See also the variable `bidi-display-reordering'.  */);
+
+  DEFVAR_PER_BUFFER ("bidi-display-reordering",
+		     &current_buffer->bidi_display_reordering, Qnil,
+		     doc: /*Non-nil means reorder bidirectional text for display in the visual order.
+See also the variable `direction-reversed'.  */);
 
  DEFVAR_PER_BUFFER ("truncate-lines", &current_buffer->truncate_lines, Qnil,
 		     doc: /* *Non-nil means do not display continuation lines.
--- a/src/buffer.h	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/buffer.h	Thu Dec 31 15:04:11 2009 -0500
@@ -658,10 +658,12 @@
   Lisp_Object word_wrap;
   /* Non-nil means display ctl chars with uparrow.  */
   Lisp_Object ctl_arrow;
-  /* Non-nil means display bidi text in correct visual order.  */
-  Lisp_Object enable_bidi_display;
-  /* Non-nil means set beginning of lines at the right end of windows.  */
-  Lisp_Object orientation_reversed;
+  /* Non-nil means reorder bidirectional text for display in the
+     visual order.  */
+  Lisp_Object bidi_display_reordering;
+  /* Non-nil means set beginning of lines at the right edge of
+     windows.  */
+  Lisp_Object direction_reversed;
   /* Non-nil means do selective display;
      see doc string in syms_of_buffer (buffer.c) for details.  */
   Lisp_Object selective_display;
--- a/src/dispextern.h	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/dispextern.h	Thu Dec 31 15:04:11 2009 -0500
@@ -2307,10 +2307,11 @@
   /* Face of the right fringe glyph.  */
   unsigned right_user_fringe_face_id : FACE_ID_BITS;
 
-  /* 1 means we need bidi processing.  */
+  /* Non-zero means we need to reorder bidirectional text for display
+     in the visual order.  */
   int bidi_p;
 
-  /* For iterating over bidi text.  */
+  /* For iterating over bidirectional text.  */
   struct bidi_it bidi_it;
 };
 
--- a/src/dispnew.c	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/dispnew.c	Thu Dec 31 15:04:11 2009 -0500
@@ -3776,12 +3776,12 @@
   if (!display_completed || cursor_in_echo_area)
     return 0;
 
-  /* Give up if we need bidi display.  */
-  if (!NILP (XBUFFER (w->buffer)->enable_bidi_display))
+  /* Give up if we need to reorder bidirectional text.  */
+  if (!NILP (XBUFFER (w->buffer)->bidi_display_reordering))
     return 0;
 
-  /* Give up if the buffer's orientation is reversed.  */
-  if (!NILP (XBUFFER (w->buffer)->orientation_reversed))
+  /* Give up if the buffer's direction is reversed.  */
+  if (!NILP (XBUFFER (w->buffer)->direction_reversed))
     return 0;
 
   /* Can't use direct output if highlighting a region.  */
--- a/src/xdisp.c	Thu Dec 31 14:44:59 2009 -0500
+++ b/src/xdisp.c	Thu Dec 31 15:04:11 2009 -0500
@@ -2658,8 +2658,8 @@
   /* Are multibyte characters enabled in current_buffer?  */
   it->multibyte_p = !NILP (current_buffer->enable_multibyte_characters);
 
-  /* Do we need multibyte processing?  */
-  it->bidi_p = !NILP (current_buffer->enable_bidi_display);
+  /* Do we need to reorded bidirectional text?  */
+  it->bidi_p = !NILP (current_buffer->bidi_display_reordering);
 
   /* Non-zero if we should highlight the region.  */
   highlight_region_p
@@ -5520,6 +5520,11 @@
 
   if (it->bidi_p)
     {
+      /* FIXME: L2R below is just for easyness of testing, as we
+	 currently support only left-to-right paragraphs.  The value
+	 should be user-definable and/or come from some ``higher
+	 protocol''. In the absence of any other guidance, the default
+	 for this initialization should be NEUTRAL_DIR.  */
       bidi_init_it (pos.charpos - 1, L2R, &it->bidi_it);
       bidi_get_next_char_visually (&it->bidi_it);
 
@@ -6100,8 +6105,8 @@
 	  else
 	    {
 	      bidi_get_next_char_visually (&it->bidi_it);
-	      IT_BYTEPOS (*it) = it->bidi_it.charpos;
-	      IT_CHARPOS (*it) = it->bidi_it.bytepos;
+	      IT_BYTEPOS (*it) = it->bidi_it.bytepos;
+	      IT_CHARPOS (*it) = it->bidi_it.charpos;
 	    }
 	  xassert (IT_BYTEPOS (*it) == CHAR_TO_BYTE (IT_CHARPOS (*it)));
 	}