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
46 Lisp_Object Qchar_tablep, Qchar_table;
48 Lisp_Object Vall_syntax_tables;
51 Lisp_Object Qcategory_table_p;
52 Lisp_Object Qcategory_designator_p;
53 Lisp_Object Qcategory_table_value_p;
55 Lisp_Object Vstandard_category_table;
57 /* Variables to determine word boundary. */
58 Lisp_Object Vword_combining_categories, Vword_separating_categories;
62 /* A char table maps from ranges of characters to values.
64 Implementing a general data structure that maps from arbitrary
65 ranges of numbers to values is tricky to do efficiently. As it
66 happens, it should suffice (and is usually more convenient, anyway)
67 when dealing with characters to restrict the sorts of ranges that
68 can be assigned values, as follows:
71 2) All characters in a charset.
72 3) All characters in a particular row of a charset, where a "row"
73 means all characters with the same first byte.
74 4) A particular character in a charset.
76 We use char tables to generalize the 256-element vectors now
77 littering the Emacs code.
79 Possible uses (all should be converted at some point):
85 5) keyboard-translate-table?
88 abstract type to generalize the Emacs vectors and Mule
89 vectors-of-vectors goo.
92 /************************************************************************/
93 /* Char Table object */
94 /************************************************************************/
99 mark_char_table_entry (Lisp_Object obj, void (*markobj) (Lisp_Object))
101 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
104 for (i = 0; i < 96; i++)
106 markobj (cte->level2[i]);
112 char_table_entry_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
114 struct Lisp_Char_Table_Entry *cte1 = XCHAR_TABLE_ENTRY (obj1);
115 struct Lisp_Char_Table_Entry *cte2 = XCHAR_TABLE_ENTRY (obj2);
118 for (i = 0; i < 96; i++)
119 if (!internal_equal (cte1->level2[i], cte2->level2[i], depth + 1))
126 char_table_entry_hash (Lisp_Object obj, int depth)
128 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
130 return internal_array_hash (cte->level2, 96, depth);
133 static const struct lrecord_description char_table_entry_description[] = {
134 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table_Entry, level2), 96 },
138 DEFINE_LRECORD_IMPLEMENTATION ("char-table-entry", char_table_entry,
139 mark_char_table_entry, internal_object_printer,
140 0, char_table_entry_equal,
141 char_table_entry_hash,
142 char_table_entry_description,
143 struct Lisp_Char_Table_Entry);
147 mark_char_table (Lisp_Object obj, void (*markobj) (Lisp_Object))
149 struct Lisp_Char_Table *ct = XCHAR_TABLE (obj);
152 for (i = 0; i < NUM_ASCII_CHARS; i++)
153 markobj (ct->ascii[i]);
155 for (i = 0; i < NUM_LEADING_BYTES; i++)
156 markobj (ct->level1[i]);
158 return ct->mirror_table;
161 /* WARNING: All functions of this nature need to be written extremely
162 carefully to avoid crashes during GC. Cf. prune_specifiers()
163 and prune_weak_hash_tables(). */
166 prune_syntax_tables (int (*obj_marked_p) (Lisp_Object))
168 Lisp_Object rest, prev = Qnil;
170 for (rest = Vall_syntax_tables;
172 rest = XCHAR_TABLE (rest)->next_table)
174 if (! obj_marked_p (rest))
176 /* This table is garbage. Remove it from the list. */
178 Vall_syntax_tables = XCHAR_TABLE (rest)->next_table;
180 XCHAR_TABLE (prev)->next_table =
181 XCHAR_TABLE (rest)->next_table;
187 char_table_type_to_symbol (enum char_table_type type)
192 case CHAR_TABLE_TYPE_GENERIC: return Qgeneric;
193 case CHAR_TABLE_TYPE_SYNTAX: return Qsyntax;
194 case CHAR_TABLE_TYPE_DISPLAY: return Qdisplay;
195 case CHAR_TABLE_TYPE_CHAR: return Qchar;
197 case CHAR_TABLE_TYPE_CATEGORY: return Qcategory;
202 static enum char_table_type
203 symbol_to_char_table_type (Lisp_Object symbol)
205 CHECK_SYMBOL (symbol);
207 if (EQ (symbol, Qgeneric)) return CHAR_TABLE_TYPE_GENERIC;
208 if (EQ (symbol, Qsyntax)) return CHAR_TABLE_TYPE_SYNTAX;
209 if (EQ (symbol, Qdisplay)) return CHAR_TABLE_TYPE_DISPLAY;
210 if (EQ (symbol, Qchar)) return CHAR_TABLE_TYPE_CHAR;
212 if (EQ (symbol, Qcategory)) return CHAR_TABLE_TYPE_CATEGORY;
215 signal_simple_error ("Unrecognized char table type", symbol);
216 return CHAR_TABLE_TYPE_GENERIC; /* not reached */
220 print_chartab_range (Emchar first, Emchar last, Lisp_Object val,
221 Lisp_Object printcharfun)
225 write_c_string (" (", printcharfun);
226 print_internal (make_char (first), printcharfun, 0);
227 write_c_string (" ", printcharfun);
228 print_internal (make_char (last), printcharfun, 0);
229 write_c_string (") ", printcharfun);
233 write_c_string (" ", printcharfun);
234 print_internal (make_char (first), printcharfun, 0);
235 write_c_string (" ", printcharfun);
237 print_internal (val, printcharfun, 1);
243 print_chartab_charset_row (Lisp_Object charset,
245 struct Lisp_Char_Table_Entry *cte,
246 Lisp_Object printcharfun)
249 Lisp_Object cat = Qunbound;
252 for (i = 32; i < 128; i++)
254 Lisp_Object pam = cte->level2[i - 32];
266 print_chartab_range (MAKE_CHAR (charset, first, 0),
267 MAKE_CHAR (charset, i - 1, 0),
270 print_chartab_range (MAKE_CHAR (charset, row, first),
271 MAKE_CHAR (charset, row, i - 1),
281 print_chartab_range (MAKE_CHAR (charset, first, 0),
282 MAKE_CHAR (charset, i - 1, 0),
285 print_chartab_range (MAKE_CHAR (charset, row, first),
286 MAKE_CHAR (charset, row, i - 1),
292 print_chartab_two_byte_charset (Lisp_Object charset,
293 struct Lisp_Char_Table_Entry *cte,
294 Lisp_Object printcharfun)
298 for (i = 32; i < 128; i++)
300 Lisp_Object jen = cte->level2[i - 32];
302 if (!CHAR_TABLE_ENTRYP (jen))
306 write_c_string (" [", printcharfun);
307 print_internal (XCHARSET_NAME (charset), printcharfun, 0);
308 sprintf (buf, " %d] ", i);
309 write_c_string (buf, printcharfun);
310 print_internal (jen, printcharfun, 0);
313 print_chartab_charset_row (charset, i, XCHAR_TABLE_ENTRY (jen),
321 print_char_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
323 struct Lisp_Char_Table *ct = XCHAR_TABLE (obj);
326 sprintf (buf, "#s(char-table type %s data (",
327 string_data (symbol_name (XSYMBOL
328 (char_table_type_to_symbol (ct->type)))));
329 write_c_string (buf, printcharfun);
331 /* Now write out the ASCII/Control-1 stuff. */
335 Lisp_Object val = Qunbound;
337 for (i = 0; i < NUM_ASCII_CHARS; i++)
346 if (!EQ (ct->ascii[i], val))
348 print_chartab_range (first, i - 1, val, printcharfun);
355 print_chartab_range (first, i - 1, val, printcharfun);
362 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
365 Lisp_Object ann = ct->level1[i - MIN_LEADING_BYTE];
366 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (i);
368 if (!CHARSETP (charset) || i == LEADING_BYTE_ASCII
369 || i == LEADING_BYTE_CONTROL_1)
371 if (!CHAR_TABLE_ENTRYP (ann))
373 write_c_string (" ", printcharfun);
374 print_internal (XCHARSET_NAME (charset),
376 write_c_string (" ", printcharfun);
377 print_internal (ann, printcharfun, 0);
381 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (ann);
382 if (XCHARSET_DIMENSION (charset) == 1)
383 print_chartab_charset_row (charset, -1, cte, printcharfun);
385 print_chartab_two_byte_charset (charset, cte, printcharfun);
391 write_c_string ("))", printcharfun);
395 char_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
397 struct Lisp_Char_Table *ct1 = XCHAR_TABLE (obj1);
398 struct Lisp_Char_Table *ct2 = XCHAR_TABLE (obj2);
401 if (CHAR_TABLE_TYPE (ct1) != CHAR_TABLE_TYPE (ct2))
404 for (i = 0; i < NUM_ASCII_CHARS; i++)
405 if (!internal_equal (ct1->ascii[i], ct2->ascii[i], depth + 1))
409 for (i = 0; i < NUM_LEADING_BYTES; i++)
410 if (!internal_equal (ct1->level1[i], ct2->level1[i], depth + 1))
418 char_table_hash (Lisp_Object obj, int depth)
420 struct Lisp_Char_Table *ct = XCHAR_TABLE (obj);
421 unsigned long hashval = internal_array_hash (ct->ascii, NUM_ASCII_CHARS,
424 hashval = HASH2 (hashval,
425 internal_array_hash (ct->level1, NUM_LEADING_BYTES, depth));
430 static const struct lrecord_description char_table_description[] = {
431 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table, ascii), NUM_ASCII_CHARS },
433 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table, level1), NUM_LEADING_BYTES },
438 DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table,
439 mark_char_table, print_char_table, 0,
440 char_table_equal, char_table_hash,
441 char_table_description,
442 struct Lisp_Char_Table);
444 DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /*
445 Return non-nil if OBJECT is a char table.
447 A char table is a table that maps characters (or ranges of characters)
448 to values. Char tables are specialized for characters, only allowing
449 particular sorts of ranges to be assigned values. Although this
450 loses in generality, it makes for extremely fast (constant-time)
451 lookups, and thus is feasible for applications that do an extremely
452 large number of lookups (e.g. scanning a buffer for a character in
453 a particular syntax, where a lookup in the syntax table must occur
456 When Mule support exists, the types of ranges that can be assigned
461 -- a single row in a two-octet charset
462 -- a single character
464 When Mule support is not present, the types of ranges that can be
468 -- a single character
470 To create a char table, use `make-char-table'. To modify a char
471 table, use `put-char-table' or `remove-char-table'. To retrieve the
472 value for a particular character, use `get-char-table'. See also
473 `map-char-table', `clear-char-table', `copy-char-table',
474 `valid-char-table-type-p', `char-table-type-list', `valid-char-table-value-p',
475 and `check-char-table-value'.
479 return CHAR_TABLEP (object) ? Qt : Qnil;
482 DEFUN ("char-table-type-list", Fchar_table_type_list, 0, 0, 0, /*
483 Return a list of the recognized char table types.
484 See `valid-char-table-type-p'.
489 return list5 (Qchar, Qcategory, Qdisplay, Qgeneric, Qsyntax);
491 return list4 (Qchar, Qdisplay, Qgeneric, Qsyntax);
495 DEFUN ("valid-char-table-type-p", Fvalid_char_table_type_p, 1, 1, 0, /*
496 Return t if TYPE if a recognized char table type.
498 Each char table type is used for a different purpose and allows different
499 sorts of values. The different char table types are
502 Used for category tables, which specify the regexp categories
503 that a character is in. The valid values are nil or a
504 bit vector of 95 elements. Higher-level Lisp functions are
505 provided for working with category tables. Currently categories
506 and category tables only exist when Mule support is present.
508 A generalized char table, for mapping from one character to
509 another. Used for case tables, syntax matching tables,
510 `keyboard-translate-table', etc. The valid values are characters.
512 An even more generalized char table, for mapping from a
513 character to anything.
515 Used for display tables, which specify how a particular character
516 is to appear when displayed. #### Not yet implemented.
518 Used for syntax tables, which specify the syntax of a particular
519 character. Higher-level Lisp functions are provided for
520 working with syntax tables. The valid values are integers.
525 return (EQ (type, Qchar) ||
527 EQ (type, Qcategory) ||
529 EQ (type, Qdisplay) ||
530 EQ (type, Qgeneric) ||
531 EQ (type, Qsyntax)) ? Qt : Qnil;
534 DEFUN ("char-table-type", Fchar_table_type, 1, 1, 0, /*
535 Return the type of char table TABLE.
536 See `valid-char-table-type-p'.
540 CHECK_CHAR_TABLE (table);
541 return char_table_type_to_symbol (XCHAR_TABLE (table)->type);
545 fill_char_table (struct Lisp_Char_Table *ct, Lisp_Object value)
549 for (i = 0; i < NUM_ASCII_CHARS; i++)
550 ct->ascii[i] = value;
552 for (i = 0; i < NUM_LEADING_BYTES; i++)
553 ct->level1[i] = value;
556 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
557 update_syntax_table (ct);
560 DEFUN ("reset-char-table", Freset_char_table, 1, 1, 0, /*
561 Reset a char table to its default state.
565 struct Lisp_Char_Table *ct;
567 CHECK_CHAR_TABLE (table);
568 ct = XCHAR_TABLE (table);
572 case CHAR_TABLE_TYPE_CHAR:
573 fill_char_table (ct, make_char (0));
575 case CHAR_TABLE_TYPE_DISPLAY:
576 case CHAR_TABLE_TYPE_GENERIC:
578 case CHAR_TABLE_TYPE_CATEGORY:
580 fill_char_table (ct, Qnil);
583 case CHAR_TABLE_TYPE_SYNTAX:
584 fill_char_table (ct, make_int (Sinherit));
594 DEFUN ("make-char-table", Fmake_char_table, 1, 1, 0, /*
595 Return a new, empty char table of type TYPE.
596 Currently recognized types are 'char, 'category, 'display, 'generic,
597 and 'syntax. See `valid-char-table-type-p'.
601 struct Lisp_Char_Table *ct;
603 enum char_table_type ty = symbol_to_char_table_type (type);
605 ct = alloc_lcrecord_type (struct Lisp_Char_Table, &lrecord_char_table);
607 if (ty == CHAR_TABLE_TYPE_SYNTAX)
609 ct->mirror_table = Fmake_char_table (Qgeneric);
610 fill_char_table (XCHAR_TABLE (ct->mirror_table),
614 ct->mirror_table = Qnil;
615 ct->next_table = Qnil;
616 XSETCHAR_TABLE (obj, ct);
617 if (ty == CHAR_TABLE_TYPE_SYNTAX)
619 ct->next_table = Vall_syntax_tables;
620 Vall_syntax_tables = obj;
622 Freset_char_table (obj);
629 make_char_table_entry (Lisp_Object initval)
633 struct Lisp_Char_Table_Entry *cte =
634 alloc_lcrecord_type (struct Lisp_Char_Table_Entry,
635 &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 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
650 struct Lisp_Char_Table_Entry *ctenew =
651 alloc_lcrecord_type (struct Lisp_Char_Table_Entry,
652 &lrecord_char_table_entry);
654 for (i = 0; i < 96; i++)
656 Lisp_Object new = cte->level2[i];
657 if (CHAR_TABLE_ENTRYP (new))
658 ctenew->level2[i] = copy_char_table_entry (new);
660 ctenew->level2[i] = new;
663 XSETCHAR_TABLE_ENTRY (obj, ctenew);
669 DEFUN ("copy-char-table", Fcopy_char_table, 1, 1, 0, /*
670 Make a new char table which is a copy of OLD-TABLE.
671 It will contain the same values for the same characters and ranges
672 as OLD-TABLE. The values will not themselves be copied.
676 struct Lisp_Char_Table *ct, *ctnew;
680 CHECK_CHAR_TABLE (old_table);
681 ct = XCHAR_TABLE (old_table);
682 ctnew = alloc_lcrecord_type (struct Lisp_Char_Table, &lrecord_char_table);
683 ctnew->type = ct->type;
685 for (i = 0; i < NUM_ASCII_CHARS; i++)
687 Lisp_Object new = ct->ascii[i];
689 assert (! (CHAR_TABLE_ENTRYP (new)));
691 ctnew->ascii[i] = new;
696 for (i = 0; i < NUM_LEADING_BYTES; i++)
698 Lisp_Object new = ct->level1[i];
699 if (CHAR_TABLE_ENTRYP (new))
700 ctnew->level1[i] = copy_char_table_entry (new);
702 ctnew->level1[i] = new;
707 if (CHAR_TABLEP (ct->mirror_table))
708 ctnew->mirror_table = Fcopy_char_table (ct->mirror_table);
710 ctnew->mirror_table = ct->mirror_table;
711 XSETCHAR_TABLE (obj, ctnew);
716 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange)
719 outrange->type = CHARTAB_RANGE_ALL;
720 else if (CHAR_OR_CHAR_INTP (range))
722 outrange->type = CHARTAB_RANGE_CHAR;
723 outrange->ch = XCHAR_OR_CHAR_INT (range);
727 signal_simple_error ("Range must be t or a character", range);
729 else if (VECTORP (range))
731 struct Lisp_Vector *vec = XVECTOR (range);
732 Lisp_Object *elts = vector_data (vec);
733 if (vector_length (vec) != 2)
734 signal_simple_error ("Length of charset row vector must be 2",
736 outrange->type = CHARTAB_RANGE_ROW;
737 outrange->charset = Fget_charset (elts[0]);
739 outrange->row = XINT (elts[1]);
740 switch (XCHARSET_TYPE (outrange->charset))
742 case CHARSET_TYPE_94:
743 case CHARSET_TYPE_96:
744 signal_simple_error ("Charset in row vector must be multi-byte",
746 case CHARSET_TYPE_94X94:
747 check_int_range (outrange->row, 33, 126);
749 case CHARSET_TYPE_96X96:
750 check_int_range (outrange->row, 32, 127);
758 if (!CHARSETP (range) && !SYMBOLP (range))
760 ("Char table range must be t, charset, char, or vector", range);
761 outrange->type = CHARTAB_RANGE_CHARSET;
762 outrange->charset = Fget_charset (range);
769 /* called from CHAR_TABLE_VALUE(). */
771 get_non_ascii_char_table_value (struct Lisp_Char_Table *ct, int leading_byte,
775 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (leading_byte);
778 BREAKUP_CHAR_1_UNSAFE (c, charset, byte1, byte2);
779 val = ct->level1[leading_byte - MIN_LEADING_BYTE];
780 if (CHAR_TABLE_ENTRYP (val))
782 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
783 val = cte->level2[byte1 - 32];
784 if (CHAR_TABLE_ENTRYP (val))
786 cte = XCHAR_TABLE_ENTRY (val);
787 assert (byte2 >= 32);
788 val = cte->level2[byte2 - 32];
789 assert (!CHAR_TABLE_ENTRYP (val));
799 get_char_table (Emchar ch, struct Lisp_Char_Table *ct)
807 BREAKUP_CHAR (ch, charset, byte1, byte2);
809 if (EQ (charset, Vcharset_ascii))
810 val = ct->ascii[byte1];
811 else if (EQ (charset, Vcharset_control_1))
812 val = ct->ascii[byte1 + 128];
815 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
816 val = ct->level1[lb];
817 if (CHAR_TABLE_ENTRYP (val))
819 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
820 val = cte->level2[byte1 - 32];
821 if (CHAR_TABLE_ENTRYP (val))
823 cte = XCHAR_TABLE_ENTRY (val);
824 assert (byte2 >= 32);
825 val = cte->level2[byte2 - 32];
826 assert (!CHAR_TABLE_ENTRYP (val));
834 return ct->ascii[(unsigned char)ch];
835 #endif /* not MULE */
839 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
840 Find value for char CH in TABLE.
844 struct Lisp_Char_Table *ct;
846 CHECK_CHAR_TABLE (table);
847 ct = XCHAR_TABLE (table);
848 CHECK_CHAR_COERCE_INT (ch);
850 return get_char_table (XCHAR (ch), ct);
853 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
854 Find value for a range in TABLE.
855 If there is more than one value, return MULTI (defaults to nil).
857 (range, table, multi))
859 struct Lisp_Char_Table *ct;
860 struct chartab_range rainj;
862 if (CHAR_OR_CHAR_INTP (range))
863 return Fget_char_table (range, table);
864 CHECK_CHAR_TABLE (table);
865 ct = XCHAR_TABLE (table);
867 decode_char_table_range (range, &rainj);
870 case CHARTAB_RANGE_ALL:
873 Lisp_Object first = ct->ascii[0];
875 for (i = 1; i < NUM_ASCII_CHARS; i++)
876 if (!EQ (first, ct->ascii[i]))
880 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
883 if (!CHARSETP (CHARSET_BY_LEADING_BYTE (i))
884 || i == LEADING_BYTE_ASCII
885 || i == LEADING_BYTE_CONTROL_1)
887 if (!EQ (first, ct->level1[i - MIN_LEADING_BYTE]))
896 case CHARTAB_RANGE_CHARSET:
897 if (EQ (rainj.charset, Vcharset_ascii))
900 Lisp_Object first = ct->ascii[0];
902 for (i = 1; i < 128; i++)
903 if (!EQ (first, ct->ascii[i]))
908 if (EQ (rainj.charset, Vcharset_control_1))
911 Lisp_Object first = ct->ascii[128];
913 for (i = 129; i < 160; i++)
914 if (!EQ (first, ct->ascii[i]))
920 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
922 if (CHAR_TABLE_ENTRYP (val))
927 case CHARTAB_RANGE_ROW:
929 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
931 if (!CHAR_TABLE_ENTRYP (val))
933 val = XCHAR_TABLE_ENTRY (val)->level2[rainj.row - 32];
934 if (CHAR_TABLE_ENTRYP (val))
938 #endif /* not MULE */
944 return Qnil; /* not reached */
948 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
953 case CHAR_TABLE_TYPE_SYNTAX:
954 if (!ERRB_EQ (errb, ERROR_ME))
955 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
956 && CHAR_OR_CHAR_INTP (XCDR (value)));
959 Lisp_Object cdr = XCDR (value);
960 CHECK_INT (XCAR (value));
961 CHECK_CHAR_COERCE_INT (cdr);
968 case CHAR_TABLE_TYPE_CATEGORY:
969 if (!ERRB_EQ (errb, ERROR_ME))
970 return CATEGORY_TABLE_VALUEP (value);
971 CHECK_CATEGORY_TABLE_VALUE (value);
975 case CHAR_TABLE_TYPE_GENERIC:
978 case CHAR_TABLE_TYPE_DISPLAY:
980 maybe_signal_simple_error ("Display char tables not yet implemented",
981 value, Qchar_table, errb);
984 case CHAR_TABLE_TYPE_CHAR:
985 if (!ERRB_EQ (errb, ERROR_ME))
986 return CHAR_OR_CHAR_INTP (value);
987 CHECK_CHAR_COERCE_INT (value);
994 return 0; /* not reached */
998 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
1002 case CHAR_TABLE_TYPE_SYNTAX:
1005 Lisp_Object car = XCAR (value);
1006 Lisp_Object cdr = XCDR (value);
1007 CHECK_CHAR_COERCE_INT (cdr);
1008 return Fcons (car, cdr);
1011 case CHAR_TABLE_TYPE_CHAR:
1012 CHECK_CHAR_COERCE_INT (value);
1020 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
1021 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
1023 (value, char_table_type))
1025 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1027 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
1030 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
1031 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
1033 (value, char_table_type))
1035 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1037 check_valid_char_table_value (value, type, ERROR_ME);
1041 /* Assign VAL to all characters in RANGE in char table CT. */
1044 put_char_table (struct Lisp_Char_Table *ct, struct chartab_range *range,
1047 switch (range->type)
1049 case CHARTAB_RANGE_ALL:
1050 fill_char_table (ct, val);
1051 return; /* avoid the duplicate call to update_syntax_table() below,
1052 since fill_char_table() also did that. */
1055 case CHARTAB_RANGE_CHARSET:
1056 if (EQ (range->charset, Vcharset_ascii))
1059 for (i = 0; i < 128; i++)
1062 else if (EQ (range->charset, Vcharset_control_1))
1065 for (i = 128; i < 160; i++)
1070 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1071 ct->level1[lb] = val;
1075 case CHARTAB_RANGE_ROW:
1077 struct Lisp_Char_Table_Entry *cte;
1078 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1079 /* make sure that there is a separate entry for the row. */
1080 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1081 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1082 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1083 cte->level2[range->row - 32] = val;
1088 case CHARTAB_RANGE_CHAR:
1091 Lisp_Object charset;
1094 BREAKUP_CHAR (range->ch, charset, byte1, byte2);
1095 if (EQ (charset, Vcharset_ascii))
1096 ct->ascii[byte1] = val;
1097 else if (EQ (charset, Vcharset_control_1))
1098 ct->ascii[byte1 + 128] = val;
1101 struct Lisp_Char_Table_Entry *cte;
1102 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
1103 /* make sure that there is a separate entry for the row. */
1104 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1105 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1106 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1107 /* now CTE is a char table entry for the charset;
1108 each entry is for a single row (or character of
1109 a one-octet charset). */
1110 if (XCHARSET_DIMENSION (charset) == 1)
1111 cte->level2[byte1 - 32] = val;
1114 /* assigning to one character in a two-octet charset. */
1115 /* make sure that the charset row contains a separate
1116 entry for each character. */
1117 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
1118 cte->level2[byte1 - 32] =
1119 make_char_table_entry (cte->level2[byte1 - 32]);
1120 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
1121 cte->level2[byte2 - 32] = val;
1125 #else /* not MULE */
1126 ct->ascii[(unsigned char) (range->ch)] = val;
1128 #endif /* not MULE */
1131 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
1132 update_syntax_table (ct);
1135 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
1136 Set the value for chars in RANGE to be VAL in TABLE.
1138 RANGE specifies one or more characters to be affected and should be
1139 one of the following:
1141 -- t (all characters are affected)
1142 -- A charset (only allowed when Mule support is present)
1143 -- A vector of two elements: a two-octet charset and a row number
1144 (only allowed when Mule support is present)
1145 -- A single character
1147 VAL must be a value appropriate for the type of TABLE.
1148 See `valid-char-table-type-p'.
1150 (range, val, table))
1152 struct Lisp_Char_Table *ct;
1153 struct chartab_range rainj;
1155 CHECK_CHAR_TABLE (table);
1156 ct = XCHAR_TABLE (table);
1157 check_valid_char_table_value (val, ct->type, ERROR_ME);
1158 decode_char_table_range (range, &rainj);
1159 val = canonicalize_char_table_value (val, ct->type);
1160 put_char_table (ct, &rainj, val);
1164 /* Map FN over the ASCII chars in CT. */
1167 map_over_charset_ascii (struct Lisp_Char_Table *ct,
1168 int (*fn) (struct chartab_range *range,
1169 Lisp_Object val, void *arg),
1172 struct chartab_range rainj;
1181 rainj.type = CHARTAB_RANGE_CHAR;
1183 for (i = start, retval = 0; i < stop && retval == 0; i++)
1185 rainj.ch = (Emchar) i;
1186 retval = (fn) (&rainj, ct->ascii[i], arg);
1194 /* Map FN over the Control-1 chars in CT. */
1197 map_over_charset_control_1 (struct Lisp_Char_Table *ct,
1198 int (*fn) (struct chartab_range *range,
1199 Lisp_Object val, void *arg),
1202 struct chartab_range rainj;
1205 int stop = start + 32;
1207 rainj.type = CHARTAB_RANGE_CHAR;
1209 for (i = start, retval = 0; i < stop && retval == 0; i++)
1211 rainj.ch = (Emchar) (i);
1212 retval = (fn) (&rainj, ct->ascii[i], arg);
1218 /* Map FN over the row ROW of two-byte charset CHARSET.
1219 There must be a separate value for that row in the char table.
1220 CTE specifies the char table entry for CHARSET. */
1223 map_over_charset_row (struct Lisp_Char_Table_Entry *cte,
1224 Lisp_Object charset, int row,
1225 int (*fn) (struct chartab_range *range,
1226 Lisp_Object val, void *arg),
1229 Lisp_Object val = cte->level2[row - 32];
1231 if (!CHAR_TABLE_ENTRYP (val))
1233 struct chartab_range rainj;
1235 rainj.type = CHARTAB_RANGE_ROW;
1236 rainj.charset = charset;
1238 return (fn) (&rainj, val, arg);
1242 struct chartab_range rainj;
1244 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1245 int start = charset94_p ? 33 : 32;
1246 int stop = charset94_p ? 127 : 128;
1248 cte = XCHAR_TABLE_ENTRY (val);
1250 rainj.type = CHARTAB_RANGE_CHAR;
1252 for (i = start, retval = 0; i < stop && retval == 0; i++)
1254 rainj.ch = MAKE_CHAR (charset, row, i);
1255 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1263 map_over_other_charset (struct Lisp_Char_Table *ct, int lb,
1264 int (*fn) (struct chartab_range *range,
1265 Lisp_Object val, void *arg),
1268 Lisp_Object val = ct->level1[lb - MIN_LEADING_BYTE];
1269 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (lb);
1271 if (!CHARSETP (charset)
1272 || lb == LEADING_BYTE_ASCII
1273 || lb == LEADING_BYTE_CONTROL_1)
1276 if (!CHAR_TABLE_ENTRYP (val))
1278 struct chartab_range rainj;
1280 rainj.type = CHARTAB_RANGE_CHARSET;
1281 rainj.charset = charset;
1282 return (fn) (&rainj, val, arg);
1286 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
1287 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1288 int start = charset94_p ? 33 : 32;
1289 int stop = charset94_p ? 127 : 128;
1292 if (XCHARSET_DIMENSION (charset) == 1)
1294 struct chartab_range rainj;
1295 rainj.type = CHARTAB_RANGE_CHAR;
1297 for (i = start, retval = 0; i < stop && retval == 0; i++)
1299 rainj.ch = MAKE_CHAR (charset, i, 0);
1300 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1305 for (i = start, retval = 0; i < stop && retval == 0; i++)
1306 retval = map_over_charset_row (cte, charset, i, fn, arg);
1315 /* Map FN (with client data ARG) over range RANGE in char table CT.
1316 Mapping stops the first time FN returns non-zero, and that value
1317 becomes the return value of map_char_table(). */
1320 map_char_table (struct Lisp_Char_Table *ct,
1321 struct chartab_range *range,
1322 int (*fn) (struct chartab_range *range,
1323 Lisp_Object val, void *arg),
1326 switch (range->type)
1328 case CHARTAB_RANGE_ALL:
1332 retval = map_over_charset_ascii (ct, fn, arg);
1336 retval = map_over_charset_control_1 (ct, fn, arg);
1341 int start = MIN_LEADING_BYTE;
1342 int stop = start + NUM_LEADING_BYTES;
1344 for (i = start, retval = 0; i < stop && retval == 0; i++)
1346 retval = map_over_other_charset (ct, i, fn, arg);
1354 case CHARTAB_RANGE_CHARSET:
1355 return map_over_other_charset (ct,
1356 XCHARSET_LEADING_BYTE (range->charset),
1359 case CHARTAB_RANGE_ROW:
1361 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE];
1362 if (!CHAR_TABLE_ENTRYP (val))
1364 struct chartab_range rainj;
1366 rainj.type = CHARTAB_RANGE_ROW;
1367 rainj.charset = range->charset;
1368 rainj.row = range->row;
1369 return (fn) (&rainj, val, arg);
1372 return map_over_charset_row (XCHAR_TABLE_ENTRY (val),
1373 range->charset, range->row,
1378 case CHARTAB_RANGE_CHAR:
1380 Emchar ch = range->ch;
1381 Lisp_Object val = CHAR_TABLE_VALUE_UNSAFE (ct, ch);
1382 struct chartab_range rainj;
1384 rainj.type = CHARTAB_RANGE_CHAR;
1386 return (fn) (&rainj, val, arg);
1396 struct slow_map_char_table_arg
1398 Lisp_Object function;
1403 slow_map_char_table_fun (struct chartab_range *range,
1404 Lisp_Object val, void *arg)
1406 Lisp_Object ranjarg = Qnil;
1407 struct slow_map_char_table_arg *closure =
1408 (struct slow_map_char_table_arg *) arg;
1410 switch (range->type)
1412 case CHARTAB_RANGE_ALL:
1417 case CHARTAB_RANGE_CHARSET:
1418 ranjarg = XCHARSET_NAME (range->charset);
1421 case CHARTAB_RANGE_ROW:
1422 ranjarg = vector2 (XCHARSET_NAME (range->charset),
1423 make_int (range->row));
1426 case CHARTAB_RANGE_CHAR:
1427 ranjarg = make_char (range->ch);
1433 closure->retval = call2 (closure->function, ranjarg, val);
1434 return !NILP (closure->retval);
1437 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
1438 Map FUNCTION over entries in TABLE, calling it with two args,
1439 each key and value in the table.
1441 RANGE specifies a subrange to map over and is in the same format as
1442 the RANGE argument to `put-range-table'. If omitted or t, it defaults to
1445 (function, table, range))
1447 struct Lisp_Char_Table *ct;
1448 struct slow_map_char_table_arg slarg;
1449 struct gcpro gcpro1, gcpro2;
1450 struct chartab_range rainj;
1452 CHECK_CHAR_TABLE (table);
1453 ct = XCHAR_TABLE (table);
1456 decode_char_table_range (range, &rainj);
1457 slarg.function = function;
1458 slarg.retval = Qnil;
1459 GCPRO2 (slarg.function, slarg.retval);
1460 map_char_table (ct, &rainj, slow_map_char_table_fun, &slarg);
1463 return slarg.retval;
1468 /************************************************************************/
1469 /* Char table read syntax */
1470 /************************************************************************/
1473 chartab_type_validate (Lisp_Object keyword, Lisp_Object value,
1474 Error_behavior errb)
1476 /* #### should deal with ERRB */
1477 symbol_to_char_table_type (value);
1482 chartab_data_validate (Lisp_Object keyword, Lisp_Object value,
1483 Error_behavior errb)
1487 /* #### should deal with ERRB */
1488 EXTERNAL_LIST_LOOP (rest, value)
1490 Lisp_Object range = XCAR (rest);
1491 struct chartab_range dummy;
1495 signal_simple_error ("Invalid list format", value);
1498 if (!CONSP (XCDR (range))
1499 || !NILP (XCDR (XCDR (range))))
1500 signal_simple_error ("Invalid range format", range);
1501 decode_char_table_range (XCAR (range), &dummy);
1502 decode_char_table_range (XCAR (XCDR (range)), &dummy);
1505 decode_char_table_range (range, &dummy);
1512 chartab_instantiate (Lisp_Object data)
1514 Lisp_Object chartab;
1515 Lisp_Object type = Qgeneric;
1516 Lisp_Object dataval = Qnil;
1518 while (!NILP (data))
1520 Lisp_Object keyw = Fcar (data);
1526 if (EQ (keyw, Qtype))
1528 else if (EQ (keyw, Qdata))
1532 chartab = Fmake_char_table (type);
1535 while (!NILP (data))
1537 Lisp_Object range = Fcar (data);
1538 Lisp_Object val = Fcar (Fcdr (data));
1540 data = Fcdr (Fcdr (data));
1543 if (CHAR_OR_CHAR_INTP (XCAR (range)))
1545 Emchar first = XCHAR_OR_CHAR_INT (Fcar (range));
1546 Emchar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
1549 for (i = first; i <= last; i++)
1550 Fput_char_table (make_char (i), val, chartab);
1556 Fput_char_table (range, val, chartab);
1565 /************************************************************************/
1566 /* Category Tables, specifically */
1567 /************************************************************************/
1569 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
1570 Return t if ARG is a category table.
1571 A category table is a type of char table used for keeping track of
1572 categories. Categories are used for classifying characters for use
1573 in regexps -- you can refer to a category rather than having to use
1574 a complicated [] expression (and category lookups are significantly
1577 There are 95 different categories available, one for each printable
1578 character (including space) in the ASCII charset. Each category
1579 is designated by one such character, called a "category designator".
1580 They are specified in a regexp using the syntax "\\cX", where X is
1581 a category designator.
1583 A category table specifies, for each character, the categories that
1584 the character is in. Note that a character can be in more than one
1585 category. More specifically, a category table maps from a character
1586 to either the value nil (meaning the character is in no categories)
1587 or a 95-element bit vector, specifying for each of the 95 categories
1588 whether the character is in that category.
1590 Special Lisp functions are provided that abstract this, so you do not
1591 have to directly manipulate bit vectors.
1595 return (CHAR_TABLEP (obj) &&
1596 XCHAR_TABLE_TYPE (obj) == CHAR_TABLE_TYPE_CATEGORY) ?
1601 check_category_table (Lisp_Object obj, Lisp_Object def)
1605 while (NILP (Fcategory_table_p (obj)))
1606 obj = wrong_type_argument (Qcategory_table_p, obj);
1611 check_category_char (Emchar ch, Lisp_Object table,
1612 unsigned int designator, unsigned int not)
1614 REGISTER Lisp_Object temp;
1615 struct Lisp_Char_Table *ctbl;
1616 #ifdef ERROR_CHECK_TYPECHECK
1617 if (NILP (Fcategory_table_p (table)))
1618 signal_simple_error ("Expected category table", table);
1620 ctbl = XCHAR_TABLE (table);
1621 temp = get_char_table (ch, ctbl);
1626 return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not : not;
1629 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
1630 Return t if category of a character at POS includes DESIGNATOR,
1631 else return nil. Optional third arg specifies which buffer
1632 \(defaulting to current), and fourth specifies the CATEGORY-TABLE,
1633 \(defaulting to the buffer's category table).
1635 (pos, designator, buffer, category_table))
1640 struct buffer *buf = decode_buffer (buffer, 0);
1643 CHECK_CATEGORY_DESIGNATOR (designator);
1644 des = XCHAR (designator);
1645 ctbl = check_category_table (category_table, Vstandard_category_table);
1646 ch = BUF_FETCH_CHAR (buf, XINT (pos));
1647 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1650 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
1651 Return t if category of character CHR includes DESIGNATOR, else nil.
1652 Optional third arg specifies the CATEGORY-TABLE to use,
1653 which defaults to the system default table.
1655 (chr, designator, category_table))
1661 CHECK_CATEGORY_DESIGNATOR (designator);
1662 des = XCHAR (designator);
1665 ctbl = check_category_table (category_table, Vstandard_category_table);
1666 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1669 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
1670 Return the current category table.
1671 This is the one specified by the current buffer, or by BUFFER if it
1676 return decode_buffer (buffer, 0)->category_table;
1679 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
1680 Return the standard category table.
1681 This is the one used for new buffers.
1685 return Vstandard_category_table;
1688 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
1689 Construct a new category table and return it.
1690 It is a copy of the TABLE, which defaults to the standard category table.
1694 if (NILP (Vstandard_category_table))
1695 return Fmake_char_table (Qcategory);
1697 table = check_category_table (table, Vstandard_category_table);
1698 return Fcopy_char_table (table);
1701 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
1702 Select a new category table for BUFFER.
1703 One argument, a category table.
1704 BUFFER defaults to the current buffer if omitted.
1708 struct buffer *buf = decode_buffer (buffer, 0);
1709 table = check_category_table (table, Qnil);
1710 buf->category_table = table;
1711 /* Indicate that this buffer now has a specified category table. */
1712 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
1716 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
1717 Return t if ARG is a category designator (a char in the range ' ' to '~').
1721 return CATEGORY_DESIGNATORP (obj) ? Qt : Qnil;
1724 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
1725 Return t if ARG is a category table value.
1726 Valid values are nil or a bit vector of size 95.
1730 return CATEGORY_TABLE_VALUEP (obj) ? Qt : Qnil;
1734 #define CATEGORYP(x) \
1735 (CHARP ((x)) && XCHAR ((x)) >= 0x20 && XCHAR ((x)) <= 0x7E)
1737 #define CATEGORY_SET(c) \
1738 (get_char_table(c, XCHAR_TABLE(current_buffer->category_table)))
1740 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0.
1741 The faster version of `!NILP (Faref (category_set, category))'. */
1742 #define CATEGORY_MEMBER(category, category_set) \
1743 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32))
1745 /* Return 1 if there is a word boundary between two word-constituent
1746 characters C1 and C2 if they appear in this order, else return 0.
1747 Use the macro WORD_BOUNDARY_P instead of calling this function
1751 word_boundary_p (Emchar c1, Emchar c2)
1753 Lisp_Object category_set1, category_set2;
1758 if (COMPOSITE_CHAR_P (c1))
1759 c1 = cmpchar_component (c1, 0, 1);
1760 if (COMPOSITE_CHAR_P (c2))
1761 c2 = cmpchar_component (c2, 0, 1);
1764 if (EQ (CHAR_CHARSET (c1), CHAR_CHARSET (c2)))
1766 tail = Vword_separating_categories;
1771 tail = Vword_combining_categories;
1775 category_set1 = CATEGORY_SET (c1);
1776 if (NILP (category_set1))
1777 return default_result;
1778 category_set2 = CATEGORY_SET (c2);
1779 if (NILP (category_set2))
1780 return default_result;
1782 for (; CONSP (tail); tail = XCONS (tail)->cdr)
1784 Lisp_Object elt = XCONS(tail)->car;
1787 && CATEGORYP (XCONS (elt)->car)
1788 && CATEGORYP (XCONS (elt)->cdr)
1789 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->car), category_set1)
1790 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->cdr), category_set2))
1791 return !default_result;
1793 return default_result;
1799 syms_of_chartab (void)
1802 defsymbol (&Qcategory_table_p, "category-table-p");
1803 defsymbol (&Qcategory_designator_p, "category-designator-p");
1804 defsymbol (&Qcategory_table_value_p, "category-table-value-p");
1807 defsymbol (&Qchar_table, "char-table");
1808 defsymbol (&Qchar_tablep, "char-table-p");
1810 DEFSUBR (Fchar_table_p);
1811 DEFSUBR (Fchar_table_type_list);
1812 DEFSUBR (Fvalid_char_table_type_p);
1813 DEFSUBR (Fchar_table_type);
1814 DEFSUBR (Freset_char_table);
1815 DEFSUBR (Fmake_char_table);
1816 DEFSUBR (Fcopy_char_table);
1817 DEFSUBR (Fget_char_table);
1818 DEFSUBR (Fget_range_char_table);
1819 DEFSUBR (Fvalid_char_table_value_p);
1820 DEFSUBR (Fcheck_valid_char_table_value);
1821 DEFSUBR (Fput_char_table);
1822 DEFSUBR (Fmap_char_table);
1825 DEFSUBR (Fcategory_table_p);
1826 DEFSUBR (Fcategory_table);
1827 DEFSUBR (Fstandard_category_table);
1828 DEFSUBR (Fcopy_category_table);
1829 DEFSUBR (Fset_category_table);
1830 DEFSUBR (Fcheck_category_at);
1831 DEFSUBR (Fchar_in_category_p);
1832 DEFSUBR (Fcategory_designator_p);
1833 DEFSUBR (Fcategory_table_value_p);
1839 vars_of_chartab (void)
1841 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
1842 Vall_syntax_tables = Qnil;
1846 structure_type_create_chartab (void)
1848 struct structure_type *st;
1850 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
1852 define_structure_type_keyword (st, Qtype, chartab_type_validate);
1853 define_structure_type_keyword (st, Qdata, chartab_data_validate);
1857 complex_vars_of_chartab (void)
1860 /* Set this now, so first buffer creation can refer to it. */
1861 /* Make it nil before calling copy-category-table
1862 so that copy-category-table will know not to try to copy from garbage */
1863 Vstandard_category_table = Qnil;
1864 Vstandard_category_table = Fcopy_category_table (Qnil);
1865 staticpro (&Vstandard_category_table);
1867 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /*
1868 List of pair (cons) of categories to determine word boundary.
1870 Emacs treats a sequence of word constituent characters as a single
1871 word (i.e. finds no word boundary between them) iff they belongs to
1872 the same charset. But, exceptions are allowed in the following cases.
1874 (1) The case that characters are in different charsets is controlled
1875 by the variable `word-combining-categories'.
1877 Emacs finds no word boundary between characters of different charsets
1878 if they have categories matching some element of this list.
1880 More precisely, if an element of this list is a cons of category CAT1
1881 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1882 C2 which has CAT2, there's no word boundary between C1 and C2.
1884 For instance, to tell that ASCII characters and Latin-1 characters can
1885 form a single word, the element `(?l . ?l)' should be in this list
1886 because both characters have the category `l' (Latin characters).
1888 (2) The case that character are in the same charset is controlled by
1889 the variable `word-separating-categories'.
1891 Emacs find a word boundary between characters of the same charset
1892 if they have categories matching some element of this list.
1894 More precisely, if an element of this list is a cons of category CAT1
1895 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1896 C2 which has CAT2, there's a word boundary between C1 and C2.
1898 For instance, to tell that there's a word boundary between Japanese
1899 Hiragana and Japanese Kanji (both are in the same charset), the
1900 element `(?H . ?C) should be in this list.
1903 Vword_combining_categories = Qnil;
1905 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /*
1906 List of pair (cons) of categories to determine word boundary.
1907 See the documentation of the variable `word-combining-categories'.
1910 Vword_separating_categories = Qnil;