Mercurial > hg > xemacs-beta
comparison src/chartab.c @ 420:41dbb7a9d5f2 r21-2-18
Import from CVS: tag r21-2-18
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:24:09 +0200 |
parents | da8ed4261e83 |
children | 11054d720c21 |
comparison
equal
deleted
inserted
replaced
419:66615b78f1a5 | 420:41dbb7a9d5f2 |
---|---|
1 /* XEmacs routines to deal with char tables. | 1 /* XEmacs routines to deal with char tables. |
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc. | 2 Copyright (C) 1992, 1995 Free Software Foundation, Inc. |
3 Copyright (C) 1995 Sun Microsystems, Inc. | 3 Copyright (C) 1995 Sun Microsystems, Inc. |
4 Copyright (C) 1995, 1996 Ben Wing. | 4 Copyright (C) 1995, 1996 Ben Wing. |
5 Copyright (C) 1995, 1997, 1999 Electrotechnical Laboratory, JAPAN. | |
6 Licensed to the Free Software Foundation. | |
5 | 7 |
6 This file is part of XEmacs. | 8 This file is part of XEmacs. |
7 | 9 |
8 XEmacs is free software; you can redistribute it and/or modify it | 10 XEmacs is free software; you can redistribute it and/or modify it |
9 under the terms of the GNU General Public License as published by the | 11 under the terms of the GNU General Public License as published by the |
48 Lisp_Object Qcategory_table_p; | 50 Lisp_Object Qcategory_table_p; |
49 Lisp_Object Qcategory_designator_p; | 51 Lisp_Object Qcategory_designator_p; |
50 Lisp_Object Qcategory_table_value_p; | 52 Lisp_Object Qcategory_table_value_p; |
51 | 53 |
52 Lisp_Object Vstandard_category_table; | 54 Lisp_Object Vstandard_category_table; |
55 | |
56 /* Variables to determine word boundary. */ | |
57 Lisp_Object Vword_combining_categories, Vword_separating_categories; | |
53 #endif /* MULE */ | 58 #endif /* MULE */ |
54 | 59 |
55 | 60 |
56 /* A char table maps from ranges of characters to values. | 61 /* A char table maps from ranges of characters to values. |
57 | 62 |
122 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj); | 127 struct Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj); |
123 | 128 |
124 return internal_array_hash (cte->level2, 96, depth); | 129 return internal_array_hash (cte->level2, 96, depth); |
125 } | 130 } |
126 | 131 |
132 static const struct lrecord_description char_table_entry_description[] = { | |
133 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table_Entry, level2), 96 }, | |
134 { XD_END } | |
135 }; | |
136 | |
127 DEFINE_LRECORD_IMPLEMENTATION ("char-table-entry", char_table_entry, | 137 DEFINE_LRECORD_IMPLEMENTATION ("char-table-entry", char_table_entry, |
128 mark_char_table_entry, internal_object_printer, | 138 mark_char_table_entry, internal_object_printer, |
129 0, char_table_entry_equal, | 139 0, char_table_entry_equal, |
130 char_table_entry_hash, | 140 char_table_entry_hash, |
141 char_table_entry_description, | |
131 struct Lisp_Char_Table_Entry); | 142 struct Lisp_Char_Table_Entry); |
132 #endif /* MULE */ | 143 #endif /* MULE */ |
133 | 144 |
134 static Lisp_Object | 145 static Lisp_Object |
135 mark_char_table (Lisp_Object obj, void (*markobj) (Lisp_Object)) | 146 mark_char_table (Lisp_Object obj, void (*markobj) (Lisp_Object)) |
413 internal_array_hash (ct->level1, NUM_LEADING_BYTES, depth)); | 424 internal_array_hash (ct->level1, NUM_LEADING_BYTES, depth)); |
414 #endif /* MULE */ | 425 #endif /* MULE */ |
415 return hashval; | 426 return hashval; |
416 } | 427 } |
417 | 428 |
429 static const struct lrecord_description char_table_description[] = { | |
430 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table, ascii), NUM_ASCII_CHARS }, | |
431 #ifdef MULE | |
432 { XD_LISP_OBJECT, offsetof(struct Lisp_Char_Table, level1), NUM_LEADING_BYTES }, | |
433 #endif | |
434 { XD_END } | |
435 }; | |
436 | |
418 DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table, | 437 DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table, |
419 mark_char_table, print_char_table, 0, | 438 mark_char_table, print_char_table, 0, |
420 char_table_equal, char_table_hash, | 439 char_table_equal, char_table_hash, |
440 char_table_description, | |
421 struct Lisp_Char_Table); | 441 struct Lisp_Char_Table); |
422 | 442 |
423 DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /* | 443 DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /* |
424 Return non-nil if OBJECT is a char table. | 444 Return non-nil if OBJECT is a char table. |
425 | 445 |
1707 (obj)) | 1727 (obj)) |
1708 { | 1728 { |
1709 return CATEGORY_TABLE_VALUEP (obj) ? Qt : Qnil; | 1729 return CATEGORY_TABLE_VALUEP (obj) ? Qt : Qnil; |
1710 } | 1730 } |
1711 | 1731 |
1732 | |
1733 #define CATEGORYP(x) \ | |
1734 (CHARP ((x)) && XCHAR ((x)) >= 0x20 && XCHAR ((x)) <= 0x7E) | |
1735 | |
1736 #define CATEGORY_SET(c) \ | |
1737 (get_char_table(c, XCHAR_TABLE(current_buffer->category_table))) | |
1738 | |
1739 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0. | |
1740 The faster version of `!NILP (Faref (category_set, category))'. */ | |
1741 #define CATEGORY_MEMBER(category, category_set) \ | |
1742 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32)) | |
1743 | |
1744 /* Return 1 if there is a word boundary between two word-constituent | |
1745 characters C1 and C2 if they appear in this order, else return 0. | |
1746 Use the macro WORD_BOUNDARY_P instead of calling this function | |
1747 directly. */ | |
1748 | |
1749 int | |
1750 word_boundary_p (Emchar c1, Emchar c2) | |
1751 { | |
1752 Lisp_Object category_set1, category_set2; | |
1753 Lisp_Object tail; | |
1754 int default_result; | |
1755 | |
1756 #if 0 | |
1757 if (COMPOSITE_CHAR_P (c1)) | |
1758 c1 = cmpchar_component (c1, 0, 1); | |
1759 if (COMPOSITE_CHAR_P (c2)) | |
1760 c2 = cmpchar_component (c2, 0, 1); | |
1761 #endif | |
1762 | |
1763 if (EQ (CHAR_CHARSET (c1), CHAR_CHARSET (c2))) | |
1764 { | |
1765 tail = Vword_separating_categories; | |
1766 default_result = 0; | |
1767 } | |
1768 else | |
1769 { | |
1770 tail = Vword_combining_categories; | |
1771 default_result = 1; | |
1772 } | |
1773 | |
1774 category_set1 = CATEGORY_SET (c1); | |
1775 if (NILP (category_set1)) | |
1776 return default_result; | |
1777 category_set2 = CATEGORY_SET (c2); | |
1778 if (NILP (category_set2)) | |
1779 return default_result; | |
1780 | |
1781 for (; CONSP (tail); tail = XCONS (tail)->cdr) | |
1782 { | |
1783 Lisp_Object elt = XCONS(tail)->car; | |
1784 | |
1785 if (CONSP (elt) | |
1786 && CATEGORYP (XCONS (elt)->car) | |
1787 && CATEGORYP (XCONS (elt)->cdr) | |
1788 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->car), category_set1) | |
1789 && CATEGORY_MEMBER (XCHAR (XCONS (elt)->cdr), category_set2)) | |
1790 return !default_result; | |
1791 } | |
1792 return default_result; | |
1793 } | |
1712 #endif /* MULE */ | 1794 #endif /* MULE */ |
1713 | 1795 |
1714 | 1796 |
1715 void | 1797 void |
1716 syms_of_chartab (void) | 1798 syms_of_chartab (void) |
1778 /* Make it nil before calling copy-category-table | 1860 /* Make it nil before calling copy-category-table |
1779 so that copy-category-table will know not to try to copy from garbage */ | 1861 so that copy-category-table will know not to try to copy from garbage */ |
1780 Vstandard_category_table = Qnil; | 1862 Vstandard_category_table = Qnil; |
1781 Vstandard_category_table = Fcopy_category_table (Qnil); | 1863 Vstandard_category_table = Fcopy_category_table (Qnil); |
1782 staticpro (&Vstandard_category_table); | 1864 staticpro (&Vstandard_category_table); |
1783 #endif /* MULE */ | 1865 |
1784 } | 1866 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /* |
1867 List of pair (cons) of categories to determine word boundary. | |
1868 | |
1869 Emacs treats a sequence of word constituent characters as a single | |
1870 word (i.e. finds no word boundary between them) iff they belongs to | |
1871 the same charset. But, exceptions are allowed in the following cases. | |
1872 | |
1873 (1) The case that characters are in different charsets is controlled | |
1874 by the variable `word-combining-categories'. | |
1875 | |
1876 Emacs finds no word boundary between characters of different charsets | |
1877 if they have categories matching some element of this list. | |
1878 | |
1879 More precisely, if an element of this list is a cons of category CAT1 | |
1880 and CAT2, and a multibyte character C1 which has CAT1 is followed by | |
1881 C2 which has CAT2, there's no word boundary between C1 and C2. | |
1882 | |
1883 For instance, to tell that ASCII characters and Latin-1 characters can | |
1884 form a single word, the element `(?l . ?l)' should be in this list | |
1885 because both characters have the category `l' (Latin characters). | |
1886 | |
1887 (2) The case that character are in the same charset is controlled by | |
1888 the variable `word-separating-categories'. | |
1889 | |
1890 Emacs find a word boundary between characters of the same charset | |
1891 if they have categories matching some element of this list. | |
1892 | |
1893 More precisely, if an element of this list is a cons of category CAT1 | |
1894 and CAT2, and a multibyte character C1 which has CAT1 is followed by | |
1895 C2 which has CAT2, there's a word boundary between C1 and C2. | |
1896 | |
1897 For instance, to tell that there's a word boundary between Japanese | |
1898 Hiragana and Japanese Kanji (both are in the same charset), the | |
1899 element `(?H . ?C) should be in this list. | |
1900 */ ); | |
1901 | |
1902 Vword_combining_categories = Qnil; | |
1903 | |
1904 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /* | |
1905 List of pair (cons) of categories to determine word boundary. | |
1906 See the documentation of the variable `word-combining-categories'. | |
1907 */ ); | |
1908 | |
1909 Vword_separating_categories = Qnil; | |
1910 #endif /* MULE */ | |
1911 } |