]> code.delx.au - gnu-emacs/blobdiff - src/composite.c
* src/keyboard.c (syms_of_keyboard): Further tweaks of docstring.
[gnu-emacs] / src / composite.c
index 16fa3cce6842154976b5e53cb9521128c9ef6af8..9bbd4550c7b41db9fd31d4c7aa2f5f4282eac789 100644 (file)
@@ -1,5 +1,5 @@
 /* Composite sequence support.
-   Copyright (C) 2001-2012 Free Software Foundation, Inc.
+   Copyright (C) 2001-2013 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
@@ -26,7 +26,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define COMPOSITE_INLINE EXTERN_INLINE
 
-#include <setjmp.h>
 #include "lisp.h"
 #include "character.h"
 #include "buffer.h"
@@ -428,7 +427,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
 
    This doesn't check the validity of composition.  */
 
-int
+bool
 find_composition (ptrdiff_t pos, ptrdiff_t limit,
                  ptrdiff_t *start, ptrdiff_t *end,
                  Lisp_Object *prop, Lisp_Object object)
@@ -643,13 +642,7 @@ compose_text (ptrdiff_t start, ptrdiff_t end, Lisp_Object components,
                       Qcomposition, prop, string);
 }
 
-
-static Lisp_Object autocmp_chars (Lisp_Object, ptrdiff_t, ptrdiff_t,
-                                  ptrdiff_t, struct window *,
-                                  struct face *, Lisp_Object);
-
-\f
-/* Lisp glyph-string handlers */
+/* Lisp glyph-string handlers.  */
 
 /* Hash table for automatic composition.  The key is a header of a
    lgstring (Lispy glyph-string), and the value is a body of a
@@ -677,7 +670,7 @@ composition_gstring_put_cache (Lisp_Object gstring, ptrdiff_t len)
   ptrdiff_t i;
 
   header = LGSTRING_HEADER (gstring);
-  hash = h->hashfn (h, header);
+  hash = h->test.hashfn (&h->test, header);
   if (len < 0)
     {
       ptrdiff_t j, glyph_len = LGSTRING_GLYPH_LEN (gstring);
@@ -709,7 +702,7 @@ static Lisp_Object fill_gstring_header (Lisp_Object, Lisp_Object,
                                         Lisp_Object, Lisp_Object,
                                         Lisp_Object);
 
-int
+bool
 composition_gstring_p (Lisp_Object gstring)
 {
   Lisp_Object header;
@@ -906,10 +899,12 @@ fill_gstring_body (Lisp_Object gstring)
    object.  Otherwise return nil.  */
 
 static Lisp_Object
-autocmp_chars (Lisp_Object rule, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t limit, struct window *win, struct face *face, Lisp_Object string)
+autocmp_chars (Lisp_Object rule, ptrdiff_t charpos, ptrdiff_t bytepos,
+              ptrdiff_t limit, struct window *win, struct face *face,
+              Lisp_Object string)
 {
   ptrdiff_t count = SPECPDL_INDEX ();
-  FRAME_PTR f = XFRAME (WGET (win, frame));
+  FRAME_PTR f = XFRAME (win->frame);
   Lisp_Object pos = make_number (charpos);
   ptrdiff_t to;
   ptrdiff_t pt = PT, pt_byte = PT_BYTE;
@@ -936,7 +931,7 @@ autocmp_chars (Lisp_Object rule, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t
 #ifdef HAVE_WINDOW_SYSTEM
   if (FRAME_WINDOW_P (f))
     {
-      font_object = font_range (charpos, &to, win, face, string);
+      font_object = font_range (charpos, bytepos, &to, win, face, string);
       if (! FONT_OBJECT_P (font_object)
          || (! NILP (re)
              && to < limit
@@ -945,7 +940,7 @@ autocmp_chars (Lisp_Object rule, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t
     }
   else
 #endif /* not HAVE_WINDOW_SYSTEM */
-    font_object = WGET (win, frame);
+    font_object = win->frame;
   lgstring = Fcomposition_get_gstring (pos, make_number (to), font_object,
                                       string);
   if (NILP (LGSTRING_ID (lgstring)))
@@ -1212,15 +1207,14 @@ composition_compute_stop_pos (struct composition_it *cmp_it, ptrdiff_t charpos,
    string.  In that case, FACE must not be NULL.
 
    If the character is composed, setup members of CMP_IT (id, nglyphs,
-   from, to, reversed_p), and return 1.  Otherwise, update
-   CMP_IT->stop_pos, and return 0.  */
+   from, to, reversed_p), and return true.  Otherwise, update
+   CMP_IT->stop_pos, and return false.  */
 
-int
-composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t endpos, struct window *w, struct face *face, Lisp_Object string)
+bool
+composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos,
+                      ptrdiff_t bytepos, ptrdiff_t endpos, struct window *w,
+                      struct face *face, Lisp_Object string)
 {
-  if (endpos < 0)
-    endpos = NILP (string) ? BEGV : 0;
-
   if (cmp_it->ch == -2)
     {
       composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string);
@@ -1229,6 +1223,9 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff
        return 0;
     }
 
+  if (endpos < 0)
+    endpos = NILP (string) ? BEGV : 0;
+
   if (cmp_it->ch < 0)
     {
       /* We are looking at a static composition.  */
@@ -1276,36 +1273,23 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff
        {
          ptrdiff_t cpos = charpos, bpos = bytepos;
 
-         while (1)
+         cmp_it->reversed_p = 1;
+         elt = XCAR (val);
+         if (cmp_it->lookback > 0)
            {
-             elt = XCAR (val);
-             if (cmp_it->lookback > 0)
-               {
-                 cpos = charpos - cmp_it->lookback;
-                 if (STRINGP (string))
-                   bpos = string_char_to_byte (string, cpos);
-                 else
-                   bpos = CHAR_TO_BYTE (cpos);
-               }
-             lgstring = autocmp_chars (elt, cpos, bpos, charpos + 1, w, face,
-                                       string);
-             if (composition_gstring_p (lgstring)
-                 && cpos + LGSTRING_CHAR_LEN (lgstring) - 1 == charpos)
-               break;
-             /* Composition failed or didn't cover the current
-                character.  */
-             if (cmp_it->lookback == 0)
-               goto no_composition;
-             lgstring = Qnil;
-             /* Try to find a shorter composition that starts after CPOS.  */
-             composition_compute_stop_pos (cmp_it, charpos, bytepos, cpos,
-                                           string);
-             if (cmp_it->ch == -2 || cmp_it->stop_pos < charpos)
-               goto no_composition;
-             val = CHAR_TABLE_REF (Vcomposition_function_table, cmp_it->ch);
-             for (i = 0; i < cmp_it->rule_idx; i++, val = XCDR (val));
+             cpos = charpos - cmp_it->lookback;
+             if (STRINGP (string))
+               bpos = string_char_to_byte (string, cpos);
+             else
+               bpos = CHAR_TO_BYTE (cpos);
            }
-         cmp_it->reversed_p = 1;
+         lgstring = autocmp_chars (elt, cpos, bpos, charpos + 1, w, face,
+                                   string);
+         if (! composition_gstring_p (lgstring)
+             || cpos + LGSTRING_CHAR_LEN (lgstring) - 1 != charpos)
+           /* Composition failed or didn't cover the current
+              character.  */
+           goto no_composition;
        }
       if (NILP (lgstring))
        goto no_composition;
@@ -1340,6 +1324,8 @@ composition_reseat_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff
       /* BYTEPOS is calculated in composition_compute_stop_pos */
       bytepos = -1;
     }
+  if (cmp_it->reversed_p)
+    endpos = -1;
   composition_compute_stop_pos (cmp_it, charpos, bytepos, endpos, string);
   return 0;
 }
@@ -1392,7 +1378,7 @@ composition_update_it (struct composition_it *cmp_it, ptrdiff_t charpos, ptrdiff
     }
   else
     {
-      /* automatic composition */
+      /* Automatic composition.  */
       Lisp_Object gstring = composition_gstring_from_id (cmp_it->id);
       Lisp_Object glyph;
       ptrdiff_t from;
@@ -1482,10 +1468,10 @@ struct position_record
 /* This is like find_composition, but find an automatic composition
    instead.  It is assured that POS is not within a static
    composition.  If found, set *GSTRING to the glyph-string
-   representing the composition, and return 1.  Otherwise, *GSTRING to
-   Qnil, and return 0.  */
+   representing the composition, and return true.  Otherwise, *GSTRING to
+   Qnil, and return false.  */
 
-static int
+static bool
 find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit,
                            ptrdiff_t *start, ptrdiff_t *end,
                            Lisp_Object *gstring, Lisp_Object string)
@@ -1498,7 +1484,7 @@ find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit,
   int c;
   Lisp_Object window;
   struct window *w;
-  int need_adjustment = 0;
+  bool need_adjustment = 0;
 
   window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
   if (NILP (window))
@@ -1968,7 +1954,7 @@ syms_of_composite (void)
   }
 
   staticpro (&gstring_work_headers);
-  gstring_work_headers = Fmake_vector (make_number (8), Qnil);
+  gstring_work_headers = make_uninit_vector (8);
   for (i = 0; i < 8; i++)
     ASET (gstring_work_headers, i, Fmake_vector (make_number (i + 2), Qnil));
   staticpro (&gstring_work);