0

I am trying to do exactly this for my C code, but once I edit latex, the setting is still active in uncomfortable places. I need to preserve the setting once I exit emacs and in all the buffers with C code.

How can I restrict the behavior to only buffers with C code?

This is what I have in .emacs

(defun my-c-mode-faces ()
  '(font-lock-comment-face ((t (:foreground "dark gray"))))
  '(font-lock-function-name-face ((t (:foreground "#fce94f" :weight bold :height 1.5))))
  '(font-lock-keyword-face ((t (:foreground "#b4fa70" :weight bold)))))
(add-hook 'c-mode-hook 'my-c-mode-faces)
onlycparra
  • 247
  • 1
  • 9
  • 2
    Possible duplicate of How to modify-face for a specific buffer? See also how to use this concept (face-remap-add-relative) with a major-mode-hook: https://stackoverflow.com/a/28008006/2112489 .  The O.P. would probably want to use the c-mode-hook, but C-mode uses a few additional hooks that could also potentially be used. – lawlist May 30 '18 at 03:28
  • thanks for your comment, I want the setting to be available in all buffers, not only in one. but only buffers with c code. I'm just coming from gedit to emacs, I still need to learn what are the minor, major modes, faces and what you mention: hooks – onlycparra May 30 '18 at 06:02
  • If you look at both examples that I linked above, and use the c-mode-hook as it relates to the second example (with the desired face), then you will be all set. Every time you open a buffer in c-mode or switch to c-mode, the face-remapping-alist variable will be set accordingly and the face will be buffer-local. As in the famous old commercial with Life cereal -- "try it, you'll like it". If you actually try the second linked example with the c-mode-hook as it relates to the desired face, and if you really have problems, then edit your question to show what you have tried ... – lawlist May 30 '18 at 06:53
  • I still have the setting everywhere, I edit to include what I have in .emacs. thanks again :) – onlycparra May 31 '18 at 01:20

1 Answers1

1
(defun my-c-mode-faces ()
  (face-remap-add-relative 'font-lock-comment-face
                              '(:foreground "dark gray"))
  (face-remap-add-relative 'font-lock-function-name-face
                              '(:foreground "#fce94f" :weight bold :height 1.5))
  (face-remap-add-relative 'font-lock-keyword-face
                              '(:foreground "#b4fa70" :weight bold)))

(add-hook 'c-mode-hook 'my-c-mode-faces)
lawlist
  • 19,106
  • 5
  • 38
  • 120