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

    Fixes and improvements.
    
    * assets/elisp_logo_warning.svg: Remove badge and use already hosted
    one.
    * COPYING.org: Fix typos.
    * README.org: Add new entry for user options and differences between
    rainbow-mode.
    * colorful-mode.el (colorful-extra-color-keywords-hook): Move to
    Customizable User options section.
    (colorful--color-luminance): Replace with color-dark-p.
    (colorful-mode-map): Add keymap.
    (colorful-change-color): Rework and use if-let instead let and if
    (I had plans for use a if progn but was discarted):.
    (colorful--colorize-match): Fix docstring and move mouse actions to
    colorful-use-prefix conditional.
    (colorful-mode): Add :keymap.
    (global-colorful-mode): Fix :group type (for those that were wondering
    why it had corfu instead colorful is because i used that part from
    corfu source code and i forgot change group).
---
 COPYING.org                   |   2 +-
 README.org                    |  45 ++++++++--
 assets/elisp_logo_warning.svg | 193 ------------------------------------------
 colorful-mode.el              |  98 +++++++++------------
 4 files changed, 79 insertions(+), 259 deletions(-)

diff --git a/COPYING.org b/COPYING.org
index 5e348028f7..5c1243a3a8 100644
--- a/COPYING.org
+++ b/COPYING.org
@@ -1,7 +1,7 @@
 * GNU General Public License
 
 /Version 3, 29 June 2007/
-/Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
+/Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org>/
 
 Everyone is permitted to copy and distribute verbatim copies of this license
 document, but changing it is not allowed.
diff --git a/README.org b/README.org
index 59c6ebcfe1..c81bcdc74d 100644
--- a/README.org
+++ b/README.org
@@ -7,13 +7,13 @@
 #+texinfo_dir_title: colorful-mode: (colorful-mode).
 #+texinfo_dir_desc: Preview color hexs in your buffer
 
-#+html: <img src="./assets/elisp_logo_warning.svg" align="right" width="10%">
+#+html: <img 
src="https://raw.githubusercontent.com/DevelopmentCool2449/emacs-svg-badges/main/elisp_logo_warning.svg";
 align="right" width="10%">
 
-🟠colorful-mode is a minor mode that allow you preview *color hex* and
-*color names*, in your current buffer in a user friendly way based on
-🌈[[https://elpa.gnu.org/packages/rainbow-mode.html][rainbow-mode.el]].
+🟢colorful-mode is a minor mode that allow you preview *color hex* and
+*color names*, in your current buffer in real time and in a user
+friendly way based on 
🌈[[https://elpa.gnu.org/packages/rainbow-mode.html][rainbow-mode.el]].
 
-* Features 🔧
+* Features ✨
 - Preview emacs colors names and hex in your current buffer /(soon
   support for CSS rgb)/.
 - Changing highlighted colors to other formats.
@@ -31,6 +31,30 @@
 #+CAPTION: with a custom prefix (in this example a nerd font character)
 [[./assets/screenshot4.png]]
 
+* User Setup and Guides 📖
+** Customizable User options
+
+- =colorful-allow-mouse-clicks= If non-nil, allow using mouse buttons
+  for change color.
+- =colorful-use-prefix= If non-nil, use prefix for preview color
+  instead highlight them.
+- =colorful-prefix-string= Prefix symbol to be used according
+  =colorful-use-prefix=.
+- =colorful-prefix-alignment= The position to put prefix string.
+The value can be left or right.
+- =colorful-extra-color-keywords-hook= Hook used for add extra color
+  keywords to =colorful-color-keywords=.
+  Available functions are: =colorful-add-color-names=.
+- =global-colorful-modes= Which major modes colorful-mode is switched
+  on in (globally).
+
+** Interactive User Functions.
+- =colorful-change-color= Change color at current cursor position.
+
+** Key bindings
+These key bindings are defined by: =colorful-mode-map=
+- =C-c c= → =colorful-change-color=.
+
 * Installation 📦
 Currently colorful-mode is not available in any elisp package archive,
 however you can install it with =package-vc-install=
@@ -49,11 +73,14 @@ For emacs 30 users you can use =use-package=
 
 * How does it compare to =rainbow-mode=?
 =colorful-mode= improves =rainbow-mode= in adding more features
-and fixing some /(and old)/ bugs.
-
-The intention is to provide a featured alternative to =rainbow.el=
-with a user-friendy approach
+and fixing some /(and old)/ bugs like:
+- The well know issue with hl-line.
+- Deprecated (and some old functions) in source code.
+- Refactoring.
+- &c.
 
+The intention is to provide a featured alternative to
+=rainbow-mode.el= with a user-friendy approach
 
 * Plans for future
 Currently this repo will only be used for feature-request /(i can't
diff --git a/assets/elisp_logo_warning.svg b/assets/elisp_logo_warning.svg
deleted file mode 100644
index f111cc10af..0000000000
--- a/assets/elisp_logo_warning.svg
+++ /dev/null
@@ -1,193 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg:svg
-   width="108.11634"
-   height="167.61635"
-   id="svg2"
-   version="1.1"
-   xml:space="preserve"
-   sodipodi:docname="elisp_logo_warning.svg"
-   inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
-   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
-   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
-   xmlns:xlink="http://www.w3.org/1999/xlink";
-   xmlns:svg="http://www.w3.org/2000/svg";
-   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
-   xmlns:cc="http://creativecommons.org/ns#";
-   xmlns:dc="http://purl.org/dc/elements/1.1/";><sodipodi:namedview
-     id="namedview1"
-     pagecolor="#505050"
-     bordercolor="#ffffff"
-     borderopacity="1"
-     inkscape:showpageshadow="0"
-     inkscape:pageopacity="0"
-     inkscape:pagecheckerboard="1"
-     inkscape:deskcolor="#505050"
-     inkscape:zoom="3.2753368"
-     inkscape:cx="54.040244"
-     inkscape:cy="83.502863"
-     inkscape:window-width="1292"
-     inkscape:window-height="745"
-     inkscape:window-x="66"
-     inkscape:window-y="-8"
-     inkscape:window-maximized="1"
-     inkscape:current-layer="layer1" /><svg:defs
-     id="defs4"><svg:linearGradient
-       id="swatch7"><svg:stop
-         style="stop-color:#000000;stop-opacity:1;"
-         offset="0"
-         id="stop7" /></svg:linearGradient><svg:linearGradient
-       id="linearGradient3"><svg:stop
-         style="stop-color:#57479d;stop-opacity:1;"
-         offset="0.29306534"
-         id="stop3" /><svg:stop
-         style="stop-color:#5b1938;stop-opacity:1;"
-         offset="0.70603013"
-         id="stop4" /></svg:linearGradient><svg:linearGradient
-       id="linearGradient4292"><svg:stop
-         id="stop4294"
-         offset="0"
-         style="stop-color:#411f5d;stop-opacity:1" /><svg:stop
-         id="stop4296"
-         offset="1"
-         style="stop-color:#5b2a85;stop-opacity:1" 
/></svg:linearGradient><svg:linearGradient
-       id="linearGradient4284"><svg:stop
-         offset="0"
-         style="stop-color:#8381c5;stop-opacity:1"
-         id="stop4286" /><svg:stop
-         id="stop4290"
-         style="stop-color:#7e55b3;stop-opacity:0.99607843"
-         offset="0.56639391" /><svg:stop
-         offset="1"
-         style="stop-color:#a52ecb;stop-opacity:0.99215686"
-         id="stop4288" /></svg:linearGradient><svg:linearGradient
-       y2="300.73987"
-       x2="236.61363"
-       y1="-161.8512"
-       x1="-122.20192"
-       spreadMethod="pad"
-       
gradientTransform="matrix(0.08192422,0,0,0.07764193,223.12164,515.26127)"
-       gradientUnits="userSpaceOnUse"
-       id="linearGradient4245"
-       xlink:href="#linearGradient4284" /><svg:linearGradient
-       y2="66.018341"
-       x2="173.94518"
-       y1="396.6066"
-       x1="447.80933"
-       
gradientTransform="matrix(0.09251715,0,0,0.09251715,200.34291,492.03412)"
-       gradientUnits="userSpaceOnUse"
-       id="linearGradient4247"
-       xlink:href="#linearGradient4292" /><svg:linearGradient
-       xlink:href="#linearGradient3"
-       id="linearGradient4"
-       x1="49.641563"
-       y1="464.52335"
-       x2="493.93356"
-       y2="464.52335"
-       gradientUnits="userSpaceOnUse"
-       
gradientTransform="matrix(0.41007792,0,0,0.75165459,154.96263,142.75359)" 
/><svg:clipPath
-       clipPathUnits="userSpaceOnUse"
-       id="clipPath22"><svg:path
-         
style="display:inline;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke-width:0.5;paint-order:fill
 markers stroke"
-         d="m 211.75667,415.81018 c 0.0332,55.84305 -0.0664,111.74112 
0.0498,167.5498 36.00972,-0.0332 72.07446,0.0664 108.0498,-0.0498 
-0.0332,-55.84305 0.0664,-111.74112 -0.0498,-167.5498 -36.0097,0.0332 
-72.0745,-0.0664 -108.0498,0.0498 z"
-         id="path23" /></svg:clipPath><svg:clipPath
-       clipPathUnits="userSpaceOnUse"
-       id="clipPath23"><svg:path
-         
style="display:inline;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke-width:0.5;paint-order:fill
 markers stroke"
-         d="m 211.75667,415.81018 c 0.0332,55.84305 -0.0664,111.74112 
0.0498,167.5498 36.00972,-0.0332 72.07446,0.0664 108.0498,-0.0498 
-0.0332,-55.84305 0.0664,-111.74112 -0.0498,-167.5498 -36.0097,0.0332 
-72.0745,-0.0664 -108.0498,0.0498 z"
-         id="path24" /></svg:clipPath><svg:clipPath
-       clipPathUnits="userSpaceOnUse"
-       id="clipPath24"><svg:path
-         
style="display:inline;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke-width:0.5;paint-order:fill
 markers stroke"
-         d="m 211.75667,415.81018 c 0.0332,55.84305 -0.0664,111.74112 
0.0498,167.5498 36.00972,-0.0332 72.07446,0.0664 108.0498,-0.0498 
-0.0332,-55.84305 0.0664,-111.74112 -0.0498,-167.5498 -36.0097,0.0332 
-72.0745,-0.0664 -108.0498,0.0498 z"
-         id="path25" /></svg:clipPath><svg:clipPath
-       clipPathUnits="userSpaceOnUse"
-       id="clipPath25"><svg:path
-         
style="display:inline;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke-width:0.5;paint-order:fill
 markers stroke"
-         d="m 211.75667,415.81018 c 0.0332,55.84305 -0.0664,111.74112 
0.0498,167.5498 36.00972,-0.0332 72.07446,0.0664 108.0498,-0.0498 
-0.0332,-55.84305 0.0664,-111.74112 -0.0498,-167.5498 -36.0097,0.0332 
-72.0745,-0.0664 -108.0498,0.0498 z"
-         id="path26" /></svg:clipPath></svg:defs><svg:metadata
-     id="metadata7"><rdf:RDF><cc:Work
-         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
-           rdf:resource="http://purl.org/dc/dcmitype/StillImage"; /><cc:license
-           
rdf:resource="https://www.gnu.org/licenses/gpl-3.0.en.html#license-text"; 
/></cc:Work></rdf:RDF></svg:metadata><svg:g
-     id="layer1"
-     style="display:inline"
-     clip-path="none"
-     transform="translate(-211.7483,-415.75201)"><svg:rect
-       
style="display:inline;mix-blend-mode:normal;fill:url(#linearGradient4);stroke:none;stroke-width:1.66557;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
-       id="bg"
-       width="182.19432"
-       height="256.83994"
-       x="175.31953"
-       y="363.49475"
-       rx="7.9409237"
-       ry="5.7339058"
-       clip-path="url(#clipPath25)" /><svg:g
-       id="emacs_logo"
-       transform="matrix(2.1296393,0,0,2.1296393,-1401.8188,446.54059)"
-       style="display:inline"><svg:path
-         d="m 245.83076,515.88126 c 0,12.19324 -9.78462,22.07781 
-21.85454,22.07781 -12.06993,0 -21.85455,-9.88457 -21.85455,-22.07781 
0,-12.19324 9.78462,-22.07781 21.85455,-22.07781 12.06992,0 21.85454,9.88457 
21.85454,22.07781 z"
-         id="path4235"
-         
style="display:inline;opacity:1;fill:url(#linearGradient4245);fill-opacity:1;stroke:url(#linearGradient4247);stroke-width:1.25045;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
-         transform="translate(554.03605,-491.79739)" /><svg:path
-         d="m 770.50076,39.591616 c 0,0 1.85048,0.130907 4.23105,-0.0789 
0.96407,-0.08497 4.62438,-0.444495 7.36096,-1.044646 0,0 3.33655,-0.714065 
5.12157,-1.371877 1.86774,-0.688298 2.88409,-1.272472 3.34156,-2.100227 
-0.0199,-0.169601 0.14085,-0.771036 -0.72047,-1.132302 -2.20206,-0.923624 
-4.75594,-0.75656 -9.80942,-0.863704 -5.60411,-0.192554 -7.46837,-1.130598 
-8.46146,-1.886099 -0.9523,-0.766424 -0.47344,-2.8868 3.60696,-4.75453 
2.05541,-0.994592 10.11286,-2.830029 10.11286,-2.830 [...]
-         id="path4237"
-         
style="display:inline;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
 /></svg:g><svg:rect
-       
style="color:#000000;display:inline;overflow:visible;visibility:visible;opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none"
-       id="rect2291"
-       width="164.28812"
-       height="89.078255"
-       x="185.09084"
-       y="526.96027"
-       clip-path="url(#clipPath24)" /><svg:rect
-       y="369.00781"
-       x="182.95723"
-       height="70.006035"
-       width="164.28812"
-       id="rect3019"
-       
style="color:#000000;display:inline;overflow:visible;visibility:visible;opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.03418;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none"
-       clip-path="url(#clipPath23)" /><svg:path
-       id="path1336"
-       
style="display:inline;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
-       d="M -14.836285,231.54517 629.7647,233.1054 c 10.7279,0 
19.36443,3.40225 19.36443,7.62837 l -7.1988,758.76805 c 0,4.22608 
-8.63653,7.62838 -19.36443,7.62838 L -22.03509,1005.57 c -10.727891,0 
-19.364425,-3.4023 -19.364425,-7.62841 l 7.198805,-758.76805 c 0,-4.22612 
8.636534,-7.62837 19.364425,-7.62837 z M 213.18262,417.13562 H 318.3335 V 
581.61408 H 213.18262 Z"
-       clip-path="url(#clipPath22)" /><svg:text
-       xml:space="preserve"
-       
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:20.1037px;line-height:125%;font-family:'Fira
 Sans';-inkscape-font-specification:'Fira 
Sans';text-align:center;writing-mode:lr-tb;text-anchor:middle;display:inline;overflow:visible;visibility:visible;opacity:1;fill:#8200d7;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.1162;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke
 [...]
-       x="236.00786"
-       y="488.54401"
-       id="text3021"
-       transform="scale(1.125978,0.888117)"><svg:tspan
-         id="tspan3027"
-         x="236.00786"
-         y="488.54401"
-         
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Fira
 Sans';-inkscape-font-specification:'Fira 
Sans'">WARNING</svg:tspan></svg:text><svg:g
-       id="flowRoot3029"
-       style="font-size:13.4385px;line-height:80.6311%;font-family:'Franklin 
Gothic Medium';text-align:center;text-anchor:middle"
-       transform="matrix(1.177743,0,0,1.057864,-46.79483,-29.65303)"
-       aria-label="This product may contain trace amounts of Elisp"><svg:path
-         d="m 234.31788,540.49605 h -1.73231 v -7.57228 h -2.38192 v -1.38453 
h 6.49615 v 1.38453 h -2.38192 z m 8.76652,0 h -1.49608 v -4.33733 q 0,-0.70211 
-0.30184,-0.98426 -0.29528,-0.28872 -0.69555,-0.28872 -0.63649,0 
-1.06957,0.50525 -0.43308,0.50526 -0.43308,1.66669 v 3.43837 h -1.49608 v 
-8.95681 h 1.49608 v 3.49086 q 0.55775,-1.43047 1.95541,-1.43047 2.04071,0 
2.04071,2.34255 z m 3.28745,-7.40167 h -1.49609 v -1.55514 h 1.49609 z m 
0,7.40167 h -1.49609 v -6.62739 h 1.49609 z m 0 [...]
-         id="path14" /><svg:path
-         style="line-height:80.6311%"
-         d="M 265.96528,573.00295 H 260.145 v -8.95682 h 5.76123 v 1.33204 h 
-4.14704 v 2.42786 h 3.33338 v 1.29923 h -3.33338 v 2.50659 h 4.20609 z m 
2.79532,0 h -1.49608 v -8.95682 h 1.49608 z m 3.28744,-7.40168 h -1.49608 v 
-1.55514 h 1.49608 z m 0,7.40168 h -1.49608 v -6.62739 h 1.49608 z m 
0.99083,-1.52233 1.40422,-0.26904 q 0.32153,0.8071 1.41734,0.8071 1.3911,0 
1.3911,-0.82022 0,-0.26247 -0.21654,-0.43308 -0.21654,-0.1706 -0.51182,-0.22966 
l -1.20737,-0.22966 q -2.0079,-0.38714 -2 [...]
-         id="path15" /></svg:g></svg:g><script /><!-- Gnu Emacs Icon
-   Copyright (C) 2008-2017 Free Software Foundation, Inc.
-
-   Author: Nicolas Petton <nico...@petton.fr>
-
-   This file is part of GNU Emacs.
-
-   GNU Emacs is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   GNU Emacs is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
-
---><!-- Created with Inkscape (http://www.inkscape.org/) --><script 
/></svg:svg>
diff --git a/colorful-mode.el b/colorful-mode.el
index a26f5710eb..3675beefdc 100644
--- a/colorful-mode.el
+++ b/colorful-mode.el
@@ -4,7 +4,7 @@
 
 ;; Author: Elias G.B. Perez <eg642...@gmail.com>
 ;; Keywords: faces
-;; Version: 0.1.0
+;; Version: 0.1.1
 
 ;; This file is not part of GNU Emacs.
 
@@ -33,8 +33,8 @@
 (require 'color)
 (require 'rx)
 
-;; Buffer-local variables
 
+;; Buffer-local variables
 (defvar-local colorful-color-keywords
     `((,(rx (seq (not (any "&"))
                  (group "#" (repeat 1 4 (= 3 (any "0-9A-Fa-f"))))
@@ -86,7 +86,6 @@ Must be a list containing regex strings.")
 
 
 ;; Customizable User options.
-
 (defgroup colorful-mode nil
   "Preview hex colors values in current buffer.."
   :tag "Colorful mode"
@@ -96,6 +95,12 @@ Must be a list containing regex strings.")
   '((t (:box (:line-width (1 . 1) :color "grey75" :style flat-button))))
   "Face used as base for highlight color names.")
 
+(defcustom colorful-extra-color-keywords-hook nil
+  "Hook used for add extra color keywords to `colorful-color-keywords'.
+Available functions are: `colorful-add-color-names'."
+  :group 'dashboard
+  :type 'hook)
+
 (defcustom colorful-allow-mouse-clicks t
   "If non-nil, allow using mouse buttons for change color."
   :type 'boolean)
@@ -115,20 +120,13 @@ The value can be left or right."
                  (const :tag "Right" right)))
 
 
-;; Functions
-
-(defun colorful--color-luminance (color)
-  "Calculate the relative luminance of COLOR string.
-Return a value between 0 and 1."
-  (let* ((values (color-values color))
-         (r (/ (nth 0 values) 256.0))
-         (g (/ (nth 1 values) 256.0))
-         (b (/ (nth 2 values) 256.0)))
-    ;; Return computed value
-    (/ (+ (* .2126 r)
-          (* .7152 g)
-          (* .0722 b)
-          255))))
+;; Keymaps
+(defvar-keymap colorful-mode-map
+  :doc "Keymap when `colorful-mode' is active."
+  "C-c c" #'colorful-change-color)
+
+
+;; Internal Functions
 
 ;; (defun colorful--hex-to-rgb (hex)
 ;;   "Return HEX color as CSS rgb format."
@@ -156,11 +154,11 @@ Return a value between 0 and 1."
     (insert text)))
 
 ;;;###autoload
-(defun colorful-change-color (&optional color beg end prompt)
-  "Change COLOR from BEG to END, opcionally use a PROMPT message text."
+(defun colorful-change-color (&optional prompt color beg end)
+  "Change COLOR at current cursor position.
+COLOR, BEG, PROMPT and END are only used as internal values, not intended
+to be used externally."
   (interactive "*")
-  ;; COLOR BEG and END are only used as lexical values,
-  ;; not intended to be used externally.
   (dolist (ov (overlays-at (point)))
     (when (overlay-get ov 'colorful--overlay)
       (setq beg (or beg (overlay-start ov))
@@ -187,23 +185,22 @@ Return a value between 0 and 1."
                    ;; TODO: () ; rgb
                    )
            (colorful-change-color
-            color beg end
-            (format "%s is already a Hex value. Try again: " color))))
+            (format "%s is already a Hex value. Try again: " color)
+            color beg end)))
         ;; ('rgb (unless (string-prefix-p "rgb" color)))
         ('name
          (if (not (assoc color color-name-rgb-alist))
              (cond ((string-prefix-p "#" color) ; Hex
-                    (let ((rep (colorful--hex-to-name color)))
-                      (if rep
-                          (colorful--replace-region beg end rep)
-                        (message "No color name available."))))
+                    (if-let ((rep (colorful--hex-to-name color)))
+                        (colorful--replace-region beg end rep)
+                      (message "No color name available.")))
                    ;; ((string-prefix-p "rgb" color) ; CSS rgb
                    ;; (let ((rep (colorful--hex-to-name color)))
                    ;; (colorful--replace-region beg end rep)))
                    )
            (colorful-change-color
-            color beg end
-            (format "%s is already a color name value. Try again: " color)))))
+            (format "%s is already a color name value. Try again: " color)
+            color beg end))))
     (message "No color found at position.")))
 
 (defun colorful--delete-overlay (overlay &rest _)
@@ -211,9 +208,9 @@ Return a value between 0 and 1."
   (delete-overlay overlay))
 
 (defun colorful--colorize-match (color &optional match)
-  "Return a matched (MATCH) string propertized with a face in BG and END range.
-Propertize with background COLOR value.  The foreground is computed using
-`colorful--color-luminance', and is either white or black."
+  "Return a matched MATCH string propertized with a face.
+The background uses COLOR color value.  The foreground is computed using
+`color-dark-p', and is either white or black."
   (let* ((match (or match 0))
          (start (match-beginning match))
          (end (match-end match))
@@ -222,19 +219,9 @@ Propertize with background COLOR value.  The foreground is 
computed using
     ;; Define colorful overlay tag
     (overlay-put ov 'colorful--overlay t)
 
-    ;; NOTE: Using colorful prefix bugs background color,
-    ;;      this is the way i found for fix this.
-    (when (and colorful-allow-mouse-clicks
-               (not colorful-use-prefix))
-      (overlay-put ov 'mouse-face 'highlight)
-      (overlay-put ov 'keymap
-                   (let ((map (make-sparse-keymap)))
-                     (keymap-set map "<mouse-1>" #'colorful-change-color)
-                     map)))
-
     ;; Delete overlays when they are modified.
     ;; This refresh them with without using `jit-lock-register' or
-    ;; any hook.
+    ;; any other hook.
     (overlay-put ov 'evaporate t)
     (overlay-put ov 'modification-hooks `(colorful--delete-overlay))
     (overlay-put ov 'insert-in-front-hooks `(colorful--delete-overlay))
@@ -259,9 +246,17 @@ Propertize with background COLOR value.  The foreground is 
computed using
       ;; NOTE: This fixs an error for invalid face when using prefix
       (overlay-put ov 'face nil))
      (t
+      ;; NOTE: Using colorful prefix bugs background color,
+      ;;      this is the way i found for fix this.
+      (when colorful-allow-mouse-clicks
+        (overlay-put ov 'mouse-face 'highlight)
+        (overlay-put ov 'keymap
+                     (let ((map (make-sparse-keymap)))
+                       (keymap-set map "<mouse-1>" #'colorful-change-color)
+                       map)))
       (overlay-put ov 'face
                    `((:foreground
-                      ,(if (< 0.0026 (colorful--color-luminance color))
+                      ,(if (color-dark-p (color-name-to-rgb color))
                            "white" "black"))
                      (:background ,color)
                      (:inherit colorful-base)))))))
@@ -278,17 +273,11 @@ Propertize with background COLOR value.  The foreground 
is computed using
 
 
 ;; Extras color regex functions and variables.
-
 (defvar colorful-color-name-font-lock-keywords
   `((,(regexp-opt (defined-colors) 'words)
      (0 (colorful-colorize-itself))))
   "Font-lock keywords to add for `colorful-color-keywords'.")
 
-(defcustom colorful-extra-color-keywords-hook nil
-  "Hook used for add extra color keywords to `colorful-color-keywords'."
-  :group 'dashboard
-  :type 'hook)
-
 (defun colorful-add-color-names ()
   "Function for add Emacs color names to `colorful-color-keywords'.
 This is intended to be used with `colorful-extra-color-keywords-hook'."
@@ -297,7 +286,6 @@ This is intended to be used with 
`colorful-extra-color-keywords-hook'."
 
 
 ;; Minor mode definitions.
-
 (defun colorful--turn-on ()
   "Helper function for turn on `colorful-mode'."
   (run-hooks 'colorful-extra-color-keywords-hook)
@@ -320,8 +308,7 @@ This is intended to be used with 
`colorful-extra-color-keywords-hook'."
 (define-minor-mode colorful-mode
   "Preview color hexs in current buffer.
 This will fontify colors strings like \"#aabbcc\" or \"blue\"."
-  :lighter nil
-  :group 'colorful-mode
+  :lighter nil :group 'colorful-mode :keymap colorful-mode-map
   (if colorful-mode
       (colorful--turn-on)
     (colorful--turn-off)))
@@ -329,9 +316,8 @@ This will fontify colors strings like \"#aabbcc\" or 
\"blue\"."
 ;;;###autoload
 (define-globalized-minor-mode global-colorful-mode
   colorful-mode colorful--turn-on
-  :predicate '(prog-mode text-mode)
-  :group 'corfu)
-
+  :predicate '(prog-mode text-mode) :group 'colorful-mode)
 
+
 (provide 'colorful-mode)
 ;;; colorful-mode.el ends here

Reply via email to