]> code.delx.au - gnu-emacs/blobdiff - src/composite.c
(clone-buffer): Use `mapc' rather than `mapcar'.
[gnu-emacs] / src / composite.c
index 9fc58bc27b6c910ec1648338e8f1357c830bcf9a..95c19d745601fe20e453506072bd3248726bf391 100644 (file)
@@ -1,13 +1,15 @@
 /* Composite sequence support.
-   Copyright (C) 1999 Electrotechnical Laboratory, JAPAN.
-   Licensed to the Free Software Foundation.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005,
+                 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+     National Institute of Advanced Industrial Science and Technology (AIST)
+     Registration Number H14PRO021
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -17,8 +19,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include <config.h>
 #include "lisp.h"
@@ -92,32 +94,32 @@ Boston, MA 02111-1307, USA.  */
 
    The former is a hash table in which keys are COMPONENTS-VECs and
    values are the corresponding COMPOSITION-IDs.  This hash table is
-   weak, but as each key (COMPONENTS-VEC) is also kept as a value of
+   weak, but as each key (COMPONENTS-VEC) is also kept as a value of the
    `composition' property, it won't be collected as garbage until all
-   text that have the same COMPONENTS-VEC are deleted.
+   bits of text that have the same COMPONENTS-VEC are deleted.
 
    The latter is a table of pointers to `struct composition' indexed
-   by COMPOSITION-ID.  This structure keep the other information (see
+   by COMPOSITION-ID.  This structure keeps the other information (see
    composite.h).
 
    In general, a text property holds information about individual
    characters.  But, a `composition' property holds information about
-   a sequence of characters (in this sense, it is like `intangible'
+   a sequence of characters (in this sense, it is like the `intangible'
    property).  That means that we should not share the property value
-   in adjacent compositions we can't distinguish them if they have the
+   in adjacent compositions -- we can't distinguish them if they have the
    same property.  So, after any changes, we call
    `update_compositions' and change a property of one of adjacent
    compositions to a copy of it.  This function also runs a proper
    composition modification function to make a composition that gets
    invalid by the change valid again.
 
-   As a value of `composition' property holds information about a
+   As the value of the `composition' property holds information about a
    specific range of text, the value gets invalid if we change the
-   text in the range.  We treat `composition' property always
+   text in the range.  We treat the `composition' property as always
    rear-nonsticky (currently by setting default-text-properties to
    (rear-nonsticky (composition))) and we never make properties of
    adjacent compositions identical.  Thus, any such changes make the
-   range just shorter.  So, we can check the validity of `composition'
+   range just shorter.  So, we can check the validity of the `composition'
    property by comparing LENGTH information with the actual length of
    the composition.
 
@@ -249,7 +251,7 @@ get_composition_id (charpos, bytepos, nchars, prop, string)
     }
 
   /* This composition is a new one.  We must register it.  */
-         
+
   /* Check if we have sufficient memory to store this information.  */
   if (composition_table_size == 0)
     {
@@ -462,7 +464,7 @@ run_composition_function (from, to, prop)
       && find_composition (to, -1, &start, &end, &prop, Qnil)
       && !COMPOSITION_VALID_P (start, end, prop))
     to = end;
-  if (!NILP (func))
+  if (!NILP (Ffboundp (func)))
     call2 (func, make_number (from), make_number (to));
   else if (!NILP (Ffboundp (Vcompose_chars_after_function)))
     call3 (Vcompose_chars_after_function,
@@ -478,14 +480,14 @@ run_composition_function (from, to, prop)
 
 void
 update_compositions (from, to, check_mask)
-     int from, to;
+     int from, to, check_mask;
 {
   Lisp_Object prop;
   int start, end;
 
   if (inhibit_modification_hooks)
     return;
-  
+
   /* If FROM and TO are not in a valid range, do nothing.  */
   if (! (BEGV <= from && from <= to && to <= ZV))
     return;
@@ -498,7 +500,8 @@ update_compositions (from, to, check_mask)
         avoid it, in such a case, we change the property of the
         latter to the copy of it.  */
       if (from > BEGV
-         && find_composition (from - 1, -1, &start, &end, &prop, Qnil))
+         && find_composition (from - 1, -1, &start, &end, &prop, Qnil)
+         && COMPOSITION_VALID_P (start, end, prop))
        {
          if (from < end)
            Fput_text_property (make_number (from), make_number (end),
@@ -508,7 +511,8 @@ update_compositions (from, to, check_mask)
          from = end;
        }
       else if (from < ZV
-              && find_composition (from, -1, &start, &from, &prop, Qnil))
+              && find_composition (from, -1, &start, &from, &prop, Qnil)
+              && COMPOSITION_VALID_P (start, from, prop))
        run_composition_function (start, from, prop);
     }
 
@@ -519,6 +523,7 @@ update_compositions (from, to, check_mask)
          (to - 1).  */
       while (from < to - 1
             && find_composition (from, to, &start, &from, &prop, Qnil)
+            && COMPOSITION_VALID_P (start, from, prop)
             && from < to - 1)
        run_composition_function (start, from, prop);
     }
@@ -526,7 +531,8 @@ update_compositions (from, to, check_mask)
   if (check_mask & CHECK_TAIL)
     {
       if (from < to
-         && find_composition (to - 1, -1, &start, &end, &prop, Qnil))
+         && find_composition (to - 1, -1, &start, &end, &prop, Qnil)
+         && COMPOSITION_VALID_P (start, end, prop))
        {
          /* TO should be also at composition boundary.  But,
             insertion or deletion will make two compositions adjacent
@@ -540,7 +546,8 @@ update_compositions (from, to, check_mask)
          run_composition_function (start, end, prop);
        }
       else if (to < ZV
-              && find_composition (to, -1, &start, &end, &prop, Qnil))
+              && find_composition (to, -1, &start, &end, &prop, Qnil)
+              && COMPOSITION_VALID_P (start, end, prop))
        run_composition_function (start, end, prop);
     }
 }
@@ -589,123 +596,6 @@ compose_text (start, end, components, modification_func, string)
                       Qcomposition, prop, string);
 }
 
-/* Compose sequences of characters in the region between START and END
-   by functions registered in Vcomposition_function_table.  If STRING
-   is non-nil, operate on characters contained between indices START
-   and END in STRING.  */
-
-void
-compose_chars_in_text (start, end, string)
-     int start, end;
-     Lisp_Object string;
-{
-  int count = 0;
-  struct gcpro gcpro1;
-  Lisp_Object tail, elt, val, to;
-  /* Set to nonzero if we don't have to compose ASCII characters.  */
-  int skip_ascii;
-  int i, len, stop, c;
-  const unsigned char *ptr, *pend;
-
-  if (! CHAR_TABLE_P (Vcomposition_function_table))
-    return;
-
-  if (STRINGP (string))
-    {
-      count = SPECPDL_INDEX ();
-      GCPRO1 (string);
-      stop = end;
-      ptr = SDATA (string) + string_char_to_byte (string, start);
-      pend = ptr + SBYTES (string);
-    }
-  else
-    {
-      record_unwind_protect (save_excursion_restore, save_excursion_save ());
-      TEMP_SET_PT (start);
-      stop = (start < GPT && GPT < end ? GPT : end);
-      ptr = CHAR_POS_ADDR (start);
-      pend = CHAR_POS_ADDR (end);
-    }
-
-  /* Preserve the match data.  */
-  record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil));
-
-  /* If none of ASCII characters have composition functions, we can
-     skip them quickly.  */
-  for (i = 0; i < 128; i++)
-    if (!NILP (CHAR_TABLE_REF (Vcomposition_function_table, i)))
-      break;
-  skip_ascii = (i == 128);
-
-
-  while (1)
-    {
-      if (skip_ascii)
-       while (start < stop && ASCII_BYTE_P (*ptr))
-         start++, ptr++;
-
-      if (start >= stop)
-       {
-         if (stop == end || start >= end)
-           break;
-         stop = end;
-         if (STRINGP (string))
-           ptr = SDATA (string) + string_char_to_byte (string, start);
-         else
-           ptr = CHAR_POS_ADDR (start);
-       }
-
-      c = STRING_CHAR_AND_LENGTH (ptr, pend - ptr, len);
-      tail = CHAR_TABLE_REF (Vcomposition_function_table, c);
-      while (CONSP (tail))
-       {
-         elt = XCAR (tail);
-         if (CONSP (elt)
-             && STRINGP (XCAR (elt))
-             && !NILP (Ffboundp (XCDR (elt))))
-           {
-             if (STRINGP (string))
-               val = Fstring_match (XCAR (elt), string, make_number (start));
-             else
-               {
-                 val = Flooking_at (XCAR (elt));
-                 if (!NILP (val))
-                   val = make_number (start);
-               }
-             if (INTEGERP (val) && XFASTINT (val) == start)
-               {
-                 to = Fmatch_end (make_number (0));
-                 val = call4 (XCDR (elt), val, to, XCAR (elt), string);
-                 if (INTEGERP (val) && XINT (val) > 1)
-                   {
-                     start += XINT (val);
-                     if (STRINGP (string))
-                       ptr = SDATA (string) + string_char_to_byte (string, start);
-                     else
-                       ptr = CHAR_POS_ADDR (start);
-                   }
-                 else
-                   {
-                     start++;
-                     ptr += len;
-                   }
-                 break;
-               }
-           }
-         tail = XCDR (tail);
-       }
-      if (!CONSP (tail))
-       {
-         /* No composition done.  Try the next character.  */
-         start++;
-         ptr += len;
-       }
-    }
-
-  unbind_to (count, Qnil);
-  if (STRINGP (string))
-    UNGCPRO;
-}
 \f
 /* Emacs Lisp APIs.  */
 
@@ -715,9 +605,9 @@ 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 detail. */)
-     (start, end, components, mod_func)
-     Lisp_Object start, end, components, mod_func;
+for the composition.  See `compose-region' for more detail.  */)
+     (start, end, components, modification_func)
+     Lisp_Object start, end, components, modification_func;
 {
   validate_region (&start, &end);
   if (!NILP (components)
@@ -726,7 +616,7 @@ for the composition.   See `compose-region' for more detail. */)
       && !STRINGP (components))
     CHECK_VECTOR (components);
 
-  compose_text (XINT (start), XINT (end), components, mod_func, Qnil);
+  compose_text (XINT (start), XINT (end), components, modification_func, Qnil);
   return Qnil;
 }
 
@@ -736,9 +626,9 @@ 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 detail.  */)
-     (string, start, end, components, mod_func)
-     Lisp_Object string, start, end, components, mod_func;
+for the composition.  See `compose-string' for more detail.  */)
+     (string, start, end, components, modification_func)
+     Lisp_Object string, start, end, components, modification_func;
 {
   CHECK_STRING (string);
   CHECK_NUMBER (start);
@@ -749,12 +639,12 @@ for the composition.   See `compose-string' for more detail.  */)
       || XINT (end) > SCHARS (string))
     args_out_of_range (start, end);
 
-  compose_text (XINT (start), XINT (end), components, mod_func, string);
+  compose_text (XINT (start), XINT (end), components, modification_func, string);
   return string;
 }
 
 DEFUN ("find-composition-internal", Ffind_composition_internal,
-       Sfind_composition_internal, 4, 4, 0, 
+       Sfind_composition_internal, 4, 4, 0,
        doc: /* Internal use only.
 
 Return information about composition at or nearest to position POS.
@@ -775,7 +665,7 @@ See `find-composition' for more detail.  */)
     }
   else
     end = -1;
-  
+
   if (!NILP (string))
     {
       CHECK_STRING (string);
@@ -839,9 +729,14 @@ syms_of_composite ()
   {
     Lisp_Object args[6];
     extern Lisp_Object QCsize;
-    
+
     args[0] = QCtest;
     args[1] = Qequal;
+    /* We used to make the hash table weak so that unreferenced
+       compostions can be garbage-collected.  But, usually once
+       created compositions are repeatedly used in an Emacs session,
+       and thus it's not worth to save memory in such a way.  So, we
+       make the table not weak.  */
     args[2] = QCweakness;
     args[3] = Qnil;
     args[4] = QCsize;
@@ -896,3 +791,6 @@ the composition gets invalid after a change in a buffer.  */);
   defsubr (&Scompose_string_internal);
   defsubr (&Sfind_composition_internal);
 }
+
+/* arch-tag: 79cefaf8-ca48-4eed-97e5-d5afb290d272
+   (do not change this comment) */