emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Bug: Add option to fontify latex blocks [9.1.9 (release_9.1.9-65


From: Carlos Pita
Subject: Re: [O] 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

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]