Pregunta

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?

¿Fue útil?

Solución

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)))

Otros consejos

By default, operators are not font-locked 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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top