428
|
1 /* XEmacs routines to deal with char tables.
|
|
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
788
|
4 Copyright (C) 1995, 1996, 2002 Ben Wing.
|
428
|
5 Copyright (C) 1995, 1997, 1999 Electrotechnical Laboratory, JAPAN.
|
|
6 Licensed to the Free Software Foundation.
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
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
|
|
13 later version.
|
|
14
|
|
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
|
|
18 for more details.
|
|
19
|
|
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. */
|
|
24
|
|
25 /* Synched up with: Mule 2.3. Not synched with FSF.
|
|
26
|
|
27 This file was written independently of the FSF implementation,
|
|
28 and is not compatible. */
|
|
29
|
|
30 /* Authorship:
|
|
31
|
|
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
|
|
36 */
|
|
37
|
|
38 #include <config.h>
|
|
39 #include "lisp.h"
|
|
40
|
|
41 #include "buffer.h"
|
|
42 #include "chartab.h"
|
|
43 #include "syntax.h"
|
|
44
|
|
45 Lisp_Object Qchar_tablep, Qchar_table;
|
|
46
|
|
47 Lisp_Object Vall_syntax_tables;
|
|
48
|
|
49 #ifdef MULE
|
|
50 Lisp_Object Qcategory_table_p;
|
|
51 Lisp_Object Qcategory_designator_p;
|
|
52 Lisp_Object Qcategory_table_value_p;
|
|
53
|
|
54 Lisp_Object Vstandard_category_table;
|
|
55
|
|
56 /* Variables to determine word boundary. */
|
|
57 Lisp_Object Vword_combining_categories, Vword_separating_categories;
|
|
58 #endif /* MULE */
|
|
59
|
826
|
60 static int check_valid_char_table_value (Lisp_Object value,
|
|
61 enum char_table_type type,
|
|
62 Error_Behavior errb);
|
|
63
|
428
|
64
|
|
65 /* A char table maps from ranges of characters to values.
|
|
66
|
|
67 Implementing a general data structure that maps from arbitrary
|
|
68 ranges of numbers to values is tricky to do efficiently. As it
|
|
69 happens, it should suffice (and is usually more convenient, anyway)
|
|
70 when dealing with characters to restrict the sorts of ranges that
|
|
71 can be assigned values, as follows:
|
|
72
|
|
73 1) All characters.
|
|
74 2) All characters in a charset.
|
|
75 3) All characters in a particular row of a charset, where a "row"
|
|
76 means all characters with the same first byte.
|
|
77 4) A particular character in a charset.
|
|
78
|
|
79 We use char tables to generalize the 256-element vectors now
|
|
80 littering the Emacs code.
|
|
81
|
|
82 Possible uses (all should be converted at some point):
|
|
83
|
|
84 1) category tables
|
|
85 2) syntax tables
|
|
86 3) display tables
|
|
87 4) case tables
|
|
88 5) keyboard-translate-table?
|
|
89
|
|
90 We provide an
|
|
91 abstract type to generalize the Emacs vectors and Mule
|
|
92 vectors-of-vectors goo.
|
|
93 */
|
|
94
|
|
95 /************************************************************************/
|
|
96 /* Char Table object */
|
|
97 /************************************************************************/
|
|
98
|
|
99 #ifdef MULE
|
|
100
|
|
101 static Lisp_Object
|
|
102 mark_char_table_entry (Lisp_Object obj)
|
|
103 {
|
440
|
104 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
|
428
|
105 int i;
|
|
106
|
|
107 for (i = 0; i < 96; i++)
|
|
108 {
|
|
109 mark_object (cte->level2[i]);
|
|
110 }
|
|
111 return Qnil;
|
|
112 }
|
|
113
|
|
114 static int
|
|
115 char_table_entry_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
116 {
|
440
|
117 Lisp_Char_Table_Entry *cte1 = XCHAR_TABLE_ENTRY (obj1);
|
|
118 Lisp_Char_Table_Entry *cte2 = XCHAR_TABLE_ENTRY (obj2);
|
428
|
119 int i;
|
|
120
|
|
121 for (i = 0; i < 96; i++)
|
|
122 if (!internal_equal (cte1->level2[i], cte2->level2[i], depth + 1))
|
|
123 return 0;
|
|
124
|
|
125 return 1;
|
|
126 }
|
|
127
|
665
|
128 static Hashcode
|
428
|
129 char_table_entry_hash (Lisp_Object obj, int depth)
|
|
130 {
|
440
|
131 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (obj);
|
428
|
132
|
826
|
133 return internal_array_hash (cte->level2, 96, depth + 1);
|
428
|
134 }
|
|
135
|
1204
|
136 static const struct memory_description char_table_entry_description[] = {
|
440
|
137 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table_Entry, level2), 96 },
|
428
|
138 { XD_END }
|
|
139 };
|
|
140
|
934
|
141 DEFINE_LRECORD_IMPLEMENTATION ("char-table-entry", char_table_entry,
|
|
142 1, /* dumpable flag */
|
|
143 mark_char_table_entry, internal_object_printer,
|
|
144 0, char_table_entry_equal,
|
|
145 char_table_entry_hash,
|
|
146 char_table_entry_description,
|
|
147 Lisp_Char_Table_Entry);
|
|
148
|
428
|
149 #endif /* MULE */
|
|
150
|
|
151 static Lisp_Object
|
|
152 mark_char_table (Lisp_Object obj)
|
|
153 {
|
440
|
154 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
|
428
|
155 int i;
|
|
156
|
|
157 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
158 mark_object (ct->ascii[i]);
|
|
159 #ifdef MULE
|
|
160 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
161 mark_object (ct->level1[i]);
|
|
162 #endif
|
793
|
163 mark_object (ct->parent);
|
|
164 mark_object (ct->default_);
|
428
|
165 return ct->mirror_table;
|
|
166 }
|
|
167
|
|
168 /* WARNING: All functions of this nature need to be written extremely
|
|
169 carefully to avoid crashes during GC. Cf. prune_specifiers()
|
|
170 and prune_weak_hash_tables(). */
|
|
171
|
|
172 void
|
|
173 prune_syntax_tables (void)
|
|
174 {
|
|
175 Lisp_Object rest, prev = Qnil;
|
|
176
|
|
177 for (rest = Vall_syntax_tables;
|
|
178 !NILP (rest);
|
|
179 rest = XCHAR_TABLE (rest)->next_table)
|
|
180 {
|
|
181 if (! marked_p (rest))
|
|
182 {
|
|
183 /* This table is garbage. Remove it from the list. */
|
|
184 if (NILP (prev))
|
|
185 Vall_syntax_tables = XCHAR_TABLE (rest)->next_table;
|
|
186 else
|
|
187 XCHAR_TABLE (prev)->next_table =
|
|
188 XCHAR_TABLE (rest)->next_table;
|
|
189 }
|
|
190 }
|
|
191 }
|
|
192
|
|
193 static Lisp_Object
|
|
194 char_table_type_to_symbol (enum char_table_type type)
|
|
195 {
|
|
196 switch (type)
|
|
197 {
|
|
198 default: abort();
|
|
199 case CHAR_TABLE_TYPE_GENERIC: return Qgeneric;
|
|
200 case CHAR_TABLE_TYPE_SYNTAX: return Qsyntax;
|
|
201 case CHAR_TABLE_TYPE_DISPLAY: return Qdisplay;
|
|
202 case CHAR_TABLE_TYPE_CHAR: return Qchar;
|
|
203 #ifdef MULE
|
|
204 case CHAR_TABLE_TYPE_CATEGORY: return Qcategory;
|
|
205 #endif
|
|
206 }
|
|
207 }
|
|
208
|
|
209 static enum char_table_type
|
|
210 symbol_to_char_table_type (Lisp_Object symbol)
|
|
211 {
|
|
212 CHECK_SYMBOL (symbol);
|
|
213
|
|
214 if (EQ (symbol, Qgeneric)) return CHAR_TABLE_TYPE_GENERIC;
|
|
215 if (EQ (symbol, Qsyntax)) return CHAR_TABLE_TYPE_SYNTAX;
|
|
216 if (EQ (symbol, Qdisplay)) return CHAR_TABLE_TYPE_DISPLAY;
|
|
217 if (EQ (symbol, Qchar)) return CHAR_TABLE_TYPE_CHAR;
|
|
218 #ifdef MULE
|
|
219 if (EQ (symbol, Qcategory)) return CHAR_TABLE_TYPE_CATEGORY;
|
|
220 #endif
|
|
221
|
563
|
222 invalid_constant ("Unrecognized char table type", symbol);
|
1204
|
223 RETURN_NOT_REACHED (CHAR_TABLE_TYPE_GENERIC);
|
428
|
224 }
|
|
225
|
|
226 static void
|
826
|
227 decode_char_table_range (Lisp_Object range, struct chartab_range *outrange)
|
428
|
228 {
|
826
|
229 if (EQ (range, Qt))
|
|
230 outrange->type = CHARTAB_RANGE_ALL;
|
|
231 else if (CHAR_OR_CHAR_INTP (range))
|
|
232 {
|
|
233 outrange->type = CHARTAB_RANGE_CHAR;
|
|
234 outrange->ch = XCHAR_OR_CHAR_INT (range);
|
|
235 }
|
|
236 #ifndef MULE
|
428
|
237 else
|
826
|
238 sferror ("Range must be t or a character", range);
|
|
239 #else /* MULE */
|
|
240 else if (VECTORP (range))
|
|
241 {
|
|
242 Lisp_Vector *vec = XVECTOR (range);
|
|
243 Lisp_Object *elts = vector_data (vec);
|
|
244 if (vector_length (vec) != 2)
|
|
245 sferror ("Length of charset row vector must be 2",
|
|
246 range);
|
|
247 outrange->type = CHARTAB_RANGE_ROW;
|
|
248 outrange->charset = Fget_charset (elts[0]);
|
|
249 CHECK_INT (elts[1]);
|
|
250 outrange->row = XINT (elts[1]);
|
|
251 switch (XCHARSET_TYPE (outrange->charset))
|
|
252 {
|
|
253 case CHARSET_TYPE_94:
|
|
254 case CHARSET_TYPE_96:
|
|
255 sferror ("Charset in row vector must be multi-byte",
|
|
256 outrange->charset);
|
|
257 case CHARSET_TYPE_94X94:
|
|
258 check_int_range (outrange->row, 33, 126);
|
|
259 break;
|
|
260 case CHARSET_TYPE_96X96:
|
|
261 check_int_range (outrange->row, 32, 127);
|
|
262 break;
|
|
263 default:
|
|
264 abort ();
|
|
265 }
|
|
266 }
|
|
267 else
|
|
268 {
|
|
269 if (!CHARSETP (range) && !SYMBOLP (range))
|
|
270 sferror
|
|
271 ("Char table range must be t, charset, char, or vector", range);
|
|
272 outrange->type = CHARTAB_RANGE_CHARSET;
|
|
273 outrange->charset = Fget_charset (range);
|
|
274 }
|
|
275 #endif /* MULE */
|
428
|
276 }
|
|
277
|
826
|
278 static Lisp_Object
|
|
279 encode_char_table_range (struct chartab_range *range)
|
428
|
280 {
|
826
|
281 switch (range->type)
|
428
|
282 {
|
826
|
283 case CHARTAB_RANGE_ALL:
|
|
284 return Qt;
|
|
285
|
|
286 #ifdef MULE
|
|
287 case CHARTAB_RANGE_CHARSET:
|
|
288 return XCHARSET_NAME (Fget_charset (range->charset));
|
428
|
289
|
826
|
290 case CHARTAB_RANGE_ROW:
|
|
291 return vector2 (XCHARSET_NAME (Fget_charset (range->charset)),
|
|
292 make_int (range->row));
|
|
293 #endif
|
|
294 case CHARTAB_RANGE_CHAR:
|
|
295 return make_char (range->ch);
|
|
296 default:
|
|
297 abort ();
|
428
|
298 }
|
826
|
299 return Qnil; /* not reached */
|
428
|
300 }
|
|
301
|
826
|
302 struct ptemap
|
428
|
303 {
|
826
|
304 Lisp_Object printcharfun;
|
|
305 int first;
|
|
306 };
|
428
|
307
|
826
|
308 static int
|
|
309 print_table_entry (struct chartab_range *range, Lisp_Object table,
|
|
310 Lisp_Object val, void *arg)
|
|
311 {
|
|
312 struct ptemap *a = (struct ptemap *) arg;
|
|
313 struct gcpro gcpro1;
|
|
314 Lisp_Object lisprange;
|
|
315 if (!a->first)
|
|
316 write_c_string (a->printcharfun, " ");
|
|
317 a->first = 0;
|
|
318 lisprange = encode_char_table_range (range);
|
|
319 GCPRO1 (lisprange);
|
|
320 write_fmt_string_lisp (a->printcharfun, "%s %s", 2, lisprange, val);
|
|
321 UNGCPRO;
|
|
322 return 0;
|
428
|
323 }
|
|
324
|
|
325 static void
|
|
326 print_char_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
327 {
|
440
|
328 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
|
826
|
329 struct chartab_range range;
|
|
330 struct ptemap arg;
|
|
331
|
|
332 range.type = CHARTAB_RANGE_ALL;
|
|
333 arg.printcharfun = printcharfun;
|
|
334 arg.first = 1;
|
428
|
335
|
793
|
336 write_fmt_string_lisp (printcharfun, "#s(char-table type %s data (",
|
|
337 1, char_table_type_to_symbol (ct->type));
|
826
|
338 map_char_table (obj, &range, print_table_entry, &arg);
|
|
339 write_c_string (printcharfun, "))");
|
428
|
340
|
826
|
341 /* #### need to print and read the default; but that will allow the
|
|
342 default to be modified, which we don't (yet) support -- but FSF does */
|
428
|
343 }
|
|
344
|
|
345 static int
|
|
346 char_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
347 {
|
440
|
348 Lisp_Char_Table *ct1 = XCHAR_TABLE (obj1);
|
|
349 Lisp_Char_Table *ct2 = XCHAR_TABLE (obj2);
|
428
|
350 int i;
|
|
351
|
|
352 if (CHAR_TABLE_TYPE (ct1) != CHAR_TABLE_TYPE (ct2))
|
|
353 return 0;
|
|
354
|
|
355 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
356 if (!internal_equal (ct1->ascii[i], ct2->ascii[i], depth + 1))
|
|
357 return 0;
|
|
358
|
|
359 #ifdef MULE
|
|
360 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
361 if (!internal_equal (ct1->level1[i], ct2->level1[i], depth + 1))
|
|
362 return 0;
|
|
363 #endif /* MULE */
|
|
364
|
826
|
365 return internal_equal (ct1->default_, ct2->default_, depth + 1);
|
428
|
366 }
|
|
367
|
665
|
368 static Hashcode
|
428
|
369 char_table_hash (Lisp_Object obj, int depth)
|
|
370 {
|
440
|
371 Lisp_Char_Table *ct = XCHAR_TABLE (obj);
|
665
|
372 Hashcode hashval = internal_array_hash (ct->ascii, NUM_ASCII_CHARS,
|
826
|
373 depth + 1);
|
428
|
374 #ifdef MULE
|
|
375 hashval = HASH2 (hashval,
|
826
|
376 internal_array_hash (ct->level1, NUM_LEADING_BYTES,
|
|
377 depth + 1));
|
428
|
378 #endif /* MULE */
|
826
|
379 return HASH2 (hashval, internal_hash (ct->default_, depth + 1));
|
428
|
380 }
|
|
381
|
1204
|
382 static const struct memory_description char_table_description[] = {
|
440
|
383 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, ascii), NUM_ASCII_CHARS },
|
428
|
384 #ifdef MULE
|
440
|
385 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, level1), NUM_LEADING_BYTES },
|
428
|
386 #endif
|
793
|
387 { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, parent) },
|
|
388 { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, default_) },
|
440
|
389 { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, mirror_table) },
|
|
390 { XD_LO_LINK, offsetof (Lisp_Char_Table, next_table) },
|
428
|
391 { XD_END }
|
|
392 };
|
|
393
|
934
|
394 DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table,
|
|
395 1, /*dumpable-flag*/
|
|
396 mark_char_table, print_char_table, 0,
|
|
397 char_table_equal, char_table_hash,
|
|
398 char_table_description,
|
|
399 Lisp_Char_Table);
|
428
|
400
|
|
401 DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /*
|
|
402 Return non-nil if OBJECT is a char table.
|
|
403 */
|
|
404 (object))
|
|
405 {
|
|
406 return CHAR_TABLEP (object) ? Qt : Qnil;
|
|
407 }
|
|
408
|
|
409 DEFUN ("char-table-type-list", Fchar_table_type_list, 0, 0, 0, /*
|
|
410 Return a list of the recognized char table types.
|
800
|
411 See `make-char-table'.
|
428
|
412 */
|
|
413 ())
|
|
414 {
|
|
415 #ifdef MULE
|
|
416 return list5 (Qchar, Qcategory, Qdisplay, Qgeneric, Qsyntax);
|
|
417 #else
|
|
418 return list4 (Qchar, Qdisplay, Qgeneric, Qsyntax);
|
|
419 #endif
|
|
420 }
|
|
421
|
|
422 DEFUN ("valid-char-table-type-p", Fvalid_char_table_type_p, 1, 1, 0, /*
|
|
423 Return t if TYPE if a recognized char table type.
|
800
|
424 See `make-char-table'.
|
428
|
425 */
|
|
426 (type))
|
|
427 {
|
|
428 return (EQ (type, Qchar) ||
|
|
429 #ifdef MULE
|
|
430 EQ (type, Qcategory) ||
|
|
431 #endif
|
|
432 EQ (type, Qdisplay) ||
|
|
433 EQ (type, Qgeneric) ||
|
|
434 EQ (type, Qsyntax)) ? Qt : Qnil;
|
|
435 }
|
|
436
|
|
437 DEFUN ("char-table-type", Fchar_table_type, 1, 1, 0, /*
|
444
|
438 Return the type of CHAR-TABLE.
|
800
|
439 See `make-char-table'.
|
428
|
440 */
|
444
|
441 (char_table))
|
428
|
442 {
|
444
|
443 CHECK_CHAR_TABLE (char_table);
|
|
444 return char_table_type_to_symbol (XCHAR_TABLE (char_table)->type);
|
428
|
445 }
|
|
446
|
|
447 void
|
826
|
448 set_char_table_default (Lisp_Object table, Lisp_Object value)
|
|
449 {
|
|
450 Lisp_Char_Table *ct = XCHAR_TABLE (table);
|
|
451 ct->default_ = value;
|
|
452 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
453 update_syntax_table (table);
|
|
454 }
|
|
455
|
|
456 static void
|
440
|
457 fill_char_table (Lisp_Char_Table *ct, Lisp_Object value)
|
428
|
458 {
|
|
459 int i;
|
|
460
|
|
461 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
462 ct->ascii[i] = value;
|
|
463 #ifdef MULE
|
|
464 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
465 ct->level1[i] = value;
|
|
466 #endif /* MULE */
|
|
467
|
|
468 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
826
|
469 update_syntax_table (wrap_char_table (ct));
|
428
|
470 }
|
|
471
|
|
472 DEFUN ("reset-char-table", Freset_char_table, 1, 1, 0, /*
|
444
|
473 Reset CHAR-TABLE to its default state.
|
428
|
474 */
|
444
|
475 (char_table))
|
428
|
476 {
|
440
|
477 Lisp_Char_Table *ct;
|
826
|
478 Lisp_Object def;
|
428
|
479
|
444
|
480 CHECK_CHAR_TABLE (char_table);
|
|
481 ct = XCHAR_TABLE (char_table);
|
428
|
482
|
|
483 switch (ct->type)
|
|
484 {
|
|
485 case CHAR_TABLE_TYPE_CHAR:
|
826
|
486 def = make_char (0);
|
428
|
487 break;
|
|
488 case CHAR_TABLE_TYPE_DISPLAY:
|
|
489 case CHAR_TABLE_TYPE_GENERIC:
|
|
490 #ifdef MULE
|
|
491 case CHAR_TABLE_TYPE_CATEGORY:
|
|
492 #endif /* MULE */
|
826
|
493 def = Qnil;
|
428
|
494 break;
|
|
495
|
|
496 case CHAR_TABLE_TYPE_SYNTAX:
|
826
|
497 def = make_int (Sinherit);
|
428
|
498 break;
|
|
499
|
|
500 default:
|
|
501 abort ();
|
826
|
502 def = Qnil;
|
|
503 break;
|
428
|
504 }
|
|
505
|
826
|
506 /* Avoid doubly updating the syntax table by setting the default ourselves,
|
|
507 since set_char_table_default() also updates. */
|
|
508 ct->default_ = def;
|
|
509 fill_char_table (ct, Qunbound);
|
|
510
|
428
|
511 return Qnil;
|
|
512 }
|
|
513
|
|
514 DEFUN ("make-char-table", Fmake_char_table, 1, 1, 0, /*
|
|
515 Return a new, empty char table of type TYPE.
|
800
|
516
|
|
517 A char table is a table that maps characters (or ranges of characters)
|
|
518 to values. Char tables are specialized for characters, only allowing
|
|
519 particular sorts of ranges to be assigned values. Although this
|
|
520 loses in generality, it makes for extremely fast (constant-time)
|
|
521 lookups, and thus is feasible for applications that do an extremely
|
|
522 large number of lookups (e.g. scanning a buffer for a character in
|
|
523 a particular syntax, where a lookup in the syntax table must occur
|
|
524 once per character).
|
|
525
|
|
526 When Mule support exists, the types of ranges that can be assigned
|
|
527 values are
|
|
528
|
|
529 -- all characters
|
|
530 -- an entire charset
|
|
531 -- a single row in a two-octet charset
|
|
532 -- a single character
|
|
533
|
|
534 When Mule support is not present, the types of ranges that can be
|
|
535 assigned values are
|
|
536
|
|
537 -- all characters
|
|
538 -- a single character
|
|
539
|
|
540 To create a char table, use `make-char-table'.
|
|
541 To modify a char table, use `put-char-table' or `remove-char-table'.
|
|
542 To retrieve the value for a particular character, use `get-char-table'.
|
826
|
543 See also `map-char-table', `reset-char-table', `copy-char-table',
|
800
|
544 `char-table-p', `valid-char-table-type-p', `char-table-type-list',
|
|
545 `valid-char-table-value-p', and `check-char-table-value'.
|
|
546
|
|
547 Each char table type is used for a different purpose and allows different
|
|
548 sorts of values. The different char table types are
|
|
549
|
|
550 `category'
|
|
551 Used for category tables, which specify the regexp categories
|
|
552 that a character is in. The valid values are nil or a
|
|
553 bit vector of 95 elements. Higher-level Lisp functions are
|
|
554 provided for working with category tables. Currently categories
|
|
555 and category tables only exist when Mule support is present.
|
|
556 `char'
|
|
557 A generalized char table, for mapping from one character to
|
|
558 another. Used for case tables, syntax matching tables,
|
|
559 `keyboard-translate-table', etc. The valid values are characters.
|
|
560 `generic'
|
|
561 An even more generalized char table, for mapping from a
|
|
562 character to anything.
|
|
563 `display'
|
|
564 Used for display tables, which specify how a particular character
|
|
565 is to appear when displayed. #### Not yet implemented.
|
|
566 `syntax'
|
|
567 Used for syntax tables, which specify the syntax of a particular
|
|
568 character. Higher-level Lisp functions are provided for
|
|
569 working with syntax tables. The valid values are integers.
|
428
|
570 */
|
|
571 (type))
|
|
572 {
|
440
|
573 Lisp_Char_Table *ct;
|
428
|
574 Lisp_Object obj;
|
|
575 enum char_table_type ty = symbol_to_char_table_type (type);
|
|
576
|
440
|
577 ct = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
|
428
|
578 ct->type = ty;
|
|
579 if (ty == CHAR_TABLE_TYPE_SYNTAX)
|
|
580 {
|
826
|
581 /* Qgeneric not Qsyntax because a syntax table has a mirror table
|
|
582 and we don't want infinite recursion */
|
428
|
583 ct->mirror_table = Fmake_char_table (Qgeneric);
|
826
|
584 set_char_table_default (ct->mirror_table, make_int (Spunct));
|
428
|
585 }
|
|
586 else
|
|
587 ct->mirror_table = Qnil;
|
|
588 ct->next_table = Qnil;
|
793
|
589 ct->parent = Qnil;
|
|
590 ct->default_ = Qnil;
|
|
591 obj = wrap_char_table (ct);
|
428
|
592 if (ty == CHAR_TABLE_TYPE_SYNTAX)
|
|
593 {
|
|
594 ct->next_table = Vall_syntax_tables;
|
|
595 Vall_syntax_tables = obj;
|
|
596 }
|
|
597 Freset_char_table (obj);
|
|
598 return obj;
|
|
599 }
|
|
600
|
|
601 #ifdef MULE
|
|
602
|
|
603 static Lisp_Object
|
|
604 make_char_table_entry (Lisp_Object initval)
|
|
605 {
|
|
606 int i;
|
440
|
607 Lisp_Char_Table_Entry *cte =
|
|
608 alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
|
428
|
609
|
|
610 for (i = 0; i < 96; i++)
|
|
611 cte->level2[i] = initval;
|
|
612
|
793
|
613 return wrap_char_table_entry (cte);
|
428
|
614 }
|
|
615
|
|
616 static Lisp_Object
|
|
617 copy_char_table_entry (Lisp_Object entry)
|
|
618 {
|
440
|
619 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
|
428
|
620 int i;
|
440
|
621 Lisp_Char_Table_Entry *ctenew =
|
|
622 alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
|
428
|
623
|
|
624 for (i = 0; i < 96; i++)
|
|
625 {
|
|
626 Lisp_Object new = cte->level2[i];
|
|
627 if (CHAR_TABLE_ENTRYP (new))
|
|
628 ctenew->level2[i] = copy_char_table_entry (new);
|
|
629 else
|
|
630 ctenew->level2[i] = new;
|
|
631 }
|
|
632
|
793
|
633 return wrap_char_table_entry (ctenew);
|
428
|
634 }
|
|
635
|
|
636 #endif /* MULE */
|
|
637
|
|
638 DEFUN ("copy-char-table", Fcopy_char_table, 1, 1, 0, /*
|
444
|
639 Return a new char table which is a copy of CHAR-TABLE.
|
428
|
640 It will contain the same values for the same characters and ranges
|
444
|
641 as CHAR-TABLE. The values will not themselves be copied.
|
428
|
642 */
|
444
|
643 (char_table))
|
428
|
644 {
|
440
|
645 Lisp_Char_Table *ct, *ctnew;
|
428
|
646 Lisp_Object obj;
|
|
647 int i;
|
|
648
|
444
|
649 CHECK_CHAR_TABLE (char_table);
|
|
650 ct = XCHAR_TABLE (char_table);
|
440
|
651 ctnew = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
|
428
|
652 ctnew->type = ct->type;
|
793
|
653 ctnew->parent = ct->parent;
|
|
654 ctnew->default_ = ct->default_;
|
428
|
655
|
|
656 for (i = 0; i < NUM_ASCII_CHARS; i++)
|
|
657 {
|
|
658 Lisp_Object new = ct->ascii[i];
|
|
659 #ifdef MULE
|
|
660 assert (! (CHAR_TABLE_ENTRYP (new)));
|
|
661 #endif /* MULE */
|
|
662 ctnew->ascii[i] = new;
|
|
663 }
|
|
664
|
|
665 #ifdef MULE
|
|
666
|
|
667 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
668 {
|
|
669 Lisp_Object new = ct->level1[i];
|
|
670 if (CHAR_TABLE_ENTRYP (new))
|
|
671 ctnew->level1[i] = copy_char_table_entry (new);
|
|
672 else
|
|
673 ctnew->level1[i] = new;
|
|
674 }
|
|
675
|
|
676 #endif /* MULE */
|
|
677
|
|
678 if (CHAR_TABLEP (ct->mirror_table))
|
|
679 ctnew->mirror_table = Fcopy_char_table (ct->mirror_table);
|
|
680 else
|
|
681 ctnew->mirror_table = ct->mirror_table;
|
|
682 ctnew->next_table = Qnil;
|
793
|
683 obj = wrap_char_table (ctnew);
|
428
|
684 if (ctnew->type == CHAR_TABLE_TYPE_SYNTAX)
|
|
685 {
|
|
686 ctnew->next_table = Vall_syntax_tables;
|
|
687 Vall_syntax_tables = obj;
|
|
688 }
|
|
689 return obj;
|
|
690 }
|
|
691
|
|
692 #ifdef MULE
|
|
693
|
826
|
694 /* called from get_char_table(). */
|
428
|
695 Lisp_Object
|
440
|
696 get_non_ascii_char_table_value (Lisp_Char_Table *ct, int leading_byte,
|
867
|
697 Ichar c)
|
428
|
698 {
|
|
699 Lisp_Object val;
|
826
|
700 Lisp_Object charset = charset_by_leading_byte (leading_byte);
|
428
|
701 int byte1, byte2;
|
|
702
|
867
|
703 BREAKUP_ICHAR_1_UNSAFE (c, charset, byte1, byte2);
|
428
|
704 val = ct->level1[leading_byte - MIN_LEADING_BYTE];
|
|
705 if (CHAR_TABLE_ENTRYP (val))
|
|
706 {
|
440
|
707 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
428
|
708 val = cte->level2[byte1 - 32];
|
|
709 if (CHAR_TABLE_ENTRYP (val))
|
|
710 {
|
|
711 cte = XCHAR_TABLE_ENTRY (val);
|
|
712 assert (byte2 >= 32);
|
|
713 val = cte->level2[byte2 - 32];
|
|
714 assert (!CHAR_TABLE_ENTRYP (val));
|
|
715 }
|
|
716 }
|
|
717
|
|
718 return val;
|
|
719 }
|
|
720
|
|
721 #endif /* MULE */
|
|
722
|
826
|
723 DEFUN ("char-table-default", Fchar_table_default, 1, 1, 0, /*
|
|
724 Return the default value for CHAR-TABLE. When an entry for a character
|
|
725 does not exist, the default is returned.
|
|
726 */
|
|
727 (char_table))
|
428
|
728 {
|
826
|
729 CHECK_CHAR_TABLE (char_table);
|
|
730 return XCHAR_TABLE (char_table)->default_;
|
428
|
731 }
|
|
732
|
826
|
733 DEFUN ("set-char-table-default", Fset_char_table_default, 2, 2, 0, /*
|
|
734 Set the default value for CHAR-TABLE to DEFAULT.
|
|
735 Currently, the default value for syntax tables cannot be changed.
|
|
736 (This policy might change in the future.)
|
|
737 */
|
|
738 (char_table, default_))
|
|
739 {
|
|
740 CHECK_CHAR_TABLE (char_table);
|
|
741 if (XCHAR_TABLE_TYPE (char_table) == CHAR_TABLE_TYPE_SYNTAX)
|
|
742 invalid_change ("Can't change default for syntax tables", char_table);
|
|
743 check_valid_char_table_value (default_, XCHAR_TABLE_TYPE (char_table),
|
|
744 ERROR_ME);
|
|
745 set_char_table_default (char_table, default_);
|
|
746 return Qnil;
|
|
747 }
|
428
|
748
|
|
749 DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
|
444
|
750 Find value for CHARACTER in CHAR-TABLE.
|
428
|
751 */
|
444
|
752 (character, char_table))
|
428
|
753 {
|
444
|
754 CHECK_CHAR_TABLE (char_table);
|
|
755 CHECK_CHAR_COERCE_INT (character);
|
428
|
756
|
826
|
757 return get_char_table (XCHAR (character), char_table);
|
|
758 }
|
|
759
|
|
760 static int
|
|
761 copy_mapper (struct chartab_range *range, Lisp_Object table,
|
|
762 Lisp_Object val, void *arg)
|
|
763 {
|
|
764 put_char_table (VOID_TO_LISP (arg), range, val);
|
|
765 return 0;
|
|
766 }
|
|
767
|
|
768 void
|
|
769 copy_char_table_range (Lisp_Object from, Lisp_Object to,
|
|
770 struct chartab_range *range)
|
|
771 {
|
|
772 map_char_table (from, range, copy_mapper, LISP_TO_VOID (to));
|
|
773 }
|
|
774
|
|
775 Lisp_Object
|
|
776 get_range_char_table (struct chartab_range *range, Lisp_Object table,
|
|
777 Lisp_Object multi)
|
|
778 {
|
|
779 Lisp_Char_Table *ct = XCHAR_TABLE (table);
|
|
780 Lisp_Object retval = Qnil;
|
|
781
|
|
782 switch (range->type)
|
|
783 {
|
|
784 case CHARTAB_RANGE_CHAR:
|
|
785 return get_char_table (range->ch, table);
|
|
786
|
|
787 case CHARTAB_RANGE_ALL:
|
|
788 {
|
|
789 int i;
|
|
790 retval = ct->ascii[0];
|
|
791
|
|
792 for (i = 1; i < NUM_ASCII_CHARS; i++)
|
|
793 if (!EQ (retval, ct->ascii[i]))
|
|
794 return multi;
|
|
795
|
|
796 #ifdef MULE
|
|
797 for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
|
|
798 i++)
|
|
799 {
|
|
800 if (!CHARSETP (charset_by_leading_byte (i))
|
|
801 || i == LEADING_BYTE_ASCII
|
|
802 || i == LEADING_BYTE_CONTROL_1)
|
|
803 continue;
|
|
804 if (!EQ (retval, ct->level1[i - MIN_LEADING_BYTE]))
|
|
805 return multi;
|
|
806 }
|
|
807 #endif /* MULE */
|
|
808
|
|
809 break;
|
|
810 }
|
|
811
|
|
812 #ifdef MULE
|
|
813 case CHARTAB_RANGE_CHARSET:
|
|
814 if (EQ (range->charset, Vcharset_ascii))
|
|
815 {
|
|
816 int i;
|
|
817 retval = ct->ascii[0];
|
|
818
|
|
819 for (i = 1; i < 128; i++)
|
|
820 if (!EQ (retval, ct->ascii[i]))
|
|
821 return multi;
|
|
822 break;
|
|
823 }
|
|
824
|
|
825 if (EQ (range->charset, Vcharset_control_1))
|
|
826 {
|
|
827 int i;
|
|
828 retval = ct->ascii[128];
|
|
829
|
|
830 for (i = 129; i < 160; i++)
|
|
831 if (!EQ (retval, ct->ascii[i]))
|
|
832 return multi;
|
|
833 break;
|
|
834 }
|
|
835
|
|
836 {
|
|
837 retval = ct->level1[XCHARSET_LEADING_BYTE (range->charset) -
|
|
838 MIN_LEADING_BYTE];
|
|
839 if (CHAR_TABLE_ENTRYP (retval))
|
|
840 return multi;
|
|
841 break;
|
|
842 }
|
|
843
|
|
844 case CHARTAB_RANGE_ROW:
|
|
845 {
|
|
846 retval = ct->level1[XCHARSET_LEADING_BYTE (range->charset) -
|
|
847 MIN_LEADING_BYTE];
|
|
848 if (!CHAR_TABLE_ENTRYP (retval))
|
|
849 break;
|
|
850 retval = XCHAR_TABLE_ENTRY (retval)->level2[range->row - 32];
|
|
851 if (CHAR_TABLE_ENTRYP (retval))
|
|
852 return multi;
|
|
853 break;
|
|
854 }
|
|
855 #endif /* not MULE */
|
|
856
|
|
857 default:
|
|
858 abort ();
|
|
859 }
|
|
860
|
|
861 if (UNBOUNDP (retval))
|
|
862 return ct->default_;
|
|
863 return retval;
|
428
|
864 }
|
|
865
|
|
866 DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
|
444
|
867 Find value for a range in CHAR-TABLE.
|
428
|
868 If there is more than one value, return MULTI (defaults to nil).
|
|
869 */
|
444
|
870 (range, char_table, multi))
|
428
|
871 {
|
|
872 struct chartab_range rainj;
|
|
873
|
|
874 if (CHAR_OR_CHAR_INTP (range))
|
444
|
875 return Fget_char_table (range, char_table);
|
|
876 CHECK_CHAR_TABLE (char_table);
|
428
|
877
|
|
878 decode_char_table_range (range, &rainj);
|
826
|
879 return get_range_char_table (&rainj, char_table, multi);
|
428
|
880 }
|
826
|
881
|
428
|
882 static int
|
|
883 check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
|
578
|
884 Error_Behavior errb)
|
428
|
885 {
|
|
886 switch (type)
|
|
887 {
|
|
888 case CHAR_TABLE_TYPE_SYNTAX:
|
|
889 if (!ERRB_EQ (errb, ERROR_ME))
|
|
890 return INTP (value) || (CONSP (value) && INTP (XCAR (value))
|
|
891 && CHAR_OR_CHAR_INTP (XCDR (value)));
|
|
892 if (CONSP (value))
|
|
893 {
|
|
894 Lisp_Object cdr = XCDR (value);
|
|
895 CHECK_INT (XCAR (value));
|
|
896 CHECK_CHAR_COERCE_INT (cdr);
|
|
897 }
|
|
898 else
|
|
899 CHECK_INT (value);
|
|
900 break;
|
|
901
|
|
902 #ifdef MULE
|
|
903 case CHAR_TABLE_TYPE_CATEGORY:
|
|
904 if (!ERRB_EQ (errb, ERROR_ME))
|
|
905 return CATEGORY_TABLE_VALUEP (value);
|
|
906 CHECK_CATEGORY_TABLE_VALUE (value);
|
|
907 break;
|
|
908 #endif /* MULE */
|
|
909
|
|
910 case CHAR_TABLE_TYPE_GENERIC:
|
|
911 return 1;
|
|
912
|
|
913 case CHAR_TABLE_TYPE_DISPLAY:
|
|
914 /* #### fix this */
|
563
|
915 maybe_signal_error (Qunimplemented,
|
|
916 "Display char tables not yet implemented",
|
|
917 value, Qchar_table, errb);
|
428
|
918 return 0;
|
|
919
|
|
920 case CHAR_TABLE_TYPE_CHAR:
|
|
921 if (!ERRB_EQ (errb, ERROR_ME))
|
|
922 return CHAR_OR_CHAR_INTP (value);
|
|
923 CHECK_CHAR_COERCE_INT (value);
|
|
924 break;
|
|
925
|
|
926 default:
|
|
927 abort ();
|
|
928 }
|
|
929
|
801
|
930 return 0; /* not (usually) reached */
|
428
|
931 }
|
|
932
|
|
933 static Lisp_Object
|
|
934 canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
|
|
935 {
|
|
936 switch (type)
|
|
937 {
|
|
938 case CHAR_TABLE_TYPE_SYNTAX:
|
|
939 if (CONSP (value))
|
|
940 {
|
|
941 Lisp_Object car = XCAR (value);
|
|
942 Lisp_Object cdr = XCDR (value);
|
|
943 CHECK_CHAR_COERCE_INT (cdr);
|
|
944 return Fcons (car, cdr);
|
|
945 }
|
|
946 break;
|
|
947 case CHAR_TABLE_TYPE_CHAR:
|
|
948 CHECK_CHAR_COERCE_INT (value);
|
|
949 break;
|
|
950 default:
|
|
951 break;
|
|
952 }
|
|
953 return value;
|
|
954 }
|
|
955
|
|
956 DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
|
|
957 Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
|
|
958 */
|
|
959 (value, char_table_type))
|
|
960 {
|
|
961 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
962
|
|
963 return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
|
|
964 }
|
|
965
|
|
966 DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
|
|
967 Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
|
|
968 */
|
|
969 (value, char_table_type))
|
|
970 {
|
|
971 enum char_table_type type = symbol_to_char_table_type (char_table_type);
|
|
972
|
|
973 check_valid_char_table_value (value, type, ERROR_ME);
|
|
974 return Qnil;
|
|
975 }
|
|
976
|
826
|
977 /* Assign VAL to all characters in RANGE in char table TABLE. */
|
428
|
978
|
|
979 void
|
826
|
980 put_char_table (Lisp_Object table, struct chartab_range *range,
|
428
|
981 Lisp_Object val)
|
|
982 {
|
826
|
983 Lisp_Char_Table *ct = XCHAR_TABLE (table);
|
|
984
|
428
|
985 switch (range->type)
|
|
986 {
|
|
987 case CHARTAB_RANGE_ALL:
|
|
988 fill_char_table (ct, val);
|
|
989 return; /* avoid the duplicate call to update_syntax_table() below,
|
|
990 since fill_char_table() also did that. */
|
|
991
|
|
992 #ifdef MULE
|
|
993 case CHARTAB_RANGE_CHARSET:
|
|
994 if (EQ (range->charset, Vcharset_ascii))
|
|
995 {
|
|
996 int i;
|
|
997 for (i = 0; i < 128; i++)
|
|
998 ct->ascii[i] = val;
|
|
999 }
|
|
1000 else if (EQ (range->charset, Vcharset_control_1))
|
|
1001 {
|
|
1002 int i;
|
|
1003 for (i = 128; i < 160; i++)
|
|
1004 ct->ascii[i] = val;
|
|
1005 }
|
|
1006 else
|
|
1007 {
|
|
1008 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
|
1009 ct->level1[lb] = val;
|
|
1010 }
|
|
1011 break;
|
|
1012
|
|
1013 case CHARTAB_RANGE_ROW:
|
|
1014 {
|
440
|
1015 Lisp_Char_Table_Entry *cte;
|
428
|
1016 int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
|
|
1017 /* make sure that there is a separate entry for the row. */
|
|
1018 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1019 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1020 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1021 cte->level2[range->row - 32] = val;
|
|
1022 }
|
|
1023 break;
|
|
1024 #endif /* MULE */
|
|
1025
|
|
1026 case CHARTAB_RANGE_CHAR:
|
|
1027 #ifdef MULE
|
|
1028 {
|
|
1029 Lisp_Object charset;
|
|
1030 int byte1, byte2;
|
|
1031
|
867
|
1032 BREAKUP_ICHAR (range->ch, charset, byte1, byte2);
|
428
|
1033 if (EQ (charset, Vcharset_ascii))
|
|
1034 ct->ascii[byte1] = val;
|
|
1035 else if (EQ (charset, Vcharset_control_1))
|
|
1036 ct->ascii[byte1 + 128] = val;
|
|
1037 else
|
|
1038 {
|
440
|
1039 Lisp_Char_Table_Entry *cte;
|
428
|
1040 int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
|
|
1041 /* make sure that there is a separate entry for the row. */
|
|
1042 if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
|
|
1043 ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
|
|
1044 cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
|
|
1045 /* now CTE is a char table entry for the charset;
|
|
1046 each entry is for a single row (or character of
|
|
1047 a one-octet charset). */
|
|
1048 if (XCHARSET_DIMENSION (charset) == 1)
|
|
1049 cte->level2[byte1 - 32] = val;
|
|
1050 else
|
|
1051 {
|
|
1052 /* assigning to one character in a two-octet charset. */
|
|
1053 /* make sure that the charset row contains a separate
|
|
1054 entry for each character. */
|
|
1055 if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
|
|
1056 cte->level2[byte1 - 32] =
|
|
1057 make_char_table_entry (cte->level2[byte1 - 32]);
|
|
1058 cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
|
|
1059 cte->level2[byte2 - 32] = val;
|
|
1060 }
|
|
1061 }
|
|
1062 }
|
|
1063 #else /* not MULE */
|
|
1064 ct->ascii[(unsigned char) (range->ch)] = val;
|
|
1065 break;
|
|
1066 #endif /* not MULE */
|
|
1067 }
|
|
1068
|
|
1069 if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
|
826
|
1070 update_syntax_table (wrap_char_table (ct));
|
428
|
1071 }
|
|
1072
|
|
1073 DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
|
444
|
1074 Set the value for chars in RANGE to be VALUE in CHAR-TABLE.
|
428
|
1075
|
|
1076 RANGE specifies one or more characters to be affected and should be
|
|
1077 one of the following:
|
|
1078
|
|
1079 -- t (all characters are affected)
|
|
1080 -- A charset (only allowed when Mule support is present)
|
|
1081 -- A vector of two elements: a two-octet charset and a row number
|
|
1082 (only allowed when Mule support is present)
|
|
1083 -- A single character
|
|
1084
|
444
|
1085 VALUE must be a value appropriate for the type of CHAR-TABLE.
|
800
|
1086 See `make-char-table'.
|
428
|
1087 */
|
444
|
1088 (range, value, char_table))
|
428
|
1089 {
|
440
|
1090 Lisp_Char_Table *ct;
|
428
|
1091 struct chartab_range rainj;
|
|
1092
|
444
|
1093 CHECK_CHAR_TABLE (char_table);
|
|
1094 ct = XCHAR_TABLE (char_table);
|
|
1095 check_valid_char_table_value (value, ct->type, ERROR_ME);
|
428
|
1096 decode_char_table_range (range, &rainj);
|
444
|
1097 value = canonicalize_char_table_value (value, ct->type);
|
826
|
1098 put_char_table (char_table, &rainj, value);
|
|
1099 return Qnil;
|
|
1100 }
|
|
1101
|
|
1102 DEFUN ("remove-char-table", Fremove_char_table, 2, 2, 0, /*
|
|
1103 Remove any value from chars in RANGE in CHAR-TABLE.
|
|
1104
|
|
1105 RANGE specifies one or more characters to be affected and should be
|
|
1106 one of the following:
|
|
1107
|
|
1108 -- t (all characters are affected)
|
|
1109 -- A charset (only allowed when Mule support is present)
|
|
1110 -- A vector of two elements: a two-octet charset and a row number
|
|
1111 (only allowed when Mule support is present)
|
|
1112 -- A single character
|
|
1113
|
|
1114 With the values removed, the default value will be returned.
|
|
1115 */
|
|
1116 (range, char_table))
|
|
1117 {
|
|
1118 struct chartab_range rainj;
|
|
1119
|
|
1120 CHECK_CHAR_TABLE (char_table);
|
|
1121 decode_char_table_range (range, &rainj);
|
|
1122 put_char_table (char_table, &rainj, Qunbound);
|
428
|
1123 return Qnil;
|
|
1124 }
|
|
1125
|
|
1126 /* Map FN over the ASCII chars in CT. */
|
|
1127
|
|
1128 static int
|
826
|
1129 map_over_charset_ascii_1 (Lisp_Char_Table *ct,
|
|
1130 int start, int stop,
|
|
1131 int (*fn) (struct chartab_range *range,
|
|
1132 Lisp_Object table, Lisp_Object val,
|
|
1133 void *arg),
|
|
1134 void *arg)
|
|
1135 {
|
|
1136 struct chartab_range rainj;
|
|
1137 int i, retval;
|
|
1138
|
|
1139 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1140
|
|
1141 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
|
1142 {
|
867
|
1143 rainj.ch = (Ichar) i;
|
826
|
1144 if (!UNBOUNDP (ct->ascii[i]))
|
|
1145 retval = (fn) (&rainj, wrap_char_table (ct), ct->ascii[i], arg);
|
|
1146 }
|
|
1147
|
|
1148 return retval;
|
|
1149 }
|
|
1150
|
|
1151
|
|
1152 /* Map FN over the ASCII chars in CT. */
|
|
1153
|
|
1154 static int
|
440
|
1155 map_over_charset_ascii (Lisp_Char_Table *ct,
|
428
|
1156 int (*fn) (struct chartab_range *range,
|
826
|
1157 Lisp_Object table, Lisp_Object val,
|
|
1158 void *arg),
|
428
|
1159 void *arg)
|
|
1160 {
|
826
|
1161 return map_over_charset_ascii_1 (ct, 0,
|
428
|
1162 #ifdef MULE
|
826
|
1163 127,
|
428
|
1164 #else
|
826
|
1165 255,
|
428
|
1166 #endif
|
826
|
1167 fn, arg);
|
428
|
1168 }
|
|
1169
|
|
1170 #ifdef MULE
|
|
1171
|
|
1172 /* Map FN over the Control-1 chars in CT. */
|
|
1173
|
|
1174 static int
|
440
|
1175 map_over_charset_control_1 (Lisp_Char_Table *ct,
|
428
|
1176 int (*fn) (struct chartab_range *range,
|
826
|
1177 Lisp_Object table, Lisp_Object val,
|
|
1178 void *arg),
|
428
|
1179 void *arg)
|
|
1180 {
|
826
|
1181 return map_over_charset_ascii_1 (ct, 128, 159, fn, arg);
|
428
|
1182 }
|
|
1183
|
|
1184 /* Map FN over the row ROW of two-byte charset CHARSET.
|
|
1185 There must be a separate value for that row in the char table.
|
|
1186 CTE specifies the char table entry for CHARSET. */
|
|
1187
|
|
1188 static int
|
826
|
1189 map_over_charset_row (Lisp_Char_Table *ct,
|
|
1190 Lisp_Char_Table_Entry *cte,
|
428
|
1191 Lisp_Object charset, int row,
|
|
1192 int (*fn) (struct chartab_range *range,
|
826
|
1193 Lisp_Object table, Lisp_Object val,
|
|
1194 void *arg),
|
428
|
1195 void *arg)
|
|
1196 {
|
|
1197 Lisp_Object val = cte->level2[row - 32];
|
|
1198
|
826
|
1199 if (UNBOUNDP (val))
|
|
1200 return 0;
|
|
1201 else if (!CHAR_TABLE_ENTRYP (val))
|
428
|
1202 {
|
|
1203 struct chartab_range rainj;
|
826
|
1204
|
428
|
1205 rainj.type = CHARTAB_RANGE_ROW;
|
|
1206 rainj.charset = charset;
|
|
1207 rainj.row = row;
|
826
|
1208 return (fn) (&rainj, wrap_char_table (ct), val, arg);
|
428
|
1209 }
|
|
1210 else
|
|
1211 {
|
|
1212 struct chartab_range rainj;
|
|
1213 int i, retval;
|
826
|
1214 int start, stop;
|
|
1215
|
|
1216 get_charset_limits (charset, &start, &stop);
|
428
|
1217
|
|
1218 cte = XCHAR_TABLE_ENTRY (val);
|
|
1219
|
|
1220 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1221
|
826
|
1222 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
428
|
1223 {
|
867
|
1224 rainj.ch = make_ichar (charset, row, i);
|
826
|
1225 if (!UNBOUNDP (cte->level2[i - 32]))
|
|
1226 retval = (fn) (&rainj, wrap_char_table (ct), cte->level2[i - 32],
|
|
1227 arg);
|
428
|
1228 }
|
|
1229 return retval;
|
|
1230 }
|
|
1231 }
|
|
1232
|
|
1233
|
|
1234 static int
|
440
|
1235 map_over_other_charset (Lisp_Char_Table *ct, int lb,
|
428
|
1236 int (*fn) (struct chartab_range *range,
|
826
|
1237 Lisp_Object table, Lisp_Object val,
|
|
1238 void *arg),
|
428
|
1239 void *arg)
|
|
1240 {
|
|
1241 Lisp_Object val = ct->level1[lb - MIN_LEADING_BYTE];
|
826
|
1242 Lisp_Object charset = charset_by_leading_byte (lb);
|
428
|
1243
|
|
1244 if (!CHARSETP (charset)
|
|
1245 || lb == LEADING_BYTE_ASCII
|
|
1246 || lb == LEADING_BYTE_CONTROL_1)
|
|
1247 return 0;
|
|
1248
|
826
|
1249 if (UNBOUNDP (val))
|
|
1250 return 0;
|
428
|
1251 if (!CHAR_TABLE_ENTRYP (val))
|
|
1252 {
|
|
1253 struct chartab_range rainj;
|
|
1254
|
|
1255 rainj.type = CHARTAB_RANGE_CHARSET;
|
|
1256 rainj.charset = charset;
|
826
|
1257 return (fn) (&rainj, wrap_char_table (ct), val, arg);
|
428
|
1258 }
|
|
1259 {
|
440
|
1260 Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
|
826
|
1261 int start, stop;
|
428
|
1262 int i, retval;
|
|
1263
|
826
|
1264 get_charset_limits (charset, &start, &stop);
|
428
|
1265 if (XCHARSET_DIMENSION (charset) == 1)
|
|
1266 {
|
|
1267 struct chartab_range rainj;
|
|
1268 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1269
|
826
|
1270 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
428
|
1271 {
|
867
|
1272 rainj.ch = make_ichar (charset, i, 0);
|
826
|
1273 if (!UNBOUNDP (cte->level2[i - 32]))
|
|
1274 retval = (fn) (&rainj, wrap_char_table (ct), cte->level2[i - 32],
|
|
1275 arg);
|
428
|
1276 }
|
|
1277 }
|
|
1278 else
|
|
1279 {
|
826
|
1280 for (i = start, retval = 0; i <= stop && retval == 0; i++)
|
|
1281 retval = map_over_charset_row (ct, cte, charset, i, fn, arg);
|
428
|
1282 }
|
|
1283
|
|
1284 return retval;
|
|
1285 }
|
|
1286 }
|
|
1287
|
|
1288 #endif /* MULE */
|
|
1289
|
|
1290 /* Map FN (with client data ARG) over range RANGE in char table CT.
|
|
1291 Mapping stops the first time FN returns non-zero, and that value
|
826
|
1292 becomes the return value of map_char_table().
|
|
1293
|
|
1294 #### This mapping code is way ugly. The FSF version, in contrast,
|
|
1295 is short and sweet, and much more recursive. There should be some way
|
|
1296 of cleaning this up. */
|
428
|
1297
|
|
1298 int
|
826
|
1299 map_char_table (Lisp_Object table,
|
428
|
1300 struct chartab_range *range,
|
|
1301 int (*fn) (struct chartab_range *range,
|
826
|
1302 Lisp_Object table, Lisp_Object val, void *arg),
|
428
|
1303 void *arg)
|
|
1304 {
|
826
|
1305 Lisp_Char_Table *ct = XCHAR_TABLE (table);
|
428
|
1306 switch (range->type)
|
|
1307 {
|
|
1308 case CHARTAB_RANGE_ALL:
|
|
1309 {
|
|
1310 int retval;
|
|
1311
|
|
1312 retval = map_over_charset_ascii (ct, fn, arg);
|
|
1313 if (retval)
|
|
1314 return retval;
|
|
1315 #ifdef MULE
|
|
1316 retval = map_over_charset_control_1 (ct, fn, arg);
|
|
1317 if (retval)
|
|
1318 return retval;
|
|
1319 {
|
|
1320 int i;
|
|
1321 int start = MIN_LEADING_BYTE;
|
|
1322 int stop = start + NUM_LEADING_BYTES;
|
|
1323
|
|
1324 for (i = start, retval = 0; i < stop && retval == 0; i++)
|
|
1325 {
|
771
|
1326 if (i != LEADING_BYTE_ASCII && i != LEADING_BYTE_CONTROL_1)
|
|
1327 retval = map_over_other_charset (ct, i, fn, arg);
|
428
|
1328 }
|
|
1329 }
|
|
1330 #endif /* MULE */
|
|
1331 return retval;
|
|
1332 }
|
|
1333
|
|
1334 #ifdef MULE
|
|
1335 case CHARTAB_RANGE_CHARSET:
|
|
1336 return map_over_other_charset (ct,
|
|
1337 XCHARSET_LEADING_BYTE (range->charset),
|
|
1338 fn, arg);
|
|
1339
|
|
1340 case CHARTAB_RANGE_ROW:
|
|
1341 {
|
771
|
1342 Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (range->charset) -
|
|
1343 MIN_LEADING_BYTE];
|
826
|
1344
|
|
1345 if (CHAR_TABLE_ENTRYP (val))
|
|
1346 return map_over_charset_row (ct, XCHAR_TABLE_ENTRY (val),
|
|
1347 range->charset, range->row, fn, arg);
|
|
1348 else if (!UNBOUNDP (val))
|
428
|
1349 {
|
|
1350 struct chartab_range rainj;
|
|
1351
|
|
1352 rainj.type = CHARTAB_RANGE_ROW;
|
|
1353 rainj.charset = range->charset;
|
|
1354 rainj.row = range->row;
|
826
|
1355 return (fn) (&rainj, table, val, arg);
|
428
|
1356 }
|
|
1357 else
|
826
|
1358 return 0;
|
428
|
1359 }
|
|
1360 #endif /* MULE */
|
|
1361
|
|
1362 case CHARTAB_RANGE_CHAR:
|
|
1363 {
|
867
|
1364 Ichar ch = range->ch;
|
826
|
1365 Lisp_Object val = get_char_table (ch, table);
|
428
|
1366 struct chartab_range rainj;
|
|
1367
|
826
|
1368 if (!UNBOUNDP (val))
|
|
1369 {
|
|
1370 rainj.type = CHARTAB_RANGE_CHAR;
|
|
1371 rainj.ch = ch;
|
|
1372 return (fn) (&rainj, table, val, arg);
|
|
1373 }
|
|
1374 else
|
|
1375 return 0;
|
428
|
1376 }
|
|
1377
|
|
1378 default:
|
|
1379 abort ();
|
|
1380 }
|
|
1381
|
|
1382 return 0;
|
|
1383 }
|
|
1384
|
|
1385 struct slow_map_char_table_arg
|
|
1386 {
|
|
1387 Lisp_Object function;
|
|
1388 Lisp_Object retval;
|
|
1389 };
|
|
1390
|
|
1391 static int
|
|
1392 slow_map_char_table_fun (struct chartab_range *range,
|
826
|
1393 Lisp_Object table, Lisp_Object val, void *arg)
|
428
|
1394 {
|
|
1395 struct slow_map_char_table_arg *closure =
|
|
1396 (struct slow_map_char_table_arg *) arg;
|
|
1397
|
826
|
1398 closure->retval = call2 (closure->function, encode_char_table_range (range),
|
|
1399 val);
|
428
|
1400 return !NILP (closure->retval);
|
|
1401 }
|
|
1402
|
|
1403 DEFUN ("map-char-table", Fmap_char_table, 2, 3, 0, /*
|
444
|
1404 Map FUNCTION over entries in CHAR-TABLE, calling it with two args,
|
428
|
1405 each key and value in the table.
|
|
1406
|
|
1407 RANGE specifies a subrange to map over and is in the same format as
|
|
1408 the RANGE argument to `put-range-table'. If omitted or t, it defaults to
|
|
1409 the entire table.
|
|
1410 */
|
444
|
1411 (function, char_table, range))
|
428
|
1412 {
|
|
1413 struct slow_map_char_table_arg slarg;
|
|
1414 struct gcpro gcpro1, gcpro2;
|
|
1415 struct chartab_range rainj;
|
|
1416
|
444
|
1417 CHECK_CHAR_TABLE (char_table);
|
428
|
1418 if (NILP (range))
|
|
1419 range = Qt;
|
|
1420 decode_char_table_range (range, &rainj);
|
|
1421 slarg.function = function;
|
|
1422 slarg.retval = Qnil;
|
|
1423 GCPRO2 (slarg.function, slarg.retval);
|
826
|
1424 map_char_table (char_table, &rainj, slow_map_char_table_fun, &slarg);
|
428
|
1425 UNGCPRO;
|
|
1426
|
|
1427 return slarg.retval;
|
|
1428 }
|
|
1429
|
|
1430
|
|
1431
|
|
1432 /************************************************************************/
|
|
1433 /* Char table read syntax */
|
|
1434 /************************************************************************/
|
|
1435
|
|
1436 static int
|
|
1437 chartab_type_validate (Lisp_Object keyword, Lisp_Object value,
|
578
|
1438 Error_Behavior errb)
|
428
|
1439 {
|
|
1440 /* #### should deal with ERRB */
|
|
1441 symbol_to_char_table_type (value);
|
|
1442 return 1;
|
|
1443 }
|
|
1444
|
826
|
1445 /* #### Document the print/read format; esp. what's this cons element? */
|
|
1446
|
428
|
1447 static int
|
|
1448 chartab_data_validate (Lisp_Object keyword, Lisp_Object value,
|
578
|
1449 Error_Behavior errb)
|
428
|
1450 {
|
|
1451 Lisp_Object rest;
|
|
1452
|
|
1453 /* #### should deal with ERRB */
|
|
1454 EXTERNAL_LIST_LOOP (rest, value)
|
|
1455 {
|
|
1456 Lisp_Object range = XCAR (rest);
|
|
1457 struct chartab_range dummy;
|
|
1458
|
|
1459 rest = XCDR (rest);
|
|
1460 if (!CONSP (rest))
|
563
|
1461 signal_error (Qlist_formation_error, "Invalid list format", value);
|
428
|
1462 if (CONSP (range))
|
|
1463 {
|
|
1464 if (!CONSP (XCDR (range))
|
|
1465 || !NILP (XCDR (XCDR (range))))
|
563
|
1466 sferror ("Invalid range format", range);
|
428
|
1467 decode_char_table_range (XCAR (range), &dummy);
|
|
1468 decode_char_table_range (XCAR (XCDR (range)), &dummy);
|
|
1469 }
|
|
1470 else
|
|
1471 decode_char_table_range (range, &dummy);
|
|
1472 }
|
|
1473
|
|
1474 return 1;
|
|
1475 }
|
|
1476
|
|
1477 static Lisp_Object
|
|
1478 chartab_instantiate (Lisp_Object data)
|
|
1479 {
|
|
1480 Lisp_Object chartab;
|
|
1481 Lisp_Object type = Qgeneric;
|
|
1482 Lisp_Object dataval = Qnil;
|
|
1483
|
|
1484 while (!NILP (data))
|
|
1485 {
|
|
1486 Lisp_Object keyw = Fcar (data);
|
|
1487 Lisp_Object valw;
|
|
1488
|
|
1489 data = Fcdr (data);
|
|
1490 valw = Fcar (data);
|
|
1491 data = Fcdr (data);
|
|
1492 if (EQ (keyw, Qtype))
|
|
1493 type = valw;
|
|
1494 else if (EQ (keyw, Qdata))
|
|
1495 dataval = valw;
|
|
1496 }
|
|
1497
|
|
1498 chartab = Fmake_char_table (type);
|
|
1499
|
|
1500 data = dataval;
|
|
1501 while (!NILP (data))
|
|
1502 {
|
|
1503 Lisp_Object range = Fcar (data);
|
|
1504 Lisp_Object val = Fcar (Fcdr (data));
|
|
1505
|
|
1506 data = Fcdr (Fcdr (data));
|
|
1507 if (CONSP (range))
|
|
1508 {
|
|
1509 if (CHAR_OR_CHAR_INTP (XCAR (range)))
|
|
1510 {
|
867
|
1511 Ichar first = XCHAR_OR_CHAR_INT (Fcar (range));
|
|
1512 Ichar last = XCHAR_OR_CHAR_INT (Fcar (Fcdr (range)));
|
|
1513 Ichar i;
|
428
|
1514
|
|
1515 for (i = first; i <= last; i++)
|
|
1516 Fput_char_table (make_char (i), val, chartab);
|
|
1517 }
|
|
1518 else
|
|
1519 abort ();
|
|
1520 }
|
|
1521 else
|
|
1522 Fput_char_table (range, val, chartab);
|
|
1523 }
|
|
1524
|
|
1525 return chartab;
|
|
1526 }
|
|
1527
|
|
1528 #ifdef MULE
|
|
1529
|
|
1530
|
|
1531 /************************************************************************/
|
|
1532 /* Category Tables, specifically */
|
|
1533 /************************************************************************/
|
|
1534
|
|
1535 DEFUN ("category-table-p", Fcategory_table_p, 1, 1, 0, /*
|
444
|
1536 Return t if OBJECT is a category table.
|
428
|
1537 A category table is a type of char table used for keeping track of
|
|
1538 categories. Categories are used for classifying characters for use
|
|
1539 in regexps -- you can refer to a category rather than having to use
|
|
1540 a complicated [] expression (and category lookups are significantly
|
|
1541 faster).
|
|
1542
|
|
1543 There are 95 different categories available, one for each printable
|
|
1544 character (including space) in the ASCII charset. Each category
|
|
1545 is designated by one such character, called a "category designator".
|
|
1546 They are specified in a regexp using the syntax "\\cX", where X is
|
|
1547 a category designator.
|
|
1548
|
|
1549 A category table specifies, for each character, the categories that
|
|
1550 the character is in. Note that a character can be in more than one
|
|
1551 category. More specifically, a category table maps from a character
|
|
1552 to either the value nil (meaning the character is in no categories)
|
|
1553 or a 95-element bit vector, specifying for each of the 95 categories
|
|
1554 whether the character is in that category.
|
|
1555
|
|
1556 Special Lisp functions are provided that abstract this, so you do not
|
|
1557 have to directly manipulate bit vectors.
|
|
1558 */
|
444
|
1559 (object))
|
428
|
1560 {
|
444
|
1561 return (CHAR_TABLEP (object) &&
|
|
1562 XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_CATEGORY) ?
|
428
|
1563 Qt : Qnil;
|
|
1564 }
|
|
1565
|
|
1566 static Lisp_Object
|
444
|
1567 check_category_table (Lisp_Object object, Lisp_Object default_)
|
428
|
1568 {
|
444
|
1569 if (NILP (object))
|
|
1570 object = default_;
|
|
1571 while (NILP (Fcategory_table_p (object)))
|
|
1572 object = wrong_type_argument (Qcategory_table_p, object);
|
|
1573 return object;
|
428
|
1574 }
|
|
1575
|
|
1576 int
|
867
|
1577 check_category_char (Ichar ch, Lisp_Object table,
|
647
|
1578 int designator, int not_p)
|
428
|
1579 {
|
|
1580 REGISTER Lisp_Object temp;
|
|
1581 if (NILP (Fcategory_table_p (table)))
|
563
|
1582 wtaerror ("Expected category table", table);
|
826
|
1583 temp = get_char_table (ch, table);
|
428
|
1584 if (NILP (temp))
|
458
|
1585 return not_p;
|
428
|
1586
|
|
1587 designator -= ' ';
|
458
|
1588 return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not_p : not_p;
|
428
|
1589 }
|
|
1590
|
|
1591 DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*
|
444
|
1592 Return t if category of the character at POSITION includes DESIGNATOR.
|
|
1593 Optional third arg BUFFER specifies which buffer to use, and defaults
|
|
1594 to the current buffer.
|
|
1595 Optional fourth arg CATEGORY-TABLE specifies the category table to
|
|
1596 use, and defaults to BUFFER's category table.
|
428
|
1597 */
|
444
|
1598 (position, designator, buffer, category_table))
|
428
|
1599 {
|
|
1600 Lisp_Object ctbl;
|
867
|
1601 Ichar ch;
|
647
|
1602 int des;
|
428
|
1603 struct buffer *buf = decode_buffer (buffer, 0);
|
|
1604
|
444
|
1605 CHECK_INT (position);
|
428
|
1606 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1607 des = XCHAR (designator);
|
788
|
1608 ctbl = check_category_table (category_table, buf->category_table);
|
444
|
1609 ch = BUF_FETCH_CHAR (buf, XINT (position));
|
428
|
1610 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
|
|
1611 }
|
|
1612
|
|
1613 DEFUN ("char-in-category-p", Fchar_in_category_p, 2, 3, 0, /*
|
788
|
1614 Return non-nil if category of CHARACTER includes DESIGNATOR.
|
444
|
1615 Optional third arg CATEGORY-TABLE specifies the category table to use,
|
788
|
1616 and defaults to the current buffer's category table.
|
428
|
1617 */
|
444
|
1618 (character, designator, category_table))
|
428
|
1619 {
|
|
1620 Lisp_Object ctbl;
|
867
|
1621 Ichar ch;
|
647
|
1622 int des;
|
428
|
1623
|
|
1624 CHECK_CATEGORY_DESIGNATOR (designator);
|
|
1625 des = XCHAR (designator);
|
444
|
1626 CHECK_CHAR (character);
|
|
1627 ch = XCHAR (character);
|
788
|
1628 ctbl = check_category_table (category_table, current_buffer->category_table);
|
428
|
1629 return check_category_char (ch, ctbl, des, 0) ? Qt : Qnil;
|
|
1630 }
|
|
1631
|
|
1632 DEFUN ("category-table", Fcategory_table, 0, 1, 0, /*
|
444
|
1633 Return BUFFER's current category table.
|
|
1634 BUFFER defaults to the current buffer.
|
428
|
1635 */
|
|
1636 (buffer))
|
|
1637 {
|
|
1638 return decode_buffer (buffer, 0)->category_table;
|
|
1639 }
|
|
1640
|
|
1641 DEFUN ("standard-category-table", Fstandard_category_table, 0, 0, 0, /*
|
|
1642 Return the standard category table.
|
|
1643 This is the one used for new buffers.
|
|
1644 */
|
|
1645 ())
|
|
1646 {
|
|
1647 return Vstandard_category_table;
|
|
1648 }
|
|
1649
|
|
1650 DEFUN ("copy-category-table", Fcopy_category_table, 0, 1, 0, /*
|
444
|
1651 Return a new category table which is a copy of CATEGORY-TABLE.
|
|
1652 CATEGORY-TABLE defaults to the standard category table.
|
428
|
1653 */
|
444
|
1654 (category_table))
|
428
|
1655 {
|
|
1656 if (NILP (Vstandard_category_table))
|
|
1657 return Fmake_char_table (Qcategory);
|
|
1658
|
444
|
1659 category_table =
|
|
1660 check_category_table (category_table, Vstandard_category_table);
|
|
1661 return Fcopy_char_table (category_table);
|
428
|
1662 }
|
|
1663
|
|
1664 DEFUN ("set-category-table", Fset_category_table, 1, 2, 0, /*
|
444
|
1665 Select CATEGORY-TABLE as the new category table for BUFFER.
|
428
|
1666 BUFFER defaults to the current buffer if omitted.
|
|
1667 */
|
444
|
1668 (category_table, buffer))
|
428
|
1669 {
|
|
1670 struct buffer *buf = decode_buffer (buffer, 0);
|
444
|
1671 category_table = check_category_table (category_table, Qnil);
|
|
1672 buf->category_table = category_table;
|
428
|
1673 /* Indicate that this buffer now has a specified category table. */
|
|
1674 buf->local_var_flags |= XINT (buffer_local_flags.category_table);
|
444
|
1675 return category_table;
|
428
|
1676 }
|
|
1677
|
|
1678 DEFUN ("category-designator-p", Fcategory_designator_p, 1, 1, 0, /*
|
444
|
1679 Return t if OBJECT is a category designator (a char in the range ' ' to '~').
|
428
|
1680 */
|
444
|
1681 (object))
|
428
|
1682 {
|
444
|
1683 return CATEGORY_DESIGNATORP (object) ? Qt : Qnil;
|
428
|
1684 }
|
|
1685
|
|
1686 DEFUN ("category-table-value-p", Fcategory_table_value_p, 1, 1, 0, /*
|
444
|
1687 Return t if OBJECT is a category table value.
|
428
|
1688 Valid values are nil or a bit vector of size 95.
|
|
1689 */
|
444
|
1690 (object))
|
428
|
1691 {
|
444
|
1692 return CATEGORY_TABLE_VALUEP (object) ? Qt : Qnil;
|
428
|
1693 }
|
|
1694
|
|
1695
|
|
1696 #define CATEGORYP(x) \
|
|
1697 (CHARP (x) && XCHAR (x) >= 0x20 && XCHAR (x) <= 0x7E)
|
|
1698
|
826
|
1699 #define CATEGORY_SET(c) get_char_table (c, current_buffer->category_table)
|
428
|
1700
|
|
1701 /* Return 1 if CATEGORY_SET contains CATEGORY, else return 0.
|
|
1702 The faster version of `!NILP (Faref (category_set, category))'. */
|
|
1703 #define CATEGORY_MEMBER(category, category_set) \
|
|
1704 (bit_vector_bit(XBIT_VECTOR (category_set), category - 32))
|
|
1705
|
|
1706 /* Return 1 if there is a word boundary between two word-constituent
|
|
1707 characters C1 and C2 if they appear in this order, else return 0.
|
|
1708 Use the macro WORD_BOUNDARY_P instead of calling this function
|
|
1709 directly. */
|
|
1710
|
|
1711 int
|
867
|
1712 word_boundary_p (Ichar c1, Ichar c2)
|
428
|
1713 {
|
|
1714 Lisp_Object category_set1, category_set2;
|
|
1715 Lisp_Object tail;
|
|
1716 int default_result;
|
|
1717
|
|
1718 #if 0
|
|
1719 if (COMPOSITE_CHAR_P (c1))
|
|
1720 c1 = cmpchar_component (c1, 0, 1);
|
|
1721 if (COMPOSITE_CHAR_P (c2))
|
|
1722 c2 = cmpchar_component (c2, 0, 1);
|
|
1723 #endif
|
|
1724
|
867
|
1725 if (EQ (ichar_charset (c1), ichar_charset (c2)))
|
428
|
1726 {
|
|
1727 tail = Vword_separating_categories;
|
|
1728 default_result = 0;
|
|
1729 }
|
|
1730 else
|
|
1731 {
|
|
1732 tail = Vword_combining_categories;
|
|
1733 default_result = 1;
|
|
1734 }
|
|
1735
|
|
1736 category_set1 = CATEGORY_SET (c1);
|
|
1737 if (NILP (category_set1))
|
|
1738 return default_result;
|
|
1739 category_set2 = CATEGORY_SET (c2);
|
|
1740 if (NILP (category_set2))
|
|
1741 return default_result;
|
|
1742
|
853
|
1743 for (; CONSP (tail); tail = XCDR (tail))
|
428
|
1744 {
|
853
|
1745 Lisp_Object elt = XCAR (tail);
|
428
|
1746
|
|
1747 if (CONSP (elt)
|
853
|
1748 && CATEGORYP (XCAR (elt))
|
|
1749 && CATEGORYP (XCDR (elt))
|
|
1750 && CATEGORY_MEMBER (XCHAR (XCAR (elt)), category_set1)
|
|
1751 && CATEGORY_MEMBER (XCHAR (XCDR (elt)), category_set2))
|
428
|
1752 return !default_result;
|
|
1753 }
|
|
1754 return default_result;
|
|
1755 }
|
|
1756 #endif /* MULE */
|
|
1757
|
|
1758
|
|
1759 void
|
|
1760 syms_of_chartab (void)
|
|
1761 {
|
442
|
1762 INIT_LRECORD_IMPLEMENTATION (char_table);
|
|
1763
|
428
|
1764 #ifdef MULE
|
442
|
1765 INIT_LRECORD_IMPLEMENTATION (char_table_entry);
|
|
1766
|
563
|
1767 DEFSYMBOL (Qcategory_table_p);
|
|
1768 DEFSYMBOL (Qcategory_designator_p);
|
|
1769 DEFSYMBOL (Qcategory_table_value_p);
|
428
|
1770 #endif /* MULE */
|
|
1771
|
563
|
1772 DEFSYMBOL (Qchar_table);
|
|
1773 DEFSYMBOL_MULTIWORD_PREDICATE (Qchar_tablep);
|
428
|
1774
|
|
1775 DEFSUBR (Fchar_table_p);
|
|
1776 DEFSUBR (Fchar_table_type_list);
|
|
1777 DEFSUBR (Fvalid_char_table_type_p);
|
|
1778 DEFSUBR (Fchar_table_type);
|
826
|
1779 DEFSUBR (Fchar_table_default);
|
|
1780 DEFSUBR (Fset_char_table_default);
|
428
|
1781 DEFSUBR (Freset_char_table);
|
|
1782 DEFSUBR (Fmake_char_table);
|
|
1783 DEFSUBR (Fcopy_char_table);
|
|
1784 DEFSUBR (Fget_char_table);
|
|
1785 DEFSUBR (Fget_range_char_table);
|
|
1786 DEFSUBR (Fvalid_char_table_value_p);
|
|
1787 DEFSUBR (Fcheck_valid_char_table_value);
|
|
1788 DEFSUBR (Fput_char_table);
|
826
|
1789 DEFSUBR (Fremove_char_table);
|
428
|
1790 DEFSUBR (Fmap_char_table);
|
|
1791
|
|
1792 #ifdef MULE
|
|
1793 DEFSUBR (Fcategory_table_p);
|
|
1794 DEFSUBR (Fcategory_table);
|
|
1795 DEFSUBR (Fstandard_category_table);
|
|
1796 DEFSUBR (Fcopy_category_table);
|
|
1797 DEFSUBR (Fset_category_table);
|
|
1798 DEFSUBR (Fcheck_category_at);
|
|
1799 DEFSUBR (Fchar_in_category_p);
|
|
1800 DEFSUBR (Fcategory_designator_p);
|
|
1801 DEFSUBR (Fcategory_table_value_p);
|
|
1802 #endif /* MULE */
|
|
1803
|
|
1804 }
|
|
1805
|
|
1806 void
|
|
1807 vars_of_chartab (void)
|
|
1808 {
|
|
1809 /* DO NOT staticpro this. It works just like Vweak_hash_tables. */
|
|
1810 Vall_syntax_tables = Qnil;
|
452
|
1811 dump_add_weak_object_chain (&Vall_syntax_tables);
|
428
|
1812 }
|
|
1813
|
|
1814 void
|
|
1815 structure_type_create_chartab (void)
|
|
1816 {
|
|
1817 struct structure_type *st;
|
|
1818
|
|
1819 st = define_structure_type (Qchar_table, 0, chartab_instantiate);
|
|
1820
|
|
1821 define_structure_type_keyword (st, Qtype, chartab_type_validate);
|
|
1822 define_structure_type_keyword (st, Qdata, chartab_data_validate);
|
|
1823 }
|
|
1824
|
|
1825 void
|
|
1826 complex_vars_of_chartab (void)
|
|
1827 {
|
|
1828 #ifdef MULE
|
|
1829 /* Set this now, so first buffer creation can refer to it. */
|
|
1830 /* Make it nil before calling copy-category-table
|
|
1831 so that copy-category-table will know not to try to copy from garbage */
|
|
1832 Vstandard_category_table = Qnil;
|
|
1833 Vstandard_category_table = Fcopy_category_table (Qnil);
|
|
1834 staticpro (&Vstandard_category_table);
|
|
1835
|
|
1836 DEFVAR_LISP ("word-combining-categories", &Vword_combining_categories /*
|
|
1837 List of pair (cons) of categories to determine word boundary.
|
|
1838
|
|
1839 Emacs treats a sequence of word constituent characters as a single
|
|
1840 word (i.e. finds no word boundary between them) iff they belongs to
|
|
1841 the same charset. But, exceptions are allowed in the following cases.
|
|
1842
|
444
|
1843 \(1) The case that characters are in different charsets is controlled
|
428
|
1844 by the variable `word-combining-categories'.
|
|
1845
|
|
1846 Emacs finds no word boundary between characters of different charsets
|
|
1847 if they have categories matching some element of this list.
|
|
1848
|
|
1849 More precisely, if an element of this list is a cons of category CAT1
|
|
1850 and CAT2, and a multibyte character C1 which has CAT1 is followed by
|
|
1851 C2 which has CAT2, there's no word boundary between C1 and C2.
|
|
1852
|
|
1853 For instance, to tell that ASCII characters and Latin-1 characters can
|
|
1854 form a single word, the element `(?l . ?l)' should be in this list
|
|
1855 because both characters have the category `l' (Latin characters).
|
|
1856
|
444
|
1857 \(2) The case that character are in the same charset is controlled by
|
428
|
1858 the variable `word-separating-categories'.
|
|
1859
|
|
1860 Emacs find a word boundary between characters of the same charset
|
|
1861 if they have categories matching some element of this list.
|
|
1862
|
|
1863 More precisely, if an element of this list is a cons of category CAT1
|
|
1864 and CAT2, and a multibyte character C1 which has CAT1 is followed by
|
|
1865 C2 which has CAT2, there's a word boundary between C1 and C2.
|
|
1866
|
|
1867 For instance, to tell that there's a word boundary between Japanese
|
|
1868 Hiragana and Japanese Kanji (both are in the same charset), the
|
|
1869 element `(?H . ?C) should be in this list.
|
|
1870 */ );
|
|
1871
|
|
1872 Vword_combining_categories = Qnil;
|
|
1873
|
|
1874 DEFVAR_LISP ("word-separating-categories", &Vword_separating_categories /*
|
|
1875 List of pair (cons) of categories to determine word boundary.
|
|
1876 See the documentation of the variable `word-combining-categories'.
|
|
1877 */ );
|
|
1878
|
|
1879 Vword_separating_categories = Qnil;
|
|
1880 #endif /* MULE */
|
|
1881 }
|