diff options
| author | Stefan Monnier | 2000-07-12 01:08:46 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-07-12 01:08:46 +0000 |
| commit | 02010917dfa84cfd9424bca304adea975c6e7cf7 (patch) | |
| tree | 4932efdcbd13943ac086742ad82bdf877c668f7f /src | |
| parent | d76c03ea6b1d5cf3fdc8857ae104574ceadbc0bb (diff) | |
| download | emacs-02010917dfa84cfd9424bca304adea975c6e7cf7.tar.gz emacs-02010917dfa84cfd9424bca304adea975c6e7cf7.zip | |
(back_comment): Use one switch rather than a few `if's.
Obey open_paren_in_column_0_is_defun_start.
When reverting to the `slow' method, try to nicely handle the case
of nested comments by checking that the comment-starter we found
does indeed match the comment-ender.
(scan_sexps_forward, scan_sexps_forward):
Ignore excessive opening parenthesis rather than throwing an error.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 10 | ||||
| -rw-r--r-- | src/syntax.c | 91 |
2 files changed, 61 insertions, 40 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 5bd4a134b86..0eb840f11be 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2000-07-11 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * syntax.c (back_comment): Use one switch rather than a few `if's. | ||
| 4 | Obey open_paren_in_column_0_is_defun_start. | ||
| 5 | When reverting to the `slow' method, try to nicely handle the case | ||
| 6 | of nested comments by checking that the comment-starter we found | ||
| 7 | does indeed match the comment-ender. | ||
| 8 | (scan_sexps_forward, scan_sexps_forward): | ||
| 9 | Ignore excessive opening parenthesis rather than throwing an error. | ||
| 10 | |||
| 1 | 2000-07-11 Gerd Moellmann <gerd@gnu.org> | 11 | 2000-07-11 Gerd Moellmann <gerd@gnu.org> |
| 2 | 12 | ||
| 3 | * doc.c (Fsubstitute_command_keys): Handle case that a GC | 13 | * doc.c (Fsubstitute_command_keys): Handle case that a GC |
diff --git a/src/syntax.c b/src/syntax.c index fcc6dc6b4da..43081e27945 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -527,7 +527,6 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 527 | if (code != Sendcomment && char_quoted (from, from_byte)) | 527 | if (code != Sendcomment && char_quoted (from, from_byte)) |
| 528 | continue; | 528 | continue; |
| 529 | 529 | ||
| 530 | /* Track parity of quotes. */ | ||
| 531 | switch (code) | 530 | switch (code) |
| 532 | { | 531 | { |
| 533 | case Sstring_fence: | 532 | case Sstring_fence: |
| @@ -568,31 +567,33 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 568 | comstart_byte = from_byte; | 567 | comstart_byte = from_byte; |
| 569 | break; | 568 | break; |
| 570 | 569 | ||
| 571 | default: | 570 | case Sendcomment: |
| 572 | ; | 571 | if (SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)) == comstyle) |
| 573 | } | 572 | /* This is the same style of comment ender as ours. */ |
| 574 | 573 | { | |
| 575 | /* If we find another earlier comment-ender, | 574 | if (comnested) |
| 576 | any comment-starts earlier than that don't count | 575 | nesting++; |
| 577 | (because they go with the earlier comment-ender). */ | 576 | else |
| 578 | if (code == Sendcomment | 577 | /* Anything before that can't count because it would match |
| 579 | && SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)) == comstyle) | 578 | this comment-ender rather than ours. */ |
| 580 | { | 579 | from = stop; /* Break out of the loop. */ |
| 581 | if (comnested) | 580 | } |
| 582 | nesting++; | 581 | break; |
| 583 | else | ||
| 584 | break; | ||
| 585 | } | ||
| 586 | 582 | ||
| 587 | /* Assume a defun-start point is outside of strings. */ | 583 | case Sopen: |
| 588 | if (code == Sopen | 584 | /* Assume a defun-start point is outside of strings. */ |
| 589 | && (from == stop | 585 | if (open_paren_in_column_0_is_defun_start |
| 590 | || (temp_byte = dec_bytepos (from_byte), | 586 | && (from == stop |
| 591 | FETCH_CHAR (temp_byte) == '\n'))) | 587 | || (temp_byte = dec_bytepos (from_byte), |
| 592 | { | 588 | FETCH_CHAR (temp_byte) == '\n'))) |
| 593 | defun_start = from; | 589 | { |
| 594 | defun_start_byte = from_byte; | 590 | defun_start = from; |
| 591 | defun_start_byte = from_byte; | ||
| 592 | from = stop; /* Break out of the loop. */ | ||
| 593 | } | ||
| 595 | break; | 594 | break; |
| 595 | |||
| 596 | default: | ||
| 596 | } | 597 | } |
| 597 | } | 598 | } |
| 598 | 599 | ||
| @@ -619,7 +620,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 619 | lossage: | 620 | lossage: |
| 620 | /* We had two kinds of string delimiters mixed up | 621 | /* We had two kinds of string delimiters mixed up |
| 621 | together. Decode this going forwards. | 622 | together. Decode this going forwards. |
| 622 | Scan fwd from the previous comment ender | 623 | Scan fwd from a known safe place (beginning-of-defun) |
| 623 | to the one in question; this records where we | 624 | to the one in question; this records where we |
| 624 | last passed a comment starter. */ | 625 | last passed a comment starter. */ |
| 625 | /* If we did not already find the defun start, find it now. */ | 626 | /* If we did not already find the defun start, find it now. */ |
| @@ -628,20 +629,30 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 628 | defun_start = find_defun_start (comment_end, comment_end_byte); | 629 | defun_start = find_defun_start (comment_end, comment_end_byte); |
| 629 | defun_start_byte = find_start_value_byte; | 630 | defun_start_byte = find_start_value_byte; |
| 630 | } | 631 | } |
| 631 | scan_sexps_forward (&state, | 632 | do |
| 632 | defun_start, defun_start_byte, | ||
| 633 | comment_end - 1, -10000, 0, Qnil, 0); | ||
| 634 | if (state.incomment) | ||
| 635 | { | ||
| 636 | /* scan_sexps_forward changed the direction of search in | ||
| 637 | global variables, so we need to update it completely. */ | ||
| 638 | |||
| 639 | from = state.comstr_start; | ||
| 640 | } | ||
| 641 | else | ||
| 642 | { | 633 | { |
| 643 | from = comment_end; | 634 | scan_sexps_forward (&state, |
| 644 | } | 635 | defun_start, defun_start_byte, |
| 636 | comment_end, -10000, 0, Qnil, 0); | ||
| 637 | defun_start = comment_end; | ||
| 638 | if (state.incomment == (comnested ? 1 : -1) | ||
| 639 | && state.comstyle == comstyle) | ||
| 640 | from = state.comstr_start; | ||
| 641 | else | ||
| 642 | { | ||
| 643 | from = comment_end; | ||
| 644 | if (state.incomment) | ||
| 645 | /* If comment_end is inside some other comment, maybe ours | ||
| 646 | is nested, so we need to try again from within the | ||
| 647 | surrounding comment. Example: { a (* " *) */ | ||
| 648 | { | ||
| 649 | /* FIXME: We should advance by one or two chars. */ | ||
| 650 | defun_start = state.comstr_start + 2; | ||
| 651 | defun_start_byte = CHAR_TO_BYTE (defun_start); | ||
| 652 | } | ||
| 653 | } | ||
| 654 | } while (defun_start < comment_end); | ||
| 655 | |||
| 645 | from_byte = CHAR_TO_BYTE (from); | 656 | from_byte = CHAR_TO_BYTE (from); |
| 646 | UPDATE_SYNTAX_TABLE_FORWARD (from - 1); | 657 | UPDATE_SYNTAX_TABLE_FORWARD (from - 1); |
| 647 | } | 658 | } |
| @@ -2525,7 +2536,7 @@ do { prev_from = from; \ | |||
| 2525 | /* curlevel++->last ran into compiler bug on Apollo */ | 2536 | /* curlevel++->last ran into compiler bug on Apollo */ |
| 2526 | curlevel->last = XINT (Fcar (tem)); | 2537 | curlevel->last = XINT (Fcar (tem)); |
| 2527 | if (++curlevel == endlevel) | 2538 | if (++curlevel == endlevel) |
| 2528 | error ("Nesting too deep for parser"); | 2539 | curlevel--; /* error ("Nesting too deep for parser"); */ |
| 2529 | curlevel->prev = -1; | 2540 | curlevel->prev = -1; |
| 2530 | curlevel->last = -1; | 2541 | curlevel->last = -1; |
| 2531 | tem = Fcdr (tem); | 2542 | tem = Fcdr (tem); |
| @@ -2673,7 +2684,7 @@ do { prev_from = from; \ | |||
| 2673 | /* curlevel++->last ran into compiler bug on Apollo */ | 2684 | /* curlevel++->last ran into compiler bug on Apollo */ |
| 2674 | curlevel->last = prev_from; | 2685 | curlevel->last = prev_from; |
| 2675 | if (++curlevel == endlevel) | 2686 | if (++curlevel == endlevel) |
| 2676 | error ("Nesting too deep for parser"); | 2687 | curlevel--; /* error ("Nesting too deep for parser"); */ |
| 2677 | curlevel->prev = -1; | 2688 | curlevel->prev = -1; |
| 2678 | curlevel->last = -1; | 2689 | curlevel->last = -1; |
| 2679 | if (targetdepth == depth) goto done; | 2690 | if (targetdepth == depth) goto done; |