From 28b41de2f491ef598197823c04fc7e86ae76a625 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Sun, 28 Aug 2022 12:30:35 +0530 Subject: fragment | Implement better autocmd management | refactor add a all_buffers option - colorizer will activate on all buffers, empty or not, still respect filetypes option handle errors when detach is called multiple times from the same buffer use bufdelete and bufdelete to remove the autocmds use a more efficient compile parse_fn function use custom ldoc template to generate vim help --- doc/modules/colorizer.buffer_utils.html | 222 +++++++++++++++++++ doc/modules/colorizer.color_utils.html | 355 +++++++++++++++++++++++++++++++ doc/modules/colorizer.html | 293 ++++++++++++++++--------- doc/modules/colorizer.matcher_utils.html | 113 ++++++++++ doc/modules/colorizer.trie.html | 69 ++++++ doc/modules/colorizer.utils.html | 87 ++++++++ doc/modules/nvim.html | 66 ------ doc/modules/trie.html | 27 ++- doc/modules/utils.html | 231 ++++++++++++++++++++ 9 files changed, 1293 insertions(+), 170 deletions(-) create mode 100644 doc/modules/colorizer.buffer_utils.html create mode 100644 doc/modules/colorizer.color_utils.html create mode 100644 doc/modules/colorizer.matcher_utils.html create mode 100644 doc/modules/colorizer.trie.html create mode 100644 doc/modules/colorizer.utils.html delete mode 100644 doc/modules/nvim.html create mode 100644 doc/modules/utils.html (limited to 'doc/modules') diff --git a/doc/modules/colorizer.buffer_utils.html b/doc/modules/colorizer.buffer_utils.html new file mode 100644 index 0000000..f2f75fe --- /dev/null +++ b/doc/modules/colorizer.buffer_utils.html @@ -0,0 +1,222 @@ + + + + + colorizer Docs + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module colorizer.buffer_utils

+

Helper functions to highlight buffer smartly

+

+ +

+ + +

Functions

+ + + + + + + + + +
highlight_buffer (buf, ns, lines, line_start, options)Highlight the buffer region.
rehighlight_buffer (buf, options)Rehighlight the buffer if colorizer is active
+

Tables

+ + + + + +
HIGHLIGHT_MODE_NAMESHighlight mode which will be use to render the colour
+

Fields

+ + + + + +
DEFAULT_NAMESPACEDefault namespace used in highlight_buffer and colorizer.attach_to_buffer.
+ +
+
+ + +

Functions

+ +
+
+ + highlight_buffer (buf, ns, lines, line_start, options) +
+
+ Highlight the buffer region. + Highlight starting from line_start (0-indexed) for each line described by lines in the + buffer buf and attach it to the namespace ns. + + +

Parameters:

+
    +
  • buf + number: buffer id +
  • +
  • ns + number: The namespace id. Default is DEFAULT_NAMESPACE. Create it with vim.api.create_namespace +
  • +
  • lines + table: the lines to highlight from the buffer. +
  • +
  • line_start + number: line_start should be 0-indexed +
  • +
  • options + table: Configuration options as described in setup +
  • +
+ + + + + +
+
+ + rehighlight_buffer (buf, options) +
+
+ Rehighlight the buffer if colorizer is active + + +

Parameters:

+
    +
  • buf + number: Buffer number +
  • +
  • options + table: Buffer options +
  • +
+ + + + + +
+
+

Tables

+ +
+
+ + HIGHLIGHT_MODE_NAMES +
+
+ Highlight mode which will be use to render the colour + + +

Fields:

+
    +
  • background + + + +
  • +
  • foreground + + + +
  • +
  • virtualtext + + + +
  • +
+ + + + + +
+
+

Fields

+ +
+
+ + DEFAULT_NAMESPACE +
+
+ Default namespace used in highlight_buffer and colorizer.attach_to_buffer. + + + + + +

See also:

+ + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2022-09-03 17:24:13 +
+
+ + diff --git a/doc/modules/colorizer.color_utils.html b/doc/modules/colorizer.color_utils.html new file mode 100644 index 0000000..613185c --- /dev/null +++ b/doc/modules/colorizer.color_utils.html @@ -0,0 +1,355 @@ + + + + + colorizer Docs + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module colorizer.color_utils

+

Helper functions to parse different colour formats

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
color_is_bright (r, g, b)Determine whether to use black or white text.
color_name_parser (line, i)Grab all the colour values from vim.api.nvim_get_color_map and create a lookup table.
rgb_function_parser (line, i)Parse for rgb() css function and return rgb hex.
rgba_function_parser (line, i)Parse for rgba() css function and return rgb hex.
hsl_function_parser (line, i)Parse for hsl() css function and return rgb hex.
hsla_function_parser (line, i)Parse for hsl() css function and return rgb hex.
argb_hex_parser (line, i)parse for 0xaarrggbb and return rgb hex.
rgba_hex_parser (line, i, opts)parse for #rrggbbaa and return rgb hex.
+ +
+
+ + +

Functions

+ +
+
+ + color_is_bright (r, g, b) +
+
+ Determine whether to use black or white text.

+ +

ref: https://stackoverflow.com/a/1855903/837964 + https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color + + +

Parameters:

+
    +
  • r + number: Red +
  • +
  • g + number: Green +
  • +
  • b + number: Blue +
  • +
+ + + + + +
+
+ + color_name_parser (line, i) +
+
+ Grab all the colour values from vim.api.nvim_get_color_map and create a lookup table. + COLOR_MAP is used to store the colour values + + +

Parameters:

+
    +
  • line + string: Line to parse +
  • +
  • i + number: Index of line from where to start parsing +
  • +
+ + + + + +
+
+ + rgb_function_parser (line, i) +
+
+ Parse for rgb() css function and return rgb hex. + + +

Parameters:

+
    +
  • line + string: Line to parse +
  • +
  • i + number: Index of line from where to start parsing +
  • +
+ +

Returns:

+
    +
  1. + number|nil: Index of line where the rgb function ended
  2. +
  3. + string|nil: rgb hex value
  4. +
+ + + + +
+
+ + rgba_function_parser (line, i) +
+
+ Parse for rgba() css function and return rgb hex. + Todo consider removing the regexes here + Todo this might not be the best approach to alpha channel. + Things like pumblend might be useful here. + + +

Parameters:

+
    +
  • line + string: Line to parse +
  • +
  • i + number: Index of line from where to start parsing +
  • +
+ +

Returns:

+
    +
  1. + number|nil: Index of line where the rgba function ended
  2. +
  3. + string|nil: rgb hex value
  4. +
+ + + + +
+
+ + hsl_function_parser (line, i) +
+
+ Parse for hsl() css function and return rgb hex. + + +

Parameters:

+
    +
  • line + string: Line to parse +
  • +
  • i + number: Index of line from where to start parsing +
  • +
+ +

Returns:

+
    +
  1. + number|nil: Index of line where the hsl function ended
  2. +
  3. + string|nil: rgb hex value
  4. +
+ + + + +
+
+ + hsla_function_parser (line, i) +
+
+ Parse for hsl() css function and return rgb hex. + + +

Parameters:

+
    +
  • line + string: Line to parse +
  • +
  • i + number: Index of line from where to start parsing +
  • +
+ +

Returns:

+
    +
  1. + number|nil: Index of line where the hsla function ended
  2. +
  3. + string|nil: rgb hex value
  4. +
+ + + + +
+
+ + argb_hex_parser (line, i) +
+
+ parse for 0xaarrggbb and return rgb hex. + a format used in android apps + + +

Parameters:

+
    +
  • line + string: line to parse +
  • +
  • i + number: index of line from where to start parsing +
  • +
+ +

Returns:

+
    +
  1. + number|nil: index of line where the hex value ended
  2. +
  3. + string|nil: rgb hex value
  4. +
+ + + + +
+
+ + rgba_hex_parser (line, i, opts) +
+
+ parse for #rrggbbaa and return rgb hex. + a format used in android apps + + +

Parameters:

+
    +
  • line + string: line to parse +
  • +
  • i + number: index of line from where to start parsing +
  • +
  • opts + table: Containing minlen, maxlen, valid_lengths +
  • +
+ +

Returns:

+
    +
  1. + number|nil: index of line where the hex value ended
  2. +
  3. + string|nil: rgb hex value
  4. +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2022-09-03 17:24:13 +
+
+ + diff --git a/doc/modules/colorizer.html b/doc/modules/colorizer.html index e02d18a..3db15a7 100644 --- a/doc/modules/colorizer.html +++ b/doc/modules/colorizer.html @@ -3,7 +3,7 @@ - Reference + colorizer Docs @@ -24,7 +24,7 @@ @@ -49,42 +52,114 @@

Module colorizer

+

Requires Neovim >= 0.6.0 and set termguicolors

Highlights terminal CSI ANSI color codes.

-

+

See also:

+ +

Usage:

+ +

Info:

+

Functions

- - + + - - + + - + - + + + + + + + + + - - + +
highlight_buffer (buf[, ns=DEFAULT_NAMESPACE], lines, line_start, options)Highlight the buffer region.highlight_buffer ()Highlight the buffer region
attach_to_buffer ([buf=0|nil[, options]])Attach to a buffer and continuously highlight changes.is_buffer_attached (buf)Check if attached to a buffer.
detach_from_buffer ([buf=0|nil[, ns=DEFAULT_NAMESPACE]])detach_from_buffer (buf, ns) Stop highlighting the current buffer.
setup ([filetypes={'*'}[, default_options]])attach_to_buffer (buf, options, typ)Attach to a buffer and continuously highlight changes.
setup (config) Easy to use function if you want the full setup without fine grained control.
get_buffer_options (buf)Return the currently active buffer options.
reload_all_buffers () Reload all of the currently active highlighted buffers.
get_buffer_options ([buf=0|nil])Return the currently active buffer options.clear_highlight_cache ()Clear the highlight cache and reload all buffers.

Fields

- +
DEFAULT_NAMESPACEDefault namespace used in `highlight_buffer` and `attach_to_buffer`.Default namespace used in colorizer.buffer_utils.highlight_buffer and attach_to_buffer.
@@ -97,97 +172,92 @@
- highlight_buffer (buf[, ns=DEFAULT_NAMESPACE], lines, line_start, options) + highlight_buffer ()
- Highlight the buffer region. -Highlight starting from `line_start` (0-indexed) for each line described by `lines` in the -buffer `buf` and attach it to the namespace `ns`. + Highlight the buffer region + + +

See also:

+ + + +
+
+ + is_buffer_attached (buf) +
+
+ Check if attached to a buffer. + +

Parameters:

  • buf - integer - buffer id. -
  • -
  • ns - integer - the namespace id. Create it with `vim.api.create_namespace` - (default DEFAULT_NAMESPACE) -
  • -
  • lines - {string,...} - the lines to highlight from the buffer. -
  • -
  • line_start - integer - should be 0-indexed -
  • -
  • options - Configuration options as described in `setup` + number|nil: A value of 0 implies the current buffer.
+

Returns:

+
    + + number|nil: if attached to the buffer, false otherwise. +

See also:

- - attach_to_buffer ([buf=0|nil[, options]]) + + detach_from_buffer (buf, ns)
- Attach to a buffer and continuously highlight changes. + Stop highlighting the current buffer.

Parameters:

  • buf - integer - A value of 0 implies the current buffer. - (default 0|nil) + number|nil: buf A value of 0 or nil implies the current buffer.
  • -
  • options - Configuration options as described in `setup` - (optional) +
  • ns + number|nil: ns the namespace id, if not given DEFAULT_NAMESPACE is used
-

See also:

-
- - detach_from_buffer ([buf=0|nil[, ns=DEFAULT_NAMESPACE]]) + + attach_to_buffer (buf, options, typ)
- Stop highlighting the current buffer. + Attach to a buffer and continuously highlight changes.

Parameters:

  • buf - integer - A value of 0 or nil implies the current buffer. - (default 0|nil) + integer: A value of 0 implies the current buffer.
  • -
  • ns - integer - the namespace id. - (default DEFAULT_NAMESPACE) +
  • options + table: Configuration options as described in setup +
  • +
  • typ + string|nil: "buf" or "file" - The type of buffer option
@@ -198,34 +268,52 @@ buffer `buf` and attach it to the namespace `ns`.
- setup ([filetypes={'*'}[, default_options]]) + setup (config)
- Easy to use function if you want the full setup without fine grained control. - Setup an autocmd which enables colorizing for the filetypes and options specified. -

By default highlights all FileTypes. -

Example config: - ``` - { 'scss', 'html', css = { rgb_fn = true; }, javascript = { no_names = true } } - ``` -

You can combine an array and more specific options. - Possible options: - - `no_names`: Don't highlight names like Blue - - `rgb_fn`: Highlight `rgb(...)` functions. - - `mode`: Highlight mode. Valid options: `foreground`,`background` + +

Easy to use function if you want the full setup without fine grained control. +Setup an autocmd which enables colorizing for the filetypes and options specified.

+ +

By default highlights all FileTypes.

+ +

Example config:~

+ +
+  { filetypes = { "css", "html" }, user_default_options = { names = true } }
+
+ +

Setup with all the default options:~

+ +
+    require("colorizer").setup {
+      filetypes = { "*" },
+      user_default_options = {
+        RGB = true, -- #RGB hex codes
+        RRGGBB = true, -- #RRGGBB hex codes
+        names = true, -- "Name" codes like Blue or blue
+        RRGGBBAA = false, -- #RRGGBBAA hex codes
+        AARRGGBB = false, -- 0xAARRGGBB hex codes
+        rgb_fn = false, -- CSS rgb() and rgba() functions
+        hsl_fn = false, -- CSS hsl() and hsla() functions
+        css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
+        css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn
+        -- Available modes for mode: foreground, background,  virtualtext
+        mode = "background", -- Set the display mode.
+        virtualtext = "■",
+      },
+      -- all the sub-options of filetypes apply to buftypes
+      buftypes = {},
+    }
+
+

Parameters:

    -
  • filetypes - A table/array of filetypes to selectively enable and/or customize. By default, enables all filetypes. - (default {'*'}) -
  • -
  • default_options - {[string]=string} - Default options to apply for the filetypes enable. - (optional) +
  • config + table: Config containing above parameters.
@@ -234,9 +322,29 @@ buffer `buf` and attach it to the namespace `ns`.

Usage:

    -
    require'colorizer'.setup()
    +
    require'colorizer'.setup()
+
+
+ + get_buffer_options (buf) +
+
+ Return the currently active buffer options. + + +

Parameters:

+
    +
  • buf + number|nil: Buffer number +
  • +
+ + + + +
@@ -253,21 +361,13 @@ buffer `buf` and attach it to the namespace `ns`.
- - get_buffer_options ([buf=0|nil]) + + clear_highlight_cache ()
- Return the currently active buffer options. + Clear the highlight cache and reload all buffers. -

Parameters:

-
    -
  • buf - integer - A value of 0 or nil implies the current buffer. - (default 0|nil) -
  • -
@@ -283,8 +383,7 @@ buffer `buf` and attach it to the namespace `ns`. DEFAULT_NAMESPACE
- Default namespace used in `highlight_buffer` and `attach_to_buffer`. - The name is "terminal_highlight" + Default namespace used in colorizer.buffer_utils.highlight_buffer and attach_to_buffer. @@ -292,7 +391,7 @@ buffer `buf` and attach it to the namespace `ns`.

See also:

@@ -305,7 +404,7 @@ buffer `buf` and attach it to the namespace `ns`.
generated by LDoc 1.4.6 -Last updated 2019-10-18 09:40:19 +Last updated 2022-09-03 17:24:13
diff --git a/doc/modules/colorizer.matcher_utils.html b/doc/modules/colorizer.matcher_utils.html new file mode 100644 index 0000000..e709932 --- /dev/null +++ b/doc/modules/colorizer.matcher_utils.html @@ -0,0 +1,113 @@ + + + + + colorizer Docs + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module colorizer.matcher_utils

+

Helper functions for colorizer to enable required parsers

+

+ +

+ + +

Functions

+ + + + + +
make_matcher (options)Parse the given options and return a function with enabled parsers.
+ +
+
+ + +

Functions

+ +
+
+ + make_matcher (options) +
+
+ Parse the given options and return a function with enabled parsers. +if no parsers enabled then return false +Do not try make the function again if it is present in the cache + + +

Parameters:

+ + +

Returns:

+
    + + function|boolean: function which will just parse the line for enabled parsers +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2022-09-03 17:24:13 +
+
+ + diff --git a/doc/modules/colorizer.trie.html b/doc/modules/colorizer.trie.html new file mode 100644 index 0000000..0261786 --- /dev/null +++ b/doc/modules/colorizer.trie.html @@ -0,0 +1,69 @@ + + + + + colorizer Docs + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module colorizer.trie

+

Trie implementation in luajit.

+

todo: write documentation

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.4.6 +Last updated 2022-09-03 17:24:13 +
+
+ + diff --git a/doc/modules/colorizer.utils.html b/doc/modules/colorizer.utils.html new file mode 100644 index 0000000..9bca259 --- /dev/null +++ b/doc/modules/colorizer.utils.html @@ -0,0 +1,87 @@ +============================================================================== +UTILS *colorizer.utils* + +Helper utils + + +============================================================================== +LUA API *colorizer.utils* + +Available Functions: + + |colorizer.utils.byte_is_alphanumeric| - Obvious + + |colorizer.utils.byte_is_hex| - Obvious + + |colorizer.utils.merge| - Merge two tables + TODO Remove this and use vim.tbl_deep_extend + + |colorizer.utils.parse_hex| - Obvious + + |colorizer.utils.percent_or_hex| - Obvious + + + +byte_is_alphanumeric({byte}) |colorizer.utils.byte_is_alphanumeric| + Obvious + + + Parameters: + {byte} - number + + Returns: + boolean + + + +byte_is_hex({byte}) |colorizer.utils.byte_is_hex| + Obvious + + + Parameters: + {byte} - number + + Returns: + boolean + + + +merge({...}) |colorizer.utils.merge| + Merge two tables + TODO Remove this and use vim.tbl_deep_extend + + + Parameters: + {...} - + + Returns: + table + + + +parse_hex({byte}) |colorizer.utils.parse_hex| + Obvious + + + Parameters: + {byte} - number + + Returns: + number + + + +percent_or_hex({v}) |colorizer.utils.percent_or_hex| + Obvious + + + Parameters: + {v} - string + + Returns: + number|nil + + + + + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/doc/modules/nvim.html b/doc/modules/nvim.html deleted file mode 100644 index 8009822..0000000 --- a/doc/modules/nvim.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - - Reference - - - - -
- -
- -
-
-
- - -
- - - - - - -
- -

Module nvim

-

Module of magic functions for nvim

-

- - - -
-
- - - - -
-
-
-generated by LDoc 1.4.6 -Last updated 2019-10-18 09:40:19 -
-
- - diff --git a/doc/modules/trie.html b/doc/modules/trie.html index 5496cfd..e353630 100644 --- a/doc/modules/trie.html +++ b/doc/modules/trie.html @@ -3,7 +3,7 @@ - Reference + colorizer Docs @@ -24,7 +24,7 @@ @@ -44,9 +47,19 @@

Module trie

-

Trie implementation in luajit - Copyright © 2019 Ashkan Kiani

-

+

Trie implementation in luajit.

+

Copyright © 2019 Ashkan Kiani + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version.

+ +

This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/.

@@ -60,7 +73,7 @@
generated by LDoc 1.4.6 -Last updated 2019-10-18 09:40:19 +Last updated 2022-09-02 21:37:16
diff --git a/doc/modules/utils.html b/doc/modules/utils.html new file mode 100644 index 0000000..3e3ff4d --- /dev/null +++ b/doc/modules/utils.html @@ -0,0 +1,231 @@ + + + + + colorizer Docs + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module utils

+

Helper utils

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + +
byte_is_alphanumeric (byte)Obvious.
byte_is_hex (byte)Obvious.
merge (...)Merge two tables.
parse_hex (byte)Obvious.
percent_or_hex (v)Obvious.
+ +
+
+ + +

Functions

+ +
+
+ + byte_is_alphanumeric (byte) +
+
+ Obvious. + + +

Parameters:

+
    +
  • byte + number +
  • +
+ +

Returns:

+
    + + boolean +
+ + + + +
+
+ + byte_is_hex (byte) +
+
+ Obvious. + + +

Parameters:

+
    +
  • byte + number +
  • +
+ +

Returns:

+
    + + boolean +
+ + + + +
+
+ + merge (...) +
+
+ Merge two tables.

+ +

todo: Remove this and use vim.tbl_deep_extend + + +

Parameters:

+
    +
  • ... + + + +
  • +
+ +

Returns:

+
    + + table +
+ + + + +
+
+ + parse_hex (byte) +
+
+ Obvious. + + +

Parameters:

+
    +
  • byte + number +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + percent_or_hex (v) +
+
+ Obvious. + + +

Parameters:

+
    +
  • v + string +
  • +
+ +

Returns:

+
    + + number|nil +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.4.6 +Last updated 2022-09-03 17:24:13 +
+
+ + -- cgit v1.2.3-70-g09d2