I would like to highlight each occurence of some word e.g. "covid" in a text when the file is loaded.
It will be in org files but even global scope for all files is not a problem. So, I can put the code in .spacemacs config file so it is loaded upon each Spacemacs startup and the words specified are being highlighted.
Here is a rough example of what I am looking for (I used search to highlight covid as an example - in my case I would prefer different background and foreground colors):
So, how does one get to something like that?
I have found this code:
(add-hook 'org-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\<covid\\>" 1
font-lock-warning-face t)))))
But it isn't working.
I would also need to modify the color and background color of the string.
How to do that?
I am not even sure whether (font-lock-add-keywords)
is the right function for this job. If there is something better or more apt for this job, let me know.
Also, (font-lock-warning-face)
, I don't know if I have to use it or I should create some own foreground and background colors in some function that will be replacing font-lock-warning-face?
UPDATE:
I have tried this code:
(add-hook 'org-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\<covid\\>" 1
'(:foreground "white" :background "red") t)))))
and after restarting Emacs I got the result is this:
Funny enough, when I try to edit the headers 1, 2, and 3 - only the 1st and 3rd go back with the style. The 2nd stays screwed no matter what I do. I looks like this:
So, it seems to me that "covid" is detected by Emacs, but for some reason the code doesn't highlight the word with the red background and white color, as I stated in the add-hook code in my .spacemacs file.
Any idea, how to fix that?