Emacs htmlize in batch mode?

I like to use the htmlize file in emacs to convert clojure source files to html.

I want to use it from the linux command line 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 reservations.

First, an X window opens, which seems a little inelegant, but it makes the same selection that I see in the buffer, and that is what I want.

The second works in batch mode, but the only syntax highlighting it does is italic strings. I assume that it does not load the clojure mod or my favorite color scheme.

Can someone find a way to get the second version to give the same results as the first? It seems like they both upload my .emacs file before guessing the bit (htmli ....).

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

+6
emacs clojure
source share
5 answers

Is the first used with -nw? which should prevent the X window from opening, but there should be enough of the "GUI" of the emacs present to be able to initialize the face system. It is still not as elegant as -batch (it will fail to start from a nonterminal process like crontab), but it will be less annoying.

+4
source share

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

+5
source share

I still can’t give you the perfect answer (I'm going to do some research on this), but I read that when called in batch mode, Emacs ignores the commands to display, such as font coloring. This makes the execution of any script that uses display properties (e.g. htmlize) problematic from batch mode.

I'm actually quite interested in modifying htmlize at some point to allow color themes to convey it, rather than using the current theme; what looks good in my Emacs session will not necessarily be well exported to HTML. For example, I use blipp-blopp for htmlize, but when coding, I use midnight, comedy or charcoal. I assume that if htmlize can directly accept the color theme specification, perhaps this will avoid learning about the current font blocking properties and then work from batch mode.

Sorry, I could not be more helpful.

+4
source share

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

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

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

+1
source share

There is an example of using 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))) 
+1
source share

All Articles