Commit | Line | Data |
---|---|---|
4ed46869 | 1 | /* GNU Emacs routines to deal with category tables. |
75c8c592 RS |
2 | Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN. |
3 | Licensed to the Free Software Foundation. | |
4ed46869 KH |
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 | |
369314dc KH |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
4ed46869 KH |
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 | \f | |
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\ | |
ea4943bf RS |
56 | CATEGORIES is a string of category mnemonics.\n\ |
57 | The value is a bool-vector which has t at the indices corresponding to\n\ | |
58 | those categories.") | |
4ed46869 KH |
59 | (categories) |
60 | Lisp_Object categories; | |
61 | { | |
62 | Lisp_Object val; | |
63 | int len; | |
64 | ||
65 | CHECK_STRING (categories, 0); | |
66 | val = MAKE_CATEGORY_SET; | |
67 | ||
115afec3 RS |
68 | if (STRING_MULTIBYTE (categories)) |
69 | error ("Multibyte string in make-category-set"); | |
70 | ||
4ed46869 KH |
71 | len = XSTRING (categories)->size; |
72 | while (--len >= 0) | |
73 | { | |
15c60737 | 74 | Lisp_Object category; |
4ed46869 | 75 | |
15c60737 | 76 | XSETFASTINT (category, XSTRING (categories)->data[len]); |
4ed46869 KH |
77 | CHECK_CATEGORY (category, 0); |
78 | SET_CATEGORY_SET (val, category, Qt); | |
79 | } | |
80 | return val; | |
81 | } | |
82 | ||
83 | \f | |
84 | /* Category staff. */ | |
85 | ||
86 | Lisp_Object check_category_table (); | |
87 | ||
88 | DEFUN ("define-category", Fdefine_category, Sdefine_category, 2, 3, 0, | |
89 | "Define CHAR as a category which is described by DOCSTRING.\n\ | |
ea4943bf | 90 | CHAR should be an ASCII printing character in the range ` ' to `~'.\n\ |
4ed46869 KH |
91 | DOCSTRING is a documentation string of the category.\n\ |
92 | The category is defined only in category table TABLE, which defaults to\n\ | |
93 | the current buffer's category table.") | |
94 | (category, docstring, table) | |
95 | Lisp_Object category, docstring, table; | |
96 | { | |
97 | CHECK_CATEGORY (category, 0); | |
98 | CHECK_STRING (docstring, 1); | |
99 | table = check_category_table (table); | |
100 | ||
101 | if (!NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) | |
102 | error ("Category `%c' is already defined", XFASTINT (category)); | |
103 | CATEGORY_DOCSTRING (table, XFASTINT (category)) = docstring; | |
104 | ||
105 | return Qnil; | |
106 | } | |
107 | ||
108 | DEFUN ("category-docstring", Fcategory_docstring, Scategory_docstring, 1, 2, 0, | |
ea4943bf | 109 | "Return the documentation string of CATEGORY, as defined in CATEGORY-TABLE.") |
4ed46869 KH |
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, | |
ea4943bf RS |
123 | "Return a category which is not yet defined in CATEGORY-TABLE.\n\ |
124 | If no category remains available, return nil.\n\ | |
125 | The optional argument CATEGORY-TABLE specifies which category table\n\ | |
126 | to modify; it defaults to the current buffer's category table.") | |
4ed46869 KH |
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 | \f | |
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) | |
ed8ec86d | 151 | && EQ (XCHAR_TABLE (arg)->purpose, Qcategory_table)) |
4ed46869 KH |
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 | |
ed8ec86d | 192 | the original and the copy. This function is called recursively by |
9da95d53 | 193 | binding TABLE to a sub char table. */ |
4ed46869 KH |
194 | |
195 | Lisp_Object | |
ed8ec86d | 196 | copy_category_table (table) |
4ed46869 KH |
197 | Lisp_Object table; |
198 | { | |
ed8ec86d KH |
199 | Lisp_Object tmp; |
200 | int i, to; | |
4ed46869 | 201 | |
ed8ec86d KH |
202 | if (!NILP (XCHAR_TABLE (table)->top)) |
203 | { | |
204 | /* TABLE is a top level char table. | |
205 | At first, make a copy of tree structure of the table. */ | |
206 | table = Fcopy_sequence (table); | |
207 | ||
208 | /* Then, copy elements for single byte characters one by one. */ | |
209 | for (i = 0; i < CHAR_TABLE_SINGLE_BYTE_SLOTS; i++) | |
210 | if (!NILP (tmp = XCHAR_TABLE (table)->contents[i])) | |
211 | XCHAR_TABLE (table)->contents[i] = Fcopy_sequence (tmp); | |
212 | to = CHAR_TABLE_ORDINARY_SLOTS; | |
9da95d53 KH |
213 | |
214 | /* Also copy the first (and sole) extra slot. It is a vector | |
215 | containing docstring of each category. */ | |
216 | Fset_char_table_extra_slot | |
217 | (table, make_number (0), | |
218 | Fcopy_sequence (Fchar_table_extra_slot (table, make_number (0)))); | |
ed8ec86d KH |
219 | } |
220 | else | |
4ed46869 | 221 | { |
ed8ec86d KH |
222 | i = 32; |
223 | to = SUB_CHAR_TABLE_ORDINARY_SLOTS; | |
4ed46869 KH |
224 | } |
225 | ||
ed8ec86d KH |
226 | /* If the table has non-nil default value, copy it. */ |
227 | if (!NILP (tmp = XCHAR_TABLE (table)->defalt)) | |
228 | XCHAR_TABLE (table)->defalt = Fcopy_sequence (tmp); | |
229 | ||
230 | /* At last, copy the remaining elements while paying attention to a | |
231 | sub char table. */ | |
232 | for (; i < to; i++) | |
233 | if (!NILP (tmp = XCHAR_TABLE (table)->contents[i])) | |
234 | XCHAR_TABLE (table)->contents[i] | |
235 | = (SUB_CHAR_TABLE_P (tmp) | |
236 | ? copy_category_table (tmp) : Fcopy_sequence (tmp)); | |
237 | ||
4ed46869 KH |
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 | ||
9da95d53 | 253 | return copy_category_table (table); |
4ed46869 KH |
254 | } |
255 | ||
70414a3d KH |
256 | DEFUN ("make-category-table", Fmake_category_table, Smake_category_table, |
257 | 0, 0, 0, | |
258 | "Construct a new and empty category table and return it.") | |
259 | () | |
260 | { | |
261 | Lisp_Object val; | |
262 | ||
263 | val = Fmake_char_table (Qcategory_table, Qnil); | |
264 | XCHAR_TABLE (val)->defalt = MAKE_CATEGORY_SET; | |
265 | Fset_char_table_extra_slot (val, make_number (0), | |
266 | Fmake_vector (make_number (95), Qnil)); | |
267 | return val; | |
268 | } | |
269 | ||
4ed46869 | 270 | DEFUN ("set-category-table", Fset_category_table, Sset_category_table, 1, 1, 0, |
ea4943bf | 271 | "Specify TABLE as the category table for the current buffer.") |
4ed46869 KH |
272 | (table) |
273 | Lisp_Object table; | |
274 | { | |
275 | table = check_category_table (table); | |
276 | current_buffer->category_table = table; | |
277 | /* Indicate that this buffer now has a specified category table. */ | |
278 | current_buffer->local_var_flags | |
279 | |= XFASTINT (buffer_local_flags.category_table); | |
280 | return table; | |
281 | } | |
282 | ||
283 | \f | |
284 | DEFUN ("char-category-set", Fchar_category_set, Schar_category_set, 1, 1, 0, | |
ea4943bf | 285 | "Return the category set of CHAR.") |
4ed46869 KH |
286 | (ch) |
287 | Lisp_Object ch; | |
288 | { | |
289 | Lisp_Object val; | |
290 | int charset; | |
291 | unsigned char c1, c2; | |
292 | ||
293 | CHECK_NUMBER (ch, 0); | |
294 | return CATEGORY_SET (XFASTINT (ch)); | |
295 | } | |
296 | ||
297 | DEFUN ("category-set-mnemonics", Fcategory_set_mnemonics, | |
298 | Scategory_set_mnemonics, 1, 1, 0, | |
ea4943bf RS |
299 | "Return a string containing mnemonics of the categories in CATEGORY-SET.\n\ |
300 | CATEGORY-SET is a bool-vector, and the categories \"in\" it are those\n\ | |
301 | that are indexes where t occurs the bool-vector.\n\ | |
302 | The return value is a string containing those same categories.") | |
4ed46869 KH |
303 | (category_set) |
304 | Lisp_Object category_set; | |
305 | { | |
306 | int i, j; | |
307 | char str[96]; | |
308 | ||
309 | CHECK_CATEGORY_SET (category_set, 0); | |
310 | ||
311 | j = 0; | |
312 | for (i = 32; i < 127; i++) | |
313 | if (CATEGORY_MEMBER (i, category_set)) | |
314 | str[j++] = i; | |
315 | str[j] = '\0'; | |
316 | ||
317 | return build_string (str); | |
318 | } | |
319 | ||
ed8ec86d | 320 | /* Modify all category sets stored under sub char-table TABLE so that |
4ed46869 KH |
321 | they contain (SET_VALUE is t) or don't contain (SET_VALUE is nil) |
322 | CATEGORY. */ | |
323 | ||
324 | void | |
325 | modify_lower_category_set (table, category, set_value) | |
326 | Lisp_Object table, category, set_value; | |
327 | { | |
328 | Lisp_Object val; | |
329 | int i; | |
330 | ||
54e67cf7 KH |
331 | val = XCHAR_TABLE (table)->defalt; |
332 | if (!CATEGORY_SET_P (val)) | |
333 | val = MAKE_CATEGORY_SET; | |
334 | SET_CATEGORY_SET (val, category, set_value); | |
335 | XCHAR_TABLE (table)->defalt = val; | |
4ed46869 | 336 | |
ed8ec86d | 337 | for (i = 32; i < SUB_CHAR_TABLE_ORDINARY_SLOTS; i++) |
4ed46869 KH |
338 | { |
339 | val = XCHAR_TABLE (table)->contents[i]; | |
340 | ||
341 | if (CATEGORY_SET_P (val)) | |
342 | SET_CATEGORY_SET (val, category, set_value); | |
ed8ec86d | 343 | else if (SUB_CHAR_TABLE_P (val)) |
4ed46869 KH |
344 | modify_lower_category_set (val, category, set_value); |
345 | } | |
346 | } | |
347 | ||
348 | void | |
349 | set_category_set (category_set, category, val) | |
350 | Lisp_Object category_set, category, val; | |
351 | { | |
352 | do { | |
353 | int idx = XINT (category) / 8; | |
354 | unsigned char bits = 1 << (XINT (category) % 8); | |
355 | ||
356 | if (NILP (val)) | |
357 | XCATEGORY_SET (category_set)->data[idx] &= ~bits; | |
358 | else | |
359 | XCATEGORY_SET (category_set)->data[idx] |= bits; | |
360 | } while (0); | |
361 | } | |
362 | ||
363 | DEFUN ("modify-category-entry", Fmodify_category_entry, | |
364 | Smodify_category_entry, 2, 4, 0, | |
ea4943bf | 365 | "Modify the category set of CHARACTER by adding CATEGORY to it.\n\ |
4ed46869 KH |
366 | The category is changed only for table TABLE, which defaults to\n\ |
367 | the current buffer's category table.\n\ | |
ea4943bf RS |
368 | If optional fourth argument RESET is non-nil,\n\ |
369 | then delete CATEGORY from the category set instead of adding it.") | |
370 | (character, category, table, reset) | |
371 | Lisp_Object character, category, table, reset; | |
4ed46869 KH |
372 | { |
373 | int c, charset, c1, c2; | |
374 | Lisp_Object set_value; /* Actual value to be set in category sets. */ | |
375 | Lisp_Object val, category_set; | |
376 | ||
ea4943bf RS |
377 | CHECK_NUMBER (character, 0); |
378 | c = XINT (character); | |
4ed46869 KH |
379 | CHECK_CATEGORY (category, 1); |
380 | table = check_category_table (table); | |
381 | ||
382 | if (NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) | |
383 | error ("Undefined category: %c", XFASTINT (category)); | |
384 | ||
385 | set_value = NILP (reset) ? Qt : Qnil; | |
386 | ||
ed8ec86d | 387 | if (c < CHAR_TABLE_SINGLE_BYTE_SLOTS) |
4ed46869 KH |
388 | { |
389 | val = XCHAR_TABLE (table)->contents[c]; | |
390 | if (!CATEGORY_SET_P (val)) | |
391 | XCHAR_TABLE (table)->contents[c] = (val = MAKE_CATEGORY_SET); | |
392 | SET_CATEGORY_SET (val, category, set_value); | |
393 | return Qnil; | |
394 | } | |
395 | ||
4ed46869 KH |
396 | SPLIT_NON_ASCII_CHAR (c, charset, c1, c2); |
397 | ||
398 | /* The top level table. */ | |
cecda314 | 399 | val = XCHAR_TABLE (table)->contents[charset + 128]; |
ed8ec86d KH |
400 | if (CATEGORY_SET_P (val)) |
401 | category_set = val; | |
402 | else if (!SUB_CHAR_TABLE_P (val)) | |
4ed46869 | 403 | { |
ed8ec86d | 404 | category_set = val = MAKE_CATEGORY_SET; |
cecda314 | 405 | XCHAR_TABLE (table)->contents[charset + 128] = category_set; |
4ed46869 | 406 | } |
4ed46869 | 407 | |
ed8ec86d | 408 | if (c1 <= 0) |
4ed46869 KH |
409 | { |
410 | /* Only a charset is specified. */ | |
ed8ec86d KH |
411 | if (SUB_CHAR_TABLE_P (val)) |
412 | /* All characters in CHARSET should be the same as for having | |
413 | CATEGORY or not. */ | |
4ed46869 KH |
414 | modify_lower_category_set (val, category, set_value); |
415 | else | |
416 | SET_CATEGORY_SET (category_set, category, set_value); | |
417 | return Qnil; | |
418 | } | |
419 | ||
420 | /* The second level table. */ | |
ed8ec86d | 421 | if (!SUB_CHAR_TABLE_P (val)) |
4ed46869 | 422 | { |
ed8ec86d | 423 | val = make_sub_char_table (Qnil); |
cecda314 | 424 | XCHAR_TABLE (table)->contents[charset + 128] = val; |
4ed46869 KH |
425 | /* We must set default category set of CHARSET in `defalt' slot. */ |
426 | XCHAR_TABLE (val)->defalt = category_set; | |
427 | } | |
428 | table = val; | |
429 | ||
430 | val = XCHAR_TABLE (table)->contents[c1]; | |
ed8ec86d KH |
431 | if (CATEGORY_SET_P (val)) |
432 | category_set = val; | |
433 | else if (!SUB_CHAR_TABLE_P (val)) | |
4ed46869 | 434 | { |
ed8ec86d | 435 | category_set = val = Fcopy_sequence (XCHAR_TABLE (table)->defalt); |
4ed46869 KH |
436 | XCHAR_TABLE (table)->contents[c1] = category_set; |
437 | } | |
4ed46869 | 438 | |
ed8ec86d | 439 | if (c2 <= 0) |
4ed46869 | 440 | { |
ed8ec86d | 441 | if (SUB_CHAR_TABLE_P (val)) |
4ed46869 KH |
442 | /* All characters in C1 group of CHARSET should be the same as |
443 | for CATEGORY. */ | |
444 | modify_lower_category_set (val, category, set_value); | |
445 | else | |
446 | SET_CATEGORY_SET (category_set, category, set_value); | |
447 | return Qnil; | |
448 | } | |
449 | ||
450 | /* The third (bottom) level table. */ | |
ed8ec86d | 451 | if (!SUB_CHAR_TABLE_P (val)) |
4ed46869 | 452 | { |
53740deb | 453 | val = make_sub_char_table (Qnil); |
4ed46869 KH |
454 | XCHAR_TABLE (table)->contents[c1] = val; |
455 | /* We must set default category set of CHARSET and C1 in | |
456 | `defalt' slot. */ | |
457 | XCHAR_TABLE (val)->defalt = category_set; | |
458 | } | |
459 | table = val; | |
460 | ||
461 | val = XCHAR_TABLE (table)->contents[c2]; | |
ed8ec86d KH |
462 | if (CATEGORY_SET_P (val)) |
463 | category_set = val; | |
464 | else if (!SUB_CHAR_TABLE_P (val)) | |
4ed46869 KH |
465 | { |
466 | category_set = Fcopy_sequence (XCHAR_TABLE (table)->defalt); | |
467 | XCHAR_TABLE (table)->contents[c2] = category_set; | |
468 | } | |
4ed46869 KH |
469 | else |
470 | /* This should never happen. */ | |
471 | error ("Invalid category table"); | |
472 | ||
473 | SET_CATEGORY_SET (category_set, category, set_value); | |
474 | ||
475 | return Qnil; | |
476 | } | |
477 | \f | |
478 | /* Dump category table to buffer in human-readable format */ | |
479 | ||
480 | static void | |
481 | describe_category (value) | |
482 | Lisp_Object value; | |
483 | { | |
484 | Lisp_Object mnemonics; | |
485 | ||
486 | Findent_to (make_number (16), make_number (1)); | |
487 | ||
488 | if (NILP (value)) | |
489 | { | |
490 | insert_string ("default\n"); | |
491 | return; | |
492 | } | |
493 | ||
cfcbf459 RS |
494 | if (CHAR_TABLE_P (value)) |
495 | { | |
496 | insert_string ("deeper char-table ...\n"); | |
497 | return; | |
498 | } | |
499 | ||
4ed46869 KH |
500 | if (!CATEGORY_SET_P (value)) |
501 | { | |
502 | insert_string ("invalid\n"); | |
503 | return; | |
504 | } | |
505 | ||
506 | mnemonics = Fcategory_set_mnemonics (value); | |
115afec3 | 507 | insert_from_string (mnemonics, 0, 0, XSTRING (mnemonics)->size, |
fc932ac6 | 508 | STRING_BYTES (XSTRING (mnemonics)), 0); |
4ed46869 KH |
509 | insert_string ("\n"); |
510 | return; | |
511 | } | |
512 | ||
513 | static Lisp_Object | |
514 | describe_category_1 (vector) | |
515 | Lisp_Object vector; | |
516 | { | |
517 | struct buffer *old = current_buffer; | |
518 | set_buffer_internal (XBUFFER (Vstandard_output)); | |
96439b6a RS |
519 | describe_vector (vector, Qnil, describe_category, 0, Qnil, Qnil, |
520 | (int *)0, 0); | |
4ed46869 KH |
521 | { |
522 | int i; | |
523 | Lisp_Object docs = XCHAR_TABLE (vector)->extras[0]; | |
524 | Lisp_Object elt; | |
525 | ||
526 | if (!VECTORP (docs) || XVECTOR (docs)->size != 95) | |
527 | { | |
528 | insert_string ("Invalid first extra slot in this char table\n"); | |
529 | return Qnil; | |
530 | } | |
531 | ||
532 | insert_string ("Meanings of mnemonice characters are:\n"); | |
533 | for (i = 0; i < 95; i++) | |
534 | { | |
535 | elt = XVECTOR (docs)->contents[i]; | |
536 | if (NILP (elt)) | |
537 | continue; | |
538 | ||
539 | insert_char (i + 32); | |
540 | insert (": ", 2); | |
115afec3 | 541 | insert_from_string (elt, 0, 0, XSTRING (elt)->size, |
fc932ac6 | 542 | STRING_BYTES (XSTRING (elt)), 0); |
4ed46869 KH |
543 | insert ("\n", 1); |
544 | } | |
545 | } | |
546 | ||
547 | while (! NILP (XCHAR_TABLE (vector)->parent)) | |
548 | { | |
549 | vector = XCHAR_TABLE (vector)->parent; | |
550 | insert_string ("\nThe parent category table is:"); | |
96439b6a RS |
551 | describe_vector (vector, Qnil, describe_category, 0, Qnil, Qnil, |
552 | (int *) 0, 0); | |
4ed46869 KH |
553 | } |
554 | ||
555 | call0 (intern ("help-mode")); | |
556 | set_buffer_internal (old); | |
557 | return Qnil; | |
558 | } | |
559 | ||
ea4943bf RS |
560 | DEFUN ("describe-categories", Fdescribe_categories, Sdescribe_categories, 0, 0, "", |
561 | "Describe the category specifications in the current category table.\n\ | |
4ed46869 KH |
562 | The descriptions are inserted in a buffer, which is then displayed.") |
563 | () | |
564 | { | |
565 | internal_with_output_to_temp_buffer | |
566 | ("*Help*", describe_category_1, current_buffer->category_table); | |
567 | ||
568 | return Qnil; | |
569 | } | |
570 | \f | |
571 | /* Return 1 if there is a word boundary between two word-constituent | |
572 | characters C1 and C2 if they appear in this order, else return 0. | |
573 | Use the macro WORD_BOUNDARY_P instead of calling this function | |
574 | directly. */ | |
575 | ||
576 | int | |
577 | word_boundary_p (c1, c2) | |
578 | int c1, c2; | |
579 | { | |
580 | Lisp_Object category_set1, category_set2; | |
581 | Lisp_Object tail; | |
582 | int default_result; | |
583 | ||
584 | if (CHAR_CHARSET (c1) == CHAR_CHARSET (c2)) | |
585 | { | |
586 | tail = Vword_separating_categories; | |
587 | default_result = 0; | |
588 | } | |
589 | else | |
590 | { | |
591 | tail = Vword_combining_categories; | |
592 | default_result = 1; | |
593 | } | |
594 | ||
595 | category_set1 = CATEGORY_SET (c1); | |
596 | if (NILP (category_set1)) | |
597 | return default_result; | |
598 | category_set2 = CATEGORY_SET (c2); | |
599 | if (NILP (category_set2)) | |
600 | return default_result; | |
601 | ||
03699b14 | 602 | for (; CONSP (tail); tail = XCDR (tail)) |
4ed46869 | 603 | { |
03699b14 | 604 | Lisp_Object elt = XCAR (tail); |
4ed46869 KH |
605 | |
606 | if (CONSP (elt) | |
03699b14 KR |
607 | && CATEGORYP (XCAR (elt)) |
608 | && CATEGORYP (XCDR (elt)) | |
609 | && CATEGORY_MEMBER (XFASTINT (XCAR (elt)), category_set1) | |
610 | && CATEGORY_MEMBER (XFASTINT (XCDR (elt)), category_set2)) | |
4ed46869 KH |
611 | return !default_result; |
612 | } | |
613 | return default_result; | |
614 | } | |
615 | ||
616 | \f | |
dfcf069d | 617 | void |
4ed46869 KH |
618 | init_category_once () |
619 | { | |
620 | /* This has to be done here, before we call Fmake_char_table. */ | |
621 | Qcategory_table = intern ("category-table"); | |
622 | staticpro (&Qcategory_table); | |
623 | ||
624 | /* Intern this now in case it isn't already done. | |
625 | Setting this variable twice is harmless. | |
626 | But don't staticpro it here--that is done in alloc.c. */ | |
627 | Qchar_table_extra_slots = intern ("char-table-extra-slots"); | |
628 | ||
629 | /* Now we are ready to set up this property, so we can | |
630 | create category tables. */ | |
631 | Fput (Qcategory_table, Qchar_table_extra_slots, make_number (2)); | |
632 | ||
633 | Vstandard_category_table = Fmake_char_table (Qcategory_table, Qnil); | |
634 | /* Set a category set which contains nothing to the default. */ | |
635 | XCHAR_TABLE (Vstandard_category_table)->defalt = MAKE_CATEGORY_SET; | |
9da95d53 | 636 | Fset_char_table_extra_slot (Vstandard_category_table, make_number (0), |
4ed46869 KH |
637 | Fmake_vector (make_number (95), Qnil)); |
638 | } | |
639 | ||
dfcf069d | 640 | void |
4ed46869 KH |
641 | syms_of_category () |
642 | { | |
643 | Qcategoryp = intern ("categoryp"); | |
644 | staticpro (&Qcategoryp); | |
645 | Qcategorysetp = intern ("categorysetp"); | |
646 | staticpro (&Qcategorysetp); | |
647 | Qcategory_table_p = intern ("category-table-p"); | |
648 | staticpro (&Qcategory_table_p); | |
649 | ||
650 | DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories, | |
651 | "List of pair (cons) of categories to determine word boundary.\n\ | |
652 | \n\ | |
653 | Emacs treats a sequence of word constituent characters as a single\n\ | |
654 | word (i.e. finds no word boundary between them) iff they belongs to\n\ | |
655 | the same charset. But, exceptions are allowed in the following cases.\n\ | |
656 | \n\ | |
61a398ea | 657 | \(1) The case that characters are in different charsets is controlled\n\ |
4ed46869 KH |
658 | by the variable `word-combining-categories'.\n\ |
659 | \n\ | |
660 | Emacs finds no word boundary between characters of different charsets\n\ | |
661 | if they have categories matching some element of this list.\n\ | |
662 | \n\ | |
663 | More precisely, if an element of this list is a cons of category CAT1\n\ | |
664 | and CAT2, and a multibyte character C1 which has CAT1 is followed by\n\ | |
665 | C2 which has CAT2, there's no word boundary between C1 and C2.\n\ | |
666 | \n\ | |
667 | For instance, to tell that ASCII characters and Latin-1 characters can\n\ | |
668 | form a single word, the element `(?l . ?l)' should be in this list\n\ | |
669 | because both characters have the category `l' (Latin characters).\n\ | |
670 | \n\ | |
61a398ea | 671 | \(2) The case that character are in the same charset is controlled by\n\ |
4ed46869 KH |
672 | the variable `word-separating-categories'.\n\ |
673 | \n\ | |
674 | Emacs find a word boundary between characters of the same charset\n\ | |
675 | if they have categories matching some element of this list.\n\ | |
676 | \n\ | |
677 | More precisely, if an element of this list is a cons of category CAT1\n\ | |
678 | and CAT2, and a multibyte character C1 which has CAT1 is followed by\n\ | |
679 | C2 which has CAT2, there's a word boundary between C1 and C2.\n\ | |
680 | \n\ | |
681 | For instance, to tell that there's a word boundary between Japanese\n\ | |
682 | Hiragana and Japanese Kanji (both are in the same charset), the\n\ | |
683 | element `(?H . ?C) should be in this list."); | |
684 | ||
685 | Vword_combining_categories = Qnil; | |
686 | ||
687 | DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories, | |
688 | "List of pair (cons) of categories to determine word boundary.\n\ | |
689 | See the documentation of the variable `word-combining-categories'."); | |
690 | ||
691 | Vword_separating_categories = Qnil; | |
692 | ||
693 | defsubr (&Smake_category_set); | |
694 | defsubr (&Sdefine_category); | |
695 | defsubr (&Scategory_docstring); | |
696 | defsubr (&Sget_unused_category); | |
697 | defsubr (&Scategory_table_p); | |
698 | defsubr (&Scategory_table); | |
699 | defsubr (&Sstandard_category_table); | |
700 | defsubr (&Scopy_category_table); | |
70414a3d | 701 | defsubr (&Smake_category_table); |
4ed46869 KH |
702 | defsubr (&Sset_category_table); |
703 | defsubr (&Schar_category_set); | |
704 | defsubr (&Scategory_set_mnemonics); | |
705 | defsubr (&Smodify_category_entry); | |
ea4943bf | 706 | defsubr (&Sdescribe_categories); |
4ed46869 KH |
707 | |
708 | category_table_version = 0; | |
709 | } |