unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Using variables instead of hex values
@ 2021-11-08  8:00 irenezerafa via Users list for the GNU Emacs text editor
  2021-11-08 16:47 ` Jean Louis
  0 siblings, 1 reply; 3+ messages in thread
From: irenezerafa via Users list for the GNU Emacs text editor @ 2021-11-08  8:00 UTC (permalink / raw)
  To: Help Gnu Emacs

I have the following piece of code and would like to use variable names instead of
using hex values directly.

(eval-when-compile
(defmacro rich-faces ()
(let ( (faces '())
(light-colors [ "#a8007f" "#005f88" "#904200" "#7f10d0"
"#006800" "#b60000" "#1f1fce" "#605b00" "#000000"])
(dark-colors [ "#ff62d4" "#3fdfd0" "#fba849" "#9f80ff"
"#4fe42f" "#fe6060" "#4fafff" "#f0dd60" "#ffffff" ]) )

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using variables instead of hex values
  2021-11-08  8:00 Using variables instead of hex values irenezerafa via Users list for the GNU Emacs text editor
@ 2021-11-08 16:47 ` Jean Louis
  2021-11-09  9:46   ` Jean Louis
  0 siblings, 1 reply; 3+ messages in thread
From: Jean Louis @ 2021-11-08 16:47 UTC (permalink / raw)
  To: irenezerafa; +Cc: Help Gnu Emacs

* irenezerafa via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-11-08 11:05]:
> I have the following piece of code and would like to use variable names instead of
> using hex values directly.
> 
> (eval-when-compile
> (defmacro rich-faces ()
> (let ( (faces '())
> (light-colors [ "#a8007f" "#005f88" "#904200" "#7f10d0"
> "#006800" "#b60000" "#1f1fce" "#605b00" "#000000"])
> (dark-colors [ "#ff62d4" "#3fdfd0" "#fba849" "#9f80ff"
> "#4fe42f" "#fe6060" "#4fafff" "#f0dd60" "#ffffff" ]) )

(color-name-to-rgb "white") ⇒ (1.0 1.0 1.0)
(color-rgb-to-hex 1.0 1.0 1.0) ⇒ "#ffffffffffff"

(defun my-color-name (color)
  (apply 'color-rgb-to-hex (color-name-to-rgb color)))

(my-color-name "white") ⇒ "#ffffffffffff"
(my-color-name "red") ⇒ "#ffff00000000"
		  		  

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using variables instead of hex values
  2021-11-08 16:47 ` Jean Louis
@ 2021-11-09  9:46   ` Jean Louis
  0 siblings, 0 replies; 3+ messages in thread
From: Jean Louis @ 2021-11-09  9:46 UTC (permalink / raw)
  To: irenezerafa, Help Gnu Emacs

* Jean Louis <bugs@gnu.support> [2021-11-08 19:50]:
> * irenezerafa via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-11-08 11:05]:
> > I have the following piece of code and would like to use variable names instead of
> > using hex values directly.
> > 
> > (eval-when-compile
> > (defmacro rich-faces ()
> > (let ( (faces '())
> > (light-colors [ "#a8007f" "#005f88" "#904200" "#7f10d0"
> > "#006800" "#b60000" "#1f1fce" "#605b00" "#000000"])
> > (dark-colors [ "#ff62d4" "#3fdfd0" "#fba849" "#9f80ff"
> > "#4fe42f" "#fe6060" "#4fafff" "#f0dd60" "#ffffff" ]) )
> 
> (color-name-to-rgb "white") ⇒ (1.0 1.0 1.0)
> (color-rgb-to-hex 1.0 1.0 1.0) ⇒ "#ffffffffffff"
> 
> (defun my-color-name (color)
>   (apply 'color-rgb-to-hex (color-name-to-rgb color)))
> 
> (my-color-name "white") ⇒ "#ffffffffffff"
> (my-color-name "red") ⇒ "#ffff00000000"

To add, you wanted variables instead of hex, then you would do
something like:

(setq white-color (my-color-name "white")) ⇒ "#ffffffffffff"

and then use it as:

(light-colors [ white ] )

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-09  9:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-08  8:00 Using variables instead of hex values irenezerafa via Users list for the GNU Emacs text editor
2021-11-08 16:47 ` Jean Louis
2021-11-09  9:46   ` Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).