aboutsummaryrefslogtreecommitdiffstats
path: root/src/syntax.c
diff options
context:
space:
mode:
authorStefan Monnier <[email protected]>2000-10-02 21:59:00 +0000
committerStefan Monnier <[email protected]>2000-10-02 21:59:00 +0000
commitabf8a9ffcc978497c75a9c32984acf7c8583967d (patch)
tree94ea3b198a9c6265878d24f31195ffe840473309 /src/syntax.c
parent00ed1b100c6f74f0b0f659799d7abad5df143956 (diff)
(forw_comment): Match nestedness of ender/starter.
(Fforward_comment): Treat an unmatched \n comment-ender as whitespace.
Diffstat (limited to 'src/syntax.c')
-rw-r--r--src/syntax.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/syntax.c b/src/syntax.c
index 1b3f9fc9dc..bb552d9ea0 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1696,7 +1696,8 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
code = syntax & 0xff;
if (code == Sendcomment
&& SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
- && --nesting <= 0)
+ && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
+ (nesting > 0 && --nesting == 0) : nesting < 0))
/* we have encountered a comment end of the same style
as the comment sequence which began this comment
section */
@@ -1709,6 +1710,7 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
break;
if (nesting > 0
&& code == Scomment
+ && SYNTAX_FLAGS_COMMENT_NESTED (syntax)
&& SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style)
/* we have encountered a nested comment of the same style
as the comment sequence which began this comment section */
@@ -1720,7 +1722,9 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax)
&& SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
&& (c1 = FETCH_CHAR (from_byte),
- SYNTAX_COMEND_SECOND (c1)))
+ SYNTAX_COMEND_SECOND (c1))
+ && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
+ SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0))
{
if (--nesting <= 0)
/* we have encountered a comment end of the same style
@@ -1738,7 +1742,9 @@ forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
&& SYNTAX_FLAGS_COMSTART_FIRST (syntax)
&& (c1 = FETCH_CHAR (from_byte),
SYNTAX_COMMENT_STYLE (c1) == style
- && SYNTAX_COMSTART_SECOND (c1)))
+ && SYNTAX_COMSTART_SECOND (c1))
+ && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
+ SYNTAX_COMMENT_NESTED (c1)))
/* we have encountered a nested comment of the same style
as the comment sequence which began this comment
section */
@@ -1819,10 +1825,8 @@ between them, return t; otherwise return nil.")
INC_BOTH (from, from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
}
- /* FIXME: here we ignore 2-char endcomments while we don't
- when going backwards. */
}
- while (code == Swhitespace || code == Sendcomment);
+ while (code == Swhitespace || (code == Sendcomment && c == '\n'));
if (code == Scomment_fence)
comstyle = ST_COMMENT_STYLE;
@@ -1876,7 +1880,6 @@ between them, return t; otherwise return nil.")
comnested = SYNTAX_COMMENT_NESTED (c);
if (code == Sendcomment)
comstyle = SYNTAX_COMMENT_STYLE (c);
- comstart_second = SYNTAX_COMSTART_SECOND (c);
if (from > stop && SYNTAX_COMEND_SECOND (c)
&& prev_char_comend_first (from, from_byte)
&& !char_quoted (from - 1, dec_bytepos (from_byte)))
@@ -1892,13 +1895,6 @@ between them, return t; otherwise return nil.")
comstyle = SYNTAX_COMMENT_STYLE (c1);
comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
}
- if (from > stop && comstart_second
- && prev_char_comstart_first (from, from_byte)
- && !char_quoted (from - 1, dec_bytepos (from_byte)))
- {
- code = Scomment;
- DEC_BOTH (from, from_byte);
- }
if (code == Scomment_fence)
{
@@ -1932,21 +1928,29 @@ between them, return t; otherwise return nil.")
&out_charpos, &out_bytepos);
if (found == -1)
{
-#if 0 /* cc-mode (and maybe others) relies on the bogus behavior. */
- /* Failure: we should go back to the end of this
- not-quite-endcomment. */
- if (SYNTAX(c) != code)
- /* It was a two-char Sendcomment. */
- INC_BOTH (from, from_byte);
- goto leave;
-#endif
+ if (c == '\n')
+ /* This end-of-line is not an end-of-comment.
+ Treat it like a whitespace.
+ CC-mode (and maybe others) relies on this behavior. */
+ ;
+ else
+ {
+ /* Failure: we should go back to the end of this
+ not-quite-endcomment. */
+ if (SYNTAX(c) != code)
+ /* It was a two-char Sendcomment. */
+ INC_BOTH (from, from_byte);
+ goto leave;
+ }
}
else
- /* We have skipped one comment. */
- from = out_charpos, from_byte = out_bytepos;
- break;
+ {
+ /* We have skipped one comment. */
+ from = out_charpos, from_byte = out_bytepos;
+ break;
+ }
}
- else if (code != Swhitespace && code != Scomment)
+ else if (code != Swhitespace)
{
leave:
immediate_quit = 0;