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 struct 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 struct Lisp_Char_Table_Entry *cte1 = XCHAR_TABLE_ENTRY (obj1);
114 struct 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 struct 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, offsetof(struct 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 struct Lisp_Char_Table_Entry);
146 mark_char_table (Lisp_Object obj)
148 struct 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 struct 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 struct 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 struct 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 struct 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 struct Lisp_Char_Table *ct1 = XCHAR_TABLE (obj1);
397 struct 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 struct 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, offsetof(struct Lisp_Char_Table, ascii), NUM_ASCII_CHARS },
432 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table, level1), NUM_LEADING_BYTES },
434 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table, mirror_table), 1 },
435 { XD_LO_LINK, offsetof(struct 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,
443 struct Lisp_Char_Table);
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'. To modify a char
472 table, use `put-char-table' or `remove-char-table'. To retrieve the
473 value for a particular character, use `get-char-table'. See also
474 `map-char-table', `clear-char-table', `copy-char-table',
475 `valid-char-table-type-p', `char-table-type-list', `valid-char-table-value-p',
476 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 TABLE.
537 See `valid-char-table-type-p'.
541 CHECK_CHAR_TABLE (table);
542 return char_table_type_to_symbol (XCHAR_TABLE (table)->type);
546 fill_char_table (struct 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 a char table to its default state.
566 struct Lisp_Char_Table *ct;
568 CHECK_CHAR_TABLE (table);
569 ct = XCHAR_TABLE (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'.
602 struct Lisp_Char_Table *ct;
604 enum char_table_type ty = symbol_to_char_table_type (type);
606 ct = alloc_lcrecord_type (struct 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 struct Lisp_Char_Table_Entry *cte =
635 alloc_lcrecord_type (struct Lisp_Char_Table_Entry,
636 &lrecord_char_table_entry);
638 for (i = 0; i < 96; i++)
639 cte->level2[i] = initval;
641 XSETCHAR_TABLE_ENTRY (obj, cte);
646 copy_char_table_entry (Lisp_Object entry)
648 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
651 struct Lisp_Char_Table_Entry *ctenew =
652 alloc_lcrecord_type (struct Lisp_Char_Table_Entry,
653 &lrecord_char_table_entry);
655 for (i = 0; i < 96; i++)
657 Lisp_Object new = cte->level2[i];
658 if (CHAR_TABLE_ENTRYP (new))
659 ctenew->level2[i] = copy_char_table_entry (new);
661 ctenew->level2[i] = new;
664 XSETCHAR_TABLE_ENTRY (obj, ctenew);
670 DEFUN ("copy-char-table", Fcopy_char_table, 1, 1, 0, /*
671 Make a new char table which is a copy of OLD-TABLE.
672 It will contain the same values for the same characters and ranges
673 as OLD-TABLE. The values will not themselves be copied.
677 struct Lisp_Char_Table *ct, *ctnew;
681 CHECK_CHAR_TABLE (old_table);
682 ct = XCHAR_TABLE (old_table);
683 ctnew = alloc_lcrecord_type (struct Lisp_Char_Table, &lrecord_char_table);
684 ctnew->type = ct->type;
686 for (i = 0; i < NUM_ASCII_CHARS; i++)
688 Lisp_Object new = ct->ascii[i];
690 assert (! (CHAR_TABLE_ENTRYP (new)));
692 ctnew->ascii[i] = new;
697 for (i = 0; i < NUM_LEADING_BYTES; i++)
699 Lisp_Object new = ct->level1[i];
700 if (CHAR_TABLE_ENTRYP (new))
701 ctnew->level1[i] = copy_char_table_entry (new);
703 ctnew->level1[i] = new;
708 if (CHAR_TABLEP (ct->mirror_table))
709 ctnew->mirror_table = Fcopy_char_table (ct->mirror_table);
711 ctnew->mirror_table = ct->mirror_table;
712 ctnew->next_table = Qnil;
713 XSETCHAR_TABLE (obj, ctnew);
714 if (ctnew->type == CHAR_TABLE_TYPE_SYNTAX)
716 ctnew->next_table = Vall_syntax_tables;
717 Vall_syntax_tables = obj;
723 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange)
726 outrange->type = CHARTAB_RANGE_ALL;
727 else if (CHAR_OR_CHAR_INTP (range))
729 outrange->type = CHARTAB_RANGE_CHAR;
730 outrange->ch = XCHAR_OR_CHAR_INT (range);
734 signal_simple_error ("Range must be t or a character", range);
736 else if (VECTORP (range))
738 struct Lisp_Vector *vec = XVECTOR (range);
739 Lisp_Object *elts = vector_data (vec);
740 if (vector_length (vec) != 2)
741 signal_simple_error ("Length of charset row vector must be 2",
743 outrange->type = CHARTAB_RANGE_ROW;
744 outrange->charset = Fget_charset (elts[0]);
746 outrange->row = XINT (elts[1]);
747 switch (XCHARSET_TYPE (outrange->charset))
749 case CHARSET_TYPE_94:
750 case CHARSET_TYPE_96:
751 signal_simple_error ("Charset in row vector must be multi-byte",
753 case CHARSET_TYPE_94X94:
754 check_int_range (outrange->row, 33, 126);
756 case CHARSET_TYPE_96X96:
757 check_int_range (outrange->row, 32, 127);
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 (struct Lisp_Char_Table *ct,
779 Charset_ID leading_byte, Emchar c)
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 struct 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, struct 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 struct 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 char CH in TABLE.
859 struct Lisp_Char_Table *ct;
861 CHECK_CHAR_TABLE (table);
862 ct = XCHAR_TABLE (table);
863 CHECK_CHAR_COERCE_INT (ch);
865 return get_char_table (XCHAR (ch), ct);
868 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
869 Find value for a range in TABLE.
870 If there is more than one value, return MULTI (defaults to nil).
872 (range, table, multi))
874 struct Lisp_Char_Table *ct;
875 struct chartab_range rainj;
877 if (CHAR_OR_CHAR_INTP (range))
878 return Fget_char_table (range, table);
879 CHECK_CHAR_TABLE (table);
880 ct = XCHAR_TABLE (table);
882 decode_char_table_range (range, &rainj);
885 case CHARTAB_RANGE_ALL:
888 Lisp_Object first = ct->ascii[0];
890 for (i = 1; i < NUM_ASCII_CHARS; i++)
891 if (!EQ (first, ct->ascii[i]))
895 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
898 if (!CHARSETP (CHARSET_BY_LEADING_BYTE (i))
899 || i == LEADING_BYTE_ASCII
900 || i == LEADING_BYTE_CONTROL_1)
902 if (!EQ (first, ct->level1[i - MIN_LEADING_BYTE]))
911 case CHARTAB_RANGE_CHARSET:
912 if (EQ (rainj.charset, Vcharset_ascii))
915 Lisp_Object first = ct->ascii[0];
917 for (i = 1; i < 128; i++)
918 if (!EQ (first, ct->ascii[i]))
923 if (EQ (rainj.charset, Vcharset_control_1))
926 Lisp_Object first = ct->ascii[128];
928 for (i = 129; i < 160; i++)
929 if (!EQ (first, ct->ascii[i]))
935 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
937 if (CHAR_TABLE_ENTRYP (val))
942 case CHARTAB_RANGE_ROW:
944 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
946 if (!CHAR_TABLE_ENTRYP (val))
948 val = XCHAR_TABLE_ENTRY (val)->level2[rainj.row - 32];
949 if (CHAR_TABLE_ENTRYP (val))
953 #endif /* not MULE */
959 return Qnil; /* not reached */
963 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
968 case CHAR_TABLE_TYPE_SYNTAX:
969 if (!ERRB_EQ (errb, ERROR_ME))
970 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
971 && CHAR_OR_CHAR_INTP (XCDR (value)));
974 Lisp_Object cdr = XCDR (value);
975 CHECK_INT (XCAR (value));
976 CHECK_CHAR_COERCE_INT (cdr);
983 case CHAR_TABLE_TYPE_CATEGORY:
984 if (!ERRB_EQ (errb, ERROR_ME))
985 return CATEGORY_TABLE_VALUEP (value);
986 CHECK_CATEGORY_TABLE_VALUE (value);
990 case CHAR_TABLE_TYPE_GENERIC:
993 case CHAR_TABLE_TYPE_DISPLAY:
995 maybe_signal_simple_error ("Display char tables not yet implemented",
996 value, Qchar_table, errb);
999 case CHAR_TABLE_TYPE_CHAR:
1000 if (!ERRB_EQ (errb, ERROR_ME))
1001 return CHAR_OR_CHAR_INTP (value);
1002 CHECK_CHAR_COERCE_INT (value);
1009 return 0; /* not reached */
1013 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
1017 case CHAR_TABLE_TYPE_SYNTAX:
1020 Lisp_Object car = XCAR (value);
1021 Lisp_Object cdr = XCDR (value);
1022 CHECK_CHAR_COERCE_INT (cdr);
1023 return Fcons (car, cdr);
1026 case CHAR_TABLE_TYPE_CHAR:
1027 CHECK_CHAR_COERCE_INT (value);
1035 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
1036 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
1038 (value, char_table_type))
1040 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1042 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
1045 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
1046 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
1048 (value, char_table_type))
1050 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1052 check_valid_char_table_value (value, type, ERROR_ME);
1056 /* Assign VAL to all characters in RANGE in char table CT. */
1059 put_char_table (struct Lisp_Char_Table *ct, struct chartab_range *range,
1062 switch (range->type)
1064 case CHARTAB_RANGE_ALL:
1065 fill_char_table (ct, val);
1066 return; /* avoid the duplicate call to update_syntax_table() below,
1067 since fill_char_table() also did that. */
1070 case CHARTAB_RANGE_CHARSET:
1071 if (EQ (range->charset, Vcharset_ascii))
1074 for (i = 0; i < 128; i++)
1077 else if (EQ (range->charset, Vcharset_control_1))
1080 for (i = 128; i < 160; i++)
1085 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1086 ct->level1[lb] = val;
1090 case CHARTAB_RANGE_ROW:
1092 struct Lisp_Char_Table_Entry *cte;
1093 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1094 /* make sure that there is a separate entry for the row. */
1095 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1096 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1097 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1098 cte->level2[range->row - 32] = val;
1103 case CHARTAB_RANGE_CHAR:
1106 Lisp_Object charset;
1109 BREAKUP_CHAR (range->ch, charset, byte1, byte2);
1110 if (EQ (charset, Vcharset_ascii))
1111 ct->ascii[byte1] = val;
1112 else if (EQ (charset, Vcharset_control_1))
1113 ct->ascii[byte1 + 128] = val;
1116 struct Lisp_Char_Table_Entry *cte;
1117 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
1118 /* make sure that there is a separate entry for the row. */
1119 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1120 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1121 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1122 /* now CTE is a char table entry for the charset;
1123 each entry is for a single row (or character of
1124 a one-octet charset). */
1125 if (XCHARSET_DIMENSION (charset) == 1)
1126 cte->level2[byte1 - 32] = val;
1129 /* assigning to one character in a two-octet charset. */
1130 /* make sure that the charset row contains a separate
1131 entry for each character. */
1132 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
1133 cte->level2[byte1 - 32] =
1134 make_char_table_entry (cte->level2[byte1 - 32]);
1135 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
1136 cte->level2[byte2 - 32] = val;
1140 #else /* not MULE */
1141 ct->ascii[(unsigned char) (range->ch)] = val;
1143 #endif /* not MULE */
1146 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
1147 update_syntax_table (ct);
1150 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
1151 Set the value for chars in RANGE to be VAL in TABLE.
1153 RANGE specifies one or more characters to be affected and should be
1154 one of the following:
1156 -- t (all characters are affected)
1157 -- A charset (only allowed when Mule support is present)
1158 -- A vector of two elements: a two-octet charset and a row number
1159 (only allowed when Mule support is present)
1160 -- A single character
1162 VAL must be a value appropriate for the type of TABLE.
1163 See `valid-char-table-type-p'.
1165 (range, val, table))
1167 struct Lisp_Char_Table *ct;
1168 struct chartab_range rainj;
1170 CHECK_CHAR_TABLE (table);
1171 ct = XCHAR_TABLE (table);
1172 check_valid_char_table_value (val, ct->type, ERROR_ME);
1173 decode_char_table_range (range, &rainj);
1174 val = canonicalize_char_table_value (val, ct->type);
1175 put_char_table (ct, &rainj, val);
1179 /* Map FN over the ASCII chars in CT. */
1182 map_over_charset_ascii (struct Lisp_Char_Table *ct,
1183 int (*fn) (struct chartab_range *range,
1184 Lisp_Object val, void *arg),
1187 struct chartab_range rainj;
1196 rainj.type = CHARTAB_RANGE_CHAR;
1198 for (i = start, retval = 0; i < stop && retval == 0; i++)
1200 rainj.ch = (Emchar) i;
1201 retval = (fn) (&rainj, ct->ascii[i], arg);
1209 /* Map FN over the Control-1 chars in CT. */
1212 map_over_charset_control_1 (struct Lisp_Char_Table *ct,
1213 int (*fn) (struct chartab_range *range,
1214 Lisp_Object val, void *arg),
1217 struct chartab_range rainj;
1220 int stop = start + 32;
1222 rainj.type = CHARTAB_RANGE_CHAR;
1224 for (i = start, retval = 0; i < stop && retval == 0; i++)
1226 rainj.ch = (Emchar) (i);
1227 retval = (fn) (&rainj, ct->ascii[i], arg);
1233 /* Map FN over the row ROW of two-byte charset CHARSET.
1234 There must be a separate value for that row in the char table.
1235 CTE specifies the char table entry for CHARSET. */
1238 map_over_charset_row (struct Lisp_Char_Table_Entry *cte,
1239 Lisp_Object charset, int row,
1240 int (*fn) (struct chartab_range *range,
1241 Lisp_Object val, void *arg),
1244 Lisp_Object val = cte->level2[row - 32];
1246 if (!CHAR_TABLE_ENTRYP (val))
1248 struct chartab_range rainj;
1250 rainj.type = CHARTAB_RANGE_ROW;
1251 rainj.charset = charset;
1253 return (fn) (&rainj, val, arg);
1257 struct chartab_range rainj;
1259 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1260 int start = charset94_p ? 33 : 32;
1261 int stop = charset94_p ? 127 : 128;
1263 cte = XCHAR_TABLE_ENTRY (val);
1265 rainj.type = CHARTAB_RANGE_CHAR;
1267 for (i = start, retval = 0; i < stop && retval == 0; i++)
1269 rainj.ch = MAKE_CHAR (charset, row, i);
1270 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1278 map_over_other_charset (struct Lisp_Char_Table *ct, Charset_ID lb,
1279 int (*fn) (struct chartab_range *range,
1280 Lisp_Object val, void *arg),
1283 Lisp_Object val = ct->level1[lb - MIN_LEADING_BYTE];
1284 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (lb);
1286 if (!CHARSETP (charset)
1287 || lb == LEADING_BYTE_ASCII
1288 || lb == LEADING_BYTE_CONTROL_1)
1291 if (!CHAR_TABLE_ENTRYP (val))
1293 struct chartab_range rainj;
1295 rainj.type = CHARTAB_RANGE_CHARSET;
1296 rainj.charset = charset;
1297 return (fn) (&rainj, val, arg);
1301 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
1302 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1303 int start = charset94_p ? 33 : 32;
1304 int stop = charset94_p ? 127 : 128;
1307 if (XCHARSET_DIMENSION (charset) == 1)
1309 struct chartab_range rainj;
1310 rainj.type = CHARTAB_RANGE_CHAR;
1312 for (i = start, retval = 0; i < stop && retval == 0; i++)
1314 rainj.ch = MAKE_CHAR (charset, i, 0);
1315 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1320 for (i = start, retval = 0; i < stop && retval == 0; i++)
1321 retval = map_over_charset_row (cte, charset, i, fn, arg);
1330 /* Map FN (with client data ARG) over range RANGE in char table CT.
1331 Mapping stops the first time FN returns non-zero, and that value
1332 becomes the return value of map_char_table(). */
1335 map_char_table (struct Lisp_Char_Table *ct,
1336 struct chartab_range *range,
1337 int (*fn) (struct chartab_range *range,
1338 Lisp_Object val, void *arg),
1341 switch (range->type)
1343 case CHARTAB_RANGE_ALL:
1347 retval = map_over_charset_ascii (ct, fn, arg);
1351 retval = map_over_charset_control_1 (ct, fn, arg);
1356 Charset_ID start = MIN_LEADING_BYTE;
1357 Charset_ID stop = start + NUM_LEADING_BYTES;
1359 for (i = start, retval = 0; i < stop && retval == 0; i++)
1361 retval = map_over_other_charset (ct, i, fn, arg);
1369 case CHARTAB_RANGE_CHARSET:
1370 return map_over_other_charset (ct,
1371 XCHARSET_LEADING_BYTE (range->charset),
1374 case CHARTAB_RANGE_ROW:
1376 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset)
1377 - MIN_LEADING_BYTE];
1378 if (!CHAR_TABLE_ENTRYP (val))
1380 struct chartab_range rainj;
1382 rainj.type = CHARTAB_RANGE_ROW;
1383 rainj.charset = range->charset;
1384 rainj.row = range->row;
1385 return (fn) (&rainj, val, arg);
1388 return map_over_charset_row (XCHAR_TABLE_ENTRY (val),
1389 range->charset, range->row,
1394 case CHARTAB_RANGE_CHAR:
1396 Emchar ch = range->ch;
1397 Lisp_Object val = CHAR_TABLE_VALUE_UNSAFE (ct, ch);
1398 struct chartab_range rainj;
1400 rainj.type = CHARTAB_RANGE_CHAR;
1402 return (fn) (&rainj, val, arg);
1412 struct slow_map_char_table_arg
1414 Lisp_Object function;
1419 slow_map_char_table_fun (struct chartab_range *range,
1420 Lisp_Object val, void *arg)
1422 Lisp_Object ranjarg = Qnil;
1423 struct slow_map_char_table_arg *closure =
1424 (struct slow_map_char_table_arg *) arg;
1426 switch (range->type)
1428 case CHARTAB_RANGE_ALL:
1433 case CHARTAB_RANGE_CHARSET:
1434 ranjarg = XCHARSET_NAME (range->charset);
1437 case CHARTAB_RANGE_ROW:
1438 ranjarg = vector2 (XCHARSET_NAME (range->charset),
1439 make_int (range->row));
1442 case CHARTAB_RANGE_CHAR:
1443 ranjarg = make_char (range->ch);
1449 closure->retval = call2 (closure->function, ranjarg, val);
1450 return !NILP (closure->retval);
1453 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
1454 Map FUNCTION over entries in TABLE, calling it with two args,
1455 each key and value in the table.
1457 RANGE specifies a subrange to map over and is in the same format as
1458 the RANGE argument to `put-range-table'. If omitted or t, it defaults to
1461 (function, table, range))
1463 struct Lisp_Char_Table *ct;
1464 struct slow_map_char_table_arg slarg;
1465 struct gcpro gcpro1, gcpro2;
1466 struct chartab_range rainj;
1468 CHECK_CHAR_TABLE (table);
1469 ct = XCHAR_TABLE (table);
1472 decode_char_table_range (range, &rainj);
1473 slarg.function = function;
1474 slarg.retval = Qnil;
1475 GCPRO2 (slarg.function, slarg.retval);
1476 map_char_table (ct, &rainj, slow_map_char_table_fun, &slarg);
1479 return slarg.retval;
1484 /************************************************************************/
1485 /* Char table read syntax */
1486 /************************************************************************/
1489 chartab_type_validate (Lisp_Object keyword, Lisp_Object value,
1490 Error_behavior errb)
1492 /* #### should deal with ERRB */
1493 symbol_to_char_table_type (value);
1498 chartab_data_validate (Lisp_Object keyword, Lisp_Object value,
1499 Error_behavior errb)
1503 /* #### should deal with ERRB */
1504 EXTERNAL_LIST_LOOP (rest, value)
1506 Lisp_Object range = XCAR (rest);
1507 struct chartab_range dummy;
1511 signal_simple_error ("Invalid list format", value);
1514 if (!CONSP (XCDR (range))
1515 || !NILP (XCDR (XCDR (range))))
1516 signal_simple_error ("Invalid range format", range);
1517 decode_char_table_range (XCAR (range), &dummy);
1518 decode_char_table_range (XCAR (XCDR (range)), &dummy);
1521 decode_char_table_range (range, &dummy);
1528 chartab_instantiate (Lisp_Object data)
1530 Lisp_Object chartab;
1531 Lisp_Object type = Qgeneric;
1532 Lisp_Object dataval = Qnil;
1534 while (!NILP (data))
1536 Lisp_Object keyw = Fcar (data);
1542 if (EQ (keyw, Qtype))
1544 else if (EQ (keyw, Qdata))
1548 chartab = Fmake_char_table (type);
1551 while (!NILP (data))
1553 Lisp_Object range = Fcar (data);
1554 Lisp_Object val = Fcar (Fcdr (data));
1556 data = Fcdr (Fcdr (data));
1559 if (CHAR_OR_CHAR_INTP (XCAR (range)))
1561 Emchar first = XCHAR_OR_CHAR_INT (Fcar (range));
1562 Emchar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
1565 for (i = first; i <= last; i++)
1566 Fput_char_table (make_char (i), val, chartab);
1572 Fput_char_table (range, val, chartab);
1581 /************************************************************************/
1582 /* Category Tables, specifically */
1583 /************************************************************************/
1585 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
1586 Return t if ARG is a category table.
1587 A category table is a type of char table used for keeping track of
1588 categories. Categories are used for classifying characters for use
1589 in regexps -- you can refer to a category rather than having to use
1590 a complicated [] expression (and category lookups are significantly
1593 There are 95 different categories available, one for each printable
1594 character (including space) in the ASCII charset. Each category
1595 is designated by one such character, called a "category designator".
1596 They are specified in a regexp using the syntax "\\cX", where X is
1597 a category designator.
1599 A category table specifies, for each character, the categories that
1600 the character is in. Note that a character can be in more than one
1601 category. More specifically, a category table maps from a character
1602 to either the value nil (meaning the character is in no categories)
1603 or a 95-element bit vector, specifying for each of the 95 categories
1604 whether the character is in that category.
1606 Special Lisp functions are provided that abstract this, so you do not
1607 have to directly manipulate bit vectors.
1611 return (CHAR_TABLEP (obj) &&
1612 XCHAR_TABLE_TYPE (obj) == CHAR_TABLE_TYPE_CATEGORY) ?
1617 check_category_table (Lisp_Object obj, Lisp_Object def)
1621 while (NILP (Fcategory_table_p (obj)))
1622 obj = wrong_type_argument (Qcategory_table_p, obj);
1627 check_category_char (Emchar ch, Lisp_Object table,
1628 unsigned int designator, unsigned int not)
1630 REGISTER Lisp_Object temp;
1631 struct Lisp_Char_Table *ctbl;
1632 #ifdef ERROR_CHECK_TYPECHECK
1633 if (NILP (Fcategory_table_p (table)))
1634 signal_simple_error ("Expected category table", table);
1636 ctbl = XCHAR_TABLE (table);
1637 temp = get_char_table (ch, ctbl);
1642 return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not : not;
1645 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
1646 Return t if category of a character at POS includes DESIGNATOR,
1647 else return nil. Optional third arg specifies which buffer
1648 \(defaulting to current), and fourth specifies the CATEGORY-TABLE,
1649 \(defaulting to the buffer's category table).
1651 (pos, designator, buffer, category_table))
1656 struct buffer *buf = decode_buffer (buffer, 0);
1659 CHECK_CATEGORY_DESIGNATOR (designator);
1660 des = XCHAR (designator);
1661 ctbl = check_category_table (category_table, Vstandard_category_table);
1662 ch = BUF_FETCH_CHAR (buf, XINT (pos));
1663 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1666 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
1667 Return t if category of character CHR includes DESIGNATOR, else nil.
1668 Optional third arg specifies the CATEGORY-TABLE to use,
1669 which defaults to the system default table.
1671 (chr, designator, category_table))
1677 CHECK_CATEGORY_DESIGNATOR (designator);
1678 des = XCHAR (designator);
1681 ctbl = check_category_table (category_table, Vstandard_category_table);
1682 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1685 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
1686 Return the current category table.
1687 This is the one specified by the current buffer, or by BUFFER if it
1692 return decode_buffer (buffer, 0)->category_table;
1695 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
1696 Return the standard category table.
1697 This is the one used for new buffers.
1701 return Vstandard_category_table;
1704 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
1705 Construct a new category table and return it.
1706 It is a copy of the TABLE, which defaults to the standard category table.
1710 if (NILP (Vstandard_category_table))
1711 return Fmake_char_table (Qcategory);
1713 table = check_category_table (table, Vstandard_category_table);
1714 return Fcopy_char_table (table);
1717 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
1718 Select a new category table for BUFFER.
1719 One argument, a category table.
1720 BUFFER defaults to the current buffer if omitted.
1724 struct buffer *buf = decode_buffer (buffer, 0);
1725 table = check_category_table (table, Qnil);
1726 buf->category_table = table;
1727 /* Indicate that this buffer now has a specified category table. */
1728 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
1732 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
1733 Return t if ARG is a category designator (a char in the range ' ' to '~').
1737 return CATEGORY_DESIGNATORP (obj) ? Qt : Qnil;
1740 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
1741 Return t if ARG is a category table value.
1742 Valid values are nil or a bit vector of size 95.
1746 return CATEGORY_TABLE_VALUEP (obj) ? Qt : Qnil;
1750 #define CATEGORYP(x) \
1751 (CHARP (x) && XCHAR (x) >= 0x20 && XCHAR (x) <= 0x7E)
1753 #define CATEGORY_SET(c) \
1754 (get_char_table(c, XCHAR_TABLE(current_buffer->category_table)))
1756 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0.
1757 The faster version of `!NILP (Faref (category_set, category))'. */
1758 #define CATEGORY_MEMBER(category, category_set) \
1759 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32))
1761 /* Return 1 if there is a word boundary between two word-constituent
1762 characters C1 and C2 if they appear in this order, else return 0.
1763 Use the macro WORD_BOUNDARY_P instead of calling this function
1766 int word_boundary_p (Emchar c1, Emchar c2);
1768 word_boundary_p (Emchar c1, Emchar c2)
1770 Lisp_Object category_set1, category_set2;
1775 if (COMPOSITE_CHAR_P (c1))
1776 c1 = cmpchar_component (c1, 0, 1);
1777 if (COMPOSITE_CHAR_P (c2))
1778 c2 = cmpchar_component (c2, 0, 1);
1781 if (EQ (CHAR_CHARSET (c1), CHAR_CHARSET (c2)))
1783 tail = Vword_separating_categories;
1788 tail = Vword_combining_categories;
1792 category_set1 = CATEGORY_SET (c1);
1793 if (NILP (category_set1))
1794 return default_result;
1795 category_set2 = CATEGORY_SET (c2);
1796 if (NILP (category_set2))
1797 return default_result;
1799 for (; CONSP (tail); tail = XCONS (tail)->cdr)
1801 Lisp_Object elt = XCONS(tail)->car;
1804 && CATEGORYP (XCONS (elt)->car)
1805 && CATEGORYP (XCONS (elt)->cdr)
1806 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->car), category_set1)
1807 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->cdr), category_set2))
1808 return !default_result;
1810 return default_result;
1816 syms_of_chartab (void)
1819 defsymbol (&Qcategory_table_p, "category-table-p");
1820 defsymbol (&Qcategory_designator_p, "category-designator-p");
1821 defsymbol (&Qcategory_table_value_p, "category-table-value-p");
1824 defsymbol (&Qchar_table, "char-table");
1825 defsymbol (&Qchar_tablep, "char-table-p");
1827 DEFSUBR (Fchar_table_p);
1828 DEFSUBR (Fchar_table_type_list);
1829 DEFSUBR (Fvalid_char_table_type_p);
1830 DEFSUBR (Fchar_table_type);
1831 DEFSUBR (Freset_char_table);
1832 DEFSUBR (Fmake_char_table);
1833 DEFSUBR (Fcopy_char_table);
1834 DEFSUBR (Fget_char_table);
1835 DEFSUBR (Fget_range_char_table);
1836 DEFSUBR (Fvalid_char_table_value_p);
1837 DEFSUBR (Fcheck_valid_char_table_value);
1838 DEFSUBR (Fput_char_table);
1839 DEFSUBR (Fmap_char_table);
1842 DEFSUBR (Fcategory_table_p);
1843 DEFSUBR (Fcategory_table);
1844 DEFSUBR (Fstandard_category_table);
1845 DEFSUBR (Fcopy_category_table);
1846 DEFSUBR (Fset_category_table);
1847 DEFSUBR (Fcheck_category_at);
1848 DEFSUBR (Fchar_in_category_p);
1849 DEFSUBR (Fcategory_designator_p);
1850 DEFSUBR (Fcategory_table_value_p);
1856 vars_of_chartab (void)
1858 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
1859 Vall_syntax_tables = Qnil;
1860 pdump_wire_list (&Vall_syntax_tables);
1864 structure_type_create_chartab (void)
1866 struct structure_type *st;
1868 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
1870 define_structure_type_keyword (st, Qtype, chartab_type_validate);
1871 define_structure_type_keyword (st, Qdata, chartab_data_validate);
1875 complex_vars_of_chartab (void)
1878 /* Set this now, so first buffer creation can refer to it. */
1879 /* Make it nil before calling copy-category-table
1880 so that copy-category-table will know not to try to copy from garbage */
1881 Vstandard_category_table = Qnil;
1882 Vstandard_category_table = Fcopy_category_table (Qnil);
1883 staticpro (&Vstandard_category_table);
1885 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /*
1886 List of pair (cons) of categories to determine word boundary.
1888 Emacs treats a sequence of word constituent characters as a single
1889 word (i.e. finds no word boundary between them) iff they belongs to
1890 the same charset. But, exceptions are allowed in the following cases.
1892 (1) The case that characters are in different charsets is controlled
1893 by the variable `word-combining-categories'.
1895 Emacs finds no word boundary between characters of different charsets
1896 if they have categories matching some element of this list.
1898 More precisely, if an element of this list is a cons of category CAT1
1899 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1900 C2 which has CAT2, there's no word boundary between C1 and C2.
1902 For instance, to tell that ASCII characters and Latin-1 characters can
1903 form a single word, the element `(?l . ?l)' should be in this list
1904 because both characters have the category `l' (Latin characters).
1906 (2) The case that character are in the same charset is controlled by
1907 the variable `word-separating-categories'.
1909 Emacs find a word boundary between characters of the same charset
1910 if they have categories matching some element of this list.
1912 More precisely, if an element of this list is a cons of category CAT1
1913 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1914 C2 which has CAT2, there's a word boundary between C1 and C2.
1916 For instance, to tell that there's a word boundary between Japanese
1917 Hiragana and Japanese Kanji (both are in the same charset), the
1918 element `(?H . ?C) should be in this list.
1921 Vword_combining_categories = Qnil;
1923 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /*
1924 List of pair (cons) of categories to determine word boundary.
1925 See the documentation of the variable `word-combining-categories'.
1928 Vword_separating_categories = Qnil;