Here is a patch on top of latest revision. It just adds an extension function while initializing font locking, as documented in [1]. It indeed reduces lines of code to some extent by moving the dirty stuff out of the fontification function (but I tried to keep the code formatting of your last commit, since it was rather different than the one shipped with emacs). The approach is more robust AFAICS since the font locking framework is correctly informed of which blocks should be refontified before fontification itself happens. It covers all types of blocks: #+BEGIN/#+END, \begin\end, \[\]. It's not a full parser but at least it matches corresponding delimiters by type by using a simple heuristic. Of course, I cannot ensure that it's bug free but I was *really* using and improving this for a couple of weeks now and I can say it does the job. If you want me to change anything just let me know, I will have some time for this for the next few days. Best regards -- Carlos --- [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Multiline-Font-Lock.html