Reputation: 105
Let's say I want all words "bad" be red (#ff0000).
What should I add to init.el so the color of the string/word "bad" will turn red in all modes whether it is org mode or some other mode into this:
https://i.imgur.com/7WMwG1s.png
I would like to do it in every file I have open and if possible it should be real time without any manual evaluation etc.
Is it possible to achieve in Emacs without installing any plugin?
Upvotes: 2
Views: 433
Reputation: 9417
There is already a package called hl-todo
(https://github.com/tarsius/hl-todo). You can configure which keywords are highlighted and which colors with hl-todo-keyword-faces
). You can configure which modes it's active in with either mode hooks or hl-todo-activate-in-modes
.
Upvotes: 1
Reputation: 32426
You can define a globalized minor mode that will be active in all your buffers quite easily, eg.
(defconst my-font-lock-keywords '(("\\_<bad\\_>" . font-lock-warning-face)))
(define-minor-mode my-font-lock-mode ""
:init-value nil
:lighter ""
(if my-font-lock-mode
(font-lock-add-keywords nil my-font-lock-keywords)
(font-lock-remove-keywords nil my-font-lock-keywords))
(font-lock-flush))
(define-global-minor-mode my-font-lock-global-mode my-font-lock-mode
(lambda () (my-font-lock-mode)))
Then, activate it with M-x my-font-lock-global-mode
(or in your init)
Upvotes: 3