emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Code block syntax highlighting in async export


From: Ihor Radchenko
Subject: Re: Code block syntax highlighting in async export
Date: Tue, 04 Oct 2022 12:04:07 +0800

David Lukeš <dafydd.lukes@gmail.com> writes:

>> Could you please provide an example?
>
>> Certainly more details is necessary, even export format (backend) is not
>> specified.
>
> Sorry for that! I somehow thought that the issue would sound familiar
> to more seasoned Org users, and someone would come back with either
> "yeah, you need to do X" or "yeah, that's a known limitation".
>
> The export backend is HTML. In case anyone wants to try reproducing
> this, I made a minimal working example here:
> https://github.com/dlukes/org-html-a-sync-export-syntax-highlighting

Thanks for the easy reproducer!
I played around with the export there, and I think I have found the
cause.

As expected, the problem originates from batch mode of Emacs
operation.

ox-html relies upon htmlize-region -> htmlize-buffer-1 ->
htmlize-make-face-map -> htmlize-face-to-fstruct ->
htmlize-face-to-fstruct-1.

In synchronous export `htmlize-face-to-fstruct-1' returns:

font-lock-comment-face -> #s(htmlize-fstruct "#b22222" nil nil nil nil nil nil 
nil "org-comment")
font-lock-comment-delimiter-face -> #s(htmlize-fstruct "#b22222" nil nil nil 
nil nil nil nil "org-comment-delimiter")
font-lock-doc-face -> #s(htmlize-fstruct "#8b2252" nil nil nil nil nil nil nil 
"org-doc")
font-lock-keyword-face -> #s(htmlize-fstruct "#a020f0" nil nil nil nil nil nil 
nil "org-keyword")
font-lock-function-name-face -> #s(htmlize-fstruct "#0000ff" nil nil nil nil 
nil nil nil "org-function-name")

In asynchronous export:

default -> #s(htmlize-fstruct "#000000" "#ffffff" 1 nil nil nil nil nil 
"org-default")
font-lock-comment-face -> #s(htmlize-fstruct nil nil nil t t nil nil nil 
"org-comment")
font-lock-comment-delimiter-face -> #s(htmlize-fstruct nil nil nil t t nil nil 
nil "org-comment-delimiter")
font-lock-doc-face -> #s(htmlize-fstruct nil nil nil nil t nil nil nil 
"org-doc")
font-lock-keyword-face -> #s(htmlize-fstruct nil nil nil t nil nil nil nil 
"org-keyword")
font-lock-function-name-face -> #s(htmlize-fstruct nil nil nil t nil nil nil 
nil "org-function-name")

-----------------------------

What can we do on the Org side to fix the issue?

One way could be avoiding batch execution altogether, like in the
attached patch. However, it will break our process sentinel watching for
the export results. Moreover, I am not sure how it will work when export
is done from terminal Emacs. Also, I know no way to _not_ create an
extra Emacs frame during such export - I imagine that a new frame (even
minimized) might be annoying for the users.

Maybe we should request Emacs to add --graphical-batch mode feature that
will preserve graphical features while not interfering with the WM?

>From 8bc0a66275ca6ffdf142e8e2c2b38d79923531d8 Mon Sep 17 00:00:00 2001
Message-Id: 
<8bc0a66275ca6ffdf142e8e2c2b38d79923531d8.1664855997.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Tue, 4 Oct 2022 11:58:45 +0800
Subject: [PATCH] ox: Do not disable graphical Emacs capabilities during async
 export

* lisp/ox.el (org-export-async-start): Run Emacs in possibly iconized
window instead of batch mode.  This way, font colors can be processed
by htmlize during async export.
---
 lisp/ox.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 42204ffde..a31459632 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -6432,7 +6432,9 @@ (defun org-export-async-start  (fun body)
                     (funcall ',copy-fun)
                     (restore-buffer-modified-p nil)
                     ;; Sexp to evaluate in the buffer.
-                    (print ,body)))
+                    (print ,body)
+                    ;; Kill Emacs at the end.
+                    (kill-emacs 0)))
          nil temp-file nil 'silent))
       ;; Start external process.
       (let* ((process-connection-type nil)
@@ -6444,7 +6446,9 @@ (defun org-export-async-start  (fun body)
                (list "org-export-process"
                      proc-buffer
                      (expand-file-name invocation-name invocation-directory)
-                     "--batch")
+                     ;; "--batch"
+                      "--iconic"
+                      )
                (if org-export-async-init-file
                    (list "-Q" "-l" org-export-async-init-file)
                  (list "-l" user-init-file))
-- 
2.35.1


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

reply via email to

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