It should be the last one before POS, or nearly the last.
When open_paren_in_column_0_is_defun_start is nonzero,
- the beginning of every line is treated as a defun-start.
+ only the beginning of the buffer is treated as a defun-start.
We record the information about where the scan started
and what its result was, so that another call in the same area
{
int opoint = PT, opoint_byte = PT_BYTE;
+ if (!open_paren_in_column_0_is_defun_start)
+ {
+ find_start_value_byte = BEGV_BYTE;
+ return BEGV;
+ }
+
/* Use previous finding, if it's valid and applies to this inquiry. */
if (current_buffer == find_start_buffer
/* Reuse the defun-start even if POS is a little farther on.
syntax-tables. */
gl_state.current_syntax_table = current_buffer->syntax_table;
gl_state.use_global = 0;
- if (open_paren_in_column_0_is_defun_start)
+ while (PT > BEGV)
{
- while (PT > BEGV)
+ /* Open-paren at start of line means we may have found our
+ defun-start. */
+ if (SYNTAX (FETCH_CHAR (PT_BYTE)) == Sopen)
{
- /* Open-paren at start of line means we may have found our
- defun-start. */
+ SETUP_SYNTAX_TABLE (PT + 1, -1); /* Try again... */
if (SYNTAX (FETCH_CHAR (PT_BYTE)) == Sopen)
- {
- SETUP_SYNTAX_TABLE (PT + 1, -1); /* Try again... */
- if (SYNTAX (FETCH_CHAR (PT_BYTE)) == Sopen)
- break;
- /* Now fallback to the default value. */
- gl_state.current_syntax_table = current_buffer->syntax_table;
- gl_state.use_global = 0;
- }
- /* Move to beg of previous line. */
- scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -2, 1);
+ break;
+ /* Now fallback to the default value. */
+ gl_state.current_syntax_table = current_buffer->syntax_table;
+ gl_state.use_global = 0;
}
+ /* Move to beg of previous line. */
+ scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -2, 1);
}
/* Record what we found, for the next try. */
case Sendcomment:
if (SYNTAX_FLAGS_COMMENT_STYLE (syntax) == comstyle
- && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax)
+ && ((com2end && SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax))
|| SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested)
/* This is the same style of comment ender as ours. */
{
(but not as the end of a range; quoting is never needed there).
Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
With arg "^a-zA-Z", skips nonletters stopping before first letter.
-Returns the distance traveled, either zero or positive. */)
+Returns the distance traveled, either zero or positive.
+Note that char classes, e.g. `[:alpha:]', are not currently supported;
+they will be treated as literals. */)
(string, lim)
Lisp_Object string, lim;
{
int start_point = PT;
int pos = PT;
int pos_byte = PT_BYTE;
+ unsigned char *p = PT_ADDR, *endp, *stop;
+
+ if (forwardp)
+ {
+ endp = (XINT (lim) == GPT) ? GPT_ADDR : CHAR_POS_ADDR (XINT (lim));
+ stop = (pos < GPT && GPT < XINT (lim)) ? GPT_ADDR : endp;
+ }
+ else
+ {
+ endp = CHAR_POS_ADDR (XINT (lim));
+ stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp;
+ }
immediate_quit = 1;
if (syntaxp)
if (forwardp)
{
if (multibyte)
- {
- if (pos < XINT (lim))
- while (fastmap[(int) SYNTAX (FETCH_CHAR (pos_byte))])
+ while (1)
+ {
+ int nbytes;
+
+ if (p >= stop)
{
- /* Since we already checked for multibyteness,
- avoid using INC_BOTH which checks again. */
- INC_POS (pos_byte);
- pos++;
- if (pos >= XINT (lim))
- break;
- UPDATE_SYNTAX_TABLE_FORWARD (pos);
+ if (p >= endp)
+ break;
+ p = GAP_END_ADDR;
+ stop = endp;
}
- }
+ c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes);
+ if (! fastmap[(int) SYNTAX (c)])
+ break;
+ p += nbytes, pos++, pos_byte += nbytes;
+ UPDATE_SYNTAX_TABLE_FORWARD (pos);
+ }
else
- {
- while (pos < XINT (lim)
- && fastmap[(int) SYNTAX (FETCH_BYTE (pos))])
- {
- pos++;
- UPDATE_SYNTAX_TABLE_FORWARD (pos);
- }
- }
+ while (1)
+ {
+ if (p >= stop)
+ {
+ if (p >= endp)
+ break;
+ p = GAP_END_ADDR;
+ stop = endp;
+ }
+ if (! fastmap[(int) SYNTAX (*p)])
+ break;
+ p++, pos++;
+ UPDATE_SYNTAX_TABLE_FORWARD (pos);
+ }
}
else
{
if (multibyte)
- {
- while (pos > XINT (lim))
- {
- int savepos = pos_byte;
- /* Since we already checked for multibyteness,
- avoid using DEC_BOTH which checks again. */
- pos--;
- DEC_POS (pos_byte);
- UPDATE_SYNTAX_TABLE_BACKWARD (pos);
- if (!fastmap[(int) SYNTAX (FETCH_CHAR (pos_byte))])
- {
- pos++;
- pos_byte = savepos;
+ while (1)
+ {
+ unsigned char *prev_p;
+ int nbytes;
+
+ if (p <= stop)
+ {
+ if (p <= endp)
break;
- }
- }
- }
+ p = GPT_ADDR;
+ stop = endp;
+ }
+ prev_p = p;
+ while (--p >= stop && ! CHAR_HEAD_P (*p));
+ PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes);
+ if (prev_p - p > nbytes)
+ p = prev_p - 1, c = *p, nbytes = 1;
+ else
+ c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH);
+ pos--, pos_byte -= nbytes;
+ UPDATE_SYNTAX_TABLE_BACKWARD (pos);
+ if (! fastmap[(int) SYNTAX (c)])
+ {
+ pos++;
+ pos_byte += nbytes;
+ break;
+ }
+ }
else
- {
- if (pos > XINT (lim))
- while (fastmap[(int) SYNTAX (FETCH_BYTE (pos - 1))])
+ while (1)
+ {
+ if (p <= stop)
{
- pos--;
- if (pos <= XINT (lim))
+ if (p <= endp)
break;
- UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
+ p = GPT_ADDR;
+ stop = endp;
}
- }
+ if (! fastmap[(int) SYNTAX (p[-1])])
+ break;
+ p--, pos--;
+ UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
+ }
}
}
else
if (forwardp)
{
if (multibyte)
- while (pos < XINT (lim))
+ while (1)
{
- c = FETCH_MULTIBYTE_CHAR (pos_byte);
+ int nbytes;
+
+ if (p >= stop)
+ {
+ if (p >= endp)
+ break;
+ p = GAP_END_ADDR;
+ stop = endp;
+ }
+ c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes);
if (SINGLE_BYTE_CHAR_P (c))
{
if (!fastmap[c])
if (!(negate ^ (i < n_char_ranges)))
break;
}
- INC_BOTH (pos, pos_byte);
+ p += nbytes, pos++, pos_byte += nbytes;
}
else
- while (pos < XINT (lim) && fastmap[FETCH_BYTE (pos)])
- pos++;
+ while (1)
+ {
+ if (p >= stop)
+ {
+ if (p >= endp)
+ break;
+ p = GAP_END_ADDR;
+ stop = endp;
+ }
+ if (!fastmap[*p])
+ break;
+ p++, pos++;
+ }
}
else
{
if (multibyte)
- while (pos > XINT (lim))
+ while (1)
{
- int prev_pos_byte = pos_byte;
+ unsigned char *prev_p;
+ int nbytes;
- DEC_POS (prev_pos_byte);
- c = FETCH_MULTIBYTE_CHAR (prev_pos_byte);
+ if (p <= stop)
+ {
+ if (p <= endp)
+ break;
+ p = GPT_ADDR;
+ stop = endp;
+ }
+ prev_p = p;
+ while (--p >= stop && ! CHAR_HEAD_P (*p));
+ PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes);
+ if (prev_p - p > nbytes)
+ p = prev_p - 1, c = *p, nbytes = 1;
+ else
+ c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH);
if (SINGLE_BYTE_CHAR_P (c))
{
if (!fastmap[c])
if (!(negate ^ (i < n_char_ranges)))
break;
}
- pos--;
- pos_byte = prev_pos_byte;
+ pos--, pos_byte -= nbytes;
}
else
- while (pos > XINT (lim) && fastmap[FETCH_BYTE (pos - 1)])
- pos--;
+ while (1)
+ {
+ if (p <= stop)
+ {
+ if (p <= endp)
+ break;
+ p = GPT_ADDR;
+ stop = endp;
+ }
+ if (!fastmap[p[-1]])
+ break;
+ p--, pos--;
+ }
}
}
}
DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 1, 0,
- doc: /* Move forward across up to N comments. If N is negative, move backward.
+ doc: /*
+Move forward across up to COUNT comments. If COUNT is negative, move backward.
Stop scanning if we find something other than a comment or whitespace.
Set point to where scanning stops.
-If N comments are found as expected, with nothing except whitespace
+If COUNT comments are found as expected, with nothing except whitespace
between them, return t; otherwise return nil. */)
(count)
Lisp_Object count;
stopbefore, oldstate, commentstop)
struct lisp_parse_state *stateptr;
register int from;
- int end, targetdepth, stopbefore;
+ int end, targetdepth, stopbefore, from_byte;
Lisp_Object oldstate;
int commentstop;
{
prev_from_syntax \
= SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte)); \
INC_BOTH (from, from_byte); \
- UPDATE_SYNTAX_TABLE_FORWARD (from); \
+ if (from < end) \
+ UPDATE_SYNTAX_TABLE_FORWARD (from); \
} while (0)
immediate_quit = 1;
else if (start_quoted)
goto startquoted;
-#if 0 /* This seems to be redundant with the identical code above. */
- SETUP_SYNTAX_TABLE (prev_from, 1);
- prev_from_syntax = SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte));
- UPDATE_SYNTAX_TABLE_FORWARD (from);
-#endif
-
while (from < end)
{
INC_FROM;
/* Record the comment style we have entered so that only
the comment-end sequence of the same style actually
terminates the comment section. */
- state.comstyle = SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte));
+ state.comstyle = SYNTAX_COMMENT_STYLE (c1);
comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax);
comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
state.incomment = comnested ? 1 : -1;
DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
&open_paren_in_column_0_is_defun_start,
- doc: /* Non-nil means an open paren in column 0 denotes the start of a defun. */);
+ doc: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
open_paren_in_column_0_is_defun_start = 1;
defsubr (&Ssyntax_table_p);