2010-08-28 81 views
6

我喜欢在emacs中使用htmlize-file将clojure源文件转换为html。批处理模式下的Emacs htmlize?

我想用它从linux命令行代替,或从clojure本身编程。

我试图

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

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

两个工作,注意事项。

第一次打开一个X窗口,这看起来有点不雅,但它确实做了与我在缓冲区中看到的完全相同的突出显示,这正是我想要的。

第二个以批处理模式工作,但突出显示的唯一语法是斜体字符串。我假设它没有加载clojure模式或我最喜欢的配色方案。

任何人都可以找到一种方法让第二个版本给出与第一个相同的结果吗? 他们似乎都在评估(htmli ....)位之前加载我的.emacs文件。

此外,有没有办法将命令发送到已经运行的emacs?从而节省启动时间?

回答

4

是否使用第一个与-nw工作?这应该阻止打开X窗口,但是仍然应该有足够的emacs的'GUI'部分来初始化faces系统。它仍然不如批处理(如果从非终端进程运行,它会失败,例如crontab),但它不会太刺激。

+0

完美!谢谢。 – 2010-09-05 21:28:47

4

我还不能给你一个理想的答案(我要去做一些研究),但我已经读过,当在批处理模式下调用时,Emacs会忽略特定于显示的命令,如字体锁着色。这使得执行任何使用显示属性(如htmlize)的脚本在批处理模式下有问题。

我其实很想修改htmlize,以允许颜色主题传递给它而不是使用当前主题;在我的Emacs会话中看起来不错的东西不一定看起来好导出到HTML。例如,我倾向于将blipp-blopp用于htmlize,但我在编码时使用午夜,comidia或木炭。我在猜测,如果htmlize可以直接接受颜色主题规范,它可能可以避免检查当前的字体锁定属性,然后可以从批处理模式工作。

对不起,我不能更有帮助。

+0

哦,这个事情上面工作中使用htmlize一个例子。感谢您的麻烦! – 2010-08-28 18:11:21

5

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

+0

我也想接受这个答案,因为它回答了子问题!我至少可以投票。谢谢。 – 2010-09-05 21:29:54

1

以下Elisp代码告诉Htmlize发出CSS类名而不是原始样式。

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

然后,您可以添加CSS到您的HTML文件,以获得任何你想要的颜色。这适用于批处理模式下的Emacs。

1

有一个在--batch模式

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