Re: Retrieving color names and hex values using list-colors-display for coding purposes

Heime <[email protected]> Sat, 18 Jul 2026 22:21:48 +0000
Newsgroups gmane.emacs.help
Message-ID <3xX3ekQcS-I9uljvBfC12D8y3E4zfkgMwidt_TjEbAJbqxh6n2D_hPMysKy9_9JrHudtCJU5ExWcIB9NJNoC42O3fNT3kQxrDVFAbIf8Q3k=@protonmail.com>
On Saturday, July 18th, 2026 at 7:29 PM, Eli Zaretskii <[email protected]> wrote=
:

> > Date: Sat, 18 Jul 2026 01:11:38 +0000
> > From: Heime <[email protected]>
> > Cc: [email protected], [email protected], [email protected]
> >
> > On Saturday, July 18th, 2026 at 3:38 AM, Eli Zaretskii <[email protected]> w=
rote:
> >
> > > > list-colors-display is an interactive function in facemenu.el, whic=
h is
> > > > part of GNU Emacs.  It should look at the range of values and deter=
mine
> > > > whether #RRRRGGGGBBBB should be used as display.
> > >
> > > Not necessarily.  It works with a list of 256 colors, so the full lis=
t
> > > available on the platform is not relevant.
> >
> > I can take the RGB values, for instance 60000, get 60000/65536, which i=
s
> > 0.915, and reduce to 256 colours via 0.915*256 to get 234.
> > Such a mapping from 16-bit values to 8-bit values should be ok.
>=20
> Not necessarily.  But why should you care about such conversions?  Why
> not let Emacs do it for you when necessary?

What will Emacs do?   I only need the rgb or hex values (in range 0-1)=20
to decide whether the contrast ratio is suitable to use.  I do not want=20
just to select a colour name and apply without ensuring the contrast ratio
is appropriate for the user.

=20
> > > Once again, please don't look at that command as guidance for which
> > > RGB specifications to use in your programs.
> >
> > But I can use the colour names?
>=20
> Yes, you can use the color names if that produces the effect you want.
> If you need higher accuracy, use RGB spec with 4 hex digits per
> component.
>=20
> > I could then make my own hex conversions and compute contrast
> > values.
>=20
> Why do you need your own hex conversions?

You are right, I can just use the colour values from color-values

> > Could I rely on the colour names from (defined-colors).
>=20
> That will give you the colors supported directly by the platform, not
> the full list of colors you could potentially use. =20

> For example, if the terminal only supports 16 colors, most of the names=
=20
> you see in the window produced by list-colors-display on a typical GUI=20
> frame will not be in the list returned by defined-colors.

Is it because the GUI Emacs and Terminal Emacs do not have the same colour
capabilities?

> > The names should be identical to the ones from list-colors-display,
> > right?
>=20
> Only as long as list-colors-display is invoked on the same terminal.
> The list of color names supported by Emacs is the one you see in
> list-colors-display on a GUI frame.

Right. Meaning that list-colors-display on a GUI frame are those
supported, not actually the ones available when running emacs on
some terminal.

I have a difficulty.  How can I define a face that would be supported=20
by Emacs on some terminal?  Because I would not know what terminal=20
someone might use, would I need to make the user select them from some
available list.  What list would that be?