abo-abo
abo-abo

Reputation: 20362

Emacs lisp: get RGB components of face?

I've recently made a switch to Emacs trunk and the region face color was changed. And I can't change it back without knowing what it was before.

So I've launched emacs24.3 and see that it was "gtk_selection_bg_color". This color name isn't valid any more in the trunk. I've found the color to be "f9b593" with screenshot->gimp->eyedrop method, but I'd like to know how to do this in Elisp, e.g. something like

(get-face-background-rgb 'region)
;; "f9b593"

Any suggestions?

Upvotes: 2

Views: 590

Answers (2)

Drew
Drew

Reputation: 30708

You can use library eyedropper.el or library palette.el --- see Color Palette --- to get the color of a face at point. And you can use library palette to explore colors, to come up with a similar but slightly different color etc. You can use library hexrgb.el to examine and modify RGB components of colors.

Upvotes: 1

Lindydancer
Lindydancer

Reputation: 26134

You can use color-value:

color-values is a compiled Lisp function in `faces.el'. (color-values COLOR &optional FRAME)

Return a description of the color named COLOR on frame FRAME. The value is a list of integer RGB values--(RED GREEN BLUE). These values appear to range from 0 to 65280 or 65535, depending on the system; white is (65280 65280 65280) or (65535 65535 65535). If FRAME is omitted or nil, use the selected frame. If FRAME cannot display COLOR, the value is nil. If COLOR is the symbol `unspecified' or one of the strings "unspecified-fg" or "unspecified-bg", the value is nil.

To get the color of a face, you can use face-foreground and face-background. In your case, you can use:

 (color-values (face-background 'region))

Upvotes: 4

Related Questions