1 /* XEmacs routines to deal with char tables.
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
3 Copyright (C) 1995 Sun Microsystems, Inc.
4 Copyright (C) 1995, 1996 Ben Wing.
5 Copyright (C) 1995, 1997, 1999 Electrotechnical Laboratory, JAPAN.
6 Licensed to the Free Software Foundation.
8 This file is part of XEmacs.
10 XEmacs is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation; either version 2, or (at your option) any
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with XEmacs; see the file COPYING. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* Synched up with: Mule 2.3. Not synched with FSF.
27 This file was written independently of the FSF implementation,
28 and is not compatible. */
32 Ben Wing: wrote, for 19.13 (Mule). Some category table stuff
33 loosely based on the original Mule.
34 Jareth Hein: fixed a couple of bugs in the implementation, and
35 added regex support for categories with check_category_at
45 Lisp_Object Qchar_tablep, Qchar_table;
47 Lisp_Object Vall_syntax_tables;
50 Lisp_Object Qcategory_table_p;
51 Lisp_Object Qcategory_designator_p;
52 Lisp_Object Qcategory_table_value_p;
54 Lisp_Object Vstandard_category_table;
56 /* Variables to determine word boundary. */
57 Lisp_Object Vword_combining_categories, Vword_separating_categories;
61 /* A char table maps from ranges of characters to values.
63 Implementing a general data structure that maps from arbitrary
64 ranges of numbers to values is tricky to do efficiently. As it
65 happens, it should suffice (and is usually more convenient, anyway)
66 when dealing with characters to restrict the sorts of ranges that
67 can be assigned values, as follows:
70 2) All characters in a charset.
71 3) All characters in a particular row of a charset, where a "row"
72 means all characters with the same first byte.
73 4) A particular character in a charset.
75 We use char tables to generalize the 256-element vectors now
76 littering the Emacs code.
78 Possible uses (all should be converted at some point):
84 5) keyboard-translate-table?
87 abstract type to generalize the Emacs vectors and Mule
88 vectors-of-vectors goo.
91 /************************************************************************/
92 /* Char Table object */
93 /************************************************************************/
98 mark_char_table_entry (Lisp_Object obj)
100 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
103 for (i = 0; i < 96; i++)
105 mark_object (cte->level2[i]);
111 char_table_entry_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
113 Lisp_Char_Table_Entry *cte1 = XCHAR_TABLE_ENTRY (obj1);
114 Lisp_Char_Table_Entry *cte2 = XCHAR_TABLE_ENTRY (obj2);
117 for (i = 0; i < 96; i++)
118 if (!internal_equal (cte1->level2[i], cte2->level2[i], depth + 1))
125 char_table_entry_hash (Lisp_Object obj, int depth)
127 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
129 return internal_array_hash (cte->level2, 96, depth);
132 static const struct lrecord_description char_table_entry_description[] = {
133 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table_Entry, level2), 96 },
137 DEFINE_LRECORD_IMPLEMENTATION ("char-table-entry", char_table_entry,
138 mark_char_table_entry, internal_object_printer,
139 0, char_table_entry_equal,
140 char_table_entry_hash,
141 char_table_entry_description,
142 Lisp_Char_Table_Entry);
146 mark_char_table (Lisp_Object obj)
148 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
151 for (i = 0; i < NUM_ASCII_CHARS; i++)
152 mark_object (ct->ascii[i]);
154 for (i = 0; i < NUM_LEADING_BYTES; i++)
155 mark_object (ct->level1[i]);
157 return ct->mirror_table;
160 /* WARNING: All functions of this nature need to be written extremely
161 carefully to avoid crashes during GC. Cf. prune_specifiers()
162 and prune_weak_hash_tables(). */
165 prune_syntax_tables (void)
167 Lisp_Object rest, prev = Qnil;
169 for (rest = Vall_syntax_tables;
171 rest = XCHAR_TABLE (rest)->next_table)
173 if (! marked_p (rest))
175 /* This table is garbage. Remove it from the list. */
177 Vall_syntax_tables = XCHAR_TABLE (rest)->next_table;
179 XCHAR_TABLE (prev)->next_table =
180 XCHAR_TABLE (rest)->next_table;
186 char_table_type_to_symbol (enum char_table_type type)
191 case CHAR_TABLE_TYPE_GENERIC: return Qgeneric;
192 case CHAR_TABLE_TYPE_SYNTAX: return Qsyntax;
193 case CHAR_TABLE_TYPE_DISPLAY: return Qdisplay;
194 case CHAR_TABLE_TYPE_CHAR: return Qchar;
196 case CHAR_TABLE_TYPE_CATEGORY: return Qcategory;
201 static enum char_table_type
202 symbol_to_char_table_type (Lisp_Object symbol)
204 CHECK_SYMBOL (symbol);
206 if (EQ (symbol, Qgeneric)) return CHAR_TABLE_TYPE_GENERIC;
207 if (EQ (symbol, Qsyntax)) return CHAR_TABLE_TYPE_SYNTAX;
208 if (EQ (symbol, Qdisplay)) return CHAR_TABLE_TYPE_DISPLAY;
209 if (EQ (symbol, Qchar)) return CHAR_TABLE_TYPE_CHAR;
211 if (EQ (symbol, Qcategory)) return CHAR_TABLE_TYPE_CATEGORY;
214 signal_simple_error ("Unrecognized char table type", symbol);
215 return CHAR_TABLE_TYPE_GENERIC; /* not reached */
219 print_chartab_range (Emchar first, Emchar last, Lisp_Object val,
220 Lisp_Object printcharfun)
224 write_c_string (" (", printcharfun);
225 print_internal (make_char (first), printcharfun, 0);
226 write_c_string (" ", printcharfun);
227 print_internal (make_char (last), printcharfun, 0);
228 write_c_string (") ", printcharfun);
232 write_c_string (" ", printcharfun);
233 print_internal (make_char (first), printcharfun, 0);
234 write_c_string (" ", printcharfun);
236 print_internal (val, printcharfun, 1);
242 print_chartab_charset_row (Lisp_Object charset,
244 Lisp_Char_Table_Entry *cte,
245 Lisp_Object printcharfun)
248 Lisp_Object cat = Qunbound;
251 for (i = 32; i < 128; i++)
253 Lisp_Object pam = cte->level2[i - 32];
265 print_chartab_range (MAKE_CHAR (charset, first, 0),
266 MAKE_CHAR (charset, i - 1, 0),
269 print_chartab_range (MAKE_CHAR (charset, row, first),
270 MAKE_CHAR (charset, row, i - 1),
280 print_chartab_range (MAKE_CHAR (charset, first, 0),
281 MAKE_CHAR (charset, i - 1, 0),
284 print_chartab_range (MAKE_CHAR (charset, row, first),
285 MAKE_CHAR (charset, row, i - 1),
291 print_chartab_two_byte_charset (Lisp_Object charset,
292 Lisp_Char_Table_Entry *cte,
293 Lisp_Object printcharfun)
297 for (i = 32; i < 128; i++)
299 Lisp_Object jen = cte->level2[i - 32];
301 if (!CHAR_TABLE_ENTRYP (jen))
305 write_c_string (" [", printcharfun);
306 print_internal (XCHARSET_NAME (charset), printcharfun, 0);
307 sprintf (buf, " %d] ", i);
308 write_c_string (buf, printcharfun);
309 print_internal (jen, printcharfun, 0);
312 print_chartab_charset_row (charset, i, XCHAR_TABLE_ENTRY (jen),
320 print_char_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
322 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
325 sprintf (buf, "#s(char-table type %s data (",
326 string_data (symbol_name (XSYMBOL
327 (char_table_type_to_symbol (ct->type)))));
328 write_c_string (buf, printcharfun);
330 /* Now write out the ASCII/Control-1 stuff. */
334 Lisp_Object val = Qunbound;
336 for (i = 0; i < NUM_ASCII_CHARS; i++)
345 if (!EQ (ct->ascii[i], val))
347 print_chartab_range (first, i - 1, val, printcharfun);
354 print_chartab_range (first, i - 1, val, printcharfun);
361 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
364 Lisp_Object ann = ct->level1[i - MIN_LEADING_BYTE];
365 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (i);
367 if (!CHARSETP (charset) || i == LEADING_BYTE_ASCII
368 || i == LEADING_BYTE_CONTROL_1)
370 if (!CHAR_TABLE_ENTRYP (ann))
372 write_c_string (" ", printcharfun);
373 print_internal (XCHARSET_NAME (charset),
375 write_c_string (" ", printcharfun);
376 print_internal (ann, printcharfun, 0);
380 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (ann);
381 if (XCHARSET_DIMENSION (charset) == 1)
382 print_chartab_charset_row (charset, -1, cte, printcharfun);
384 print_chartab_two_byte_charset (charset, cte, printcharfun);
390 write_c_string ("))", printcharfun);
394 char_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
396 Lisp_Char_Table *ct1 = XCHAR_TABLE (obj1);
397 Lisp_Char_Table *ct2 = XCHAR_TABLE (obj2);
400 if (CHAR_TABLE_TYPE (ct1) != CHAR_TABLE_TYPE (ct2))
403 for (i = 0; i < NUM_ASCII_CHARS; i++)
404 if (!internal_equal (ct1->ascii[i], ct2->ascii[i], depth + 1))
408 for (i = 0; i < NUM_LEADING_BYTES; i++)
409 if (!internal_equal (ct1->level1[i], ct2->level1[i], depth + 1))
417 char_table_hash (Lisp_Object obj, int depth)
419 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
420 unsigned long hashval = internal_array_hash (ct->ascii, NUM_ASCII_CHARS,
423 hashval = HASH2 (hashval,
424 internal_array_hash (ct->level1, NUM_LEADING_BYTES, depth));
429 static const struct lrecord_description char_table_description[] = {
430 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, ascii), NUM_ASCII_CHARS },
432 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, level1), NUM_LEADING_BYTES },
434 { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, mirror_table) },
435 { XD_LO_LINK, offsetof (Lisp_Char_Table, next_table) },
439 DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table,
440 mark_char_table, print_char_table, 0,
441 char_table_equal, char_table_hash,
442 char_table_description,
445 DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /*
446 Return non-nil if OBJECT is a char table.
448 A char table is a table that maps characters (or ranges of characters)
449 to values. Char tables are specialized for characters, only allowing
450 particular sorts of ranges to be assigned values. Although this
451 loses in generality, it makes for extremely fast (constant-time)
452 lookups, and thus is feasible for applications that do an extremely
453 large number of lookups (e.g. scanning a buffer for a character in
454 a particular syntax, where a lookup in the syntax table must occur
457 When Mule support exists, the types of ranges that can be assigned
462 -- a single row in a two-octet charset
463 -- a single character
465 When Mule support is not present, the types of ranges that can be
469 -- a single character
471 To create a char table, use `make-char-table'.
472 To modify a char table, use `put-char-table' or `remove-char-table'.
473 To retrieve the value for a particular character, use `get-char-table'.
474 See also `map-char-table', `clear-char-table', `copy-char-table',
475 `valid-char-table-type-p', `char-table-type-list',
476 `valid-char-table-value-p', and `check-char-table-value'.
480 return CHAR_TABLEP (object) ? Qt : Qnil;
483 DEFUN ("char-table-type-list", Fchar_table_type_list, 0, 0, 0, /*
484 Return a list of the recognized char table types.
485 See `valid-char-table-type-p'.
490 return list5 (Qchar, Qcategory, Qdisplay, Qgeneric, Qsyntax);
492 return list4 (Qchar, Qdisplay, Qgeneric, Qsyntax);
496 DEFUN ("valid-char-table-type-p", Fvalid_char_table_type_p, 1, 1, 0, /*
497 Return t if TYPE if a recognized char table type.
499 Each char table type is used for a different purpose and allows different
500 sorts of values. The different char table types are
503 Used for category tables, which specify the regexp categories
504 that a character is in. The valid values are nil or a
505 bit vector of 95 elements. Higher-level Lisp functions are
506 provided for working with category tables. Currently categories
507 and category tables only exist when Mule support is present.
509 A generalized char table, for mapping from one character to
510 another. Used for case tables, syntax matching tables,
511 `keyboard-translate-table', etc. The valid values are characters.
513 An even more generalized char table, for mapping from a
514 character to anything.
516 Used for display tables, which specify how a particular character
517 is to appear when displayed. #### Not yet implemented.
519 Used for syntax tables, which specify the syntax of a particular
520 character. Higher-level Lisp functions are provided for
521 working with syntax tables. The valid values are integers.
526 return (EQ (type, Qchar) ||
528 EQ (type, Qcategory) ||
530 EQ (type, Qdisplay) ||
531 EQ (type, Qgeneric) ||
532 EQ (type, Qsyntax)) ? Qt : Qnil;
535 DEFUN ("char-table-type", Fchar_table_type, 1, 1, 0, /*
536 Return the type of CHAR-TABLE.
537 See `valid-char-table-type-p'.
541 CHECK_CHAR_TABLE (char_table);
542 return char_table_type_to_symbol (XCHAR_TABLE (char_table)->type);
546 fill_char_table (Lisp_Char_Table *ct, Lisp_Object value)
550 for (i = 0; i < NUM_ASCII_CHARS; i++)
551 ct->ascii[i] = value;
553 for (i = 0; i < NUM_LEADING_BYTES; i++)
554 ct->level1[i] = value;
557 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
558 update_syntax_table (ct);
561 DEFUN ("reset-char-table", Freset_char_table, 1, 1, 0, /*
562 Reset CHAR-TABLE to its default state.
568 CHECK_CHAR_TABLE (char_table);
569 ct = XCHAR_TABLE (char_table);
573 case CHAR_TABLE_TYPE_CHAR:
574 fill_char_table (ct, make_char (0));
576 case CHAR_TABLE_TYPE_DISPLAY:
577 case CHAR_TABLE_TYPE_GENERIC:
579 case CHAR_TABLE_TYPE_CATEGORY:
581 fill_char_table (ct, Qnil);
584 case CHAR_TABLE_TYPE_SYNTAX:
585 fill_char_table (ct, make_int (Sinherit));
595 DEFUN ("make-char-table", Fmake_char_table, 1, 1, 0, /*
596 Return a new, empty char table of type TYPE.
597 Currently recognized types are 'char, 'category, 'display, 'generic,
598 and 'syntax. See `valid-char-table-type-p'.
604 enum char_table_type ty = symbol_to_char_table_type (type);
606 ct = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
608 if (ty == CHAR_TABLE_TYPE_SYNTAX)
610 ct->mirror_table = Fmake_char_table (Qgeneric);
611 fill_char_table (XCHAR_TABLE (ct->mirror_table),
615 ct->mirror_table = Qnil;
616 ct->next_table = Qnil;
617 XSETCHAR_TABLE (obj, ct);
618 if (ty == CHAR_TABLE_TYPE_SYNTAX)
620 ct->next_table = Vall_syntax_tables;
621 Vall_syntax_tables = obj;
623 Freset_char_table (obj);
630 make_char_table_entry (Lisp_Object initval)
634 Lisp_Char_Table_Entry *cte =
635 alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
637 for (i = 0; i < 96; i++)
638 cte->level2[i] = initval;
640 XSETCHAR_TABLE_ENTRY (obj, cte);
645 copy_char_table_entry (Lisp_Object entry)
647 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
650 Lisp_Char_Table_Entry *ctenew =
651 alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
653 for (i = 0; i < 96; i++)
655 Lisp_Object new = cte->level2[i];
656 if (CHAR_TABLE_ENTRYP (new))
657 ctenew->level2[i] = copy_char_table_entry (new);
659 ctenew->level2[i] = new;
662 XSETCHAR_TABLE_ENTRY (obj, ctenew);
668 DEFUN ("copy-char-table", Fcopy_char_table, 1, 1, 0, /*
669 Return a new char table which is a copy of CHAR-TABLE.
670 It will contain the same values for the same characters and ranges
671 as CHAR-TABLE. The values will not themselves be copied.
675 Lisp_Char_Table *ct, *ctnew;
679 CHECK_CHAR_TABLE (char_table);
680 ct = XCHAR_TABLE (char_table);
681 ctnew = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
682 ctnew->type = ct->type;
684 for (i = 0; i < NUM_ASCII_CHARS; i++)
686 Lisp_Object new = ct->ascii[i];
688 assert (! (CHAR_TABLE_ENTRYP (new)));
690 ctnew->ascii[i] = new;
695 for (i = 0; i < NUM_LEADING_BYTES; i++)
697 Lisp_Object new = ct->level1[i];
698 if (CHAR_TABLE_ENTRYP (new))
699 ctnew->level1[i] = copy_char_table_entry (new);
701 ctnew->level1[i] = new;
706 if (CHAR_TABLEP (ct->mirror_table))
707 ctnew->mirror_table = Fcopy_char_table (ct->mirror_table);
709 ctnew->mirror_table = ct->mirror_table;
710 ctnew->next_table = Qnil;
711 XSETCHAR_TABLE (obj, ctnew);
712 if (ctnew->type == CHAR_TABLE_TYPE_SYNTAX)
714 ctnew->next_table = Vall_syntax_tables;
715 Vall_syntax_tables = obj;
721 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange)
724 outrange->type = CHARTAB_RANGE_ALL;
725 else if (CHAR_OR_CHAR_INTP (range))
727 outrange->type = CHARTAB_RANGE_CHAR;
728 outrange->ch = XCHAR_OR_CHAR_INT (range);
732 signal_simple_error ("Range must be t or a character", range);
734 else if (VECTORP (range))
736 Lisp_Vector *vec = XVECTOR (range);
737 Lisp_Object *elts = vector_data (vec);
738 if (vector_length (vec) != 2)
739 signal_simple_error ("Length of charset row vector must be 2",
741 outrange->type = CHARTAB_RANGE_ROW;
742 outrange->charset = Fget_charset (elts[0]);
744 outrange->row = XINT (elts[1]);
745 if (XCHARSET_DIMENSION (outrange->charset) >= 2)
747 switch (XCHARSET_CHARS (outrange->charset))
750 check_int_range (outrange->row, 33, 126);
753 check_int_range (outrange->row, 32, 127);
760 signal_simple_error ("Charset in row vector must be multi-byte",
765 if (!CHARSETP (range) && !SYMBOLP (range))
767 ("Char table range must be t, charset, char, or vector", range);
768 outrange->type = CHARTAB_RANGE_CHARSET;
769 outrange->charset = Fget_charset (range);
776 /* called from CHAR_TABLE_VALUE(). */
778 get_non_ascii_char_table_value (Lisp_Char_Table *ct, Charset_ID leading_byte,
785 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (leading_byte);
790 BREAKUP_CHAR (c, charset, byte1, byte2);
792 BREAKUP_CHAR_1_UNSAFE (c, charset, byte1, byte2);
794 val = ct->level1[leading_byte - MIN_LEADING_BYTE];
795 if (CHAR_TABLE_ENTRYP (val))
797 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
798 val = cte->level2[byte1 - 32];
799 if (CHAR_TABLE_ENTRYP (val))
801 cte = XCHAR_TABLE_ENTRY (val);
802 assert (byte2 >= 32);
803 val = cte->level2[byte2 - 32];
804 assert (!CHAR_TABLE_ENTRYP (val));
814 get_char_table (Emchar ch, Lisp_Char_Table *ct)
822 BREAKUP_CHAR (ch, charset, byte1, byte2);
824 if (EQ (charset, Vcharset_ascii))
825 val = ct->ascii[byte1];
826 else if (EQ (charset, Vcharset_control_1))
827 val = ct->ascii[byte1 + 128];
830 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
831 val = ct->level1[lb];
832 if (CHAR_TABLE_ENTRYP (val))
834 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
835 val = cte->level2[byte1 - 32];
836 if (CHAR_TABLE_ENTRYP (val))
838 cte = XCHAR_TABLE_ENTRY (val);
839 assert (byte2 >= 32);
840 val = cte->level2[byte2 - 32];
841 assert (!CHAR_TABLE_ENTRYP (val));
849 return ct->ascii[(unsigned char)ch];
850 #endif /* not MULE */
854 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
855 Find value for CHARACTER in CHAR-TABLE.
857 (character, char_table))
859 CHECK_CHAR_TABLE (char_table);
860 CHECK_CHAR_COERCE_INT (character);
862 return get_char_table (XCHAR (character), XCHAR_TABLE (char_table));
865 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
866 Find value for a range in CHAR-TABLE.
867 If there is more than one value, return MULTI (defaults to nil).
869 (range, char_table, multi))
872 struct chartab_range rainj;
874 if (CHAR_OR_CHAR_INTP (range))
875 return Fget_char_table (range, char_table);
876 CHECK_CHAR_TABLE (char_table);
877 ct = XCHAR_TABLE (char_table);
879 decode_char_table_range (range, &rainj);
882 case CHARTAB_RANGE_ALL:
885 Lisp_Object first = ct->ascii[0];
887 for (i = 1; i < NUM_ASCII_CHARS; i++)
888 if (!EQ (first, ct->ascii[i]))
892 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
895 if (!CHARSETP (CHARSET_BY_LEADING_BYTE (i))
896 || i == LEADING_BYTE_ASCII
897 || i == LEADING_BYTE_CONTROL_1)
899 if (!EQ (first, ct->level1[i - MIN_LEADING_BYTE]))
908 case CHARTAB_RANGE_CHARSET:
909 if (EQ (rainj.charset, Vcharset_ascii))
912 Lisp_Object first = ct->ascii[0];
914 for (i = 1; i < 128; i++)
915 if (!EQ (first, ct->ascii[i]))
920 if (EQ (rainj.charset, Vcharset_control_1))
923 Lisp_Object first = ct->ascii[128];
925 for (i = 129; i < 160; i++)
926 if (!EQ (first, ct->ascii[i]))
932 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
934 if (CHAR_TABLE_ENTRYP (val))
939 case CHARTAB_RANGE_ROW:
941 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
943 if (!CHAR_TABLE_ENTRYP (val))
945 val = XCHAR_TABLE_ENTRY (val)->level2[rainj.row - 32];
946 if (CHAR_TABLE_ENTRYP (val))
950 #endif /* not MULE */
956 return Qnil; /* not reached */
960 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
965 case CHAR_TABLE_TYPE_SYNTAX:
966 if (!ERRB_EQ (errb, ERROR_ME))
967 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
968 && CHAR_OR_CHAR_INTP (XCDR (value)));
971 Lisp_Object cdr = XCDR (value);
972 CHECK_INT (XCAR (value));
973 CHECK_CHAR_COERCE_INT (cdr);
980 case CHAR_TABLE_TYPE_CATEGORY:
981 if (!ERRB_EQ (errb, ERROR_ME))
982 return CATEGORY_TABLE_VALUEP (value);
983 CHECK_CATEGORY_TABLE_VALUE (value);
987 case CHAR_TABLE_TYPE_GENERIC:
990 case CHAR_TABLE_TYPE_DISPLAY:
992 maybe_signal_simple_error ("Display char tables not yet implemented",
993 value, Qchar_table, errb);
996 case CHAR_TABLE_TYPE_CHAR:
997 if (!ERRB_EQ (errb, ERROR_ME))
998 return CHAR_OR_CHAR_INTP (value);
999 CHECK_CHAR_COERCE_INT (value);
1006 return 0; /* not reached */
1010 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
1014 case CHAR_TABLE_TYPE_SYNTAX:
1017 Lisp_Object car = XCAR (value);
1018 Lisp_Object cdr = XCDR (value);
1019 CHECK_CHAR_COERCE_INT (cdr);
1020 return Fcons (car, cdr);
1023 case CHAR_TABLE_TYPE_CHAR:
1024 CHECK_CHAR_COERCE_INT (value);
1032 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
1033 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
1035 (value, char_table_type))
1037 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1039 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
1042 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
1043 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
1045 (value, char_table_type))
1047 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1049 check_valid_char_table_value (value, type, ERROR_ME);
1053 /* Assign VAL to all characters in RANGE in char table CT. */
1056 put_char_table (Lisp_Char_Table *ct, struct chartab_range *range,
1059 switch (range->type)
1061 case CHARTAB_RANGE_ALL:
1062 fill_char_table (ct, val);
1063 return; /* avoid the duplicate call to update_syntax_table() below,
1064 since fill_char_table() also did that. */
1067 case CHARTAB_RANGE_CHARSET:
1068 if (EQ (range->charset, Vcharset_ascii))
1071 for (i = 0; i < 128; i++)
1074 else if (EQ (range->charset, Vcharset_control_1))
1077 for (i = 128; i < 160; i++)
1082 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1083 ct->level1[lb] = val;
1087 case CHARTAB_RANGE_ROW:
1089 Lisp_Char_Table_Entry *cte;
1090 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1091 /* make sure that there is a separate entry for the row. */
1092 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1093 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1094 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1095 cte->level2[range->row - 32] = val;
1100 case CHARTAB_RANGE_CHAR:
1103 Lisp_Object charset;
1106 BREAKUP_CHAR (range->ch, charset, byte1, byte2);
1107 if (EQ (charset, Vcharset_ascii))
1108 ct->ascii[byte1] = val;
1109 else if (EQ (charset, Vcharset_control_1))
1110 ct->ascii[byte1 + 128] = val;
1113 Lisp_Char_Table_Entry *cte;
1114 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
1115 /* make sure that there is a separate entry for the row. */
1116 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1117 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1118 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1119 /* now CTE is a char table entry for the charset;
1120 each entry is for a single row (or character of
1121 a one-octet charset). */
1122 if (XCHARSET_DIMENSION (charset) == 1)
1123 cte->level2[byte1 - 32] = val;
1126 /* assigning to one character in a two-octet charset. */
1127 /* make sure that the charset row contains a separate
1128 entry for each character. */
1129 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
1130 cte->level2[byte1 - 32] =
1131 make_char_table_entry (cte->level2[byte1 - 32]);
1132 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
1133 cte->level2[byte2 - 32] = val;
1137 #else /* not MULE */
1138 ct->ascii[(unsigned char) (range->ch)] = val;
1140 #endif /* not MULE */
1143 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
1144 update_syntax_table (ct);
1147 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
1148 Set the value for chars in RANGE to be VALUE in CHAR-TABLE.
1150 RANGE specifies one or more characters to be affected and should be
1151 one of the following:
1153 -- t (all characters are affected)
1154 -- A charset (only allowed when Mule support is present)
1155 -- A vector of two elements: a two-octet charset and a row number
1156 (only allowed when Mule support is present)
1157 -- A single character
1159 VALUE must be a value appropriate for the type of CHAR-TABLE.
1160 See `valid-char-table-type-p'.
1162 (range, value, char_table))
1164 Lisp_Char_Table *ct;
1165 struct chartab_range rainj;
1167 CHECK_CHAR_TABLE (char_table);
1168 ct = XCHAR_TABLE (char_table);
1169 check_valid_char_table_value (value, ct->type, ERROR_ME);
1170 decode_char_table_range (range, &rainj);
1171 value = canonicalize_char_table_value (value, ct->type);
1172 put_char_table (ct, &rainj, value);
1176 /* Map FN over the ASCII chars in CT. */
1179 map_over_charset_ascii (Lisp_Char_Table *ct,
1180 int (*fn) (struct chartab_range *range,
1181 Lisp_Object val, void *arg),
1184 struct chartab_range rainj;
1193 rainj.type = CHARTAB_RANGE_CHAR;
1195 for (i = start, retval = 0; i < stop && retval == 0; i++)
1197 rainj.ch = (Emchar) i;
1198 retval = (fn) (&rainj, ct->ascii[i], arg);
1206 /* Map FN over the Control-1 chars in CT. */
1209 map_over_charset_control_1 (Lisp_Char_Table *ct,
1210 int (*fn) (struct chartab_range *range,
1211 Lisp_Object val, void *arg),
1214 struct chartab_range rainj;
1217 int stop = start + 32;
1219 rainj.type = CHARTAB_RANGE_CHAR;
1221 for (i = start, retval = 0; i < stop && retval == 0; i++)
1223 rainj.ch = (Emchar) (i);
1224 retval = (fn) (&rainj, ct->ascii[i], arg);
1230 /* Map FN over the row ROW of two-byte charset CHARSET.
1231 There must be a separate value for that row in the char table.
1232 CTE specifies the char table entry for CHARSET. */
1235 map_over_charset_row (Lisp_Char_Table_Entry *cte,
1236 Lisp_Object charset, int row,
1237 int (*fn) (struct chartab_range *range,
1238 Lisp_Object val, void *arg),
1241 Lisp_Object val = cte->level2[row - 32];
1243 if (!CHAR_TABLE_ENTRYP (val))
1245 struct chartab_range rainj;
1247 rainj.type = CHARTAB_RANGE_ROW;
1248 rainj.charset = charset;
1250 return (fn) (&rainj, val, arg);
1254 struct chartab_range rainj;
1256 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1257 int start = charset94_p ? 33 : 32;
1258 int stop = charset94_p ? 127 : 128;
1260 cte = XCHAR_TABLE_ENTRY (val);
1262 rainj.type = CHARTAB_RANGE_CHAR;
1264 for (i = start, retval = 0; i < stop && retval == 0; i++)
1266 rainj.ch = MAKE_CHAR (charset, row, i);
1267 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1275 map_over_other_charset (Lisp_Char_Table *ct, Charset_ID lb,
1276 int (*fn) (struct chartab_range *range,
1277 Lisp_Object val, void *arg),
1280 Lisp_Object val = ct->level1[lb - MIN_LEADING_BYTE];
1281 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (lb);
1283 if (!CHARSETP (charset)
1284 || lb == LEADING_BYTE_ASCII
1285 || lb == LEADING_BYTE_CONTROL_1)
1288 if (!CHAR_TABLE_ENTRYP (val))
1290 struct chartab_range rainj;
1292 rainj.type = CHARTAB_RANGE_CHARSET;
1293 rainj.charset = charset;
1294 return (fn) (&rainj, val, arg);
1298 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
1299 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1300 int start = charset94_p ? 33 : 32;
1301 int stop = charset94_p ? 127 : 128;
1304 if (XCHARSET_DIMENSION (charset) == 1)
1306 struct chartab_range rainj;
1307 rainj.type = CHARTAB_RANGE_CHAR;
1309 for (i = start, retval = 0; i < stop && retval == 0; i++)
1311 rainj.ch = MAKE_CHAR (charset, i, 0);
1312 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1317 for (i = start, retval = 0; i < stop && retval == 0; i++)
1318 retval = map_over_charset_row (cte, charset, i, fn, arg);
1327 /* Map FN (with client data ARG) over range RANGE in char table CT.
1328 Mapping stops the first time FN returns non-zero, and that value
1329 becomes the return value of map_char_table(). */
1332 map_char_table (Lisp_Char_Table *ct,
1333 struct chartab_range *range,
1334 int (*fn) (struct chartab_range *range,
1335 Lisp_Object val, void *arg),
1338 switch (range->type)
1340 case CHARTAB_RANGE_ALL:
1344 retval = map_over_charset_ascii (ct, fn, arg);
1348 retval = map_over_charset_control_1 (ct, fn, arg);
1353 Charset_ID start = MIN_LEADING_BYTE;
1354 Charset_ID stop = start + NUM_LEADING_BYTES;
1356 for (i = start, retval = 0; i < stop && retval == 0; i++)
1358 retval = map_over_other_charset (ct, i, fn, arg);
1366 case CHARTAB_RANGE_CHARSET:
1367 return map_over_other_charset (ct,
1368 XCHARSET_LEADING_BYTE (range->charset),
1371 case CHARTAB_RANGE_ROW:
1373 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset)
1374 - MIN_LEADING_BYTE];
1375 if (!CHAR_TABLE_ENTRYP (val))
1377 struct chartab_range rainj;
1379 rainj.type = CHARTAB_RANGE_ROW;
1380 rainj.charset = range->charset;
1381 rainj.row = range->row;
1382 return (fn) (&rainj, val, arg);
1385 return map_over_charset_row (XCHAR_TABLE_ENTRY (val),
1386 range->charset, range->row,
1391 case CHARTAB_RANGE_CHAR:
1393 Emchar ch = range->ch;
1394 Lisp_Object val = CHAR_TABLE_VALUE_UNSAFE (ct, ch);
1395 struct chartab_range rainj;
1397 rainj.type = CHARTAB_RANGE_CHAR;
1399 return (fn) (&rainj, val, arg);
1409 struct slow_map_char_table_arg
1411 Lisp_Object function;
1416 slow_map_char_table_fun (struct chartab_range *range,
1417 Lisp_Object val, void *arg)
1419 Lisp_Object ranjarg = Qnil;
1420 struct slow_map_char_table_arg *closure =
1421 (struct slow_map_char_table_arg *) arg;
1423 switch (range->type)
1425 case CHARTAB_RANGE_ALL:
1430 case CHARTAB_RANGE_CHARSET:
1431 ranjarg = XCHARSET_NAME (range->charset);
1434 case CHARTAB_RANGE_ROW:
1435 ranjarg = vector2 (XCHARSET_NAME (range->charset),
1436 make_int (range->row));
1439 case CHARTAB_RANGE_CHAR:
1440 ranjarg = make_char (range->ch);
1446 closure->retval = call2 (closure->function, ranjarg, val);
1447 return !NILP (closure->retval);
1450 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
1451 Map FUNCTION over entries in CHAR-TABLE, calling it with two args,
1452 each key and value in the table.
1454 RANGE specifies a subrange to map over and is in the same format as
1455 the RANGE argument to `put-range-table'. If omitted or t, it defaults to
1458 (function, char_table, range))
1460 Lisp_Char_Table *ct;
1461 struct slow_map_char_table_arg slarg;
1462 struct gcpro gcpro1, gcpro2;
1463 struct chartab_range rainj;
1465 CHECK_CHAR_TABLE (char_table);
1466 ct = XCHAR_TABLE (char_table);
1469 decode_char_table_range (range, &rainj);
1470 slarg.function = function;
1471 slarg.retval = Qnil;
1472 GCPRO2 (slarg.function, slarg.retval);
1473 map_char_table (ct, &rainj, slow_map_char_table_fun, &slarg);
1476 return slarg.retval;
1481 /************************************************************************/
1482 /* Char table read syntax */
1483 /************************************************************************/
1486 chartab_type_validate (Lisp_Object keyword, Lisp_Object value,
1487 Error_behavior errb)
1489 /* #### should deal with ERRB */
1490 symbol_to_char_table_type (value);
1495 chartab_data_validate (Lisp_Object keyword, Lisp_Object value,
1496 Error_behavior errb)
1500 /* #### should deal with ERRB */
1501 EXTERNAL_LIST_LOOP (rest, value)
1503 Lisp_Object range = XCAR (rest);
1504 struct chartab_range dummy;
1508 signal_simple_error ("Invalid list format", value);
1511 if (!CONSP (XCDR (range))
1512 || !NILP (XCDR (XCDR (range))))
1513 signal_simple_error ("Invalid range format", range);
1514 decode_char_table_range (XCAR (range), &dummy);
1515 decode_char_table_range (XCAR (XCDR (range)), &dummy);
1518 decode_char_table_range (range, &dummy);
1525 chartab_instantiate (Lisp_Object data)
1527 Lisp_Object chartab;
1528 Lisp_Object type = Qgeneric;
1529 Lisp_Object dataval = Qnil;
1531 while (!NILP (data))
1533 Lisp_Object keyw = Fcar (data);
1539 if (EQ (keyw, Qtype))
1541 else if (EQ (keyw, Qdata))
1545 chartab = Fmake_char_table (type);
1548 while (!NILP (data))
1550 Lisp_Object range = Fcar (data);
1551 Lisp_Object val = Fcar (Fcdr (data));
1553 data = Fcdr (Fcdr (data));
1556 if (CHAR_OR_CHAR_INTP (XCAR (range)))
1558 Emchar first = XCHAR_OR_CHAR_INT (Fcar (range));
1559 Emchar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
1562 for (i = first; i <= last; i++)
1563 Fput_char_table (make_char (i), val, chartab);
1569 Fput_char_table (range, val, chartab);
1578 /************************************************************************/
1579 /* Category Tables, specifically */
1580 /************************************************************************/
1582 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
1583 Return t if OBJECT is a category table.
1584 A category table is a type of char table used for keeping track of
1585 categories. Categories are used for classifying characters for use
1586 in regexps -- you can refer to a category rather than having to use
1587 a complicated [] expression (and category lookups are significantly
1590 There are 95 different categories available, one for each printable
1591 character (including space) in the ASCII charset. Each category
1592 is designated by one such character, called a "category designator".
1593 They are specified in a regexp using the syntax "\\cX", where X is
1594 a category designator.
1596 A category table specifies, for each character, the categories that
1597 the character is in. Note that a character can be in more than one
1598 category. More specifically, a category table maps from a character
1599 to either the value nil (meaning the character is in no categories)
1600 or a 95-element bit vector, specifying for each of the 95 categories
1601 whether the character is in that category.
1603 Special Lisp functions are provided that abstract this, so you do not
1604 have to directly manipulate bit vectors.
1608 return (CHAR_TABLEP (object) &&
1609 XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_CATEGORY) ?
1614 check_category_table (Lisp_Object object, Lisp_Object default_)
1618 while (NILP (Fcategory_table_p (object)))
1619 object = wrong_type_argument (Qcategory_table_p, object);
1624 check_category_char (Emchar ch, Lisp_Object table,
1625 unsigned int designator, unsigned int not)
1627 REGISTER Lisp_Object temp;
1628 Lisp_Char_Table *ctbl;
1629 #ifdef ERROR_CHECK_TYPECHECK
1630 if (NILP (Fcategory_table_p (table)))
1631 signal_simple_error ("Expected category table", table);
1633 ctbl = XCHAR_TABLE (table);
1634 temp = get_char_table (ch, ctbl);
1639 return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not : not;
1642 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
1643 Return t if category of the character at POSITION includes DESIGNATOR.
1644 Optional third arg BUFFER specifies which buffer to use, and defaults
1645 to the current buffer.
1646 Optional fourth arg CATEGORY-TABLE specifies the category table to
1647 use, and defaults to BUFFER's category table.
1649 (position, designator, buffer, category_table))
1654 struct buffer *buf = decode_buffer (buffer, 0);
1656 CHECK_INT (position);
1657 CHECK_CATEGORY_DESIGNATOR (designator);
1658 des = XCHAR (designator);
1659 ctbl = check_category_table (category_table, Vstandard_category_table);
1660 ch = BUF_FETCH_CHAR (buf, XINT (position));
1661 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1664 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
1665 Return t if category of CHARACTER includes DESIGNATOR, else nil.
1666 Optional third arg CATEGORY-TABLE specifies the category table to use,
1667 and defaults to the standard category table.
1669 (character, designator, category_table))
1675 CHECK_CATEGORY_DESIGNATOR (designator);
1676 des = XCHAR (designator);
1677 CHECK_CHAR (character);
1678 ch = XCHAR (character);
1679 ctbl = check_category_table (category_table, Vstandard_category_table);
1680 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1683 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
1684 Return BUFFER's current category table.
1685 BUFFER defaults to the current buffer.
1689 return decode_buffer (buffer, 0)->category_table;
1692 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
1693 Return the standard category table.
1694 This is the one used for new buffers.
1698 return Vstandard_category_table;
1701 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
1702 Return a new category table which is a copy of CATEGORY-TABLE.
1703 CATEGORY-TABLE defaults to the standard category table.
1707 if (NILP (Vstandard_category_table))
1708 return Fmake_char_table (Qcategory);
1711 check_category_table (category_table, Vstandard_category_table);
1712 return Fcopy_char_table (category_table);
1715 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
1716 Select CATEGORY-TABLE as the new category table for BUFFER.
1717 BUFFER defaults to the current buffer if omitted.
1719 (category_table, buffer))
1721 struct buffer *buf = decode_buffer (buffer, 0);
1722 category_table = check_category_table (category_table, Qnil);
1723 buf->category_table = category_table;
1724 /* Indicate that this buffer now has a specified category table. */
1725 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
1726 return category_table;
1729 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
1730 Return t if OBJECT is a category designator (a char in the range ' ' to '~').
1734 return CATEGORY_DESIGNATORP (object) ? Qt : Qnil;
1737 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
1738 Return t if OBJECT is a category table value.
1739 Valid values are nil or a bit vector of size 95.
1743 return CATEGORY_TABLE_VALUEP (object) ? Qt : Qnil;
1747 #define CATEGORYP(x) \
1748 (CHARP (x) && XCHAR (x) >= 0x20 && XCHAR (x) <= 0x7E)
1750 #define CATEGORY_SET(c) \
1751 (get_char_table(c, XCHAR_TABLE(current_buffer->category_table)))
1753 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0.
1754 The faster version of `!NILP (Faref (category_set, category))'. */
1755 #define CATEGORY_MEMBER(category, category_set) \
1756 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32))
1758 /* Return 1 if there is a word boundary between two word-constituent
1759 characters C1 and C2 if they appear in this order, else return 0.
1760 Use the macro WORD_BOUNDARY_P instead of calling this function
1763 int word_boundary_p (Emchar c1, Emchar c2);
1765 word_boundary_p (Emchar c1, Emchar c2)
1767 Lisp_Object category_set1, category_set2;
1772 if (COMPOSITE_CHAR_P (c1))
1773 c1 = cmpchar_component (c1, 0, 1);
1774 if (COMPOSITE_CHAR_P (c2))
1775 c2 = cmpchar_component (c2, 0, 1);
1778 if (EQ (CHAR_CHARSET (c1), CHAR_CHARSET (c2)))
1780 tail = Vword_separating_categories;
1785 tail = Vword_combining_categories;
1789 category_set1 = CATEGORY_SET (c1);
1790 if (NILP (category_set1))
1791 return default_result;
1792 category_set2 = CATEGORY_SET (c2);
1793 if (NILP (category_set2))
1794 return default_result;
1796 for (; CONSP (tail); tail = XCONS (tail)->cdr)
1798 Lisp_Object elt = XCONS(tail)->car;
1801 && CATEGORYP (XCONS (elt)->car)
1802 && CATEGORYP (XCONS (elt)->cdr)
1803 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->car), category_set1)
1804 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->cdr), category_set2))
1805 return !default_result;
1807 return default_result;
1813 syms_of_chartab (void)
1815 INIT_LRECORD_IMPLEMENTATION (char_table);
1818 INIT_LRECORD_IMPLEMENTATION (char_table_entry);
1820 defsymbol (&Qcategory_table_p, "category-table-p");
1821 defsymbol (&Qcategory_designator_p, "category-designator-p");
1822 defsymbol (&Qcategory_table_value_p, "category-table-value-p");
1825 defsymbol (&Qchar_table, "char-table");
1826 defsymbol (&Qchar_tablep, "char-table-p");
1828 DEFSUBR (Fchar_table_p);
1829 DEFSUBR (Fchar_table_type_list);
1830 DEFSUBR (Fvalid_char_table_type_p);
1831 DEFSUBR (Fchar_table_type);
1832 DEFSUBR (Freset_char_table);
1833 DEFSUBR (Fmake_char_table);
1834 DEFSUBR (Fcopy_char_table);
1835 DEFSUBR (Fget_char_table);
1836 DEFSUBR (Fget_range_char_table);
1837 DEFSUBR (Fvalid_char_table_value_p);
1838 DEFSUBR (Fcheck_valid_char_table_value);
1839 DEFSUBR (Fput_char_table);
1840 DEFSUBR (Fmap_char_table);
1843 DEFSUBR (Fcategory_table_p);
1844 DEFSUBR (Fcategory_table);
1845 DEFSUBR (Fstandard_category_table);
1846 DEFSUBR (Fcopy_category_table);
1847 DEFSUBR (Fset_category_table);
1848 DEFSUBR (Fcheck_category_at);
1849 DEFSUBR (Fchar_in_category_p);
1850 DEFSUBR (Fcategory_designator_p);
1851 DEFSUBR (Fcategory_table_value_p);
1857 vars_of_chartab (void)
1859 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
1860 Vall_syntax_tables = Qnil;
1861 pdump_wire_list (&Vall_syntax_tables);
1865 structure_type_create_chartab (void)
1867 struct structure_type *st;
1869 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
1871 define_structure_type_keyword (st, Qtype, chartab_type_validate);
1872 define_structure_type_keyword (st, Qdata, chartab_data_validate);
1876 complex_vars_of_chartab (void)
1879 /* Set this now, so first buffer creation can refer to it. */
1880 /* Make it nil before calling copy-category-table
1881 so that copy-category-table will know not to try to copy from garbage */
1882 Vstandard_category_table = Qnil;
1883 Vstandard_category_table = Fcopy_category_table (Qnil);
1884 staticpro (&Vstandard_category_table);
1886 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /*
1887 List of pair (cons) of categories to determine word boundary.
1889 Emacs treats a sequence of word constituent characters as a single
1890 word (i.e. finds no word boundary between them) iff they belongs to
1891 the same charset. But, exceptions are allowed in the following cases.
1893 \(1) The case that characters are in different charsets is controlled
1894 by the variable `word-combining-categories'.
1896 Emacs finds no word boundary between characters of different charsets
1897 if they have categories matching some element of this list.
1899 More precisely, if an element of this list is a cons of category CAT1
1900 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1901 C2 which has CAT2, there's no word boundary between C1 and C2.
1903 For instance, to tell that ASCII characters and Latin-1 characters can
1904 form a single word, the element `(?l . ?l)' should be in this list
1905 because both characters have the category `l' (Latin characters).
1907 \(2) The case that character are in the same charset is controlled by
1908 the variable `word-separating-categories'.
1910 Emacs find a word boundary between characters of the same charset
1911 if they have categories matching some element of this list.
1913 More precisely, if an element of this list is a cons of category CAT1
1914 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1915 C2 which has CAT2, there's a word boundary between C1 and C2.
1917 For instance, to tell that there's a word boundary between Japanese
1918 Hiragana and Japanese Kanji (both are in the same charset), the
1919 element `(?H . ?C) should be in this list.
1922 Vword_combining_categories = Qnil;
1924 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /*
1925 List of pair (cons) of categories to determine word boundary.
1926 See the documentation of the variable `word-combining-categories'.
1929 Vword_separating_categories = Qnil;