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?
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.
emacsclient -e "(htmlize-file \"/home/john/file.clj\" )" -a ""
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With