Module colorizer.config
Provides configuration options and utilities for setting up colorizer.
Functions
set_bo_value (bo_type, val, ud_opts) | Set options for a specific buffer or file type. |
apply_alias_options (ud_opts) | Parse and apply alias options to the user options. |
get_setup_options (opts) | Initializes colorizer with user-provided options. |
new_bo_options (bufnr, bo_type) | Retrieve buffer-specific options or user_default_options defined when setup() was called. |
get_bo_options (bo_type, buftype, filetype) | Retrieve options based on buffer type and file type. |
Tables
user_default_options | Default user options for colorizer. |
options | Options for colorizer that were passed in to setup function |
ud_opts | Configuration options for the `setup` function. |
Functions
- set_bo_value (bo_type, val, ud_opts)
-
Set options for a specific buffer or file type.
Parameters:
- bo_type 'buftype'|'filetype': The type of buffer option
- val string: The specific value to set.
- ud_opts table: `user_default_options`
- apply_alias_options (ud_opts)
-
Parse and apply alias options to the user options.
Parameters:
- ud_opts table: user_default_options
Returns:
-
table
- get_setup_options (opts)
-
Initializes colorizer with user-provided options.
Merges default settings with any user-specified options, setting up `filetypes`,
`user_default_options`, and `user_commands`.
Parameters:
- opts table|nil: Configuration options for colorizer.
Returns:
-
table: Final settings after merging user and default options.
- new_bo_options (bufnr, bo_type)
-
Retrieve buffer-specific options or user_default_options defined when setup() was called.
Parameters:
- bufnr number: The buffer number.
- bo_type 'buftype'|'filetype': The type of buffer option
- get_bo_options (bo_type, buftype, filetype)
-
Retrieve options based on buffer type and file type. Prefer filetype.
Parameters:
- bo_type 'buftype'|'filetype': The type of buffer option
- buftype string: Buffer type.
- filetype string: File type.
Returns:
-
table
Tables
- user_default_options
-
Default user options for colorizer.
This table defines individual options and alias options, allowing configuration of
colorizer's behavior for different color formats (e.g., `#RGB`, `#RRGGBB`, `#AARRGGBB`, etc.).
Individual Options: Options like `names`, `RGB`, `RRGGBB`, `RRGGBBAA`, `hsl_fn`, `rgb_fn`, `AARRGGBB`, `tailwind`, and `sass` can be enabled or disabled independently.
Alias Options: `css` and `css_fn` enable multiple options at once. - `css_fn = true` enables `hsl_fn` and `rgb_fn`. - `css = true` enables `names`, `RGB`, `RRGGBB`, `RRGGBBAA`, `hsl_fn`, and `rgb_fn`.
Option Priority: Individual options have higher priority than aliases. If both `css` and `css_fn` are true, `css_fn` has more priority over `css`.
Fields:
- names boolean: Enables named colors (e.g., "Blue").
- names_opts table: Names options for customizing casing, digit stripping, etc
- names_custom table|function|false: Custom color name to RGB value mappings should return a table of color names to RGB value pairs
- RGB boolean: Enables `#RGB` hex codes.
- RGBA boolean: Enables `#RGBA` hex codes.
- RRGGBB boolean: Enables `#RRGGBB` hex codes.
- RRGGBBAA boolean: Enables `#RRGGBBAA` hex codes.
- AARRGGBB boolean: Enables `0xAARRGGBB` hex codes.
- rgb_fn boolean: Enables CSS `rgb()` and `rgba()` functions.
- hsl_fn boolean: Enables CSS `hsl()` and `hsla()` functions.
- css boolean: Enables all CSS features (`rgb_fn`, `hsl_fn`, `names`, `RGB`, `RRGGBB`).
- css_fn boolean: Enables all CSS functions (`rgb_fn`, `hsl_fn`).
- tailwind boolean|string: Enables Tailwind CSS colors (e.g., `"normal"`, `"lsp"`, `"both"`).
- tailwind_opts table: Tailwind options for updating names cache, etc
- sass table: Sass color configuration (`enable` flag and `parsers`).
- mode 'background'|'foreground'|'virtualtext': Display mode
- virtualtext string: Character used for virtual text display.
- virtualtext_inline boolean|'before'|'after': Shows virtual text inline with color.
- virtualtext_mode 'background'|'foreground': Mode for virtual text display.
- always_update boolean: Always update color values, even if buffer is not focused.
- hooks table: Table of hook functions
- disable_line_highlight function: Returns boolean which controls if line should be parsed for highlights
- options
-
Options for colorizer that were passed in to setup function
Fields:
- filetypes
- buftypes
- user_commands
- lazy_load
- user_default_options
- exclusions
- all
- ud_opts
-
Configuration options for the `setup` function.
Fields:
- filetypes (table|nil): Optional. A list of file types where colorizer should be enabled. Use `"*"` for all file types.
- user_default_options
table: Default options for color handling.
- `names` (boolean): Enables named color codes like `"Blue"`. - `names_opts` (table): Names options for customizing casing, digit stripping, etc - `lowercase` (boolean): Converts color names to lowercase. - `camelcase` (boolean): Converts color names to camelCase. This is the default naming scheme for colors returned from `vim.api.nvim_get_color_map` - `uppercase` (boolean): Converts color names to uppercase. - `strip_digits` (boolean): Removes digits from color names. - `names_custom` (table|function|false): Custom color name to RGB value mappings - `RGB` (boolean): Enables support for `#RGB` hex codes. - `RGBA` (boolean): Enables support for `#RGBA` hex codes. - `RRGGBB` (boolean): Enables support for `#RRGGBB` hex codes. - `RRGGBBAA` (boolean): Enables support for `#RRGGBBAA` hex codes. - `AARRGGBB` (boolean): Enables support for `0xAARRGGBB` hex codes. - `rgb_fn` (boolean): Enables CSS `rgb()` and `rgba()` functions. - `hsl_fn` (boolean): Enables CSS `hsl()` and `hsla()` functions. - `css` (boolean): Enables all CSS-related features (e.g., `names`, `RGB`, `RRGGBB`, `hsl_fn`, `rgb_fn`). - `css_fn` (boolean): Enables all CSS function-related features (e.g., `rgb_fn`, `hsl_fn`). - `tailwind` (boolean|string): Enables Tailwind CSS colors. Accepts `true`, `"normal"`, `"lsp"`, or `"both"`. - `tailwind_opts` (table): Tailwind options for updating names cache, etc - `update_names` (boolean): Updates Tailwind "normal" names cache from LSP results. This provides a smoother highlighting experience when tailwind = "both" is used. Highlighting on non-tailwind lsp buffers (like cmp) becomes more consistent. - `sass` (table): Configures Sass color support. - `enable` (boolean): Enables Sass color parsing. - `parsers` (table): A list of parsers to use, typically includes `"css"`. - `mode` (string): Determines the display mode for highlights. Options are `"background"`, `"foreground"`, and `"virtualtext"`. - `virtualtext` (string): Character used for virtual text display of colors (default is `"■"`). - `virtualtext_inline` (boolean|'before'|'after'): Shows the virtual text inline with the color. True defaults to 'before'. - `virtualtext_mode` ('background'|'foreground'): Determines the display mode for virtual text. - `always_update` (boolean): If true, updates color values even if the buffer is not focused.
- `hooks` (table): Table of hook functions - `disable_line_highlight` (function): Returns a boolean that controls if the line should be parsed for highlights. Called with 3 parameters: - `line` (string): The line's contents. - `bufnr` (number): The buffer number. - `line_num` (number): The line number (0-indexed). Add 1 to get the line number in the buffer. - buftypes (table|nil): Optional. A list of buffer types where colorizer should be enabled. Defaults to all buffer types if not provided.
- user_commands (boolean|table): If true, enables all user commands for colorizer. If `false`, disables user commands. Alternatively, provide a table of specific commands to enable: - `"ColorizerAttachToBuffer"` - `"ColorizerDetachFromBuffer"` - `"ColorizerReloadAllBuffers"` - `"ColorizerToggle"`
- lazy_load (boolean): If true, lazily schedule buffer highlighting setup function