Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs htmlize in batch mode?

Tags:

emacs

clojure

I like to use htmlize-file in emacs to turn clojure source files into html.

I want to use it from the linux command line instead, or programmatically from clojure itself.

I tried

$ emacs --eval "(htmlize-file \"/home/john/file.clj\" ) (kill-emacs)"

and

$ emacs -batch --eval "(htmlize-file \"/home/john/file.clj\" )"

Both work, with caveats.

The first opens an X-window, which seems a bit inelegant, but it does do exactly the same highlighting that I'd see in a buffer, which is what I want.

The second one works in batch mode, but the only syntax highlighting that it does is to italicize the strings. I hypothesise that it's not loading clojure-mode or my favourite colour scheme.

Can anyone find a way of getting the second version to give the same results as the first? They both seem to load my .emacs file before evaling the (htmli....) bit.

Also, is there any way to send the commands to an already running emacs? And thus save the startup time?

like image 873
John Lawrence Aspden Avatar asked Aug 28 '10 15:08

John Lawrence Aspden


3 Answers

Does using the first one with -nw work? that should prevent an X window being opened, but there should still be enough of the 'GUI' part of emacs present to be able to initialise the faces system. It's still not as elegant as -batch (it'll fail if run from a non-terminal process, eg crontab) but it'll be less irritating.

like image 110
NikkiA Avatar answered Nov 08 '22 12:11

NikkiA


emacsclient -e "(htmlize-file \"/home/john/file.clj\" )" -a ""

like image 29
jfs Avatar answered Nov 08 '22 12:11

jfs


I can't give you an ideal answer yet (I'm going to go do some research on this), but I have read that when invoked in batch mode, Emacs ignores display-specific commands like font-lock coloring. This makes execution of any script that uses display properties (like htmlize) problematic from batch mode.

I'm actually fairly interested in modifying htmlize at some point to allow color themes to be passed to it rather than using the current theme; what looks good in my Emacs session won't necessarily look good exported to HTML. For example, I tend to use blipp-blopp for htmlize, but I use midnight, comidia or charcoal while coding. I'm speculating that if htmlize could accept a color-theme specification directly, it might be able to avoid examining current font-lock properties and would then work from batch mode.

Sorry I couldn't be more helpful.

like image 23
R. P. Dillon Avatar answered Nov 08 '22 11:11

R. P. Dillon