After this change, rainbow-delimiters--apply-color just calls
rainbow-delimiters--propertize-delimiter, so remove it and rename
the latter to the former.
Important note: this is a *performance optimization only*, yielding
a very easy 10%-15% gain. The code is supposed to work with *both*
dynamic and lexical binding.
The reason we had our own implementation was to avoid
`syntax-begin-function`, which may break the assumption we rely on that
`syntax-ppss` is exactly equivalent to `parse-partial-sexp` from
`point-min`.
Instead of rolling our own, use the standard one, with
`syntax-begin-function` set to nil.
Instead of setting rainbow-delimiters--parse-partial-sexp-cache to nil
when turning on, kill the local binding when turning off. This allows
the GC to collect the old value immediately after the mode is turned off,
instead of when the buffer is killed or the mode is turned on again.
So far, we assumed that [] () {} are always the delimiters, and the only
delimiters, we want to highlight. But this is not true. For example, in
Pascal, {} are comment delimiters, and in C++, <> serve as brackets
in template syntax. The respective major modes get this right, we don't,
so rely on them. Code simplification is an added benefit.
Note: currently it's probably buggy and certainly incomplete. For example,
it doesn't respect rainbow-delimiters-highlight-TYPE-p yet.
The PPSS cache can never be inserted into in the middle, so testing whether
to insert into the middle is unnecessary.
rainbow-delimiters-syntax-ppss-run adds all the intermediate results
to the front of the cache, so it always leaves the cache in a state where
the elements are always exactly
rainbow-delimiters-parse-partial-sexp-cache-max-span apart, so there's no
gap bigger than rainbow-delimiters-parse-partial-sexp-cache-max-span to
insert into.
The before change hook always removes all elements until before the point
of the change, leaving no gap either.
The only way for a gap bigger than
rainbow-delimiters-parse-partial-sexp-cache-max-span to arise is the user
changing that variable, but that variable an implementation detail, so
worrying about it changing is like worrying about
(fset #'rainbow-delimiters-syntax-ppss-run #'ignore).
All in all, it serves only to make the code more complicated. So remove it.
Generalized variables are supported in push only since Emacs 24.3,
using primitive operations instead allows the code to work in older
versions, too.
The regression was introduced in 3dfd3fa9b1, fixes#46.
`rainbow-delimiters-mode' may be restored via desktop.el. When this
happens inside an `mmm-mode' buffer, the subregion-specific values of
the syntax table will not be restored, and so
`rainbow-delimiters-syntax-table' can be nil. We handle this case by
skipping propertization if the syntax table is unset.
Closes https://github.com/purcell/emacs.d/issues/209