Skip to content

Commit

Permalink
Fix/112 aliases application (#115)
Browse files Browse the repository at this point in the history
* doc: updates readme

* ref: reset config cache when setting up colorizer

* fix: correctly apply alias value to it's target options

* doc: updates docs

* ref: simplifies setup configuration

* ref: refactor config options

* ref: calling colorizer.setup should re-initialize config.options

* ref: refactors names parser

* ref: refactors config module
  • Loading branch information
catgoose authored Dec 24, 2024
1 parent b8ed35b commit cbbd548
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 341 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ library to do custom highlighting themselves.
names = true, -- "Name" codes like Blue or blue
-- Expects a table of color name to rgb value pairs. # is optional
-- Example: { cool = "#107dac", ["notcool"] = "ee9240" }
names_custom = nil, -- Extra names to be highlighted: table|function|nil
-- Set to false|nil to disable
names_custom = false, -- Custom names to be highlighted: table|function|false|nil
RGB = true, -- #RGB hex codes
RRGGBB = true, -- #RRGGBB hex codes
RRGGBBAA = false, -- #RRGGBBAA hex codes
Expand Down Expand Up @@ -167,10 +168,10 @@ MODES:
For basic setup, you can use a command like the following.

```lua
-- Attaches to every FileType mode
-- Attaches to every FileType with default options
require("colorizer").setup()

-- Attach to certain Filetypes, add special configuration for `html`
-- Attach to certain Filetypes, add special `mode` configuration for `html`
-- Use `background` for everything else.
require("colorizer").setup({
filetypes = {
Expand All @@ -180,8 +181,8 @@ require("colorizer").setup({
},
})

-- Use the `default_options` as the second parameter, which uses
-- `foreground` for every mode. This is the inverse of the previous
-- Use `user_default_options` as the second parameter, which uses
-- `background` for every mode. This is the inverse of the previous
-- setup configuration.
require("colorizer").setup({
filetypes = {
Expand All @@ -192,9 +193,7 @@ require("colorizer").setup({
user_default_options = { mode = "background" },
})

-- Use the `default_options` as the second parameter, which uses
-- `foreground` for every mode. This is the inverse of the previous
-- setup configuration.
-- Use default for all filetypes with overrides for css and html
require("colorizer").setup({
filetypes = {
"*", -- Highlight all files, but customize some others.
Expand All @@ -208,7 +207,7 @@ require("colorizer").setup({
filetypes = {
"*", -- Highlight all files, but customize some others.
"!vim", -- Exclude vim from highlighting.
-- Exclusion Only makes sense if '*' is specified!
-- Exclusion Only makes sense if '*' is specified first!
},
})

Expand Down Expand Up @@ -332,10 +331,10 @@ Alternatively, use the following script from root directory:
scripts/start_minimal.sh
```

To test colorization with your config, edit `test/expect.txt` to see expected
To test colorization with your config, edit `test/expect.lua` to see expected
highlights.
The returned table of `user_default_options` from `text/expect.txt` will be used
to conveniently reattach Colorizer to `test/expect.txt` on save.
The returned table of `user_default_options` from `text/expect.lua` will be used
to conveniently reattach Colorizer to `test/expect.lua` on save.

## Extras

Expand All @@ -348,7 +347,6 @@ Documentaion is generated using ldoc. See
- [ ] Add more display modes. E.g - sign column
- [ ] Use a more space efficient trie implementation.
- [ ] Support custom parsers
- [ ] Allow custom color names

## Similar projects

Expand Down
110 changes: 51 additions & 59 deletions doc/colorizer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -437,29 +437,47 @@ Provides configuration options and utilities for setting up colorizer.
LUA API *colorizer.config-lua-api*

Functions: ~
|get_settings| - Initializes colorizer with user-provided options.
|set_bo_value| - Set options for a specific buffer or file type.

|new_buffer_options| - Retrieve default options or buffer-specific options.
|apply_alias_options| - Parse and apply alias options to the user options.

|get_options| - Retrieve options based on buffer type and file type.
|get_setup_options| - Initializes colorizer with user-provided options.

|set_bo_value| - Set options for a specific buffer or file type.
|new_bo_options| - Retrieve buffer-specific options or user_default_options
defined when setup() was called.

|parse_buffer_options| - Parse buffer Configuration and convert aliases to
normal values
|get_bo_options| - Retrieve options based on buffer type and file type.

Tables: ~
|user_default_options| - Default user options for colorizer.

|setup_options| - Options for colorizer that were passed in to setup
function

|default_options| - Plugin default options cache from vim.deepcopy
|options| - Options for colorizer that were passed in to setup function

|opts| - Configuration options for the `setup` function.


get_settings({opts}) *colorizer.config.get_settings*
set_bo_value({bo_type}, {value}, {options}) *colorizer.config.set_bo_value*
Set options for a specific buffer or file type.

Parameters: ~
{bo_type} - 'buftype'|'filetype': The type of buffer option
{value} - string: The specific value to set.
{options} - table: Options to associate with the value.



apply_alias_options({options}) *colorizer.config.apply_alias_options*
Parse and apply alias options to the user options.

Parameters: ~
{options} - table: user_default_options

returns:~
table



get_setup_options({opts}) *colorizer.config.get_setup_options*
Initializes colorizer with user-provided options.

Merges default settings with any user-specified options, setting up
Expand All @@ -468,23 +486,26 @@ get_settings({opts}) *colorizer.config.get_settings*


Parameters: ~
{opts} - opts User-provided configuration options.
{opts} - table: Configuration options for colorizer.

returns:~
table Final settings after merging user and default options.



new_buffer_options({bufnr}, {bo_type}) *colorizer.config.new_buffer_options*
Retrieve default options or buffer-specific options.
new_bo_options({bufnr}, {bo_type}) *colorizer.config.new_bo_options*
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_options({bo_type}, {buftype}, {filetype}) *colorizer.config.get_options*

*colorizer.config.get_bo_options*
get_bo_options({bo_type}, {buftype}, {filetype})
Retrieve options based on buffer type and file type.
Prefer filetype.

Expand All @@ -499,27 +520,6 @@ get_options({bo_type}, {buftype}, {filetype}) *colorizer.config.get_options*



set_bo_value({bo_type}, {value}, {options}) *colorizer.config.set_bo_value*
Set options for a specific buffer or file type.

Parameters: ~
{bo_type} - 'buftype'|'filetype': The type of buffer option
{value} - string: The specific value to set.
{options} - table: Options to associate with the value.



parse_buffer_options({options}) *colorizer.config.parse_buffer_options*
Parse buffer Configuration and convert aliases to normal values

Parameters: ~
{options} - table: options table

returns:~
table



user_default_options *colorizer.config.user_default_options*
Default user options for colorizer.

Expand Down Expand Up @@ -569,21 +569,17 @@ user_default_options *colorizer.config.user_default_options*



setup_options *colorizer.config.setup_options*
options *colorizer.config.options*
Options for colorizer that were passed in to setup function

Fields: ~
{exclusions} - table
{all} - table
{default_options} - table
{user_commands} - boolean
{filetypes} - table
{buftypes} - table



default_options *colorizer.config.default_options*
Plugin default options cache from vim.deepcopy
{setup_options} -
{exclusions} -
{all} -
{default_options} -
{user_commands} -
{filetypes} -
{buftypes} -



Expand All @@ -597,7 +593,7 @@ opts *colorizer.config.opts*
- `RGB` (boolean): Enables support for `#RGB` hex codes.
- `RRGGBB` (boolean): Enables support for `#RRGGBB` hex codes.
- `names` (boolean): Enables named color codes like `"Blue"`.
- `names_custom` (table|function): Extra color name to RGB value mappings
- `names_custom` (table|function|nil): Extra color name to RGB value mappings
- `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.
Expand Down Expand Up @@ -689,13 +685,11 @@ This module provides a parser for identifying and converting `hsl()` and
LUA API *colorizer.parser.hsl-lua-api*

Functions: ~
|hsl_function_parser| - Parses `hsl()` and `hsla()` CSS functions and
converts them to RGB hexadecimal format.
|parser| - Parses `hsl()` and `hsla()` CSS functions and converts them to
RGB hexadecimal format.



*colorizer.parser.hsl.hsl_function_parser*
hsl_function_parser({line}, {i}, {opts})
parser({line}, {i}, {opts}) *colorizer.parser.hsl.parser*
Parses `hsl()` and `hsla()` CSS functions and converts them to RGB
hexadecimal format.

Expand Down Expand Up @@ -862,13 +856,11 @@ This module provides a parser for identifying and converting `rgb()` and
LUA API *colorizer.parser.rgb-lua-api*

Functions: ~
|rgb_function_parser| - Parses `rgb()` and `rgba()` CSS functions and
converts them to RGB hexadecimal format.

|parser| - Parses `rgb()` and `rgba()` CSS functions and converts them to
RGB hexadecimal format.


*colorizer.parser.rgb.rgb_function_parser*
rgb_function_parser({line}, {i}, {opts})
parser({line}, {i}, {opts}) *colorizer.parser.rgb.parser*
Parses `rgb()` and `rgba()` CSS functions and converts them to RGB
hexadecimal format.

Expand Down
Loading

0 comments on commit cbbd548

Please sign in to comment.