Font lock face in emacs

1

Using M-x customize-face RET RET when the cursor is on a type name (this opens the customization of font-lock-type-face) in a c++ code, I managed to make the face of type names bold. Next, when I opened a .tex file, the face of the text of a caption was boldded as well... Seems like the two are sharing something (font-lock-type-face?) in common.

How can I set the font-lock-type-face to have one face when the mode is c++, and another face when the mode is LaTeX?

Dror

Posted 2012-10-17T15:02:35.813

Reputation: 1 510

Answers

1

I don't have the code for tex mode with me now, but yes, it is possible, in fact all too common, IMHO, that the same font-lock face is reused for something quite different. If that is the case here, i.e., if the tex-mode code hard-codes the face it uses as the same face, then you are out of luck (modulo rewriting that code to use a different face).

To see what face is actually used, in your tex-mode buffer, put the cursor on the text in question and hit C-u C-x =. That will display lots of info about the position and character, and near the bottom it will tell you about any text properties, including property face, that are on that character. If it says font-lock-type-face then yes, the same face is used.

If that is not the case, so you see a different face name, then the problem is perhaps only that that face's definition inherits from font-lock-type-face. In that case, you're in luck: just customize that face, whatever it is.

In the out-of-luck case, consider also using M-x report-emacs-bug to suggest that Emacs Dev not simply reuse the same face, font-lock-type-face, but instead they create a tex mode-specific face for this. They can have that face inherit from font-lock-type-face if they want, but they should not just reuse that face. This is my opinion, not necessarily shared by Emacs Dev -- just letting you know.

Drew

Posted 2012-10-17T15:02:35.813

Reputation: 1 898

Seems like I'm out of luck :) – Dror – 2013-09-02T11:49:00.143

You can trump it with your own defvar | set-face-attribute | font-lock-add-keywords: http://stackoverflow.com/questions/17981738/face-font-in-c-mode-when-adding-new-keyword/17982646#17982646   For example, I have colorized my own begin/end document in latex-mode to make it stand out better.

– lawlist – 2013-09-02T16:05:09.967

It should be pretty clear. If the same face is used in the code, you can either (a) change the code (or request that Emacs Dev do that) or (b) change the face appearance here and there, now and again, as @lawlist suggested. There is no miracle here. Faces are not mode-local or buffer-local. You might not like the answer but that's it. Take your pick. But first verify the guesses about the same face being used. If two different faces are used and it's just that one inherits from the other, then there is no problem --- just customize one or the other. – Drew – 2013-09-05T04:33:53.497

As far as I can tell the same face is used. See my comment above. – Dror – 2013-09-06T11:37:26.573

In that case, either change the code (or request that it be changed in Emacs) or follow @lawlist's suggestion. You say "as far as I can tell". Did you use C-u C-x = as I suggested? That will tell you exactly which faces are used -- no guessing needed. – Drew – 2013-09-06T15:39:22.580