]> code.delx.au - gnu-emacs/blobdiff - src/category.c
Fix line-move-visual's following of column in R2L lines.
[gnu-emacs] / src / category.c
index 13c6e46d283c6fffbc2cd3b35fc46c5a51a08c0d..b20493e5949ff3e5dd21bac10f2848146bd78fcd 100644 (file)
@@ -1,6 +1,6 @@
 /* GNU Emacs routines to deal with category tables.
 
-Copyright (C) 1998, 2001-201 Free Software Foundation, Inc.
+Copyright (C) 1998, 2001-2015 Free Software Foundation, Inc.
 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
   2005, 2006, 2007, 2008, 2009, 2010, 2011
   National Institute of Advanced Industrial Science and Technology (AIST)
@@ -30,10 +30,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
-#define CATEGORY_INLINE EXTERN_INLINE
-
-#include <ctype.h>
-#include <setjmp.h>
 #include "lisp.h"
 #include "character.h"
 #include "buffer.h"
@@ -41,6 +37,13 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "category.h"
 #include "keymap.h"
 
+/* This setter is used only in this file, so it can be private.  */
+static void
+bset_category_table (struct buffer *b, Lisp_Object val)
+{
+  b->INTERNAL_FIELD (category_table) = val;
+}
+
 /* The version number of the latest category table.  Each category
    table has a unique version number.  It is assigned a new number
    also when it is modified.  When a regular expression is compiled
@@ -50,19 +53,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
    For the moment, we are not using this feature.  */
 static int category_table_version;
-
-static Lisp_Object Qcategory_table, Qcategoryp, Qcategorysetp, Qcategory_table_p;
-
-/* Make CATEGORY_SET includes (if VAL is t) or excludes (if VAL is
-   nil) CATEGORY.  */
-#define SET_CATEGORY_SET(category_set, category, val) \
-  set_category_set (category_set, category, val)
-static void set_category_set (Lisp_Object, Lisp_Object, Lisp_Object);
 \f
 /* Category set staff.  */
 
-static Lisp_Object hash_get_category_set (Lisp_Object, Lisp_Object);
-
 static Lisp_Object
 hash_get_category_set (Lisp_Object table, Lisp_Object category_set)
 {
@@ -71,11 +64,12 @@ hash_get_category_set (Lisp_Object table, Lisp_Object category_set)
   EMACS_UINT hash;
 
   if (NILP (XCHAR_TABLE (table)->extras[1]))
-    XCHAR_TABLE (table)->extras[1]
-      = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
-                        make_float (DEFAULT_REHASH_SIZE),
-                        make_float (DEFAULT_REHASH_THRESHOLD),
-                        Qnil, Qnil, Qnil);
+    set_char_table_extras
+      (table, 1,
+       make_hash_table (hashtest_equal, make_number (DEFAULT_HASH_SIZE),
+                       make_float (DEFAULT_REHASH_SIZE),
+                       make_float (DEFAULT_REHASH_THRESHOLD),
+                       Qnil));
   h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]);
   i = hash_lookup (h, category_set, &hash);
   if (i >= 0)
@@ -84,6 +78,13 @@ hash_get_category_set (Lisp_Object table, Lisp_Object category_set)
   return category_set;
 }
 
+/* Make CATEGORY_SET include (if VAL) or exclude (if !VAL) CATEGORY.  */
+
+static void
+set_category_set (Lisp_Object category_set, EMACS_INT category, bool val)
+{
+  bool_vector_set (category_set, category, val);
+}
 
 DEFUN ("make-category-set", Fmake_category_set, Smake_category_set, 1, 1, 0,
        doc: /* Return a newly created category-set which contains CATEGORIES.
@@ -93,7 +94,7 @@ those categories.  */)
   (Lisp_Object categories)
 {
   Lisp_Object val;
-  int len;
+  ptrdiff_t len;
 
   CHECK_STRING (categories);
   val = MAKE_CATEGORY_SET;
@@ -104,11 +105,11 @@ those categories.  */)
   len = SCHARS (categories);
   while (--len >= 0)
     {
-      Lisp_Object category;
+      unsigned char cat = SREF (categories, len);
+      Lisp_Object category = make_number (cat);
 
-      XSETFASTINT (category, SREF (categories, len));
       CHECK_CATEGORY (category);
-      SET_CATEGORY_SET (val, category, Qt);
+      set_category_set (val, cat, 1);
     }
   return val;
 }
@@ -136,7 +137,7 @@ the current buffer's category table.  */)
     error ("Category `%c' is already defined", (int) XFASTINT (category));
   if (!NILP (Vpurify_flag))
     docstring = Fpurecopy (docstring);
-  CATEGORY_DOCSTRING (table, XFASTINT (category)) = docstring;
+  SET_CATEGORY_DOCSTRING (table, XFASTINT (category), docstring);
 
   return Qnil;
 }
@@ -238,10 +239,10 @@ copy_category_table (Lisp_Object table)
   table = copy_char_table (table);
 
   if (! NILP (XCHAR_TABLE (table)->defalt))
-    XCHAR_TABLE (table)->defalt
-      = Fcopy_sequence (XCHAR_TABLE (table)->defalt);
-  XCHAR_TABLE (table)->extras[0]
-    = Fcopy_sequence (XCHAR_TABLE (table)->extras[0]);
+    set_char_table_defalt (table,
+                          Fcopy_sequence (XCHAR_TABLE (table)->defalt));
+  set_char_table_extras
+    (table, 0, Fcopy_sequence (XCHAR_TABLE (table)->extras[0]));
   map_char_table (copy_category_entry, Qnil, table, table);
 
   return table;
@@ -270,9 +271,9 @@ DEFUN ("make-category-table", Fmake_category_table, Smake_category_table,
   int i;
 
   val = Fmake_char_table (Qcategory_table, Qnil);
-  XCHAR_TABLE (val)->defalt = MAKE_CATEGORY_SET;
+  set_char_table_defalt (val, MAKE_CATEGORY_SET);
   for (i = 0; i < (1 << CHARTAB_SIZE_BITS_0); i++)
-    XCHAR_TABLE (val)->contents[i] = MAKE_CATEGORY_SET;
+    set_char_table_contents (val, i, MAKE_CATEGORY_SET);
   Fset_char_table_extra_slot (val, make_number (0),
                              Fmake_vector (make_number (95), Qnil));
   return val;
@@ -285,7 +286,7 @@ Return TABLE.  */)
 {
   int idx;
   table = check_category_table (table);
-  BSET (current_buffer, category_table, table);
+  bset_category_table (current_buffer, table);
   /* Indicate that this buffer now has a specified category table.  */
   idx = PER_BUFFER_VAR_IDX (category_table);
   SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1);
@@ -330,20 +331,6 @@ The return value is a string containing those same categories.  */)
   return build_string (str);
 }
 
-static void
-set_category_set (Lisp_Object category_set, Lisp_Object category, Lisp_Object val)
-{
-  do {
-    int idx = XINT (category) / 8;
-    unsigned char bits = 1 << (XINT (category) % 8);
-
-    if (NILP (val))
-      XCATEGORY_SET (category_set)->data[idx] &= ~bits;
-    else
-      XCATEGORY_SET (category_set)->data[idx] |= bits;
-  } while (0);
-}
-
 DEFUN ("modify-category-entry", Fmodify_category_entry,
        Smodify_category_entry, 2, 4, 0,
        doc: /* Modify the category set of CHARACTER by adding CATEGORY to it.
@@ -355,7 +342,7 @@ If optional fourth argument RESET is non-nil,
 then delete CATEGORY from the category set instead of adding it.  */)
   (Lisp_Object character, Lisp_Object category, Lisp_Object table, Lisp_Object reset)
 {
-  Lisp_Object set_value;       /* Actual value to be set in category sets.  */
+  bool set_value;      /* Actual value to be set in category sets.  */
   Lisp_Object category_set;
   int start, end;
   int from, to;
@@ -380,7 +367,7 @@ then delete CATEGORY from the category set instead of adding it.  */)
   if (NILP (CATEGORY_DOCSTRING (table, XFASTINT (category))))
     error ("Undefined category: %c", (int) XFASTINT (category));
 
-  set_value = NILP (reset) ? Qt : Qnil;
+  set_value = NILP (reset);
 
   while (start <= end)
     {
@@ -389,7 +376,7 @@ then delete CATEGORY from the category set instead of adding it.  */)
       if (CATEGORY_MEMBER (XFASTINT (category), category_set) != NILP (reset))
        {
          category_set = Fcopy_sequence (category_set);
-         SET_CATEGORY_SET (category_set, category, set_value);
+         set_category_set (category_set, XFASTINT (category), set_value);
          category_set = hash_get_category_set (table, category_set);
          char_table_set_range (table, start, to, category_set);
        }
@@ -399,17 +386,17 @@ then delete CATEGORY from the category set instead of adding it.  */)
   return Qnil;
 }
 \f
-/* Return 1 if there is a word boundary between two word-constituent
-   characters C1 and C2 if they appear in this order, else return 0.
+/* Return true if there is a word boundary between two word-constituent
+   characters C1 and C2 if they appear in this order.
    Use the macro WORD_BOUNDARY_P instead of calling this function
    directly.  */
 
-int
+bool
 word_boundary_p (int c1, int c2)
 {
   Lisp_Object category_set1, category_set2;
   Lisp_Object tail;
-  int default_result;
+  bool default_result;
 
   if (EQ (CHAR_TABLE_REF (Vchar_script_table, c1),
          CHAR_TABLE_REF (Vchar_script_table, c2)))
@@ -454,19 +441,11 @@ init_category_once (void)
 {
   /* This has to be done here, before we call Fmake_char_table.  */
   DEFSYM (Qcategory_table, "category-table");
-
-  /* Intern this now in case it isn't already done.
-     Setting this variable twice is harmless.
-     But don't staticpro it here--that is done in alloc.c.  */
-  Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots");
-
-  /* Now we are ready to set up this property, so we can
-     create category tables.  */
   Fput (Qcategory_table, Qchar_table_extra_slots, make_number (2));
 
   Vstandard_category_table = Fmake_char_table (Qcategory_table, Qnil);
   /* Set a category set which contains nothing to the default.  */
-  XCHAR_TABLE (Vstandard_category_table)->defalt = MAKE_CATEGORY_SET;
+  set_char_table_defalt (Vstandard_category_table, MAKE_CATEGORY_SET);
   Fset_char_table_extra_slot (Vstandard_category_table, make_number (0),
                              Fmake_vector (make_number (95), Qnil));
 }