Preview any color in your buffer in real time.
π¨ =colorful-mode= is a minor mode that allow you highlight/preview any color format such as color hex and color names, in your current buffer in real time and in a user friendly way based/inspired on π[[https://elpa.gnu.org/packages/rainbow-mode.html][rainbow-mode.el]].
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).
Optionally use a prefix/suffix string instead highlight.
Optionally highlight colors only inside in strings.
Omitting color keywords from being highlighted.
Screenshots and animated GIFs π· [[https://raw.githubusercontent.com/DevelopmentCool2449/colorful-mode/main/assets/gif1.gif]] /With prefix instead highlight/.
[[https://raw.githubusercontent.com/DevelopmentCool2449/colorful-mode/main/assets/gif2.gif]] [[https://raw.githubusercontent.com/DevelopmentCool2449/colorful-mode/main/assets/gif3.gif]] [[https://raw.githubusercontent.com/DevelopmentCool2449/colorful-mode/main/assets/screenshot1.png]] [[https://raw.githubusercontent.com/DevelopmentCool2449/colorful-mode/main/assets/screenshot2.png]]
[[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 π ** Customizable User options
=colorful-allow-mouse-clicks (default: t)= If non-nil, allow using mouse buttons for change color.
=colorful-use-prefix (default: nil)= If non-nil, use prefix for preview color instead highlight them. NOTE: css derived modes by default colorize rgb and hex colors, this may interfere with colorful prefix, you can disable this setting css-fontify-colors to nil
=colorful-prefix-string (default: "β")= String to be used in highlights. Only relevant if `colorful-use-prefix' is non-nil.
=colorful-prefix-alignment (default: 'left)= The position to put prefix string. The value can be left or right. Only relevant if `colorful-use-prefix' is non-nil.
=colorful-extra-color-keyword-functions= default: '((emacs-lisp-mode . colorful-add-color-names) ((mhtml-mode html-ts-mode css-mode css-ts-mode) . (colorful-add-rgb-colors colorful-add-hsl-colors colorful-add-color-names)) (latex-mode . colorful-add-latex-colors) colorful-add-hex-colors) List of functions to add extra color keywords to colorful-color-keywords.
It can be a cons cell specifying the mode (or a list of modes) e.g:
(((css-mode css-ts-mode) . colorful-add-rgb-colors) (emacs-lisp-mode . (colorful-add-color-names colorful-add-rgb-colors)) ((text-mode html-mode) . (colorful-add-color-names colorful-add-rgb-colors)) ...)
Or a simple list of functions for executing wherever colorful is active: (colorful-add-color-names colorful-add-rgb-colors)
Available functions are:
=colorful-exclude-colors (default: '("#def"))= List of keyword to don't highlight.
=colorful-short-hex-conversions (default: 2)= If set to 2, hex values converted by colorful should be as short as possible. Setting this to 2 will make hex values follow a 24-bit specification and can make them inaccurate.
=colorful-only-strings (default: nil)= If non-nil colorful will only highlight colors inside strings. If set to only-prog, only highlight colors in strings if current major mode is derived from prog-mode.
=global-colorful-modes (default: '(mhtml-mode html-ts-mode scss-mode css-mode css-ts-mode prog-mode))= Which major modes global-colorful-mode is switched on in (globally).
** Faces
** Interactive User Functions.
** Key bindings These key bindings are defined by: =colorful-mode-map=
** Adding extra colors Colorful by default provides extra functions that highlight additional colors:
For use them add it to:
;; 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))
See: =colorful-extra-color-keyword-functions= for more details.
For install colorful run:
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=
Or if you prefer using =use-package= macro:
(use-package colorful-mode :ensure t ; Optional :hook (prog-mode text-mode) ...)
Author note: Please add a comparation table with colorful-mode alternatives such as rainbow-mode, built-in css-mode color preview ...
| 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} | β | β |
[1] rainbow-mode (like colorful) uses regex for highlight some keywords, however it cannot exclude specifics colors keywords (such as "#def" that overrides C "#define" keyword). [2] Only for some colors. [3] I didn't a benchmark however due colorful-mode uses overlays instead text properties it can be a bit slow.
The intention is to provide a featured alternative to =rainbow-mode.el= 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=.
On the other hand, if you want convert colors, overlays, optional prefix strings and more features you can use =colorful-mode.el=.