Skip to content

Commit

Permalink
[FEATURE] Add support for sass variables
Browse files Browse the repository at this point in the history
Import support

import using use and import keyword

multiple imports in single line

multiple imports in multiple lines ( using commas )

recursive imports

watch imports for changes and automatically rehighlight buffer

buffer variables

recursive variables support

multiple variables in single line

parse imported files only when they are changed

Loosely based on https://github.com/norcalli/nvim-colorizer.lua/pull/22/files
  • Loading branch information
Akianonymus committed Sep 14, 2022
1 parent dc806df commit f986d9a
Show file tree
Hide file tree
Showing 17 changed files with 744 additions and 200 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ library to do custom highlighting themselves.
-- Available methods are false / true / "normal" / "lsp" / "both"
-- True is same as normal
tailwind = false, -- Enable tailwind colors
-- parsers can contain values used in |user_default_options|
sass = { enable = false, parsers = { css }, }, -- Enable sass colors
virtualtext = "",
},
-- all the sub-options of filetypes apply to buftypes
Expand Down
64 changes: 61 additions & 3 deletions doc/colorizer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ user_default_options *colorizer.user_default_options*
mode = "background", -- Set the display mode.
-- Available methods are false / true / "normal" / "lsp" / "both"
-- True is same as normal
tailwind = false -- Enable tailwind colors
tailwind = false, -- Enable tailwind colors
-- parsers can contain values used in |user_default_options|
sass = { enable = false, parsers = { css }, }, -- Enable sass colors
virtualtext = "■",
}
<
Expand All @@ -226,6 +228,7 @@ user_default_options *colorizer.user_default_options*
{css_fn} - boolean
{mode} - string
{tailwind} - boolean|string
{sass} - table
{virtualtext} - string


Expand Down Expand Up @@ -292,7 +295,7 @@ highlight_buffer({buf}, {ns}, {lines}, {line_start}, {line_end}, {options},
{options_local} - table: Buffer local variables

returns:~
nil or boolean or number,function or nil
nil or boolean or number,table



Expand All @@ -309,7 +312,7 @@ rehighlight_buffer({buf}, {options}, {options_local}, {use_local_lines})
options_local

returns:~
nil or boolean or number,function or nil
nil or boolean or number,table



Expand Down Expand Up @@ -348,6 +351,14 @@ Functions: ~
|color_name_parser| - Grab all the colour values from
`vim.api.nvim_get_color_map` and create a lookup table.

|sass_cleanup| - Cleanup sass variables

|sass_update_variables| - Parse the given lines for sass variabled and add
to SASS[buf].DEFINITIONS_ALL.

|sass_name_parser| - Parse the given line for sass color names
check for value in SASS[buf].DEFINITIONS_ALL

|rgb_function_parser| - Parse for rgb() css function and return rgb hex.

|rgba_function_parser| - Parse for rgba() css function and return rgb hex.
Expand Down Expand Up @@ -390,6 +401,53 @@ color_name_parser({line}, {i}, {opts}) *colorizer.color_utils.color_name_parser*



sass_cleanup({buf}) *colorizer.color_utils.sass_cleanup*
Cleanup sass variables

Parameters: ~
{buf} - number




*colorizer.color_utils.sass_update_variables*
sass_update_variables({buf}, {line_start}, {line_end}, {lines}, {color_parser},
{options}, {options_local})
Parse the given lines for sass variabled and add to
SASS[buf].DEFINITIONS_ALL.

which is then used in |sass_name_parser|
If lines are not given, then fetch the lines with line_start and line_end


Parameters: ~
{buf} - number
{line_start} - number
{line_end} - number
{lines} - table|nil
{color_parser} - function|boolean
{options} - table: Buffer options
{options_local} - table|nil: Buffer local variables

returns:~
boolean



sass_name_parser({line}, {i}, {buf}) *colorizer.color_utils.sass_name_parser*
Parse the given line for sass color names
check for value in SASS[buf].DEFINITIONS_ALL

Parameters: ~
{line} - string: Line to parse
{i} - number: Index of line from where to start parsing
{buf} - number

returns:~
number or nil, string or nil



rgb_function_parser({line}, {i}) *colorizer.color_utils.rgb_function_parser*
Parse for rgb() css function and return rgb hex.

Expand Down
4 changes: 2 additions & 2 deletions doc/modules/colorizer.buffer_utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h3>Parameters:</h3>
<h3>Returns:</h3>
<ol>

nil|boolean|number,function|nil
nil|boolean|number,table
</ol>


Expand Down Expand Up @@ -182,7 +182,7 @@ <h3>Parameters:</h3>
<h3>Returns:</h3>
<ol>

nil|boolean|number,function|nil
nil|boolean|number,table
</ol>


Expand Down
110 changes: 110 additions & 0 deletions doc/modules/colorizer.color_utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ <h2><a href="#Functions">Functions</a></h2>
<tr>
<td class="name" nowrap><a href="#color_name_parser">color_name_parser (line, i, opts)</a></td>
<td class="summary">Grab all the colour values from <code>vim.api.nvim_get_color_map</code> and create a lookup table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sass_cleanup">sass_cleanup (buf)</a></td>
<td class="summary">Cleanup sass variables</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sass_update_variables">sass_update_variables (buf, line_start, line_end, lines, color_parser, options, options_local)</a></td>
<td class="summary">Parse the given lines for sass variabled and add to SASS[buf].DEFINITIONS_ALL.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sass_name_parser">sass_name_parser (line, i, buf)</a></td>
<td class="summary">Parse the given line for sass color names
check for value in SASS[buf].DEFINITIONS_ALL</td>
</tr>
<tr>
<td class="name" nowrap><a href="#rgb_function_parser">rgb_function_parser (line, i)</a></td>
Expand Down Expand Up @@ -155,6 +168,103 @@ <h3>Parameters:</h3>



</dd>
<dt>
<a name = "sass_cleanup"></a>
<strong>sass_cleanup (buf)</strong>
</dt>
<dd>
Cleanup sass variables


<h3>Parameters:</h3>
<ul>
<li><span class="parameter">buf</span>
number
</li>
</ul>





</dd>
<dt>
<a name = "sass_update_variables"></a>
<strong>sass_update_variables (buf, line_start, line_end, lines, color_parser, options, options_local)</strong>
</dt>
<dd>
Parse the given lines for sass variabled and add to SASS[buf].DEFINITIONS<em>ALL.
which is then used in |sass</em>name<em>parser|
If lines are not given, then fetch the lines with line</em>start and line_end


<h3>Parameters:</h3>
<ul>
<li><span class="parameter">buf</span>
number
</li>
<li><span class="parameter">line_start</span>
number
</li>
<li><span class="parameter">line_end</span>
number
</li>
<li><span class="parameter">lines</span>
table|nil
</li>
<li><span class="parameter">color_parser</span>
function|boolean
</li>
<li><span class="parameter">options</span>
table: Buffer options
</li>
<li><span class="parameter">options_local</span>
table|nil: Buffer local variables
</li>
</ul>

<h3>Returns:</h3>
<ol>

boolean
</ol>




</dd>
<dt>
<a name = "sass_name_parser"></a>
<strong>sass_name_parser (line, i, buf)</strong>
</dt>
<dd>
Parse the given line for sass color names
check for value in SASS[buf].DEFINITIONS_ALL


<h3>Parameters:</h3>
<ul>
<li><span class="parameter">line</span>
string: Line to parse
</li>
<li><span class="parameter">i</span>
number: Index of line from where to start parsing
</li>
<li><span class="parameter">buf</span>
number
</li>
</ul>

<h3>Returns:</h3>
<ol>

number|nil, string|nil
</ol>




</dd>
<dt>
<a name = "rgb_function_parser"></a>
Expand Down
7 changes: 6 additions & 1 deletion doc/modules/colorizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ <h2 class="section-header "><a name="Tables"></a>Tables</h2>
mode = "background", -- Set the display mode.
-- Available methods are false / true / "normal" / "lsp" / "both"
-- True is same as normal
tailwind = false -- Enable tailwind colors
tailwind = false, -- Enable tailwind colors
-- parsers can contain values used in |user_default_options|
sass = { enable = false, parsers = { css }, }, -- Enable sass colors
virtualtext = "■",
}
</pre>
Expand Down Expand Up @@ -443,6 +445,9 @@ <h3>Fields:</h3>
<li><span class="parameter">tailwind</span>
boolean|string
</li>
<li><span class="parameter">sass</span>
table
</li>
<li><span class="parameter">virtualtext</span>
string
</li>
Expand Down
87 changes: 0 additions & 87 deletions doc/modules/colorizer.utils.html

This file was deleted.

Loading

0 comments on commit f986d9a

Please sign in to comment.