Mercurial > emacs
annotate src/category.c @ 20776:219fdecc30d3
(internal_equal): Use compare_window_configurations.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 26 Jan 1998 08:47:06 +0000 |
parents | 5a0922f8c841 |
children | 1b98a0ab1bee |
rev | line source |
---|---|
17052 | 1 /* GNU Emacs routines to deal with category tables. |
18341
33e78cc7f058
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
17787
diff
changeset
|
2 Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN. |
33e78cc7f058
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
17787
diff
changeset
|
3 Licensed to the Free Software Foundation. |
17052 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2, or (at your option) | |
10 any later version. | |
11 | |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; see the file COPYING. If not, write to | |
17071 | 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 Boston, MA 02111-1307, USA. */ | |
17052 | 21 |
22 | |
23 /* Here we handle three objects: category, category set, and category | |
24 table. Read comments in the file category.h to understand them. */ | |
25 | |
26 #include <config.h> | |
27 #include <ctype.h> | |
28 #include "lisp.h" | |
29 #include "buffer.h" | |
30 #include "charset.h" | |
31 #include "category.h" | |
32 | |
33 /* The version number of the latest category table. Each category | |
34 table has a unique version number. It is assigned a new number | |
35 also when it is modified. When a regular expression is compiled | |
36 into the struct re_pattern_buffer, the version number of the | |
37 category table (of the current buffer) at that moment is also | |
38 embedded in the structure. | |
39 | |
40 For the moment, we are not using this feature. */ | |
41 static int category_table_version; | |
42 | |
43 Lisp_Object Qcategory_table, Qcategoryp, Qcategorysetp, Qcategory_table_p; | |
44 | |
45 /* Variables to determine word boundary. */ | |
46 Lisp_Object Vword_combining_categories, Vword_separating_categories; | |
47 | |
48 /* Temporary internal variable used in macro CHAR_HAS_CATEGORY. */ | |
49 Lisp_Object _temp_category_set; | |
50 | |
51 | |
52 /* Category set staff. */ | |
53 | |
54 DEFUN ("make-category-set", Fmake_category_set, Smake_category_set, 1, 1, 0, | |
55 "Return a newly created category-set which contains CATEGORIES.\n\ | |
56 CATEGORIES is a string of category mnemonics.") | |
57 (categories) | |
58 Lisp_Object categories; | |
59 { | |
60 Lisp_Object val; | |
61 int len; | |
62 | |
63 CHECK_STRING (categories, 0); | |
64 val = MAKE_CATEGORY_SET; | |
65 | |
20612
5a0922f8c841
(Fmake_category_set): Don't allow multibyte string.
Richard M. Stallman <rms@gnu.org>
parents:
20189
diff
changeset
|
66 if (STRING_MULTIBYTE (categories)) |
5a0922f8c841
(Fmake_category_set): Don't allow multibyte string.
Richard M. Stallman <rms@gnu.org>
parents:
20189
diff
changeset
|
67 error ("Multibyte string in make-category-set"); |
5a0922f8c841
(Fmake_category_set): Don't allow multibyte string.
Richard M. Stallman <rms@gnu.org>
parents:
20189
diff
changeset
|
68 |
17052 | 69 len = XSTRING (categories)->size; |
70 while (--len >= 0) | |
71 { | |
17369
566b26e1930e
(Fmake_category_set): Use XSETFASTINT.
Karl Heuer <kwzh@gnu.org>
parents:
17324
diff
changeset
|
72 Lisp_Object category; |
17052 | 73 |
17369
566b26e1930e
(Fmake_category_set): Use XSETFASTINT.
Karl Heuer <kwzh@gnu.org>
parents:
17324
diff
changeset
|
74 XSETFASTINT (category, XSTRING (categories)->data[len]); |
17052 | 75 CHECK_CATEGORY (category, 0); |
76 SET_CATEGORY_SET (val, category, Qt); | |
77 } | |
78 return val; | |
79 } | |
80 | |
81 | |
82 /* Category staff. */ | |
83 | |
84 Lisp_Object check_category_table (); | |
85 | |
86 DEFUN ("define-category", Fdefine_category, Sdefine_category, 2, 3, 0, | |
87 "Define CHAR as a category which is described by DOCSTRING.\n\ | |
88 CHAR should be a visible letter of ` ' thru `~'.\n\ | |
89 DOCSTRING is a documentation string of the category.\n\ | |
90 The category is defined only in category table TABLE, which defaults to\n\ | |
91 the current buffer's category table.") | |
92 (category, docstring, table) | |
93 Lisp_Object category, docstring, table; | |
94 { | |
95 CHECK_CATEGORY (category, 0); | |
96 CHECK_STRING (docstring, 1); | |
97 table = check_category_table (table); | |
98 | |
99 if (!NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) | |
100 error ("Category `%c' is already defined", XFASTINT (category)); | |
101 CATEGORY_DOCSTRING (table, XFASTINT (category)) = docstring; | |
102 | |
103 return Qnil; | |
104 } | |
105 | |
106 DEFUN ("category-docstring", Fcategory_docstring, Scategory_docstring, 1, 2, 0, | |
107 "Return a documentation string of CATEGORY.\n\ | |
108 Optional second arg specifies CATEGORY-TABLE,\n\ | |
109 which defaults to the current buffer's category table.") | |
110 (category, table) | |
111 Lisp_Object category, table; | |
112 { | |
113 Lisp_Object doc; | |
114 | |
115 CHECK_CATEGORY (category, 0); | |
116 table = check_category_table (table); | |
117 | |
118 return CATEGORY_DOCSTRING (table, XFASTINT (category)); | |
119 } | |
120 | |
121 DEFUN ("get-unused-category", Fget_unused_category, Sget_unused_category, | |
122 0, 1, 0, | |
123 "Return a category which is not yet defined.\n\ | |
124 If total number of categories has reached the limit (95), return nil.\n\ | |
125 Optional argument specifies CATEGORY-TABLE,\n\ | |
126 which defaults to the current buffer's category table.") | |
127 (table) | |
128 Lisp_Object table; | |
129 { | |
130 int i; | |
131 Lisp_Object docstring_vector; | |
132 | |
133 table = check_category_table (table); | |
134 | |
135 for (i = ' '; i <= '~'; i++) | |
136 if (NILP (CATEGORY_DOCSTRING (table, i))) | |
137 return make_number (i); | |
138 | |
139 return Qnil; | |
140 } | |
141 | |
142 | |
143 /* Category-table staff. */ | |
144 | |
145 DEFUN ("category-table-p", Fcategory_table_p, Scategory_table_p, 1, 1, 0, | |
146 "Return t if ARG is a category table.") | |
147 (arg) | |
148 Lisp_Object arg; | |
149 { | |
150 if (CHAR_TABLE_P (arg) | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
151 && EQ (XCHAR_TABLE (arg)->purpose, Qcategory_table)) |
17052 | 152 return Qt; |
153 return Qnil; | |
154 } | |
155 | |
156 /* If TABLE is nil, return the current category table. If TABLE is | |
157 not nil, check the validity of TABLE as a category table. If | |
158 valid, return TABLE itself, but if not valid, signal an error of | |
159 wrong-type-argument. */ | |
160 | |
161 Lisp_Object | |
162 check_category_table (table) | |
163 Lisp_Object table; | |
164 { | |
165 register Lisp_Object tem; | |
166 if (NILP (table)) | |
167 return current_buffer->category_table; | |
168 while (tem = Fcategory_table_p (table), NILP (tem)) | |
169 table = wrong_type_argument (Qcategory_table_p, table); | |
170 return table; | |
171 } | |
172 | |
173 DEFUN ("category-table", Fcategory_table, Scategory_table, 0, 0, 0, | |
174 "Return the current category table.\n\ | |
175 This is the one specified by the current buffer.") | |
176 () | |
177 { | |
178 return current_buffer->category_table; | |
179 } | |
180 | |
181 DEFUN ("standard-category-table", Fstandard_category_table, | |
182 Sstandard_category_table, 0, 0, 0, | |
183 "Return the standard category table.\n\ | |
184 This is the one used for new buffers.") | |
185 () | |
186 { | |
187 return Vstandard_category_table; | |
188 } | |
189 | |
190 /* Return a copy of category table TABLE. We can't simply use the | |
191 function copy-sequence because no contents should be shared between | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
192 the original and the copy. This function is called recursively by |
20189
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
193 binding TABLE to a sub char table. */ |
17052 | 194 |
195 Lisp_Object | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
196 copy_category_table (table) |
17052 | 197 Lisp_Object table; |
198 { | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
199 Lisp_Object tmp; |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
200 int i, to; |
17052 | 201 |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
202 if (!NILP (XCHAR_TABLE (table)->top)) |
17052 | 203 { |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
204 /* TABLE is a top level char table. |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
205 At first, make a copy of tree structure of the table. */ |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
206 table = Fcopy_sequence (table); |
17052 | 207 |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
208 /* Then, copy elements for single byte characters one by one. */ |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
209 for (i = 0; i < CHAR_TABLE_SINGLE_BYTE_SLOTS; i++) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
210 if (!NILP (tmp = XCHAR_TABLE (table)->contents[i])) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
211 XCHAR_TABLE (table)->contents[i] = Fcopy_sequence (tmp); |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
212 to = CHAR_TABLE_ORDINARY_SLOTS; |
20189
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
213 |
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
214 /* Also copy the first (and sole) extra slot. It is a vector |
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
215 containing docstring of each category. */ |
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
216 Fset_char_table_extra_slot |
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
217 (table, make_number (0), |
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
218 Fcopy_sequence (Fchar_table_extra_slot (table, make_number (0)))); |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
219 } |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
220 else |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
221 { |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
222 i = 32; |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
223 to = SUB_CHAR_TABLE_ORDINARY_SLOTS; |
17052 | 224 } |
225 | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
226 /* If the table has non-nil default value, copy it. */ |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
227 if (!NILP (tmp = XCHAR_TABLE (table)->defalt)) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
228 XCHAR_TABLE (table)->defalt = Fcopy_sequence (tmp); |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
229 |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
230 /* At last, copy the remaining elements while paying attention to a |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
231 sub char table. */ |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
232 for (; i < to; i++) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
233 if (!NILP (tmp = XCHAR_TABLE (table)->contents[i])) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
234 XCHAR_TABLE (table)->contents[i] |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
235 = (SUB_CHAR_TABLE_P (tmp) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
236 ? copy_category_table (tmp) : Fcopy_sequence (tmp)); |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
237 |
17052 | 238 return table; |
239 } | |
240 | |
241 DEFUN ("copy-category-table", Fcopy_category_table, Scopy_category_table, | |
242 0, 1, 0, | |
243 "Construct a new category table and return it.\n\ | |
244 It is a copy of the TABLE, which defaults to the standard category table.") | |
245 (table) | |
246 Lisp_Object table; | |
247 { | |
248 if (!NILP (table)) | |
249 check_category_table (table); | |
250 else | |
251 table = Vstandard_category_table; | |
252 | |
20189
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
253 return copy_category_table (table); |
17052 | 254 } |
255 | |
256 DEFUN ("set-category-table", Fset_category_table, Sset_category_table, 1, 1, 0, | |
257 "Select a new category table for the current buffer.\n\ | |
258 One argument, a category table.") | |
259 (table) | |
260 Lisp_Object table; | |
261 { | |
262 table = check_category_table (table); | |
263 current_buffer->category_table = table; | |
264 /* Indicate that this buffer now has a specified category table. */ | |
265 current_buffer->local_var_flags | |
266 |= XFASTINT (buffer_local_flags.category_table); | |
267 return table; | |
268 } | |
269 | |
270 | |
271 DEFUN ("char-category-set", Fchar_category_set, Schar_category_set, 1, 1, 0, | |
272 "Return a category set of CHAR.") | |
273 (ch) | |
274 Lisp_Object ch; | |
275 { | |
276 Lisp_Object val; | |
277 int charset; | |
278 unsigned char c1, c2; | |
279 | |
280 CHECK_NUMBER (ch, 0); | |
281 return CATEGORY_SET (XFASTINT (ch)); | |
282 } | |
283 | |
284 DEFUN ("category-set-mnemonics", Fcategory_set_mnemonics, | |
285 Scategory_set_mnemonics, 1, 1, 0, | |
286 "Return a string of mnemonics of all categories in CATEGORY-SET.") | |
287 (category_set) | |
288 Lisp_Object category_set; | |
289 { | |
290 int i, j; | |
291 char str[96]; | |
292 | |
293 CHECK_CATEGORY_SET (category_set, 0); | |
294 | |
295 j = 0; | |
296 for (i = 32; i < 127; i++) | |
297 if (CATEGORY_MEMBER (i, category_set)) | |
298 str[j++] = i; | |
299 str[j] = '\0'; | |
300 | |
301 return build_string (str); | |
302 } | |
303 | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
304 /* Modify all category sets stored under sub char-table TABLE so that |
17052 | 305 they contain (SET_VALUE is t) or don't contain (SET_VALUE is nil) |
306 CATEGORY. */ | |
307 | |
308 void | |
309 modify_lower_category_set (table, category, set_value) | |
310 Lisp_Object table, category, set_value; | |
311 { | |
312 Lisp_Object val; | |
313 int i; | |
314 | |
315 if (NILP (XCHAR_TABLE (table)->defalt)) | |
316 { | |
317 val = MAKE_CATEGORY_SET; | |
318 SET_CATEGORY_SET (val, category, set_value); | |
319 XCHAR_TABLE (table)->defalt = val; | |
320 } | |
321 | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
322 for (i = 32; i < SUB_CHAR_TABLE_ORDINARY_SLOTS; i++) |
17052 | 323 { |
324 val = XCHAR_TABLE (table)->contents[i]; | |
325 | |
326 if (CATEGORY_SET_P (val)) | |
327 SET_CATEGORY_SET (val, category, set_value); | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
328 else if (SUB_CHAR_TABLE_P (val)) |
17052 | 329 modify_lower_category_set (val, category, set_value); |
330 } | |
331 } | |
332 | |
333 void | |
334 set_category_set (category_set, category, val) | |
335 Lisp_Object category_set, category, val; | |
336 { | |
337 do { | |
338 int idx = XINT (category) / 8; | |
339 unsigned char bits = 1 << (XINT (category) % 8); | |
340 | |
341 if (NILP (val)) | |
342 XCATEGORY_SET (category_set)->data[idx] &= ~bits; | |
343 else | |
344 XCATEGORY_SET (category_set)->data[idx] |= bits; | |
345 } while (0); | |
346 } | |
347 | |
348 DEFUN ("modify-category-entry", Fmodify_category_entry, | |
349 Smodify_category_entry, 2, 4, 0, | |
350 "Modify the category set of CHAR by adding CATEGORY to it.\n\ | |
351 The category is changed only for table TABLE, which defaults to\n\ | |
352 the current buffer's category table.\n\ | |
353 If optional forth argument RESET is non NIL,\n\ | |
354 CATEGORY is deleted from the category set instead of being added.") | |
355 (ch, category, table, reset) | |
356 Lisp_Object ch, category, table, reset; | |
357 { | |
358 int c, charset, c1, c2; | |
359 Lisp_Object set_value; /* Actual value to be set in category sets. */ | |
360 Lisp_Object val, category_set; | |
361 | |
362 CHECK_NUMBER (ch, 0); | |
363 c = XINT (ch); | |
364 CHECK_CATEGORY (category, 1); | |
365 table = check_category_table (table); | |
366 | |
367 if (NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) | |
368 error ("Undefined category: %c", XFASTINT (category)); | |
369 | |
370 set_value = NILP (reset) ? Qt : Qnil; | |
371 | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
372 if (c < CHAR_TABLE_SINGLE_BYTE_SLOTS) |
17052 | 373 { |
374 val = XCHAR_TABLE (table)->contents[c]; | |
375 if (!CATEGORY_SET_P (val)) | |
376 XCHAR_TABLE (table)->contents[c] = (val = MAKE_CATEGORY_SET); | |
377 SET_CATEGORY_SET (val, category, set_value); | |
378 return Qnil; | |
379 } | |
380 | |
381 SPLIT_NON_ASCII_CHAR (c, charset, c1, c2); | |
382 | |
383 /* The top level table. */ | |
17187
9ab0c08a3359
Adjusted for the change of CHAR_TABLE_ORDINARY_SLOTS.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
384 val = XCHAR_TABLE (table)->contents[charset + 128]; |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
385 if (CATEGORY_SET_P (val)) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
386 category_set = val; |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
387 else if (!SUB_CHAR_TABLE_P (val)) |
17052 | 388 { |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
389 category_set = val = MAKE_CATEGORY_SET; |
17187
9ab0c08a3359
Adjusted for the change of CHAR_TABLE_ORDINARY_SLOTS.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
390 XCHAR_TABLE (table)->contents[charset + 128] = category_set; |
17052 | 391 } |
392 | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
393 if (c1 <= 0) |
17052 | 394 { |
395 /* Only a charset is specified. */ | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
396 if (SUB_CHAR_TABLE_P (val)) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
397 /* All characters in CHARSET should be the same as for having |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
398 CATEGORY or not. */ |
17052 | 399 modify_lower_category_set (val, category, set_value); |
400 else | |
401 SET_CATEGORY_SET (category_set, category, set_value); | |
402 return Qnil; | |
403 } | |
404 | |
405 /* The second level table. */ | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
406 if (!SUB_CHAR_TABLE_P (val)) |
17052 | 407 { |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
408 val = make_sub_char_table (Qnil); |
17187
9ab0c08a3359
Adjusted for the change of CHAR_TABLE_ORDINARY_SLOTS.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
409 XCHAR_TABLE (table)->contents[charset + 128] = val; |
17052 | 410 /* We must set default category set of CHARSET in `defalt' slot. */ |
411 XCHAR_TABLE (val)->defalt = category_set; | |
412 } | |
413 table = val; | |
414 | |
415 val = XCHAR_TABLE (table)->contents[c1]; | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
416 if (CATEGORY_SET_P (val)) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
417 category_set = val; |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
418 else if (!SUB_CHAR_TABLE_P (val)) |
17052 | 419 { |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
420 category_set = val = Fcopy_sequence (XCHAR_TABLE (table)->defalt); |
17052 | 421 XCHAR_TABLE (table)->contents[c1] = category_set; |
422 } | |
423 | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
424 if (c2 <= 0) |
17052 | 425 { |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
426 if (SUB_CHAR_TABLE_P (val)) |
17052 | 427 /* All characters in C1 group of CHARSET should be the same as |
428 for CATEGORY. */ | |
429 modify_lower_category_set (val, category, set_value); | |
430 else | |
431 SET_CATEGORY_SET (category_set, category, set_value); | |
432 return Qnil; | |
433 } | |
434 | |
435 /* The third (bottom) level table. */ | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
436 if (!SUB_CHAR_TABLE_P (val)) |
17052 | 437 { |
17459
22fc94ab9e79
(Fmodify_category_entry): Delete second arg in call to make_sub_char_table.
Karl Heuer <kwzh@gnu.org>
parents:
17369
diff
changeset
|
438 val = make_sub_char_table (Qnil); |
17052 | 439 XCHAR_TABLE (table)->contents[c1] = val; |
440 /* We must set default category set of CHARSET and C1 in | |
441 `defalt' slot. */ | |
442 XCHAR_TABLE (val)->defalt = category_set; | |
443 } | |
444 table = val; | |
445 | |
446 val = XCHAR_TABLE (table)->contents[c2]; | |
17324
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
447 if (CATEGORY_SET_P (val)) |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
448 category_set = val; |
ed53084a1655
(category-table-p): Check only type and purpose.
Kenichi Handa <handa@m17n.org>
parents:
17187
diff
changeset
|
449 else if (!SUB_CHAR_TABLE_P (val)) |
17052 | 450 { |
451 category_set = Fcopy_sequence (XCHAR_TABLE (table)->defalt); | |
452 XCHAR_TABLE (table)->contents[c2] = category_set; | |
453 } | |
454 else | |
455 /* This should never happen. */ | |
456 error ("Invalid category table"); | |
457 | |
458 SET_CATEGORY_SET (category_set, category, set_value); | |
459 | |
460 return Qnil; | |
461 } | |
462 | |
463 /* Dump category table to buffer in human-readable format */ | |
464 | |
465 static void | |
466 describe_category (value) | |
467 Lisp_Object value; | |
468 { | |
469 Lisp_Object mnemonics; | |
470 | |
471 Findent_to (make_number (16), make_number (1)); | |
472 | |
473 if (NILP (value)) | |
474 { | |
475 insert_string ("default\n"); | |
476 return; | |
477 } | |
478 | |
19659
315acc2627fe
(describe_category): Handle a sub-chartable.
Richard M. Stallman <rms@gnu.org>
parents:
18613
diff
changeset
|
479 if (CHAR_TABLE_P (value)) |
315acc2627fe
(describe_category): Handle a sub-chartable.
Richard M. Stallman <rms@gnu.org>
parents:
18613
diff
changeset
|
480 { |
315acc2627fe
(describe_category): Handle a sub-chartable.
Richard M. Stallman <rms@gnu.org>
parents:
18613
diff
changeset
|
481 insert_string ("deeper char-table ...\n"); |
315acc2627fe
(describe_category): Handle a sub-chartable.
Richard M. Stallman <rms@gnu.org>
parents:
18613
diff
changeset
|
482 return; |
315acc2627fe
(describe_category): Handle a sub-chartable.
Richard M. Stallman <rms@gnu.org>
parents:
18613
diff
changeset
|
483 } |
315acc2627fe
(describe_category): Handle a sub-chartable.
Richard M. Stallman <rms@gnu.org>
parents:
18613
diff
changeset
|
484 |
17052 | 485 if (!CATEGORY_SET_P (value)) |
486 { | |
487 insert_string ("invalid\n"); | |
488 return; | |
489 } | |
490 | |
491 mnemonics = Fcategory_set_mnemonics (value); | |
20612
5a0922f8c841
(Fmake_category_set): Don't allow multibyte string.
Richard M. Stallman <rms@gnu.org>
parents:
20189
diff
changeset
|
492 insert_from_string (mnemonics, 0, 0, XSTRING (mnemonics)->size, |
5a0922f8c841
(Fmake_category_set): Don't allow multibyte string.
Richard M. Stallman <rms@gnu.org>
parents:
20189
diff
changeset
|
493 XSTRING (mnemonics)->size_byte, 0); |
17052 | 494 insert_string ("\n"); |
495 return; | |
496 } | |
497 | |
498 static Lisp_Object | |
499 describe_category_1 (vector) | |
500 Lisp_Object vector; | |
501 { | |
502 struct buffer *old = current_buffer; | |
503 set_buffer_internal (XBUFFER (Vstandard_output)); | |
17787
eacf563a6d0d
(describe_category_1): Pass new args to describe_vector.
Richard M. Stallman <rms@gnu.org>
parents:
17459
diff
changeset
|
504 describe_vector (vector, Qnil, describe_category, 0, Qnil, Qnil, |
eacf563a6d0d
(describe_category_1): Pass new args to describe_vector.
Richard M. Stallman <rms@gnu.org>
parents:
17459
diff
changeset
|
505 (int *)0, 0); |
17052 | 506 { |
507 int i; | |
508 Lisp_Object docs = XCHAR_TABLE (vector)->extras[0]; | |
509 Lisp_Object elt; | |
510 | |
511 if (!VECTORP (docs) || XVECTOR (docs)->size != 95) | |
512 { | |
513 insert_string ("Invalid first extra slot in this char table\n"); | |
514 return Qnil; | |
515 } | |
516 | |
517 insert_string ("Meanings of mnemonice characters are:\n"); | |
518 for (i = 0; i < 95; i++) | |
519 { | |
520 elt = XVECTOR (docs)->contents[i]; | |
521 if (NILP (elt)) | |
522 continue; | |
523 | |
524 insert_char (i + 32); | |
525 insert (": ", 2); | |
20612
5a0922f8c841
(Fmake_category_set): Don't allow multibyte string.
Richard M. Stallman <rms@gnu.org>
parents:
20189
diff
changeset
|
526 insert_from_string (elt, 0, 0, XSTRING (elt)->size, |
5a0922f8c841
(Fmake_category_set): Don't allow multibyte string.
Richard M. Stallman <rms@gnu.org>
parents:
20189
diff
changeset
|
527 XSTRING (elt)->size_byte, 0); |
17052 | 528 insert ("\n", 1); |
529 } | |
530 } | |
531 | |
532 while (! NILP (XCHAR_TABLE (vector)->parent)) | |
533 { | |
534 vector = XCHAR_TABLE (vector)->parent; | |
535 insert_string ("\nThe parent category table is:"); | |
17787
eacf563a6d0d
(describe_category_1): Pass new args to describe_vector.
Richard M. Stallman <rms@gnu.org>
parents:
17459
diff
changeset
|
536 describe_vector (vector, Qnil, describe_category, 0, Qnil, Qnil, |
eacf563a6d0d
(describe_category_1): Pass new args to describe_vector.
Richard M. Stallman <rms@gnu.org>
parents:
17459
diff
changeset
|
537 (int *) 0, 0); |
17052 | 538 } |
539 | |
540 call0 (intern ("help-mode")); | |
541 set_buffer_internal (old); | |
542 return Qnil; | |
543 } | |
544 | |
545 DEFUN ("describe-category", Fdescribe_category, Sdescribe_category, 0, 0, "", | |
546 "Describe the category specifications in the category table.\n\ | |
547 The descriptions are inserted in a buffer, which is then displayed.") | |
548 () | |
549 { | |
550 internal_with_output_to_temp_buffer | |
551 ("*Help*", describe_category_1, current_buffer->category_table); | |
552 | |
553 return Qnil; | |
554 } | |
555 | |
556 /* Return 1 if there is a word boundary between two word-constituent | |
557 characters C1 and C2 if they appear in this order, else return 0. | |
558 Use the macro WORD_BOUNDARY_P instead of calling this function | |
559 directly. */ | |
560 | |
561 int | |
562 word_boundary_p (c1, c2) | |
563 int c1, c2; | |
564 { | |
565 Lisp_Object category_set1, category_set2; | |
566 Lisp_Object tail; | |
567 int default_result; | |
568 | |
569 if (CHAR_CHARSET (c1) == CHAR_CHARSET (c2)) | |
570 { | |
571 tail = Vword_separating_categories; | |
572 default_result = 0; | |
573 } | |
574 else | |
575 { | |
576 tail = Vword_combining_categories; | |
577 default_result = 1; | |
578 } | |
579 | |
580 category_set1 = CATEGORY_SET (c1); | |
581 if (NILP (category_set1)) | |
582 return default_result; | |
583 category_set2 = CATEGORY_SET (c2); | |
584 if (NILP (category_set2)) | |
585 return default_result; | |
586 | |
587 for (; CONSP (tail); tail = XCONS (tail)->cdr) | |
588 { | |
589 Lisp_Object elt = XCONS(tail)->car; | |
590 | |
591 if (CONSP (elt) | |
592 && CATEGORYP (XCONS (elt)->car) | |
593 && CATEGORYP (XCONS (elt)->cdr) | |
18613
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18341
diff
changeset
|
594 && CATEGORY_MEMBER (XFASTINT (XCONS (elt)->car), category_set1) |
614b916ff5bf
Fix bugs with inappropriate mixing of Lisp_Object with int.
Richard M. Stallman <rms@gnu.org>
parents:
18341
diff
changeset
|
595 && CATEGORY_MEMBER (XFASTINT (XCONS (elt)->cdr), category_set2)) |
17052 | 596 return !default_result; |
597 } | |
598 return default_result; | |
599 } | |
600 | |
601 | |
602 init_category_once () | |
603 { | |
604 /* This has to be done here, before we call Fmake_char_table. */ | |
605 Qcategory_table = intern ("category-table"); | |
606 staticpro (&Qcategory_table); | |
607 | |
608 /* Intern this now in case it isn't already done. | |
609 Setting this variable twice is harmless. | |
610 But don't staticpro it here--that is done in alloc.c. */ | |
611 Qchar_table_extra_slots = intern ("char-table-extra-slots"); | |
612 | |
613 /* Now we are ready to set up this property, so we can | |
614 create category tables. */ | |
615 Fput (Qcategory_table, Qchar_table_extra_slots, make_number (2)); | |
616 | |
617 Vstandard_category_table = Fmake_char_table (Qcategory_table, Qnil); | |
618 /* Set a category set which contains nothing to the default. */ | |
619 XCHAR_TABLE (Vstandard_category_table)->defalt = MAKE_CATEGORY_SET; | |
20189
16f5b56c2f68
(copy_category_table): Copy also the first extra slot
Kenichi Handa <handa@m17n.org>
parents:
19659
diff
changeset
|
620 Fset_char_table_extra_slot (Vstandard_category_table, make_number (0), |
17052 | 621 Fmake_vector (make_number (95), Qnil)); |
622 } | |
623 | |
624 syms_of_category () | |
625 { | |
626 Qcategoryp = intern ("categoryp"); | |
627 staticpro (&Qcategoryp); | |
628 Qcategorysetp = intern ("categorysetp"); | |
629 staticpro (&Qcategorysetp); | |
630 Qcategory_table_p = intern ("category-table-p"); | |
631 staticpro (&Qcategory_table_p); | |
632 | |
633 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories, | |
634 "List of pair (cons) of categories to determine word boundary.\n\ | |
635 \n\ | |
636 Emacs treats a sequence of word constituent characters as a single\n\ | |
637 word (i.e. finds no word boundary between them) iff they belongs to\n\ | |
638 the same charset. But, exceptions are allowed in the following cases.\n\ | |
639 \n\ | |
640 (1) The case that characters are in different charsets is controlled\n\ | |
641 by the variable `word-combining-categories'.\n\ | |
642 \n\ | |
643 Emacs finds no word boundary between characters of different charsets\n\ | |
644 if they have categories matching some element of this list.\n\ | |
645 \n\ | |
646 More precisely, if an element of this list is a cons of category CAT1\n\ | |
647 and CAT2, and a multibyte character C1 which has CAT1 is followed by\n\ | |
648 C2 which has CAT2, there's no word boundary between C1 and C2.\n\ | |
649 \n\ | |
650 For instance, to tell that ASCII characters and Latin-1 characters can\n\ | |
651 form a single word, the element `(?l . ?l)' should be in this list\n\ | |
652 because both characters have the category `l' (Latin characters).\n\ | |
653 \n\ | |
654 (2) The case that character are in the same charset is controlled by\n\ | |
655 the variable `word-separating-categories'.\n\ | |
656 \n\ | |
657 Emacs find a word boundary between characters of the same charset\n\ | |
658 if they have categories matching some element of this list.\n\ | |
659 \n\ | |
660 More precisely, if an element of this list is a cons of category CAT1\n\ | |
661 and CAT2, and a multibyte character C1 which has CAT1 is followed by\n\ | |
662 C2 which has CAT2, there's a word boundary between C1 and C2.\n\ | |
663 \n\ | |
664 For instance, to tell that there's a word boundary between Japanese\n\ | |
665 Hiragana and Japanese Kanji (both are in the same charset), the\n\ | |
666 element `(?H . ?C) should be in this list."); | |
667 | |
668 Vword_combining_categories = Qnil; | |
669 | |
670 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories, | |
671 "List of pair (cons) of categories to determine word boundary.\n\ | |
672 See the documentation of the variable `word-combining-categories'."); | |
673 | |
674 Vword_separating_categories = Qnil; | |
675 | |
676 defsubr (&Smake_category_set); | |
677 defsubr (&Sdefine_category); | |
678 defsubr (&Scategory_docstring); | |
679 defsubr (&Sget_unused_category); | |
680 defsubr (&Scategory_table_p); | |
681 defsubr (&Scategory_table); | |
682 defsubr (&Sstandard_category_table); | |
683 defsubr (&Scopy_category_table); | |
684 defsubr (&Sset_category_table); | |
685 defsubr (&Schar_category_set); | |
686 defsubr (&Scategory_set_mnemonics); | |
687 defsubr (&Smodify_category_entry); | |
688 defsubr (&Sdescribe_category); | |
689 | |
690 category_table_version = 0; | |
691 } |