Next: Parser State, Previous: Motion via Parsing, Up: Parsing Expressions
For syntactic analysis, such as in indentation, often the useful thing is to compute the syntactic state corresponding to a given buffer position. This function does that conveniently.
This function returns the parser state that the parser would reach at position pos starting from the beginning of the buffer. See Parser State, for a description of the parser state.
The return value is the same as if you call the low-level parsing function
parse-partial-sexp
to parse from the beginning of the buffer to pos (see Low-Level Parsing). However,syntax-ppss
uses a cache to speed up the computation. Due to this optimization, the second value (previous complete subexpression) and sixth value (minimum parenthesis depth) in the returned parser state are not meaningful.This function has a side effect: it adds a buffer-local entry to
before-change-functions
(see Change Hooks) forsyntax-ppss-flush-cache
(see below). This entry keeps the cache consistent as the buffer is modified. However, the cache might not be updated ifsyntax-ppss
is called whilebefore-change-functions
is temporarily let-bound, or if the buffer is modified without running the hook, such as when usinginhibit-modification-hooks
. In those cases, it is necessary to callsyntax-ppss-flush-cache
explicitly.
This function flushes the cache used by
syntax-ppss
, starting at position beg. The remaining arguments, ignored-args, are ignored; this function accepts them so that it can be directly used on hooks such asbefore-change-functions
(see Change Hooks).
Major modes can make syntax-ppss
run faster by specifying
where it needs to start parsing.
If this is non-
nil
, it should be a function that moves to an earlier buffer position where the parser state is equivalent tonil
—in other words, a position outside of any comment, string, or parenthesis.syntax-ppss
uses it to further optimize its computations, when the cache gives no help.