Remove imap-hash.el now that tramp-imap.el is gone.
[bpt/emacs.git] / src / composite.c
index cab57e8..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,9 +172,8 @@ Lisp_Object composition_temp;
    If the composition is invalid, return -1.  */
 
 int
-get_composition_id (charpos, bytepos, nchars, prop, string)
-     int charpos, bytepos, nchars;
-     Lisp_Object prop, 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;
@@ -190,7 +181,8 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
   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)
@@ -292,7 +284,7 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
       && 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)))
@@ -300,7 +292,7 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
     }
   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)
@@ -429,10 +421,9 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
    This doesn't check the validity of composition.  */
 
 int
-find_composition (pos, limit, start, end, prop, object)
-     int pos, limit;
-     EMACS_INT *start, *end;
-     Lisp_Object *prop, object;
+find_composition (EMACS_INT pos, EMACS_INT limit,
+                 EMACS_INT *start, EMACS_INT *end,
+                 Lisp_Object *prop, Lisp_Object object)
 {
   Lisp_Object val;
 
@@ -470,9 +461,7 @@ find_composition (pos, limit, start, end, prop, object)
    FROM and TO with property PROP.  */
 
 static void
-run_composition_function (from, to, prop)
-     int from, to;
-     Lisp_Object prop;
+run_composition_function (EMACS_INT from, EMACS_INT to, Lisp_Object prop)
 {
   Lisp_Object func;
   EMACS_INT start, end;
@@ -504,9 +493,7 @@ run_composition_function (from, to, prop)
    change is deletion, FROM == TO.  Otherwise, FROM < TO.  */
 
 void
-update_compositions (from, to, check_mask)
-     EMACS_INT from, to;
-     int check_mask;
+update_compositions (EMACS_INT from, EMACS_INT to, int check_mask)
 {
   Lisp_Object prop;
   EMACS_INT start, end;
@@ -612,8 +599,7 @@ update_compositions (from, to, check_mask)
    top-level copies of them so that none of them are `eq'.  */
 
 void
-make_composition_value_copy (list)
-     Lisp_Object list;
+make_composition_value_copy (Lisp_Object list)
 {
   Lisp_Object plist, val;
 
@@ -638,9 +624,8 @@ make_composition_value_copy (list)
    indices START and END in STRING.  */
 
 void
-compose_text (start, end, components, modification_func, string)
-     int start, end;
-     Lisp_Object components, modification_func, string;
+compose_text (EMACS_INT start, EMACS_INT end, Lisp_Object components,
+             Lisp_Object modification_func, Lisp_Object string)
 {
   Lisp_Object prop;
 
@@ -651,9 +636,9 @@ compose_text (start, end, components, modification_func, string)
 }
 
 
-static Lisp_Object autocmp_chars P_ ((Lisp_Object, EMACS_INT, EMACS_INT,
-                                     EMACS_INT, struct window *,
-                                     struct face *, Lisp_Object));
+static Lisp_Object autocmp_chars (Lisp_Object, EMACS_INT, EMACS_INT,
+                                  EMACS_INT, struct window *,
+                                  struct face *, Lisp_Object);
 
 \f
 /* Lisp glyph-string handlers */
@@ -664,11 +649,10 @@ static Lisp_Object autocmp_chars P_ ((Lisp_Object, EMACS_INT, EMACS_INT,
 
 static Lisp_Object gstring_hash_table;
 
-static Lisp_Object gstring_lookup_cache P_ ((Lisp_Object));
+static Lisp_Object gstring_lookup_cache (Lisp_Object);
 
 static Lisp_Object
-gstring_lookup_cache (header)
-     Lisp_Object header;
+gstring_lookup_cache (Lisp_Object header)
 {
   struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
   int i = hash_lookup (h, header, NULL);
@@ -677,9 +661,7 @@ gstring_lookup_cache (header)
 }
 
 Lisp_Object
-composition_gstring_put_cache (gstring, len)
-     Lisp_Object gstring;
-     int len;
+composition_gstring_put_cache (Lisp_Object gstring, int len)
 {
   struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
   unsigned hash;
@@ -707,21 +689,19 @@ composition_gstring_put_cache (gstring, len)
 }
 
 Lisp_Object
-composition_gstring_from_id (id)
-     int id;
+composition_gstring_from_id (int id)
 {
   struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
 
   return HASH_VALUE (h, id);
 }
 
-static Lisp_Object fill_gstring_header P_ ((Lisp_Object, Lisp_Object,
-                                           Lisp_Object, Lisp_Object,
-                                           Lisp_Object));
+static Lisp_Object fill_gstring_header (Lisp_Object, Lisp_Object,
+                                        Lisp_Object, Lisp_Object,
+                                        Lisp_Object);
 
 int
-composition_gstring_p (gstring)
-     Lisp_Object gstring;
+composition_gstring_p (Lisp_Object gstring)
 {
   Lisp_Object header;
   int i;
@@ -752,10 +732,8 @@ composition_gstring_p (gstring)
 }
 
 int
-composition_gstring_width (gstring, from, to, metrics)
-     Lisp_Object gstring;
-     int from, 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;
@@ -811,8 +789,7 @@ static Lisp_Object gstring_work;
 static Lisp_Object gstring_work_headers;
 
 static Lisp_Object
-fill_gstring_header (header, start, end, font_object, string)
-     Lisp_Object header, start, end, font_object, string;
+fill_gstring_header (Lisp_Object header, Lisp_Object start, Lisp_Object end, Lisp_Object font_object, Lisp_Object string)
 {
   EMACS_INT from, to, from_byte;
   EMACS_INT len, i;
@@ -869,11 +846,8 @@ fill_gstring_header (header, start, end, font_object, string)
   return header;
 }
 
-extern void font_fill_lglyph_metrics P_ ((Lisp_Object, Lisp_Object));
-
 static void
-fill_gstring_body (gstring)
-     Lisp_Object gstring;
+fill_gstring_body (Lisp_Object gstring)
 {
   Lisp_Object font_object = LGSTRING_FONT (gstring);
   Lisp_Object header = AREF (gstring, 0);
@@ -923,12 +897,7 @@ fill_gstring_body (gstring)
    object.  Otherwise return nil.  */
 
 static Lisp_Object
-autocmp_chars (rule, charpos, bytepos, limit, win, face, string)
-     Lisp_Object rule;
-     EMACS_INT charpos, bytepos, limit;
-     struct window *win;
-     struct face *face;
-     Lisp_Object string;
+autocmp_chars (Lisp_Object rule, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT limit, struct window *win, struct face *face, Lisp_Object string)
 {
   int count = SPECPDL_INDEX ();
   FRAME_PTR f = XFRAME (win->frame);
@@ -936,7 +905,7 @@ autocmp_chars (rule, charpos, bytepos, limit, win, face, string)
   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);
@@ -998,7 +967,9 @@ autocmp_chars (rule, charpos, bytepos, limit, win, face, string)
 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)),      \
@@ -1020,10 +991,7 @@ static int _work_char;
    composition.  */
 
 void
-composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string)
-     struct composition_it *cmp_it;
-     EMACS_INT charpos, bytepos, endpos;
-     Lisp_Object string;
+composition_compute_stop_pos (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT endpos, Lisp_Object string)
 {
   EMACS_INT start, end, c;
   Lisp_Object prop, val;
@@ -1060,19 +1028,6 @@ composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string)
       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;
@@ -1123,6 +1078,16 @@ composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string)
                }
            }
        }
+      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)
     {
@@ -1253,30 +1218,10 @@ composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string)
    CMP_IT->stop_pos, and return 0.  */
 
 int
-composition_reseat_it (cmp_it, charpos, bytepos, endpos, w, face, string)
-     struct composition_it *cmp_it;
-     EMACS_INT charpos, bytepos, endpos;
-     struct window *w;
-     struct face *face;
-     Lisp_Object string;
+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)
     {
@@ -1338,7 +1283,7 @@ composition_reseat_it (cmp_it, charpos, bytepos, endpos, w, face, string)
              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
@@ -1417,10 +1362,7 @@ composition_reseat_it (cmp_it, charpos, bytepos, endpos, w, face, string)
    the cluster, or -1 if the composition is somehow broken.  */
 
 int
-composition_update_it (cmp_it, charpos, bytepos, string)
-     struct composition_it *cmp_it;
-     EMACS_INT charpos, bytepos;
-     Lisp_Object string;
+composition_update_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_INT bytepos, Lisp_Object string)
 {
   int i, c;
 
@@ -1453,7 +1395,7 @@ composition_update_it (cmp_it, charpos, bytepos, string)
       /* 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)
        {
@@ -1496,8 +1438,7 @@ composition_update_it (cmp_it, charpos, bytepos, string)
        {
          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;
@@ -1543,9 +1484,7 @@ struct position_record
    the composition, and return 1.  Otherwise, return 0.  */
 
 static int
-find_automatic_composition (pos, limit, start, end, gstring, string)
-     EMACS_INT pos, limit, *start, *end;
-     Lisp_Object *gstring, string;
+find_automatic_composition (EMACS_INT pos, EMACS_INT limit, EMACS_INT *start, EMACS_INT *end, Lisp_Object *gstring, Lisp_Object string)
 {
   EMACS_INT head, tail, stop;
   /* Limit to check a composition after POS.  */
@@ -1715,9 +1654,8 @@ find_automatic_composition (pos, limit, start, end, gstring, string)
 /* Return the adjusted point provided that point is moved from LAST_PT
    to NEW_PT.  */
 
-int
-composition_adjust_point (last_pt, new_pt)
-     EMACS_INT last_pt, new_pt;
+EMACS_INT
+composition_adjust_point (EMACS_INT last_pt, EMACS_INT new_pt)
 {
   EMACS_INT charpos, bytepos, startpos, beg, end, pos;
   Lisp_Object val;
@@ -1799,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;
@@ -1845,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)
@@ -1866,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);
@@ -1888,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;
@@ -1945,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);
     }
 
@@ -1974,7 +1906,7 @@ See `find-composition' for more details.  */)
 
 \f
 void
-syms_of_composite ()
+syms_of_composite (void)
 {
   int i;
 
@@ -1984,7 +1916,6 @@ syms_of_composite ()
   /* Make a hash table for static composition.  */
   {
     Lisp_Object args[6];
-    extern Lisp_Object QCsize;
 
     args[0] = QCtest;
     args[1] = Qequal;
@@ -2004,8 +1935,6 @@ syms_of_composite ()
   /* Make a hash table for glyph-string.  */
   {
     Lisp_Object args[6];
-    extern Lisp_Object QCsize;
-
     args[0] = QCtest;
     args[1] = Qequal;
     args[2] = QCweakness;
@@ -2027,7 +1956,7 @@ syms_of_composite ()
   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.
@@ -2047,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.
@@ -2065,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
@@ -2104,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) */