24 |
#include "lisp.h" |
#include "lisp.h" |
25 |
#include "commands.h" |
#include "commands.h" |
26 |
#include "buffer.h" |
#include "buffer.h" |
27 |
#include "charset.h" |
#include "character.h" |
28 |
#include "keymap.h" |
#include "keymap.h" |
29 |
|
|
30 |
/* Make syntax table lookup grant data in gl_state. */ |
/* Make syntax table lookup grant data in gl_state. */ |
835 |
static Lisp_Object Vsyntax_code_object; |
static Lisp_Object Vsyntax_code_object; |
836 |
|
|
837 |
|
|
|
/* Look up the value for CHARACTER in syntax table TABLE's parent |
|
|
and its parents. SYNTAX_ENTRY calls this, when TABLE itself has nil |
|
|
for CHARACTER. It's actually used only when not compiled with GCC. */ |
|
|
|
|
|
Lisp_Object |
|
|
syntax_parent_lookup (table, character) |
|
|
Lisp_Object table; |
|
|
int character; |
|
|
{ |
|
|
Lisp_Object value; |
|
|
|
|
|
while (1) |
|
|
{ |
|
|
table = XCHAR_TABLE (table)->parent; |
|
|
if (NILP (table)) |
|
|
return Qnil; |
|
|
|
|
|
value = XCHAR_TABLE (table)->contents[character]; |
|
|
if (!NILP (value)) |
|
|
return value; |
|
|
} |
|
|
} |
|
|
|
|
838 |
DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0, |
DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0, |
839 |
doc: /* Return the syntax code of CHARACTER, described by a character. |
doc: /* Return the syntax code of CHARACTER, described by a character. |
840 |
For example, if CHARACTER is a word constituent, |
For example, if CHARACTER is a word constituent, |
953 |
doc: /* Set syntax for character CHAR according to string NEWENTRY. |
doc: /* Set syntax for character CHAR according to string NEWENTRY. |
954 |
The syntax is changed only for table SYNTAX_TABLE, which defaults to |
The syntax is changed only for table SYNTAX_TABLE, which defaults to |
955 |
the current buffer's syntax table. |
the current buffer's syntax table. |
956 |
|
CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters |
957 |
|
in the range MIN and MAX are changed. |
958 |
The first character of NEWENTRY should be one of the following: |
The first character of NEWENTRY should be one of the following: |
959 |
Space or - whitespace syntax. w word constituent. |
Space or - whitespace syntax. w word constituent. |
960 |
_ symbol constituent. . punctuation. |
_ symbol constituent. . punctuation. |
991 |
(c, newentry, syntax_table) |
(c, newentry, syntax_table) |
992 |
Lisp_Object c, newentry, syntax_table; |
Lisp_Object c, newentry, syntax_table; |
993 |
{ |
{ |
994 |
CHECK_NUMBER (c); |
if (CONSP (c)) |
995 |
|
{ |
996 |
|
CHECK_CHARACTER (XCAR (c)); |
997 |
|
CHECK_CHARACTER (XCDR (c)); |
998 |
|
} |
999 |
|
else |
1000 |
|
CHECK_CHARACTER (c); |
1001 |
|
|
1002 |
if (NILP (syntax_table)) |
if (NILP (syntax_table)) |
1003 |
syntax_table = current_buffer->syntax_table; |
syntax_table = current_buffer->syntax_table; |
1004 |
else |
else |
1005 |
check_syntax_table (syntax_table); |
check_syntax_table (syntax_table); |
1006 |
|
|
1007 |
SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), Fstring_to_syntax (newentry)); |
newentry = Fstring_to_syntax (newentry); |
1008 |
|
if (CONSP (c)) |
1009 |
|
SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table, c, newentry); |
1010 |
|
else |
1011 |
|
SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), newentry); |
1012 |
return Qnil; |
return Qnil; |
1013 |
} |
} |
1014 |
|
|
1407 |
If syntaxp, each character counts as itself. |
If syntaxp, each character counts as itself. |
1408 |
Otherwise, handle backslashes and ranges specially. */ |
Otherwise, handle backslashes and ranges specially. */ |
1409 |
|
|
1410 |
while (i_byte < size_byte) |
if (size_byte == XSTRING (string)->size) |
1411 |
{ |
while (i_byte < size_byte) |
1412 |
c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len); |
{ |
1413 |
i_byte += len; |
c = str[i_byte++]; |
1414 |
|
|
1415 |
if (syntaxp) |
if (syntaxp) |
1416 |
fastmap[syntax_spec_code[c & 0377]] = 1; |
fastmap[syntax_spec_code[c]] = 1; |
1417 |
else |
else |
1418 |
{ |
{ |
1419 |
if (c == '\\') |
if (c == '\\') |
1420 |
{ |
{ |
1421 |
if (i_byte == size_byte) |
if (i_byte == size_byte) |
1422 |
break; |
break; |
1423 |
|
|
1424 |
c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); |
c = str[i_byte++]; |
|
i_byte += len; |
|
1425 |
} |
} |
1426 |
if (i_byte < size_byte |
if (i_byte < size_byte |
1427 |
&& str[i_byte] == '-') |
&& str[i_byte] == '-') |
1435 |
break; |
break; |
1436 |
|
|
1437 |
/* Get the end of the range. */ |
/* Get the end of the range. */ |
1438 |
c2 =STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); |
c2 = str[i_byte++]; |
1439 |
i_byte += len; |
while (c <= c2) |
1440 |
|
fastmap[c++] = 1; |
|
if (SINGLE_BYTE_CHAR_P (c)) |
|
|
{ |
|
|
if (! SINGLE_BYTE_CHAR_P (c2)) |
|
|
{ |
|
|
/* Handle a range starting with a character of |
|
|
less than 256, and ending with a character of |
|
|
not less than 256. Split that into two |
|
|
ranges, the low one ending at 0377, and the |
|
|
high one starting at the smallest character |
|
|
in the charset of C2 and ending at C2. */ |
|
|
int charset = CHAR_CHARSET (c2); |
|
|
int c1 = MAKE_CHAR (charset, 0, 0); |
|
|
|
|
|
char_ranges[n_char_ranges++] = c1; |
|
|
char_ranges[n_char_ranges++] = c2; |
|
|
c2 = 0377; |
|
|
} |
|
|
while (c <= c2) |
|
|
{ |
|
|
fastmap[c] = 1; |
|
|
c++; |
|
|
} |
|
|
} |
|
|
else if (c <= c2) /* Both C and C2 are multibyte char. */ |
|
|
{ |
|
|
char_ranges[n_char_ranges++] = c; |
|
|
char_ranges[n_char_ranges++] = c2; |
|
|
} |
|
1441 |
} |
} |
1442 |
else |
else |
1443 |
{ |
fastmap[c] = 1; |
|
if (SINGLE_BYTE_CHAR_P (c)) |
|
|
fastmap[c] = 1; |
|
|
else |
|
|
{ |
|
|
char_ranges[n_char_ranges++] = c; |
|
|
char_ranges[n_char_ranges++] = c; |
|
|
} |
|
|
} |
|
1444 |
} |
} |
1445 |
} |
} |
1446 |
|
else |
1447 |
|
while (i_byte < size_byte) |
1448 |
|
{ |
1449 |
|
c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len); |
1450 |
|
i_byte += len; |
1451 |
|
|
1452 |
|
if (syntaxp) |
1453 |
|
fastmap[syntax_spec_code[c & 0377]] = 1; |
1454 |
|
else |
1455 |
|
{ |
1456 |
|
if (c == '\\') |
1457 |
|
{ |
1458 |
|
if (i_byte == size_byte) |
1459 |
|
break; |
1460 |
|
|
1461 |
|
c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); |
1462 |
|
i_byte += len; |
1463 |
|
} |
1464 |
|
if (i_byte < size_byte |
1465 |
|
&& str[i_byte] == '-') |
1466 |
|
{ |
1467 |
|
unsigned int c2; |
1468 |
|
|
1469 |
|
/* Skip over the dash. */ |
1470 |
|
i_byte++; |
1471 |
|
|
1472 |
|
if (i_byte == size_byte) |
1473 |
|
break; |
1474 |
|
|
1475 |
|
/* Get the end of the range. */ |
1476 |
|
c2 =STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len); |
1477 |
|
i_byte += len; |
1478 |
|
|
1479 |
|
if (ASCII_CHAR_P (c)) |
1480 |
|
while (c <= c2 && c < 0x80) |
1481 |
|
fastmap[c++] = 1; |
1482 |
|
if (c <= c2) |
1483 |
|
{ |
1484 |
|
char_ranges[n_char_ranges++] = c; |
1485 |
|
char_ranges[n_char_ranges++] = c2; |
1486 |
|
} |
1487 |
|
} |
1488 |
|
else |
1489 |
|
{ |
1490 |
|
if (ASCII_CHAR_P (c)) |
1491 |
|
fastmap[c] = 1; |
1492 |
|
else |
1493 |
|
{ |
1494 |
|
char_ranges[n_char_ranges++] = c; |
1495 |
|
char_ranges[n_char_ranges++] = c; |
1496 |
|
} |
1497 |
|
} |
1498 |
|
} |
1499 |
|
} |
1500 |
|
|
1501 |
/* If ^ was the first character, complement the fastmap. */ |
/* If ^ was the first character, complement the fastmap. */ |
1502 |
if (negate) |
if (negate) |
1579 |
while (pos < XINT (lim)) |
while (pos < XINT (lim)) |
1580 |
{ |
{ |
1581 |
c = FETCH_MULTIBYTE_CHAR (pos_byte); |
c = FETCH_MULTIBYTE_CHAR (pos_byte); |
1582 |
if (SINGLE_BYTE_CHAR_P (c)) |
if (ASCII_CHAR_P (c)) |
1583 |
{ |
{ |
1584 |
if (!fastmap[c]) |
if (!fastmap[c]) |
1585 |
break; |
break; |
1639 |
} |
} |
1640 |
} |
} |
1641 |
|
|
|
#if 0 /* Not needed now that a position in mid-character |
|
|
cannot be specified in Lisp. */ |
|
|
if (multibyte |
|
|
/* INC_POS or DEC_POS might have moved POS over LIM. */ |
|
|
&& (forwardp ? (pos > XINT (lim)) : (pos < XINT (lim)))) |
|
|
pos = XINT (lim); |
|
|
#endif |
|
|
|
|
1642 |
if (! multibyte) |
if (! multibyte) |
1643 |
pos_byte = pos; |
pos_byte = pos; |
1644 |
|
|
2943 |
|
|
2944 |
/* All multibyte characters have syntax `word' by default. */ |
/* All multibyte characters have syntax `word' by default. */ |
2945 |
temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; |
temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; |
2946 |
for (i = CHAR_TABLE_SINGLE_BYTE_SLOTS; i < CHAR_TABLE_ORDINARY_SLOTS; i++) |
char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp); |
|
XCHAR_TABLE (Vstandard_syntax_table)->contents[i] = temp; |
|
2947 |
} |
} |
2948 |
|
|
2949 |
void |
void |