aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkianonymus <anonymus.aki@gmail.com>2022-09-09 09:51:23 +0530
committerAkianonymus <anonymus.aki@gmail.com>2022-09-09 09:51:23 +0530
commita9aacd33ce50961fcf835a4b713e58f8080189ed (patch)
tree37a766e4485f4f0e7df90d31a902e1c65e9f5c1a
parenttailwind: Do not use LspAttach method if vim version <= 7 (diff)
Fix reload on au ColorScheme | Check if buffer is valid before attaching
-rw-r--r--doc/colorizer.txt7
-rw-r--r--doc/modules/colorizer.buffer_utils.html18
-rw-r--r--lua/colorizer.lua12
-rw-r--r--lua/colorizer/buffer_utils.lua6
4 files changed, 42 insertions, 1 deletions
diff --git a/doc/colorizer.txt b/doc/colorizer.txt
index 3dba4d2..05fc8da 100644
--- a/doc/colorizer.txt
+++ b/doc/colorizer.txt
@@ -247,6 +247,8 @@ Helper functions to highlight buffer smartly
LUA API *colorizer.buffer_utils-lua-api*
Functions: ~
+ |clear_hl_cache| - Clean the highlight cache
+
|highlight_buffer| - Highlight the buffer region.
|rehighlight_buffer| - Rehighlight the buffer if colorizer is active
@@ -260,6 +262,11 @@ Fields: ~
`colorizer.attach_to_buffer`.
+clear_hl_cache() *colorizer.buffer_utils.clear_hl_cache*
+ Clean the highlight cache
+
+
+
*colorizer.buffer_utils.highlight_buffer*
highlight_buffer({buf}, {ns}, {lines}, {line_start}, {line_end}, {options},
diff --git a/doc/modules/colorizer.buffer_utils.html b/doc/modules/colorizer.buffer_utils.html
index 315794d..7260c5c 100644
--- a/doc/modules/colorizer.buffer_utils.html
+++ b/doc/modules/colorizer.buffer_utils.html
@@ -62,6 +62,10 @@
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
+ <td class="name" nowrap><a href="#clear_hl_cache">clear_hl_cache ()</a></td>
+ <td class="summary">Clean the highlight cache</td>
+ </tr>
+ <tr>
<td class="name" nowrap><a href="#highlight_buffer">highlight_buffer (buf, ns, lines, line_start, line_end, options, options_local)</a></td>
<td class="summary">Highlight the buffer region.</td>
</tr>
@@ -93,6 +97,20 @@
<dl class="function">
<dt>
+ <a name = "clear_hl_cache"></a>
+ <strong>clear_hl_cache ()</strong>
+ </dt>
+ <dd>
+ Clean the highlight cache
+
+
+
+
+
+
+
+</dd>
+ <dt>
<a name = "highlight_buffer"></a>
<strong>highlight_buffer (buf, ns, lines, line_start, line_end, options, options_local)</strong>
</dt>
diff --git a/lua/colorizer.lua b/lua/colorizer.lua
index 93d21db..f9010c4 100644
--- a/lua/colorizer.lua
+++ b/lua/colorizer.lua
@@ -65,6 +65,7 @@ local buffer_utils = require "colorizer.buffer_utils"
local DEFAULT_NAMESPACE = buffer_utils.DEFAULT_NAMESPACE
local HIGHLIGHT_MODE_NAMES = buffer_utils.HIGHLIGHT_MODE_NAMES
+local clear_hl_cache = buffer_utils.clear_hl_cache
local rehighlight_buffer = buffer_utils.rehighlight_buffer
---Highlight the buffer region
@@ -166,7 +167,12 @@ end
local function is_buffer_attached(buf)
if buf == 0 or buf == nil then
buf = current_buf()
+ else
+ if not api.nvim_buf_is_valid(buf) then
+ return
+ end
end
+
local au = api.nvim_get_autocmds {
group = AUGROUP_ID,
event = { "WinScrolled", "TextChanged", "TextChangedI", "TextChangedP" },
@@ -214,6 +220,10 @@ end
local function attach_to_buffer(buf, options, typ)
if buf == 0 or buf == nil then
buf = current_buf()
+ else
+ if not api.nvim_buf_is_valid(buf) then
+ return
+ end
end
if not options then
@@ -448,7 +458,7 @@ end
--- Clear the highlight cache and reload all buffers.
local function clear_highlight_cache()
- HIGHLIGHT_CACHE = {}
+ clear_hl_cache()
vim.schedule(reload_all_buffers)
end
diff --git a/lua/colorizer/buffer_utils.lua b/lua/colorizer/buffer_utils.lua
index 2f31a2b..a3b3da7 100644
--- a/lua/colorizer/buffer_utils.lua
+++ b/lua/colorizer/buffer_utils.lua
@@ -30,6 +30,11 @@ local HIGHLIGHT_MODE_NAMES = {
}
local HIGHLIGHT_CACHE = {}
+--- Clean the highlight cache
+local function clear_hl_cache()
+ HIGHLIGHT_CACHE = {}
+end
+
--- Make a deterministic name for a highlight given these attributes
local function make_highlight_name(rgb, mode)
return table.concat({ HIGHLIGHT_NAME_PREFIX, HIGHLIGHT_MODE_NAMES[mode], rgb }, "_")
@@ -333,6 +338,7 @@ end
return {
DEFAULT_NAMESPACE = DEFAULT_NAMESPACE,
HIGHLIGHT_MODE_NAMES = HIGHLIGHT_MODE_NAMES,
+ clear_hl_cache = clear_hl_cache,
rehighlight_buffer = rehighlight_buffer,
highlight_buffer = highlight_buffer,
}