I am trying to change the default font face for preprocessor directives #define
and #include
without using the font-lock-preprocessor-face
.
Instead I want to use the font-lock-add-keywords
method and regular expressions.
I also want this to apply to assembly and C modes only.
Asked
Active
Viewed 335 times
1

Rainer Joswig
- 136,269
- 10
- 221
- 346

SFbay007
- 1,917
- 1
- 20
- 39
-
**Duplicative**: http://stackoverflow.com/questions/17981738/face-font-in-c-mode-when-adding-new-keyword – lawlist Aug 03 '13 at 01:51
2 Answers
1
You shouldn't go to these measures if all you want to
do is to redefine font-lock-preprocessor-face
for c-mode
.
The reason is that font-lock already uses regex and it's
already slow. And now you would parse the exact same source
the second time with the exact same regex.
I used to use some custom regexes to fontify C++, but switched it off after a year because it was slowing me down.
You can check how slow it is by opening a 50k source
and using C-v a bunch of times.
Now try again with find-file-literally
- and it's fine.
Do this instead:
(make-face 'c-preprocessor-face)
(set-face-background 'c-preprocessor-face "blue")
(set-face-foreground 'c-preprocessor-face "yellow")
(add-hook 'asm-mode-hook
(lambda ()
(set (make-local-variable
'font-lock-comment-face)
'c-preprocessor-face)))
(add-hook 'c-mode-hook
(lambda()
(set (make-local-variable
'c-preprocessor-face-name)
'c-preprocessor-face)))

abo-abo
- 20,038
- 3
- 50
- 71
-
Thanks for the response abo-abo. My main request here is to make preprocessors "#if #else #ifndef ...etc" in black and the preorpocessros "#include and #define" in blue. For that I need to use regex. But that is not working for me. – SFbay007 Aug 05 '13 at 16:50
0
Have you looked at my comment
and answer
to your previous question, which was essentially the same question as this current thread?
-
Hi Lawlist.... I appreciate your followup. My main request here is to make preprocessors "#if #else #ifndef ...etc" in black and the preorpocessros "#include and #define" in blue. For that I need to use regex. But that is not working for me. I could not find a working solution in what you proposed. – SFbay007 Aug 05 '13 at 16:50