branch: externals/colorful-mode
commit ee72b3bbcffda5d7327d57b78fc5f464e9a36bea
Author: Elias G. B. Perez <eg642...@gmail.com>
Commit: Elias G. B. Perez <eg642...@gmail.com>

    Fix issue with converting hex to color name
    
    Converting hex to emacs color name returned
    a wrong color name due has the same value as
    hex (like black and grey1/grey0).
    Also add support for converting to non 24-bits
    hex in CSS rgb(a).
    * colorful-mode.el (colorful--name-to-hex)
    (colorful--hex-to-name, colorful--rgb-to-hex):
    Rework and bug fix.
---
 colorful-mode.el | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/colorful-mode.el b/colorful-mode.el
index 02a09eba95..59132f33a1 100644
--- a/colorful-mode.el
+++ b/colorful-mode.el
@@ -260,20 +260,18 @@ RGB must be a string."
          (r (colorful--percentage-to-absolute (nth 0 rgb)))
          (g (colorful--percentage-to-absolute (nth 1 rgb)))
          (b (colorful--percentage-to-absolute (nth 2 rgb))))
-    (format "#%02X%02X%02X" r g b)))
+    (color-rgb-to-hex (/ r 255.0) (/ g 255.0) (/ b 255.0) (if 
colorful-short-hex-convertions 2))))
 
 (defun colorful--hex-to-name (hex)
   "Return HEX as Emacs color name."
-  (let ((color (color-values hex))
-        name)
+  (catch 'name
     (dolist (color-list color-name-rgb-alist)
-      (if (equal (cdr color-list) color)
-          (setq name (car color-list))))
-    name))
+      (if (equal (cdr color-list) (color-values hex))
+          (throw 'name (car color-list))))))
 
 (defun colorful--name-to-hex (name)
   "Return Emacs color NAME as hex color format."
-  (let* ((short (if colorful-short-hex-convertions 2 1))
+  (let* ((short (if colorful-short-hex-convertions 2))
          (color (append (color-name-to-rgb name) `(,short))))
     (apply #'color-rgb-to-hex color)))
 

Reply via email to