Reputation: 81
I wanted to make a derived mode for python-mode
to add custom keywords and color. So I retreived the part of the code that defines the face of the keywords and added my own keywords.
If I use an already existing face it works just fine. But I want to use custom faces so it doesn't change color if in the same time of other faces. I search how to define a face and end up with this:
(defface printr-face
'((t :foreground "red" :weight bold))
"Face for printr function"
:group 'python-print-color-faces)
the part of the code I try to apply it (inside the variable "python-font-lock-keywords") look like this:
(,(rx symbol-start (or "printr") symbol-end) . printr-face)
The printr-face
does appear in the list when I use
M-x list-faces-display
.
But the face isn't applied. M-x describe-face
see it as default.
What am I doing wrong? How can I use my newly defined face ?
Upvotes: 0
Views: 1629
Reputation: 81
choroba was in the right. Also I missed a set a parenthesis in the defface:
(defface printr-face `((t (:foreground "red" :weight bold))) "Face for printr function"
:group 'python-print-color)
(I forgot to encapsulated the :forground :weight)
then
(font-lock-add-keywords
'python-print-color-mode
'(("printr" . 'printr)
("printg" . 'printg)))
Note that I had to use "." instead of "1" to make it work. Not sure what the "1" should have done but it wasn't working for me.
Upvotes: 1
Reputation: 241758
When adding new faces to new keywords, you need to add the keywords, too:
(font-lock-add-keywords
'my-mode
'(("regex1" 1 'my-face1)
("regex2" 1 'my-face2))
1)
Upvotes: 1