Reputation: 987
How can I set font color for operators? I'm programing in C++, and I would like operators such as '+', '=', '!=', '<<' and such be colored as I wish.
I tried move the cursor onto an operator and 'M-x customize-face' but it takes me to 'all faces' by default. Which is the one I should edit?
Upvotes: 2
Views: 1989
Reputation: 6419
By default, operators are not font-lock
ed in my version of c++-mode
(Emacs 24.3 default). You can get the face under the cursor with C-u C-x =
. To add font locking to operators you can add then this way:
(font-lock-add-keywords 'c++-mode
'(("\\(~^<>:=,.\\+*/%-]\\)" 0 'highlight)))
The regex, and face may be customized. I am not a regex ninja, so the operators highlighted are very simplistic.
Upvotes: 0
Reputation: 6419
I believe this is what you're looking for.
;; * the name of our face *
(defface font-lock-operator-face
'((((class color)
:background "darkseagreen2")))
"Basic face for highlighting."
:group 'basic-faces)
;; You'll have a hard time missing these colors
(set-face-foreground 'font-lock-operator-face "red")
(set-face-background 'font-lock-operator-face "blue")
(font-lock-add-keywords 'c++-mode
'(("\\(~^&\|!<>:=,.\\+*/%-]\\)" 0 'font-lock-operator-face)))
Upvotes: 3