Alex Henning home about projects blog

Coloring Text in Emacs

I was working on a dashboard for blogging in emacs as part of my current goal of learning emacs lisp, and I would a very annoying problem. I wanted to color certain lines, this isn't syntax highlighting, merely, coloring of key lines.

At first I duckduckgo'd and duckduckgo'd, but all I could find was syntax highlighting of keywords and this page. I looked at add-text-properties and propertize. I was trying the property face, however, the property I wanted isn't face, but font-lock-face. Why? It has something to do with font-lock-mode… it was a good half of a day wasted. Anyways, I ended up with a nice little function for highlighting the current line:

1:  (defun blog-set-line-face (face)
2:    (add-text-properties
3:     (line-beginning-position)
4:     (line-end-position)
5:     `(font-lock-face ,face)))
6:  

To go along with the color theme, you can use the color theme faces:

I'll probably throw the initial verion of blog.el on github in the next few days.

Posted on 06 November 2010 in emacs lisp highlighting

<Previous: Installing Emacs from Source on UbuntuNext: Licensing - WTFPL>

blog comments powered by Disqus