branch: externals/colorful-mode commit 641aac77d003513216403d7f6e2f79fe78b45db2 Author: Elijah Gabe P. <eg642...@gmail.com> Commit: Elijah Gabe P. <eg642...@gmail.com>
Add support for #RGBA and #RRGGBBAA * test/emacs-colors.el: Add tests for #RGBA and #RRGGBBAA. * colorful-mode.el: (colorful-hex-font-lock-keywords) (colorful--colorize-match, colorful--colorize): Add support for hex alpha. * README.org: Clarify, add built-in css-fontify-colors to comparation table and fix typos * CONTRIBUTING.ORG: Clarify and fix typos --- CONTRIBUTING.ORG | 4 +-- README.org | 75 ++++++++++++++++++++++++++++++++-------------------- colorful-mode.el | 26 +++++++++++++----- test/emacs-colors.el | 14 +++++----- 4 files changed, 75 insertions(+), 44 deletions(-) diff --git a/CONTRIBUTING.ORG b/CONTRIBUTING.ORG index 6e7868c9d6..e64dbd46e8 100644 --- a/CONTRIBUTING.ORG +++ b/CONTRIBUTING.ORG @@ -4,8 +4,8 @@ If your contribution is less than 15 lines [see: [[https://www.gnu.org/software/ you can send a patch and your contribution will be reviewed and maybe merged quickly. -If you want send a patch *you will need assign copyright to FSF*, -for this then please email the following information to +However if your contribution is longer *you will need assign copyright to FSF*, +for this then please fill and email the following information to <ass...@gnu.org>, and they will send you the assignment form for your *past and future changes*. diff --git a/README.org b/README.org index 752f7e2621..ab96dc02ee 100644 --- a/README.org +++ b/README.org @@ -25,8 +25,11 @@ in real time and in a user friendly way based/inspired on 🌈[[https://elpa.gnu * Features ✨ - Real time color highlight. -- Supports hexadecimals colors, color names, rgb[a]/hsl[a] and LaTex colors (gray, rbg, RGB, HTML) -- Convert current color at point to other formats such as hexadecimal or color names (only available for some colors). +- Supports hexadecimal (#RRGGBB, #RGB, #RRGGBBAA, #RGBA), color names, rgb(a)/hsl(a) + and LaTex colors (gray, rbg, RGB, HTML) +- Convert current color at point to other formats such as hexadecimal + or color names(only available for some colors) + with mouse click support. - Optionally use a prefix/suffix string instead highlight. - Optionally highlight colors only inside in strings. - Omitting color keywords from being highlighted. @@ -43,7 +46,7 @@ in real time and in a user friendly way based/inspired on 🌈[[https://elpa.gnu [[https://raw.githubusercontent.com/DevelopmentCool2449/colorful-mode/main/assets/screenshot3.png]] /With a custom prefix (in this example a custom character)/. -* User Options, Setups and Guides 📖 +* User Options 🔧 ** Customizable User options - =colorful-allow-mouse-clicks (default: t)= If non-nil, allow using mouse buttons for change color. @@ -118,9 +121,23 @@ These key bindings are defined by: =colorful-mode-map= - =C-x c c= → =colorful-convert-and-copy-color=. - =C-x c r= → =colorful-convert-and-change-color=. -** Adding extra colors -Colorful by default provides extra functions that highlight additional -colors: +* Setups and Guides 📖 + +** Enabling colors to specifics major-modes +If you want to use css rgb colors outside css-derived modes, you +can add them to `colorful-extra-color-keyword-functions' in your config. + +#+begin_src elisp + (add-to-list 'colorful-extra-color-keyword-functions '(insert-your-major-mode . colorful-add-rgb-colors)) +#+end_src + +If you want also use hsl and rgb together you can use this +#+begin_src elisp + (add-to-list 'colorful-extra-color-keyword-functions '(insert-your-major-mode . (colorful-add-rgb-colors colorful-add-hsl-colors))) +#+end_src + +colorful provides extra functions out-the-box that enable additional +highlighting: - =colorful-add-hex-colors= Add Hexadecimal Colors. - =colorful-add-color-names= Add color names. @@ -128,12 +145,6 @@ colors: - =colorful-add-hsl-colors= Add CSS HSL colors. - =colorful-add-latex-colors= Add LaTex rgb/RGB/HTML/Grey colors. -For use them add it to: -#+begin_src emacs-lisp -;; In this example add emacs color names only for yaml-mode and derived. - (add-to-list 'colorful-extra-color-keyword-functions '(yaml-mode . colorful-add-color-names)) -#+end_src - See: =colorful-extra-color-keyword-functions= for more details. * Usage and Installation 📦 @@ -142,15 +153,17 @@ It's recommended that you must use emacs-28.x or higher. For install colorful run: - =M-x package-install colorful-mode= -Once you have it installed you can run colorful locally in your buffer -with =M-x colorful-mode=, if want enable it globally without using -hooks then you can do =M-x global-colorful-mode= +Once you have it installed you can activate colorful locally in your +buffer with =M-x colorful-mode=, if want enable it globally without +using hooks then you can do =M-x global-colorful-mode= Or if you prefer using =use-package= macro: #+begin_src emacs-lisp + (use-package colorful-mode :ensure t ; Optional :hook (prog-mode text-mode) + ;; :config (global-colorful-mode) ; Enable it globally ...) #+end_src @@ -159,19 +172,20 @@ Or if you prefer using =use-package= macro: Author note: Please add a comparation table with colorful-mode alternatives such as rainbow-mode, built-in css-mode color preview ... #+END_COMMENT -* How does it compare to =rainbow-mode=? -=colorful-mode= improves =rainbow-mode= in adding more features -and fixing some /(and old)/ bugs: - -| Comparation | colorful-mode.el | rainbow-mode.el | -|-------------------------------------------------------+------------------+-----------------| -| Compatible with hl-line and other overlays? | ✓ | ❌ | -| Convert color to other formats? | ✓ | ❌ | -| Optionally use string prefix/suffix instead highlight | ✓ | ❌ | -| Exclude keywords/colors? | ✓ | ❌^{1} | -| Allow highlight specifics colors in specific modes | ✓ | ✓^{2} | -| Optionally highlight only in strings | ✓ | ❌ | -| No performance issues?^{3} | ❌ | ✓ | + +* How does it compare to =rainbow-mode= or built-in =css fontify colors=? +=colorful-mode= improves =rainbow-mode= and =css-fontify-colors= in adding more features: + +| Comparation | colorful-mode.el | rainbow-mode.el | built-in css-fontify-colors | +|-------------------------------------------------------+------------------+-----------------+-----------------------------| +| Compatible with hl-line and other overlays? | ✓ | ❌ | ❌ | +| Convert color to other formats? | ✓ | ❌ | ❌ | +| Optionally use string prefix/suffix instead highlight | ✓ | ❌ | ❌ | +| Exclude keywords/colors? | ✓ | ❌^{1} | ❌ | +| Allow highlight specifics colors in specific modes | ✓ | ✓^{2} | ❌ | +| Optionally highlight only in strings | ✓ | ❌ | ❌ | +| No performance issues?^{3} | ❌ | ✓ | ✓ | +| | | | | #+begin_src text [1] rainbow-mode (like colorful) uses regex for highlight some keywords, however it cannot exclude specifics colors keywords @@ -182,11 +196,14 @@ and fixing some /(and old)/ bugs: #+end_src The intention is to provide a featured alternative to -=rainbow-mode.el= with a user-friendly approach. +=rainbow-mode.el= and =css-fontify-colors= with a user-friendly approach. If you prefer only highlights without color conversion, prefix/suffix string indicator and/or anything else you can use =rainbow-mode.el=. +or something built-in and just for css then use built-in +css-fontify-colors which is activated by default + On the other hand, if you want convert colors, overlays, optional prefix strings and more features you can use =colorful-mode.el=. * [[https://raw.githubusercontent.com/DevelopmentCool2449/colorful-mode/main/CONTRIBUITING.org][How to Contribute]] diff --git a/colorful-mode.el b/colorful-mode.el index 9341631281..e2f3e7adbc 100644 --- a/colorful-mode.el +++ b/colorful-mode.el @@ -489,15 +489,14 @@ PROMPT must be a string with 1 format control (generally a string argument)." (defun colorful--colorize-match (color beg end) "Overlay match with a face from BEG to END. The background uses COLOR color value. The foreground is obtained -bu `readable-foreground-color' and it can be white or black." +from `readable-foreground-color' and it can be white or black." ;; Delete duplicates overlays found (dolist (ov (overlays-in beg end)) (if (overlay-get ov 'colorful--overlay) (colorful--delete-overlay ov))) - (when-let* (color - (ov (make-overlay beg end nil t t)) - (map (make-sparse-keymap))) + (let* ((ov (make-overlay beg end nil t t)) + (map (make-sparse-keymap))) (if colorful-allow-mouse-clicks (keymap-set map "<mouse-1>" (if buffer-read-only @@ -578,20 +577,33 @@ converted to a Hex color." ((string-prefix-p "{gray}{" string) (setq string (colorful--latex-gray-to-hex string))) + ((string-prefix-p "#" string) + (setq string (cond + ;; Check if hex is #RRGGBBAA or #RGBA and then + ;; ignore their Alpha hex values. + ((length= string 9) ; For #RRGGBBAA + (substring string 0 7)) + ((length= string 5) ; For #RGBA + (substring string 0 4)) + ;; Otherwise, just pass it. + (t string)))) + (t (setq string (string-replace "0x" "#" string)))) - (colorful--colorize-match string beg end))) + ;; Ensure that is a valid color and that string is non-nil + (if (and string (color-defined-p string)) + (colorful--colorize-match string beg end)))) ;;;; Extra coloring definitions (defvar colorful-hex-font-lock-keywords `((,(rx (seq (not (any "&")) - (group (or "#" "0x") (repeat 1 4 (= 3 (any "0-9A-Fa-f")))) + (group (or "#" "0x") (repeat 1 14 (any "0-9A-Fa-f"))) word-boundary)) (1 (colorful--colorize 1))) (,(rx (seq bol - (group (or "#" "0x") (repeat 1 4 (= 3 (any "0-9A-Fa-f")))) + (group (or "#" "0x") (repeat 1 14 (any "0-9A-Fa-f"))) word-boundary)) (0 (colorful--colorize))) (,(rx (seq (any "Rr") (any "Gg") (any "Bb") ":" diff --git a/test/emacs-colors.el b/test/emacs-colors.el index 04171182c9..7c8f7ce7aa 100644 --- a/test/emacs-colors.el +++ b/test/emacs-colors.el @@ -4,17 +4,14 @@ ;; Color name Test for colorful-mode ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;;; `0x' Syntax - +;;; `0xRRGGBB' Syntax 0x152364 "0x152364" 0x1f1d2e "0x1f1d2e" 0x26233a "0x26233a" 0xdef124 "0xdef124" 0xf00 "0xf00" -;;; `#' Syntax - +;;; `#RRGGBB' Syntax #152364 "#152364" #1f1d2e "#1f1d2e" #26233a "#26233a" @@ -22,8 +19,13 @@ #f00 "#f00" #def "#def" ; <- Should not be highlighted -;;; Color names +;;; `#RRGGBBAA' Syntax +#152364CC "#152364CC" + +;;; `#RGBA' Syntax +#f00C "#f00C" +;;; Color names red "red" blue "blue" orange "orange"