/* GNU Emacs routines to deal with syntax tables; also word and list parsing.
- Copyright (C) 1985, 1987, 1993 Free Software Foundation, Inc.
+ Copyright (C) 1985, 1987, 1993, 1994 Free Software Foundation, Inc.
This file is part of GNU Emacs.
return find_start_value;
/* Back up to start of line. */
- tem = scan_buffer ('\n', pos, -1, &shortage);
+ tem = scan_buffer ('\n', pos, -1, &shortage, 1);
while (tem > BEGV)
{
if (SYNTAX (FETCH_CHAR (tem)) == Sopen)
break;
/* Move to beg of previous line. */
- tem = scan_buffer ('\n', tem, -2, &shortage);
+ tem = scan_buffer ('\n', tem, -2, &shortage, 1);
}
/* Record what we found, for the next try. */
Lisp_Object ch;
{
CHECK_NUMBER (ch, 0);
- return make_number (syntax_code_spec[(int) SYNTAX (0xFF & XINT (ch))]);
+ return make_number (syntax_code_spec[(int) SYNTAX (XINT (ch))]);
+}
+
+DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0,
+ "Return the matching parenthesis of CHAR, or nil if none.")
+ (ch)
+ Lisp_Object ch;
+{
+ int code;
+ CHECK_NUMBER (ch, 0);
+ code = SYNTAX (XINT (ch));
+ if (code == Sopen || code == Sclose)
+ return make_number (SYNTAX_MATCH (XINT (ch)));
+ return Qnil;
}
/* This comment supplies the doc string for modify-syntax-entry,
while (count1 > 0)
{
stop = ZV;
- while (from < stop)
+ do
{
+ if (from == stop)
+ {
+ SET_PT (from);
+ return Qnil;
+ }
c = FETCH_CHAR (from);
code = SYNTAX (c);
from++;
comstyle = SYNTAX_COMMENT_STYLE (FETCH_CHAR (from));
from++;
}
-
- if (code == Scomment)
- {
- while (1)
- {
- if (from == stop)
- {
- immediate_quit = 0;
- SET_PT (from);
- return Qnil;
- }
- c = FETCH_CHAR (from);
- if (SYNTAX (c) == Sendcomment
- && SYNTAX_COMMENT_STYLE (c) == comstyle)
- /* we have encountered a comment end of the same style
- as the comment sequence which began this comment
- section */
- break;
- from++;
- if (from < stop && SYNTAX_COMEND_FIRST (c)
- && SYNTAX_COMEND_SECOND (FETCH_CHAR (from))
- && SYNTAX_COMMENT_STYLE (c) == comstyle)
- /* we have encountered a comment end of the same style
- as the comment sequence which began this comment
- section */
- { from++; break; }
- }
- /* We have skipped one comment. */
- break;
- }
- else if (code != Swhitespace && code != Sendcomment)
+ }
+ while (code == Swhitespace || code == Sendcomment);
+ if (code != Scomment)
+ {
+ immediate_quit = 0;
+ SET_PT (from - 1);
+ return Qnil;
+ }
+ /* We're at the start of a comment. */
+ while (1)
+ {
+ if (from == stop)
{
immediate_quit = 0;
- SET_PT (from - 1);
+ SET_PT (from);
return Qnil;
}
+ c = FETCH_CHAR (from);
+ if (SYNTAX (c) == Sendcomment
+ && SYNTAX_COMMENT_STYLE (c) == comstyle)
+ /* we have encountered a comment end of the same style
+ as the comment sequence which began this comment
+ section */
+ break;
+ from++;
+ if (from < stop && SYNTAX_COMEND_FIRST (c)
+ && SYNTAX_COMEND_SECOND (FETCH_CHAR (from))
+ && SYNTAX_COMMENT_STYLE (c) == comstyle)
+ /* we have encountered a comment end of the same style
+ as the comment sequence which began this comment
+ section */
+ { from++; break; }
}
-
- /* End of comment reached */
+ /* We have skipped one comment. */
count1--;
}
int comment_end = from;
int comstart_pos = 0;
int comstart_parity = 0;
+ int scanstart = from - 1;
/* At beginning of range to scan, we're outside of strings;
that determines quote parity to the comment-end. */
{
code = Sendcomment;
from--;
+ c = FETCH_CHAR (from);
}
- else if (from > stop && SYNTAX_COMSTART_SECOND (c)
- && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from - 1))
- && comstyle == SYNTAX_COMMENT_STYLE (c))
- {
- code = Scomment;
- from--;
- }
+ /* If this char starts a 2-char comment start sequence,
+ treat it like a 1-char comment starter. */
+ if (from < scanstart && SYNTAX_COMSTART_FIRST (c)
+ && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from + 1))
+ && comstyle == SYNTAX_COMMENT_STYLE (FETCH_CHAR (from + 1)))
+ code = Scomment;
/* Ignore escaped characters. */
if (char_quoted (from))
if (!parse_sexp_ignore_comments) break;
while (1)
{
- if (from == stop) goto done;
+ if (from == stop)
+ {
+ if (depth == 0)
+ goto done;
+ goto lose;
+ }
c = FETCH_CHAR (from);
if (SYNTAX (c) == Sendcomment
&& SYNTAX_COMMENT_STYLE (c) == comstyle)
if (SYNTAX (c = FETCH_CHAR (from)) == Scomment
&& SYNTAX_COMMENT_STYLE (c) == comstyle)
break;
- if (from == stop) goto done;
+ if (from == stop)
+ {
+ if (depth == 0)
+ goto done2;
+ goto lose;
+ }
from--;
if (SYNTAX_COMSTART_SECOND (c)
&& SYNTAX_COMSTART_FIRST (FETCH_CHAR (from))
int comment_end = from;
int comstart_pos = 0;
int comstart_parity = 0;
+ int scanstart = from - 1;
/* At beginning of range to scan, we're outside of strings;
that determines quote parity to the comment-end. */
{
code = Sendcomment;
from--;
+ c = FETCH_CHAR (from);
}
- else if (from > stop && SYNTAX_COMSTART_SECOND (c)
- && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from - 1))
- && comstyle == SYNTAX_COMMENT_STYLE (c))
- {
- code = Scomment;
- from--;
- }
+ /* If this char starts a 2-char comment start sequence,
+ treat it like a 1-char comment starter. */
+ if (from < scanstart && SYNTAX_COMSTART_FIRST (c)
+ && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from + 1))
+ && comstyle == SYNTAX_COMMENT_STYLE (FETCH_CHAR (from + 1)))
+ code = Scomment;
/* Ignore escaped characters. */
if (char_quoted (from))
defsubr (&Scopy_syntax_table);
defsubr (&Sset_syntax_table);
defsubr (&Schar_syntax);
+ defsubr (&Smatching_paren);
defsubr (&Smodify_syntax_entry);
defsubr (&Sdescribe_syntax);