Emacs: Find face definition (color, other styles, etc.) at point
Asked Answered
H

2

9

I'm making a theme for Emacs based on the default themes, namely the GUI default theme (white background) and the theme that comes out of the --reverse-video flag (black background). Just going to provide more colors for plugin faces etc., so that they all have a more unified look.

In case you're interested: https://github.com/Greduan/emacs-theme-better-defaults

Now since I am going to be working off of already existing themes for which I am not entirely sure where I can find the source I thought I should ask here what the best way to go about this would be.

Let's say I have my point on top of a comment, is there a command or something of the sort that I can call so that I can find the colors etc. with which that certain face is defined?

I am aware of describe-face, what-cursor-position (C-x = or C-u C-x =) and of list-colors-display.

The first two don't provide the information I need, namely what color it's using (hex code or otherwise), or at least I couldn't find it. I could probably use list-colors-display but that would truly be a PITA to try to find the exact color it's using. lol

Any help is appreciated. Thanks. :)

Hypoplasia answered 16/8, 2014 at 1:4 Comment(0)
Y
8

Actually, describe-face does provide the information you seem to be looking for. Place the cursor on a character with the face you're interested in. Do M-x describe-face. It will default to the face of the character at point. Hit enter: it will describe that face. Here's an example of what you get for the default face from the inkpot theme; notice the foreground and background hex values, which are the items you wanted:

Face: default (sample) (customize this face)

Documentation:
Basic default face.

Defined in `faces.el'.

        Family: DejaVu Sans Mono
       Foundry: unknown
         Width: normal
        Height: 150
        Weight: normal
         Slant: normal
    Foreground: #bdbdbd
    Background: #0d0d16
     Underline: nil
      Overline: nil
Strike-through: nil
           Box: nil
       Inverse: nil
       Stipple: nil
          Font: #<font-object -unknown-DejaVu Sans Mono-normal-normal-normal-*-26-*-*-*-m-0-iso10646-1>
       Fontset: -unknown-DejaVu Sans Mono-normal-normal-normal-*-26-*-*-*-m-0-fontset-auto1
       Inherit: nil
Yodle answered 16/8, 2014 at 10:23 Comment(2)
So it does. Dang it! I swear I tried it, all of those showed blank. lol. I tried it in several places though and it shows fine now. Thank you very much. :)Hypoplasia
If the face has nil values for the properties you're looking for, but also has an inherit property, you should follow that link for details on the face(s) it inherits from. Or failing anything else, the default face.Nikos
D
12

You can use describe-char to do this. describe-char will show the text properties for the character the point is over, which will show you, among other things, the list of faces being used to decorate the character. You can go to the face properties directly from the character properties window or use describe-face.

Doe answered 16/8, 2014 at 2:33 Comment(7)
describe-char will tell you which face is applied to the character, but you'll still need to use describe-face to get the color properties (ie, foreground and background).Yodle
Dan: It's all linked from the output of describe-char, so that's the simplest starting point.Nikos
phils: true that it's linked, but it saves a step to describe-face rather than describe-char and then follow the link.Yodle
The reason I always use/recommend describe-char (well, C-u C-x = which incorporates it) is that there can be multiple faces active on a character. describe-face will offer a relevant default, but not necessarily the one you needed.Nikos
Your answer is very useful, thank you. :) I will, however, accept @Yodle 's answer because it answers my original question. :) I still upvoted yours though. Thank you. :)Hypoplasia
phils: interesting re: multiple faces -- hadn't thought about that.Yodle
This helped me more because describe-face on a currently highlighted line only ever described the hl-line face and I was interested in a sub-face inside the line. Thank you.Norri
Y
8

Actually, describe-face does provide the information you seem to be looking for. Place the cursor on a character with the face you're interested in. Do M-x describe-face. It will default to the face of the character at point. Hit enter: it will describe that face. Here's an example of what you get for the default face from the inkpot theme; notice the foreground and background hex values, which are the items you wanted:

Face: default (sample) (customize this face)

Documentation:
Basic default face.

Defined in `faces.el'.

        Family: DejaVu Sans Mono
       Foundry: unknown
         Width: normal
        Height: 150
        Weight: normal
         Slant: normal
    Foreground: #bdbdbd
    Background: #0d0d16
     Underline: nil
      Overline: nil
Strike-through: nil
           Box: nil
       Inverse: nil
       Stipple: nil
          Font: #<font-object -unknown-DejaVu Sans Mono-normal-normal-normal-*-26-*-*-*-m-0-iso10646-1>
       Fontset: -unknown-DejaVu Sans Mono-normal-normal-normal-*-26-*-*-*-m-0-fontset-auto1
       Inherit: nil
Yodle answered 16/8, 2014 at 10:23 Comment(2)
So it does. Dang it! I swear I tried it, all of those showed blank. lol. I tried it in several places though and it shows fine now. Thank you very much. :)Hypoplasia
If the face has nil values for the properties you're looking for, but also has an inherit property, you should follow that link for details on the face(s) it inherits from. Or failing anything else, the default face.Nikos

© 2022 - 2024 — McMap. All rights reserved.