Re: Retrieving color names and hex values using list-colors-display for coding purposes
Heime <[email protected]> Fri, 17 Jul 2026 12:10:15 +0000
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <G2rKiuFdV3luy8CiwmXIxD4yG5pCgQX81LQn2jfqjRl30h9gfFku5Fw7XuoRDBrRw2PAXmV_zPkt8JIg-AlLOKlnGBvGUKWW_deCa85FtcE=@protonmail.com> |
On Friday, July 17th, 2026 at 11:21 PM, Eli Zaretskii <[email protected]> wrote: > > Date: Fri, 17 Jul 2026 11:02:17 +0000 > > From: Heime <[email protected]> > > Cc: [email protected], [email protected] > > > > On Friday, July 17th, 2026 at 6:08 PM, Eli Zaretskii <[email protected]> wro= te: > > > > > > Date: Thu, 16 Jul 2026 20:50:36 +0000 > > > > From: Heime <[email protected]> > > > > Cc: Eli Zaretskii <[email protected]>, [email protected] > > > > > > > > On Friday, July 17th, 2026 at 3:48 AM, packrat386 <[email protected]= m> wrote: > > > > > > > > > "Heime" <[email protected]> writes: > > > > > > > > > > > On Thursday, July 16th, 2026 at 5:42 PM, Eli Zaretskii <eliz@gn= u.org> wrote: > > > > > > > > > > > >> > Date: Thu, 16 Jul 2026 02:56:34 +0000 > > > > > >> > From: Heime <[email protected]> > > > > > >> > > > > > > >> > > > > > > >> > How can I get list of colour names and hex numbers (list-col= ors-display) > > > > > >> > that I can then use in my code with a loop. > > > > > >> > > > > > >> The function defined-colors will return the list of names of s= upported > > > > > >> colors. The function color-values will return the RGB triplet= for the > > > > > >> given color. > > > > > > > > > > > > How does the computation for white give 65535 ? > > > > > > > > > > > > "white" 65535 65535 65535 > > > > > > > > > > 65535 is 0xFFFF. So the RGB values are 16 bit integers and "white= " means > > > > > the max of all three. > > > > > > > > I do not understand this. If 16-bit numbers require a 4-digit hex = value > > > > like FFFF, why does the hex values for white when calling (list-col= or-display) > > > > display #FFFFFF - which is only a 2-big hex value for each colour? > > > > When I look for white using (list-color-display) I get a hex value = of > > > > #ffffff. I do not understand this because if each colour is 16-bit > > > > > > There are different representations for the RGB specification of a > > > color, you can have 3 or 6 or 9 or 12 hex digits. See "Color Names" > > > in the ELisp manual. The relations between them are somewhat complex= , > > > and you don't need or want to dig into this in almost all cases. Jus= t > > > use 16 bits per component and 12-digit specs all the time, and Emacs > > > will do the rest. > > > > When I look at the definition of faces, I almost always see people > > using #RRGGBB - 6 hex digits, 2 digits per colour. That is 256 > > shades per colour. Furthermore, although (color-values colour-name) > > gives values in the range 0-65535 per colour, the hex value displayed > > at the end in still #RRGGBB - meaning that the actual colour is lost. >=20 > WHY DO YOU CARE??? >=20 > You ask questions and get the best answers we can provide. Until and > unless what these answers say doesn't actually work when you try, why > do you insist on digging into the Emacs's sources that might do stuff > differently, for whatever reasons? >=20 > I could perhaps sit down and explain to you in a very detailed fashion > why you see in faces.el what you see, but why should I invest that > non-trivial effort? And why should you insist on asking about that, > when you evidently didn't even try what you were suggested to do? An explanation would be good, but then I have to decide what to use in=20 practice, which undoubatedly is more important. =20 > Understanding why we do in Emacs's sources what we do there requires a > lot of knowledge about the internal workings and the history of Emacs. > All of that is completely irrelevant to writing code on the level on > which you are now. So please take the advice you are given and try > it, and only ask followup questions about "other ways of doing that" > if the advice doesn't work for some reason. >=20 > Okay? What is the advice exactly? I am writing colour faces and want to compute contrast ratio to support accessibility rules. It makes a difference what= =20 hex values I use. You suggest using names, many people use #RRGGBB. There does not seem to be any clear agreed way. =20 If I take a name, the colour values for the name are in range 0-65535 which requires #RRRRGGGGBBBB. And the hex value displayed is #RRGGBB. Which value should one use, the common #RRGGBB or the #RRRRGGGGBBBB. For instance modus-themes uses #RRGGBB. Emacs internally uses 16-bit per component, but the displayed hex code is usually 6-digit. Can't people see a problem with this! =20 The common, practical hex format in Emacs and web standards is #RRGGBB. Seems to me that developers are routinely disregarding any improvements with higher bit colours. But internally you care about them and use them.