[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding some convenience functions to color.el
From: |
Philip Kaludercic |
Subject: |
Re: Adding some convenience functions to color.el |
Date: |
Fri, 09 Jun 2023 06:22:03 +0000 |
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