Emacs htmlize in batch mode? - emacs

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)"
and
$ 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?

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.

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

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.

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.

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

Related

orgmode - change code block background color

Below code will change html export background color to #eff0fe:
#+ATTR_HTML: :style background-color:#eff0fe;
#+BEGIN_EXAMPLE
hello world!
#+END_EXAMPLE
like below:
How can we change the background color when edit in emacs?
I saw Pretty fontification of source code blocks document but sounds like it doesn't work for me!
Another approach (which I think is more general) is explained in this page and I have copy-pasted the snippet here. It will only change the code block, and not the #+BEGIN, #+END, or #+RESULTS lines.
The example below will darken the code block by 3 percent (notice the number 3 at the last parameter) relative to the background color of your emacs theme. However, if you change your theme during editing the color of the code block will stay the same.
(require 'color)
(set-face-attribute 'org-block nil :background
(color-darken-name
(face-attribute 'default :background) 3))
Output using a light theme:
Output using a dark theme:
You can modify further the code block color for individual programming language. The example below will modify the code block color for emacs-lisp and python.
(setq org-src-block-faces '(("emacs-lisp" (:background "#EEE2FF"))
("python" (:background "#E5FFB8"))))
Sounds like some face name changed, below config works:
(custom-set-faces
'(org-block-begin-line
((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF" :extend t))))
'(org-block
((t (:background "#EFF0F1" :extend t))))
'(org-block-end-line
((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF" :extend t))))
)
Output:

Emacs colors. why it is gray on current line? zenburn theme

I installed Prelude on my emacs24. I'm using ubuntu 12.04
It worked perfectly the first time I used it, but all the next times it doesn't.
On my current line the font color is gray so it's hard to see what I write. Previously it was a Bold case, keeping any color the line had for reserved words.
How can I fix this?
or also the empty lines with spaces are all yellow
I've been trying to fix it on the:
~/.emacs.d/elpa/zenburn-theme-20130716.1457/zenburn-theme.el
file but I can't find a solution... I think the problem could be between this lines:
;;;;; hl-line-mode
`(hl-line-face ((,class (:background ,zenburn-bg-05))
(t :weight bold)))
`(hl-line ((,class (:background ,zenburn-bg-05)) ; old emacsen
(t :weight bold)))
Thanks!
You can change the background and foreground to whatever you want, or turn it off completely. You can add bold or underline or overline or slant, or whatever floats your boat. One of my very first projects was to take the settings from color-theme and put it into my .emacs file and I haven't used a specific color theme since. Oh, and of course you want to open your .emacs or init file to see if there are any settings that conflict with the color theme you are using.
(global-hl-line-mode 1) ;; highlight current line -- see hl-line.el
(custom-set-faces
'(highlight ((t (:background "grey80" :foreground "black" :bold t)))) ;; highlight current line
)
Important:
Add to .bashrc file:
export TERM=xterm-256color
and I found the perfect configuration for me. Here it goes:
;;;;; hl-line-mode
(custom-set-faces
'(highlight ((t (:background "grey20" :foreground nil :bold t)))) ;; highligh\
t current line
)
This way you keep every color for reserved words all bold and a gray background for the current line. Everything will be beautiful =)

How to disable auctex fontification, without losing color highlighting?

I like maximum syntax highlighting of AucTeX, but I don't like AucTeX messing with fonts. For example, if I use italics, it shows italicized letters in my emacs buffer, and shows subscripts and superscripts in small letters (slightly above or below the line). I prefer to use a fixed width font regardless of the latex environment I am in.
I tried changing the settings for the variable font-latex-deactivated-keyword-classes, but then the syntax coloring also disappears.
Could someone suggest a way to fix this?
Thanks.
From http://www.gnu.org/software/auctex/manual/auctex/Faces.html#Faces
In case you want to change the colors and fonts used by font-latex please refer to the faces mentioned in the explanations above and use M-x customize-face RET <face> RET. All faces defined by font-latex are accessible through a customization group by typing
M-x customize-group RET font-latex-highlighting-faces RET.
The above command opens the settings buffer where you can set the appropriate font face. Once you save changes, your .emacs file will contain a line similar to:
'(font-latex-sectioning-5-face ((((class color) (background light))
(:inherit variable-pitch :foreground "blue4" :weight normal :foundry
"outline" :family "Century Gothic")
In your example, you can customize the Font Latex Italic Face to your specifications. Your .emacs should then contain
'(font-latex-italic-face ...)
to whatever you set it to. You can similarly customize superscript, subscript and whole host of other font faces.
In recent versions of AUCTeX:
(setq font-latex-fontify-script nil)
(setq font-latex-fontify-sectioning 'color)
See this page in the manual and the section Deactivating defaults of built-in keyword classes.
Tested on Emacs 24.3. Put the following in your ~/.emacs file:
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(font-latex-bold-face ((t nil)))
'(font-latex-doctex-documentation-face ((t nil)))
'(font-latex-doctex-preprocessor-face ((t nil)))
'(font-latex-italic-face ((t nil)))
'(font-latex-math-face ((t nil)))
'(font-latex-sectioning-0-face ((t nil)))
'(font-latex-sectioning-1-face ((t nil)))
'(font-latex-sectioning-2-face ((t nil)))
'(font-latex-sectioning-3-face ((t nil)))
'(font-latex-sectioning-4-face ((t nil)))
'(font-latex-sectioning-5-face ((t nil)))
'(font-latex-sedate-face ((t nil)))
'(font-latex-slide-title-face ((t nil)))
'(font-latex-string-face ((t nil)))
'(font-latex-subscript-face ((t nil)))
'(font-latex-superscript-face ((t nil)))
'(font-latex-verbatim-face ((t nil)))
'(font-latex-warning-face ((t nil))))

Emacs customize-face loses/fails to recognise font-name it wrote to my .emacs itself

I used the Options/Set Default Font menu item to set my default emacs font to be LMMonoLtCond10 (it brought up a nice font-selector GUI widget to let me do this). My emacs immediately adopted the new font, and I was very happy. I then did Options/Save Options, and on inspecting my .emacs.d/init.el file saw that it had written the following there:
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black"
:inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal
:weight light :height 120 :width normal :foundry "unknown" :family "LMMonoLtCond10"))))
(There are a couple of other faces I've defined below that.)
Unfortunately, if I quit emacs, and restart, it completely fails to recreate the font configuration that I had selected. Instead, I think it's giving me LMRoman-12. Am I doing something wrong, or is this an emacs bug.
I'm using Emacs 23.1.1:
(emacs-version)
"GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.20.1)
of 2011-03-05 on palmer, modified by Debian"
on an Ubuntu system.
Sounds like it might be a bug. M-x report-emacs-bug

Change Emacs syntax highlighting colors

I'm running Emacs, editing files in C++ mode and PHP mode. I love syntax highlighting as a concept, but the default colors are a travesty. I can barely read some of them: way too dark. What is the easiest way to change their values? I can't seem to find anything about this on the web. I don't even mind changing the binary as I'm compiling my own Emacs. I just want to find the place where it says blue is #0000FF and change it to #AAAAFF for example.
I find it easiest to use color-theme for this sort of thing.
But if you don't want to do that, put the cursor over the offending text, and hit M-x customize-face. It should default to the face that the cursor is over.
See 49.1.6 Customizing Specific Items.
Two ways - you can install the package color-theme, which has lots of nice schemes to select and is easier to do it by hand. The by-hand looks like this (in your .emacs file)
(custom-set-faces
custom-set-faces was added by Custom.
If you edit it by hand, you could mess it up, so be careful.
Your init file should contain only one such instance.
If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "lightyellow2" :foreground "gray20" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :width normal :family "liberation mono"))))
'(background "blue")
'(font-lock-builtin-face ((((class color) (background dark)) (:foreground "Turquoise"))))
'(font-lock-comment-face ((t (:foreground "MediumAquamarine"))))
'(font-lock-constant-face ((((class color) (background dark)) (:bold t :foreground "DarkOrchid"))))
'(font-lock-doc-string-face ((t (:foreground "green2"))))
'(font-lock-function-name-face ((t (:foreground "SkyBlue"))))
'(font-lock-keyword-face ((t (:bold t :foreground "CornflowerBlue"))))
'(font-lock-preprocessor-face ((t (:italic nil :foreground "CornFlowerBlue"))))
'(font-lock-reference-face ((t (:foreground "DodgerBlue"))))
'(font-lock-string-face ((t (:foreground "LimeGreen"))))
...
etc. etc.
You can also type
`M-x customize-face RET`
which will give you all the customizations to set, ultimately end up in your .emacs file.
Put the cursor on a face ("color") that you want to change. Hit C-u C-x =. That will tell you which face(s) are present at that position, and it will let you click to customize it/them. Save your customizations.
If you don't care about color highlighting at all, or none of the previous answers work for you (or take too much time and effort to figure out), here is a very simple solution that will get rid of colors altogether.
Typing the following will get rid of colors:
M-x global-font-lock-mode
You can also do this as an interim step to allow you to actually see everything your screen to try any of the above answers. In my case, this was very useful because the color of certain key pieces of text which would allow me to change colors were themselves nearly invisible - for instance, the prompt of M-x.
If you want the change to be permanent, you can add this to your .emacs file:
(setq-default global-font-lock-mode nil)
Starting with Emacs 24.1, you can use M-x customize-themes to select a colour theme.
Emacs comes with a dozen or so themes with varying brightness and colourfulness, so you'll most likely find something that mostly matches your preferences.
You can also find more colour themes installable through MELPA at https://peach-melpa.org/ - no, that web site seems to be down. You can search for "theme" at melpa.org, but it doesn't show any screenshots.