emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex-and-related faces
@ 2021-03-19 16:56 Sébastien Miquel
  2021-03-25  4:26 ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Sébastien Miquel @ 2021-03-19 16:56 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

Hi,

With the current org-do-latex-and-related function, fontification of
a region before a LaTeX fragment repeatedly adds the
'org-latex-and-related face to the fragment.

You can reproduce with an org buffer with the following content.

#+BEGIN_SRC org
Foo
  $a^2 + b^2 = c^2$
#+END_SRC

  - Use (setq org-highlight-latex-and-related '(latex))
  - Write some text at the end of the first line, triggering
    refonfication of the line
  - For each character inserted, the org-latex-and-related face is
    added (as a duplicate) to the fragment, as you can check using
    describe-text-properties.

The attached patch fixes this.

-- 
Sébastien Miquel


[-- Attachment #2: 0001-org.el-org-do-latex-and-related-Fix-duplicate-latex-.patch --]
[-- Type: text/x-patch, Size: 899 bytes --]

From ccce24e08b903e0e955a6b22f6c7321851ec5750 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miquel@posteo.eu>
Date: Fri, 19 Mar 2021 16:55:27 +0100
Subject: [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex faces

* lisp/org.el (org-do-latex-and-related): Do not add a
'org-latex-and-related face beyond the fontification limit
---
 lisp/org.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index 4db2dbe04..a0c703630 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5502,6 +5502,8 @@ highlighting was done, nil otherwise."
 	(while (and (< (point) limit)
 		    (re-search-forward org-latex-and-related-regexp nil t))
 	  (cond
+           ((>= (match-beginning 0) limit)
+	    (throw 'found nil))
 	   ((cl-some (lambda (f)
 		       (memq f '(org-code org-verbatim underline
 					  org-special-keyword)))
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex-and-related faces
  2021-03-19 16:56 [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex-and-related faces Sébastien Miquel
@ 2021-03-25  4:26 ` Kyle Meyer
  2021-03-25  7:09   ` Sébastien Miquel
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2021-03-25  4:26 UTC (permalink / raw)
  To: sebastien.miquel; +Cc: emacs-orgmode

Sébastien Miquel writes:

> With the current org-do-latex-and-related function, fontification of
> a region before a LaTeX fragment repeatedly adds the
> 'org-latex-and-related face to the fragment.
>
> You can reproduce with an org buffer with the following content.
[...]
> The attached patch fixes this.

Thanks for the clear reproduction steps and for the patch.

> Subject: [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex faces
>
> * lisp/org.el (org-do-latex-and-related): Do not add a
> 'org-latex-and-related face beyond the fontification limit

Please add a period after the changelog entry.

  https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html

> ---
>  lisp/org.el | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lisp/org.el b/lisp/org.el
> index 4db2dbe04..a0c703630 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -5502,6 +5502,8 @@ highlighting was done, nil otherwise."
>  	(while (and (< (point) limit)
>  		    (re-search-forward org-latex-and-related-regexp nil t))
>  	  (cond
> +           ((>= (match-beginning 0) limit)
> +	    (throw 'found nil))

Any reason not to pass limit as re-search-forward's BOUND instead?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex-and-related faces
  2021-03-25  4:26 ` Kyle Meyer
@ 2021-03-25  7:09   ` Sébastien Miquel
  2021-03-27  6:07     ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Sébastien Miquel @ 2021-03-25  7:09 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1057 bytes --]

Kyle Meyer writes:

 > Please add a period after the changelog entry.

Done.

 > Any reason not to pass limit as re-search-forward's BOUND instead?

I've looked at the history of this code, and some earlier comment
indicated that limit was ignored on purpose.

The only case where it'd make a difference with my patch is when limit
is in the middle of a latex fragment (since re-search-forward's BOUND
bounds the end of the match).

Now, AFAIU, this should almost never happen, since the fontified
region is extended
  + according to the font-lock-multiline text property, that latex
    fragment do have
  + and to contain matching begin/end delimiters.

I can think of a few edge cases where it may make a difference :
  - If you write a multiline fragment, and add $ delimiters
    afterwards, starting with the closing one. Then when you add the
    opening one, you wouldn't get fontification, I think
  - If you add an empty line in a multiline $ fragment by mistake, which
    breaks fontification, then remove it

-- 
Sébastien Miquel


[-- Attachment #2: 0001-org.el-org-do-latex-and-related-Fix-duplicate-latex-.patch --]
[-- Type: text/x-patch, Size: 900 bytes --]

From 7fb4e2d408791742281bf220d227ccdcfd5baa71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miquel@posteo.eu>
Date: Fri, 19 Mar 2021 16:55:27 +0100
Subject: [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex faces

* lisp/org.el (org-do-latex-and-related): Do not add a
'org-latex-and-related face beyond the fontification limit.
---
 lisp/org.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index 4db2dbe04..a0c703630 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5502,6 +5502,8 @@ highlighting was done, nil otherwise."
 	(while (and (< (point) limit)
 		    (re-search-forward org-latex-and-related-regexp nil t))
 	  (cond
+           ((>= (match-beginning 0) limit)
+	    (throw 'found nil))
 	   ((cl-some (lambda (f)
 		       (memq f '(org-code org-verbatim underline
 					  org-special-keyword)))
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex-and-related faces
  2021-03-25  7:09   ` Sébastien Miquel
@ 2021-03-27  6:07     ` Kyle Meyer
  0 siblings, 0 replies; 4+ messages in thread
From: Kyle Meyer @ 2021-03-27  6:07 UTC (permalink / raw)
  To: sebastien.miquel; +Cc: emacs-orgmode

Sébastien Miquel writes:

> I've looked at the history of this code, and some earlier comment
> indicated that limit was ignored on purpose.

Thanks for digging.  LIMIT was dropped from the re-search-forward call
in 80268c0e0 (Fix fontification of LaTeX environments, 2019-01-01), with
the addition of the now-removed comment you mention.

The related thread is
https://orgmode.org/list/CAELgYhdcW1XnR7BTmos6vAF_YPJ4Wdp=3FEAhBEYfeA4B2nvSw@mail.gmail.com/T/#u

I'm not sure about that change, but either way I think it's a good
reason to stick with your proposed approach.  Pushed (36622362d).

Thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-27  6:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-19 16:56 [PATCH] org.el (org-do-latex-and-related): Fix duplicate 'latex-and-related faces Sébastien Miquel
2021-03-25  4:26 ` Kyle Meyer
2021-03-25  7:09   ` Sébastien Miquel
2021-03-27  6:07     ` Kyle Meyer

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).