Colorize snippets of text in emacs

emacs

Solution

This is what I've done, using `font-lock-add-keywords`. I wanted to highlight the words `TODO:`, `HACK:`, and `FIXME:` in my code.

(defface todo-face
'((t ()))
"Face for highlighting comments like TODO: and HACK:")

(set-face-background 'todo-face cyan-name)

;; Add keywords we want highlighted
(defun add-todo-to-current-mode ()
    (font-lock-add-keywords nil
       '(("\\(TODO\\|HACK\\|FIXME\\):" 1 'todo-face prepend))
       t))

Problem

Suppose I have a few words I would like to highlight, so I want to change the color of those few words only to, say, green. Is there an easy way to do this in emacs? Thank you.

Original source