emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carlos Pita <carlosjosepita@gmail.com>
To: emacs-orgmode@gnu.org
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: Fri, 21 Dec 2018 23:38:35 -0300	[thread overview]
Message-ID: <CAELgYhfF849mLfrYZ8bO8WcAj7H7W3h+gJLeCSSY_iAnABZhaw@mail.gmail.com> (raw)
In-Reply-To: <CAELgYhfQYSN7C96-feO6x=v4-d2HESePTqW5bcHjUy7oBRgMoQ@mail.gmail.com>

Nicolas, I have modified org-fontify-meta-lines-and-blocks-1 following
your approach:

@@ -5991,6 +5991,13 @@ by a #."
         (dc3 (downcase (match-string 3)))
         end end1 quoting block-type)
     (cond
+     ((and (match-end 4) (equal dc3 "+end"))
+          (save-match-data
+            (save-excursion
+              (when (re-search-backward
+                     (concat "^[ \t]*#\\+begin" (match-string 4) "\\>.*")
+                     nil t)  ;; on purpose, we look further than LIMIT
+                (org-fontify-meta-lines-and-blocks-1 limit)))))
      ((and (match-end 4) (equal dc3 "+begin"))
       ;; Truly a block
       (setq block-type (downcase (match-string 5))

Nevertheless I'm not quite satisfied. If you play a bit with opening
and ending delimiters and moving around the buffer you will quite
easily find border cases in which the block is indeed recognized and
properties adequately set but still font locking is only partially
refreshed until you scroll, move to another buffer, etc.

I tried any combination of save-match-data and save-excursion wrapping
the recursive call, even without any of them, to no avail.

What I think it's happening here is that ignoring the limit forwards
could be a tolerable trick, but when you start jumping forward and
backwards in you fontification function, font-lock routines lose track
of what is meant to be refreshed; and if, instead, you save everything
before jumping around it's like nothing or too little have been
refontified from the point of view of the framework.

I still believe that explicitly extending the region is a saner
approach, it's the documented one at least. Maybe you could rewrite my
function in a better way using the precomputed latex regexps and
augmenting them with #+BEGIN/END counterparts. That still relies on
ignoring limits in the font locking function but from a cursory
inspection I understand the framework is quite robust when you move
the point further than allowed. Also, as I've said before, some border
cases remain when the block is too large (larger than the jit chunk)
and you break the ending delimiter, but nothing to worry about.

Best regards
--
Carlos

  reply	other threads:[~2018-12-22  2:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27 22:32 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/)] Carlos Pita
2018-11-27 22:58 ` Carlos Pita
2018-11-27 23:49   ` Nicolas Goaziou
2018-11-28  0:14     ` Carlos Pita
2018-11-28  0:27       ` Carlos Pita
2018-11-28  1:22         ` Carlos Pita
2018-11-28 10:57       ` Nicolas Goaziou
2018-11-28 15:02         ` Carlos Pita
2018-11-28 16:55           ` Carlos Pita
2018-11-28 17:28             ` Carlos Pita
2018-11-28 18:38               ` Carlos Pita
2018-11-28 22:46                 ` Carlos Pita
2018-12-03  3:54                   ` Carlos Pita
2018-12-03  4:18                     ` Carlos Pita
2018-12-19 21:42                       ` Nicolas Goaziou
2018-12-21 23:37                         ` Carlos Pita
2018-12-21 23:54                           ` Carlos Pita
2018-12-22  0:42                             ` Carlos Pita
2018-12-22  0:46                               ` Carlos Pita
2018-12-22  2:38                                 ` Carlos Pita [this message]
2018-12-22  8:21                                   ` Nicolas Goaziou
2018-12-22 13:16                                     ` Carlos Pita
2018-12-22 15:07                                       ` Carlos Pita
2019-01-01 16:46                                         ` Nicolas Goaziou
2019-01-01 17:11                                           ` Carlos Pita
2019-01-01 17:14                                             ` Carlos Pita
2019-01-01 18:17                                             ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAELgYhfF849mLfrYZ8bO8WcAj7H7W3h+gJLeCSSY_iAnABZhaw@mail.gmail.com \
    --to=carlosjosepita@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).