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
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.
There is a example to use htmlize in --batch
mode
http://sebastien.kirche.free.fr/emacs_stuff/elisp/my-htmlize.el
;; Make sure the the htmlize library is in load-path.
;; You might want to load ~/.emacs
;; USAGE:
;; emacs -batch -l my-htmlize.el INFILE > OUTFILE
;; Example:
(custom-set-faces
'(default ((t (:foreground "#ffffff" :background "black"))))
'(font-lock-builtin-face ((t (:foreground "#ff0000"))))
'(font-lock-comment-face ((t (:bold t :foreground "#333300"))))
'(font-lock-constant-face ((t (:foreground "magenta"))))
'(font-lock-function-name-face ((t (:bold t :foreground "Blue"))))
'(font-lock-keyword-face ((t (:foreground "yellow3"))))
'(font-lock-string-face ((t (:foreground "light blue"))))
'(font-lock-type-face ((t (:foreground "green"))))
'(font-lock-variable-name-face ((t (:foreground "cyan" :bold t))))
'(font-lock-warning-face ((t (:foreground "red" :weight bold)))))
(setq htmlize-use-rgb-map 'force)
(require 'htmlize)
(find-file (pop command-line-args-left))
(font-lock-fontify-buffer)
(with-current-buffer (htmlize-buffer)
(princ (buffer-string)))
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.
emacsclient -e "(htmlize-file \"/home/john/file.clj\" )" -a ""
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.