Setting font-lock-face for different values ​​for different main modes

I'm trying to set, for example, font-lock-comment-facein Bluefor csharp-mode, but for c++-mode- is Redthis possible or not?

Right now using:

(set-face-attribute 'font-lock-comment-face nil :foreground "#57a64a")
(set-face-attribute 'font-lock-keyword-face nil :foreground "#569cd6")

but it sets the value globally, and not just for the mode.

Forgot to add im version using: GNU Emacs 24.4.1 (i686-pc-mingw32) 2014-10-24 on LEG570 on Windows 8

+4
source share
1 answer

Wow! Thanks, I thought this was not possible, but then I found this: http://www.emacswiki.org/emacs/FacesPerBuffer

Just look at the wiki example, it looks like you need:

 (make-face 'php-comment-face)
 (set-face-foreground 'php-comment-face "LightGrey")
 (add-hook 'php-mode-hook 
       (lambda ()
        ;; ...
        (set (make-local-variable 'font-lock-comment-face)
             'php-comment-face)
        ;; ...

: Emacs defaut font face per-buffer/mode

UPD

cc-mode, (add-hook csharp-mode-hook ... (add-hook c-mode-hook ..., :

(make-face 'c-comment-face)
(set-face-foreground 'c-comment-face "Red")

(add-hook 'c-mode-hook
       (lambda ()
        ;; ...
        (set (make-local-variable 'font-lock-comment-face)
             'c-comment-face)))


(make-face 'cs-comment-face)
(set-face-foreground 'cs-comment-face "Blue")

(add-hook 'csharp-mode-hook
       (lambda ()
        ;; ...
        (set (make-local-variable 'font-lock-comment-face)
             'cs-comment-face)))

, csharp c-mode. (remove-hook ... .

+2

Source: https://habr.com/ru/post/1570027/


All Articles