aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkianonymus <anonymus.aki@gmail.com>2022-09-08 13:37:41 +0530
committerAkianonymus <anonymus.aki@gmail.com>2022-09-08 15:37:05 +0530
commit7d3e62087fbbad2dc10d59359f19a42180a19391 (patch)
tree8c03381d06b75b4692fbe6e2d8c1cebc91196797
parenttailwind: Use true for normal mode (diff)
docs: Use name in Last Updated | Cleanup | Improve insert mode perf
Fix highlight not refreshing for last line when tailwind mode is activated
-rw-r--r--doc/colorizer.txt8
-rw-r--r--doc/index.html2
-rw-r--r--doc/modules/colorizer.buffer_utils.html16
-rw-r--r--doc/modules/colorizer.color_utils.html2
-rw-r--r--doc/modules/colorizer.html2
-rw-r--r--doc/modules/colorizer.matcher_utils.html2
-rw-r--r--doc/modules/colorizer.trie.html2
-rw-r--r--doc/modules/utils.html2
-rw-r--r--lua/colorizer.lua11
-rw-r--r--lua/colorizer/buffer_utils.lua50
-rw-r--r--scripts/gen_docs.sh6
11 files changed, 69 insertions, 34 deletions
diff --git a/doc/colorizer.txt b/doc/colorizer.txt
index 1ff8269..3dba4d2 100644
--- a/doc/colorizer.txt
+++ b/doc/colorizer.txt
@@ -262,7 +262,8 @@ Fields: ~
*colorizer.buffer_utils.highlight_buffer*
-highlight_buffer({buf}, {ns}, {lines}, {line_start}, {options}, {options_local})
+highlight_buffer({buf}, {ns}, {lines}, {line_start}, {line_end}, {options},
+{options_local})
Highlight the buffer region.
Highlight starting from `line_start` (0-indexed) for each line described by
@@ -276,6 +277,7 @@ highlight_buffer({buf}, {ns}, {lines}, {line_start}, {options}, {options_local})
it with `vim.api.create_namespace`
{lines} - table: the lines to highlight from the buffer.
{line_start} - number: line_start should be 0-indexed
+ {line_end} - number: Last line to highlight
{options} - table: Configuration options as described in `setup`
{options_local} - table: Buffer local variables
@@ -286,13 +288,15 @@ highlight_buffer({buf}, {ns}, {lines}, {line_start}, {options}, {options_local})
*colorizer.buffer_utils.rehighlight_buffer*
-rehighlight_buffer({buf}, {options}, {options_local})
+rehighlight_buffer({buf}, {options}, {options_local}, {use_local_lines})
Rehighlight the buffer if colorizer is active
Parameters: ~
{buf} - number: Buffer number
{options} - table: Buffer options
{options_local} - table|nil: Buffer local variables
+ {use_local_lines} - boolean|nil Whether to use lines num range from
+ options_local
returns:~
nil or boolean or number,function or nil
diff --git a/doc/index.html b/doc/index.html
index a14a7d8..6042cb2 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -77,7 +77,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
-<i style="float:right;">Last updated 2022-09-07 11:26:36 </i>
+<i style="float:right;">Last updated - September </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/modules/colorizer.buffer_utils.html b/doc/modules/colorizer.buffer_utils.html
index a25f6ef..315794d 100644
--- a/doc/modules/colorizer.buffer_utils.html
+++ b/doc/modules/colorizer.buffer_utils.html
@@ -62,11 +62,11 @@
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
- <td class="name" nowrap><a href="#highlight_buffer">highlight_buffer (buf, ns, lines, line_start, options, options_local)</a></td>
+ <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>
<tr>
- <td class="name" nowrap><a href="#rehighlight_buffer">rehighlight_buffer (buf, options, options_local)</a></td>
+ <td class="name" nowrap><a href="#rehighlight_buffer">rehighlight_buffer (buf, options, options_local, use_local_lines)</a></td>
<td class="summary">Rehighlight the buffer if colorizer is active</td>
</tr>
</table>
@@ -94,7 +94,7 @@
<dl class="function">
<dt>
<a name = "highlight_buffer"></a>
- <strong>highlight_buffer (buf, ns, lines, line_start, options, options_local)</strong>
+ <strong>highlight_buffer (buf, ns, lines, line_start, line_end, options, options_local)</strong>
</dt>
<dd>
Highlight the buffer region.
@@ -116,6 +116,9 @@
<li><span class="parameter">line_start</span>
number: line_start should be 0-indexed
</li>
+ <li><span class="parameter">line_end</span>
+ number: Last line to highlight
+ </li>
<li><span class="parameter">options</span>
table: Configuration options as described in <code>setup</code>
</li>
@@ -136,7 +139,7 @@
</dd>
<dt>
<a name = "rehighlight_buffer"></a>
- <strong>rehighlight_buffer (buf, options, options_local)</strong>
+ <strong>rehighlight_buffer (buf, options, options_local, use_local_lines)</strong>
</dt>
<dd>
Rehighlight the buffer if colorizer is active
@@ -153,6 +156,9 @@
<li><span class="parameter">options_local</span>
table|nil: Buffer local variables
</li>
+ <li><span class="parameter">use_local_lines</span>
+ boolean|nil Whether to use lines num range from options_local
+ </li>
</ul>
<h3>Returns:</h3>
@@ -231,7 +237,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
-<i style="float:right;">Last updated 2022-09-07 11:26:36 </i>
+<i style="float:right;">Last updated - September </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/modules/colorizer.color_utils.html b/doc/modules/colorizer.color_utils.html
index 522999c..a02853b 100644
--- a/doc/modules/colorizer.color_utils.html
+++ b/doc/modules/colorizer.color_utils.html
@@ -351,7 +351,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
-<i style="float:right;">Last updated 2022-09-07 11:26:36 </i>
+<i style="float:right;">Last updated - September </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/modules/colorizer.html b/doc/modules/colorizer.html
index 090c424..3b04ab9 100644
--- a/doc/modules/colorizer.html
+++ b/doc/modules/colorizer.html
@@ -478,7 +478,7 @@ Setup an autocmd which enables colorizing for the filetypes and options specifie
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
-<i style="float:right;">Last updated 2022-09-07 11:26:36 </i>
+<i style="float:right;">Last updated - September </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/modules/colorizer.matcher_utils.html b/doc/modules/colorizer.matcher_utils.html
index 7319be5..5a5514f 100644
--- a/doc/modules/colorizer.matcher_utils.html
+++ b/doc/modules/colorizer.matcher_utils.html
@@ -106,7 +106,7 @@ Do not try make the function again if it is present in the cache
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
-<i style="float:right;">Last updated 2022-09-07 11:26:36 </i>
+<i style="float:right;">Last updated - September </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/modules/colorizer.trie.html b/doc/modules/colorizer.trie.html
index 7f015f7..e5fc981 100644
--- a/doc/modules/colorizer.trie.html
+++ b/doc/modules/colorizer.trie.html
@@ -62,7 +62,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
-<i style="float:right;">Last updated 2022-09-07 11:26:36 </i>
+<i style="float:right;">Last updated - September </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/modules/utils.html b/doc/modules/utils.html
index 6651212..8ff8fed 100644
--- a/doc/modules/utils.html
+++ b/doc/modules/utils.html
@@ -224,7 +224,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
-<i style="float:right;">Last updated 2022-09-07 11:26:36 </i>
+<i style="float:right;">Last updated - September </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/lua/colorizer.lua b/lua/colorizer.lua
index b1786d8..93d21db 100644
--- a/lua/colorizer.lua
+++ b/lua/colorizer.lua
@@ -250,10 +250,17 @@ local function attach_to_buffer(buf, options, typ)
autocmds[#autocmds + 1] = autocmd({ "TextChanged", "TextChangedI", "TextChangedP" }, {
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
- rehighlight_buffer(buf, options, BUFFER_LOCAL[buf])
+ if args.event == "TextChanged" then
+ rehighlight_buffer(buf, options, BUFFER_LOCAL[buf])
+ else
+ local pos = vim.fn.getpos "."
+ BUFFER_LOCAL[buf].__startline = pos[2] - 1
+ BUFFER_LOCAL[buf].__endline = pos[2]
+ rehighlight_buffer(buf, options, BUFFER_LOCAL[buf], true)
+ end
end
end,
})
diff --git a/lua/colorizer/buffer_utils.lua b/lua/colorizer/buffer_utils.lua
index 6feaadb..81994d5 100644
--- a/lua/colorizer/buffer_utils.lua
+++ b/lua/colorizer/buffer_utils.lua
@@ -75,13 +75,8 @@ local function create_highlight(rgb_hex, options)
return highlight_name
end
-local function add_highlight(options, buf, ns, data)
- clear_namespace(
- buf,
- ns,
- BUFFER_LINES[buf]["old_min"] or BUFFER_LINES[buf]["min"],
- BUFFER_LINES[buf]["old_max"] or BUFFER_LINES[buf]["max"]
- )
+local function add_highlight(options, buf, ns, data, line_start, line_end)
+ clear_namespace(buf, ns, line_start, line_end)
if vim.tbl_contains({ "foreground", "background" }, options.mode) then
for linenr, hls in pairs(data) do
@@ -110,9 +105,26 @@ local function highlight_buffer_tailwind(buf, ns, mode, options)
---@diagnostic disable-next-line: param-type-mismatch
vim.lsp.buf_request(buf, "textDocument/documentColor", opts, function(err, results, _, _)
if err == nil and results ~= nil then
- local datas = {}
+ local datas, line_start, line_end = {}, nil, nil
for _, color in pairs(results) do
local cur_line = color.range.start.line
+ if line_start then
+ if cur_line < line_start then
+ line_start = cur_line
+ end
+ else
+ line_start = cur_line
+ end
+
+ local end_line = color.range["end"].line
+ if line_end then
+ if end_line > line_end then
+ line_end = end_line
+ end
+ else
+ line_end = end_line
+ end
+
local r, g, b, a = color.color.red or 0, color.color.green or 0, color.color.blue or 0, color.color.alpha or 0
local rgb_hex = string.format("%02x%02x%02x", r * a * 255, g * a * 255, b * a * 255)
local name = create_highlight(rgb_hex, mode)
@@ -123,7 +135,7 @@ local function highlight_buffer_tailwind(buf, ns, mode, options)
table.insert(d, { name = name, range = { first_col, end_col } })
datas[cur_line] = d
end
- add_highlight(options, buf, ns, datas)
+ add_highlight(options, buf, ns, datas, line_start, line_end + 2)
end
end)
end, 10)
@@ -139,10 +151,11 @@ local TW_LSP_AU_ID = {}
---@param ns number: The namespace id. Default is DEFAULT_NAMESPACE. Create it with `vim.api.create_namespace`
---@param lines table: the lines to highlight from the buffer.
---@param line_start number: line_start should be 0-indexed
+---@param line_end number: Last line to highlight
---@param options table: Configuration options as described in `setup`
---@param options_local table: Buffer local variables
---@return nil|boolean|number,function|nil
-function highlight_buffer(buf, ns, lines, line_start, options, options_local)
+function highlight_buffer(buf, ns, lines, line_start, line_end, options, options_local)
if buf == 0 or buf == nil then
buf = api.nvim_get_current_buf()
end
@@ -172,7 +185,7 @@ function highlight_buffer(buf, ns, lines, line_start, options, options_local)
end
end
end
- add_highlight(options, buf, ns, data)
+ add_highlight(options, buf, ns, data, line_start, line_end)
if not options.tailwind or (options.tailwind ~= "lsp" and options.tailwind ~= "both") then
return
@@ -262,8 +275,6 @@ local function getrow(buf)
-- store current window position to be used later to incremently highlight
BUFFER_LINES[buf]["max"] = new_max
BUFFER_LINES[buf]["min"] = new_min
- BUFFER_LINES[buf]["old_max"] = max
- BUFFER_LINES[buf]["old_min"] = min
return min, max
end
@@ -271,17 +282,24 @@ end
---@param buf number: Buffer number
---@param options table: Buffer options
---@param options_local table|nil: Buffer local variables
+---@param use_local_lines boolean|nil Whether to use lines num range from options_local
---@return nil|boolean|number,function|nil
-function rehighlight_buffer(buf, options, options_local)
+function rehighlight_buffer(buf, options, options_local, use_local_lines)
if buf == 0 or buf == nil then
buf = api.nvim_get_current_buf()
end
local ns = DEFAULT_NAMESPACE
- local min, max = getrow(buf)
+ local min, max
+ if use_local_lines and options_local then
+ min, max = options_local.__startline, options_local.__endline
+ else
+ min, max = getrow(buf)
+ end
+
local lines = buf_get_lines(buf, min, max, false)
- return highlight_buffer(buf, ns, lines, min, options, options_local or {})
+ return highlight_buffer(buf, ns, lines, min, max, options, options_local or {})
end
--- @export
diff --git a/scripts/gen_docs.sh b/scripts/gen_docs.sh
index 3363d42..2be3ec6 100644
--- a/scripts/gen_docs.sh
+++ b/scripts/gen_docs.sh
@@ -15,11 +15,11 @@ create_vim_doc() (
fi
if [[ -d "${target}" ]]; then
- ldoc -p "${project_name}" -t "${project_name} Docs" -u "${target}" -l "${TMP_DIR}" -d "${TMP_DIR}" || cleanup
+ ldoc -p "${project_name}" -t "${project_name} Docs" -u "${target}" -l "${TMP_DIR}" -d "${TMP_DIR}" --date "- $(date +'%B')" || cleanup
cd "${TMP_DIR}/modules" || exit 1
cat "${project_name}".html "${project_name}"*.*.html >"${project_name}".txt || cleanup
elif [[ -f "${target}" ]]; then
- ldoc -p "${project_name}" -t "${project_name} Docs" -u "${target}" -l "${TMP_DIR}" -d "${TMP_DIR}" || cleanup
+ ldoc -p "${project_name}" -t "${project_name} Docs" -u "${target}" -l "${TMP_DIR}" -d "${TMP_DIR}" --date "- $(date +'%B')" || cleanup
cd "${TMP_DIR}" || exit 1
cat index.html >"${project_name}".txt || cleanup
else
@@ -55,7 +55,7 @@ main() {
project_name="colorizer"
if command -v ldoc 1>/dev/null; then
# html docs
- ldoc -f discount -p "${project_name}" -t "${project_name} Docs" -u lua "${@}" -s doc || cleanup
+ ldoc -f discount -p "${project_name}" -t "${project_name} Docs" -u lua "${@}" -s doc --date "- $(date +'%B')" || cleanup
# vim docs
create_vim_doc "${project_name}" lua doc/ldoc_vim.ltp || cleanup