diff options
Diffstat (limited to 'src/syntax.c')
| -rw-r--r-- | src/syntax.c | 996 |
1 files changed, 619 insertions, 377 deletions
diff --git a/src/syntax.c b/src/syntax.c index 586e2f92ea0..648d7495db6 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -26,7 +26,7 @@ Boston, MA 02110-1301, USA. */ | |||
| 26 | #include "lisp.h" | 26 | #include "lisp.h" |
| 27 | #include "commands.h" | 27 | #include "commands.h" |
| 28 | #include "buffer.h" | 28 | #include "buffer.h" |
| 29 | #include "charset.h" | 29 | #include "character.h" |
| 30 | #include "keymap.h" | 30 | #include "keymap.h" |
| 31 | #include "regex.h" | 31 | #include "regex.h" |
| 32 | 32 | ||
| @@ -101,7 +101,8 @@ static int find_defun_start P_ ((int, int)); | |||
| 101 | static int back_comment P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int, int, | 101 | static int back_comment P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int, int, |
| 102 | EMACS_INT *, EMACS_INT *)); | 102 | EMACS_INT *, EMACS_INT *)); |
| 103 | static int char_quoted P_ ((int, int)); | 103 | static int char_quoted P_ ((int, int)); |
| 104 | static Lisp_Object skip_chars P_ ((int, int, Lisp_Object, Lisp_Object, int)); | 104 | static Lisp_Object skip_chars P_ ((int, Lisp_Object, Lisp_Object, int)); |
| 105 | static Lisp_Object skip_syntaxes P_ ((int, Lisp_Object, Lisp_Object)); | ||
| 105 | static Lisp_Object scan_lists P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int)); | 106 | static Lisp_Object scan_lists P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int)); |
| 106 | static void scan_sexps_forward P_ ((struct lisp_parse_state *, | 107 | static void scan_sexps_forward P_ ((struct lisp_parse_state *, |
| 107 | int, int, int, int, | 108 | int, int, int, int, |
| @@ -306,7 +307,7 @@ char_quoted (charpos, bytepos) | |||
| 306 | int c; | 307 | int c; |
| 307 | 308 | ||
| 308 | UPDATE_SYNTAX_TABLE_BACKWARD (charpos); | 309 | UPDATE_SYNTAX_TABLE_BACKWARD (charpos); |
| 309 | c = FETCH_CHAR (bytepos); | 310 | c = FETCH_CHAR_AS_MULTIBYTE (bytepos); |
| 310 | code = SYNTAX (c); | 311 | code = SYNTAX (c); |
| 311 | if (! (code == Scharquote || code == Sescape)) | 312 | if (! (code == Scharquote || code == Sescape)) |
| 312 | break; | 313 | break; |
| @@ -398,11 +399,11 @@ find_defun_start (pos, pos_byte) | |||
| 398 | 399 | ||
| 399 | /* Open-paren at start of line means we may have found our | 400 | /* Open-paren at start of line means we may have found our |
| 400 | defun-start. */ | 401 | defun-start. */ |
| 401 | c = FETCH_CHAR (PT_BYTE); | 402 | c = FETCH_CHAR_AS_MULTIBYTE (PT_BYTE); |
| 402 | if (SYNTAX (c) == Sopen) | 403 | if (SYNTAX (c) == Sopen) |
| 403 | { | 404 | { |
| 404 | SETUP_SYNTAX_TABLE (PT + 1, -1); /* Try again... */ | 405 | SETUP_SYNTAX_TABLE (PT + 1, -1); /* Try again... */ |
| 405 | c = FETCH_CHAR (PT_BYTE); | 406 | c = FETCH_CHAR_AS_MULTIBYTE (PT_BYTE); |
| 406 | if (SYNTAX (c) == Sopen) | 407 | if (SYNTAX (c) == Sopen) |
| 407 | break; | 408 | break; |
| 408 | /* Now fallback to the default value. */ | 409 | /* Now fallback to the default value. */ |
| @@ -523,7 +524,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 523 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 524 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 524 | 525 | ||
| 525 | prev_syntax = syntax; | 526 | prev_syntax = syntax; |
| 526 | c = FETCH_CHAR (from_byte); | 527 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 527 | syntax = SYNTAX_WITH_FLAGS (c); | 528 | syntax = SYNTAX_WITH_FLAGS (c); |
| 528 | code = SYNTAX (c); | 529 | code = SYNTAX (c); |
| 529 | 530 | ||
| @@ -552,7 +553,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 552 | int next = from, next_byte = from_byte, next_c, next_syntax; | 553 | int next = from, next_byte = from_byte, next_c, next_syntax; |
| 553 | DEC_BOTH (next, next_byte); | 554 | DEC_BOTH (next, next_byte); |
| 554 | UPDATE_SYNTAX_TABLE_BACKWARD (next); | 555 | UPDATE_SYNTAX_TABLE_BACKWARD (next); |
| 555 | next_c = FETCH_CHAR (next_byte); | 556 | next_c = FETCH_CHAR_AS_MULTIBYTE (next_byte); |
| 556 | next_syntax = SYNTAX_WITH_FLAGS (next_c); | 557 | next_syntax = SYNTAX_WITH_FLAGS (next_c); |
| 557 | if (((com2start || comnested) | 558 | if (((com2start || comnested) |
| 558 | && SYNTAX_FLAGS_COMEND_SECOND (syntax) | 559 | && SYNTAX_FLAGS_COMEND_SECOND (syntax) |
| @@ -855,29 +856,6 @@ char syntax_code_spec[16] = | |||
| 855 | static Lisp_Object Vsyntax_code_object; | 856 | static Lisp_Object Vsyntax_code_object; |
| 856 | 857 | ||
| 857 | 858 | ||
| 858 | /* Look up the value for CHARACTER in syntax table TABLE's parent | ||
| 859 | and its parents. SYNTAX_ENTRY calls this, when TABLE itself has nil | ||
| 860 | for CHARACTER. It's actually used only when not compiled with GCC. */ | ||
| 861 | |||
| 862 | Lisp_Object | ||
| 863 | syntax_parent_lookup (table, character) | ||
| 864 | Lisp_Object table; | ||
| 865 | int character; | ||
| 866 | { | ||
| 867 | Lisp_Object value; | ||
| 868 | |||
| 869 | while (1) | ||
| 870 | { | ||
| 871 | table = XCHAR_TABLE (table)->parent; | ||
| 872 | if (NILP (table)) | ||
| 873 | return Qnil; | ||
| 874 | |||
| 875 | value = XCHAR_TABLE (table)->contents[character]; | ||
| 876 | if (!NILP (value)) | ||
| 877 | return value; | ||
| 878 | } | ||
| 879 | } | ||
| 880 | |||
| 881 | DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0, | 859 | DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0, |
| 882 | doc: /* Return the syntax code of CHARACTER, described by a character. | 860 | doc: /* Return the syntax code of CHARACTER, described by a character. |
| 883 | For example, if CHARACTER is a word constituent, | 861 | For example, if CHARACTER is a word constituent, |
| @@ -996,6 +974,8 @@ DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, | |||
| 996 | doc: /* Set syntax for character CHAR according to string NEWENTRY. | 974 | doc: /* Set syntax for character CHAR according to string NEWENTRY. |
| 997 | The syntax is changed only for table SYNTAX-TABLE, which defaults to | 975 | The syntax is changed only for table SYNTAX-TABLE, which defaults to |
| 998 | the current buffer's syntax table. | 976 | the current buffer's syntax table. |
| 977 | CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters | ||
| 978 | in the range MIN and MAX are changed. | ||
| 999 | The first character of NEWENTRY should be one of the following: | 979 | The first character of NEWENTRY should be one of the following: |
| 1000 | Space or - whitespace syntax. w word constituent. | 980 | Space or - whitespace syntax. w word constituent. |
| 1001 | _ symbol constituent. . punctuation. | 981 | _ symbol constituent. . punctuation. |
| @@ -1032,14 +1012,24 @@ usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */) | |||
| 1032 | (c, newentry, syntax_table) | 1012 | (c, newentry, syntax_table) |
| 1033 | Lisp_Object c, newentry, syntax_table; | 1013 | Lisp_Object c, newentry, syntax_table; |
| 1034 | { | 1014 | { |
| 1035 | CHECK_NUMBER (c); | 1015 | if (CONSP (c)) |
| 1016 | { | ||
| 1017 | CHECK_CHARACTER_CAR (c); | ||
| 1018 | CHECK_CHARACTER_CDR (c); | ||
| 1019 | } | ||
| 1020 | else | ||
| 1021 | CHECK_CHARACTER (c); | ||
| 1036 | 1022 | ||
| 1037 | if (NILP (syntax_table)) | 1023 | if (NILP (syntax_table)) |
| 1038 | syntax_table = current_buffer->syntax_table; | 1024 | syntax_table = current_buffer->syntax_table; |
| 1039 | else | 1025 | else |
| 1040 | check_syntax_table (syntax_table); | 1026 | check_syntax_table (syntax_table); |
| 1041 | 1027 | ||
| 1042 | SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), Fstring_to_syntax (newentry)); | 1028 | newentry = Fstring_to_syntax (newentry); |
| 1029 | if (CONSP (c)) | ||
| 1030 | SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table, c, newentry); | ||
| 1031 | else | ||
| 1032 | SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), newentry); | ||
| 1043 | 1033 | ||
| 1044 | /* We clear the regexp cache, since character classes can now have | 1034 | /* We clear the regexp cache, since character classes can now have |
| 1045 | different values from those in the compiled regexps.*/ | 1035 | different values from those in the compiled regexps.*/ |
| @@ -1198,6 +1188,10 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, | |||
| 1198 | 1188 | ||
| 1199 | int parse_sexp_ignore_comments; | 1189 | int parse_sexp_ignore_comments; |
| 1200 | 1190 | ||
| 1191 | /* Char-table of functions that find the next or previous word | ||
| 1192 | boundary. */ | ||
| 1193 | Lisp_Object Vfind_word_boundary_function_table; | ||
| 1194 | |||
| 1201 | /* Return the position across COUNT words from FROM. | 1195 | /* Return the position across COUNT words from FROM. |
| 1202 | If that many words cannot be found before the end of the buffer, return 0. | 1196 | If that many words cannot be found before the end of the buffer, return 0. |
| 1203 | COUNT negative means scan backward and stop at word beginning. */ | 1197 | COUNT negative means scan backward and stop at word beginning. */ |
| @@ -1211,6 +1205,7 @@ scan_words (from, count) | |||
| 1211 | register int from_byte = CHAR_TO_BYTE (from); | 1205 | register int from_byte = CHAR_TO_BYTE (from); |
| 1212 | register enum syntaxcode code; | 1206 | register enum syntaxcode code; |
| 1213 | int ch0, ch1; | 1207 | int ch0, ch1; |
| 1208 | Lisp_Object func, script, pos; | ||
| 1214 | 1209 | ||
| 1215 | immediate_quit = 1; | 1210 | immediate_quit = 1; |
| 1216 | QUIT; | 1211 | QUIT; |
| @@ -1227,7 +1222,7 @@ scan_words (from, count) | |||
| 1227 | return 0; | 1222 | return 0; |
| 1228 | } | 1223 | } |
| 1229 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 1224 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 1230 | ch0 = FETCH_CHAR (from_byte); | 1225 | ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1231 | code = SYNTAX (ch0); | 1226 | code = SYNTAX (ch0); |
| 1232 | INC_BOTH (from, from_byte); | 1227 | INC_BOTH (from, from_byte); |
| 1233 | if (words_include_escapes | 1228 | if (words_include_escapes |
| @@ -1238,18 +1233,33 @@ scan_words (from, count) | |||
| 1238 | } | 1233 | } |
| 1239 | /* Now CH0 is a character which begins a word and FROM is the | 1234 | /* Now CH0 is a character which begins a word and FROM is the |
| 1240 | position of the next character. */ | 1235 | position of the next character. */ |
| 1241 | while (1) | 1236 | func = CHAR_TABLE_REF (Vfind_word_boundary_function_table, ch0); |
| 1237 | if (! NILP (Ffboundp (func))) | ||
| 1242 | { | 1238 | { |
| 1243 | if (from == end) break; | 1239 | pos = call2 (func, make_number (from - 1), make_number (end)); |
| 1244 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 1240 | if (INTEGERP (pos) && XINT (pos) > from) |
| 1245 | ch1 = FETCH_CHAR (from_byte); | 1241 | { |
| 1246 | code = SYNTAX (ch1); | 1242 | from = XINT (pos); |
| 1247 | if (!(words_include_escapes | 1243 | from_byte = CHAR_TO_BYTE (from); |
| 1248 | && (code == Sescape || code == Scharquote))) | 1244 | } |
| 1249 | if (code != Sword || WORD_BOUNDARY_P (ch0, ch1)) | 1245 | } |
| 1250 | break; | 1246 | else |
| 1251 | INC_BOTH (from, from_byte); | 1247 | { |
| 1252 | ch0 = ch1; | 1248 | script = CHAR_TABLE_REF (Vchar_script_table, ch0); |
| 1249 | while (1) | ||
| 1250 | { | ||
| 1251 | if (from == end) break; | ||
| 1252 | UPDATE_SYNTAX_TABLE_FORWARD (from); | ||
| 1253 | ch1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); | ||
| 1254 | code = SYNTAX (ch1); | ||
| 1255 | if ((code != Sword | ||
| 1256 | && (! words_include_escapes | ||
| 1257 | || (code != Sescape && code != Scharquote))) | ||
| 1258 | || ! EQ (CHAR_TABLE_REF (Vchar_script_table, ch1), script)) | ||
| 1259 | break; | ||
| 1260 | INC_BOTH (from, from_byte); | ||
| 1261 | ch0 = ch1; | ||
| 1262 | } | ||
| 1253 | } | 1263 | } |
| 1254 | count--; | 1264 | count--; |
| 1255 | } | 1265 | } |
| @@ -1264,7 +1274,7 @@ scan_words (from, count) | |||
| 1264 | } | 1274 | } |
| 1265 | DEC_BOTH (from, from_byte); | 1275 | DEC_BOTH (from, from_byte); |
| 1266 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 1276 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 1267 | ch1 = FETCH_CHAR (from_byte); | 1277 | ch1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1268 | code = SYNTAX (ch1); | 1278 | code = SYNTAX (ch1); |
| 1269 | if (words_include_escapes | 1279 | if (words_include_escapes |
| 1270 | && (code == Sescape || code == Scharquote)) | 1280 | && (code == Sescape || code == Scharquote)) |
| @@ -1274,22 +1284,37 @@ scan_words (from, count) | |||
| 1274 | } | 1284 | } |
| 1275 | /* Now CH1 is a character which ends a word and FROM is the | 1285 | /* Now CH1 is a character which ends a word and FROM is the |
| 1276 | position of it. */ | 1286 | position of it. */ |
| 1277 | while (1) | 1287 | func = CHAR_TABLE_REF (Vfind_word_boundary_function_table, ch1); |
| 1288 | if (! NILP (Ffboundp (func))) | ||
| 1289 | { | ||
| 1290 | pos = call2 (func, make_number (from), make_number (beg)); | ||
| 1291 | if (INTEGERP (pos) && XINT (pos) < from) | ||
| 1292 | { | ||
| 1293 | from = XINT (pos); | ||
| 1294 | from_byte = CHAR_TO_BYTE (from); | ||
| 1295 | } | ||
| 1296 | } | ||
| 1297 | else | ||
| 1278 | { | 1298 | { |
| 1279 | if (from == beg) | 1299 | script = CHAR_TABLE_REF (Vchar_script_table, ch1); |
| 1280 | break; | 1300 | while (1) |
| 1281 | DEC_BOTH (from, from_byte); | 1301 | { |
| 1282 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 1302 | if (from == beg) |
| 1283 | ch0 = FETCH_CHAR (from_byte); | ||
| 1284 | code = SYNTAX (ch0); | ||
| 1285 | if (!(words_include_escapes | ||
| 1286 | && (code == Sescape || code == Scharquote))) | ||
| 1287 | if (code != Sword || WORD_BOUNDARY_P (ch0, ch1)) | ||
| 1288 | { | ||
| 1289 | INC_BOTH (from, from_byte); | ||
| 1290 | break; | 1303 | break; |
| 1291 | } | 1304 | DEC_BOTH (from, from_byte); |
| 1292 | ch1 = ch0; | 1305 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 1306 | ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte); | ||
| 1307 | code = SYNTAX (ch0); | ||
| 1308 | if ((code != Sword | ||
| 1309 | && (! words_include_escapes | ||
| 1310 | || (code != Sescape && code != Scharquote))) | ||
| 1311 | || ! EQ (CHAR_TABLE_REF (Vchar_script_table, ch0), script)) | ||
| 1312 | { | ||
| 1313 | INC_BOTH (from, from_byte); | ||
| 1314 | break; | ||
| 1315 | } | ||
| 1316 | ch1 = ch0; | ||
| 1317 | } | ||
| 1293 | } | 1318 | } |
| 1294 | count++; | 1319 | count++; |
| 1295 | } | 1320 | } |
| @@ -1344,7 +1369,7 @@ Returns the distance traveled, either zero or positive. */) | |||
| 1344 | (string, lim) | 1369 | (string, lim) |
| 1345 | Lisp_Object string, lim; | 1370 | Lisp_Object string, lim; |
| 1346 | { | 1371 | { |
| 1347 | return skip_chars (1, 0, string, lim, 1); | 1372 | return skip_chars (1, string, lim, 1); |
| 1348 | } | 1373 | } |
| 1349 | 1374 | ||
| 1350 | DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0, | 1375 | DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0, |
| @@ -1354,7 +1379,7 @@ Returns the distance traveled, either zero or negative. */) | |||
| 1354 | (string, lim) | 1379 | (string, lim) |
| 1355 | Lisp_Object string, lim; | 1380 | Lisp_Object string, lim; |
| 1356 | { | 1381 | { |
| 1357 | return skip_chars (0, 0, string, lim, 1); | 1382 | return skip_chars (0, string, lim, 1); |
| 1358 | } | 1383 | } |
| 1359 | 1384 | ||
| 1360 | DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0, | 1385 | DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0, |
| @@ -1366,7 +1391,7 @@ This function returns the distance traveled, either zero or positive. */) | |||
| 1366 | (syntax, lim) | 1391 | (syntax, lim) |
| 1367 | Lisp_Object syntax, lim; | 1392 | Lisp_Object syntax, lim; |
| 1368 | { | 1393 | { |
| 1369 | return skip_chars (1, 1, syntax, lim, 0); | 1394 | return skip_syntaxes (1, syntax, lim); |
| 1370 | } | 1395 | } |
| 1371 | 1396 | ||
| 1372 | DEFUN ("skip-syntax-backward", Fskip_syntax_backward, Sskip_syntax_backward, 1, 2, 0, | 1397 | DEFUN ("skip-syntax-backward", Fskip_syntax_backward, Sskip_syntax_backward, 1, 2, 0, |
| @@ -1378,25 +1403,27 @@ This function returns the distance traveled, either zero or negative. */) | |||
| 1378 | (syntax, lim) | 1403 | (syntax, lim) |
| 1379 | Lisp_Object syntax, lim; | 1404 | Lisp_Object syntax, lim; |
| 1380 | { | 1405 | { |
| 1381 | return skip_chars (0, 1, syntax, lim, 0); | 1406 | return skip_syntaxes (0, syntax, lim); |
| 1382 | } | 1407 | } |
| 1383 | 1408 | ||
| 1384 | static Lisp_Object | 1409 | static Lisp_Object |
| 1385 | skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) | 1410 | skip_chars (forwardp, string, lim, handle_iso_classes) |
| 1386 | int forwardp, syntaxp; | 1411 | int forwardp; |
| 1387 | Lisp_Object string, lim; | 1412 | Lisp_Object string, lim; |
| 1388 | int handle_iso_classes; | 1413 | int handle_iso_classes; |
| 1389 | { | 1414 | { |
| 1390 | register unsigned int c; | 1415 | register unsigned int c; |
| 1391 | unsigned char fastmap[0400]; | 1416 | unsigned char fastmap[0400]; |
| 1392 | /* If SYNTAXP is 0, STRING may contain multi-byte form of characters | 1417 | /* Store the ranges of non-ASCII characters. */ |
| 1393 | of which codes don't fit in FASTMAP. In that case, set the | ||
| 1394 | ranges of characters in CHAR_RANGES. */ | ||
| 1395 | int *char_ranges; | 1418 | int *char_ranges; |
| 1396 | int n_char_ranges = 0; | 1419 | int n_char_ranges = 0; |
| 1397 | int negate = 0; | 1420 | int negate = 0; |
| 1398 | register int i, i_byte; | 1421 | register int i, i_byte; |
| 1399 | int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 1422 | /* Set to 1 if the current buffer is multibyte and the region |
| 1423 | contains non-ASCII chars. */ | ||
| 1424 | int multibyte; | ||
| 1425 | /* Set to 1 if STRING is multibyte and it contains non-ASCII | ||
| 1426 | chars. */ | ||
| 1400 | int string_multibyte; | 1427 | int string_multibyte; |
| 1401 | int size_byte; | 1428 | int size_byte; |
| 1402 | const unsigned char *str; | 1429 | const unsigned char *str; |
| @@ -1404,32 +1431,8 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) | |||
| 1404 | Lisp_Object iso_classes; | 1431 | Lisp_Object iso_classes; |
| 1405 | 1432 | ||
| 1406 | CHECK_STRING (string); | 1433 | CHECK_STRING (string); |
| 1407 | char_ranges = (int *) alloca (SCHARS (string) * (sizeof (int)) * 2); | ||
| 1408 | string_multibyte = STRING_MULTIBYTE (string); | ||
| 1409 | str = SDATA (string); | ||
| 1410 | size_byte = SBYTES (string); | ||
| 1411 | iso_classes = Qnil; | 1434 | iso_classes = Qnil; |
| 1412 | 1435 | ||
| 1413 | /* Adjust the multibyteness of the string to that of the buffer. */ | ||
| 1414 | if (multibyte != string_multibyte) | ||
| 1415 | { | ||
| 1416 | int nbytes; | ||
| 1417 | |||
| 1418 | if (multibyte) | ||
| 1419 | nbytes = count_size_as_multibyte (SDATA (string), | ||
| 1420 | SCHARS (string)); | ||
| 1421 | else | ||
| 1422 | nbytes = SCHARS (string); | ||
| 1423 | if (nbytes != size_byte) | ||
| 1424 | { | ||
| 1425 | unsigned char *tmp = (unsigned char *) alloca (nbytes); | ||
| 1426 | copy_text (SDATA (string), tmp, size_byte, | ||
| 1427 | string_multibyte, multibyte); | ||
| 1428 | size_byte = nbytes; | ||
| 1429 | str = tmp; | ||
| 1430 | } | ||
| 1431 | } | ||
| 1432 | |||
| 1433 | if (NILP (lim)) | 1436 | if (NILP (lim)) |
| 1434 | XSETINT (lim, forwardp ? ZV : BEGV); | 1437 | XSETINT (lim, forwardp ? ZV : BEGV); |
| 1435 | else | 1438 | else |
| @@ -1441,10 +1444,16 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) | |||
| 1441 | if (XINT (lim) < BEGV) | 1444 | if (XINT (lim) < BEGV) |
| 1442 | XSETFASTINT (lim, BEGV); | 1445 | XSETFASTINT (lim, BEGV); |
| 1443 | 1446 | ||
| 1447 | multibyte = (!NILP (current_buffer->enable_multibyte_characters) | ||
| 1448 | && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); | ||
| 1449 | string_multibyte = SBYTES (string) > SCHARS (string); | ||
| 1450 | |||
| 1444 | bzero (fastmap, sizeof fastmap); | 1451 | bzero (fastmap, sizeof fastmap); |
| 1445 | 1452 | ||
| 1446 | i_byte = 0; | 1453 | str = SDATA (string); |
| 1454 | size_byte = SBYTES (string); | ||
| 1447 | 1455 | ||
| 1456 | i_byte = 0; | ||
| 1448 | if (i_byte < size_byte | 1457 | if (i_byte < size_byte |
| 1449 | && SREF (string, 0) == '^') | 1458 | && SREF (string, 0) == '^') |
| 1450 | { | 1459 | { |
| @@ -1452,21 +1461,23 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) | |||
| 1452 | } | 1461 | } |
| 1453 | 1462 | ||
| 1454 | /* Find the characters specified and set their elements of fastmap. | 1463 | /* Find the characters specified and set their elements of fastmap. |
| 1455 | If syntaxp, each character counts as itself. | 1464 | Handle backslashes and ranges specially. |
| 1456 | Otherwise, handle backslashes and ranges specially. */ | ||
| 1457 | 1465 | ||
| 1458 | while (i_byte < size_byte) | 1466 | If STRING contains non-ASCII characters, setup char_ranges for |
| 1467 | them and use fastmap only for their leading codes. */ | ||
| 1468 | |||
| 1469 | if (! string_multibyte) | ||
| 1459 | { | 1470 | { |
| 1460 | c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len); | 1471 | int string_has_eight_bit = 0; |
| 1461 | i_byte += len; | ||
| 1462 | 1472 | ||
| 1463 | if (syntaxp) | 1473 | /* At first setup fastmap. */ |
| 1464 | fastmap[syntax_spec_code[c & 0377]] = 1; | 1474 | while (i_byte < size_byte) |
| 1465 | else | ||
| 1466 | { | 1475 | { |
| 1476 | c = str[i_byte++]; | ||
| 1477 | |||
| 1467 | if (handle_iso_classes && c == '[' | 1478 | if (handle_iso_classes && c == '[' |
| 1468 | && i_byte < size_byte | 1479 | && i_byte < size_byte |
| 1469 | && STRING_CHAR (str + i_byte, size_byte - i_byte) == ':') | 1480 | && str[i_byte] == ':') |
| 1470 | { | 1481 | { |
| 1471 | const unsigned char *class_beg = str + i_byte + 1; | 1482 | const unsigned char *class_beg = str + i_byte + 1; |
| 1472 | const unsigned char *class_end = class_beg; | 1483 | const unsigned char *class_end = class_beg; |
| @@ -1505,6 +1516,129 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) | |||
| 1505 | if (i_byte == size_byte) | 1516 | if (i_byte == size_byte) |
| 1506 | break; | 1517 | break; |
| 1507 | 1518 | ||
| 1519 | c = str[i_byte++]; | ||
| 1520 | } | ||
| 1521 | /* Treat `-' as range character only if another character | ||
| 1522 | follows. */ | ||
| 1523 | if (i_byte + 1 < size_byte | ||
| 1524 | && str[i_byte] == '-') | ||
| 1525 | { | ||
| 1526 | unsigned int c2; | ||
| 1527 | |||
| 1528 | /* Skip over the dash. */ | ||
| 1529 | i_byte++; | ||
| 1530 | |||
| 1531 | /* Get the end of the range. */ | ||
| 1532 | c2 = str[i_byte++]; | ||
| 1533 | if (c2 == '\\' | ||
| 1534 | && i_byte < size_byte) | ||
| 1535 | c2 = str[i_byte++]; | ||
| 1536 | |||
| 1537 | if (c <= c2) | ||
| 1538 | { | ||
| 1539 | while (c <= c2) | ||
| 1540 | fastmap[c++] = 1; | ||
| 1541 | if (! ASCII_CHAR_P (c2)) | ||
| 1542 | string_has_eight_bit = 1; | ||
| 1543 | } | ||
| 1544 | } | ||
| 1545 | else | ||
| 1546 | { | ||
| 1547 | fastmap[c] = 1; | ||
| 1548 | if (! ASCII_CHAR_P (c)) | ||
| 1549 | string_has_eight_bit = 1; | ||
| 1550 | } | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | /* If the current range is multibyte and STRING contains | ||
| 1554 | eight-bit chars, arrange fastmap and setup char_ranges for | ||
| 1555 | the corresponding multibyte chars. */ | ||
| 1556 | if (multibyte && string_has_eight_bit) | ||
| 1557 | { | ||
| 1558 | unsigned char fastmap2[0400]; | ||
| 1559 | int range_start_byte, range_start_char; | ||
| 1560 | |||
| 1561 | bcopy (fastmap2 + 0200, fastmap + 0200, 0200); | ||
| 1562 | bzero (fastmap + 0200, 0200); | ||
| 1563 | /* We are sure that this loop stops. */ | ||
| 1564 | for (i = 0200; ! fastmap2[i]; i++); | ||
| 1565 | c = unibyte_char_to_multibyte (i); | ||
| 1566 | fastmap[CHAR_LEADING_CODE (c)] = 1; | ||
| 1567 | range_start_byte = i; | ||
| 1568 | range_start_char = c; | ||
| 1569 | char_ranges = (int *) alloca (sizeof (int) * 128 * 2); | ||
| 1570 | for (i = 129; i < 0400; i++) | ||
| 1571 | { | ||
| 1572 | c = unibyte_char_to_multibyte (i); | ||
| 1573 | fastmap[CHAR_LEADING_CODE (c)] = 1; | ||
| 1574 | if (i - range_start_byte != c - range_start_char) | ||
| 1575 | { | ||
| 1576 | char_ranges[n_char_ranges++] = range_start_char; | ||
| 1577 | char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) | ||
| 1578 | + range_start_char); | ||
| 1579 | range_start_byte = i; | ||
| 1580 | range_start_char = c; | ||
| 1581 | } | ||
| 1582 | } | ||
| 1583 | char_ranges[n_char_ranges++] = range_start_char; | ||
| 1584 | char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) | ||
| 1585 | + range_start_char); | ||
| 1586 | } | ||
| 1587 | } | ||
| 1588 | else /* STRING is multibyte */ | ||
| 1589 | { | ||
| 1590 | char_ranges = (int *) alloca (sizeof (int) * SCHARS (string) * 2); | ||
| 1591 | |||
| 1592 | while (i_byte < size_byte) | ||
| 1593 | { | ||
| 1594 | unsigned char leading_code; | ||
| 1595 | |||
| 1596 | leading_code = str[i_byte]; | ||
| 1597 | c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len); | ||
| 1598 | i_byte += len; | ||
| 1599 | |||
| 1600 | if (handle_iso_classes && c == '[' | ||
| 1601 | && i_byte < size_byte | ||
| 1602 | && STRING_CHAR (str + i_byte, size_byte - i_byte) == ':') | ||
| 1603 | { | ||
| 1604 | const unsigned char *class_beg = str + i_byte + 1; | ||
| 1605 | const unsigned char *class_end = class_beg; | ||
| 1606 | const unsigned char *class_limit = str + size_byte - 2; | ||
| 1607 | /* Leave room for the null. */ | ||
| 1608 | unsigned char class_name[CHAR_CLASS_MAX_LENGTH + 1]; | ||
| 1609 | re_wctype_t cc; | ||
| 1610 | |||
| 1611 | if (class_limit - class_beg > CHAR_CLASS_MAX_LENGTH) | ||
| 1612 | class_limit = class_beg + CHAR_CLASS_MAX_LENGTH; | ||
| 1613 | |||
| 1614 | while (class_end < class_limit | ||
| 1615 | && *class_end >= 'a' && *class_end <= 'z') | ||
| 1616 | class_end++; | ||
| 1617 | |||
| 1618 | if (class_end == class_beg | ||
| 1619 | || *class_end != ':' || class_end[1] != ']') | ||
| 1620 | goto not_a_class_name_multibyte; | ||
| 1621 | |||
| 1622 | bcopy (class_beg, class_name, class_end - class_beg); | ||
| 1623 | class_name[class_end - class_beg] = 0; | ||
| 1624 | |||
| 1625 | cc = re_wctype (class_name); | ||
| 1626 | if (cc == 0) | ||
| 1627 | error ("Invalid ISO C character class"); | ||
| 1628 | |||
| 1629 | iso_classes = Fcons (make_number (cc), iso_classes); | ||
| 1630 | |||
| 1631 | i_byte = class_end + 2 - str; | ||
| 1632 | continue; | ||
| 1633 | } | ||
| 1634 | |||
| 1635 | not_a_class_name_multibyte: | ||
| 1636 | if (c == '\\') | ||
| 1637 | { | ||
| 1638 | if (i_byte == size_byte) | ||
| 1639 | break; | ||
| 1640 | |||
| 1641 | leading_code = str[i_byte]; | ||
| 1508 | c = STRING_CHAR_AND_LENGTH (str + i_byte, | 1642 | c = STRING_CHAR_AND_LENGTH (str + i_byte, |
| 1509 | size_byte - i_byte, len); | 1643 | size_byte - i_byte, len); |
| 1510 | i_byte += len; | 1644 | i_byte += len; |
| @@ -1515,61 +1649,90 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) | |||
| 1515 | && str[i_byte] == '-') | 1649 | && str[i_byte] == '-') |
| 1516 | { | 1650 | { |
| 1517 | unsigned int c2; | 1651 | unsigned int c2; |
| 1652 | unsigned char leading_code2; | ||
| 1518 | 1653 | ||
| 1519 | /* Skip over the dash. */ | 1654 | /* Skip over the dash. */ |
| 1520 | i_byte++; | 1655 | i_byte++; |
| 1521 | 1656 | ||
| 1522 | /* Get the end of the range. */ | 1657 | /* Get the end of the range. */ |
| 1658 | leading_code2 = str[i_byte]; | ||
| 1523 | c2 = STRING_CHAR_AND_LENGTH (str + i_byte, | 1659 | c2 = STRING_CHAR_AND_LENGTH (str + i_byte, |
| 1524 | size_byte - i_byte, len); | 1660 | size_byte - i_byte, len); |
| 1525 | i_byte += len; | 1661 | i_byte += len; |
| 1526 | 1662 | ||
| 1527 | if (SINGLE_BYTE_CHAR_P (c)) | 1663 | if (c2 == '\\' |
| 1664 | && i_byte < size_byte) | ||
| 1665 | { | ||
| 1666 | leading_code2 = str[i_byte]; | ||
| 1667 | c2 =STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len); | ||
| 1668 | i_byte += len; | ||
| 1669 | } | ||
| 1670 | |||
| 1671 | if (c > c2) | ||
| 1672 | continue; | ||
| 1673 | if (ASCII_CHAR_P (c)) | ||
| 1674 | { | ||
| 1675 | while (c <= c2 && c < 0x80) | ||
| 1676 | fastmap[c++] = 1; | ||
| 1677 | leading_code = CHAR_LEADING_CODE (c); | ||
| 1678 | } | ||
| 1679 | if (! ASCII_CHAR_P (c)) | ||
| 1528 | { | 1680 | { |
| 1529 | if (! SINGLE_BYTE_CHAR_P (c2)) | 1681 | while (leading_code <= leading_code2) |
| 1682 | fastmap[leading_code++] = 1; | ||
| 1683 | if (c <= c2) | ||
| 1530 | { | 1684 | { |
| 1531 | /* Handle a range starting with a character of | 1685 | char_ranges[n_char_ranges++] = c; |
| 1532 | less than 256, and ending with a character of | ||
| 1533 | not less than 256. Split that into two | ||
| 1534 | ranges, the low one ending at 0377, and the | ||
| 1535 | high one starting at the smallest character | ||
| 1536 | in the charset of C2 and ending at C2. */ | ||
| 1537 | int charset = CHAR_CHARSET (c2); | ||
| 1538 | int c1 = MAKE_CHAR (charset, 0, 0); | ||
| 1539 | |||
| 1540 | char_ranges[n_char_ranges++] = c1; | ||
| 1541 | char_ranges[n_char_ranges++] = c2; | 1686 | char_ranges[n_char_ranges++] = c2; |
| 1542 | c2 = 0377; | ||
| 1543 | } | 1687 | } |
| 1544 | while (c <= c2) | ||
| 1545 | { | ||
| 1546 | fastmap[c] = 1; | ||
| 1547 | c++; | ||
| 1548 | } | ||
| 1549 | } | ||
| 1550 | else if (c <= c2) /* Both C and C2 are multibyte char. */ | ||
| 1551 | { | ||
| 1552 | char_ranges[n_char_ranges++] = c; | ||
| 1553 | char_ranges[n_char_ranges++] = c2; | ||
| 1554 | } | 1688 | } |
| 1555 | } | 1689 | } |
| 1556 | else | 1690 | else |
| 1557 | { | 1691 | { |
| 1558 | if (SINGLE_BYTE_CHAR_P (c)) | 1692 | if (ASCII_CHAR_P (c)) |
| 1559 | fastmap[c] = 1; | 1693 | fastmap[c] = 1; |
| 1560 | else | 1694 | else |
| 1561 | { | 1695 | { |
| 1696 | fastmap[leading_code] = 1; | ||
| 1562 | char_ranges[n_char_ranges++] = c; | 1697 | char_ranges[n_char_ranges++] = c; |
| 1563 | char_ranges[n_char_ranges++] = c; | 1698 | char_ranges[n_char_ranges++] = c; |
| 1564 | } | 1699 | } |
| 1565 | } | 1700 | } |
| 1566 | } | 1701 | } |
| 1702 | |||
| 1703 | /* If the current range is unibyte and STRING contains non-ASCII | ||
| 1704 | chars, arrange fastmap for the corresponding unibyte | ||
| 1705 | chars. */ | ||
| 1706 | |||
| 1707 | if (! multibyte && n_char_ranges > 0) | ||
| 1708 | { | ||
| 1709 | bzero (fastmap + 0200, 0200); | ||
| 1710 | for (i = 0; i < n_char_ranges; i += 2) | ||
| 1711 | { | ||
| 1712 | int c1 = char_ranges[i]; | ||
| 1713 | int c2 = char_ranges[i + 1]; | ||
| 1714 | |||
| 1715 | for (; c1 <= c2; c1++) | ||
| 1716 | fastmap[CHAR_TO_BYTE8 (c1)] = 1; | ||
| 1717 | } | ||
| 1718 | } | ||
| 1567 | } | 1719 | } |
| 1568 | 1720 | ||
| 1569 | /* If ^ was the first character, complement the fastmap. */ | 1721 | /* If ^ was the first character, complement the fastmap. */ |
| 1570 | if (negate) | 1722 | if (negate) |
| 1571 | for (i = 0; i < sizeof fastmap; i++) | 1723 | { |
| 1572 | fastmap[i] ^= 1; | 1724 | if (! multibyte) |
| 1725 | for (i = 0; i < sizeof fastmap; i++) | ||
| 1726 | fastmap[i] ^= 1; | ||
| 1727 | else | ||
| 1728 | { | ||
| 1729 | for (i = 0; i < 0200; i++) | ||
| 1730 | fastmap[i] ^= 1; | ||
| 1731 | /* All non-ASCII chars possibly match. */ | ||
| 1732 | for (; i < sizeof fastmap; i++) | ||
| 1733 | fastmap[i] = 1; | ||
| 1734 | } | ||
| 1735 | } | ||
| 1573 | 1736 | ||
| 1574 | { | 1737 | { |
| 1575 | int start_point = PT; | 1738 | int start_point = PT; |
| @@ -1589,254 +1752,312 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes) | |||
| 1589 | } | 1752 | } |
| 1590 | 1753 | ||
| 1591 | immediate_quit = 1; | 1754 | immediate_quit = 1; |
| 1592 | if (syntaxp) | 1755 | if (forwardp) |
| 1593 | { | 1756 | { |
| 1594 | SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1); | 1757 | if (multibyte) |
| 1595 | if (forwardp) | 1758 | while (1) |
| 1596 | { | 1759 | { |
| 1597 | if (multibyte) | 1760 | int nbytes; |
| 1598 | while (1) | ||
| 1599 | { | ||
| 1600 | int nbytes; | ||
| 1601 | 1761 | ||
| 1602 | if (p >= stop) | 1762 | if (p >= stop) |
| 1603 | { | 1763 | { |
| 1604 | if (p >= endp) | 1764 | if (p >= endp) |
| 1605 | break; | ||
| 1606 | p = GAP_END_ADDR; | ||
| 1607 | stop = endp; | ||
| 1608 | } | ||
| 1609 | c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); | ||
| 1610 | if (! fastmap[(int) SYNTAX (c)]) | ||
| 1611 | break; | 1765 | break; |
| 1612 | p += nbytes, pos++, pos_byte += nbytes; | 1766 | p = GAP_END_ADDR; |
| 1613 | UPDATE_SYNTAX_TABLE_FORWARD (pos); | 1767 | stop = endp; |
| 1614 | } | 1768 | } |
| 1615 | else | 1769 | c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); |
| 1616 | while (1) | 1770 | if (! NILP (iso_classes) && in_classes (c, iso_classes)) |
| 1617 | { | 1771 | { |
| 1618 | if (p >= stop) | 1772 | if (negate) |
| 1619 | { | ||
| 1620 | if (p >= endp) | ||
| 1621 | break; | ||
| 1622 | p = GAP_END_ADDR; | ||
| 1623 | stop = endp; | ||
| 1624 | } | ||
| 1625 | if (! fastmap[(int) SYNTAX (*p)]) | ||
| 1626 | break; | 1773 | break; |
| 1627 | p++, pos++; | 1774 | else |
| 1628 | UPDATE_SYNTAX_TABLE_FORWARD (pos); | 1775 | goto fwd_ok; |
| 1629 | } | 1776 | } |
| 1630 | } | ||
| 1631 | else | ||
| 1632 | { | ||
| 1633 | if (multibyte) | ||
| 1634 | while (1) | ||
| 1635 | { | ||
| 1636 | unsigned char *prev_p; | ||
| 1637 | int nbytes; | ||
| 1638 | 1777 | ||
| 1639 | if (p <= stop) | 1778 | if (! fastmap[*p]) |
| 1640 | { | 1779 | break; |
| 1641 | if (p <= endp) | 1780 | if (! ASCII_CHAR_P (c)) |
| 1642 | break; | 1781 | { |
| 1643 | p = GPT_ADDR; | 1782 | /* As we are looking at a multibyte character, we |
| 1644 | stop = endp; | 1783 | must look up the character in the table |
| 1645 | } | 1784 | CHAR_RANGES. If there's no data in the table, |
| 1646 | prev_p = p; | 1785 | that character is not what we want to skip. */ |
| 1647 | while (--p >= stop && ! CHAR_HEAD_P (*p)); | 1786 | |
| 1648 | PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes); | 1787 | /* The following code do the right thing even if |
| 1649 | if (prev_p - p > nbytes) | 1788 | n_char_ranges is zero (i.e. no data in |
| 1650 | p = prev_p - 1, c = *p, nbytes = 1; | 1789 | CHAR_RANGES). */ |
| 1651 | else | 1790 | for (i = 0; i < n_char_ranges; i += 2) |
| 1652 | c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); | 1791 | if (c >= char_ranges[i] && c <= char_ranges[i + 1]) |
| 1653 | pos--, pos_byte -= nbytes; | ||
| 1654 | UPDATE_SYNTAX_TABLE_BACKWARD (pos); | ||
| 1655 | if (! fastmap[(int) SYNTAX (c)]) | ||
| 1656 | { | ||
| 1657 | pos++; | ||
| 1658 | pos_byte += nbytes; | ||
| 1659 | break; | 1792 | break; |
| 1660 | } | 1793 | if (!(negate ^ (i < n_char_ranges))) |
| 1794 | break; | ||
| 1661 | } | 1795 | } |
| 1662 | else | 1796 | fwd_ok: |
| 1663 | while (1) | 1797 | p += nbytes, pos++, pos_byte += nbytes; |
| 1798 | } | ||
| 1799 | else | ||
| 1800 | while (1) | ||
| 1801 | { | ||
| 1802 | if (p >= stop) | ||
| 1664 | { | 1803 | { |
| 1665 | if (p <= stop) | 1804 | if (p >= endp) |
| 1666 | { | ||
| 1667 | if (p <= endp) | ||
| 1668 | break; | ||
| 1669 | p = GPT_ADDR; | ||
| 1670 | stop = endp; | ||
| 1671 | } | ||
| 1672 | UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); | ||
| 1673 | if (! fastmap[(int) SYNTAX (p[-1])]) | ||
| 1674 | break; | 1805 | break; |
| 1675 | p--, pos--; | 1806 | p = GAP_END_ADDR; |
| 1807 | stop = endp; | ||
| 1676 | } | 1808 | } |
| 1677 | } | 1809 | |
| 1810 | if (!NILP (iso_classes) && in_classes (*p, iso_classes)) | ||
| 1811 | { | ||
| 1812 | if (negate) | ||
| 1813 | break; | ||
| 1814 | else | ||
| 1815 | goto fwd_unibyte_ok; | ||
| 1816 | } | ||
| 1817 | |||
| 1818 | if (!fastmap[*p]) | ||
| 1819 | break; | ||
| 1820 | fwd_unibyte_ok: | ||
| 1821 | p++, pos++, pos_byte++; | ||
| 1822 | } | ||
| 1678 | } | 1823 | } |
| 1679 | else | 1824 | else |
| 1680 | { | 1825 | { |
| 1681 | if (forwardp) | 1826 | if (multibyte) |
| 1682 | { | 1827 | while (1) |
| 1683 | if (multibyte) | 1828 | { |
| 1684 | while (1) | 1829 | unsigned char *prev_p; |
| 1685 | { | ||
| 1686 | int nbytes; | ||
| 1687 | |||
| 1688 | if (p >= stop) | ||
| 1689 | { | ||
| 1690 | if (p >= endp) | ||
| 1691 | break; | ||
| 1692 | p = GAP_END_ADDR; | ||
| 1693 | stop = endp; | ||
| 1694 | } | ||
| 1695 | c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); | ||
| 1696 | 1830 | ||
| 1697 | if (! NILP (iso_classes) && in_classes (c, iso_classes)) | 1831 | if (p <= stop) |
| 1698 | { | 1832 | { |
| 1699 | if (negate) | 1833 | if (p <= endp) |
| 1700 | break; | 1834 | break; |
| 1701 | else | 1835 | p = GPT_ADDR; |
| 1702 | goto fwd_ok; | 1836 | stop = endp; |
| 1703 | } | 1837 | } |
| 1838 | prev_p = p; | ||
| 1839 | while (--p >= stop && ! CHAR_HEAD_P (*p)); | ||
| 1840 | c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); | ||
| 1704 | 1841 | ||
| 1705 | if (SINGLE_BYTE_CHAR_P (c)) | 1842 | if (! NILP (iso_classes) && in_classes (c, iso_classes)) |
| 1706 | { | 1843 | { |
| 1707 | if (!fastmap[c]) | 1844 | if (negate) |
| 1708 | break; | 1845 | break; |
| 1709 | } | ||
| 1710 | else | 1846 | else |
| 1711 | { | 1847 | goto back_ok; |
| 1712 | /* If we are looking at a multibyte character, | ||
| 1713 | we must look up the character in the table | ||
| 1714 | CHAR_RANGES. If there's no data in the | ||
| 1715 | table, that character is not what we want to | ||
| 1716 | skip. */ | ||
| 1717 | |||
| 1718 | /* The following code do the right thing even if | ||
| 1719 | n_char_ranges is zero (i.e. no data in | ||
| 1720 | CHAR_RANGES). */ | ||
| 1721 | for (i = 0; i < n_char_ranges; i += 2) | ||
| 1722 | if (c >= char_ranges[i] && c <= char_ranges[i + 1]) | ||
| 1723 | break; | ||
| 1724 | if (!(negate ^ (i < n_char_ranges))) | ||
| 1725 | break; | ||
| 1726 | } | ||
| 1727 | fwd_ok: | ||
| 1728 | p += nbytes, pos++, pos_byte += nbytes; | ||
| 1729 | } | 1848 | } |
| 1730 | else | ||
| 1731 | while (1) | ||
| 1732 | { | ||
| 1733 | if (p >= stop) | ||
| 1734 | { | ||
| 1735 | if (p >= endp) | ||
| 1736 | break; | ||
| 1737 | p = GAP_END_ADDR; | ||
| 1738 | stop = endp; | ||
| 1739 | } | ||
| 1740 | |||
| 1741 | if (!NILP (iso_classes) && in_classes (*p, iso_classes)) | ||
| 1742 | { | ||
| 1743 | if (negate) | ||
| 1744 | break; | ||
| 1745 | else | ||
| 1746 | goto fwd_unibyte_ok; | ||
| 1747 | } | ||
| 1748 | 1849 | ||
| 1749 | if (!fastmap[*p]) | 1850 | if (! fastmap[*p]) |
| 1851 | break; | ||
| 1852 | if (! ASCII_CHAR_P (c)) | ||
| 1853 | { | ||
| 1854 | /* See the comment in the previous similar code. */ | ||
| 1855 | for (i = 0; i < n_char_ranges; i += 2) | ||
| 1856 | if (c >= char_ranges[i] && c <= char_ranges[i + 1]) | ||
| 1857 | break; | ||
| 1858 | if (!(negate ^ (i < n_char_ranges))) | ||
| 1750 | break; | 1859 | break; |
| 1751 | fwd_unibyte_ok: | ||
| 1752 | p++, pos++; | ||
| 1753 | } | 1860 | } |
| 1754 | } | 1861 | back_ok: |
| 1862 | pos--, pos_byte -= prev_p - p; | ||
| 1863 | } | ||
| 1755 | else | 1864 | else |
| 1756 | { | 1865 | while (1) |
| 1757 | if (multibyte) | 1866 | { |
| 1758 | while (1) | 1867 | if (p <= stop) |
| 1759 | { | 1868 | { |
| 1760 | unsigned char *prev_p; | 1869 | if (p <= endp) |
| 1761 | int nbytes; | 1870 | break; |
| 1871 | p = GPT_ADDR; | ||
| 1872 | stop = endp; | ||
| 1873 | } | ||
| 1762 | 1874 | ||
| 1763 | if (p <= stop) | 1875 | if (! NILP (iso_classes) && in_classes (p[-1], iso_classes)) |
| 1764 | { | 1876 | { |
| 1765 | if (p <= endp) | 1877 | if (negate) |
| 1766 | break; | 1878 | break; |
| 1767 | p = GPT_ADDR; | ||
| 1768 | stop = endp; | ||
| 1769 | } | ||
| 1770 | prev_p = p; | ||
| 1771 | while (--p >= stop && ! CHAR_HEAD_P (*p)); | ||
| 1772 | PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes); | ||
| 1773 | if (prev_p - p > nbytes) | ||
| 1774 | p = prev_p - 1, c = *p, nbytes = 1; | ||
| 1775 | else | 1879 | else |
| 1776 | c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); | 1880 | goto back_unibyte_ok; |
| 1881 | } | ||
| 1777 | 1882 | ||
| 1778 | if (! NILP (iso_classes) && in_classes (c, iso_classes)) | 1883 | if (!fastmap[p[-1]]) |
| 1779 | { | 1884 | break; |
| 1780 | if (negate) | 1885 | back_unibyte_ok: |
| 1781 | break; | 1886 | p--, pos--, pos_byte--; |
| 1782 | else | 1887 | } |
| 1783 | goto back_ok; | 1888 | } |
| 1784 | } | ||
| 1785 | 1889 | ||
| 1786 | if (SINGLE_BYTE_CHAR_P (c)) | 1890 | SET_PT_BOTH (pos, pos_byte); |
| 1787 | { | 1891 | immediate_quit = 0; |
| 1788 | if (!fastmap[c]) | ||
| 1789 | break; | ||
| 1790 | } | ||
| 1791 | else | ||
| 1792 | { | ||
| 1793 | /* See the comment in the previous similar code. */ | ||
| 1794 | for (i = 0; i < n_char_ranges; i += 2) | ||
| 1795 | if (c >= char_ranges[i] && c <= char_ranges[i + 1]) | ||
| 1796 | break; | ||
| 1797 | if (!(negate ^ (i < n_char_ranges))) | ||
| 1798 | break; | ||
| 1799 | } | ||
| 1800 | back_ok: | ||
| 1801 | pos--, pos_byte -= nbytes; | ||
| 1802 | } | ||
| 1803 | else | ||
| 1804 | while (1) | ||
| 1805 | { | ||
| 1806 | if (p <= stop) | ||
| 1807 | { | ||
| 1808 | if (p <= endp) | ||
| 1809 | break; | ||
| 1810 | p = GPT_ADDR; | ||
| 1811 | stop = endp; | ||
| 1812 | } | ||
| 1813 | 1892 | ||
| 1814 | if (! NILP (iso_classes) && in_classes (p[-1], iso_classes)) | 1893 | return make_number (PT - start_point); |
| 1815 | { | 1894 | } |
| 1816 | if (negate) | 1895 | } |
| 1817 | break; | ||
| 1818 | else | ||
| 1819 | goto back_unibyte_ok; | ||
| 1820 | } | ||
| 1821 | 1896 | ||
| 1822 | if (!fastmap[p[-1]]) | 1897 | |
| 1823 | break; | 1898 | static Lisp_Object |
| 1824 | back_unibyte_ok: | 1899 | skip_syntaxes (forwardp, string, lim) |
| 1825 | p--, pos--; | 1900 | int forwardp; |
| 1826 | } | 1901 | Lisp_Object string, lim; |
| 1827 | } | 1902 | { |
| 1903 | register unsigned int c; | ||
| 1904 | unsigned char fastmap[0400]; | ||
| 1905 | int negate = 0; | ||
| 1906 | register int i, i_byte; | ||
| 1907 | int multibyte; | ||
| 1908 | int size_byte; | ||
| 1909 | unsigned char *str; | ||
| 1910 | |||
| 1911 | CHECK_STRING (string); | ||
| 1912 | |||
| 1913 | if (NILP (lim)) | ||
| 1914 | XSETINT (lim, forwardp ? ZV : BEGV); | ||
| 1915 | else | ||
| 1916 | CHECK_NUMBER_COERCE_MARKER (lim); | ||
| 1917 | |||
| 1918 | /* In any case, don't allow scan outside bounds of buffer. */ | ||
| 1919 | if (XINT (lim) > ZV) | ||
| 1920 | XSETFASTINT (lim, ZV); | ||
| 1921 | if (XINT (lim) < BEGV) | ||
| 1922 | XSETFASTINT (lim, BEGV); | ||
| 1923 | |||
| 1924 | if (forwardp ? (PT >= XFASTINT (lim)) : (PT <= XFASTINT (lim))) | ||
| 1925 | return make_number (0); | ||
| 1926 | |||
| 1927 | multibyte = (!NILP (current_buffer->enable_multibyte_characters) | ||
| 1928 | && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); | ||
| 1929 | |||
| 1930 | bzero (fastmap, sizeof fastmap); | ||
| 1931 | |||
| 1932 | if (SBYTES (string) > SCHARS (string)) | ||
| 1933 | /* As this is very rare case (syntax spec is ASCII only), don't | ||
| 1934 | consider efficiency. */ | ||
| 1935 | string = string_make_unibyte (string); | ||
| 1936 | |||
| 1937 | str = SDATA (string); | ||
| 1938 | size_byte = SBYTES (string); | ||
| 1939 | |||
| 1940 | i_byte = 0; | ||
| 1941 | if (i_byte < size_byte | ||
| 1942 | && SREF (string, 0) == '^') | ||
| 1943 | { | ||
| 1944 | negate = 1; i_byte++; | ||
| 1945 | } | ||
| 1946 | |||
| 1947 | /* Find the syntaxes specified and set their elements of fastmap. */ | ||
| 1948 | |||
| 1949 | while (i_byte < size_byte) | ||
| 1950 | { | ||
| 1951 | c = str[i_byte++]; | ||
| 1952 | fastmap[syntax_spec_code[c]] = 1; | ||
| 1953 | } | ||
| 1954 | |||
| 1955 | /* If ^ was the first character, complement the fastmap. */ | ||
| 1956 | if (negate) | ||
| 1957 | for (i = 0; i < sizeof fastmap; i++) | ||
| 1958 | fastmap[i] ^= 1; | ||
| 1959 | |||
| 1960 | { | ||
| 1961 | int start_point = PT; | ||
| 1962 | int pos = PT; | ||
| 1963 | int pos_byte = PT_BYTE; | ||
| 1964 | unsigned char *p = PT_ADDR, *endp, *stop; | ||
| 1965 | |||
| 1966 | if (forwardp) | ||
| 1967 | { | ||
| 1968 | endp = (XINT (lim) == GPT) ? GPT_ADDR : CHAR_POS_ADDR (XINT (lim)); | ||
| 1969 | stop = (pos < GPT && GPT < XINT (lim)) ? GPT_ADDR : endp; | ||
| 1970 | } | ||
| 1971 | else | ||
| 1972 | { | ||
| 1973 | endp = CHAR_POS_ADDR (XINT (lim)); | ||
| 1974 | stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp; | ||
| 1828 | } | 1975 | } |
| 1829 | 1976 | ||
| 1830 | #if 0 /* Not needed now that a position in mid-character | 1977 | immediate_quit = 1; |
| 1831 | cannot be specified in Lisp. */ | 1978 | SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1); |
| 1832 | if (multibyte | 1979 | if (forwardp) |
| 1833 | /* INC_POS or DEC_POS might have moved POS over LIM. */ | 1980 | { |
| 1834 | && (forwardp ? (pos > XINT (lim)) : (pos < XINT (lim)))) | 1981 | if (multibyte) |
| 1835 | pos = XINT (lim); | 1982 | { |
| 1836 | #endif | 1983 | while (1) |
| 1984 | { | ||
| 1985 | int nbytes; | ||
| 1986 | |||
| 1987 | if (p >= stop) | ||
| 1988 | { | ||
| 1989 | if (p >= endp) | ||
| 1990 | break; | ||
| 1991 | p = GAP_END_ADDR; | ||
| 1992 | stop = endp; | ||
| 1993 | } | ||
| 1994 | c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); | ||
| 1995 | if (! fastmap[(int) SYNTAX (c)]) | ||
| 1996 | break; | ||
| 1997 | p += nbytes, pos++, pos_byte += nbytes; | ||
| 1998 | UPDATE_SYNTAX_TABLE_FORWARD (pos); | ||
| 1999 | } | ||
| 2000 | } | ||
| 2001 | else | ||
| 2002 | { | ||
| 2003 | while (1) | ||
| 2004 | { | ||
| 2005 | if (p >= stop) | ||
| 2006 | { | ||
| 2007 | if (p >= endp) | ||
| 2008 | break; | ||
| 2009 | p = GAP_END_ADDR; | ||
| 2010 | stop = endp; | ||
| 2011 | } | ||
| 2012 | if (! fastmap[(int) SYNTAX (*p)]) | ||
| 2013 | break; | ||
| 2014 | p++, pos++, pos_byte++; | ||
| 2015 | UPDATE_SYNTAX_TABLE_FORWARD (pos); | ||
| 2016 | } | ||
| 2017 | } | ||
| 2018 | } | ||
| 2019 | else | ||
| 2020 | { | ||
| 2021 | if (multibyte) | ||
| 2022 | { | ||
| 2023 | while (1) | ||
| 2024 | { | ||
| 2025 | unsigned char *prev_p; | ||
| 1837 | 2026 | ||
| 1838 | if (! multibyte) | 2027 | if (p <= stop) |
| 1839 | pos_byte = pos; | 2028 | { |
| 2029 | if (p <= endp) | ||
| 2030 | break; | ||
| 2031 | p = GPT_ADDR; | ||
| 2032 | stop = endp; | ||
| 2033 | } | ||
| 2034 | UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); | ||
| 2035 | prev_p = p; | ||
| 2036 | while (--p >= stop && ! CHAR_HEAD_P (*p)); | ||
| 2037 | c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); | ||
| 2038 | if (! fastmap[(int) SYNTAX (c)]) | ||
| 2039 | break; | ||
| 2040 | pos--, pos_byte -= prev_p - p; | ||
| 2041 | } | ||
| 2042 | } | ||
| 2043 | else | ||
| 2044 | { | ||
| 2045 | while (1) | ||
| 2046 | { | ||
| 2047 | if (p <= stop) | ||
| 2048 | { | ||
| 2049 | if (p <= endp) | ||
| 2050 | break; | ||
| 2051 | p = GPT_ADDR; | ||
| 2052 | stop = endp; | ||
| 2053 | } | ||
| 2054 | UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); | ||
| 2055 | if (! fastmap[(int) SYNTAX (p[-1])]) | ||
| 2056 | break; | ||
| 2057 | p--, pos--, pos_byte--; | ||
| 2058 | } | ||
| 2059 | } | ||
| 2060 | } | ||
| 1840 | 2061 | ||
| 1841 | SET_PT_BOTH (pos, pos_byte); | 2062 | SET_PT_BOTH (pos, pos_byte); |
| 1842 | immediate_quit = 0; | 2063 | immediate_quit = 0; |
| @@ -1921,7 +2142,7 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax, | |||
| 1921 | *bytepos_ptr = from_byte; | 2142 | *bytepos_ptr = from_byte; |
| 1922 | return 0; | 2143 | return 0; |
| 1923 | } | 2144 | } |
| 1924 | c = FETCH_CHAR (from_byte); | 2145 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1925 | syntax = SYNTAX_WITH_FLAGS (c); | 2146 | syntax = SYNTAX_WITH_FLAGS (c); |
| 1926 | code = syntax & 0xff; | 2147 | code = syntax & 0xff; |
| 1927 | if (code == Sendcomment | 2148 | if (code == Sendcomment |
| @@ -1951,7 +2172,7 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax, | |||
| 1951 | forw_incomment: | 2172 | forw_incomment: |
| 1952 | if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax) | 2173 | if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax) |
| 1953 | && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style | 2174 | && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style |
| 1954 | && (c1 = FETCH_CHAR (from_byte), | 2175 | && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 1955 | SYNTAX_COMEND_SECOND (c1)) | 2176 | SYNTAX_COMEND_SECOND (c1)) |
| 1956 | && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) || | 2177 | && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) || |
| 1957 | SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0)) | 2178 | SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0)) |
| @@ -1970,7 +2191,7 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax, | |||
| 1970 | if (nesting > 0 | 2191 | if (nesting > 0 |
| 1971 | && from < stop | 2192 | && from < stop |
| 1972 | && SYNTAX_FLAGS_COMSTART_FIRST (syntax) | 2193 | && SYNTAX_FLAGS_COMSTART_FIRST (syntax) |
| 1973 | && (c1 = FETCH_CHAR (from_byte), | 2194 | && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 1974 | SYNTAX_COMMENT_STYLE (c1) == style | 2195 | SYNTAX_COMMENT_STYLE (c1) == style |
| 1975 | && SYNTAX_COMSTART_SECOND (c1)) | 2196 | && SYNTAX_COMSTART_SECOND (c1)) |
| 1976 | && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) || | 2197 | && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) || |
| @@ -2034,7 +2255,7 @@ between them, return t; otherwise return nil. */) | |||
| 2034 | immediate_quit = 0; | 2255 | immediate_quit = 0; |
| 2035 | return Qnil; | 2256 | return Qnil; |
| 2036 | } | 2257 | } |
| 2037 | c = FETCH_CHAR (from_byte); | 2258 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2038 | code = SYNTAX (c); | 2259 | code = SYNTAX (c); |
| 2039 | comstart_first = SYNTAX_COMSTART_FIRST (c); | 2260 | comstart_first = SYNTAX_COMSTART_FIRST (c); |
| 2040 | comnested = SYNTAX_COMMENT_NESTED (c); | 2261 | comnested = SYNTAX_COMMENT_NESTED (c); |
| @@ -2042,7 +2263,7 @@ between them, return t; otherwise return nil. */) | |||
| 2042 | INC_BOTH (from, from_byte); | 2263 | INC_BOTH (from, from_byte); |
| 2043 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2264 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2044 | if (from < stop && comstart_first | 2265 | if (from < stop && comstart_first |
| 2045 | && (c1 = FETCH_CHAR (from_byte), | 2266 | && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 2046 | SYNTAX_COMSTART_SECOND (c1))) | 2267 | SYNTAX_COMSTART_SECOND (c1))) |
| 2047 | { | 2268 | { |
| 2048 | /* We have encountered a comment start sequence and we | 2269 | /* We have encountered a comment start sequence and we |
| @@ -2100,7 +2321,7 @@ between them, return t; otherwise return nil. */) | |||
| 2100 | DEC_BOTH (from, from_byte); | 2321 | DEC_BOTH (from, from_byte); |
| 2101 | /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */ | 2322 | /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */ |
| 2102 | quoted = char_quoted (from, from_byte); | 2323 | quoted = char_quoted (from, from_byte); |
| 2103 | c = FETCH_CHAR (from_byte); | 2324 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2104 | code = SYNTAX (c); | 2325 | code = SYNTAX (c); |
| 2105 | comstyle = 0; | 2326 | comstyle = 0; |
| 2106 | comnested = SYNTAX_COMMENT_NESTED (c); | 2327 | comnested = SYNTAX_COMMENT_NESTED (c); |
| @@ -2117,7 +2338,7 @@ between them, return t; otherwise return nil. */) | |||
| 2117 | code = Sendcomment; | 2338 | code = Sendcomment; |
| 2118 | /* Calling char_quoted, above, set up global syntax position | 2339 | /* Calling char_quoted, above, set up global syntax position |
| 2119 | at the new value of FROM. */ | 2340 | at the new value of FROM. */ |
| 2120 | c1 = FETCH_CHAR (from_byte); | 2341 | c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2121 | comstyle = SYNTAX_COMMENT_STYLE (c1); | 2342 | comstyle = SYNTAX_COMMENT_STYLE (c1); |
| 2122 | comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 2343 | comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
| 2123 | } | 2344 | } |
| @@ -2131,7 +2352,7 @@ between them, return t; otherwise return nil. */) | |||
| 2131 | { | 2352 | { |
| 2132 | DEC_BOTH (from, from_byte); | 2353 | DEC_BOTH (from, from_byte); |
| 2133 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2354 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2134 | c = FETCH_CHAR (from_byte); | 2355 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2135 | if (SYNTAX (c) == Scomment_fence | 2356 | if (SYNTAX (c) == Scomment_fence |
| 2136 | && !char_quoted (from, from_byte)) | 2357 | && !char_quoted (from, from_byte)) |
| 2137 | { | 2358 | { |
| @@ -2197,11 +2418,11 @@ between them, return t; otherwise return nil. */) | |||
| 2197 | return Qt; | 2418 | return Qt; |
| 2198 | } | 2419 | } |
| 2199 | 2420 | ||
| 2200 | /* Return syntax code of character C if C is a single byte character | 2421 | /* Return syntax code of character C if C is an ASCII character |
| 2201 | or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */ | 2422 | or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */ |
| 2202 | 2423 | ||
| 2203 | #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \ | 2424 | #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \ |
| 2204 | ((SINGLE_BYTE_CHAR_P (c) || !multibyte_symbol_p) \ | 2425 | ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \ |
| 2205 | ? SYNTAX (c) : Ssymbol) | 2426 | ? SYNTAX (c) : Ssymbol) |
| 2206 | 2427 | ||
| 2207 | static Lisp_Object | 2428 | static Lisp_Object |
| @@ -2245,7 +2466,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2245 | { | 2466 | { |
| 2246 | int comstart_first, prefix; | 2467 | int comstart_first, prefix; |
| 2247 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2468 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2248 | c = FETCH_CHAR (from_byte); | 2469 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2249 | code = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2470 | code = SYNTAX_WITH_MULTIBYTE_CHECK (c); |
| 2250 | comstart_first = SYNTAX_COMSTART_FIRST (c); | 2471 | comstart_first = SYNTAX_COMSTART_FIRST (c); |
| 2251 | comnested = SYNTAX_COMMENT_NESTED (c); | 2472 | comnested = SYNTAX_COMMENT_NESTED (c); |
| @@ -2256,7 +2477,8 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2256 | INC_BOTH (from, from_byte); | 2477 | INC_BOTH (from, from_byte); |
| 2257 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2478 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2258 | if (from < stop && comstart_first | 2479 | if (from < stop && comstart_first |
| 2259 | && (c = FETCH_CHAR (from_byte), SYNTAX_COMSTART_SECOND (c)) | 2480 | && (c = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 2481 | SYNTAX_COMSTART_SECOND (c)) | ||
| 2260 | && parse_sexp_ignore_comments) | 2482 | && parse_sexp_ignore_comments) |
| 2261 | { | 2483 | { |
| 2262 | /* we have encountered a comment start sequence and we | 2484 | /* we have encountered a comment start sequence and we |
| @@ -2265,7 +2487,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2265 | only a comment end of the same style actually ends | 2487 | only a comment end of the same style actually ends |
| 2266 | the comment section */ | 2488 | the comment section */ |
| 2267 | code = Scomment; | 2489 | code = Scomment; |
| 2268 | c1 = FETCH_CHAR (from_byte); | 2490 | c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2269 | comstyle = SYNTAX_COMMENT_STYLE (c1); | 2491 | comstyle = SYNTAX_COMMENT_STYLE (c1); |
| 2270 | comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 2492 | comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
| 2271 | INC_BOTH (from, from_byte); | 2493 | INC_BOTH (from, from_byte); |
| @@ -2291,7 +2513,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2291 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2513 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2292 | 2514 | ||
| 2293 | /* Some compilers can't handle this inside the switch. */ | 2515 | /* Some compilers can't handle this inside the switch. */ |
| 2294 | c = FETCH_CHAR (from_byte); | 2516 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2295 | temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2517 | temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); |
| 2296 | switch (temp) | 2518 | switch (temp) |
| 2297 | { | 2519 | { |
| @@ -2334,7 +2556,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2334 | case Smath: | 2556 | case Smath: |
| 2335 | if (!sexpflag) | 2557 | if (!sexpflag) |
| 2336 | break; | 2558 | break; |
| 2337 | if (from != stop && c == FETCH_CHAR (from_byte)) | 2559 | if (from != stop && c == FETCH_CHAR_AS_MULTIBYTE (from_byte)) |
| 2338 | { | 2560 | { |
| 2339 | INC_BOTH (from, from_byte); | 2561 | INC_BOTH (from, from_byte); |
| 2340 | } | 2562 | } |
| @@ -2361,12 +2583,12 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2361 | case Sstring: | 2583 | case Sstring: |
| 2362 | case Sstring_fence: | 2584 | case Sstring_fence: |
| 2363 | temp_pos = dec_bytepos (from_byte); | 2585 | temp_pos = dec_bytepos (from_byte); |
| 2364 | stringterm = FETCH_CHAR (temp_pos); | 2586 | stringterm = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2365 | while (1) | 2587 | while (1) |
| 2366 | { | 2588 | { |
| 2367 | if (from >= stop) goto lose; | 2589 | if (from >= stop) goto lose; |
| 2368 | UPDATE_SYNTAX_TABLE_FORWARD (from); | 2590 | UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2369 | c = FETCH_CHAR (from_byte); | 2591 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2370 | if (code == Sstring | 2592 | if (code == Sstring |
| 2371 | ? (c == stringterm | 2593 | ? (c == stringterm |
| 2372 | && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) | 2594 | && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) |
| @@ -2409,7 +2631,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2409 | { | 2631 | { |
| 2410 | DEC_BOTH (from, from_byte); | 2632 | DEC_BOTH (from, from_byte); |
| 2411 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2633 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2412 | c = FETCH_CHAR (from_byte); | 2634 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2413 | code = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2635 | code = SYNTAX_WITH_MULTIBYTE_CHECK (c); |
| 2414 | if (depth == min_depth) | 2636 | if (depth == min_depth) |
| 2415 | last_good = from; | 2637 | last_good = from; |
| @@ -2427,7 +2649,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2427 | DEC_BOTH (from, from_byte); | 2649 | DEC_BOTH (from, from_byte); |
| 2428 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2650 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2429 | code = Sendcomment; | 2651 | code = Sendcomment; |
| 2430 | c1 = FETCH_CHAR (from_byte); | 2652 | c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2431 | comstyle = SYNTAX_COMMENT_STYLE (c1); | 2653 | comstyle = SYNTAX_COMMENT_STYLE (c1); |
| 2432 | comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 2654 | comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
| 2433 | } | 2655 | } |
| @@ -2460,7 +2682,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2460 | else | 2682 | else |
| 2461 | temp_pos--; | 2683 | temp_pos--; |
| 2462 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2684 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2463 | c1 = FETCH_CHAR (temp_pos); | 2685 | c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2464 | temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); | 2686 | temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); |
| 2465 | /* Don't allow comment-end to be quoted. */ | 2687 | /* Don't allow comment-end to be quoted. */ |
| 2466 | if (temp_code == Sendcomment) | 2688 | if (temp_code == Sendcomment) |
| @@ -2472,7 +2694,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2472 | temp_pos = dec_bytepos (temp_pos); | 2694 | temp_pos = dec_bytepos (temp_pos); |
| 2473 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2695 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2474 | } | 2696 | } |
| 2475 | c1 = FETCH_CHAR (temp_pos); | 2697 | c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2476 | temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); | 2698 | temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); |
| 2477 | if (! (quoted || temp_code == Sword | 2699 | if (! (quoted || temp_code == Sword |
| 2478 | || temp_code == Ssymbol | 2700 | || temp_code == Ssymbol |
| @@ -2487,7 +2709,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2487 | break; | 2709 | break; |
| 2488 | temp_pos = dec_bytepos (from_byte); | 2710 | temp_pos = dec_bytepos (from_byte); |
| 2489 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2711 | UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2490 | if (from != stop && c == FETCH_CHAR (temp_pos)) | 2712 | if (from != stop && c == FETCH_CHAR_AS_MULTIBYTE (temp_pos)) |
| 2491 | DEC_BOTH (from, from_byte); | 2713 | DEC_BOTH (from, from_byte); |
| 2492 | if (mathexit) | 2714 | if (mathexit) |
| 2493 | { | 2715 | { |
| @@ -2532,7 +2754,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2532 | DEC_BOTH (from, from_byte); | 2754 | DEC_BOTH (from, from_byte); |
| 2533 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2755 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2534 | if (!char_quoted (from, from_byte) | 2756 | if (!char_quoted (from, from_byte) |
| 2535 | && (c = FETCH_CHAR (from_byte), | 2757 | && (c = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 2536 | SYNTAX_WITH_MULTIBYTE_CHECK (c) == code)) | 2758 | SYNTAX_WITH_MULTIBYTE_CHECK (c) == code)) |
| 2537 | break; | 2759 | break; |
| 2538 | } | 2760 | } |
| @@ -2540,14 +2762,15 @@ scan_lists (from, count, depth, sexpflag) | |||
| 2540 | break; | 2762 | break; |
| 2541 | 2763 | ||
| 2542 | case Sstring: | 2764 | case Sstring: |
| 2543 | stringterm = FETCH_CHAR (from_byte); | 2765 | stringterm = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2544 | while (1) | 2766 | while (1) |
| 2545 | { | 2767 | { |
| 2546 | if (from == stop) goto lose; | 2768 | if (from == stop) goto lose; |
| 2547 | DEC_BOTH (from, from_byte); | 2769 | DEC_BOTH (from, from_byte); |
| 2548 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2770 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2549 | if (!char_quoted (from, from_byte) | 2771 | if (!char_quoted (from, from_byte) |
| 2550 | && stringterm == (c = FETCH_CHAR (from_byte)) | 2772 | && (stringterm |
| 2773 | == (c = FETCH_CHAR_AS_MULTIBYTE (from_byte))) | ||
| 2551 | && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) | 2774 | && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) |
| 2552 | break; | 2775 | break; |
| 2553 | } | 2776 | } |
| @@ -2650,7 +2873,7 @@ This includes chars with "quote" or "prefix" syntax (' or p). */) | |||
| 2650 | 2873 | ||
| 2651 | while (!char_quoted (pos, pos_byte) | 2874 | while (!char_quoted (pos, pos_byte) |
| 2652 | /* Previous statement updates syntax table. */ | 2875 | /* Previous statement updates syntax table. */ |
| 2653 | && ((c = FETCH_CHAR (pos_byte), SYNTAX (c) == Squote) | 2876 | && ((c = FETCH_CHAR_AS_MULTIBYTE (pos_byte), SYNTAX (c) == Squote) |
| 2654 | || SYNTAX_PREFIX (c))) | 2877 | || SYNTAX_PREFIX (c))) |
| 2655 | { | 2878 | { |
| 2656 | opoint = pos; | 2879 | opoint = pos; |
| @@ -2678,7 +2901,8 @@ scan_sexps_forward (stateptr, from, from_byte, end, targetdepth, | |||
| 2678 | stopbefore, oldstate, commentstop) | 2901 | stopbefore, oldstate, commentstop) |
| 2679 | struct lisp_parse_state *stateptr; | 2902 | struct lisp_parse_state *stateptr; |
| 2680 | register int from; | 2903 | register int from; |
| 2681 | int end, targetdepth, stopbefore, from_byte; | 2904 | int from_byte; |
| 2905 | int end, targetdepth, stopbefore; | ||
| 2682 | Lisp_Object oldstate; | 2906 | Lisp_Object oldstate; |
| 2683 | int commentstop; | 2907 | int commentstop; |
| 2684 | { | 2908 | { |
| @@ -2715,7 +2939,7 @@ scan_sexps_forward (stateptr, from, from_byte, end, targetdepth, | |||
| 2715 | #define INC_FROM \ | 2939 | #define INC_FROM \ |
| 2716 | do { prev_from = from; \ | 2940 | do { prev_from = from; \ |
| 2717 | prev_from_byte = from_byte; \ | 2941 | prev_from_byte = from_byte; \ |
| 2718 | temp = FETCH_CHAR (prev_from_byte); \ | 2942 | temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \ |
| 2719 | prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \ | 2943 | prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \ |
| 2720 | INC_BOTH (from, from_byte); \ | 2944 | INC_BOTH (from, from_byte); \ |
| 2721 | if (from < end) \ | 2945 | if (from < end) \ |
| @@ -2871,7 +3095,7 @@ do { prev_from = from; \ | |||
| 2871 | while (from < end) | 3095 | while (from < end) |
| 2872 | { | 3096 | { |
| 2873 | /* Some compilers can't handle this inside the switch. */ | 3097 | /* Some compilers can't handle this inside the switch. */ |
| 2874 | temp = FETCH_CHAR (from_byte); | 3098 | temp = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2875 | temp = SYNTAX (temp); | 3099 | temp = SYNTAX (temp); |
| 2876 | switch (temp) | 3100 | switch (temp) |
| 2877 | { | 3101 | { |
| @@ -2945,7 +3169,7 @@ do { prev_from = from; \ | |||
| 2945 | if (stopbefore) goto stop; /* this arg means stop at sexp start */ | 3169 | if (stopbefore) goto stop; /* this arg means stop at sexp start */ |
| 2946 | curlevel->last = prev_from; | 3170 | curlevel->last = prev_from; |
| 2947 | state.instring = (code == Sstring | 3171 | state.instring = (code == Sstring |
| 2948 | ? (FETCH_CHAR (prev_from_byte)) | 3172 | ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte)) |
| 2949 | : ST_STRING_STYLE); | 3173 | : ST_STRING_STYLE); |
| 2950 | if (boundary_stop) goto done; | 3174 | if (boundary_stop) goto done; |
| 2951 | startinstring: | 3175 | startinstring: |
| @@ -2957,7 +3181,7 @@ do { prev_from = from; \ | |||
| 2957 | int c; | 3181 | int c; |
| 2958 | 3182 | ||
| 2959 | if (from >= end) goto done; | 3183 | if (from >= end) goto done; |
| 2960 | c = FETCH_CHAR (from_byte); | 3184 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2961 | /* Some compilers can't handle this inside the switch. */ | 3185 | /* Some compilers can't handle this inside the switch. */ |
| 2962 | temp = SYNTAX (c); | 3186 | temp = SYNTAX (c); |
| 2963 | 3187 | ||
| @@ -3183,8 +3407,7 @@ init_syntax_once () | |||
| 3183 | 3407 | ||
| 3184 | /* All multibyte characters have syntax `word' by default. */ | 3408 | /* All multibyte characters have syntax `word' by default. */ |
| 3185 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; | 3409 | temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; |
| 3186 | for (i = CHAR_TABLE_SINGLE_BYTE_SLOTS; i < CHAR_TABLE_ORDINARY_SLOTS; i++) | 3410 | char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp); |
| 3187 | XCHAR_TABLE (Vstandard_syntax_table)->contents[i] = temp; | ||
| 3188 | } | 3411 | } |
| 3189 | 3412 | ||
| 3190 | void | 3413 | void |
| @@ -3232,6 +3455,25 @@ See the info node `(elisp)Syntax Properties' for a description of the | |||
| 3232 | doc: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */); | 3455 | doc: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */); |
| 3233 | open_paren_in_column_0_is_defun_start = 1; | 3456 | open_paren_in_column_0_is_defun_start = 1; |
| 3234 | 3457 | ||
| 3458 | |||
| 3459 | DEFVAR_LISP ("find-word-boundary-function-table", | ||
| 3460 | &Vfind_word_boundary_function_table, | ||
| 3461 | doc: /* | ||
| 3462 | Char table of functions to search for the word boundary. | ||
| 3463 | Each function is called with two arguments; POS and LIMIT. | ||
| 3464 | POS and LIMIT are character positions in the current buffer. | ||
| 3465 | |||
| 3466 | If POS is less than LIMIT, POS is at the first character of a word, | ||
| 3467 | and the return value of a function is a position after the last | ||
| 3468 | character of that word. | ||
| 3469 | |||
| 3470 | If POS is not less than LIMIT, POS is at the last character of a word, | ||
| 3471 | and the return value of a function is a position at the first | ||
| 3472 | character of that word. | ||
| 3473 | |||
| 3474 | In both cases, LIMIT bounds the search. */); | ||
| 3475 | Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil); | ||
| 3476 | |||
| 3235 | defsubr (&Ssyntax_table_p); | 3477 | defsubr (&Ssyntax_table_p); |
| 3236 | defsubr (&Ssyntax_table); | 3478 | defsubr (&Ssyntax_table); |
| 3237 | defsubr (&Sstandard_syntax_table); | 3479 | defsubr (&Sstandard_syntax_table); |