marshalyyx2000 / colorful-mode

🎨Preview any color in your buffer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

./assets/colorful-mode-logo.svg

Available in:

JCS ELPA

🟢colorful-mode is a minor mode that allow you 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 on 🌈rainbow-mode.el.

WARNING: THIS PACKAGE STILL IN A EXPERIMENTAL STATE, ABRUPT CHANGES SUCH AS DELETE USER FUNCTIONS, OPTIONS AND KEYBINDINGS OR UNEXPECTED BREAKS ARE USUALLY COMMON

Features ✨

  • Preview emacs colors names, hexadecimal colors and CSS rgb functions in your current buffer in real time.
  • Replace or copy to other color formats such as hexadecimal or color names.
  • Preview using highlight or a prefix/suffix string.
  • Preview only colors in strings.
  • Exclude colors such as hex values and color names.

Screenshots and animated GIFs 📷

./assets/gif1.gif With prefix instead highliht.

./assets/gif2.gif ./assets/gif3.gif ./assets/screenshot1.png ./assets/screenshot2.png ./assets/screenshot3.png

./assets/screenshot4.png With a custom prefix (in this example a non-ASCII/non-Unicode 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-use-prefix.
  • 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)) colorful-add-hex-colors) List of functions to add extra color keywords to colorful-color-keywords.

    It can be a cons cell specifing 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-add-hex-colors.
    • colorful-add-color-names.
    • colorful-add-rgb-colors.
    • colorful-add-hsl-colors.
  • colorful-exclude-colors (default: '("#def")) List of keyword to don’t highlight.
  • colorful-short-hex-convertions (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

  • colorful-base Face used as base for highlight color names.

Interactive User Functions.

  • colorful-change-or-copy-color Change or copy color to a converted format at current cursor position.
  • colorful-convert-and-change-color Convert color to a valid format and replace color at current cursor position.
  • colorful-convert-and-copy-color Convert color to a valid format and copy it at current cursor position.
  • colorful-mode Buffer-local minor mode.
  • global-colorful-mode Global minor mode.

Key bindings

These key bindings are defined by: colorful-mode-map

  • C-c c ccolorful-change-or-copy-color.
  • C-c c kcolorful-convert-and-copy-color.
  • C-c c rcolorful-convert-and-change-color.

Adding extra colors

Colorful by default provides extra functions that highlight additional colors:

  • colorful-add-hex-colors Add Hexadecimal Colors.
  • colorful-add-color-names Add color names.
  • colorful-add-rgb-colors Add CSS RGB colors.
  • colorful-add-hsl-colors Add CSS HSL 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))

NOTE: colorful-keyword is buffer-local variable.

See: colorful-extra-color-keyword-functions for more details.

Usage and Installation 📦

It’s recommended that you must use emacs-28.X or higher.

For install colorful run:

  • M-x package-install colorful-mode

Or if you prefer using use-package macro:

(use-package colorful-mode
  :ensure t ; <-- Optional
  :hook (prog-mode text-mode)
  ...)

How does it compare to rainbow-mode?

colorful-mode improves rainbow-mode in adding more features and fixing some (and old) bugs:

Comparationcolorful-mode.elrainbow-mode.el
Compatible with hl-line and other overlays?
Convert color to other formats?
Insert open color hex?Work in progress
Opcionally use string prefix/suffix instead highlight
Exclude keywords/colors?1
Allow highlight specifics colors in specific modes2
Opcionally 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 slow.

The intention is to provide a featured alternative to rainbow-mode.el with a user-friendy approach

If you prefer only highlights without color convertion, 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.

Plans for future

Currently this repo will only be used for feature-request, send bug reports, and feedback (i would greatly appreciate this since i’m not expert in elisp).

Due I have plans for submit it to GNU ELPA keep in mind if you want to contribute with a PR you will need assign copyright to FSF, this for make FSF can still maintaining or save the package if this repo gets deleted or something else happen. If you don’t want assign copyright please open an issue and send instructions for your feature/code, so i can implement it without requiring copyright paperwork. Also if your contribution is less than 15 lines [see: Copyright Assignment] you can open a PR and your contribution will be merged quickly. However for people that are willing to doing paperwork you must wait until this package is ready for submit to ELPA, this is for ensure that you are ready for doing paperwork.

Also i will try to make this package as stable as possible before submit it to ELPA, later that I won’t be able to be the mantainer of this package, However I would like if someone would be able to be the mantainer (if you are interested please email me <eg642616@gmail.com>).

Powered by GNU Emacs

Powered by Org Mode

About

🎨Preview any color in your buffer

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 100.0%