From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlos Pita Subject: Re: Bug: Add option to fontify latex blocks [9.1.9 (release_9.1.9-65-g5e4542 @ /home/carlos/local/stow/emacs-26/share/emacs/26.1.50/lisp/org/)] Date: Sat, 22 Dec 2018 12:07:08 -0300 Message-ID: References: <87h8g2kv81.fsf@gmail.com> <87lg5ershk.fsf@nicolasgoaziou.fr> <87d0qpsc4g.fsf@nicolasgoaziou.fr> <87woo5xkgf.fsf@nicolasgoaziou.fr> <87k1k2ynsh.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0000000000006806bf057d9db8e5" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gais7-00073n-K3 for emacs-orgmode@gnu.org; Sat, 22 Dec 2018 10:07:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gais6-00043H-5h for emacs-orgmode@gnu.org; Sat, 22 Dec 2018 10:07:23 -0500 Received: from mail-yw1-xc36.google.com ([2607:f8b0:4864:20::c36]:42917) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gais5-00041N-V1 for emacs-orgmode@gnu.org; Sat, 22 Dec 2018 10:07:22 -0500 Received: by mail-yw1-xc36.google.com with SMTP id x2so3313426ywc.9 for ; Sat, 22 Dec 2018 07:07:21 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --0000000000006806bf057d9db8e5 Content-Type: text/plain; charset="UTF-8" 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 --0000000000006806bf057d9db8e5 Content-Type: text/x-patch; charset="US-ASCII"; name="region-extend.patch" Content-Disposition: attachment; filename="region-extend.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jpzlhyoj0 ZGlmZiAtLWdpdCBhL2xpc3Avb3JnLmVsIGIvbGlzcC9vcmcuZWwKaW5kZXggNWRkNWMwMi4uMTE1 ZmE0ZCAxMDA2NDQKLS0tIGEvbGlzcC9vcmcuZWwKKysrIGIvbGlzcC9vcmcuZWwKQEAgLTYxMDIs NiArNjEwMiwyNCBAQCBieSBhICMuIgogCSAgICAoYWRkLXRleHQtcHJvcGVydGllcyBjbG9zaW5n LXN0YXJ0IGVuZCAnKGludmlzaWJsZSB0KSkpCiAJICB0KSkpKSkKIAorKGRlZnVuIG9yZy1mb250 aWZ5LWV4dGVuZC1yZWdpb24gKGJlZyBlbmQgX29sZC1sZW4pCisgIChsZXQgKChiZWdpbi1yZSAi XFwoXFxcXFxcW1xcfFxcKCNcXCtiZWdpbl9cXHxcXFxcYmVnaW57XFwpXFxTLStcXCkiKQorCShl bmQtcmUgIlxcKFxcXFxcXF1cXHxcXCgjXFwrZW5kX1xcfFxcXFxlbmR7XFwpXFxTLStcXCkiKQor CShleHRlbmQgKGxhbWJkYSAocjEgcjIgZGlyKQorCQkgIChsZXQgKChyZSAocmVwbGFjZS1yZWdl eHAtaW4tc3RyaW5nICJcXChiZWdpblxcfGVuZFxcKSIgcjEKKwkJCSAgICAgKHJlcG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