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.
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))
Use library HighLight. You can use overlays or text properties. You can save the highlighting permanently or let it be temporary. You can highlight in many ways (regexp, mouse-drag,...). Lots of possibilities.
The highlight package has hlt-highlight-regexp-region
and hlt-highlight-regexp-to-end
, which do exactly what you want.
http://www.emacswiki.org/cgi-bin/wiki/highlight.el
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With