Mercurial > hg > xemacs-beta
comparison src/syntax.c @ 20:859a2309aef8 r19-15b93
Import from CVS: tag r19-15b93
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:50:05 +0200 |
parents | 0293115a14e9 |
children | 131b0175ea99 |
comparison
equal
deleted
inserted
replaced
19:ac1f612d5250 | 20:859a2309aef8 |
---|---|
89 | 89 |
90 static Bufpos | 90 static Bufpos |
91 find_defun_start (struct buffer *buf, Bufpos pos) | 91 find_defun_start (struct buffer *buf, Bufpos pos) |
92 { | 92 { |
93 Bufpos tem; | 93 Bufpos tem; |
94 Lisp_Object table = buf->syntax_table; | 94 Lisp_Object syntaxtab = buf->syntax_table; |
95 | 95 |
96 /* Use previous finding, if it's valid and applies to this inquiry. */ | 96 /* Use previous finding, if it's valid and applies to this inquiry. */ |
97 if (buf == find_start_buffer | 97 if (buf == find_start_buffer |
98 /* Reuse the defun-start even if POS is a little farther on. | 98 /* Reuse the defun-start even if POS is a little farther on. |
99 POS might be in the next defun, but that's ok. | 99 POS might be in the next defun, but that's ok. |
108 tem = find_next_newline (buf, pos, -1); | 108 tem = find_next_newline (buf, pos, -1); |
109 | 109 |
110 while (tem > BUF_BEGV (buf)) | 110 while (tem > BUF_BEGV (buf)) |
111 { | 111 { |
112 /* Open-paren at start of line means we found our defun-start. */ | 112 /* Open-paren at start of line means we found our defun-start. */ |
113 if (SYNTAX (table, BUF_FETCH_CHAR (buf, tem)) == Sopen) | 113 if (SYNTAX (syntaxtab, BUF_FETCH_CHAR (buf, tem)) == Sopen) |
114 break; | 114 break; |
115 /* Move to beg of previous line. */ | 115 /* Move to beg of previous line. */ |
116 tem = find_next_newline (buf, tem, -2); | 116 tem = find_next_newline (buf, tem, -2); |
117 } | 117 } |
118 | 118 |
124 find_start_pos = pos; | 124 find_start_pos = pos; |
125 | 125 |
126 return find_start_value; | 126 return find_start_value; |
127 } | 127 } |
128 | 128 |
129 DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0 /* | 129 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /* |
130 Return t if ARG is a syntax table. | 130 Return t if ARG is a syntax table. |
131 Any vector of 256 elements will do. | 131 Any vector of 256 elements will do. |
132 */ ) | 132 */ |
133 (obj) | 133 (obj)) |
134 Lisp_Object obj; | |
135 { | 134 { |
136 if (VECTORP (obj) && vector_length (XVECTOR (obj)) == 0400) | 135 if (VECTORP (obj) && vector_length (XVECTOR (obj)) == 0400) |
137 return Qt; | 136 return Qt; |
138 return Qnil; | 137 return Qnil; |
139 } | 138 } |
146 while (NILP (Fsyntax_table_p (obj))) | 145 while (NILP (Fsyntax_table_p (obj))) |
147 obj = wrong_type_argument (Qsyntax_table_p, obj); | 146 obj = wrong_type_argument (Qsyntax_table_p, obj); |
148 return (obj); | 147 return (obj); |
149 } | 148 } |
150 | 149 |
151 DEFUN ("syntax-table", Fsyntax_table, Ssyntax_table, 0, 1, 0 /* | 150 DEFUN ("syntax-table", Fsyntax_table, 0, 1, 0, /* |
152 Return the current syntax table. | 151 Return the current syntax table. |
153 This is the one specified by the current buffer, or by BUFFER if it | 152 This is the one specified by the current buffer, or by BUFFER if it |
154 is non-nil. | 153 is non-nil. |
155 */ ) | 154 */ |
156 (buffer) | 155 (buffer)) |
157 Lisp_Object buffer; | |
158 { | 156 { |
159 return decode_buffer (buffer, 0)->syntax_table; | 157 return decode_buffer (buffer, 0)->syntax_table; |
160 } | 158 } |
161 | 159 |
162 DEFUN ("standard-syntax-table", Fstandard_syntax_table, | 160 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /* |
163 Sstandard_syntax_table, 0, 0, 0 /* | |
164 Return the standard syntax table. | 161 Return the standard syntax table. |
165 This is the one used for new buffers. | 162 This is the one used for new buffers. |
166 */ ) | 163 */ |
167 () | 164 ()) |
168 { | 165 { |
169 return Vstandard_syntax_table; | 166 return Vstandard_syntax_table; |
170 } | 167 } |
171 | 168 |
172 DEFUN ("copy-syntax-table", Fcopy_syntax_table, Scopy_syntax_table, 0, 1, 0 /* | 169 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /* |
173 Construct a new syntax table and return it. | 170 Construct a new syntax table and return it. |
174 It is a copy of the TABLE, which defaults to the standard syntax table. | 171 It is a copy of the TABLE, which defaults to the standard syntax table. |
175 */ ) | 172 */ |
176 (table) | 173 (table)) |
177 Lisp_Object table; | |
178 { | 174 { |
179 if (NILP (Vstandard_syntax_table)) | 175 if (NILP (Vstandard_syntax_table)) |
180 /* Can only be null during initialization */ | 176 /* Can only be null during initialization */ |
181 return make_vector (0400, Qzero); | 177 return make_vector (0400, Qzero); |
182 | 178 |
183 table = check_syntax_table (table, Vstandard_syntax_table); | 179 table = check_syntax_table (table, Vstandard_syntax_table); |
184 return Fcopy_sequence (table); | 180 return Fcopy_sequence (table); |
185 } | 181 } |
186 | 182 |
187 DEFUN ("set-syntax-table", Fset_syntax_table, Sset_syntax_table, 1, 2, 0 /* | 183 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /* |
188 Select a new syntax table for BUFFER. | 184 Select a new syntax table for BUFFER. |
189 One argument, a syntax table. | 185 One argument, a syntax table. |
190 BUFFER defaults to the current buffer if omitted. | 186 BUFFER defaults to the current buffer if omitted. |
191 */ ) | 187 */ |
192 (table, buffer) | 188 (table, buffer)) |
193 Lisp_Object table, buffer; | |
194 { | 189 { |
195 struct buffer *buf = decode_buffer (buffer, 0); | 190 struct buffer *buf = decode_buffer (buffer, 0); |
196 table = check_syntax_table (table, Qnil); | 191 table = check_syntax_table (table, Qnil); |
197 buf->syntax_table = table; | 192 buf->syntax_table = table; |
198 /* Indicate that this buffer now has a specified syntax table. */ | 193 /* Indicate that this buffer now has a specified syntax table. */ |
230 { | 225 { |
231 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@', | 226 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@', |
232 'e', '\0' | 227 'e', '\0' |
233 }; | 228 }; |
234 | 229 |
235 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, | 230 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /* |
236 Ssyntax_designator_chars, 0, 0, 0 /* | |
237 Return a string of the recognized syntax designator chars. | 231 Return a string of the recognized syntax designator chars. |
238 The chars are ordered by their internal syntax codes, which are | 232 The chars are ordered by their internal syntax codes, which are |
239 numbered starting at 0. | 233 numbered starting at 0. |
240 */ ) | 234 */ |
241 () | 235 ()) |
242 { | 236 { |
243 return Vsyntax_designator_chars_string; | 237 return Vsyntax_designator_chars_string; |
244 } | 238 } |
245 | 239 |
246 DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 2, 0 /* | 240 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /* |
247 Return the syntax code of CHAR, described by a character. | 241 Return the syntax code of CHAR, described by a character. |
248 For example, if CHAR is a word constituent, the character `?w' is returned. | 242 For example, if CHAR is a word constituent, the character `?w' is returned. |
249 The characters that correspond to various syntax codes | 243 The characters that correspond to various syntax codes |
250 are listed in the documentation of `modify-syntax-entry'. | 244 are listed in the documentation of `modify-syntax-entry'. |
251 Optional second argument TABLE defaults to the current buffer's | 245 Optional second argument TABLE defaults to the current buffer's |
252 syntax table. | 246 syntax table. |
253 */ ) | 247 */ |
254 (ch, table) | 248 (ch, table)) |
255 Lisp_Object ch, table; | |
256 { | 249 { |
257 CHECK_CHAR_COERCE_INT (ch); | 250 CHECK_CHAR_COERCE_INT (ch); |
258 table = check_syntax_table (table, current_buffer->syntax_table); | 251 table = check_syntax_table (table, current_buffer->syntax_table); |
259 | 252 |
260 return make_int (syntax_code_spec[(int) SYNTAX (table, XINT (ch))]); | 253 return make_int (syntax_code_spec[(int) SYNTAX (table, XINT (ch))]); |
270 return Qnil; | 263 return Qnil; |
271 else | 264 else |
272 return make_char (stringterm); | 265 return make_char (stringterm); |
273 } | 266 } |
274 | 267 |
275 DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 2, 0 /* | 268 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /* |
276 Return the matching parenthesis of CHAR, or nil if none. | 269 Return the matching parenthesis of CHAR, or nil if none. |
277 Optional second argument TABLE defaults to the current buffer's | 270 Optional second argument TABLE defaults to the current buffer's |
278 syntax table. | 271 syntax table. |
279 */ ) | 272 */ |
280 (ch, table) | 273 (ch, table)) |
281 Lisp_Object ch, table; | |
282 { | 274 { |
283 int code; | 275 int code; |
284 CHECK_CHAR_COERCE_INT (ch); | 276 CHECK_CHAR_COERCE_INT (ch); |
285 | 277 |
286 table = check_syntax_table (table, current_buffer->syntax_table); | 278 table = check_syntax_table (table, current_buffer->syntax_table); |
380 } | 372 } |
381 | 373 |
382 return from; | 374 return from; |
383 } | 375 } |
384 | 376 |
385 DEFUN ("forward-word", Fforward_word, Sforward_word, 1, 2, "_p" /* | 377 DEFUN ("forward-word", Fforward_word, 1, 2, "_p", /* |
386 Move point forward ARG words (backward if ARG is negative). | 378 Move point forward ARG words (backward if ARG is negative). |
387 Normally returns t. | 379 Normally returns t. |
388 If an edge of the buffer is reached, point is left there | 380 If an edge of the buffer is reached, point is left there |
389 and nil is returned. | 381 and nil is returned. |
390 */ ) | 382 */ |
391 (count, buffer) | 383 (count, buffer)) |
392 Lisp_Object count, buffer; | |
393 { | 384 { |
394 Bufpos val; | 385 Bufpos val; |
395 struct buffer *buf = decode_buffer (buffer, 0); | 386 struct buffer *buf = decode_buffer (buffer, 0); |
396 CHECK_INT (count); | 387 CHECK_INT (count); |
397 | 388 |
584 above, which is part of Fforward_comment() in FSF). Attempts to port | 575 above, which is part of Fforward_comment() in FSF). Attempts to port |
585 that logic made this function break, so I'm leaving it out. If anyone | 576 that logic made this function break, so I'm leaving it out. If anyone |
586 ever complains about this function not working properly, take a look | 577 ever complains about this function not working properly, take a look |
587 at those changes. --ben */ | 578 at those changes. --ben */ |
588 | 579 |
589 DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 2, 0 /* | 580 DEFUN ("forward-comment", Fforward_comment, 1, 2, 0, /* |
590 Move forward across up to N comments. If N is negative, move backward. | 581 Move forward across up to N comments. If N is negative, move backward. |
591 Stop scanning if we find something other than a comment or whitespace. | 582 Stop scanning if we find something other than a comment or whitespace. |
592 Set point to where scanning stops. | 583 Set point to where scanning stops. |
593 If N comments are found as expected, with nothing except whitespace | 584 If N comments are found as expected, with nothing except whitespace |
594 between them, return t; otherwise return nil. | 585 between them, return t; otherwise return nil. |
595 Point is set in either case. | 586 Point is set in either case. |
596 Optional argument BUFFER defaults to the current buffer. | 587 Optional argument BUFFER defaults to the current buffer. |
597 */ ) | 588 */ |
598 (n, buffer) | 589 (n, buffer)) |
599 Lisp_Object n, buffer; | |
600 { | 590 { |
601 Bufpos from; | 591 Bufpos from; |
602 Bufpos stop; | 592 Bufpos stop; |
603 Emchar c; | 593 Emchar c; |
604 enum syntaxcode code; | 594 enum syntaxcode code; |
1088 || code == Sescape)) | 1078 || code == Sescape)) |
1089 pos--, quoted = !quoted; | 1079 pos--, quoted = !quoted; |
1090 return quoted; | 1080 return quoted; |
1091 } | 1081 } |
1092 | 1082 |
1093 DEFUN ("scan-lists", Fscan_lists, Sscan_lists, 3, 5, 0 /* | 1083 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /* |
1094 Scan from character number FROM by COUNT lists. | 1084 Scan from character number FROM by COUNT lists. |
1095 Returns the character number of the position thus found. | 1085 Returns the character number of the position thus found. |
1096 | 1086 |
1097 If DEPTH is nonzero, paren depth begins counting from that value, | 1087 If DEPTH is nonzero, paren depth begins counting from that value, |
1098 only places where the depth in parentheses becomes zero | 1088 only places where the depth in parentheses becomes zero |
1108 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead | 1098 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead |
1109 of in the current buffer. | 1099 of in the current buffer. |
1110 | 1100 |
1111 If optional arg NOERROR is non-nil, scan-lists will return nil instead of | 1101 If optional arg NOERROR is non-nil, scan-lists will return nil instead of |
1112 signalling an error. | 1102 signalling an error. |
1113 */ ) | 1103 */ |
1114 (from, count, depth, buffer, no_error) | 1104 (from, count, depth, buffer, no_error)) |
1115 Lisp_Object from, count, depth, buffer, no_error; | |
1116 { | 1105 { |
1117 struct buffer *buf; | 1106 struct buffer *buf; |
1118 | 1107 |
1119 CHECK_INT (from); | 1108 CHECK_INT (from); |
1120 CHECK_INT (count); | 1109 CHECK_INT (count); |
1123 | 1112 |
1124 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0, | 1113 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0, |
1125 !NILP (no_error)); | 1114 !NILP (no_error)); |
1126 } | 1115 } |
1127 | 1116 |
1128 DEFUN ("scan-sexps", Fscan_sexps, Sscan_sexps, 2, 4, 0 /* | 1117 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /* |
1129 Scan from character number FROM by COUNT balanced expressions. | 1118 Scan from character number FROM by COUNT balanced expressions. |
1130 If COUNT is negative, scan backwards. | 1119 If COUNT is negative, scan backwards. |
1131 Returns the character number of the position thus found. | 1120 Returns the character number of the position thus found. |
1132 | 1121 |
1133 Comments are ignored if `parse-sexp-ignore-comments' is non-nil. | 1122 Comments are ignored if `parse-sexp-ignore-comments' is non-nil. |
1140 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead | 1129 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead |
1141 of in the current buffer. | 1130 of in the current buffer. |
1142 | 1131 |
1143 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of | 1132 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of |
1144 signalling an error. | 1133 signalling an error. |
1145 */ ) | 1134 */ |
1146 (from, count, buffer, no_error) | 1135 (from, count, buffer, no_error)) |
1147 Lisp_Object from, count, buffer, no_error; | |
1148 { | 1136 { |
1149 struct buffer *buf = decode_buffer (buffer, 0); | 1137 struct buffer *buf = decode_buffer (buffer, 0); |
1150 CHECK_INT (from); | 1138 CHECK_INT (from); |
1151 CHECK_INT (count); | 1139 CHECK_INT (count); |
1152 | 1140 |
1153 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (no_error)); | 1141 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (no_error)); |
1154 } | 1142 } |
1155 | 1143 |
1156 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, Sbackward_prefix_chars, | 1144 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /* |
1157 0, 1, 0 /* | |
1158 Move point backward over any number of chars with prefix syntax. | 1145 Move point backward over any number of chars with prefix syntax. |
1159 This includes chars with \"quote\" or \"prefix\" syntax (' or p). | 1146 This includes chars with \"quote\" or \"prefix\" syntax (' or p). |
1160 | 1147 |
1161 Optional arg BUFFER defaults to the current buffer. | 1148 Optional arg BUFFER defaults to the current buffer. |
1162 */ ) | 1149 */ |
1163 (buffer) | 1150 (buffer)) |
1164 Lisp_Object buffer; | |
1165 { | 1151 { |
1166 struct buffer *buf = decode_buffer (buffer, 0); | 1152 struct buffer *buf = decode_buffer (buffer, 0); |
1167 Bufpos beg = BUF_BEGV (buf); | 1153 Bufpos beg = BUF_BEGV (buf); |
1168 Bufpos pos = BUF_PT (buf); | 1154 Bufpos pos = BUF_PT (buf); |
1169 Lisp_Object table = buf->syntax_table; | 1155 Lisp_Object table = buf->syntax_table; |
1450 state.location = from; | 1436 state.location = from; |
1451 | 1437 |
1452 *stateptr = state; | 1438 *stateptr = state; |
1453 } | 1439 } |
1454 | 1440 |
1455 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 7, 0 /* | 1441 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /* |
1456 Parse Lisp syntax starting at FROM until TO; return status of parse at TO. | 1442 Parse Lisp syntax starting at FROM until TO; return status of parse at TO. |
1457 Parsing stops at TO or when certain criteria are met; | 1443 Parsing stops at TO or when certain criteria are met; |
1458 point is set to where parsing stops. | 1444 point is set to where parsing stops. |
1459 If fifth arg STATE is omitted or nil, | 1445 If fifth arg STATE is omitted or nil, |
1460 parsing assumes that FROM is the beginning of a function. | 1446 parsing assumes that FROM is the beginning of a function. |
1474 any character that starts a sexp. | 1460 any character that starts a sexp. |
1475 Fifth arg STATE is an eight-element list like what this function returns. | 1461 Fifth arg STATE is an eight-element list like what this function returns. |
1476 It is used to initialize the state of the parse. Its second and third | 1462 It is used to initialize the state of the parse. Its second and third |
1477 elements are ignored. | 1463 elements are ignored. |
1478 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. | 1464 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. |
1479 */ ) | 1465 */ |
1480 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer) | 1466 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer)) |
1481 Lisp_Object from, to, targetdepth, stopbefore, oldstate, commentstop, buffer; | |
1482 { | 1467 { |
1483 struct lisp_parse_state state; | 1468 struct lisp_parse_state state; |
1484 int target; | 1469 int target; |
1485 Bufpos start, end; | 1470 Bufpos start, end; |
1486 struct buffer *buf = decode_buffer (buffer, 0); | 1471 struct buffer *buf = decode_buffer (buffer, 0); |
1530 void | 1515 void |
1531 syms_of_syntax (void) | 1516 syms_of_syntax (void) |
1532 { | 1517 { |
1533 defsymbol (&Qsyntax_table_p, "syntax-table-p"); | 1518 defsymbol (&Qsyntax_table_p, "syntax-table-p"); |
1534 | 1519 |
1535 defsubr (&Ssyntax_table_p); | 1520 DEFSUBR (Fsyntax_table_p); |
1536 defsubr (&Ssyntax_table); | 1521 DEFSUBR (Fsyntax_table); |
1537 defsubr (&Sstandard_syntax_table); | 1522 DEFSUBR (Fstandard_syntax_table); |
1538 defsubr (&Scopy_syntax_table); | 1523 DEFSUBR (Fcopy_syntax_table); |
1539 defsubr (&Sset_syntax_table); | 1524 DEFSUBR (Fset_syntax_table); |
1540 defsubr (&Ssyntax_designator_chars); | 1525 DEFSUBR (Fsyntax_designator_chars); |
1541 defsubr (&Schar_syntax); | 1526 DEFSUBR (Fchar_syntax); |
1542 defsubr (&Smatching_paren); | 1527 DEFSUBR (Fmatching_paren); |
1543 /* defsubr (&Smodify_syntax_entry); now in Lisp. */ | 1528 /* DEFSUBR (Fmodify_syntax_entry); now in Lisp. */ |
1544 /* defsubr (&Sdescribe_syntax); now in Lisp. */ | 1529 /* DEFSUBR (Fdescribe_syntax); now in Lisp. */ |
1545 | 1530 |
1546 defsubr (&Sforward_word); | 1531 DEFSUBR (Fforward_word); |
1547 | 1532 |
1548 defsubr (&Sforward_comment); | 1533 DEFSUBR (Fforward_comment); |
1549 defsubr (&Sscan_lists); | 1534 DEFSUBR (Fscan_lists); |
1550 defsubr (&Sscan_sexps); | 1535 DEFSUBR (Fscan_sexps); |
1551 defsubr (&Sbackward_prefix_chars); | 1536 DEFSUBR (Fbackward_prefix_chars); |
1552 defsubr (&Sparse_partial_sexp); | 1537 DEFSUBR (Fparse_partial_sexp); |
1553 } | 1538 } |
1554 | 1539 |
1555 void | 1540 void |
1556 vars_of_syntax (void) | 1541 vars_of_syntax (void) |
1557 { | 1542 { |