From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yilkal Argaw Newsgroups: gmane.emacs.devel Subject: Adding some convenience functions to color.el Date: Fri, 9 Jun 2023 02:57:41 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003dd52505fda705ae" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27138"; mail-complaints-to="usenet@ciao.gmane.io" To: Emacs Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jun 09 01:58:55 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q7PWo-0006yy-Ll for ged-emacs-devel@m.gmane-mx.org; Fri, 09 Jun 2023 01:58:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7PVx-0000Uv-B8; Thu, 08 Jun 2023 19:58:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7PVw-0000Uh-An for emacs-devel@gnu.org; Thu, 08 Jun 2023 19:58:00 -0400 Original-Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q7PVt-0006y1-85 for emacs-devel@gnu.org; Thu, 08 Jun 2023 19:58:00 -0400 Original-Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1a28de15c8aso205082fac.2 for ; Thu, 08 Jun 2023 16:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686268673; x=1688860673; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=OcbVD5AgL+dv7eNz0rdX8svKGcDfHlnpnjMjVVoVmt0=; b=ih/qYger/eDVugc/t6cyWX1y4qk8skrVOfmq2tNPgun+GgjjyAD/03VXTQiIfGfW7/ lsuc9MmTVAEdHrd//JBxPaOdi3eaoClUcKTt7LJmKkZ1ie3gYBX6s8XouLxktc22GaRY OE7xLgRIBeZCB9/iVpw4D8GIroSXIE9FiL8o5i0AKqaOIpivMFxys4z9Um+75gH0uLYN NuwbrWYLNnQfLRv1KesZvKjoG6aVC0ZQ40wzQSoYOFhCo2AlnK39NaSrJat3QiIlKVhP biE4WJU9ZIz2YqYsYoWSFCahRphcqLuGuUq/uJJTjV+P7O0iBY7YR3iF9zAZYt5iK+Vx I3zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686268673; x=1688860673; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OcbVD5AgL+dv7eNz0rdX8svKGcDfHlnpnjMjVVoVmt0=; b=EcsCs3ojhNFEA3bfLH2ql4RrunyImRhW/D/dBHcNN1BiMvkLh5Xf1fiL/8ixDCsaLk R8NW4u84aNng6rRLgKN9jDEZ312mDuWimekbuMKZ9Lkzg23v1aVlapHrRNrSWHPSqJ+M Ry8IVDlhYZj9oPpH02oYD06zOe55cw5/6JFEQLm40gj6/TiRYxysxXL1P2qHl4doChY6 ZMW9AMuor5eyFB/ELBpfqubREgp5v/QvP5x1/8TAJHErIlD75E95Lqlj+qOVl8CAv7vv KFFh6n6TWFA5FhB8laOyAAXYZQD12lNGif6aQk8YMaFwvuTNqgjRFr3Er9D+Pq5hf5VW RLHw== X-Gm-Message-State: AC+VfDy8GSSwwN3bFhszCYbUEOXmW2byrVZCo4zU/qISMsGkpxK42JUT GXYcJfENTcHOMJIwfofpoNf/Pz43j2GbrU1NAcCtawH3zdeOpg== X-Google-Smtp-Source: ACHHUZ7/k3QLrJ0kXKMdzF9j1/pfOi6L6CtKQY0zyPnlbyEyneTeiwbzRyX4lDssBuKi0vujrsBeXwfBlf+LNJwfxB0= X-Received: by 2002:a05:6870:9202:b0:18e:7c5e:b5c1 with SMTP id e2-20020a056870920200b0018e7c5eb5c1mr25835oaf.45.1686268672855; Thu, 08 Jun 2023 16:57:52 -0700 (PDT) Received-SPF: pass client-ip=2001:4860:4864:20::2f; envelope-from=yilkalargawworkneh@gmail.com; helo=mail-oa1-x2f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:306702 Archived-At: --0000000000003dd52505fda705ae Content-Type: text/plain; charset="UTF-8" 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 --0000000000003dd52505fda705ae Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi
Today I was messing around with= some theme that=C2=A0 made use of color.el and I noticed some functions th= at might be of use could be added to color.el to help with the conditionall= y assigning setting some colors based on lightness or darkness of some othe= r 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/c= olor.el
index f68cf5e6b17..3740c3d5a7c 100644
--- a/lisp/color.el
= +++ b/lisp/color.el
@@ -119,6 +119,18 @@ inclusive."
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 (color-hue-to-rgb m1 m2 H)
=C2=A0 =C2=A0 =C2=A0 =C2=A0= (color-hue-to-rgb m1 m2 (mod (- H (/ 3.0)) 1))))))
=C2=A0
+(defun co= lor-name-to-hsl (color)
+ "Convert COLOR to HSL."
+ =C2=A0(= apply #'color-rgb-to-hsl (color-name-to-rgb color)))
+
+(defun co= lor-name-light-p (color)
+ =C2=A0 "Return non-nil if COLOR is on th= e lighter side."
+ =C2=A0(when color (>=3D (caddr (color-name-to= -hsl color) 0.5))))
+
+(defun color-name-dark-p (color)
+ =C2=A0&q= uot;Return non-nil if COLOR is on the darker side."
+ =C2=A0(when c= olor (not (color-name-light-p color))))
+
=C2=A0(defun color-compleme= nt-hex (color)
=C2=A0 =C2=A0"Return the color that is the complemen= t of COLOR, in hexadecimal format."
=C2=A0 =C2=A0(apply 'color-= rgb-to-hex (color-complement color)))


With Regards
Yilkal Argaw
--0000000000003dd52505fda705ae--