summaryrefslogtreecommitdiff
path: root/src/syntax.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax.c')
-rw-r--r--src/syntax.c131
1 files changed, 62 insertions, 69 deletions
diff --git a/src/syntax.c b/src/syntax.c
index a79ab863367..a03202d386c 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -535,7 +535,7 @@ char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos)
while (charpos > beg)
{
int c;
- DEC_BOTH (charpos, bytepos);
+ dec_both (&charpos, &bytepos);
UPDATE_SYNTAX_TABLE_BACKWARD (charpos);
c = FETCH_CHAR_AS_MULTIBYTE (bytepos);
@@ -556,11 +556,9 @@ char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos)
static ptrdiff_t
dec_bytepos (ptrdiff_t bytepos)
{
- if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
- return bytepos - 1;
-
- DEC_POS (bytepos);
- return bytepos;
+ return (bytepos
+ - (!NILP (BVAR (current_buffer, enable_multibyte_characters))
+ ? prev_char_len (bytepos) : 1));
}
/* Return a defun-start position before POS and not too far before.
@@ -667,7 +665,7 @@ prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte)
int c;
bool val;
- DEC_BOTH (pos, pos_byte);
+ dec_both (&pos, &pos_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (pos);
c = FETCH_CHAR (pos_byte);
val = SYNTAX_COMEND_FIRST (c);
@@ -738,7 +736,7 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
bool com2start, com2end, comstart;
/* Move back and examine a character. */
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
prev_syntax = syntax;
@@ -773,7 +771,7 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
{
ptrdiff_t next = from, next_byte = from_byte;
int next_c, next_syntax;
- DEC_BOTH (next, next_byte);
+ dec_both (&next, &next_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (next);
next_c = FETCH_CHAR_AS_MULTIBYTE (next_byte);
next_syntax = SYNTAX_WITH_FLAGS (next_c);
@@ -1150,8 +1148,7 @@ the value of a `syntax-table' text property. */)
if (*p)
{
- int len;
- int character = STRING_CHAR_AND_LENGTH (p, len);
+ int len, character = string_char_and_length (p, &len);
XSETINT (match, character);
if (XFIXNAT (match) == ' ')
match = Qnil;
@@ -1444,7 +1441,7 @@ scan_words (ptrdiff_t from, EMACS_INT count)
int ch0, ch1;
Lisp_Object func, pos;
- SETUP_SYNTAX_TABLE (from, count);
+ SETUP_SYNTAX_TABLE (from, clip_to_bounds (PTRDIFF_MIN, count, PTRDIFF_MAX));
while (count > 0)
{
@@ -1455,7 +1452,7 @@ scan_words (ptrdiff_t from, EMACS_INT count)
UPDATE_SYNTAX_TABLE_FORWARD (from);
ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
code = SYNTAX (ch0);
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
if (words_include_escapes
&& (code == Sescape || code == Scharquote))
break;
@@ -1488,7 +1485,7 @@ scan_words (ptrdiff_t from, EMACS_INT count)
|| (code != Sescape && code != Scharquote)))
|| word_boundary_p (ch0, ch1))
break;
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
ch0 = ch1;
rarely_quit (from);
}
@@ -1501,7 +1498,7 @@ scan_words (ptrdiff_t from, EMACS_INT count)
{
if (from == beg)
return 0;
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
ch1 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
code = SYNTAX (ch1);
@@ -1530,7 +1527,7 @@ scan_words (ptrdiff_t from, EMACS_INT count)
{
if (from == beg)
break;
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
code = SYNTAX (ch0);
@@ -1539,7 +1536,7 @@ scan_words (ptrdiff_t from, EMACS_INT count)
|| (code != Sescape && code != Scharquote)))
|| word_boundary_p (ch0, ch1))
{
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
break;
}
ch1 = ch0;
@@ -1818,7 +1815,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim,
leading_code = str[i_byte];
}
- c = STRING_CHAR_AND_LENGTH (str + i_byte, len);
+ c = string_char_and_length (str + i_byte, &len);
i_byte += len;
@@ -1834,14 +1831,14 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim,
/* Get the end of the range. */
leading_code2 = str[i_byte];
- c2 = STRING_CHAR_AND_LENGTH (str + i_byte, len);
+ c2 = string_char_and_length (str + i_byte, &len);
i_byte += len;
if (c2 == '\\'
&& i_byte < size_byte)
{
leading_code2 = str[i_byte];
- c2 = STRING_CHAR_AND_LENGTH (str + i_byte, len);
+ c2 = string_char_and_length (str + i_byte, &len);
i_byte += len;
}
@@ -1953,7 +1950,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim,
p = GAP_END_ADDR;
stop = endp;
}
- c = STRING_CHAR_AND_LENGTH (p, nbytes);
+ c = string_char_and_length (p, &nbytes);
if (! NILP (iso_classes) && in_classes (c, iso_classes))
{
if (negate)
@@ -2175,7 +2172,7 @@ skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim)
stop = endp;
}
if (multibyte)
- c = STRING_CHAR_AND_LENGTH (p, nbytes);
+ c = string_char_and_length (p, &nbytes);
else
c = *p, nbytes = 1;
if (! fastmap[SYNTAX (c)])
@@ -2357,7 +2354,7 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
/* We have encountered a nested comment of the same style
as the comment sequence which began this comment section. */
nesting++;
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
forw_incomment:
@@ -2378,7 +2375,7 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
break;
else
{
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
}
}
@@ -2395,7 +2392,7 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
as the comment sequence which began this comment section. */
{
syntax = Smax; /* So that "#|#" isn't also a comment ender. */
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
nesting++;
}
@@ -2437,7 +2434,7 @@ between them, return t; otherwise return nil. */)
from = PT;
from_byte = PT_BYTE;
- SETUP_SYNTAX_TABLE (from, count1);
+ SETUP_SYNTAX_TABLE (from, clip_to_bounds (PTRDIFF_MIN, count1, PTRDIFF_MAX));
while (count1 > 0)
{
do
@@ -2456,7 +2453,7 @@ between them, return t; otherwise return nil. */)
comstart_first = SYNTAX_FLAGS_COMSTART_FIRST (syntax);
comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax);
comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0);
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
if (from < stop && comstart_first
&& (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte),
@@ -2471,7 +2468,7 @@ between them, return t; otherwise return nil. */)
code = Scomment;
comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax);
comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax);
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
}
rarely_quit (++quit_count);
@@ -2482,7 +2479,7 @@ between them, return t; otherwise return nil. */)
comstyle = ST_COMMENT_STYLE;
else if (code != Scomment)
{
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
SET_PT_BOTH (from, from_byte);
return Qnil;
}
@@ -2495,7 +2492,7 @@ between them, return t; otherwise return nil. */)
SET_PT_BOTH (from, from_byte);
return Qnil;
}
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
/* We have skipped one comment. */
count1--;
@@ -2511,7 +2508,7 @@ between them, return t; otherwise return nil. */)
return Qnil;
}
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
/* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
bool quoted = char_quoted (from, from_byte);
c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
@@ -2529,7 +2526,7 @@ between them, return t; otherwise return nil. */)
/* We must record the comment style encountered so that
later, we can match only the proper comment begin
sequence of the same style. */
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
code = Sendcomment;
/* Calling char_quoted, above, set up global syntax position
at the new value of FROM. */
@@ -2547,7 +2544,7 @@ between them, return t; otherwise return nil. */)
while (1)
{
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
if (SYNTAX (c) == Scomment_fence
@@ -2572,8 +2569,9 @@ between them, return t; otherwise return nil. */)
}
else if (code == Sendcomment)
{
- found = back_comment (from, from_byte, stop, comnested, comstyle,
- &out_charpos, &out_bytepos);
+ found = (!quoted || !Vcomment_end_can_be_escaped)
+ && back_comment (from, from_byte, stop, comnested, comstyle,
+ &out_charpos, &out_bytepos);
if (!found)
{
if (c == '\n')
@@ -2587,7 +2585,7 @@ between them, return t; otherwise return nil. */)
not-quite-endcomment. */
if (SYNTAX (c) != code)
/* It was a two-char Sendcomment. */
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
goto leave;
}
}
@@ -2601,7 +2599,7 @@ between them, return t; otherwise return nil. */)
else if (code != Swhitespace || quoted)
{
leave:
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
SET_PT_BOTH (from, from_byte);
return Qnil;
}
@@ -2626,7 +2624,7 @@ syntax_multibyte (int c, bool multibyte_symbol_p)
}
static Lisp_Object
-scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
+scan_lists (EMACS_INT from0, EMACS_INT count, EMACS_INT depth, bool sexpflag)
{
Lisp_Object val;
ptrdiff_t stop = count > 0 ? ZV : BEGV;
@@ -2639,7 +2637,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
int comstyle = 0; /* Style of comment encountered. */
bool comnested = 0; /* Whether the comment is nestable or not. */
ptrdiff_t temp_pos;
- EMACS_INT last_good = from;
+ EMACS_INT last_good = from0;
bool found;
ptrdiff_t from_byte;
ptrdiff_t out_bytepos, out_charpos;
@@ -2650,14 +2648,13 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
if (depth > 0) min_depth = 0;
- if (from > ZV) from = ZV;
- if (from < BEGV) from = BEGV;
+ ptrdiff_t from = clip_to_bounds (BEGV, from0, ZV);
from_byte = CHAR_TO_BYTE (from);
maybe_quit ();
- SETUP_SYNTAX_TABLE (from, count);
+ SETUP_SYNTAX_TABLE (from, clip_to_bounds (PTRDIFF_MIN, count, PTRDIFF_MAX));
while (count > 0)
{
while (from < stop)
@@ -2675,7 +2672,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
prefix = SYNTAX_FLAGS_PREFIX (syntax);
if (depth == min_depth)
last_good = from;
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
if (from < stop && comstart_first
&& (c = FETCH_CHAR_AS_MULTIBYTE (from_byte),
@@ -2691,7 +2688,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
code = Scomment;
comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax);
comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax);
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
}
@@ -2704,7 +2701,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
case Scharquote:
if (from == stop)
goto lose;
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
/* Treat following character as a word constituent. */
FALLTHROUGH;
case Sword:
@@ -2720,7 +2717,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
{
case Scharquote:
case Sescape:
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
if (from == stop)
goto lose;
break;
@@ -2731,7 +2728,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
default:
goto done;
}
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
rarely_quit (++quit_count);
}
goto done;
@@ -2753,7 +2750,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
goto done;
goto lose;
}
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_FORWARD (from);
break;
@@ -2762,7 +2759,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
break;
if (from != stop && c == FETCH_CHAR_AS_MULTIBYTE (from_byte))
{
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
}
if (mathexit)
{
@@ -2802,11 +2799,11 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
break;
if (c_code == Scharquote || c_code == Sescape)
- INC_BOTH (from, from_byte);
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
+ inc_both (&from, &from_byte);
rarely_quit (++quit_count);
}
- INC_BOTH (from, from_byte);
+ inc_both (&from, &from_byte);
if (!depth && sexpflag) goto done;
break;
default:
@@ -2831,7 +2828,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
while (from > stop)
{
rarely_quit (++quit_count);
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
int syntax = SYNTAX_WITH_FLAGS (c);
@@ -2850,7 +2847,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
later, we can match only the proper comment begin
sequence of the same style. */
int c2, other_syntax;
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
code = Sendcomment;
c2 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
@@ -2864,7 +2861,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
if we decremented FROM in the if-statement above. */
if (code != Sendcomment && char_quoted (from, from_byte))
{
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
code = Sword;
}
else if (SYNTAX_FLAGS_PREFIX (syntax))
@@ -2881,11 +2878,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
after passing it. */
while (from > stop)
{
- temp_pos = from_byte;
- if (! NILP (BVAR (current_buffer, enable_multibyte_characters)))
- DEC_POS (temp_pos);
- else
- temp_pos--;
+ temp_pos = dec_bytepos (from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from - 1);
c1 = FETCH_CHAR_AS_MULTIBYTE (temp_pos);
/* Don't allow comment-end to be quoted. */
@@ -2894,7 +2887,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
quoted = char_quoted (from - 1, temp_pos);
if (quoted)
{
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
temp_pos = dec_bytepos (temp_pos);
UPDATE_SYNTAX_TABLE_BACKWARD (from - 1);
}
@@ -2905,7 +2898,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
case Sword: case Ssymbol: case Squote: break;
default: goto done2;
}
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
rarely_quit (++quit_count);
}
goto done2;
@@ -2918,7 +2911,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
temp_pos = dec_bytepos (from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from - 1);
if (from != stop && c == FETCH_CHAR_AS_MULTIBYTE (temp_pos))
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
}
if (mathexit)
{
@@ -2961,7 +2954,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
{
if (from == stop)
goto lose;
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
if (!char_quoted (from, from_byte))
{
@@ -2980,7 +2973,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
{
if (from == stop)
goto lose;
- DEC_BOTH (from, from_byte);
+ dec_both (&from, &from_byte);
UPDATE_SYNTAX_TABLE_BACKWARD (from);
if (!char_quoted (from, from_byte))
{
@@ -3090,7 +3083,7 @@ the prefix syntax flag (p). */)
SETUP_SYNTAX_TABLE (pos, -1);
- DEC_BOTH (pos, pos_byte);
+ dec_both (&pos, &pos_byte);
while (!char_quoted (pos, pos_byte)
/* Previous statement updates syntax table. */
@@ -3102,7 +3095,7 @@ the prefix syntax flag (p). */)
if (pos <= beg)
break;
- DEC_BOTH (pos, pos_byte);
+ dec_both (&pos, &pos_byte);
rarely_quit (pos);
}
@@ -3179,7 +3172,7 @@ scan_sexps_forward (struct lisp_parse_state *state,
prev_from = from;
prev_from_byte = from_byte;
if (from != BEGV)
- DEC_BOTH (prev_from, prev_from_byte);
+ dec_both (&prev_from, &prev_from_byte);
/* Use this macro instead of `from++'. */
#define INC_FROM \
@@ -3188,7 +3181,7 @@ do { prev_from = from; \
temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \
prev_prev_from_syntax = prev_from_syntax; \
prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
- INC_BOTH (from, from_byte); \
+ inc_both (&from, &from_byte); \
if (from < end) \
UPDATE_SYNTAX_TABLE_FORWARD (from); \
} while (0)