Remove imap-hash.el now that tramp-imap.el is gone.
[bpt/emacs.git] / src / composite.c
index f7b0211..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;
@@ -848,8 +846,6 @@ fill_gstring_header (Lisp_Object header, Lisp_Object start, Lisp_Object end, Lis
   return header;
 }
 
-extern void font_fill_lglyph_metrics (Lisp_Object, Lisp_Object);
-
 static void
 fill_gstring_body (Lisp_Object gstring)
 {
@@ -909,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);
@@ -971,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)),      \
@@ -1030,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;
@@ -1093,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)
     {
@@ -1225,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)
     {
@@ -1303,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
@@ -1415,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)
        {
@@ -1458,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;
@@ -1675,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;
@@ -1758,16 +1737,13 @@ where
 
 If GLYPH is nil, the remaining elements of the glyph-string vector
 should be ignored.  */)
-     (from, to, font_object, string)
-     Lisp_Object font_object, from, to, string;
+  (Lisp_Object from, Lisp_Object to, Lisp_Object font_object, Lisp_Object string)
 {
   Lisp_Object gstring, header;
   EMACS_INT frompos, topos;
 
   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;
@@ -1804,8 +1780,7 @@ DEFUN ("compose-region-internal", Fcompose_region_internal,
 Compose text in the region between START and END.
 Optional 3rd and 4th arguments are COMPONENTS and MODIFICATION-FUNC
 for the composition.  See `compose-region' for more details.  */)
-     (start, end, components, modification_func)
-     Lisp_Object start, end, components, modification_func;
+  (Lisp_Object start, Lisp_Object end, Lisp_Object components, Lisp_Object modification_func)
 {
   validate_region (&start, &end);
   if (!NILP (components)
@@ -1825,8 +1800,7 @@ DEFUN ("compose-string-internal", Fcompose_string_internal,
 Compose text between indices START and END of STRING.
 Optional 4th and 5th arguments are COMPONENTS and MODIFICATION-FUNC
 for the composition.  See `compose-string' for more details.  */)
-     (string, start, end, components, modification_func)
-     Lisp_Object string, start, end, components, modification_func;
+  (Lisp_Object string, Lisp_Object start, Lisp_Object end, Lisp_Object components, Lisp_Object modification_func)
 {
   CHECK_STRING (string);
   CHECK_NUMBER (start);
@@ -1847,8 +1821,7 @@ DEFUN ("find-composition-internal", Ffind_composition_internal,
 
 Return information about composition at or nearest to position POS.
 See `find-composition' for more details.  */)
-     (pos, limit, string, detail_p)
-     Lisp_Object pos, limit, string, detail_p;
+  (Lisp_Object pos, Lisp_Object limit, Lisp_Object string, Lisp_Object detail_p)
 {
   Lisp_Object prop, tail, gstring;
   EMACS_INT start, end, from, to;
@@ -1904,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);
     }
 
@@ -1943,7 +1916,6 @@ syms_of_composite (void)
   /* Make a hash table for static composition.  */
   {
     Lisp_Object args[6];
-    extern Lisp_Object QCsize;
 
     args[0] = QCtest;
     args[1] = Qequal;
@@ -1963,8 +1935,6 @@ syms_of_composite (void)
   /* Make a hash table for glyph-string.  */
   {
     Lisp_Object args[6];
-    extern Lisp_Object QCsize;
-
     args[0] = QCtest;
     args[1] = Qequal;
     args[2] = QCweakness;
@@ -1986,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.
@@ -2006,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.
@@ -2024,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
@@ -2063,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) */