* Adding some convenience functions to color.el
@ 2023-06-08 23:57 Yilkal Argaw
2023-06-09 6:22 ` Philip Kaludercic
2023-06-09 6:55 ` Eli Zaretskii
0 siblings, 2 replies; 5+ messages in thread
From: Yilkal Argaw @ 2023-06-08 23:57 UTC (permalink / raw)
To: Emacs Devel
[-- Attachment #1: Type: text/plain, Size: 1217 bytes --]
Hi
Today I was messing around with some theme that made use of color.el and I
noticed some functions that might be of use could be added to color.el to
help with the conditionally assigning setting some colors based on
lightness or darkness of some other color. I wondered if it might be useful
to other users and if it might be worth adding it to color.el. I
diff --git a/lisp/color.el b/lisp/color.el
index f68cf5e6b17..3740c3d5a7c 100644
--- a/lisp/color.el
+++ b/lisp/color.el
@@ -119,6 +119,18 @@ inclusive."
(color-hue-to-rgb m1 m2 H)
(color-hue-to-rgb m1 m2 (mod (- H (/ 3.0)) 1))))))
+(defun color-name-to-hsl (color)
+ "Convert COLOR to HSL."
+ (apply #'color-rgb-to-hsl (color-name-to-rgb color)))
+
+(defun color-name-light-p (color)
+ "Return non-nil if COLOR is on the lighter side."
+ (when color (>= (caddr (color-name-to-hsl color) 0.5))))
+
+(defun color-name-dark-p (color)
+ "Return non-nil if COLOR is on the darker side."
+ (when color (not (color-name-light-p color))))
+
(defun color-complement-hex (color)
"Return the color that is the complement of COLOR, in hexadecimal
format."
(apply 'color-rgb-to-hex (color-complement color)))
With Regards
Yilkal Argaw
[-- Attachment #2: Type: text/html, Size: 1441 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Adding some convenience functions to color.el
2023-06-08 23:57 Adding some convenience functions to color.el Yilkal Argaw
@ 2023-06-09 6:22 ` Philip Kaludercic
2023-06-09 6:55 ` Eli Zaretskii
1 sibling, 0 replies; 5+ messages in thread
From: Philip Kaludercic @ 2023-06-09 6:22 UTC (permalink / raw)
To: Yilkal Argaw; +Cc: Emacs Devel
Yilkal Argaw <yilkalargawworkneh@gmail.com> writes:
> Hi
> Today I was messing around with some theme that made use of color.el and I
> noticed some functions that might be of use could be added to color.el to
> help with the conditionally assigning setting some colors based on
> lightness or darkness of some other color. I wondered if it might be useful
> to other users and if it might be worth adding it to color.el. I
>
> diff --git a/lisp/color.el b/lisp/color.el
> index f68cf5e6b17..3740c3d5a7c 100644
> --- a/lisp/color.el
> +++ b/lisp/color.el
> @@ -119,6 +119,18 @@ inclusive."
> (color-hue-to-rgb m1 m2 H)
> (color-hue-to-rgb m1 m2 (mod (- H (/ 3.0)) 1))))))
>
> +(defun color-name-to-hsl (color)
> + "Convert COLOR to HSL."
I think it would make sense to mention what COLOR is. Or at least call
it COLOR-NAME.
> + (apply #'color-rgb-to-hsl (color-name-to-rgb color)))
> +
> +(defun color-name-light-p (color)
> + "Return non-nil if COLOR is on the lighter side."
> + (when color (>= (caddr (color-name-to-hsl color) 0.5))))
IMO using `and' is better if you are interested the return value of an
expression, while `when' is usually more indicative of a side-effect (on
my first reading of this assumption had me confused to the point of the
function).
But setting that aside, why should someone pass nil to this function?
> +
> +(defun color-name-dark-p (color)
> + "Return non-nil if COLOR is on the darker side."
> + (when color (not (color-name-light-p color))))
> +
> (defun color-complement-hex (color)
> "Return the color that is the complement of COLOR, in hexadecimal
> format."
> (apply 'color-rgb-to-hex (color-complement color)))
This is useful!
Could you prepare a patch and update etc/NEWS? It seems that the other
color functions are not documented in the Emacs Lisp manual.
>
> With Regards
> Yilkal Argaw
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adding some convenience functions to color.el
2023-06-08 23:57 Adding some convenience functions to color.el Yilkal Argaw
2023-06-09 6:22 ` Philip Kaludercic
@ 2023-06-09 6:55 ` Eli Zaretskii
2023-06-09 7:26 ` Yilkal Argaw
1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2023-06-09 6:55 UTC (permalink / raw)
To: Yilkal Argaw; +Cc: emacs-devel
> From: Yilkal Argaw <yilkalargawworkneh@gmail.com>
> Date: Fri, 9 Jun 2023 02:57:41 +0300
>
> Today I was messing around with some theme that made use of color.el and I noticed some functions
> that might be of use could be added to color.el to help with the conditionally assigning setting some
> colors based on lightness or darkness of some other color. I wondered if it might be useful to other
> users and if it might be worth adding it to color.el. I
We already have color-dark-p (and color-name-to-rgb to complement it),
so I'm not sure I understand the rationale for these functions. Can
you explain more why you needed them?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adding some convenience functions to color.el
2023-06-09 6:55 ` Eli Zaretskii
@ 2023-06-09 7:26 ` Yilkal Argaw
2023-06-09 7:34 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Yilkal Argaw @ 2023-06-09 7:26 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]
> From: Eli Zaretskii <eliz@gnu.org>
> We already have color-dark-p (and color-name-to-rgb to complement it),
> so I'm not sure I understand the rationale for these functions. Can
> you explain more why you needed them?
Sorry I totally missed color-dark-p. I did not check faces.el and
color-dark-p was in faces.el.
Having color-name-to-hsl is just a convenience function to make it easier
when working in some
color spaces. Because some operations are easier in certain color spaces.
On Fri, Jun 9, 2023 at 9:55 AM Eli Zaretskii <eliz@gnu.org> wrote:
> > From: Yilkal Argaw <yilkalargawworkneh@gmail.com>
> > Date: Fri, 9 Jun 2023 02:57:41 +0300
> >
> > Today I was messing around with some theme that made use of color.el
> and I noticed some functions
> > that might be of use could be added to color.el to help with the
> conditionally assigning setting some
> > colors based on lightness or darkness of some other color. I wondered if
> it might be useful to other
> > users and if it might be worth adding it to color.el. I
>
> We already have color-dark-p (and color-name-to-rgb to complement it),
> so I'm not sure I understand the rationale for these functions. Can
> you explain more why you needed them?
>
[-- Attachment #2: Type: text/html, Size: 2095 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adding some convenience functions to color.el
2023-06-09 7:26 ` Yilkal Argaw
@ 2023-06-09 7:34 ` Eli Zaretskii
0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2023-06-09 7:34 UTC (permalink / raw)
To: Yilkal Argaw; +Cc: emacs-devel
> From: Yilkal Argaw <yilkalargawworkneh@gmail.com>
> Date: Fri, 9 Jun 2023 10:26:57 +0300
> Cc: emacs-devel@gnu.org
>
> > From: Eli Zaretskii <eliz@gnu.org>
> > We already have color-dark-p (and color-name-to-rgb to complement it),
> > so I'm not sure I understand the rationale for these functions. Can
> > you explain more why you needed them?
>
> Sorry I totally missed color-dark-p. I did not check faces.el and color-dark-p was in faces.el.
They are now documented in the ELisp manual.
> Having color-name-to-hsl is just a convenience function to make it easier when working in some
> color spaces. Because some operations are easier in certain color spaces.
color.el already provides color-rgb-to-hsl and color-hsl-to-rgb, so
you should be able to easily work in the HSL space, and still call
functions that accept RGB arguments.
IMO, we already have a large and rich collection of color-related
functions, so adding more will run the risk to increase confusion and
produce inconsistencies. (E.g., your proposed color-name-dark-p uses
a threshold for dark vs light colors that is different from what we
use in color-dark-p.)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-09 7:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-08 23:57 Adding some convenience functions to color.el Yilkal Argaw
2023-06-09 6:22 ` Philip Kaludercic
2023-06-09 6:55 ` Eli Zaretskii
2023-06-09 7:26 ` Yilkal Argaw
2023-06-09 7:34 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).