tags:

views:

108

answers:

3

I have a log file that has a lot of tagging information, i.e, "ERROR", "WARNING", "*". I want to show the log info with different color/fonts based on the tagging info. How can I do that?

Do I have to come up with my own major/minor modes? Is there some elisp code that I can reuse?

+5  A: 

You can do this interactively with:

M-s h r regexp <RET> FACE <RET>

or

C-x w h regexp <RET> FACE <RET>

see the documentation for Interactive Highlighting. Note: The second key binding is only available after you've turned on Hi-Lock mode via M-x global-hi-lock-mode.

If you want to set up a minor mode to do this on a regular basis, I'd check out fixme-mode and modify things from there.

It might be useful to read the Faces portion of the manual to understand what is going on.

Trey Jackson
C-x w h is not bound to any command in my standard Emacs (23.1.2). Instead, highlight-regexp is bound to M-s h r. Strange.
mmmasterluke
@mmmasterluke Thanks, I didn't notice that, I've updated the answer to reflect this.
Trey Jackson
+3  A: 

You can use a similar function in hooks for modes you care:

(defun add-watchwords ()
  (font-lock-add-keywords
   nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
          1 font-lock-warning-face t))))

I use this for coding modes obviously, so you should adjust the items you want highlighted.

Bozhidar Batsov
+4  A: 

Generic Mode was designed to ease the creation of simple custom modes for things like this.

Boojum