gl_state.offset = 0;
if (parse_sexp_lookup_properties)
if (count > 0 || from > BEGV)
- update_syntax_table (count > 0 ? from : from - 1, count, 1, Qnil);
+ update_syntax_table (count > 0 ? from : from - 1, count, true, Qnil);
}
/* Same as above, but in OBJECT. If OBJECT is nil, use current buffer.
{
Lisp_Object tmp_table;
int cnt = 0;
- bool invalidate = 1;
+ bool invalidate = true;
INTERVAL i;
if (init)
gl_state.stop = gl_state.e_property;
i = interval_of (charpos, object);
gl_state.backward_i = gl_state.forward_i = i;
- invalidate = 0;
+ invalidate = false;
if (!i)
return;
/* interval_of updates only ->position of the return value, so
i = update_interval (i, charpos);
if (INTERVAL_LAST_POS (i) != gl_state.b_property)
{
- invalidate = 0;
+ invalidate = false;
gl_state.forward_i = i;
gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
}
i = update_interval (i, charpos);
if (i->position != gl_state.e_property)
{
- invalidate = 0;
+ invalidate = false;
gl_state.backward_i = i;
gl_state.b_property = i->position - gl_state.offset;
}
}
eassert (i == NULL); /* This property goes to the end. */
if (count > 0)
- gl_state.e_property = gl_state.stop;
+ {
+ gl_state.e_property = gl_state.stop;
+ gl_state.forward_i = i;
+ }
else
gl_state.b_property = gl_state.start;
}
+
+static void
+parse_sexp_propertize (ptrdiff_t charpos)
+{
+ EMACS_INT modiffs = CHARS_MODIFF;
+ safe_call1 (Vparse_sexp_propertize_function,
+ make_number (1 + charpos));
+ if (modiffs != CHARS_MODIFF)
+ error ("parse-sexp-propertize-function modified the buffer!");
+ if (parse_sexp_propertize_done <= charpos)
+ error ("parse-sexp-propertize-function did not move"
+ " parse-sexp-propertize-done");
+ SETUP_SYNTAX_TABLE (charpos, 1);
+ if (gl_state.e_property > parse_sexp_propertize_done)
+ {
+ gl_state.e_property = parse_sexp_propertize_done;
+ gl_state.e_property_truncated = true;
+ }
+}
+
+void
+update_syntax_table_forward (ptrdiff_t charpos, bool init,
+ Lisp_Object object)
+{
+ if (!(gl_state.e_property_truncated))
+ update_syntax_table (charpos, 1, init, object);
+ if ((gl_state.e_property > parse_sexp_propertize_done
+ || gl_state.e_property_truncated)
+ && NILP (object))
+ {
+ if (parse_sexp_propertize_done > charpos)
+ {
+ gl_state.e_property = parse_sexp_propertize_done;
+ gl_state.e_property_truncated = true;
+ }
+ else
+ parse_sexp_propertize (charpos);
+ }
+}
\f
/* Returns true if char at CHARPOS is quoted.
Global syntax-table data should be set up already to be good at CHARPOS
- or after. On return global syntax data is good for lookup at CHARPOS. */
+ or after. On return global syntax data is good for lookup at CHARPOS. */
static bool
char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos)
OFROM[I] is position of the earliest comment-starter seen
which is I+2X quotes from the comment-end.
PARITY is current parity of quotes from the comment end. */
- int string_style = -1; /* Presumed outside of any string. */
+ int string_style = -1; /* Presumed outside of any string. */
bool string_lossage = 0;
/* Not a real lossage: indicates that we have passed a matching comment
starter plus a non-matching comment-ender, meaning that any matching
ptrdiff_t defun_start = 0;
ptrdiff_t defun_start_byte = 0;
enum syntaxcode code;
- ptrdiff_t nesting = 1; /* current comment nesting */
+ ptrdiff_t nesting = 1; /* Current comment nesting. */
int c;
int syntax = 0;
is nested, so we need to try again from within the
surrounding comment. Example: { a (* " *) */
{
- /* FIXME: We should advance by one or two chars. */
+ /* FIXME: We should advance by one or two chars. */
defun_start = state.comstr_start + 2;
defun_start_byte = CHAR_TO_BYTE (defun_start);
}
staticpro (&gl_state.current_syntax_table);
staticpro (&gl_state.old_prop);
- /* Defined in regex.c */
+ /* Defined in regex.c. */
staticpro (&re_match_object);
DEFSYM (Qscan_error, "scan-error");
See the info node `(elisp)Syntax Properties' for a description of the
`syntax-table' property. */);
+ DEFVAR_INT ("parse-sexp-propertize-done", parse_sexp_propertize_done,
+ doc: /* Position up to which syntax-table properties have been set. */);
+ parse_sexp_propertize_done = -1;
+
+ DEFVAR_LISP ("parse-sexp-propertize-function",
+ Vparse_sexp_propertize_function,
+ doc: /* Function to set the `syntax-table' text property.
+Called with one argument, the position at which the property is needed.
+After running it, `parse-sexp-propertize-done' should be strictly greater
+than the argument passed. */);
+ /* Note: Qnil is a temporary (and invalid) value; it will be properly set in
+ syntax.el. */
+ Vparse_sexp_propertize_function = Qnil;
+
words_include_escapes = 0;
DEFVAR_BOOL ("words-include-escapes", words_include_escapes,
doc: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
INLINE_HEADER_BEGIN
extern void update_syntax_table (ptrdiff_t, EMACS_INT, bool, Lisp_Object);
+extern void update_syntax_table_forward (ptrdiff_t, bool, Lisp_Object);
/* The standard syntax table is stored where it will automatically
be used in all new buffers. */
other side by any char with the same syntaxcode. */
Sstring_fence, /* Starts/ends string which is delimited on the
other side by any char with the same syntaxcode. */
- Smax /* Upper bound on codes that are meaningful */
+ Smax /* Upper bound on codes that are meaningful. */
};
struct gl_state_s
{
- Lisp_Object object; /* The object we are scanning. */
- ptrdiff_t start; /* Where to stop. */
- ptrdiff_t stop; /* Where to stop. */
+ Lisp_Object object; /* The object we are scanning. */
+ ptrdiff_t start; /* Where to stop. */
+ ptrdiff_t stop; /* Where to stop. */
bool use_global; /* Whether to use global_code
- or c_s_t. */
- Lisp_Object global_code; /* Syntax code of current char. */
- Lisp_Object current_syntax_table; /* Syntax table for current pos. */
- Lisp_Object old_prop; /* Syntax-table prop at prev pos. */
- ptrdiff_t b_property; /* First index where c_s_t is valid. */
+ or c_s_t. */
+ Lisp_Object global_code; /* Syntax code of current char. */
+ Lisp_Object current_syntax_table; /* Syntax table for current pos. */
+ Lisp_Object old_prop; /* Syntax-table prop at prev pos. */
+ ptrdiff_t b_property; /* First index where c_s_t is valid. */
ptrdiff_t e_property; /* First index where c_s_t is
- not valid. */
- INTERVAL forward_i; /* Where to start lookup on forward */
+ not valid. */
+ bool e_property_truncated; /* true if e_property if was truncated
+ by parse_sexp_propertize_done. */
+ INTERVAL forward_i; /* Where to start lookup on forward. */
INTERVAL backward_i; /* or backward movement. The
data in c_s_t is valid
between these intervals,
and possibly at the
intervals too, depending
- on: */
+ on: */
/* Offset for positions specified to UPDATE_SYNTAX_TABLE. */
ptrdiff_t offset;
};
UPDATE_SYNTAX_TABLE_FORWARD (ptrdiff_t charpos)
{
if (parse_sexp_lookup_properties && charpos >= gl_state.e_property)
- update_syntax_table (charpos + gl_state.offset, 1, false, gl_state.object);
+ update_syntax_table_forward (charpos + gl_state.offset, false, gl_state.object);
}
/* Make syntax table state (gl_state) good for CHARPOS, assuming it is
SETUP_BUFFER_SYNTAX_TABLE (void)
{
gl_state.use_global = false;
+ gl_state.e_property_truncated = false;
gl_state.current_syntax_table = BVAR (current_buffer, syntax_table);
}