branch: externals/ement commit 6fc290886832f6bef914eb46155e08f08ef1d5f0 Author: Adam Porter <a...@alphapapa.net> Commit: Adam Porter <a...@alphapapa.net>
Tidy: Compilation warning --- ement-lib.el | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/ement-lib.el b/ement-lib.el index 3b1024e6fd..8bfad5e1fd 100644 --- a/ement-lib.el +++ b/ement-lib.el @@ -95,7 +95,7 @@ that stray such forms don't remain if the function is removed." ;; Copied from Emacs 28. See <https://github.com/alphapapa/ement.el/issues/99>. -;; FIXME: Remove this workaround when possible. +;; TODO(future): Remove these workarounds when dropping support for Emacs <28. (eval-and-compile (unless (boundp 'color-luminance-dark-limit) @@ -108,27 +108,28 @@ determined experimentally."))) (defalias 'ement--color-dark-p (if (fboundp 'color-dark-p) 'color-dark-p - (lambda (rgb) - "Whether RGB is more readable against white than black. + (with-suppressed-warnings ((free-vars ement--color-luminance-dark-limit)) + (lambda (rgb) + "Whether RGB is more readable against white than black. RGB is a 3-element list (R G B), each component in the range [0,1]. This predicate can be used both for determining a suitable (black or white) contrast colour with RGB as background and as foreground." - (unless (<= 0 (apply #'min rgb) (apply #'max rgb) 1) - (error "RGB components %S not in [0,1]" rgb)) - ;; Compute the relative luminance after gamma-correcting (assuming sRGB), - ;; and compare to a cut-off value determined experimentally. - ;; See https://en.wikipedia.org/wiki/Relative_luminance for details. - (let* ((sr (nth 0 rgb)) - (sg (nth 1 rgb)) - (sb (nth 2 rgb)) - ;; Gamma-correct the RGB components to linear values. - ;; Use the power 2.2 as an approximation to sRGB gamma; - ;; it should be good enough for the purpose of this function. - (r (expt sr 2.2)) - (g (expt sg 2.2)) - (b (expt sb 2.2)) - (y (+ (* r 0.2126) (* g 0.7152) (* b 0.0722)))) - (< y ement--color-luminance-dark-limit))))) + (unless (<= 0 (apply #'min rgb) (apply #'max rgb) 1) + (error "RGB components %S not in [0,1]" rgb)) + ;; Compute the relative luminance after gamma-correcting (assuming sRGB), + ;; and compare to a cut-off value determined experimentally. + ;; See https://en.wikipedia.org/wiki/Relative_luminance for details. + (let* ((sr (nth 0 rgb)) + (sg (nth 1 rgb)) + (sb (nth 2 rgb)) + ;; Gamma-correct the RGB components to linear values. + ;; Use the power 2.2 as an approximation to sRGB gamma; + ;; it should be good enough for the purpose of this function. + (r (expt sr 2.2)) + (g (expt sg 2.2)) + (b (expt sb 2.2)) + (y (+ (* r 0.2126) (* g 0.7152) (* b 0.0722)))) + (< y ement--color-luminance-dark-limit)))))) ;;;; Functions