aboutsummaryrefslogtreecommitdiff
path: root/lua/colorizer.lua
diff options
context:
space:
mode:
authorAkianonymus <anonymus.aki@gmail.com>2022-09-09 23:55:43 +0530
committerAki <anonymus.aki@gmail.com>2022-09-14 11:47:08 +0530
commitf986d9a0ea1feff1388b5c7d297ec3faa19036a7 (patch)
tree501de10a0709883b9facfb26960f59a181b58d01 /lua/colorizer.lua
parentbuffer_utils: Do not error when lsp info cannot be fetched (diff)
[FEATURE] Add support for sass variables
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
Diffstat (limited to 'lua/colorizer.lua')
-rw-r--r--lua/colorizer.lua42
1 files changed, 31 insertions, 11 deletions
diff --git a/lua/colorizer.lua b/lua/colorizer.lua
index 4af765c..90b964a 100644
--- a/lua/colorizer.lua
+++ b/lua/colorizer.lua
@@ -108,7 +108,9 @@ local BUFFER_LOCAL = {}
-- 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>
@@ -124,6 +126,7 @@ local BUFFER_LOCAL = {}
--@field css_fn boolean
--@field mode string
--@field tailwind boolean|string
+--@field sass table
--@field virtualtext string
local USER_DEFAULT_OPTIONS = {
RGB = true,
@@ -137,6 +140,7 @@ local USER_DEFAULT_OPTIONS = {
css_fn = false,
mode = "background",
tailwind = false,
+ sass = { enable = false, parsers = { css = true } },
virtualtext = "■",
}
@@ -198,10 +202,13 @@ local function detach_from_buffer(buf, ns)
clear_namespace(buf, ns or DEFAULT_NAMESPACE, 0, -1)
if BUFFER_LOCAL[buf] then
- if BUFFER_LOCAL[buf].__tailwind_ns then
- clear_namespace(buf, BUFFER_LOCAL[buf].__tailwind_ns, 0, -1)
- if type(BUFFER_LOCAL[buf].__tailwind_detach) == "function" then
- BUFFER_LOCAL[buf].__tailwind_detach()
+ for _, namespace in pairs(BUFFER_LOCAL[buf].__detach.ns) do
+ clear_namespace(buf, namespace, 0, -1)
+ end
+
+ for _, f in pairs(BUFFER_LOCAL[buf].__detach.functions) do
+ if type(f) == "function" then
+ f(buf)
end
end
@@ -210,6 +217,7 @@ local function detach_from_buffer(buf, ns)
end
BUFFER_LOCAL[buf].__autocmds = nil
+ BUFFER_LOCAL[buf].__detach = nil
end
-- because now the buffer is not visible, so delete its information
BUFFER_OPTIONS[buf] = nil
@@ -253,9 +261,13 @@ local function attach_to_buffer(buf, options, typ)
BUFFER_OPTIONS[buf] = options
BUFFER_LOCAL[buf] = BUFFER_LOCAL[buf] or {}
- local tailwind_ns, tailwind_detach = rehighlight_buffer(buf, options)
- BUFFER_LOCAL[buf].__tailwind_ns = BUFFER_LOCAL[buf].__tailwind_ns or tailwind_ns
- BUFFER_LOCAL[buf].__tailwind_detach = BUFFER_LOCAL[buf].__tailwind_detach or tailwind_detach
+ local highlighted, returns = rehighlight_buffer(buf, options)
+
+ if not highlighted then
+ return
+ end
+
+ BUFFER_LOCAL[buf].__detach = BUFFER_LOCAL[buf].__detach or returns.detach
BUFFER_LOCAL[buf].__init = true
@@ -266,13 +278,20 @@ local function attach_to_buffer(buf, options, typ)
local autocmds = {}
local au_group_id = AUGROUP_ID
- autocmds[#autocmds + 1] = autocmd({ "TextChanged", "TextChangedI", "TextChangedP" }, {
+ local text_changed_au = { "TextChanged", "TextChangedI", "TextChangedP" }
+ -- only enable InsertLeave in sass, rest don't require it
+ if options.sass and options.sass.enable then
+ table.insert(text_changed_au, "InsertLeave")
+ end
+
+ autocmds[#autocmds + 1] = autocmd(text_changed_au, {
group = au_group_id,
buffer = buf,
callback = function(args)
-- only reload if it was not disabled using detach_from_buffer
if BUFFER_OPTIONS[buf] then
- if args.event == "TextChanged" then
+ BUFFER_LOCAL[buf].__event = args.event
+ if args.event == "TextChanged" or args.event == "InsertLeave" then
rehighlight_buffer(buf, options, BUFFER_LOCAL[buf])
else
local pos = vim.fn.getpos "."
@@ -287,9 +306,10 @@ local function attach_to_buffer(buf, options, typ)
autocmds[#autocmds + 1] = autocmd({ "WinScrolled" }, {
group = au_group_id,
buffer = buf,
- callback = function()
+ callback = function(args)
-- only reload if it was not disabled using detach_from_buffer
if BUFFER_OPTIONS[buf] then
+ BUFFER_LOCAL[buf].__event = args.event
rehighlight_buffer(buf, options, BUFFER_LOCAL[buf])
end
end,