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, void (*markobj) (Lisp_Object))
100 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
103 for (i = 0; i < 96; i++)
105 markobj (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, void (*markobj) (Lisp_Object))
148 struct Lisp_Char_Table *ct = XCHAR_TABLE (obj);
151 for (i = 0; i < NUM_ASCII_CHARS; i++)
152 markobj (ct->ascii[i]);
154 for (i = 0; i < NUM_LEADING_BYTES; i++)
155 markobj (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 (int (*obj_marked_p) (Lisp_Object))
167 Lisp_Object rest, prev = Qnil;
169 for (rest = Vall_syntax_tables;
171 rest = XCHAR_TABLE (rest)->next_table)
173 if (! obj_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 },
437 DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table,
438 mark_char_table, print_char_table, 0,
439 char_table_equal, char_table_hash,
440 char_table_description,
441 struct Lisp_Char_Table);
443 DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /*
444 Return non-nil if OBJECT is a char table.
446 A char table is a table that maps characters (or ranges of characters)
447 to values. Char tables are specialized for characters, only allowing
448 particular sorts of ranges to be assigned values. Although this
449 loses in generality, it makes for extremely fast (constant-time)
450 lookups, and thus is feasible for applications that do an extremely
451 large number of lookups (e.g. scanning a buffer for a character in
452 a particular syntax, where a lookup in the syntax table must occur
455 When Mule support exists, the types of ranges that can be assigned
460 -- a single row in a two-octet charset
461 -- a single character
463 When Mule support is not present, the types of ranges that can be
467 -- a single character
469 To create a char table, use `make-char-table'. To modify a char
470 table, use `put-char-table' or `remove-char-table'. To retrieve the
471 value for a particular character, use `get-char-table'. See also
472 `map-char-table', `clear-char-table', `copy-char-table',
473 `valid-char-table-type-p', `char-table-type-list', `valid-char-table-value-p',
474 and `check-char-table-value'.
478 return CHAR_TABLEP (object) ? Qt : Qnil;
481 DEFUN ("char-table-type-list", Fchar_table_type_list, 0, 0, 0, /*
482 Return a list of the recognized char table types.
483 See `valid-char-table-type-p'.
488 return list5 (Qchar, Qcategory, Qdisplay, Qgeneric, Qsyntax);
490 return list4 (Qchar, Qdisplay, Qgeneric, Qsyntax);
494 DEFUN ("valid-char-table-type-p", Fvalid_char_table_type_p, 1, 1, 0, /*
495 Return t if TYPE if a recognized char table type.
497 Each char table type is used for a different purpose and allows different
498 sorts of values. The different char table types are
501 Used for category tables, which specify the regexp categories
502 that a character is in. The valid values are nil or a
503 bit vector of 95 elements. Higher-level Lisp functions are
504 provided for working with category tables. Currently categories
505 and category tables only exist when Mule support is present.
507 A generalized char table, for mapping from one character to
508 another. Used for case tables, syntax matching tables,
509 `keyboard-translate-table', etc. The valid values are characters.
511 An even more generalized char table, for mapping from a
512 character to anything.
514 Used for display tables, which specify how a particular character
515 is to appear when displayed. #### Not yet implemented.
517 Used for syntax tables, which specify the syntax of a particular
518 character. Higher-level Lisp functions are provided for
519 working with syntax tables. The valid values are integers.
524 return (EQ (type, Qchar) ||
526 EQ (type, Qcategory) ||
528 EQ (type, Qdisplay) ||
529 EQ (type, Qgeneric) ||
530 EQ (type, Qsyntax)) ? Qt : Qnil;
533 DEFUN ("char-table-type", Fchar_table_type, 1, 1, 0, /*
534 Return the type of char table TABLE.
535 See `valid-char-table-type-p'.
539 CHECK_CHAR_TABLE (table);
540 return char_table_type_to_symbol (XCHAR_TABLE (table)->type);
544 fill_char_table (struct Lisp_Char_Table *ct, Lisp_Object value)
548 for (i = 0; i < NUM_ASCII_CHARS; i++)
549 ct->ascii[i] = value;
551 for (i = 0; i < NUM_LEADING_BYTES; i++)
552 ct->level1[i] = value;
555 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
556 update_syntax_table (ct);
559 DEFUN ("reset-char-table", Freset_char_table, 1, 1, 0, /*
560 Reset a char table to its default state.
564 struct Lisp_Char_Table *ct;
566 CHECK_CHAR_TABLE (table);
567 ct = XCHAR_TABLE (table);
571 case CHAR_TABLE_TYPE_CHAR:
572 fill_char_table (ct, make_char (0));
574 case CHAR_TABLE_TYPE_DISPLAY:
575 case CHAR_TABLE_TYPE_GENERIC:
577 case CHAR_TABLE_TYPE_CATEGORY:
579 fill_char_table (ct, Qnil);
582 case CHAR_TABLE_TYPE_SYNTAX:
583 fill_char_table (ct, make_int (Sinherit));
593 DEFUN ("make-char-table", Fmake_char_table, 1, 1, 0, /*
594 Return a new, empty char table of type TYPE.
595 Currently recognized types are 'char, 'category, 'display, 'generic,
596 and 'syntax. See `valid-char-table-type-p'.
600 struct Lisp_Char_Table *ct;
602 enum char_table_type ty = symbol_to_char_table_type (type);
604 ct = alloc_lcrecord_type (struct Lisp_Char_Table, &lrecord_char_table);
606 if (ty == CHAR_TABLE_TYPE_SYNTAX)
608 ct->mirror_table = Fmake_char_table (Qgeneric);
609 fill_char_table (XCHAR_TABLE (ct->mirror_table),
613 ct->mirror_table = Qnil;
614 ct->next_table = Qnil;
615 XSETCHAR_TABLE (obj, ct);
616 if (ty == CHAR_TABLE_TYPE_SYNTAX)
618 ct->next_table = Vall_syntax_tables;
619 Vall_syntax_tables = obj;
621 Freset_char_table (obj);
628 make_char_table_entry (Lisp_Object initval)
632 struct Lisp_Char_Table_Entry *cte =
633 alloc_lcrecord_type (struct Lisp_Char_Table_Entry,
634 &lrecord_char_table_entry);
636 for (i = 0; i < 96; i++)
637 cte->level2[i] = initval;
639 XSETCHAR_TABLE_ENTRY (obj, cte);
644 copy_char_table_entry (Lisp_Object entry)
646 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
649 struct Lisp_Char_Table_Entry *ctenew =
650 alloc_lcrecord_type (struct Lisp_Char_Table_Entry,
651 &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 Make a new char table which is a copy of OLD-TABLE.
670 It will contain the same values for the same characters and ranges
671 as OLD-TABLE. The values will not themselves be copied.
675 struct Lisp_Char_Table *ct, *ctnew;
679 CHECK_CHAR_TABLE (old_table);
680 ct = XCHAR_TABLE (old_table);
681 ctnew = alloc_lcrecord_type (struct 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 XSETCHAR_TABLE (obj, ctnew);
715 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange)
718 outrange->type = CHARTAB_RANGE_ALL;
719 else if (CHAR_OR_CHAR_INTP (range))
721 outrange->type = CHARTAB_RANGE_CHAR;
722 outrange->ch = XCHAR_OR_CHAR_INT (range);
726 signal_simple_error ("Range must be t or a character", range);
728 else if (VECTORP (range))
730 struct Lisp_Vector *vec = XVECTOR (range);
731 Lisp_Object *elts = vector_data (vec);
732 if (vector_length (vec) != 2)
733 signal_simple_error ("Length of charset row vector must be 2",
735 outrange->type = CHARTAB_RANGE_ROW;
736 outrange->charset = Fget_charset (elts[0]);
738 outrange->row = XINT (elts[1]);
739 switch (XCHARSET_TYPE (outrange->charset))
741 case CHARSET_TYPE_94:
742 case CHARSET_TYPE_96:
743 signal_simple_error ("Charset in row vector must be multi-byte",
745 case CHARSET_TYPE_94X94:
746 check_int_range (outrange->row, 33, 126);
748 case CHARSET_TYPE_96X96:
749 check_int_range (outrange->row, 32, 127);
757 if (!CHARSETP (range) && !SYMBOLP (range))
759 ("Char table range must be t, charset, char, or vector", range);
760 outrange->type = CHARTAB_RANGE_CHARSET;
761 outrange->charset = Fget_charset (range);
768 /* called from CHAR_TABLE_VALUE(). */
770 get_non_ascii_char_table_value (struct Lisp_Char_Table *ct,
771 Charset_ID leading_byte, Emchar c)
777 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (leading_byte);
782 BREAKUP_CHAR (c, charset, byte1, byte2);
784 BREAKUP_CHAR_1_UNSAFE (c, charset, byte1, byte2);
786 val = ct->level1[leading_byte - MIN_LEADING_BYTE];
787 if (CHAR_TABLE_ENTRYP (val))
789 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
790 val = cte->level2[byte1 - 32];
791 if (CHAR_TABLE_ENTRYP (val))
793 cte = XCHAR_TABLE_ENTRY (val);
794 assert (byte2 >= 32);
795 val = cte->level2[byte2 - 32];
796 assert (!CHAR_TABLE_ENTRYP (val));
806 get_char_table (Emchar ch, struct Lisp_Char_Table *ct)
814 BREAKUP_CHAR (ch, charset, byte1, byte2);
816 if (EQ (charset, Vcharset_ascii))
817 val = ct->ascii[byte1];
818 else if (EQ (charset, Vcharset_control_1))
819 val = ct->ascii[byte1 + 128];
822 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
823 val = ct->level1[lb];
824 if (CHAR_TABLE_ENTRYP (val))
826 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
827 val = cte->level2[byte1 - 32];
828 if (CHAR_TABLE_ENTRYP (val))
830 cte = XCHAR_TABLE_ENTRY (val);
831 assert (byte2 >= 32);
832 val = cte->level2[byte2 - 32];
833 assert (!CHAR_TABLE_ENTRYP (val));
841 return ct->ascii[(unsigned char)ch];
842 #endif /* not MULE */
846 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
847 Find value for char CH in TABLE.
851 struct Lisp_Char_Table *ct;
853 CHECK_CHAR_TABLE (table);
854 ct = XCHAR_TABLE (table);
855 CHECK_CHAR_COERCE_INT (ch);
857 return get_char_table (XCHAR (ch), ct);
860 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
861 Find value for a range in TABLE.
862 If there is more than one value, return MULTI (defaults to nil).
864 (range, table, multi))
866 struct Lisp_Char_Table *ct;
867 struct chartab_range rainj;
869 if (CHAR_OR_CHAR_INTP (range))
870 return Fget_char_table (range, table);
871 CHECK_CHAR_TABLE (table);
872 ct = XCHAR_TABLE (table);
874 decode_char_table_range (range, &rainj);
877 case CHARTAB_RANGE_ALL:
880 Lisp_Object first = ct->ascii[0];
882 for (i = 1; i < NUM_ASCII_CHARS; i++)
883 if (!EQ (first, ct->ascii[i]))
887 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
890 if (!CHARSETP (CHARSET_BY_LEADING_BYTE (i))
891 || i == LEADING_BYTE_ASCII
892 || i == LEADING_BYTE_CONTROL_1)
894 if (!EQ (first, ct->level1[i - MIN_LEADING_BYTE]))
903 case CHARTAB_RANGE_CHARSET:
904 if (EQ (rainj.charset, Vcharset_ascii))
907 Lisp_Object first = ct->ascii[0];
909 for (i = 1; i < 128; i++)
910 if (!EQ (first, ct->ascii[i]))
915 if (EQ (rainj.charset, Vcharset_control_1))
918 Lisp_Object first = ct->ascii[128];
920 for (i = 129; i < 160; i++)
921 if (!EQ (first, ct->ascii[i]))
927 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
929 if (CHAR_TABLE_ENTRYP (val))
934 case CHARTAB_RANGE_ROW:
936 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
938 if (!CHAR_TABLE_ENTRYP (val))
940 val = XCHAR_TABLE_ENTRY (val)->level2[rainj.row - 32];
941 if (CHAR_TABLE_ENTRYP (val))
945 #endif /* not MULE */
951 return Qnil; /* not reached */
955 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
960 case CHAR_TABLE_TYPE_SYNTAX:
961 if (!ERRB_EQ (errb, ERROR_ME))
962 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
963 && CHAR_OR_CHAR_INTP (XCDR (value)));
966 Lisp_Object cdr = XCDR (value);
967 CHECK_INT (XCAR (value));
968 CHECK_CHAR_COERCE_INT (cdr);
975 case CHAR_TABLE_TYPE_CATEGORY:
976 if (!ERRB_EQ (errb, ERROR_ME))
977 return CATEGORY_TABLE_VALUEP (value);
978 CHECK_CATEGORY_TABLE_VALUE (value);
982 case CHAR_TABLE_TYPE_GENERIC:
985 case CHAR_TABLE_TYPE_DISPLAY:
987 maybe_signal_simple_error ("Display char tables not yet implemented",
988 value, Qchar_table, errb);
991 case CHAR_TABLE_TYPE_CHAR:
992 if (!ERRB_EQ (errb, ERROR_ME))
993 return CHAR_OR_CHAR_INTP (value);
994 CHECK_CHAR_COERCE_INT (value);
1001 return 0; /* not reached */
1005 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
1009 case CHAR_TABLE_TYPE_SYNTAX:
1012 Lisp_Object car = XCAR (value);
1013 Lisp_Object cdr = XCDR (value);
1014 CHECK_CHAR_COERCE_INT (cdr);
1015 return Fcons (car, cdr);
1018 case CHAR_TABLE_TYPE_CHAR:
1019 CHECK_CHAR_COERCE_INT (value);
1027 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
1028 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
1030 (value, char_table_type))
1032 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1034 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
1037 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
1038 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
1040 (value, char_table_type))
1042 enum char_table_type type = symbol_to_char_table_type (char_table_type);
1044 check_valid_char_table_value (value, type, ERROR_ME);
1048 /* Assign VAL to all characters in RANGE in char table CT. */
1051 put_char_table (struct Lisp_Char_Table *ct, struct chartab_range *range,
1054 switch (range->type)
1056 case CHARTAB_RANGE_ALL:
1057 fill_char_table (ct, val);
1058 return; /* avoid the duplicate call to update_syntax_table() below,
1059 since fill_char_table() also did that. */
1062 case CHARTAB_RANGE_CHARSET:
1063 if (EQ (range->charset, Vcharset_ascii))
1066 for (i = 0; i < 128; i++)
1069 else if (EQ (range->charset, Vcharset_control_1))
1072 for (i = 128; i < 160; i++)
1077 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1078 ct->level1[lb] = val;
1082 case CHARTAB_RANGE_ROW:
1084 struct Lisp_Char_Table_Entry *cte;
1085 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
1086 /* make sure that there is a separate entry for the row. */
1087 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1088 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1089 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1090 cte->level2[range->row - 32] = val;
1095 case CHARTAB_RANGE_CHAR:
1098 Lisp_Object charset;
1101 BREAKUP_CHAR (range->ch, charset, byte1, byte2);
1102 if (EQ (charset, Vcharset_ascii))
1103 ct->ascii[byte1] = val;
1104 else if (EQ (charset, Vcharset_control_1))
1105 ct->ascii[byte1 + 128] = val;
1108 struct Lisp_Char_Table_Entry *cte;
1109 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
1110 /* make sure that there is a separate entry for the row. */
1111 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
1112 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
1113 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
1114 /* now CTE is a char table entry for the charset;
1115 each entry is for a single row (or character of
1116 a one-octet charset). */
1117 if (XCHARSET_DIMENSION (charset) == 1)
1118 cte->level2[byte1 - 32] = val;
1121 /* assigning to one character in a two-octet charset. */
1122 /* make sure that the charset row contains a separate
1123 entry for each character. */
1124 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
1125 cte->level2[byte1 - 32] =
1126 make_char_table_entry (cte->level2[byte1 - 32]);
1127 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
1128 cte->level2[byte2 - 32] = val;
1132 #else /* not MULE */
1133 ct->ascii[(unsigned char) (range->ch)] = val;
1135 #endif /* not MULE */
1138 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
1139 update_syntax_table (ct);
1142 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
1143 Set the value for chars in RANGE to be VAL in TABLE.
1145 RANGE specifies one or more characters to be affected and should be
1146 one of the following:
1148 -- t (all characters are affected)
1149 -- A charset (only allowed when Mule support is present)
1150 -- A vector of two elements: a two-octet charset and a row number
1151 (only allowed when Mule support is present)
1152 -- A single character
1154 VAL must be a value appropriate for the type of TABLE.
1155 See `valid-char-table-type-p'.
1157 (range, val, table))
1159 struct Lisp_Char_Table *ct;
1160 struct chartab_range rainj;
1162 CHECK_CHAR_TABLE (table);
1163 ct = XCHAR_TABLE (table);
1164 check_valid_char_table_value (val, ct->type, ERROR_ME);
1165 decode_char_table_range (range, &rainj);
1166 val = canonicalize_char_table_value (val, ct->type);
1167 put_char_table (ct, &rainj, val);
1171 /* Map FN over the ASCII chars in CT. */
1174 map_over_charset_ascii (struct Lisp_Char_Table *ct,
1175 int (*fn) (struct chartab_range *range,
1176 Lisp_Object val, void *arg),
1179 struct chartab_range rainj;
1188 rainj.type = CHARTAB_RANGE_CHAR;
1190 for (i = start, retval = 0; i < stop && retval == 0; i++)
1192 rainj.ch = (Emchar) i;
1193 retval = (fn) (&rainj, ct->ascii[i], arg);
1201 /* Map FN over the Control-1 chars in CT. */
1204 map_over_charset_control_1 (struct Lisp_Char_Table *ct,
1205 int (*fn) (struct chartab_range *range,
1206 Lisp_Object val, void *arg),
1209 struct chartab_range rainj;
1212 int stop = start + 32;
1214 rainj.type = CHARTAB_RANGE_CHAR;
1216 for (i = start, retval = 0; i < stop && retval == 0; i++)
1218 rainj.ch = (Emchar) (i);
1219 retval = (fn) (&rainj, ct->ascii[i], arg);
1225 /* Map FN over the row ROW of two-byte charset CHARSET.
1226 There must be a separate value for that row in the char table.
1227 CTE specifies the char table entry for CHARSET. */
1230 map_over_charset_row (struct Lisp_Char_Table_Entry *cte,
1231 Lisp_Object charset, int row,
1232 int (*fn) (struct chartab_range *range,
1233 Lisp_Object val, void *arg),
1236 Lisp_Object val = cte->level2[row - 32];
1238 if (!CHAR_TABLE_ENTRYP (val))
1240 struct chartab_range rainj;
1242 rainj.type = CHARTAB_RANGE_ROW;
1243 rainj.charset = charset;
1245 return (fn) (&rainj, val, arg);
1249 struct chartab_range rainj;
1251 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1252 int start = charset94_p ? 33 : 32;
1253 int stop = charset94_p ? 127 : 128;
1255 cte = XCHAR_TABLE_ENTRY (val);
1257 rainj.type = CHARTAB_RANGE_CHAR;
1259 for (i = start, retval = 0; i < stop && retval == 0; i++)
1261 rainj.ch = MAKE_CHAR (charset, row, i);
1262 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1270 map_over_other_charset (struct Lisp_Char_Table *ct, Charset_ID lb,
1271 int (*fn) (struct chartab_range *range,
1272 Lisp_Object val, void *arg),
1275 Lisp_Object val = ct->level1[lb - MIN_LEADING_BYTE];
1276 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (lb);
1278 if (!CHARSETP (charset)
1279 || lb == LEADING_BYTE_ASCII
1280 || lb == LEADING_BYTE_CONTROL_1)
1283 if (!CHAR_TABLE_ENTRYP (val))
1285 struct chartab_range rainj;
1287 rainj.type = CHARTAB_RANGE_CHARSET;
1288 rainj.charset = charset;
1289 return (fn) (&rainj, val, arg);
1293 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
1294 int charset94_p = (XCHARSET_CHARS (charset) == 94);
1295 int start = charset94_p ? 33 : 32;
1296 int stop = charset94_p ? 127 : 128;
1299 if (XCHARSET_DIMENSION (charset) == 1)
1301 struct chartab_range rainj;
1302 rainj.type = CHARTAB_RANGE_CHAR;
1304 for (i = start, retval = 0; i < stop && retval == 0; i++)
1306 rainj.ch = MAKE_CHAR (charset, i, 0);
1307 retval = (fn) (&rainj, cte->level2[i - 32], arg);
1312 for (i = start, retval = 0; i < stop && retval == 0; i++)
1313 retval = map_over_charset_row (cte, charset, i, fn, arg);
1322 /* Map FN (with client data ARG) over range RANGE in char table CT.
1323 Mapping stops the first time FN returns non-zero, and that value
1324 becomes the return value of map_char_table(). */
1327 map_char_table (struct Lisp_Char_Table *ct,
1328 struct chartab_range *range,
1329 int (*fn) (struct chartab_range *range,
1330 Lisp_Object val, void *arg),
1333 switch (range->type)
1335 case CHARTAB_RANGE_ALL:
1339 retval = map_over_charset_ascii (ct, fn, arg);
1343 retval = map_over_charset_control_1 (ct, fn, arg);
1348 Charset_ID start = MIN_LEADING_BYTE;
1349 Charset_ID stop = start + NUM_LEADING_BYTES;
1351 for (i = start, retval = 0; i < stop && retval == 0; i++)
1353 retval = map_over_other_charset (ct, i, fn, arg);
1361 case CHARTAB_RANGE_CHARSET:
1362 return map_over_other_charset (ct,
1363 XCHARSET_LEADING_BYTE (range->charset),
1366 case CHARTAB_RANGE_ROW:
1368 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset)
1369 - MIN_LEADING_BYTE];
1370 if (!CHAR_TABLE_ENTRYP (val))
1372 struct chartab_range rainj;
1374 rainj.type = CHARTAB_RANGE_ROW;
1375 rainj.charset = range->charset;
1376 rainj.row = range->row;
1377 return (fn) (&rainj, val, arg);
1380 return map_over_charset_row (XCHAR_TABLE_ENTRY (val),
1381 range->charset, range->row,
1386 case CHARTAB_RANGE_CHAR:
1388 Emchar ch = range->ch;
1389 Lisp_Object val = CHAR_TABLE_VALUE_UNSAFE (ct, ch);
1390 struct chartab_range rainj;
1392 rainj.type = CHARTAB_RANGE_CHAR;
1394 return (fn) (&rainj, val, arg);
1404 struct slow_map_char_table_arg
1406 Lisp_Object function;
1411 slow_map_char_table_fun (struct chartab_range *range,
1412 Lisp_Object val, void *arg)
1414 Lisp_Object ranjarg = Qnil;
1415 struct slow_map_char_table_arg *closure =
1416 (struct slow_map_char_table_arg *) arg;
1418 switch (range->type)
1420 case CHARTAB_RANGE_ALL:
1425 case CHARTAB_RANGE_CHARSET:
1426 ranjarg = XCHARSET_NAME (range->charset);
1429 case CHARTAB_RANGE_ROW:
1430 ranjarg = vector2 (XCHARSET_NAME (range->charset),
1431 make_int (range->row));
1434 case CHARTAB_RANGE_CHAR:
1435 ranjarg = make_char (range->ch);
1441 closure->retval = call2 (closure->function, ranjarg, val);
1442 return !NILP (closure->retval);
1445 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
1446 Map FUNCTION over entries in TABLE, calling it with two args,
1447 each key and value in the table.
1449 RANGE specifies a subrange to map over and is in the same format as
1450 the RANGE argument to `put-range-table'. If omitted or t, it defaults to
1453 (function, table, range))
1455 struct Lisp_Char_Table *ct;
1456 struct slow_map_char_table_arg slarg;
1457 struct gcpro gcpro1, gcpro2;
1458 struct chartab_range rainj;
1460 CHECK_CHAR_TABLE (table);
1461 ct = XCHAR_TABLE (table);
1464 decode_char_table_range (range, &rainj);
1465 slarg.function = function;
1466 slarg.retval = Qnil;
1467 GCPRO2 (slarg.function, slarg.retval);
1468 map_char_table (ct, &rainj, slow_map_char_table_fun, &slarg);
1471 return slarg.retval;
1476 /************************************************************************/
1477 /* Char table read syntax */
1478 /************************************************************************/
1481 chartab_type_validate (Lisp_Object keyword, Lisp_Object value,
1482 Error_behavior errb)
1484 /* #### should deal with ERRB */
1485 symbol_to_char_table_type (value);
1490 chartab_data_validate (Lisp_Object keyword, Lisp_Object value,
1491 Error_behavior errb)
1495 /* #### should deal with ERRB */
1496 EXTERNAL_LIST_LOOP (rest, value)
1498 Lisp_Object range = XCAR (rest);
1499 struct chartab_range dummy;
1503 signal_simple_error ("Invalid list format", value);
1506 if (!CONSP (XCDR (range))
1507 || !NILP (XCDR (XCDR (range))))
1508 signal_simple_error ("Invalid range format", range);
1509 decode_char_table_range (XCAR (range), &dummy);
1510 decode_char_table_range (XCAR (XCDR (range)), &dummy);
1513 decode_char_table_range (range, &dummy);
1520 chartab_instantiate (Lisp_Object data)
1522 Lisp_Object chartab;
1523 Lisp_Object type = Qgeneric;
1524 Lisp_Object dataval = Qnil;
1526 while (!NILP (data))
1528 Lisp_Object keyw = Fcar (data);
1534 if (EQ (keyw, Qtype))
1536 else if (EQ (keyw, Qdata))
1540 chartab = Fmake_char_table (type);
1543 while (!NILP (data))
1545 Lisp_Object range = Fcar (data);
1546 Lisp_Object val = Fcar (Fcdr (data));
1548 data = Fcdr (Fcdr (data));
1551 if (CHAR_OR_CHAR_INTP (XCAR (range)))
1553 Emchar first = XCHAR_OR_CHAR_INT (Fcar (range));
1554 Emchar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
1557 for (i = first; i <= last; i++)
1558 Fput_char_table (make_char (i), val, chartab);
1564 Fput_char_table (range, val, chartab);
1573 /************************************************************************/
1574 /* Category Tables, specifically */
1575 /************************************************************************/
1577 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
1578 Return t if ARG is a category table.
1579 A category table is a type of char table used for keeping track of
1580 categories. Categories are used for classifying characters for use
1581 in regexps -- you can refer to a category rather than having to use
1582 a complicated [] expression (and category lookups are significantly
1585 There are 95 different categories available, one for each printable
1586 character (including space) in the ASCII charset. Each category
1587 is designated by one such character, called a "category designator".
1588 They are specified in a regexp using the syntax "\\cX", where X is
1589 a category designator.
1591 A category table specifies, for each character, the categories that
1592 the character is in. Note that a character can be in more than one
1593 category. More specifically, a category table maps from a character
1594 to either the value nil (meaning the character is in no categories)
1595 or a 95-element bit vector, specifying for each of the 95 categories
1596 whether the character is in that category.
1598 Special Lisp functions are provided that abstract this, so you do not
1599 have to directly manipulate bit vectors.
1603 return (CHAR_TABLEP (obj) &&
1604 XCHAR_TABLE_TYPE (obj) == CHAR_TABLE_TYPE_CATEGORY) ?
1609 check_category_table (Lisp_Object obj, Lisp_Object def)
1613 while (NILP (Fcategory_table_p (obj)))
1614 obj = wrong_type_argument (Qcategory_table_p, obj);
1619 check_category_char (Emchar ch, Lisp_Object table,
1620 unsigned int designator, unsigned int not)
1622 REGISTER Lisp_Object temp;
1623 struct Lisp_Char_Table *ctbl;
1624 #ifdef ERROR_CHECK_TYPECHECK
1625 if (NILP (Fcategory_table_p (table)))
1626 signal_simple_error ("Expected category table", table);
1628 ctbl = XCHAR_TABLE (table);
1629 temp = get_char_table (ch, ctbl);
1634 return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not : not;
1637 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
1638 Return t if category of a character at POS includes DESIGNATOR,
1639 else return nil. Optional third arg specifies which buffer
1640 \(defaulting to current), and fourth specifies the CATEGORY-TABLE,
1641 \(defaulting to the buffer's category table).
1643 (pos, designator, buffer, category_table))
1648 struct buffer *buf = decode_buffer (buffer, 0);
1651 CHECK_CATEGORY_DESIGNATOR (designator);
1652 des = XCHAR (designator);
1653 ctbl = check_category_table (category_table, Vstandard_category_table);
1654 ch = BUF_FETCH_CHAR (buf, XINT (pos));
1655 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1658 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
1659 Return t if category of character CHR includes DESIGNATOR, else nil.
1660 Optional third arg specifies the CATEGORY-TABLE to use,
1661 which defaults to the system default table.
1663 (chr, designator, category_table))
1669 CHECK_CATEGORY_DESIGNATOR (designator);
1670 des = XCHAR (designator);
1673 ctbl = check_category_table (category_table, Vstandard_category_table);
1674 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
1677 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
1678 Return the current category table.
1679 This is the one specified by the current buffer, or by BUFFER if it
1684 return decode_buffer (buffer, 0)->category_table;
1687 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
1688 Return the standard category table.
1689 This is the one used for new buffers.
1693 return Vstandard_category_table;
1696 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
1697 Construct a new category table and return it.
1698 It is a copy of the TABLE, which defaults to the standard category table.
1702 if (NILP (Vstandard_category_table))
1703 return Fmake_char_table (Qcategory);
1705 table = check_category_table (table, Vstandard_category_table);
1706 return Fcopy_char_table (table);
1709 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
1710 Select a new category table for BUFFER.
1711 One argument, a category table.
1712 BUFFER defaults to the current buffer if omitted.
1716 struct buffer *buf = decode_buffer (buffer, 0);
1717 table = check_category_table (table, Qnil);
1718 buf->category_table = table;
1719 /* Indicate that this buffer now has a specified category table. */
1720 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
1724 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
1725 Return t if ARG is a category designator (a char in the range ' ' to '~').
1729 return CATEGORY_DESIGNATORP (obj) ? Qt : Qnil;
1732 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
1733 Return t if ARG is a category table value.
1734 Valid values are nil or a bit vector of size 95.
1738 return CATEGORY_TABLE_VALUEP (obj) ? Qt : Qnil;
1742 #define CATEGORYP(x) \
1743 (CHARP ((x)) && XCHAR ((x)) >= 0x20 && XCHAR ((x)) <= 0x7E)
1745 #define CATEGORY_SET(c) \
1746 (get_char_table(c, XCHAR_TABLE(current_buffer->category_table)))
1748 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0.
1749 The faster version of `!NILP (Faref (category_set, category))'. */
1750 #define CATEGORY_MEMBER(category, category_set) \
1751 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32))
1753 /* Return 1 if there is a word boundary between two word-constituent
1754 characters C1 and C2 if they appear in this order, else return 0.
1755 Use the macro WORD_BOUNDARY_P instead of calling this function
1759 word_boundary_p (Emchar c1, Emchar c2)
1761 Lisp_Object category_set1, category_set2;
1766 if (COMPOSITE_CHAR_P (c1))
1767 c1 = cmpchar_component (c1, 0, 1);
1768 if (COMPOSITE_CHAR_P (c2))
1769 c2 = cmpchar_component (c2, 0, 1);
1772 if (EQ (CHAR_CHARSET (c1), CHAR_CHARSET (c2)))
1774 tail = Vword_separating_categories;
1779 tail = Vword_combining_categories;
1783 category_set1 = CATEGORY_SET (c1);
1784 if (NILP (category_set1))
1785 return default_result;
1786 category_set2 = CATEGORY_SET (c2);
1787 if (NILP (category_set2))
1788 return default_result;
1790 for (; CONSP (tail); tail = XCONS (tail)->cdr)
1792 Lisp_Object elt = XCONS(tail)->car;
1795 && CATEGORYP (XCONS (elt)->car)
1796 && CATEGORYP (XCONS (elt)->cdr)
1797 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->car), category_set1)
1798 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->cdr), category_set2))
1799 return !default_result;
1801 return default_result;
1807 syms_of_chartab (void)
1810 defsymbol (&Qcategory_table_p, "category-table-p");
1811 defsymbol (&Qcategory_designator_p, "category-designator-p");
1812 defsymbol (&Qcategory_table_value_p, "category-table-value-p");
1815 defsymbol (&Qchar_table, "char-table");
1816 defsymbol (&Qchar_tablep, "char-table-p");
1818 DEFSUBR (Fchar_table_p);
1819 DEFSUBR (Fchar_table_type_list);
1820 DEFSUBR (Fvalid_char_table_type_p);
1821 DEFSUBR (Fchar_table_type);
1822 DEFSUBR (Freset_char_table);
1823 DEFSUBR (Fmake_char_table);
1824 DEFSUBR (Fcopy_char_table);
1825 DEFSUBR (Fget_char_table);
1826 DEFSUBR (Fget_range_char_table);
1827 DEFSUBR (Fvalid_char_table_value_p);
1828 DEFSUBR (Fcheck_valid_char_table_value);
1829 DEFSUBR (Fput_char_table);
1830 DEFSUBR (Fmap_char_table);
1833 DEFSUBR (Fcategory_table_p);
1834 DEFSUBR (Fcategory_table);
1835 DEFSUBR (Fstandard_category_table);
1836 DEFSUBR (Fcopy_category_table);
1837 DEFSUBR (Fset_category_table);
1838 DEFSUBR (Fcheck_category_at);
1839 DEFSUBR (Fchar_in_category_p);
1840 DEFSUBR (Fcategory_designator_p);
1841 DEFSUBR (Fcategory_table_value_p);
1847 vars_of_chartab (void)
1849 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
1850 Vall_syntax_tables = Qnil;
1854 structure_type_create_chartab (void)
1856 struct structure_type *st;
1858 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
1860 define_structure_type_keyword (st, Qtype, chartab_type_validate);
1861 define_structure_type_keyword (st, Qdata, chartab_data_validate);
1865 complex_vars_of_chartab (void)
1868 /* Set this now, so first buffer creation can refer to it. */
1869 /* Make it nil before calling copy-category-table
1870 so that copy-category-table will know not to try to copy from garbage */
1871 Vstandard_category_table = Qnil;
1872 Vstandard_category_table = Fcopy_category_table (Qnil);
1873 staticpro (&Vstandard_category_table);
1875 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /*
1876 List of pair (cons) of categories to determine word boundary.
1878 Emacs treats a sequence of word constituent characters as a single
1879 word (i.e. finds no word boundary between them) iff they belongs to
1880 the same charset. But, exceptions are allowed in the following cases.
1882 (1) The case that characters are in different charsets is controlled
1883 by the variable `word-combining-categories'.
1885 Emacs finds no word boundary between characters of different charsets
1886 if they have categories matching some element of this list.
1888 More precisely, if an element of this list is a cons of category CAT1
1889 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1890 C2 which has CAT2, there's no word boundary between C1 and C2.
1892 For instance, to tell that ASCII characters and Latin-1 characters can
1893 form a single word, the element `(?l . ?l)' should be in this list
1894 because both characters have the category `l' (Latin characters).
1896 (2) The case that character are in the same charset is controlled by
1897 the variable `word-separating-categories'.
1899 Emacs find a word boundary between characters of the same charset
1900 if they have categories matching some element of this list.
1902 More precisely, if an element of this list is a cons of category CAT1
1903 and CAT2, and a multibyte character C1 which has CAT1 is followed by
1904 C2 which has CAT2, there's a word boundary between C1 and C2.
1906 For instance, to tell that there's a word boundary between Japanese
1907 Hiragana and Japanese Kanji (both are in the same charset), the
1908 element `(?H . ?C) should be in this list.
1911 Vword_combining_categories = Qnil;
1913 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /*
1914 List of pair (cons) of categories to determine word boundary.
1915 See the documentation of the variable `word-combining-categories'.
1918 Vword_separating_categories = Qnil;