Re: Retrieving color names and hex values using list-colors-display for coding purposes
Eli Zaretskii <[email protected]> Sat, 18 Jul 2026 10:29:35 +0300
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <[email protected]> |
> 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]> wrote: > > > > list-colors-display is an interactive function in facemenu.el, which is > > > part of GNU Emacs. It should look at the range of values and determine > > > whether #RRRRGGGGBBBB should be used as display. > > > > Not necessarily. It works with a list of 256 colors, so the full list > > available on the platform is not relevant. > > I can take the RGB values, for instance 60000, get 60000/65536, which is > 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. Not necessarily. But why should you care about such conversions? Why not let Emacs do it for you when necessary? > > 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? 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. > I could then make my own hex conversions and compute contrast > values. Why do you need your own hex conversions? > Could I rely on the colour names from (defined-colors). That will give you the colors supported directly by the platform, not the full list of colors you could potentially use. For example, if the terminal only supports 16 colors, most of the names you see in the window produced by list-colors-display on a typical GUI frame will not be in the list returned by defined-colors. > The names should be identical to the ones from list-colors-display, > right? 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.