My question is similar to this one and that one: I would like to add highlighting of some characters that are not highlighted in some programming modes, like python-mode
and fortran-mode
.
So, following Lindydancer's answer to the first question cited above, I try the following in my init file:
(defun python-fortran-common-hook ()
(font-lock-add-keywords nil
'(;
("+" (0 font-lock-negation-char-face))
("-" (0 font-lock-negation-char-face))
("*" (0 font-lock-negation-char-face))
("/" (0 font-lock-negation-char-face))
("=" (0 font-lock-negation-char-face))
("<" (0 font-lock-negation-char-face))
(">" (0 font-lock-negation-char-face))
("," (0 font-lock-negation-char-face))
(";" (0 font-lock-negation-char-face))
(":" (0 font-lock-negation-char-face))
)))
(add-hook 'python-mode-hook #'python-fortran-common-hook)
(add-hook 'fortran-mode-hook #'python-fortran-common-hook)
The problem is that for some reason this does not work (the characters I want to highlight still have the default highlighting), and my question is why.
Note 1: I tried the same with an add-hook
form, and it works. But I would greatly appreciate to have the above form, not to have to write and add-hook
for each mode that I want to have this highlighting. I am aware of prog-mode
, but there are modes in it for which I don't want this highlighting.
Note 2: Of course, if there is a better way to achieve what I want, I would be glad to hear about it.