Mercurial > hg > xemacs-beta
comparison src/syntax.c @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | abe6d1db359e |
children | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
154 | 154 |
155 return find_start_value; | 155 return find_start_value; |
156 } | 156 } |
157 | 157 |
158 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /* | 158 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /* |
159 Return t if ARG is a syntax table. | 159 Return t if OBJECT is a syntax table. |
160 Any vector of 256 elements will do. | 160 Any vector of 256 elements will do. |
161 */ | 161 */ |
162 (obj)) | 162 (object)) |
163 { | 163 { |
164 return CHAR_TABLEP (obj) && XCHAR_TABLE_TYPE (obj) == CHAR_TABLE_TYPE_SYNTAX | 164 return (CHAR_TABLEP (object) |
165 && XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_SYNTAX) | |
165 ? Qt : Qnil; | 166 ? Qt : Qnil; |
166 } | 167 } |
167 | 168 |
168 static Lisp_Object | 169 static Lisp_Object |
169 check_syntax_table (Lisp_Object obj, Lisp_Object default_) | 170 check_syntax_table (Lisp_Object obj, Lisp_Object default_) |
193 { | 194 { |
194 return Vstandard_syntax_table; | 195 return Vstandard_syntax_table; |
195 } | 196 } |
196 | 197 |
197 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /* | 198 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /* |
198 Construct a new syntax table and return it. | 199 Return a new syntax table which is a copy of SYNTAX-TABLE. |
199 It is a copy of the TABLE, which defaults to the standard syntax table. | 200 SYNTAX-TABLE defaults to the standard syntax table. |
200 */ | 201 */ |
201 (table)) | 202 (syntax_table)) |
202 { | 203 { |
203 if (NILP (Vstandard_syntax_table)) | 204 if (NILP (Vstandard_syntax_table)) |
204 return Fmake_char_table (Qsyntax); | 205 return Fmake_char_table (Qsyntax); |
205 | 206 |
206 table = check_syntax_table (table, Vstandard_syntax_table); | 207 syntax_table = check_syntax_table (syntax_table, Vstandard_syntax_table); |
207 return Fcopy_char_table (table); | 208 return Fcopy_char_table (syntax_table); |
208 } | 209 } |
209 | 210 |
210 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /* | 211 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /* |
211 Select a new syntax table for BUFFER. | 212 Select SYNTAX-TABLE as the new syntax table for BUFFER. |
212 One argument, a syntax table. | |
213 BUFFER defaults to the current buffer if omitted. | 213 BUFFER defaults to the current buffer if omitted. |
214 */ | 214 */ |
215 (table, buffer)) | 215 (syntax_table, buffer)) |
216 { | 216 { |
217 struct buffer *buf = decode_buffer (buffer, 0); | 217 struct buffer *buf = decode_buffer (buffer, 0); |
218 table = check_syntax_table (table, Qnil); | 218 syntax_table = check_syntax_table (syntax_table, Qnil); |
219 buf->syntax_table = table; | 219 buf->syntax_table = syntax_table; |
220 buf->mirror_syntax_table = XCHAR_TABLE (table)->mirror_table; | 220 buf->mirror_syntax_table = XCHAR_TABLE (syntax_table)->mirror_table; |
221 /* Indicate that this buffer now has a specified syntax table. */ | 221 /* Indicate that this buffer now has a specified syntax table. */ |
222 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table); | 222 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table); |
223 return table; | 223 return syntax_table; |
224 } | 224 } |
225 | 225 |
226 /* Convert a letter which signifies a syntax code | 226 /* Convert a letter which signifies a syntax code |
227 into the code it signifies. | 227 into the code it signifies. |
228 This is used by modify-syntax-entry, and other things. */ | 228 This is used by modify-syntax-entry, and other things. */ |
260 { | 260 { |
261 return Vsyntax_designator_chars_string; | 261 return Vsyntax_designator_chars_string; |
262 } | 262 } |
263 | 263 |
264 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /* | 264 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /* |
265 Return the syntax code of CHAR, described by a character. | 265 Return the syntax code of CHARACTER, described by a character. |
266 For example, if CHAR is a word constituent, the character `?w' is returned. | 266 For example, if CHARACTER is a word constituent, |
267 the character `?w' is returned. | |
267 The characters that correspond to various syntax codes | 268 The characters that correspond to various syntax codes |
268 are listed in the documentation of `modify-syntax-entry'. | 269 are listed in the documentation of `modify-syntax-entry'. |
269 Optional second argument TABLE defaults to the current buffer's | 270 Optional second argument SYNTAX-TABLE defaults to the current buffer's |
270 syntax table. | 271 syntax table. |
271 */ | 272 */ |
272 (ch, table)) | 273 (character, syntax_table)) |
273 { | 274 { |
274 Lisp_Char_Table *mirrortab; | 275 Lisp_Char_Table *mirrortab; |
275 | 276 |
276 if (NILP(ch)) | 277 if (NILP (character)) |
277 { | 278 { |
278 ch = make_char('\000'); | 279 character = make_char ('\000'); |
279 } | 280 } |
280 CHECK_CHAR_COERCE_INT (ch); | 281 CHECK_CHAR_COERCE_INT (character); |
281 table = check_syntax_table (table, current_buffer->syntax_table); | 282 syntax_table = check_syntax_table (syntax_table, current_buffer->syntax_table); |
282 mirrortab = XCHAR_TABLE (XCHAR_TABLE (table)->mirror_table); | 283 mirrortab = XCHAR_TABLE (XCHAR_TABLE (syntax_table)->mirror_table); |
283 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, XCHAR (ch))]); | 284 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, XCHAR (character))]); |
284 } | 285 } |
285 | 286 |
286 #ifdef MULE | 287 #ifdef MULE |
287 | 288 |
288 enum syntaxcode | 289 enum syntaxcode |
294 } | 295 } |
295 | 296 |
296 #endif | 297 #endif |
297 | 298 |
298 Lisp_Object | 299 Lisp_Object |
299 syntax_match (Lisp_Object table, Emchar ch) | 300 syntax_match (Lisp_Object syntax_table, Emchar ch) |
300 { | 301 { |
301 Lisp_Object code = XCHAR_TABLE_VALUE_UNSAFE (table, ch); | 302 Lisp_Object code = XCHAR_TABLE_VALUE_UNSAFE (syntax_table, ch); |
302 Lisp_Object code2 = code; | 303 Lisp_Object code2 = code; |
303 | 304 |
304 if (CONSP (code)) | 305 if (CONSP (code)) |
305 code2 = XCAR (code); | 306 code2 = XCAR (code); |
306 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit) | 307 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit) |
308 | 309 |
309 return CONSP (code) ? XCDR (code) : Qnil; | 310 return CONSP (code) ? XCDR (code) : Qnil; |
310 } | 311 } |
311 | 312 |
312 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /* | 313 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /* |
313 Return the matching parenthesis of CHAR, or nil if none. | 314 Return the matching parenthesis of CHARACTER, or nil if none. |
314 Optional second argument TABLE defaults to the current buffer's | 315 Optional second argument SYNTAX-TABLE defaults to the current buffer's |
315 syntax table. | 316 syntax table. |
316 */ | 317 */ |
317 (ch, table)) | 318 (character, syntax_table)) |
318 { | 319 { |
319 Lisp_Char_Table *mirrortab; | 320 Lisp_Char_Table *mirrortab; |
320 int code; | 321 int code; |
321 | 322 |
322 CHECK_CHAR_COERCE_INT (ch); | 323 CHECK_CHAR_COERCE_INT (character); |
323 table = check_syntax_table (table, current_buffer->syntax_table); | 324 syntax_table = check_syntax_table (syntax_table, current_buffer->syntax_table); |
324 mirrortab = XCHAR_TABLE (XCHAR_TABLE (table)->mirror_table); | 325 mirrortab = XCHAR_TABLE (XCHAR_TABLE (syntax_table)->mirror_table); |
325 code = SYNTAX (mirrortab, XCHAR (ch)); | 326 code = SYNTAX (mirrortab, XCHAR (character)); |
326 if (code == Sopen || code == Sclose || code == Sstring) | 327 if (code == Sopen || code == Sclose || code == Sstring) |
327 return syntax_match (table, XCHAR (ch)); | 328 return syntax_match (syntax_table, XCHAR (character)); |
328 return Qnil; | 329 return Qnil; |
329 } | 330 } |
330 | 331 |
331 | 332 |
332 | 333 |
646 that logic made this function break, so I'm leaving it out. If anyone | 647 that logic made this function break, so I'm leaving it out. If anyone |
647 ever complains about this function not working properly, take a look | 648 ever complains about this function not working properly, take a look |
648 at those changes. --ben */ | 649 at those changes. --ben */ |
649 | 650 |
650 DEFUN ("forward-comment", Fforward_comment, 1, 2, 0, /* | 651 DEFUN ("forward-comment", Fforward_comment, 1, 2, 0, /* |
651 Move forward across up to N comments. If N is negative, move backward. | 652 Move forward across up to COUNT comments, or backwards if COUNT is negative. |
652 Stop scanning if we find something other than a comment or whitespace. | 653 Stop scanning if we find something other than a comment or whitespace. |
653 Set point to where scanning stops. | 654 Set point to where scanning stops. |
654 If N comments are found as expected, with nothing except whitespace | 655 If COUNT comments are found as expected, with nothing except whitespace |
655 between them, return t; otherwise return nil. | 656 between them, return t; otherwise return nil. |
656 Point is set in either case. | 657 Point is set in either case. |
657 Optional argument BUFFER defaults to the current buffer. | 658 Optional argument BUFFER defaults to the current buffer. |
658 */ | 659 */ |
659 (n, buffer)) | 660 (count, buffer)) |
660 { | 661 { |
661 Bufpos from; | 662 Bufpos from; |
662 Bufpos stop; | 663 Bufpos stop; |
663 Emchar c; | 664 Emchar c; |
664 enum syntaxcode code; | 665 enum syntaxcode code; |
665 EMACS_INT count; | 666 EMACS_INT n; |
666 struct buffer *buf = decode_buffer (buffer, 0); | 667 struct buffer *buf = decode_buffer (buffer, 0); |
667 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table); | 668 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table); |
668 | 669 |
669 CHECK_INT (n); | 670 CHECK_INT (count); |
670 count = XINT (n); | 671 n = XINT (count); |
671 | 672 |
672 from = BUF_PT (buf); | 673 from = BUF_PT (buf); |
673 | 674 |
674 while (count > 0) | 675 while (n > 0) |
675 { | 676 { |
676 QUIT; | 677 QUIT; |
677 | 678 |
678 stop = BUF_ZV (buf); | 679 stop = BUF_ZV (buf); |
679 while (from < stop) | 680 while (from < stop) |
738 } | 739 } |
739 from++; | 740 from++; |
740 } | 741 } |
741 | 742 |
742 /* End of comment reached */ | 743 /* End of comment reached */ |
743 count--; | 744 n--; |
744 } | 745 } |
745 | 746 |
746 while (count < 0) | 747 while (n < 0) |
747 { | 748 { |
748 QUIT; | 749 QUIT; |
749 | 750 |
750 stop = BUF_BEGV (buf); | 751 stop = BUF_BEGV (buf); |
751 while (from > stop) | 752 while (from > stop) |
797 BUF_SET_PT (buf, from + 1); | 798 BUF_SET_PT (buf, from + 1); |
798 return Qnil; | 799 return Qnil; |
799 } | 800 } |
800 } | 801 } |
801 | 802 |
802 count++; | 803 n++; |
803 } | 804 } |
804 | 805 |
805 BUF_SET_PT (buf, from); | 806 BUF_SET_PT (buf, from); |
806 return Qt; | 807 return Qt; |
807 } | 808 } |
808 | 809 |
809 | 810 |
810 Lisp_Object | 811 Lisp_Object |
811 scan_lists (struct buffer *buf, Bufpos from, int count, int depth, | 812 scan_lists (struct buffer *buf, Bufpos from, int count, int depth, |
812 int sexpflag, int no_error) | 813 int sexpflag, int noerror) |
813 { | 814 { |
814 Bufpos stop; | 815 Bufpos stop; |
815 Emchar c; | 816 Emchar c; |
816 int quoted; | 817 int quoted; |
817 int mathexit = 0; | 818 int mathexit = 0; |
927 case Sclose: | 928 case Sclose: |
928 close1: | 929 close1: |
929 if (!--depth) goto done; | 930 if (!--depth) goto done; |
930 if (depth < min_depth) | 931 if (depth < min_depth) |
931 { | 932 { |
932 if (no_error) | 933 if (noerror) |
933 return Qnil; | 934 return Qnil; |
934 error ("Containing expression ends prematurely"); | 935 error ("Containing expression ends prematurely"); |
935 } | 936 } |
936 break; | 937 break; |
937 | 938 |
1072 case Sopen: | 1073 case Sopen: |
1073 open2: | 1074 open2: |
1074 if (!--depth) goto done2; | 1075 if (!--depth) goto done2; |
1075 if (depth < min_depth) | 1076 if (depth < min_depth) |
1076 { | 1077 { |
1077 if (no_error) | 1078 if (noerror) |
1078 return Qnil; | 1079 return Qnil; |
1079 error ("Containing expression ends prematurely"); | 1080 error ("Containing expression ends prematurely"); |
1080 } | 1081 } |
1081 break; | 1082 break; |
1082 | 1083 |
1124 | 1125 |
1125 | 1126 |
1126 return (make_int (from)); | 1127 return (make_int (from)); |
1127 | 1128 |
1128 lose: | 1129 lose: |
1129 if (!no_error) | 1130 if (!noerror) |
1130 error ("Unbalanced parentheses"); | 1131 error ("Unbalanced parentheses"); |
1131 return Qnil; | 1132 return Qnil; |
1132 } | 1133 } |
1133 | 1134 |
1134 int | 1135 int |
1166 of in the current buffer. | 1167 of in the current buffer. |
1167 | 1168 |
1168 If optional arg NOERROR is non-nil, scan-lists will return nil instead of | 1169 If optional arg NOERROR is non-nil, scan-lists will return nil instead of |
1169 signalling an error. | 1170 signalling an error. |
1170 */ | 1171 */ |
1171 (from, count, depth, buffer, no_error)) | 1172 (from, count, depth, buffer, noerror)) |
1172 { | 1173 { |
1173 struct buffer *buf; | 1174 struct buffer *buf; |
1174 | 1175 |
1175 CHECK_INT (from); | 1176 CHECK_INT (from); |
1176 CHECK_INT (count); | 1177 CHECK_INT (count); |
1177 CHECK_INT (depth); | 1178 CHECK_INT (depth); |
1178 buf = decode_buffer (buffer, 0); | 1179 buf = decode_buffer (buffer, 0); |
1179 | 1180 |
1180 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0, | 1181 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0, |
1181 !NILP (no_error)); | 1182 !NILP (noerror)); |
1182 } | 1183 } |
1183 | 1184 |
1184 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /* | 1185 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /* |
1185 Scan from character number FROM by COUNT balanced expressions. | 1186 Scan from character number FROM by COUNT balanced expressions. |
1186 If COUNT is negative, scan backwards. | 1187 If COUNT is negative, scan backwards. |
1197 of in the current buffer. | 1198 of in the current buffer. |
1198 | 1199 |
1199 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of | 1200 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of |
1200 signalling an error. | 1201 signalling an error. |
1201 */ | 1202 */ |
1202 (from, count, buffer, no_error)) | 1203 (from, count, buffer, noerror)) |
1203 { | 1204 { |
1204 struct buffer *buf = decode_buffer (buffer, 0); | 1205 struct buffer *buf = decode_buffer (buffer, 0); |
1205 CHECK_INT (from); | 1206 CHECK_INT (from); |
1206 CHECK_INT (count); | 1207 CHECK_INT (count); |
1207 | 1208 |
1208 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (no_error)); | 1209 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (noerror)); |
1209 } | 1210 } |
1210 | 1211 |
1211 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /* | 1212 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /* |
1212 Move point backward over any number of chars with prefix syntax. | 1213 Move point backward over any number of chars with prefix syntax. |
1213 This includes chars with "quote" or "prefix" syntax (' or p). | 1214 This includes chars with "quote" or "prefix" syntax (' or p). |
1506 | 1507 |
1507 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /* | 1508 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /* |
1508 Parse Lisp syntax starting at FROM until TO; return status of parse at TO. | 1509 Parse Lisp syntax starting at FROM until TO; return status of parse at TO. |
1509 Parsing stops at TO or when certain criteria are met; | 1510 Parsing stops at TO or when certain criteria are met; |
1510 point is set to where parsing stops. | 1511 point is set to where parsing stops. |
1511 If fifth arg STATE is omitted or nil, | 1512 If fifth arg OLDSTATE is omitted or nil, |
1512 parsing assumes that FROM is the beginning of a function. | 1513 parsing assumes that FROM is the beginning of a function. |
1513 Value is a list of eight elements describing final state of parsing: | 1514 Value is a list of eight elements describing final state of parsing: |
1514 0. depth in parens. | 1515 0. depth in parens. |
1515 1. character address of start of innermost containing list; nil if none. | 1516 1. character address of start of innermost containing list; nil if none. |
1516 2. character address of start of last complete sexp terminated. | 1517 2. character address of start of last complete sexp terminated. |
1522 7. nil if in comment style a, or not in a comment; t if in comment style b | 1523 7. nil if in comment style a, or not in a comment; t if in comment style b |
1523 If third arg TARGETDEPTH is non-nil, parsing stops if the depth | 1524 If third arg TARGETDEPTH is non-nil, parsing stops if the depth |
1524 in parentheses becomes equal to TARGETDEPTH. | 1525 in parentheses becomes equal to TARGETDEPTH. |
1525 Fourth arg STOPBEFORE non-nil means stop when come to | 1526 Fourth arg STOPBEFORE non-nil means stop when come to |
1526 any character that starts a sexp. | 1527 any character that starts a sexp. |
1527 Fifth arg STATE is an eight-element list like what this function returns. | 1528 Fifth arg OLDSTATE is an eight-element list like what this function returns. |
1528 It is used to initialize the state of the parse. Its second and third | 1529 It is used to initialize the state of the parse. Its second and third |
1529 elements are ignored. | 1530 elements are ignored. |
1530 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. | 1531 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. |
1531 */ | 1532 */ |
1532 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer)) | 1533 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer)) |