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: Mon, 3 Dec 2018 00:54:24 -0300 Message-ID: References: <87h8g2kv81.fsf@gmail.com> <87lg5ershk.fsf@nicolasgoaziou.fr> <87d0qpsc4g.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTfJe-0004m8-2B for emacs-orgmode@gnu.org; Sun, 02 Dec 2018 22:54:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTfJd-000118-9H for emacs-orgmode@gnu.org; Sun, 02 Dec 2018 22:54:37 -0500 Received: from mail-yw1-xc2a.google.com ([2607:f8b0:4864:20::c2a]:37940) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTfJd-000112-1y for emacs-orgmode@gnu.org; Sun, 02 Dec 2018 22:54:37 -0500 Received: by mail-yw1-xc2a.google.com with SMTP id i20so4846359ywc.5 for ; Sun, 02 Dec 2018 19:54:37 -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 Hi all, I've been adding some improvements to the region extension function (pasted below) in order to better support nesting, but anyway I'm convinced that the current approach to org-highlight-latex-and-related == '(latex) is hopeless except for small fragments and should be reworked or dropped or kept with a caveat. This is because it quite easily bumps into jit-lock-chunk-size (which is set at 500 by default). Multiline matchers, specially medium to large ones, are explicitly disadvised for a good reason. Once you have a larger chunk of latex no region extension function will do it. But immediately after you wrap the large latex environment inside a #+BEGIN/#+END pair the extension function becomes helpful again: this because the #+BEGIN/#+END matcher is incremental and eventually the region to refontify spans the entire extended region and the latex matcher is able to do its thing again. Anyway, here is the extension function: (defun my-org-extend-region (beg end old-len) (let ((begin-re "[\t ]*\\(#\\+BEGIN_\\|\\\\begin{\\)%s[ \t}]?") (end-re "[\t ]*\\(#\\+END_\\|\\\\end{\\)%s[ \t}]?") (name-re "\\([a-zA-Z0-9_\\*]+\\)") (extend (lambda (re pos dir) (let ((re (format re (regexp-quote (match-string 2))))) (or (re-search-forward re nil t dir) pos))))) (save-match-data (save-excursion (goto-char beg) (beginning-of-line) (if (looking-at (format end-re name-re)) (setq beg (funcall extend begin-re beg -1)) (when (looking-at (format begin-re name-re)) (setq end (funcall extend end-re end 1))))))) (message "%s--%s" beg end) (cons beg end)) Best regards -- Carlos