Emacs htmlize in batch mode?

后端 未结 5 509
栀梦
栀梦 2021-02-06 08:50

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

相关标签:
5条回答
  • 2021-02-06 09:34

    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.

    0 讨论(0)
  • 2021-02-06 09:42

    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)))
    
    0 讨论(0)
  • 2021-02-06 09:43

    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.

    0 讨论(0)
  • 2021-02-06 09:49

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

    0 讨论(0)
  • 2021-02-06 09:57

    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.

    0 讨论(0)
提交回复
热议问题