Re: Help using font-lock

Andy Sawyer <[email protected]> Sat, 17 Jun 2006 10:39:01 +0100
Newsgroups gmane.emacs.xemacs.general
Organization International Rescue
Message-ID <[email protected]>
"Dan Bar Dov" <[email protected]> writes:

> I'm having a problem understanding how to use font-lock-mode 
> without using any major mode.
>
> Actually, I'm editing some text in text-mode and I'd like several 
> forms to be highlighted.
>
> I tried to set the following in my init.el, but this does not seem to work
>
> (setq font-lock-keywords
>       '(("   \\*.*" . 'font-lock-string-face)
> 	("---+ .*" . 'font-lock-string-face)
> ))
>
> I do not want to write a new major mode or anything fancy, something
> very simple.

 Writing a new major mode to do this is one of those things that turns
out to be very simple, once you know how :). Try this:

,----
| (define-derived-mode dbd-mode
|   text-mode
|   "DBD"
|   "Highlight for DBD."
|   (font-lock-mode 1))
| 
| (defconst dbd-mode-font-lock-keywords
|   '(("   \\*.*" . font-lock-string-face)
|     ("---+ .*" . font-lock-string-face))
|     "`font-lock-keywords' for `dbd-mode'.")
| 
| (put 'dbd-mode 'font-lock-defaults
|      '(dbd-mode-font-lock-keywords))
`----

then when you're editing your text just M-x dbd-mode.

Hope this helps,
 '(andys)