Module colorizer.config
Configuration Provides configuration options and utilities for setting up colorizer.
Colorizer supports two configuration formats:
New structured format (recommended): Uses the options key with logically grouped settings under
parsers,display, andhooks.Legacy flat format: Uses the
user_default_optionskey with flat keys likeRGB,RRGGBB,rgb_fn,mode, etc. Always supported. Automatically translated to the new format internally.
NEW FORMAT EXAMPLE ~
lua require("colorizer").setup({
options = {
parsers = {
css = true, -- preset: enables names, hex, rgb, hsl, oklch, css_var
tailwind = { enable = true },
},
display = {
mode = "virtualtext",
virtualtext = { position = "after" },
},
},
}) <
LEGACY FORMAT EXAMPLE ~
lua require("colorizer").setup({
user_default_options = {
css = true,
tailwind = "normal",
mode = "virtualtext",
virtualtext_inline = "after",
},
}) <
PRESETS ~
parsers.css = true enables: names, hex (all), rgb, hsl, oklch, css_var
parsers.css_fn = true enables: rgb, hsl, oklch
Individual settings always override presets:
lua parsers = { css = true, rgb = { enable = false } } -- rgb is disabled despite css preset <
CUSTOM PARSERS ~
Register custom parsers via parsers.custom:
lua parsers = {
custom = {
{
name = "my_parser",
prefixes = { "Color." },
parse = function(ctx)
-- return length, rgb_hex or nil
end,
},
},
} <
Functions
| apply_alias_options (ud_opts) | Parse and apply alias options to the user options (legacy format). |
| apply_presets (user_parsers) | Apply preset expansions to user-provided parsers config. |
| as_flat (opts) | Convert new-format options back to legacy flat format. |
| expand_sass_parsers (sass_parsers) | Build a new-format options table for sass color parsing. |
| get_bo_options (bo_type, buftype, filetype) | Retrieve options based on buffer type and file type. |
| get_setup_options (opts) | Initializes colorizer with user-provided options. |
| is_legacy_options (opts) | Detect if options are in legacy (old flat) format. |
| new_bo_options (bufnr, bo_type) | Retrieve buffer-specific options or default options for a buffer. |
| resolve_options (opts) | Resolve options from any format to canonical new format. |
| set_bo_value (bo_type, val, opts) | Set options for a specific buffer or file type. |
| translate_filetypes (old_ft) | Translate old polymorphic filetypes/buftypes format to new structured format. |
| translate_options (old_opts) | Translate legacy flat options to new structured format. |
| validate_new_options (opts) | Validate new-format options. |
Tables
| options | Options for colorizer that were passed in to setup function. |
Fields
| default_options | Canonical default options (read-only reference for tests/inspection). |
Functions
- apply_alias_options (ud_opts)
- Parse and apply alias options to the user options (legacy format).
- apply_presets (user_parsers)
- Apply preset expansions to user-provided parsers config. Expands css/css_fn presets into individual parser enables, but only for parsers that the user hasn't explicitly configured. Operates on the user's raw options BEFORE merging with defaults.
- as_flat (opts)
- Convert new-format options back to legacy flat format. Used for backward compatibility with code that hasn't been updated yet.
- expand_sass_parsers (sass_parsers)
- Build a new-format options table for sass color parsing. Expands sass.parsers presets into a full options table suitable for matcher.make(). Results are memoized since sass_parsers configs are stable per buffer lifetime.
- get_bo_options (bo_type, buftype, filetype)
- Retrieve options based on buffer type and file type. Prefer filetype.
- get_setup_options (opts)
-
Initializes colorizer with user-provided options.
Merges default settings with any user-specified options, setting up
filetypes,user_default_options, anduser_commands. Accepts both new options key and legacyuser_default_optionskey. - is_legacy_options (opts)
- Detect if options are in legacy (old flat) format.
- new_bo_options (bufnr, bo_type)
- Retrieve buffer-specific options or default options for a buffer.
- resolve_options (opts)
- Resolve options from any format to canonical new format. Accepts new-format options, legacy flat options, or nil (returns defaults). Applies presets and validation.
- set_bo_value (bo_type, val, opts)
- Set options for a specific buffer or file type.
- translate_filetypes (old_ft)
- Translate old polymorphic filetypes/buftypes format to new structured format.
- translate_options (old_opts)
- Translate legacy flat options to new structured format. Returns a partial new-format table containing only the values present in old_opts.
- validate_new_options (opts)
- Validate new-format options. Validates enums, processes names.custom, checks hook types.
Tables
- options
-
Options for colorizer that were passed in to setup function.
After setup(),
M.options.optionsholds the canonical new-format config.M.options.user_default_optionsholds a backward-compatible flat view.