Remove imap-hash.el now that tramp-imap.el is gone.
[bpt/emacs.git] / src / composite.c
index 392da1c..58bc685 100644 (file)
@@ -1,7 +1,6 @@
 /* Composite sequence support.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005,
-                 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2001-2011 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H14PRO021
    Copyright (C) 2003, 2006
@@ -153,15 +152,8 @@ int n_compositions;
    COMPOSITION-ID.  */
 Lisp_Object composition_hash_table;
 
-/* Function to call to adjust composition.  */
-Lisp_Object Vcompose_chars_after_function;
-
 Lisp_Object Qauto_composed;
-Lisp_Object Vauto_composition_mode;
-Lisp_Object Vauto_composition_function;
 Lisp_Object Qauto_composition_function;
-Lisp_Object Vcomposition_function_table;
-
 /* Maximum number of characters to look back for
    auto-compositions.  */
 #define MAX_AUTO_COMPOSITION_LOOKBACK 3
@@ -180,7 +172,8 @@ Lisp_Object composition_temp;
    If the composition is invalid, return -1.  */
 
 int
-get_composition_id (int charpos, int bytepos, int nchars, Lisp_Object prop, Lisp_Object string)
+get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
+                   Lisp_Object prop, Lisp_Object string)
 {
   Lisp_Object id, length, components, key, *key_contents;
   int glyph_len;
@@ -188,7 +181,8 @@ get_composition_id (int charpos, int bytepos, int nchars, Lisp_Object prop, Lisp
   int hash_index;
   unsigned hash_code;
   struct composition *cmp;
-  int i, ch;
+  EMACS_INT i;
+  int ch;
 
   /* PROP should be
        Form-A: ((LENGTH . COMPONENTS) . MODIFICATION-FUNC)
@@ -290,7 +284,7 @@ get_composition_id (int charpos, int bytepos, int nchars, Lisp_Object prop, Lisp
       && VECTORP (AREF (components, 0)))
     {
       /* COMPONENTS is a glyph-string.  */
-      int len = ASIZE (key);
+      EMACS_UINT len = ASIZE (key);
 
       for (i = 1; i < len; i++)
        if (! VECTORP (AREF (key, i)))
@@ -298,7 +292,7 @@ get_composition_id (int charpos, int bytepos, int nchars, Lisp_Object prop, Lisp
     }
   else if (VECTORP (components) || CONSP (components))
     {
-      int len = XVECTOR (key)->size;
+      EMACS_UINT len = XVECTOR (key)->size;
 
       /* The number of elements should be odd.  */
       if ((len % 2) == 0)
@@ -427,7 +421,9 @@ get_composition_id (int charpos, int bytepos, int nchars, Lisp_Object prop, Lisp
    This doesn't check the validity of composition.  */
 
 int
-find_composition (int pos, int limit, EMACS_INT *start, EMACS_INT *end, Lisp_Object *prop, Lisp_Object object)
+find_composition (EMACS_INT pos, EMACS_INT limit,
+                 EMACS_INT *start, EMACS_INT *end,
+                 Lisp_Object *prop, Lisp_Object object)
 {
   Lisp_Object val;
 
@@ -465,7 +461,7 @@ find_composition (int pos, int limit, EMACS_INT *start, EMACS_INT *end, Lisp_Obj
    FROM and TO with property PROP.  */
 
 static void
-run_composition_function (int from, int to, Lisp_Object prop)
+run_composition_function (EMACS_INT from, EMACS_INT to, Lisp_Object prop)
 {
   Lisp_Object func;
   EMACS_INT start, end;
@@ -628,7 +624,8 @@ make_composition_value_copy (Lisp_Object list)
    indices START and END in STRING.  */
 
 void
-compose_text (int start, int end, Lisp_Object components, Lisp_Object modification_func, Lisp_Object string)
+compose_text (EMACS_INT start, EMACS_INT end, Lisp_Object components,
+             Lisp_Object modification_func, Lisp_Object string)
 {
   Lisp_Object prop;
 
@@ -735,7 +732,8 @@ composition_gstring_p (Lisp_Object gstring)
 }
 
 int
-composition_gstring_width (Lisp_Object gstring, int from, int to, struct font_metrics *metrics)
+composition_gstring_width (Lisp_Object gstring, EMACS_INT from, EMACS_INT to,
+                          struct font_metrics *metrics)
 {
   Lisp_Object *glyph;
   int width = 0;
@@ -907,7 +905,7 @@ autocmp_chars (Lisp_Object rule, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT
   EMACS_INT to;
   EMACS_INT pt = PT, pt_byte = PT_BYTE;
   Lisp_Object re, font_object, lgstring;
-  int len;
+  EMACS_INT len;
 
   record_unwind_save_match_data ();
   re = AREF (rule, 0);
@@ -969,7 +967,9 @@ autocmp_chars (Lisp_Object rule, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT
 static Lisp_Object _work_val;
 static int _work_char;
 
-/* 1 iff the character C is composable.  */
+/* 1 iff the character C is composable.  Characters of general
+   category Z? or C? are not composable except for ZWNJ and ZWJ. */
+
 #define CHAR_COMPOSABLE_P(C)                                           \
   ((C) == 0x200C || (C) == 0x200D                                      \
    || (_work_val = CHAR_TABLE_REF (Vunicode_category_table, (C)),      \
@@ -1028,19 +1028,6 @@ composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos,
       cmp_it->stop_pos = endpos = start;
       cmp_it->ch = -1;
     }
-  if (NILP (string))
-    {
-      /* A composition never strides over PT.  */
-      if (PT > charpos)
-       {
-         if (PT < endpos)
-           cmp_it->stop_pos = endpos = PT;
-       }
-      else if (PT < charpos && PT > endpos)
-       {
-         cmp_it->stop_pos = endpos = PT - 1;
-       }
-    }
   if (NILP (current_buffer->enable_multibyte_characters)
       || NILP (Vauto_composition_mode))
     return;
@@ -1091,6 +1078,16 @@ composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos,
                }
            }
        }
+      if (charpos == endpos)
+       {
+         /* We couldn't find a composition point before ENDPOS.  But,
+            some character after ENDPOS may be composed with
+            characters before ENDPOS.  So, we should stop at the safe
+            point.  */
+         charpos = endpos - MAX_AUTO_COMPOSITION_LOOKBACK;
+         if (charpos < start)
+           charpos = start;
+       }
     }
   else if (charpos > endpos)
     {
@@ -1223,23 +1220,8 @@ composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos,
 int
 composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT endpos, struct window *w, struct face *face, Lisp_Object string)
 {
-  if (endpos <= charpos)
-    {
-      if (NILP (string))
-       {
-         if (endpos < 0)
-           endpos = BEGV;
-         if (endpos < PT && PT < charpos)
-           endpos = PT;
-       }
-      else if (endpos < 0)
-       endpos = 0;
-    }
-  else
-    {
-      if (NILP (string) && charpos < PT && PT < endpos)
-       endpos = PT;
-    }
+  if (endpos < 0)
+    endpos = NILP (string) ? BEGV : 0;
 
   if (cmp_it->ch == -2)
     {
@@ -1301,7 +1283,7 @@ composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
              elt = XCAR (val);
              if (cmp_it->lookback > 0)
                {
-                 cpos -= cmp_it->lookback;
+                 cpos = charpos - cmp_it->lookback;
                  if (STRINGP (string))
                    bpos = string_char_to_byte (string, cpos);
                  else
@@ -1413,7 +1395,7 @@ composition_update_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
       /* automatic composition */
       Lisp_Object gstring = composition_gstring_from_id (cmp_it->id);
       Lisp_Object glyph;
-      int from, to;
+      EMACS_INT from;
 
       if (cmp_it->nglyphs == 0)
        {
@@ -1456,8 +1438,7 @@ composition_update_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
        {
          c = XINT (LGSTRING_CHAR (gstring, i));
          cmp_it->nbytes += CHAR_BYTES (c);
-         cmp_it->width = (LGLYPH_WIDTH (glyph) > 0
-                          ? CHAR_WIDTH (LGLYPH_CHAR (glyph)) : 0);
+         cmp_it->width += CHAR_WIDTH (c);
        }
     }
   return c;
@@ -1673,7 +1654,7 @@ find_automatic_composition (EMACS_INT pos, EMACS_INT limit, EMACS_INT *start, EM
 /* Return the adjusted point provided that point is moved from LAST_PT
    to NEW_PT.  */
 
-int
+EMACS_INT
 composition_adjust_point (EMACS_INT last_pt, EMACS_INT new_pt)
 {
   EMACS_INT charpos, bytepos, startpos, beg, end, pos;
@@ -1763,8 +1744,6 @@ should be ignored.  */)
 
   CHECK_NATNUM (from);
   CHECK_NATNUM (to);
-  if (XINT (to) > XINT (from) + MAX_COMPOSITION_COMPONENTS)
-    to = make_number (XINT (from) + MAX_COMPOSITION_COMPONENTS);
   if (! FONT_OBJECT_P (font_object))
     {
       struct coding_system *coding;
@@ -1898,9 +1877,9 @@ See `find-composition' for more details.  */)
     id = COMPOSITION_ID (prop);
   else
     {
-      int start_byte = (NILP (string)
-                       ? CHAR_TO_BYTE (start)
-                       : string_char_to_byte (string, start));
+      EMACS_INT start_byte = (NILP (string)
+                             ? CHAR_TO_BYTE (start)
+                             : string_char_to_byte (string, start));
       id = get_composition_id (start, start_byte, end - start, prop, string);
     }
 
@@ -1977,7 +1956,7 @@ syms_of_composite (void)
   Vtext_property_default_nonsticky
     = Fcons (Fcons (Qcomposition, Qt), Vtext_property_default_nonsticky);
 
-  DEFVAR_LISP ("compose-chars-after-function", &Vcompose_chars_after_function,
+  DEFVAR_LISP ("compose-chars-after-function", Vcompose_chars_after_function,
               doc: /* Function to adjust composition of buffer text.
 
 This function is called with three arguments: FROM, TO, and OBJECT.
@@ -1997,12 +1976,12 @@ The default value is the function `compose-chars-after'.  */);
   Qauto_composition_function = intern_c_string ("auto-composition-function");
   staticpro (&Qauto_composition_function);
 
-  DEFVAR_LISP ("auto-composition-mode", &Vauto_composition_mode,
+  DEFVAR_LISP ("auto-composition-mode", Vauto_composition_mode,
               doc: /* Non-nil if Auto-Composition mode is enabled.
 Use the command `auto-composition-mode' to change this variable. */);
   Vauto_composition_mode = Qt;
 
-  DEFVAR_LISP ("auto-composition-function", &Vauto_composition_function,
+  DEFVAR_LISP ("auto-composition-function", Vauto_composition_function,
               doc: /* Function to call to compose characters automatically.
 This function is called from the display routine with four arguments:
 FROM, TO, WINDOW, and STRING.
@@ -2015,7 +1994,7 @@ string.  In this case, the function must compose characters in the
 string.  */);
   Vauto_composition_function = Qnil;
 
-  DEFVAR_LISP ("composition-function-table", &Vcomposition_function_table,
+  DEFVAR_LISP ("composition-function-table", Vcomposition_function_table,
               doc: /* Char-table of functions for automatic character composition.
 For each character that has to be composed automatically with
 preceding and/or following characters, this char-table contains
@@ -2054,5 +2033,3 @@ See also the documentation of `auto-composition-mode'.  */);
   defsubr (&Scomposition_get_gstring);
 }
 
-/* arch-tag: 79cefaf8-ca48-4eed-97e5-d5afb290d272
-   (do not change this comment) */