Take the 2-minute tour ×

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


$ 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?

share|improve this question
add comment

4 Answers

up vote 3 down vote accepted

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.

share|improve this answer
Perfect! Thank you. –  John Lawrence Aspden Sep 5 '10 at 21:28
add comment

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

share|improve this answer
I'd like to accept this answer as well, since it answers the subsidiary question! I can vote it up at least. Thank you. –  John Lawrence Aspden Sep 5 '10 at 21:29
add comment

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.

share|improve this answer
Oh well, the things above work. Thanks for taking the trouble! –  John Lawrence Aspden Aug 28 '10 at 18:11
add comment

The following Elisp code tells Htmlize to emit CSS class names instead of raw styles.

(setq org-export-htmlize-output-type 'css)

Then you can add CSS to your HTML file to get whatever colors you want. This works with Emacs in batch mode.

share|improve this answer
add comment

Your Answer


