Mercurial > emacs
comparison src/syntax.c @ 89483:2f877ed80fa6
*** empty log message ***
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Mon, 08 Sep 2003 12:53:41 +0000 |
| parents | 375f2633d815 9664825d832f |
| children | 96081c0be5ca |
comparison
equal
deleted
inserted
replaced
| 88123:375f2633d815 | 89483:2f877ed80fa6 |
|---|---|
| 22 #include <config.h> | 22 #include <config.h> |
| 23 #include <ctype.h> | 23 #include <ctype.h> |
| 24 #include "lisp.h" | 24 #include "lisp.h" |
| 25 #include "commands.h" | 25 #include "commands.h" |
| 26 #include "buffer.h" | 26 #include "buffer.h" |
| 27 #include "charset.h" | 27 #include "character.h" |
| 28 #include "keymap.h" | 28 #include "keymap.h" |
| 29 | 29 |
| 30 /* Make syntax table lookup grant data in gl_state. */ | 30 /* Make syntax table lookup grant data in gl_state. */ |
| 31 #define SYNTAX_ENTRY_VIA_PROPERTY | 31 #define SYNTAX_ENTRY_VIA_PROPERTY |
| 32 | 32 |
| 95 | 95 |
| 96 | 96 |
| 97 static int find_defun_start P_ ((int, int)); | 97 static int find_defun_start P_ ((int, int)); |
| 98 static int back_comment P_ ((int, int, int, int, int, int *, int *)); | 98 static int back_comment P_ ((int, int, int, int, int, int *, int *)); |
| 99 static int char_quoted P_ ((int, int)); | 99 static int char_quoted P_ ((int, int)); |
| 100 static Lisp_Object skip_chars P_ ((int, int, Lisp_Object, Lisp_Object)); | 100 static Lisp_Object skip_chars P_ ((int, Lisp_Object, Lisp_Object)); |
| 101 static Lisp_Object skip_syntaxes P_ ((int, Lisp_Object, Lisp_Object)); | |
| 101 static Lisp_Object scan_lists P_ ((int, int, int, int)); | 102 static Lisp_Object scan_lists P_ ((int, int, int, int)); |
| 102 static void scan_sexps_forward P_ ((struct lisp_parse_state *, | 103 static void scan_sexps_forward P_ ((struct lisp_parse_state *, |
| 103 int, int, int, int, | 104 int, int, int, int, |
| 104 int, Lisp_Object, int)); | 105 int, Lisp_Object, int)); |
| 105 | 106 |
| 291 DEC_BOTH (charpos, bytepos); | 292 DEC_BOTH (charpos, bytepos); |
| 292 | 293 |
| 293 while (bytepos >= beg) | 294 while (bytepos >= beg) |
| 294 { | 295 { |
| 295 UPDATE_SYNTAX_TABLE_BACKWARD (charpos); | 296 UPDATE_SYNTAX_TABLE_BACKWARD (charpos); |
| 296 code = SYNTAX (FETCH_CHAR (bytepos)); | 297 code = SYNTAX (FETCH_CHAR_AS_MULTIBYTE (bytepos)); |
| 297 if (! (code == Scharquote || code == Sescape)) | 298 if (! (code == Scharquote || code == Sescape)) |
| 298 break; | 299 break; |
| 299 | 300 |
| 300 DEC_BOTH (charpos, bytepos); | 301 DEC_BOTH (charpos, bytepos); |
| 301 quoted = !quoted; | 302 quoted = !quoted; |
| 380 gl_state.use_global = 0; | 381 gl_state.use_global = 0; |
| 381 while (PT > BEGV) | 382 while (PT > BEGV) |
| 382 { | 383 { |
| 383 /* Open-paren at start of line means we may have found our | 384 /* Open-paren at start of line means we may have found our |
| 384 defun-start. */ | 385 defun-start. */ |
| 385 if (SYNTAX (FETCH_CHAR (PT_BYTE)) == Sopen) | 386 if (SYNTAX (FETCH_CHAR_AS_MULTIBYTE (PT_BYTE)) == Sopen) |
| 386 { | 387 { |
| 387 SETUP_SYNTAX_TABLE (PT + 1, -1); /* Try again... */ | 388 SETUP_SYNTAX_TABLE (PT + 1, -1); /* Try again... */ |
| 388 if (SYNTAX (FETCH_CHAR (PT_BYTE)) == Sopen) | 389 if (SYNTAX (FETCH_CHAR_AS_MULTIBYTE (PT_BYTE)) == Sopen) |
| 389 break; | 390 break; |
| 390 /* Now fallback to the default value. */ | 391 /* Now fallback to the default value. */ |
| 391 gl_state.current_syntax_table = current_buffer->syntax_table; | 392 gl_state.current_syntax_table = current_buffer->syntax_table; |
| 392 gl_state.use_global = 0; | 393 gl_state.use_global = 0; |
| 393 } | 394 } |
| 503 /* Move back and examine a character. */ | 504 /* Move back and examine a character. */ |
| 504 DEC_BOTH (from, from_byte); | 505 DEC_BOTH (from, from_byte); |
| 505 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 506 UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 506 | 507 |
| 507 prev_syntax = syntax; | 508 prev_syntax = syntax; |
| 508 c = FETCH_CHAR (from_byte); | 509 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 509 syntax = SYNTAX_WITH_FLAGS (c); | 510 syntax = SYNTAX_WITH_FLAGS (c); |
| 510 code = SYNTAX (c); | 511 code = SYNTAX (c); |
| 511 | 512 |
| 512 /* Check for 2-char comment markers. */ | 513 /* Check for 2-char comment markers. */ |
| 513 com2start = (SYNTAX_FLAGS_COMSTART_FIRST (syntax) | 514 com2start = (SYNTAX_FLAGS_COMSTART_FIRST (syntax) |
| 532 if (from > stop && (com2end || com2start)) | 533 if (from > stop && (com2end || com2start)) |
| 533 { | 534 { |
| 534 int next = from, next_byte = from_byte, next_c, next_syntax; | 535 int next = from, next_byte = from_byte, next_c, next_syntax; |
| 535 DEC_BOTH (next, next_byte); | 536 DEC_BOTH (next, next_byte); |
| 536 UPDATE_SYNTAX_TABLE_BACKWARD (next); | 537 UPDATE_SYNTAX_TABLE_BACKWARD (next); |
| 537 next_c = FETCH_CHAR (next_byte); | 538 next_c = FETCH_CHAR_AS_MULTIBYTE (next_byte); |
| 538 next_syntax = SYNTAX_WITH_FLAGS (next_c); | 539 next_syntax = SYNTAX_WITH_FLAGS (next_c); |
| 539 if (((com2start || comnested) | 540 if (((com2start || comnested) |
| 540 && SYNTAX_FLAGS_COMEND_SECOND (syntax) | 541 && SYNTAX_FLAGS_COMEND_SECOND (syntax) |
| 541 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax)) | 542 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax)) |
| 542 || ((com2end || comnested) | 543 || ((com2end || comnested) |
| 836 sharing objects, the function `describe-syntax' can give a more | 837 sharing objects, the function `describe-syntax' can give a more |
| 837 compact listing. */ | 838 compact listing. */ |
| 838 static Lisp_Object Vsyntax_code_object; | 839 static Lisp_Object Vsyntax_code_object; |
| 839 | 840 |
| 840 | 841 |
| 841 /* Look up the value for CHARACTER in syntax table TABLE's parent | |
| 842 and its parents. SYNTAX_ENTRY calls this, when TABLE itself has nil | |
| 843 for CHARACTER. It's actually used only when not compiled with GCC. */ | |
| 844 | |
| 845 Lisp_Object | |
| 846 syntax_parent_lookup (table, character) | |
| 847 Lisp_Object table; | |
| 848 int character; | |
| 849 { | |
| 850 Lisp_Object value; | |
| 851 | |
| 852 while (1) | |
| 853 { | |
| 854 table = XCHAR_TABLE (table)->parent; | |
| 855 if (NILP (table)) | |
| 856 return Qnil; | |
| 857 | |
| 858 value = XCHAR_TABLE (table)->contents[character]; | |
| 859 if (!NILP (value)) | |
| 860 return value; | |
| 861 } | |
| 862 } | |
| 863 | |
| 864 DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0, | 842 DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0, |
| 865 doc: /* Return the syntax code of CHARACTER, described by a character. | 843 doc: /* Return the syntax code of CHARACTER, described by a character. |
| 866 For example, if CHARACTER is a word constituent, | 844 For example, if CHARACTER is a word constituent, |
| 867 the character `w' is returned. | 845 the character `w' is returned. |
| 868 The characters that correspond to various syntax codes | 846 The characters that correspond to various syntax codes |
| 977 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, | 955 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, |
| 978 "cSet syntax for character: \nsSet syntax for %s to: ", | 956 "cSet syntax for character: \nsSet syntax for %s to: ", |
| 979 doc: /* Set syntax for character CHAR according to string NEWENTRY. | 957 doc: /* Set syntax for character CHAR according to string NEWENTRY. |
| 980 The syntax is changed only for table SYNTAX_TABLE, which defaults to | 958 The syntax is changed only for table SYNTAX_TABLE, which defaults to |
| 981 the current buffer's syntax table. | 959 the current buffer's syntax table. |
| 960 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters | |
| 961 in the range MIN and MAX are changed. | |
| 982 The first character of NEWENTRY should be one of the following: | 962 The first character of NEWENTRY should be one of the following: |
| 983 Space or - whitespace syntax. w word constituent. | 963 Space or - whitespace syntax. w word constituent. |
| 984 _ symbol constituent. . punctuation. | 964 _ symbol constituent. . punctuation. |
| 985 ( open-parenthesis. ) close-parenthesis. | 965 ( open-parenthesis. ) close-parenthesis. |
| 986 " string quote. \\ escape. | 966 " string quote. \\ escape. |
| 1013 between expressions. | 993 between expressions. |
| 1014 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */) | 994 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */) |
| 1015 (c, newentry, syntax_table) | 995 (c, newentry, syntax_table) |
| 1016 Lisp_Object c, newentry, syntax_table; | 996 Lisp_Object c, newentry, syntax_table; |
| 1017 { | 997 { |
| 1018 CHECK_NUMBER (c); | 998 if (CONSP (c)) |
| 999 { | |
| 1000 CHECK_CHARACTER_CAR (c); | |
| 1001 CHECK_CHARACTER_CDR (c); | |
| 1002 } | |
| 1003 else | |
| 1004 CHECK_CHARACTER (c); | |
| 1019 | 1005 |
| 1020 if (NILP (syntax_table)) | 1006 if (NILP (syntax_table)) |
| 1021 syntax_table = current_buffer->syntax_table; | 1007 syntax_table = current_buffer->syntax_table; |
| 1022 else | 1008 else |
| 1023 check_syntax_table (syntax_table); | 1009 check_syntax_table (syntax_table); |
| 1024 | 1010 |
| 1025 SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), Fstring_to_syntax (newentry)); | 1011 newentry = Fstring_to_syntax (newentry); |
| 1012 if (CONSP (c)) | |
| 1013 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table, c, newentry); | |
| 1014 else | |
| 1015 SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), newentry); | |
| 1026 return Qnil; | 1016 return Qnil; |
| 1027 } | 1017 } |
| 1028 | 1018 |
| 1029 /* Dump syntax table to buffer in human-readable format */ | 1019 /* Dump syntax table to buffer in human-readable format */ |
| 1030 | 1020 |
| 1174 return syntax; | 1164 return syntax; |
| 1175 } | 1165 } |
| 1176 | 1166 |
| 1177 int parse_sexp_ignore_comments; | 1167 int parse_sexp_ignore_comments; |
| 1178 | 1168 |
| 1169 /* Char-table of functions that find the next or previous word | |
| 1170 boundary. */ | |
| 1171 Lisp_Object Vfind_word_boundary_function_table; | |
| 1172 | |
| 1179 /* Return the position across COUNT words from FROM. | 1173 /* Return the position across COUNT words from FROM. |
| 1180 If that many words cannot be found before the end of the buffer, return 0. | 1174 If that many words cannot be found before the end of the buffer, return 0. |
| 1181 COUNT negative means scan backward and stop at word beginning. */ | 1175 COUNT negative means scan backward and stop at word beginning. */ |
| 1182 | 1176 |
| 1183 int | 1177 int |
| 1187 register int beg = BEGV; | 1181 register int beg = BEGV; |
| 1188 register int end = ZV; | 1182 register int end = ZV; |
| 1189 register int from_byte = CHAR_TO_BYTE (from); | 1183 register int from_byte = CHAR_TO_BYTE (from); |
| 1190 register enum syntaxcode code; | 1184 register enum syntaxcode code; |
| 1191 int ch0, ch1; | 1185 int ch0, ch1; |
| 1186 Lisp_Object func, script, pos; | |
| 1192 | 1187 |
| 1193 immediate_quit = 1; | 1188 immediate_quit = 1; |
| 1194 QUIT; | 1189 QUIT; |
| 1195 | 1190 |
| 1196 SETUP_SYNTAX_TABLE (from, count); | 1191 SETUP_SYNTAX_TABLE (from, count); |
| 1203 { | 1198 { |
| 1204 immediate_quit = 0; | 1199 immediate_quit = 0; |
| 1205 return 0; | 1200 return 0; |
| 1206 } | 1201 } |
| 1207 UPDATE_SYNTAX_TABLE_FORWARD (from); | 1202 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 1208 ch0 = FETCH_CHAR (from_byte); | 1203 ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1209 code = SYNTAX (ch0); | 1204 code = SYNTAX (ch0); |
| 1210 INC_BOTH (from, from_byte); | 1205 INC_BOTH (from, from_byte); |
| 1211 if (words_include_escapes | 1206 if (words_include_escapes |
| 1212 && (code == Sescape || code == Scharquote)) | 1207 && (code == Sescape || code == Scharquote)) |
| 1213 break; | 1208 break; |
| 1214 if (code == Sword) | 1209 if (code == Sword) |
| 1215 break; | 1210 break; |
| 1216 } | 1211 } |
| 1217 /* Now CH0 is a character which begins a word and FROM is the | 1212 /* Now CH0 is a character which begins a word and FROM is the |
| 1218 position of the next character. */ | 1213 position of the next character. */ |
| 1219 while (1) | 1214 func = CHAR_TABLE_REF (Vfind_word_boundary_function_table, ch0); |
| 1220 { | 1215 if (! NILP (Ffboundp (func))) |
| 1221 if (from == end) break; | 1216 { |
| 1222 UPDATE_SYNTAX_TABLE_FORWARD (from); | 1217 pos = call2 (func, make_number (from - 1), make_number (end)); |
| 1223 ch1 = FETCH_CHAR (from_byte); | 1218 if (INTEGERP (pos) && XINT (pos) > from) |
| 1224 code = SYNTAX (ch1); | 1219 { |
| 1225 if (!(words_include_escapes | 1220 from = XINT (pos); |
| 1226 && (code == Sescape || code == Scharquote))) | 1221 from_byte = CHAR_TO_BYTE (from); |
| 1227 if (code != Sword || WORD_BOUNDARY_P (ch0, ch1)) | 1222 } |
| 1228 break; | 1223 } |
| 1229 INC_BOTH (from, from_byte); | 1224 else |
| 1230 ch0 = ch1; | 1225 { |
| 1226 script = CHAR_TABLE_REF (Vchar_script_table, ch0); | |
| 1227 while (1) | |
| 1228 { | |
| 1229 if (from == end) break; | |
| 1230 UPDATE_SYNTAX_TABLE_FORWARD (from); | |
| 1231 ch1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); | |
| 1232 code = SYNTAX (ch1); | |
| 1233 if ((code != Sword | |
| 1234 && (! words_include_escapes | |
| 1235 || (code != Sescape && code != Scharquote))) | |
| 1236 || ! EQ (CHAR_TABLE_REF (Vchar_script_table, ch1), script)) | |
| 1237 break; | |
| 1238 INC_BOTH (from, from_byte); | |
| 1239 ch0 = ch1; | |
| 1240 } | |
| 1231 } | 1241 } |
| 1232 count--; | 1242 count--; |
| 1233 } | 1243 } |
| 1234 while (count < 0) | 1244 while (count < 0) |
| 1235 { | 1245 { |
| 1240 immediate_quit = 0; | 1250 immediate_quit = 0; |
| 1241 return 0; | 1251 return 0; |
| 1242 } | 1252 } |
| 1243 DEC_BOTH (from, from_byte); | 1253 DEC_BOTH (from, from_byte); |
| 1244 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 1254 UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 1245 ch1 = FETCH_CHAR (from_byte); | 1255 ch1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1246 code = SYNTAX (ch1); | 1256 code = SYNTAX (ch1); |
| 1247 if (words_include_escapes | 1257 if (words_include_escapes |
| 1248 && (code == Sescape || code == Scharquote)) | 1258 && (code == Sescape || code == Scharquote)) |
| 1249 break; | 1259 break; |
| 1250 if (code == Sword) | 1260 if (code == Sword) |
| 1251 break; | 1261 break; |
| 1252 } | 1262 } |
| 1253 /* Now CH1 is a character which ends a word and FROM is the | 1263 /* Now CH1 is a character which ends a word and FROM is the |
| 1254 position of it. */ | 1264 position of it. */ |
| 1255 while (1) | 1265 func = CHAR_TABLE_REF (Vfind_word_boundary_function_table, ch1); |
| 1256 { | 1266 if (! NILP (Ffboundp (func))) |
| 1257 int temp_byte; | 1267 { |
| 1258 | 1268 pos = call2 (func, make_number (from), make_number (beg)); |
| 1259 if (from == beg) | 1269 if (INTEGERP (pos) && XINT (pos) < from) |
| 1260 break; | 1270 { |
| 1261 temp_byte = dec_bytepos (from_byte); | 1271 from = XINT (pos); |
| 1262 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 1272 from_byte = CHAR_TO_BYTE (from); |
| 1263 ch0 = FETCH_CHAR (temp_byte); | 1273 } |
| 1264 code = SYNTAX (ch0); | 1274 } |
| 1265 if (!(words_include_escapes | 1275 else |
| 1266 && (code == Sescape || code == Scharquote))) | 1276 { |
| 1267 if (code != Sword || WORD_BOUNDARY_P (ch0, ch1)) | 1277 script = CHAR_TABLE_REF (Vchar_script_table, ch1); |
| 1268 break; | 1278 while (1) |
| 1269 DEC_BOTH (from, from_byte); | 1279 { |
| 1270 ch1 = ch0; | 1280 int temp_byte; |
| 1281 | |
| 1282 if (from == beg) | |
| 1283 break; | |
| 1284 temp_byte = dec_bytepos (from_byte); | |
| 1285 UPDATE_SYNTAX_TABLE_BACKWARD (from); | |
| 1286 ch0 = FETCH_CHAR_AS_MULTIBYTE (temp_byte); | |
| 1287 code = SYNTAX (ch0); | |
| 1288 if ((code != Sword | |
| 1289 && (! words_include_escapes | |
| 1290 || (code != Sescape && code != Scharquote))) | |
| 1291 || ! EQ (CHAR_TABLE_REF (Vchar_script_table, ch0), script)) | |
| 1292 break; | |
| 1293 DEC_BOTH (from, from_byte); | |
| 1294 ch1 = ch0; | |
| 1295 } | |
| 1271 } | 1296 } |
| 1272 count++; | 1297 count++; |
| 1273 } | 1298 } |
| 1274 | 1299 |
| 1275 immediate_quit = 0; | 1300 immediate_quit = 0; |
| 1314 Note that char classes, e.g. `[:alpha:]', are not currently supported; | 1339 Note that char classes, e.g. `[:alpha:]', are not currently supported; |
| 1315 they will be treated as literals. */) | 1340 they will be treated as literals. */) |
| 1316 (string, lim) | 1341 (string, lim) |
| 1317 Lisp_Object string, lim; | 1342 Lisp_Object string, lim; |
| 1318 { | 1343 { |
| 1319 return skip_chars (1, 0, string, lim); | 1344 return skip_chars (1, string, lim); |
| 1320 } | 1345 } |
| 1321 | 1346 |
| 1322 DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0, | 1347 DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0, |
| 1323 doc: /* Move point backward, stopping after a char not in STRING, or at pos LIM. | 1348 doc: /* Move point backward, stopping after a char not in STRING, or at pos LIM. |
| 1324 See `skip-chars-forward' for details. | 1349 See `skip-chars-forward' for details. |
| 1325 Returns the distance traveled, either zero or negative. */) | 1350 Returns the distance traveled, either zero or negative. */) |
| 1326 (string, lim) | 1351 (string, lim) |
| 1327 Lisp_Object string, lim; | 1352 Lisp_Object string, lim; |
| 1328 { | 1353 { |
| 1329 return skip_chars (0, 0, string, lim); | 1354 return skip_chars (0, string, lim); |
| 1330 } | 1355 } |
| 1331 | 1356 |
| 1332 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0, | 1357 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0, |
| 1333 doc: /* Move point forward across chars in specified syntax classes. | 1358 doc: /* Move point forward across chars in specified syntax classes. |
| 1334 SYNTAX is a string of syntax code characters. | 1359 SYNTAX is a string of syntax code characters. |
| 1336 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. | 1361 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. |
| 1337 This function returns the distance traveled, either zero or positive. */) | 1362 This function returns the distance traveled, either zero or positive. */) |
| 1338 (syntax, lim) | 1363 (syntax, lim) |
| 1339 Lisp_Object syntax, lim; | 1364 Lisp_Object syntax, lim; |
| 1340 { | 1365 { |
| 1341 return skip_chars (1, 1, syntax, lim); | 1366 return skip_syntaxes (1, syntax, lim); |
| 1342 } | 1367 } |
| 1343 | 1368 |
| 1344 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, Sskip_syntax_backward, 1, 2, 0, | 1369 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, Sskip_syntax_backward, 1, 2, 0, |
| 1345 doc: /* Move point backward across chars in specified syntax classes. | 1370 doc: /* Move point backward across chars in specified syntax classes. |
| 1346 SYNTAX is a string of syntax code characters. | 1371 SYNTAX is a string of syntax code characters. |
| 1348 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. | 1373 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. |
| 1349 This function returns the distance traveled, either zero or negative. */) | 1374 This function returns the distance traveled, either zero or negative. */) |
| 1350 (syntax, lim) | 1375 (syntax, lim) |
| 1351 Lisp_Object syntax, lim; | 1376 Lisp_Object syntax, lim; |
| 1352 { | 1377 { |
| 1353 return skip_chars (0, 1, syntax, lim); | 1378 return skip_syntaxes (0, syntax, lim); |
| 1354 } | 1379 } |
| 1355 | 1380 |
| 1356 static Lisp_Object | 1381 static Lisp_Object |
| 1357 skip_chars (forwardp, syntaxp, string, lim) | 1382 skip_chars (forwardp, string, lim) |
| 1358 int forwardp, syntaxp; | 1383 int forwardp; |
| 1359 Lisp_Object string, lim; | 1384 Lisp_Object string, lim; |
| 1360 { | 1385 { |
| 1361 register unsigned int c; | 1386 register unsigned int c; |
| 1362 unsigned char fastmap[0400]; | 1387 unsigned char fastmap[0400]; |
| 1363 /* If SYNTAXP is 0, STRING may contain multi-byte form of characters | 1388 /* Store the ranges of non-ASCII characters. */ |
| 1364 of which codes don't fit in FASTMAP. In that case, set the | |
| 1365 ranges of characters in CHAR_RANGES. */ | |
| 1366 int *char_ranges; | 1389 int *char_ranges; |
| 1367 int n_char_ranges = 0; | 1390 int n_char_ranges = 0; |
| 1368 int negate = 0; | 1391 int negate = 0; |
| 1369 register int i, i_byte; | 1392 register int i, i_byte; |
| 1370 int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 1393 /* Set to 1 if the current buffer is multibyte and the region |
| 1394 contains non-ASCII chars. */ | |
| 1395 int multibyte; | |
| 1396 /* Set to 1 if STRING is multibyte and it contains non-ASCII | |
| 1397 chars. */ | |
| 1371 int string_multibyte; | 1398 int string_multibyte; |
| 1372 int size_byte; | 1399 int size_byte; |
| 1373 const unsigned char *str; | 1400 const unsigned char *str; |
| 1374 int len; | 1401 int len; |
| 1375 | 1402 |
| 1376 CHECK_STRING (string); | 1403 CHECK_STRING (string); |
| 1377 char_ranges = (int *) alloca (SCHARS (string) * (sizeof (int)) * 2); | |
| 1378 string_multibyte = STRING_MULTIBYTE (string); | |
| 1379 str = SDATA (string); | |
| 1380 size_byte = SBYTES (string); | |
| 1381 | |
| 1382 /* Adjust the multibyteness of the string to that of the buffer. */ | |
| 1383 if (multibyte != string_multibyte) | |
| 1384 { | |
| 1385 int nbytes; | |
| 1386 | |
| 1387 if (multibyte) | |
| 1388 nbytes = count_size_as_multibyte (SDATA (string), | |
| 1389 SCHARS (string)); | |
| 1390 else | |
| 1391 nbytes = SCHARS (string); | |
| 1392 if (nbytes != size_byte) | |
| 1393 { | |
| 1394 unsigned char *tmp = (unsigned char *) alloca (nbytes); | |
| 1395 copy_text (SDATA (string), tmp, size_byte, | |
| 1396 string_multibyte, multibyte); | |
| 1397 size_byte = nbytes; | |
| 1398 str = tmp; | |
| 1399 } | |
| 1400 } | |
| 1401 | 1404 |
| 1402 if (NILP (lim)) | 1405 if (NILP (lim)) |
| 1403 XSETINT (lim, forwardp ? ZV : BEGV); | 1406 XSETINT (lim, forwardp ? ZV : BEGV); |
| 1404 else | 1407 else |
| 1405 CHECK_NUMBER_COERCE_MARKER (lim); | 1408 CHECK_NUMBER_COERCE_MARKER (lim); |
| 1408 if (XINT (lim) > ZV) | 1411 if (XINT (lim) > ZV) |
| 1409 XSETFASTINT (lim, ZV); | 1412 XSETFASTINT (lim, ZV); |
| 1410 if (XINT (lim) < BEGV) | 1413 if (XINT (lim) < BEGV) |
| 1411 XSETFASTINT (lim, BEGV); | 1414 XSETFASTINT (lim, BEGV); |
| 1412 | 1415 |
| 1416 multibyte = (!NILP (current_buffer->enable_multibyte_characters) | |
| 1417 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); | |
| 1418 string_multibyte = SBYTES (string) > SCHARS (string); | |
| 1419 | |
| 1413 bzero (fastmap, sizeof fastmap); | 1420 bzero (fastmap, sizeof fastmap); |
| 1421 if (multibyte) | |
| 1422 char_ranges = (int *) alloca (SCHARS (string) * (sizeof (int)) * 2); | |
| 1423 | |
| 1424 str = SDATA (string); | |
| 1425 size_byte = SBYTES (string); | |
| 1414 | 1426 |
| 1415 i_byte = 0; | 1427 i_byte = 0; |
| 1416 | |
| 1417 if (i_byte < size_byte | 1428 if (i_byte < size_byte |
| 1418 && SREF (string, 0) == '^') | 1429 && SREF (string, 0) == '^') |
| 1419 { | 1430 { |
| 1420 negate = 1; i_byte++; | 1431 negate = 1; i_byte++; |
| 1421 } | 1432 } |
| 1422 | 1433 |
| 1423 /* Find the characters specified and set their elements of fastmap. | 1434 /* Find the characters specified and set their elements of fastmap. |
| 1424 If syntaxp, each character counts as itself. | 1435 Handle backslashes and ranges specially. |
| 1425 Otherwise, handle backslashes and ranges specially. */ | 1436 |
| 1426 | 1437 If STRING contains non-ASCII characters, setup char_ranges for |
| 1427 while (i_byte < size_byte) | 1438 them and use fastmap only for their leading codes. */ |
| 1428 { | 1439 |
| 1429 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len); | 1440 if (! string_multibyte) |
| 1430 i_byte += len; | 1441 { |
| 1431 | 1442 int string_has_eight_bit = 0; |
| 1432 if (syntaxp) | 1443 |
| 1433 fastmap[syntax_spec_code[c & 0377]] = 1; | 1444 /* At first setup fastmap. */ |
| 1434 else | 1445 while (i_byte < size_byte) |
| 1435 { | 1446 { |
| 1447 c = str[i_byte++]; | |
| 1448 | |
| 1436 if (c == '\\') | 1449 if (c == '\\') |
| 1437 { | 1450 { |
| 1438 if (i_byte == size_byte) | 1451 if (i_byte == size_byte) |
| 1439 break; | 1452 break; |
| 1440 | 1453 |
| 1454 c = str[i_byte++]; | |
| 1455 } | |
| 1456 if (i_byte < size_byte | |
| 1457 && str[i_byte] == '-') | |
| 1458 { | |
| 1459 unsigned int c2; | |
| 1460 | |
| 1461 /* Skip over the dash. */ | |
| 1462 i_byte++; | |
| 1463 | |
| 1464 if (i_byte == size_byte) | |
| 1465 break; | |
| 1466 | |
| 1467 /* Get the end of the range. */ | |
| 1468 c2 = str[i_byte++]; | |
| 1469 if (c2 == '\\' | |
| 1470 && i_byte < size_byte) | |
| 1471 c2 = str[i_byte++]; | |
| 1472 | |
| 1473 if (c <= c2) | |
| 1474 { | |
| 1475 while (c <= c2) | |
| 1476 fastmap[c++] = 1; | |
| 1477 if (! ASCII_CHAR_P (c2)) | |
| 1478 string_has_eight_bit = 1; | |
| 1479 } | |
| 1480 } | |
| 1481 else | |
| 1482 { | |
| 1483 fastmap[c] = 1; | |
| 1484 if (! ASCII_CHAR_P (c)) | |
| 1485 string_has_eight_bit = 1; | |
| 1486 } | |
| 1487 } | |
| 1488 | |
| 1489 /* If the current range is multibyte and STRING contains | |
| 1490 eight-bit chars, arrange fastmap and setup char_ranges for | |
| 1491 the corresponding multibyte chars. */ | |
| 1492 if (multibyte && string_has_eight_bit) | |
| 1493 { | |
| 1494 unsigned char fastmap2[0400]; | |
| 1495 int range_start_byte, range_start_char; | |
| 1496 | |
| 1497 bcopy (fastmap2 + 0200, fastmap + 0200, 0200); | |
| 1498 bzero (fastmap + 0200, 0200); | |
| 1499 /* We are sure that this loop stops. */ | |
| 1500 for (i = 0200; ! fastmap2[i]; i++); | |
| 1501 c = unibyte_char_to_multibyte (i); | |
| 1502 fastmap[CHAR_LEADING_CODE (c)] = 1; | |
| 1503 range_start_byte = i; | |
| 1504 range_start_char = c; | |
| 1505 for (i = 129; i < 0400; i++) | |
| 1506 { | |
| 1507 c = unibyte_char_to_multibyte (i); | |
| 1508 fastmap[CHAR_LEADING_CODE (c)] = 1; | |
| 1509 if (i - range_start_byte != c - range_start_char) | |
| 1510 { | |
| 1511 char_ranges[n_char_ranges++] = range_start_char; | |
| 1512 char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) | |
| 1513 + range_start_char); | |
| 1514 range_start_byte = i; | |
| 1515 range_start_char = c; | |
| 1516 } | |
| 1517 } | |
| 1518 char_ranges[n_char_ranges++] = range_start_char; | |
| 1519 char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) | |
| 1520 + range_start_char); | |
| 1521 } | |
| 1522 } | |
| 1523 else | |
| 1524 { | |
| 1525 while (i_byte < size_byte) | |
| 1526 { | |
| 1527 unsigned char leading_code; | |
| 1528 | |
| 1529 leading_code = str[i_byte]; | |
| 1530 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len); | |
| 1531 i_byte += len; | |
| 1532 | |
| 1533 if (c == '\\') | |
| 1534 { | |
| 1535 if (i_byte == size_byte) | |
| 1536 break; | |
| 1537 | |
| 1538 leading_code = str[i_byte]; | |
| 1441 c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); | 1539 c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); |
| 1442 i_byte += len; | 1540 i_byte += len; |
| 1443 } | 1541 } |
| 1444 if (i_byte < size_byte | 1542 if (i_byte < size_byte |
| 1445 && str[i_byte] == '-') | 1543 && str[i_byte] == '-') |
| 1446 { | 1544 { |
| 1447 unsigned int c2; | 1545 unsigned int c2; |
| 1546 unsigned char leading_code2; | |
| 1448 | 1547 |
| 1449 /* Skip over the dash. */ | 1548 /* Skip over the dash. */ |
| 1450 i_byte++; | 1549 i_byte++; |
| 1451 | 1550 |
| 1452 if (i_byte == size_byte) | 1551 if (i_byte == size_byte) |
| 1453 break; | 1552 break; |
| 1454 | 1553 |
| 1455 /* Get the end of the range. */ | 1554 /* Get the end of the range. */ |
| 1456 c2 =STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); | 1555 leading_code2 = str[i_byte]; |
| 1556 c2 =STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len); | |
| 1457 i_byte += len; | 1557 i_byte += len; |
| 1458 | 1558 |
| 1459 if (SINGLE_BYTE_CHAR_P (c)) | 1559 if (c2 == '\\' |
| 1560 && i_byte < size_byte) | |
| 1460 { | 1561 { |
| 1461 if (! SINGLE_BYTE_CHAR_P (c2)) | 1562 leading_code2 = str[i_byte]; |
| 1563 c2 =STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len); | |
| 1564 i_byte += len; | |
| 1565 } | |
| 1566 | |
| 1567 if (ASCII_CHAR_P (c)) | |
| 1568 { | |
| 1569 while (c <= c2 && c < 0x80) | |
| 1570 fastmap[c++] = 1; | |
| 1571 leading_code = CHAR_LEADING_CODE (c); | |
| 1572 } | |
| 1573 if (! ASCII_CHAR_P (c)) | |
| 1574 { | |
| 1575 while (leading_code <= leading_code2) | |
| 1576 fastmap[leading_code++] = 1; | |
| 1577 if (c <= c2) | |
| 1462 { | 1578 { |
| 1463 /* Handle a range starting with a character of | 1579 char_ranges[n_char_ranges++] = c; |
| 1464 less than 256, and ending with a character of | |
| 1465 not less than 256. Split that into two | |
| 1466 ranges, the low one ending at 0377, and the | |
| 1467 high one starting at the smallest character | |
| 1468 in the charset of C2 and ending at C2. */ | |
| 1469 int charset = CHAR_CHARSET (c2); | |
| 1470 int c1 = MAKE_CHAR (charset, 0, 0); | |
| 1471 | |
| 1472 char_ranges[n_char_ranges++] = c1; | |
| 1473 char_ranges[n_char_ranges++] = c2; | 1580 char_ranges[n_char_ranges++] = c2; |
| 1474 c2 = 0377; | |
| 1475 } | |
| 1476 while (c <= c2) | |
| 1477 { | |
| 1478 fastmap[c] = 1; | |
| 1479 c++; | |
| 1480 } | 1581 } |
| 1481 } | 1582 } |
| 1482 else if (c <= c2) /* Both C and C2 are multibyte char. */ | |
| 1483 { | |
| 1484 char_ranges[n_char_ranges++] = c; | |
| 1485 char_ranges[n_char_ranges++] = c2; | |
| 1486 } | |
| 1487 } | 1583 } |
| 1488 else | 1584 else |
| 1489 { | 1585 { |
| 1490 if (SINGLE_BYTE_CHAR_P (c)) | 1586 if (ASCII_CHAR_P (c)) |
| 1491 fastmap[c] = 1; | 1587 fastmap[c] = 1; |
| 1492 else | 1588 else |
| 1493 { | 1589 { |
| 1590 fastmap[leading_code] = 1; | |
| 1494 char_ranges[n_char_ranges++] = c; | 1591 char_ranges[n_char_ranges++] = c; |
| 1495 char_ranges[n_char_ranges++] = c; | 1592 char_ranges[n_char_ranges++] = c; |
| 1496 } | 1593 } |
| 1497 } | 1594 } |
| 1498 } | 1595 } |
| 1596 | |
| 1597 /* If the current range is unibyte and STRING contains non-ASCII | |
| 1598 chars, arrange fastmap for the corresponding unibyte | |
| 1599 chars. */ | |
| 1600 | |
| 1601 if (! multibyte && n_char_ranges > 0) | |
| 1602 { | |
| 1603 bzero (fastmap + 0200, 0200); | |
| 1604 for (i = 0; i < n_char_ranges; i += 2) | |
| 1605 { | |
| 1606 int c1 = char_ranges[i]; | |
| 1607 int c2 = char_ranges[i + 1]; | |
| 1608 | |
| 1609 for (; c1 <= c2; c1++) | |
| 1610 fastmap[CHAR_TO_BYTE8 (c1)] = 1; | |
| 1611 } | |
| 1612 } | |
| 1499 } | 1613 } |
| 1500 | 1614 |
| 1501 /* If ^ was the first character, complement the fastmap. */ | 1615 /* If ^ was the first character, complement the fastmap. */ |
| 1502 if (negate) | 1616 if (negate) |
| 1503 for (i = 0; i < sizeof fastmap; i++) | 1617 { |
| 1504 fastmap[i] ^= 1; | 1618 if (! multibyte) |
| 1619 for (i = 0; i < sizeof fastmap; i++) | |
| 1620 fastmap[i] ^= 1; | |
| 1621 else | |
| 1622 { | |
| 1623 for (i = 0; i < 0200; i++) | |
| 1624 fastmap[i] ^= 1; | |
| 1625 /* All non-ASCII chars possibly match. */ | |
| 1626 for (; i < sizeof fastmap; i++) | |
| 1627 fastmap[i] = 1; | |
| 1628 } | |
| 1629 } | |
| 1505 | 1630 |
| 1506 { | 1631 { |
| 1507 int start_point = PT; | 1632 int start_point = PT; |
| 1508 int pos = PT; | 1633 int pos = PT; |
| 1509 int pos_byte = PT_BYTE; | 1634 int pos_byte = PT_BYTE; |
| 1510 unsigned char *p = PT_ADDR, *endp, *stop; | 1635 unsigned char *p = PT_ADDR, *endp, *stop; |
| 1511 | 1636 |
| 1512 if (forwardp) | 1637 if (forwardp) |
| 1513 { | 1638 { |
| 1639 endp = (XINT (lim) == GPT) ? GPT_ADDR : CHAR_POS_ADDR (XINT (lim)); | |
| 1640 stop = (pos < GPT && GPT < XINT (lim)) ? GPT_ADDR : endp; | |
| 1641 } | |
| 1642 else | |
| 1643 { | |
| 1644 endp = CHAR_POS_ADDR (XINT (lim)); | |
| 1645 stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp; | |
| 1646 } | |
| 1647 | |
| 1648 immediate_quit = 1; | |
| 1649 if (forwardp) | |
| 1650 { | |
| 1651 if (multibyte) | |
| 1652 while (1) | |
| 1653 { | |
| 1654 int nbytes; | |
| 1655 | |
| 1656 if (p >= stop) | |
| 1657 { | |
| 1658 if (p >= endp) | |
| 1659 break; | |
| 1660 p = GAP_END_ADDR; | |
| 1661 stop = endp; | |
| 1662 } | |
| 1663 if (! fastmap[*p]) | |
| 1664 break; | |
| 1665 c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); | |
| 1666 if (! ASCII_CHAR_P (c)) | |
| 1667 { | |
| 1668 /* As we are looking at a multibyte character, we | |
| 1669 must look up the character in the table | |
| 1670 CHAR_RANGES. If there's no data in the table, | |
| 1671 that character is not what we want to skip. */ | |
| 1672 | |
| 1673 /* The following code do the right thing even if | |
| 1674 n_char_ranges is zero (i.e. no data in | |
| 1675 CHAR_RANGES). */ | |
| 1676 for (i = 0; i < n_char_ranges; i += 2) | |
| 1677 if (c >= char_ranges[i] && c <= char_ranges[i + 1]) | |
| 1678 break; | |
| 1679 if (!(negate ^ (i < n_char_ranges))) | |
| 1680 break; | |
| 1681 } | |
| 1682 p += nbytes, pos++, pos_byte += nbytes; | |
| 1683 } | |
| 1684 else | |
| 1685 while (1) | |
| 1686 { | |
| 1687 if (p >= stop) | |
| 1688 { | |
| 1689 if (p >= endp) | |
| 1690 break; | |
| 1691 p = GAP_END_ADDR; | |
| 1692 stop = endp; | |
| 1693 } | |
| 1694 if (!fastmap[*p]) | |
| 1695 break; | |
| 1696 p++, pos++, pos_byte++; | |
| 1697 } | |
| 1698 } | |
| 1699 else | |
| 1700 { | |
| 1701 if (multibyte) | |
| 1702 while (1) | |
| 1703 { | |
| 1704 unsigned char *prev_p; | |
| 1705 | |
| 1706 if (p <= stop) | |
| 1707 { | |
| 1708 if (p <= endp) | |
| 1709 break; | |
| 1710 p = GPT_ADDR; | |
| 1711 stop = endp; | |
| 1712 } | |
| 1713 prev_p = p; | |
| 1714 while (--p >= stop && ! CHAR_HEAD_P (*p)); | |
| 1715 if (! fastmap[*p]) | |
| 1716 break; | |
| 1717 c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); | |
| 1718 if (! ASCII_CHAR_P (c)) | |
| 1719 { | |
| 1720 /* See the comment in the previous similar code. */ | |
| 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 pos--, pos_byte -= prev_p - p; | |
| 1728 } | |
| 1729 else | |
| 1730 while (1) | |
| 1731 { | |
| 1732 if (p <= stop) | |
| 1733 { | |
| 1734 if (p <= endp) | |
| 1735 break; | |
| 1736 p = GPT_ADDR; | |
| 1737 stop = endp; | |
| 1738 } | |
| 1739 if (!fastmap[p[-1]]) | |
| 1740 break; | |
| 1741 p--, pos--, pos_byte--; | |
| 1742 } | |
| 1743 } | |
| 1744 | |
| 1745 SET_PT_BOTH (pos, pos_byte); | |
| 1746 immediate_quit = 0; | |
| 1747 | |
| 1748 return make_number (PT - start_point); | |
| 1749 } | |
| 1750 } | |
| 1751 | |
| 1752 | |
| 1753 static Lisp_Object | |
| 1754 skip_syntaxes (forwardp, string, lim) | |
| 1755 int forwardp; | |
| 1756 Lisp_Object string, lim; | |
| 1757 { | |
| 1758 register unsigned int c; | |
| 1759 unsigned char fastmap[0400]; | |
| 1760 int negate = 0; | |
| 1761 register int i, i_byte; | |
| 1762 int multibyte; | |
| 1763 int size_byte; | |
| 1764 unsigned char *str; | |
| 1765 | |
| 1766 CHECK_STRING (string); | |
| 1767 | |
| 1768 if (NILP (lim)) | |
| 1769 XSETINT (lim, forwardp ? ZV : BEGV); | |
| 1770 else | |
| 1771 CHECK_NUMBER_COERCE_MARKER (lim); | |
| 1772 | |
| 1773 /* In any case, don't allow scan outside bounds of buffer. */ | |
| 1774 if (XINT (lim) > ZV) | |
| 1775 XSETFASTINT (lim, ZV); | |
| 1776 if (XINT (lim) < BEGV) | |
| 1777 XSETFASTINT (lim, BEGV); | |
| 1778 | |
| 1779 if (forwardp ? (PT >= XFASTINT (lim)) : (PT <= XFASTINT (lim))) | |
| 1780 return Qnil; | |
| 1781 | |
| 1782 multibyte = (!NILP (current_buffer->enable_multibyte_characters) | |
| 1783 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); | |
| 1784 | |
| 1785 bzero (fastmap, sizeof fastmap); | |
| 1786 | |
| 1787 if (SBYTES (string) > SCHARS (string)) | |
| 1788 /* As this is very rare case (syntax spec is ASCII only), don't | |
| 1789 consider efficiency. */ | |
| 1790 string = string_make_unibyte (string); | |
| 1791 | |
| 1792 str = SDATA (string); | |
| 1793 size_byte = SBYTES (string); | |
| 1794 | |
| 1795 i_byte = 0; | |
| 1796 if (i_byte < size_byte | |
| 1797 && SREF (string, 0) == '^') | |
| 1798 { | |
| 1799 negate = 1; i_byte++; | |
| 1800 } | |
| 1801 | |
| 1802 /* Find the syntaxes specified and set their elements of fastmap. */ | |
| 1803 | |
| 1804 while (i_byte < size_byte) | |
| 1805 { | |
| 1806 c = str[i_byte++]; | |
| 1807 fastmap[syntax_spec_code[c]] = 1; | |
| 1808 } | |
| 1809 | |
| 1810 /* If ^ was the first character, complement the fastmap. */ | |
| 1811 if (negate) | |
| 1812 for (i = 0; i < sizeof fastmap; i++) | |
| 1813 fastmap[i] ^= 1; | |
| 1814 | |
| 1815 { | |
| 1816 int start_point = PT; | |
| 1817 int pos = PT; | |
| 1818 int pos_byte = PT_BYTE; | |
| 1819 unsigned char *p = PT_ADDR, *endp, *stop; | |
| 1820 | |
| 1821 if (forwardp) | |
| 1822 { | |
| 1514 endp = (XINT (lim) == GPT) ? GPT_ADDR : CHAR_POS_ADDR (XINT (lim)); | 1823 endp = (XINT (lim) == GPT) ? GPT_ADDR : CHAR_POS_ADDR (XINT (lim)); |
| 1515 stop = (pos < GPT && GPT < XINT (lim)) ? GPT_ADDR : endp; | 1824 stop = (pos < GPT && GPT < XINT (lim)) ? GPT_ADDR : endp; |
| 1516 } | 1825 } |
| 1517 else | 1826 else |
| 1518 { | 1827 { |
| 1519 endp = CHAR_POS_ADDR (XINT (lim)); | 1828 endp = CHAR_POS_ADDR (XINT (lim)); |
| 1520 stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp; | 1829 stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp; |
| 1521 } | 1830 } |
| 1522 | 1831 |
| 1523 immediate_quit = 1; | 1832 immediate_quit = 1; |
| 1524 if (syntaxp) | 1833 SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1); |
| 1834 if (forwardp) | |
| 1525 { | 1835 { |
| 1526 SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1); | 1836 if (multibyte) |
| 1527 if (forwardp) | |
| 1528 { | 1837 { |
| 1529 if (multibyte) | 1838 while (1) |
| 1530 while (1) | 1839 { |
| 1531 { | 1840 int nbytes; |
| 1532 int nbytes; | 1841 |
| 1533 | 1842 if (p >= stop) |
| 1534 if (p >= stop) | 1843 { |
| 1535 { | 1844 if (p >= endp) |
| 1536 if (p >= endp) | 1845 break; |
| 1537 break; | 1846 p = GAP_END_ADDR; |
| 1538 p = GAP_END_ADDR; | 1847 stop = endp; |
| 1539 stop = endp; | 1848 } |
| 1540 } | 1849 c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); |
| 1541 c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); | 1850 if (! fastmap[(int) SYNTAX (c)]) |
| 1542 if (! fastmap[(int) SYNTAX (c)]) | 1851 break; |
| 1543 break; | 1852 p += nbytes, pos++, pos_byte += nbytes; |
| 1544 p += nbytes, pos++, pos_byte += nbytes; | 1853 UPDATE_SYNTAX_TABLE_FORWARD (pos); |
| 1545 UPDATE_SYNTAX_TABLE_FORWARD (pos); | 1854 } |
| 1546 } | |
| 1547 else | |
| 1548 while (1) | |
| 1549 { | |
| 1550 if (p >= stop) | |
| 1551 { | |
| 1552 if (p >= endp) | |
| 1553 break; | |
| 1554 p = GAP_END_ADDR; | |
| 1555 stop = endp; | |
| 1556 } | |
| 1557 if (! fastmap[(int) SYNTAX (*p)]) | |
| 1558 break; | |
| 1559 p++, pos++; | |
| 1560 UPDATE_SYNTAX_TABLE_FORWARD (pos); | |
| 1561 } | |
| 1562 } | 1855 } |
| 1563 else | 1856 else |
| 1564 { | 1857 { |
| 1565 if (multibyte) | 1858 while (1) |
| 1566 while (1) | 1859 { |
| 1567 { | 1860 if (p >= stop) |
| 1568 unsigned char *prev_p; | 1861 { |
| 1569 int nbytes; | 1862 if (p >= endp) |
| 1570 | |
| 1571 if (p <= stop) | |
| 1572 { | |
| 1573 if (p <= endp) | |
| 1574 break; | |
| 1575 p = GPT_ADDR; | |
| 1576 stop = endp; | |
| 1577 } | |
| 1578 prev_p = p; | |
| 1579 while (--p >= stop && ! CHAR_HEAD_P (*p)); | |
| 1580 PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes); | |
| 1581 if (prev_p - p > nbytes) | |
| 1582 p = prev_p - 1, c = *p, nbytes = 1; | |
| 1583 else | |
| 1584 c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); | |
| 1585 pos--, pos_byte -= nbytes; | |
| 1586 UPDATE_SYNTAX_TABLE_BACKWARD (pos); | |
| 1587 if (! fastmap[(int) SYNTAX (c)]) | |
| 1588 { | |
| 1589 pos++; | |
| 1590 pos_byte += nbytes; | |
| 1591 break; | 1863 break; |
| 1592 } | 1864 p = GAP_END_ADDR; |
| 1593 } | 1865 stop = endp; |
| 1594 else | 1866 } |
| 1595 while (1) | 1867 if (! fastmap[(int) SYNTAX (*p)]) |
| 1596 { | 1868 break; |
| 1597 if (p <= stop) | 1869 p++, pos++, pos_byte++; |
| 1598 { | 1870 UPDATE_SYNTAX_TABLE_FORWARD (pos); |
| 1599 if (p <= endp) | 1871 } |
| 1600 break; | |
| 1601 p = GPT_ADDR; | |
| 1602 stop = endp; | |
| 1603 } | |
| 1604 if (! fastmap[(int) SYNTAX (p[-1])]) | |
| 1605 break; | |
| 1606 p--, pos--; | |
| 1607 UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); | |
| 1608 } | |
| 1609 } | 1872 } |
| 1610 } | 1873 } |
| 1611 else | 1874 else |
| 1612 { | 1875 { |
| 1613 if (forwardp) | 1876 if (multibyte) |
| 1614 { | 1877 { |
| 1615 if (multibyte) | 1878 while (1) |
| 1616 while (1) | 1879 { |
| 1617 { | 1880 unsigned char *prev_p; |
| 1618 int nbytes; | 1881 |
| 1619 | 1882 if (p <= stop) |
| 1620 if (p >= stop) | 1883 { |
| 1621 { | 1884 if (p <= endp) |
| 1622 if (p >= endp) | 1885 break; |
| 1623 break; | 1886 p = GPT_ADDR; |
| 1624 p = GAP_END_ADDR; | 1887 stop = endp; |
| 1625 stop = endp; | 1888 } |
| 1626 } | 1889 prev_p = p; |
| 1627 c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes); | 1890 while (--p >= stop && ! CHAR_HEAD_P (*p)); |
| 1628 if (SINGLE_BYTE_CHAR_P (c)) | 1891 c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); |
| 1629 { | 1892 if (! fastmap[(int) SYNTAX (c)]) |
| 1630 if (!fastmap[c]) | 1893 break; |
| 1631 break; | 1894 pos--, pos_byte -= prev_p - p; |
| 1632 } | 1895 UPDATE_SYNTAX_TABLE_BACKWARD (pos); |
| 1633 else | 1896 } |
| 1634 { | |
| 1635 /* If we are looking at a multibyte character, | |
| 1636 we must look up the character in the table | |
| 1637 CHAR_RANGES. If there's no data in the | |
| 1638 table, that character is not what we want to | |
| 1639 skip. */ | |
| 1640 | |
| 1641 /* The following code do the right thing even if | |
| 1642 n_char_ranges is zero (i.e. no data in | |
| 1643 CHAR_RANGES). */ | |
| 1644 for (i = 0; i < n_char_ranges; i += 2) | |
| 1645 if (c >= char_ranges[i] && c <= char_ranges[i + 1]) | |
| 1646 break; | |
| 1647 if (!(negate ^ (i < n_char_ranges))) | |
| 1648 break; | |
| 1649 } | |
| 1650 p += nbytes, pos++, pos_byte += nbytes; | |
| 1651 } | |
| 1652 else | |
| 1653 while (1) | |
| 1654 { | |
| 1655 if (p >= stop) | |
| 1656 { | |
| 1657 if (p >= endp) | |
| 1658 break; | |
| 1659 p = GAP_END_ADDR; | |
| 1660 stop = endp; | |
| 1661 } | |
| 1662 if (!fastmap[*p]) | |
| 1663 break; | |
| 1664 p++, pos++; | |
| 1665 } | |
| 1666 } | 1897 } |
| 1667 else | 1898 else |
| 1668 { | 1899 { |
| 1669 if (multibyte) | 1900 while (1) |
| 1670 while (1) | 1901 { |
| 1671 { | 1902 if (p <= stop) |
| 1672 unsigned char *prev_p; | 1903 { |
| 1673 int nbytes; | 1904 if (p <= endp) |
| 1674 | 1905 break; |
| 1675 if (p <= stop) | 1906 p = GPT_ADDR; |
| 1676 { | 1907 stop = endp; |
| 1677 if (p <= endp) | 1908 } |
| 1678 break; | 1909 if (! fastmap[(int) SYNTAX (p[-1])]) |
| 1679 p = GPT_ADDR; | 1910 break; |
| 1680 stop = endp; | 1911 p--, pos--, pos_byte--; |
| 1681 } | 1912 UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); |
| 1682 prev_p = p; | 1913 } |
| 1683 while (--p >= stop && ! CHAR_HEAD_P (*p)); | |
| 1684 PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes); | |
| 1685 if (prev_p - p > nbytes) | |
| 1686 p = prev_p - 1, c = *p, nbytes = 1; | |
| 1687 else | |
| 1688 c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH); | |
| 1689 if (SINGLE_BYTE_CHAR_P (c)) | |
| 1690 { | |
| 1691 if (!fastmap[c]) | |
| 1692 break; | |
| 1693 } | |
| 1694 else | |
| 1695 { | |
| 1696 /* See the comment in the previous similar code. */ | |
| 1697 for (i = 0; i < n_char_ranges; i += 2) | |
| 1698 if (c >= char_ranges[i] && c <= char_ranges[i + 1]) | |
| 1699 break; | |
| 1700 if (!(negate ^ (i < n_char_ranges))) | |
| 1701 break; | |
| 1702 } | |
| 1703 pos--, pos_byte -= nbytes; | |
| 1704 } | |
| 1705 else | |
| 1706 while (1) | |
| 1707 { | |
| 1708 if (p <= stop) | |
| 1709 { | |
| 1710 if (p <= endp) | |
| 1711 break; | |
| 1712 p = GPT_ADDR; | |
| 1713 stop = endp; | |
| 1714 } | |
| 1715 if (!fastmap[p[-1]]) | |
| 1716 break; | |
| 1717 p--, pos--; | |
| 1718 } | |
| 1719 } | 1914 } |
| 1720 } | 1915 } |
| 1721 | |
| 1722 #if 0 /* Not needed now that a position in mid-character | |
| 1723 cannot be specified in Lisp. */ | |
| 1724 if (multibyte | |
| 1725 /* INC_POS or DEC_POS might have moved POS over LIM. */ | |
| 1726 && (forwardp ? (pos > XINT (lim)) : (pos < XINT (lim)))) | |
| 1727 pos = XINT (lim); | |
| 1728 #endif | |
| 1729 | |
| 1730 if (! multibyte) | |
| 1731 pos_byte = pos; | |
| 1732 | 1916 |
| 1733 SET_PT_BOTH (pos, pos_byte); | 1917 SET_PT_BOTH (pos, pos_byte); |
| 1734 immediate_quit = 0; | 1918 immediate_quit = 0; |
| 1735 | 1919 |
| 1736 return make_number (PT - start_point); | 1920 return make_number (PT - start_point); |
| 1786 *incomment_ptr = nesting; | 1970 *incomment_ptr = nesting; |
| 1787 *charpos_ptr = from; | 1971 *charpos_ptr = from; |
| 1788 *bytepos_ptr = from_byte; | 1972 *bytepos_ptr = from_byte; |
| 1789 return 0; | 1973 return 0; |
| 1790 } | 1974 } |
| 1791 c = FETCH_CHAR (from_byte); | 1975 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1792 syntax = SYNTAX_WITH_FLAGS (c); | 1976 syntax = SYNTAX_WITH_FLAGS (c); |
| 1793 code = syntax & 0xff; | 1977 code = syntax & 0xff; |
| 1794 if (code == Sendcomment | 1978 if (code == Sendcomment |
| 1795 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style | 1979 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style |
| 1796 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? | 1980 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? |
| 1816 UPDATE_SYNTAX_TABLE_FORWARD (from); | 2000 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 1817 | 2001 |
| 1818 forw_incomment: | 2002 forw_incomment: |
| 1819 if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax) | 2003 if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax) |
| 1820 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style | 2004 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style |
| 1821 && (c1 = FETCH_CHAR (from_byte), | 2005 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 1822 SYNTAX_COMEND_SECOND (c1)) | 2006 SYNTAX_COMEND_SECOND (c1)) |
| 1823 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) || | 2007 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) || |
| 1824 SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0)) | 2008 SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0)) |
| 1825 { | 2009 { |
| 1826 if (--nesting <= 0) | 2010 if (--nesting <= 0) |
| 1835 } | 2019 } |
| 1836 } | 2020 } |
| 1837 if (nesting > 0 | 2021 if (nesting > 0 |
| 1838 && from < stop | 2022 && from < stop |
| 1839 && SYNTAX_FLAGS_COMSTART_FIRST (syntax) | 2023 && SYNTAX_FLAGS_COMSTART_FIRST (syntax) |
| 1840 && (c1 = FETCH_CHAR (from_byte), | 2024 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 1841 SYNTAX_COMMENT_STYLE (c1) == style | 2025 SYNTAX_COMMENT_STYLE (c1) == style |
| 1842 && SYNTAX_COMSTART_SECOND (c1)) | 2026 && SYNTAX_COMSTART_SECOND (c1)) |
| 1843 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) || | 2027 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) || |
| 1844 SYNTAX_COMMENT_NESTED (c1))) | 2028 SYNTAX_COMMENT_NESTED (c1))) |
| 1845 /* we have encountered a nested comment of the same style | 2029 /* we have encountered a nested comment of the same style |
| 1899 { | 2083 { |
| 1900 SET_PT_BOTH (from, from_byte); | 2084 SET_PT_BOTH (from, from_byte); |
| 1901 immediate_quit = 0; | 2085 immediate_quit = 0; |
| 1902 return Qnil; | 2086 return Qnil; |
| 1903 } | 2087 } |
| 1904 c = FETCH_CHAR (from_byte); | 2088 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1905 code = SYNTAX (c); | 2089 code = SYNTAX (c); |
| 1906 comstart_first = SYNTAX_COMSTART_FIRST (c); | 2090 comstart_first = SYNTAX_COMSTART_FIRST (c); |
| 1907 comnested = SYNTAX_COMMENT_NESTED (c); | 2091 comnested = SYNTAX_COMMENT_NESTED (c); |
| 1908 comstyle = SYNTAX_COMMENT_STYLE (c); | 2092 comstyle = SYNTAX_COMMENT_STYLE (c); |
| 1909 INC_BOTH (from, from_byte); | 2093 INC_BOTH (from, from_byte); |
| 1910 UPDATE_SYNTAX_TABLE_FORWARD (from); | 2094 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 1911 if (from < stop && comstart_first | 2095 if (from < stop && comstart_first |
| 1912 && (c1 = FETCH_CHAR (from_byte), | 2096 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 1913 SYNTAX_COMSTART_SECOND (c1))) | 2097 SYNTAX_COMSTART_SECOND (c1))) |
| 1914 { | 2098 { |
| 1915 /* We have encountered a comment start sequence and we | 2099 /* We have encountered a comment start sequence and we |
| 1916 are ignoring all text inside comments. We must record | 2100 are ignoring all text inside comments. We must record |
| 1917 the comment style this sequence begins so that later, | 2101 the comment style this sequence begins so that later, |
| 1965 } | 2149 } |
| 1966 | 2150 |
| 1967 DEC_BOTH (from, from_byte); | 2151 DEC_BOTH (from, from_byte); |
| 1968 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */ | 2152 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */ |
| 1969 quoted = char_quoted (from, from_byte); | 2153 quoted = char_quoted (from, from_byte); |
| 1970 c = FETCH_CHAR (from_byte); | 2154 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1971 code = SYNTAX (c); | 2155 code = SYNTAX (c); |
| 1972 comstyle = 0; | 2156 comstyle = 0; |
| 1973 comnested = SYNTAX_COMMENT_NESTED (c); | 2157 comnested = SYNTAX_COMMENT_NESTED (c); |
| 1974 if (code == Sendcomment) | 2158 if (code == Sendcomment) |
| 1975 comstyle = SYNTAX_COMMENT_STYLE (c); | 2159 comstyle = SYNTAX_COMMENT_STYLE (c); |
| 1982 sequence of the same style. */ | 2166 sequence of the same style. */ |
| 1983 DEC_BOTH (from, from_byte); | 2167 DEC_BOTH (from, from_byte); |
| 1984 code = Sendcomment; | 2168 code = Sendcomment; |
| 1985 /* Calling char_quoted, above, set up global syntax position | 2169 /* Calling char_quoted, above, set up global syntax position |
| 1986 at the new value of FROM. */ | 2170 at the new value of FROM. */ |
| 1987 c1 = FETCH_CHAR (from_byte); | 2171 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 1988 comstyle = SYNTAX_COMMENT_STYLE (c1); | 2172 comstyle = SYNTAX_COMMENT_STYLE (c1); |
| 1989 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 2173 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
| 1990 } | 2174 } |
| 1991 | 2175 |
| 1992 if (code == Scomment_fence) | 2176 if (code == Scomment_fence) |
| 1998 { | 2182 { |
| 1999 DEC_BOTH (from, from_byte); | 2183 DEC_BOTH (from, from_byte); |
| 2000 if (from == stop) | 2184 if (from == stop) |
| 2001 break; | 2185 break; |
| 2002 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2186 UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2003 c = FETCH_CHAR (from_byte); | 2187 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2004 if (SYNTAX (c) == Scomment_fence | 2188 if (SYNTAX (c) == Scomment_fence |
| 2005 && !char_quoted (from, from_byte)) | 2189 && !char_quoted (from, from_byte)) |
| 2006 { | 2190 { |
| 2007 found = 1; | 2191 found = 1; |
| 2008 break; | 2192 break; |
| 2059 SET_PT_BOTH (from, from_byte); | 2243 SET_PT_BOTH (from, from_byte); |
| 2060 immediate_quit = 0; | 2244 immediate_quit = 0; |
| 2061 return Qt; | 2245 return Qt; |
| 2062 } | 2246 } |
| 2063 | 2247 |
| 2064 /* Return syntax code of character C if C is a single byte character | 2248 /* Return syntax code of character C if C is an ASCII character |
| 2065 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */ | 2249 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */ |
| 2066 | 2250 |
| 2067 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \ | 2251 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \ |
| 2068 ((SINGLE_BYTE_CHAR_P (c) || !multibyte_symbol_p) \ | 2252 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \ |
| 2069 ? SYNTAX (c) : Ssymbol) | 2253 ? SYNTAX (c) : Ssymbol) |
| 2070 | 2254 |
| 2071 static Lisp_Object | 2255 static Lisp_Object |
| 2072 scan_lists (from, count, depth, sexpflag) | 2256 scan_lists (from, count, depth, sexpflag) |
| 2073 register int from; | 2257 register int from; |
| 2106 { | 2290 { |
| 2107 while (from < stop) | 2291 while (from < stop) |
| 2108 { | 2292 { |
| 2109 int comstart_first, prefix; | 2293 int comstart_first, prefix; |
| 2110 UPDATE_SYNTAX_TABLE_FORWARD (from); | 2294 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2111 c = FETCH_CHAR (from_byte); | 2295 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2112 code = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2296 code = SYNTAX_WITH_MULTIBYTE_CHECK (c); |
| 2113 comstart_first = SYNTAX_COMSTART_FIRST (c); | 2297 comstart_first = SYNTAX_COMSTART_FIRST (c); |
| 2114 comnested = SYNTAX_COMMENT_NESTED (c); | 2298 comnested = SYNTAX_COMMENT_NESTED (c); |
| 2115 comstyle = SYNTAX_COMMENT_STYLE (c); | 2299 comstyle = SYNTAX_COMMENT_STYLE (c); |
| 2116 prefix = SYNTAX_PREFIX (c); | 2300 prefix = SYNTAX_PREFIX (c); |
| 2117 if (depth == min_depth) | 2301 if (depth == min_depth) |
| 2118 last_good = from; | 2302 last_good = from; |
| 2119 INC_BOTH (from, from_byte); | 2303 INC_BOTH (from, from_byte); |
| 2120 UPDATE_SYNTAX_TABLE_FORWARD (from); | 2304 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2121 if (from < stop && comstart_first | 2305 if (from < stop && comstart_first |
| 2122 && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from_byte)) | 2306 && SYNTAX_COMSTART_SECOND (FETCH_CHAR_AS_MULTIBYTE (from_byte)) |
| 2123 && parse_sexp_ignore_comments) | 2307 && parse_sexp_ignore_comments) |
| 2124 { | 2308 { |
| 2125 /* we have encountered a comment start sequence and we | 2309 /* we have encountered a comment start sequence and we |
| 2126 are ignoring all text inside comments. We must record | 2310 are ignoring all text inside comments. We must record |
| 2127 the comment style this sequence begins so that later, | 2311 the comment style this sequence begins so that later, |
| 2128 only a comment end of the same style actually ends | 2312 only a comment end of the same style actually ends |
| 2129 the comment section */ | 2313 the comment section */ |
| 2130 code = Scomment; | 2314 code = Scomment; |
| 2131 c1 = FETCH_CHAR (from_byte); | 2315 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2132 comstyle = SYNTAX_COMMENT_STYLE (c1); | 2316 comstyle = SYNTAX_COMMENT_STYLE (c1); |
| 2133 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 2317 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
| 2134 INC_BOTH (from, from_byte); | 2318 INC_BOTH (from, from_byte); |
| 2135 UPDATE_SYNTAX_TABLE_FORWARD (from); | 2319 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2136 } | 2320 } |
| 2152 while (from < stop) | 2336 while (from < stop) |
| 2153 { | 2337 { |
| 2154 UPDATE_SYNTAX_TABLE_FORWARD (from); | 2338 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2155 | 2339 |
| 2156 /* Some compilers can't handle this inside the switch. */ | 2340 /* Some compilers can't handle this inside the switch. */ |
| 2157 c = FETCH_CHAR (from_byte); | 2341 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2158 temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2342 temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); |
| 2159 switch (temp) | 2343 switch (temp) |
| 2160 { | 2344 { |
| 2161 case Scharquote: | 2345 case Scharquote: |
| 2162 case Sescape: | 2346 case Sescape: |
| 2195 break; | 2379 break; |
| 2196 | 2380 |
| 2197 case Smath: | 2381 case Smath: |
| 2198 if (!sexpflag) | 2382 if (!sexpflag) |
| 2199 break; | 2383 break; |
| 2200 if (from != stop && c == FETCH_CHAR (from_byte)) | 2384 if (from != stop && c == FETCH_CHAR_AS_MULTIBYTE (from_byte)) |
| 2201 { | 2385 { |
| 2202 INC_BOTH (from, from_byte); | 2386 INC_BOTH (from, from_byte); |
| 2203 } | 2387 } |
| 2204 if (mathexit) | 2388 if (mathexit) |
| 2205 { | 2389 { |
| 2223 break; | 2407 break; |
| 2224 | 2408 |
| 2225 case Sstring: | 2409 case Sstring: |
| 2226 case Sstring_fence: | 2410 case Sstring_fence: |
| 2227 temp_pos = dec_bytepos (from_byte); | 2411 temp_pos = dec_bytepos (from_byte); |
| 2228 stringterm = FETCH_CHAR (temp_pos); | 2412 stringterm = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2229 while (1) | 2413 while (1) |
| 2230 { | 2414 { |
| 2231 if (from >= stop) goto lose; | 2415 if (from >= stop) goto lose; |
| 2232 UPDATE_SYNTAX_TABLE_FORWARD (from); | 2416 UPDATE_SYNTAX_TABLE_FORWARD (from); |
| 2233 c = FETCH_CHAR (from_byte); | 2417 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2234 if (code == Sstring | 2418 if (code == Sstring |
| 2235 ? (c == stringterm | 2419 ? (c == stringterm |
| 2236 && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) | 2420 && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) |
| 2237 : SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring_fence) | 2421 : SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring_fence) |
| 2238 break; | 2422 break; |
| 2271 { | 2455 { |
| 2272 while (from > stop) | 2456 while (from > stop) |
| 2273 { | 2457 { |
| 2274 DEC_BOTH (from, from_byte); | 2458 DEC_BOTH (from, from_byte); |
| 2275 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2459 UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2276 c = FETCH_CHAR (from_byte); | 2460 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2277 code = SYNTAX_WITH_MULTIBYTE_CHECK (c); | 2461 code = SYNTAX_WITH_MULTIBYTE_CHECK (c); |
| 2278 if (depth == min_depth) | 2462 if (depth == min_depth) |
| 2279 last_good = from; | 2463 last_good = from; |
| 2280 comstyle = 0; | 2464 comstyle = 0; |
| 2281 comnested = SYNTAX_COMMENT_NESTED (c); | 2465 comnested = SYNTAX_COMMENT_NESTED (c); |
| 2289 later, we can match only the proper comment begin | 2473 later, we can match only the proper comment begin |
| 2290 sequence of the same style. */ | 2474 sequence of the same style. */ |
| 2291 DEC_BOTH (from, from_byte); | 2475 DEC_BOTH (from, from_byte); |
| 2292 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2476 UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2293 code = Sendcomment; | 2477 code = Sendcomment; |
| 2294 c1 = FETCH_CHAR (from_byte); | 2478 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2295 comstyle = SYNTAX_COMMENT_STYLE (c1); | 2479 comstyle = SYNTAX_COMMENT_STYLE (c1); |
| 2296 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 2480 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
| 2297 } | 2481 } |
| 2298 | 2482 |
| 2299 /* Quoting turns anything except a comment-ender | 2483 /* Quoting turns anything except a comment-ender |
| 2322 if (! NILP (current_buffer->enable_multibyte_characters)) | 2506 if (! NILP (current_buffer->enable_multibyte_characters)) |
| 2323 DEC_POS (temp_pos); | 2507 DEC_POS (temp_pos); |
| 2324 else | 2508 else |
| 2325 temp_pos--; | 2509 temp_pos--; |
| 2326 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2510 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2327 c1 = FETCH_CHAR (temp_pos); | 2511 c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2328 temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); | 2512 temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); |
| 2329 /* Don't allow comment-end to be quoted. */ | 2513 /* Don't allow comment-end to be quoted. */ |
| 2330 if (temp_code == Sendcomment) | 2514 if (temp_code == Sendcomment) |
| 2331 goto done2; | 2515 goto done2; |
| 2332 quoted = char_quoted (from - 1, temp_pos); | 2516 quoted = char_quoted (from - 1, temp_pos); |
| 2334 { | 2518 { |
| 2335 DEC_BOTH (from, from_byte); | 2519 DEC_BOTH (from, from_byte); |
| 2336 temp_pos = dec_bytepos (temp_pos); | 2520 temp_pos = dec_bytepos (temp_pos); |
| 2337 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2521 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2338 } | 2522 } |
| 2339 c1 = FETCH_CHAR (temp_pos); | 2523 c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos); |
| 2340 temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); | 2524 temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1); |
| 2341 if (! (quoted || temp_code == Sword | 2525 if (! (quoted || temp_code == Sword |
| 2342 || temp_code == Ssymbol | 2526 || temp_code == Ssymbol |
| 2343 || temp_code == Squote)) | 2527 || temp_code == Squote)) |
| 2344 goto done2; | 2528 goto done2; |
| 2349 case Smath: | 2533 case Smath: |
| 2350 if (!sexpflag) | 2534 if (!sexpflag) |
| 2351 break; | 2535 break; |
| 2352 temp_pos = dec_bytepos (from_byte); | 2536 temp_pos = dec_bytepos (from_byte); |
| 2353 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2537 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2354 if (from != stop && c == FETCH_CHAR (temp_pos)) | 2538 if (from != stop && c == FETCH_CHAR_AS_MULTIBYTE (temp_pos)) |
| 2355 DEC_BOTH (from, from_byte); | 2539 DEC_BOTH (from, from_byte); |
| 2356 if (mathexit) | 2540 if (mathexit) |
| 2357 { | 2541 { |
| 2358 mathexit = 0; | 2542 mathexit = 0; |
| 2359 goto open2; | 2543 goto open2; |
| 2395 { | 2579 { |
| 2396 DEC_BOTH (from, from_byte); | 2580 DEC_BOTH (from, from_byte); |
| 2397 if (from == stop) goto lose; | 2581 if (from == stop) goto lose; |
| 2398 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 2582 UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2399 if (!char_quoted (from, from_byte) | 2583 if (!char_quoted (from, from_byte) |
| 2400 && (c = FETCH_CHAR (from_byte), | 2584 && (c = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 2401 SYNTAX_WITH_MULTIBYTE_CHECK (c) == code)) | 2585 SYNTAX_WITH_MULTIBYTE_CHECK (c) == code)) |
| 2402 break; | 2586 break; |
| 2403 } | 2587 } |
| 2404 if (code == Sstring_fence && !depth && sexpflag) goto done2; | 2588 if (code == Sstring_fence && !depth && sexpflag) goto done2; |
| 2405 break; | 2589 break; |
| 2406 | 2590 |
| 2407 case Sstring: | 2591 case Sstring: |
| 2408 stringterm = FETCH_CHAR (from_byte); | 2592 stringterm = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2409 while (1) | 2593 while (1) |
| 2410 { | 2594 { |
| 2411 if (from == stop) goto lose; | 2595 if (from == stop) goto lose; |
| 2412 temp_pos = from_byte; | 2596 temp_pos = from_byte; |
| 2413 if (! NILP (current_buffer->enable_multibyte_characters)) | 2597 if (! NILP (current_buffer->enable_multibyte_characters)) |
| 2414 DEC_POS (temp_pos); | 2598 DEC_POS (temp_pos); |
| 2415 else | 2599 else |
| 2416 temp_pos--; | 2600 temp_pos--; |
| 2417 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); | 2601 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1); |
| 2418 if (!char_quoted (from - 1, temp_pos) | 2602 if (!char_quoted (from - 1, temp_pos) |
| 2419 && stringterm == (c = FETCH_CHAR (temp_pos)) | 2603 && stringterm == (c = FETCH_CHAR_AS_MULTIBYTE (temp_pos)) |
| 2420 && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) | 2604 && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring) |
| 2421 break; | 2605 break; |
| 2422 DEC_BOTH (from, from_byte); | 2606 DEC_BOTH (from, from_byte); |
| 2423 } | 2607 } |
| 2424 DEC_BOTH (from, from_byte); | 2608 DEC_BOTH (from, from_byte); |
| 2522 | 2706 |
| 2523 DEC_BOTH (pos, pos_byte); | 2707 DEC_BOTH (pos, pos_byte); |
| 2524 | 2708 |
| 2525 while (!char_quoted (pos, pos_byte) | 2709 while (!char_quoted (pos, pos_byte) |
| 2526 /* Previous statement updates syntax table. */ | 2710 /* Previous statement updates syntax table. */ |
| 2527 && ((c = FETCH_CHAR (pos_byte), SYNTAX (c) == Squote) | 2711 && ((c = FETCH_CHAR_AS_MULTIBYTE (pos_byte), SYNTAX (c) == Squote) |
| 2528 || SYNTAX_PREFIX (c))) | 2712 || SYNTAX_PREFIX (c))) |
| 2529 { | 2713 { |
| 2530 opoint = pos; | 2714 opoint = pos; |
| 2531 opoint_byte = pos_byte; | 2715 opoint_byte = pos_byte; |
| 2532 | 2716 |
| 2550 static void | 2734 static void |
| 2551 scan_sexps_forward (stateptr, from, from_byte, end, targetdepth, | 2735 scan_sexps_forward (stateptr, from, from_byte, end, targetdepth, |
| 2552 stopbefore, oldstate, commentstop) | 2736 stopbefore, oldstate, commentstop) |
| 2553 struct lisp_parse_state *stateptr; | 2737 struct lisp_parse_state *stateptr; |
| 2554 register int from; | 2738 register int from; |
| 2555 int end, targetdepth, stopbefore, from_byte; | 2739 int from_byte; |
| 2740 int end, targetdepth, stopbefore; | |
| 2556 Lisp_Object oldstate; | 2741 Lisp_Object oldstate; |
| 2557 int commentstop; | 2742 int commentstop; |
| 2558 { | 2743 { |
| 2559 struct lisp_parse_state state; | 2744 struct lisp_parse_state state; |
| 2560 | 2745 |
| 2588 /* Use this macro instead of `from++'. */ | 2773 /* Use this macro instead of `from++'. */ |
| 2589 #define INC_FROM \ | 2774 #define INC_FROM \ |
| 2590 do { prev_from = from; \ | 2775 do { prev_from = from; \ |
| 2591 prev_from_byte = from_byte; \ | 2776 prev_from_byte = from_byte; \ |
| 2592 prev_from_syntax \ | 2777 prev_from_syntax \ |
| 2593 = SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte)); \ | 2778 = SYNTAX_WITH_FLAGS (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte)); \ |
| 2594 INC_BOTH (from, from_byte); \ | 2779 INC_BOTH (from, from_byte); \ |
| 2595 if (from < end) \ | 2780 if (from < end) \ |
| 2596 UPDATE_SYNTAX_TABLE_FORWARD (from); \ | 2781 UPDATE_SYNTAX_TABLE_FORWARD (from); \ |
| 2597 } while (0) | 2782 } while (0) |
| 2598 | 2783 |
| 2704 state.comstr_start = prev_from; | 2889 state.comstr_start = prev_from; |
| 2705 code = Scomment; | 2890 code = Scomment; |
| 2706 } | 2891 } |
| 2707 else if (from < end) | 2892 else if (from < end) |
| 2708 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax)) | 2893 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax)) |
| 2709 if (c1 = FETCH_CHAR (from_byte), | 2894 if (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte), |
| 2710 SYNTAX_COMSTART_SECOND (c1)) | 2895 SYNTAX_COMSTART_SECOND (c1)) |
| 2711 /* Duplicate code to avoid a complex if-expression | 2896 /* Duplicate code to avoid a complex if-expression |
| 2712 which causes trouble for the SGI compiler. */ | 2897 which causes trouble for the SGI compiler. */ |
| 2713 { | 2898 { |
| 2714 /* Record the comment style we have entered so that only | 2899 /* Record the comment style we have entered so that only |
| 2742 curlevel->last = prev_from; | 2927 curlevel->last = prev_from; |
| 2743 symstarted: | 2928 symstarted: |
| 2744 while (from < end) | 2929 while (from < end) |
| 2745 { | 2930 { |
| 2746 /* Some compilers can't handle this inside the switch. */ | 2931 /* Some compilers can't handle this inside the switch. */ |
| 2747 temp = SYNTAX (FETCH_CHAR (from_byte)); | 2932 temp = SYNTAX (FETCH_CHAR_AS_MULTIBYTE (from_byte)); |
| 2748 switch (temp) | 2933 switch (temp) |
| 2749 { | 2934 { |
| 2750 case Scharquote: | 2935 case Scharquote: |
| 2751 case Sescape: | 2936 case Sescape: |
| 2752 INC_FROM; | 2937 INC_FROM; |
| 2815 case Sstring_fence: | 3000 case Sstring_fence: |
| 2816 state.comstr_start = from - 1; | 3001 state.comstr_start = from - 1; |
| 2817 if (stopbefore) goto stop; /* this arg means stop at sexp start */ | 3002 if (stopbefore) goto stop; /* this arg means stop at sexp start */ |
| 2818 curlevel->last = prev_from; | 3003 curlevel->last = prev_from; |
| 2819 state.instring = (code == Sstring | 3004 state.instring = (code == Sstring |
| 2820 ? (FETCH_CHAR (prev_from_byte)) | 3005 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte)) |
| 2821 : ST_STRING_STYLE); | 3006 : ST_STRING_STYLE); |
| 2822 if (boundary_stop) goto done; | 3007 if (boundary_stop) goto done; |
| 2823 startinstring: | 3008 startinstring: |
| 2824 { | 3009 { |
| 2825 nofence = state.instring != ST_STRING_STYLE; | 3010 nofence = state.instring != ST_STRING_STYLE; |
| 2827 while (1) | 3012 while (1) |
| 2828 { | 3013 { |
| 2829 int c; | 3014 int c; |
| 2830 | 3015 |
| 2831 if (from >= end) goto done; | 3016 if (from >= end) goto done; |
| 2832 c = FETCH_CHAR (from_byte); | 3017 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); |
| 2833 /* Some compilers can't handle this inside the switch. */ | 3018 /* Some compilers can't handle this inside the switch. */ |
| 2834 temp = SYNTAX (c); | 3019 temp = SYNTAX (c); |
| 2835 | 3020 |
| 2836 /* Check TEMP here so that if the char has | 3021 /* Check TEMP here so that if the char has |
| 2837 a syntax-table property which says it is NOT | 3022 a syntax-table property which says it is NOT |
| 3039 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp); | 3224 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp); |
| 3040 } | 3225 } |
| 3041 | 3226 |
| 3042 /* All multibyte characters have syntax `word' by default. */ | 3227 /* All multibyte characters have syntax `word' by default. */ |
| 3043 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; | 3228 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; |
| 3044 for (i = CHAR_TABLE_SINGLE_BYTE_SLOTS; i < CHAR_TABLE_ORDINARY_SLOTS; i++) | 3229 char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp); |
| 3045 XCHAR_TABLE (Vstandard_syntax_table)->contents[i] = temp; | |
| 3046 } | 3230 } |
| 3047 | 3231 |
| 3048 void | 3232 void |
| 3049 syms_of_syntax () | 3233 syms_of_syntax () |
| 3050 { | 3234 { |
| 3079 | 3263 |
| 3080 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start", | 3264 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start", |
| 3081 &open_paren_in_column_0_is_defun_start, | 3265 &open_paren_in_column_0_is_defun_start, |
| 3082 doc: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */); | 3266 doc: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */); |
| 3083 open_paren_in_column_0_is_defun_start = 1; | 3267 open_paren_in_column_0_is_defun_start = 1; |
| 3268 | |
| 3269 | |
| 3270 DEFVAR_LISP ("find-word-boundary-function-table", | |
| 3271 &Vfind_word_boundary_function_table, | |
| 3272 doc: /* | |
| 3273 Char table of functions to search for the word boundary. | |
| 3274 Each function is called with two arguments; POS and LIMIT. | |
| 3275 POS and LIMIT are character positions in the current buffer. | |
| 3276 | |
| 3277 If POS is less than LIMIT, POS is at the first character of a word, | |
| 3278 and the return value of a function is a position after the last | |
| 3279 character of that word. | |
| 3280 | |
| 3281 If POS is not less than LIMIT, POS is at the last character of a word, | |
| 3282 and the return value of a function is a position at the first | |
| 3283 character of that word. | |
| 3284 | |
| 3285 In both cases, LIMIT bounds the search. */); | |
| 3286 Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil); | |
| 3084 | 3287 |
| 3085 defsubr (&Ssyntax_table_p); | 3288 defsubr (&Ssyntax_table_p); |
| 3086 defsubr (&Ssyntax_table); | 3289 defsubr (&Ssyntax_table); |
| 3087 defsubr (&Sstandard_syntax_table); | 3290 defsubr (&Sstandard_syntax_table); |
| 3088 defsubr (&Scopy_syntax_table); | 3291 defsubr (&Scopy_syntax_table); |
