emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Patch] [Feature request] Add option to natively fontify latex snippets and environment
@ 2019-01-02 22:52 Carlos Pita
  2019-01-03 15:34 ` Carlos Pita
  0 siblings, 1 reply; 5+ messages in thread
From: Carlos Pita @ 2019-01-02 22:52 UTC (permalink / raw)
  To: emacs-orgmode

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

This patch adds a fourth 'native value to
org-highlight-latex-and-related. It matches the same structures than
'latex but it calls org-src-font-lock-fontify-block instead.

It's a simple change that brings full latex fontification by building
on top of org-src. I'm using it (implemented as an advice) since a few
weeks ago and haven't noticed any problem.

Hope you like the idea.

Best regards
--
Carlos

[-- Attachment #2: 0001-Add-option-to-natively-fontify-latex-snippets-and-en.patch --]
[-- Type: text/x-patch, Size: 2859 bytes --]

From 3dbbf0f9c04003a5a0f0027c581a2ed6aa9fb892 Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
Date: Wed, 2 Jan 2019 19:43:21 -0300
Subject: [PATCH] Add option to natively fontify latex snippets and
 environments

---
 lisp/org.el | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 2e63a65..3c9a5dc 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4138,6 +4138,7 @@ org-level-* faces."
   "Non-nil means highlight LaTeX related syntax in the buffer.
 When non nil, the value should be a list containing any of the
 following symbols:
+  `native'   Highlight LaTeX snippets and environments natively.
   `latex'    Highlight LaTeX snippets and environments.
   `script'   Highlight subscript and superscript.
   `entities' Highlight entities."
@@ -4147,6 +4148,7 @@ following symbols:
   :type '(choice
 	  (const :tag "No highlighting" nil)
 	  (set :greedy t :tag "Highlight"
+	       (const :tag "LaTeX snippets and environments (native)" native)
 	       (const :tag "LaTeX snippets and environments" latex)
 	       (const :tag "Subscript and superscript" script)
 	       (const :tag "Entities" entities))))
@@ -6093,7 +6095,8 @@ Result depends on variable `org-highlight-latex-and-related'."
 		(list org-match-substring-with-braces-regexp))
 	       (org-use-sub-superscripts (list org-match-substring-regexp))))
 	(re-latex
-	 (when (memq 'latex org-highlight-latex-and-related)
+	 (when (or (memq 'latex org-highlight-latex-and-related)
+		   (memq 'native org-highlight-latex-and-related))
 	   (let ((matchers (plist-get org-format-latex-options :matchers)))
 	     (delq nil
 		   (mapcar (lambda (x)
@@ -6117,17 +6120,20 @@ highlighting was done, nil otherwise."
       (while (re-search-forward org-latex-and-related-regexp
 				nil t) ;; on purpose, we ignore LIMIT
 	(unless (cl-some (lambda (f) (memq f '(org-code org-verbatim underline
-						   org-special-keyword)))
+							org-special-keyword)))
 			 (save-excursion
 			   (goto-char (1+ (match-beginning 0)))
 			   (face-at-point nil t)))
-	  (let ((offset (if (memq (char-after (1+ (match-beginning 0)))
-				  '(?_ ?^))
-			    1
-			  0)))
-	    (font-lock-prepend-text-property
-	     (+ offset (match-beginning 0)) (match-end 0)
-	     'face 'org-latex-and-related)
+	  (let* ((offset (if (memq (char-after (1+ (match-beginning 0)))
+				   '(?_ ?^))
+			     1
+			   0))
+		 (start (+ offset (match-beginning 0)))
+		 (end (match-end 0)))
+	    (if (memq 'native org-highlight-latex-and-related)
+		(org-src-font-lock-fontify-block "latex" start end)
+	      (font-lock-prepend-text-property start end
+					       'face 'org-latex-and-related))
 	    (add-text-properties (+ offset (match-beginning 0)) (match-end 0)
 				 '(font-lock-multiline t)))
 	  (throw 'found t)))
-- 
2.19.2


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

* Re: [Patch] [Feature request] Add option to natively fontify latex snippets and environment
  2019-01-02 22:52 [Patch] [Feature request] Add option to natively fontify latex snippets and environment Carlos Pita
@ 2019-01-03 15:34 ` Carlos Pita
  2019-01-04 13:22   ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Carlos Pita @ 2019-01-03 15:34 UTC (permalink / raw)
  To: emacs-orgmode

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

I've improved the commit message to better align org mode conventions
and also added a note to ORG-NEWS about the new feature.

[-- Attachment #2: 0001-Add-option-to-natively-fontify-LaTeX-snippets-and-en.patch --]
[-- Type: text/x-patch, Size: 3782 bytes --]

From 19d1d83901d3cc4444959b0cef5d2832da307e01 Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
Date: Wed, 2 Jan 2019 19:43:21 -0300
Subject: [PATCH] Add option to natively fontify LaTeX snippets and
 environments

* lisp/org.el: add a 'native value to org-highlight-latex-and-related
  that allows to use tex native font locking by means of
  org-src-font-lock-fontify-block.
* etc/ORG-NEWS: add note about new feature.
---
 etc/ORG-NEWS |  5 +++++
 lisp/org.el  | 24 +++++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c1e426c..51d6a07 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -99,6 +99,11 @@ system than the main Org document.  For example:
 *** New cell movement functions in tables
 ~S-<UP>~, ~S-<DOWN>~, ~S-<RIGHT>~, and ~S-<LEFT>~ now move cells in
 the corresponding direction by swapping with the adjacent cell.
+*** New option to natively fontify LaTeX snippets and environments
+A 'native option was added to org-highlight-latex-and-related. It
+matches the same structures than 'latex but it calls
+org-src-font-lock-fontify-block instead, thus bringing about full
+LaTeX font locking.
 
 ** New functions
 *** ~org-dynamic-block-insert-dblock~
diff --git a/lisp/org.el b/lisp/org.el
index 2e63a65..3c9a5dc 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4138,6 +4138,7 @@ org-level-* faces."
   "Non-nil means highlight LaTeX related syntax in the buffer.
 When non nil, the value should be a list containing any of the
 following symbols:
+  `native'   Highlight LaTeX snippets and environments natively.
   `latex'    Highlight LaTeX snippets and environments.
   `script'   Highlight subscript and superscript.
   `entities' Highlight entities."
@@ -4147,6 +4148,7 @@ following symbols:
   :type '(choice
 	  (const :tag "No highlighting" nil)
 	  (set :greedy t :tag "Highlight"
+	       (const :tag "LaTeX snippets and environments (native)" native)
 	       (const :tag "LaTeX snippets and environments" latex)
 	       (const :tag "Subscript and superscript" script)
 	       (const :tag "Entities" entities))))
@@ -6093,7 +6095,8 @@ Result depends on variable `org-highlight-latex-and-related'."
 		(list org-match-substring-with-braces-regexp))
 	       (org-use-sub-superscripts (list org-match-substring-regexp))))
 	(re-latex
-	 (when (memq 'latex org-highlight-latex-and-related)
+	 (when (or (memq 'latex org-highlight-latex-and-related)
+		   (memq 'native org-highlight-latex-and-related))
 	   (let ((matchers (plist-get org-format-latex-options :matchers)))
 	     (delq nil
 		   (mapcar (lambda (x)
@@ -6117,17 +6120,20 @@ highlighting was done, nil otherwise."
       (while (re-search-forward org-latex-and-related-regexp
 				nil t) ;; on purpose, we ignore LIMIT
 	(unless (cl-some (lambda (f) (memq f '(org-code org-verbatim underline
-						   org-special-keyword)))
+							org-special-keyword)))
 			 (save-excursion
 			   (goto-char (1+ (match-beginning 0)))
 			   (face-at-point nil t)))
-	  (let ((offset (if (memq (char-after (1+ (match-beginning 0)))
-				  '(?_ ?^))
-			    1
-			  0)))
-	    (font-lock-prepend-text-property
-	     (+ offset (match-beginning 0)) (match-end 0)
-	     'face 'org-latex-and-related)
+	  (let* ((offset (if (memq (char-after (1+ (match-beginning 0)))
+				   '(?_ ?^))
+			     1
+			   0))
+		 (start (+ offset (match-beginning 0)))
+		 (end (match-end 0)))
+	    (if (memq 'native org-highlight-latex-and-related)
+		(org-src-font-lock-fontify-block "latex" start end)
+	      (font-lock-prepend-text-property start end
+					       'face 'org-latex-and-related))
 	    (add-text-properties (+ offset (match-beginning 0)) (match-end 0)
 				 '(font-lock-multiline t)))
 	  (throw 'found t)))
-- 
2.20.1


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

* Re: [Patch] [Feature request] Add option to natively fontify latex snippets and environment
  2019-01-03 15:34 ` Carlos Pita
@ 2019-01-04 13:22   ` Nicolas Goaziou
  2019-01-14 18:10     ` Carlos Pita
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2019-01-04 13:22 UTC (permalink / raw)
  To: Carlos Pita; +Cc: emacs-orgmode

Hello,

Carlos Pita <carlosjosepita@gmail.com> writes:

> I've improved the commit message to better align org mode conventions
> and also added a note to ORG-NEWS about the new feature.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

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

* Re: [Patch] [Feature request] Add option to natively fontify latex snippets and environment
  2019-01-04 13:22   ` Nicolas Goaziou
@ 2019-01-14 18:10     ` Carlos Pita
  2019-01-15  2:23       ` stardiviner
  0 siblings, 1 reply; 5+ messages in thread
From: Carlos Pita @ 2019-01-14 18:10 UTC (permalink / raw)
  To: Carlos Pita, emacs-orgmode

Hi Nicolas,

I was thinking that maybe it would be nicer to make this depend on the
value of org-src-fontify-natively. What do you think?

Regards
--
Carlos

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

* Re: [Patch] [Feature request] Add option to natively fontify latex snippets and environment
  2019-01-14 18:10     ` Carlos Pita
@ 2019-01-15  2:23       ` stardiviner
  0 siblings, 0 replies; 5+ messages in thread
From: stardiviner @ 2019-01-15  2:23 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Carlos Pita


Carlos Pita <carlosjosepita@gmail.com> writes:

> Hi Nicolas,
>
> I was thinking that maybe it would be nicer to make this depend on the
> value of org-src-fontify-natively. What do you think?
>
> Regards

I don't think so. BTW, I found this patch cause my Org Mode buffer
fontify error.

After some raw latex block, all following fontify wrong. This is
happened when I use latest master branch a few days ago. I disable the
option to disable this fontify. I have `org-src-fontify-natively`
enabled by default. It might cause my Org Mode buffer fontify failed
again.

At least, I think this patch should need more test.

--
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

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

end of thread, other threads:[~2019-01-15  2:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-02 22:52 [Patch] [Feature request] Add option to natively fontify latex snippets and environment Carlos Pita
2019-01-03 15:34 ` Carlos Pita
2019-01-04 13:22   ` Nicolas Goaziou
2019-01-14 18:10     ` Carlos Pita
2019-01-15  2:23       ` stardiviner

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