From 500a778ead6e3bd6a82b51baca43a843753ef86a Mon Sep 17 00:00:00 2001 From: Julian V Date: Fri, 10 Mar 2023 18:15:41 +0100 Subject: [PATCH 1/3] Add buf_states table to update function --- lua/smartcolumn.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lua/smartcolumn.lua b/lua/smartcolumn.lua index 85566ad..47ab9d1 100644 --- a/lua/smartcolumn.lua +++ b/lua/smartcolumn.lua @@ -35,6 +35,7 @@ local function exceed(buf, win, min_colorcolumn) return not is_disabled() and max_column > min_colorcolumn end +local buf_states = {} local function update() local buf_filetype = vim.api.nvim_buf_get_option(0, "filetype") local colorcolumns = @@ -54,14 +55,18 @@ local function update() for _, win in pairs(wins) do local buf = vim.api.nvim_win_get_buf(win) if buf == current_buf then - if exceed(buf, win, min_colorcolumn) then - if type(colorcolumns) == "table" then - vim.wo[win].colorcolumn = table.concat(colorcolumns, ",") + local current_state = exceed(buf, win, min_colorcolumn) + if current_state ~= buf_states[buf] then + buf_states[buf] = current_state + if current_state then + if type(colorcolumns) == "table" then + vim.wo[win].colorcolumn = table.concat(colorcolumns, ",") + else + vim.wo[win].colorcolumn = colorcolumns + end else - vim.wo[win].colorcolumn = colorcolumns + vim.wo[win].colorcolumn = nil end - else - vim.wo[win].colorcolumn = nil end end end From cb7875f3af4f1de044345840e2f8f54a3d8bfa10 Mon Sep 17 00:00:00 2001 From: Julian V Date: Tue, 21 Mar 2023 15:39:54 +0100 Subject: [PATCH 2/3] Fix README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e516687..acdc97b 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ The available options: - `{ "80", "100" }` - `disabled_filetypes` (table of strings) : the `colorcolumn` will be disabled under the filetypes in this table - `{ "help", "text", "markdown" }` (default) - - `{ "NvimTree", "Lazy", "mason", "help" }` + - `{ "NvimTree", "lazy", "mason", "help" }` - `scope` (strings): the plugin only checks whether the lines within scope exceed colorcolumn - `"file"` (default): current file - `"window"`: visible part of current window From 531c68f14f890d27fdffee5978ab62df4cc0d33b Mon Sep 17 00:00:00 2001 From: m4xshen Date: Wed, 22 Mar 2023 00:51:29 +0800 Subject: [PATCH 3/3] Use `vim.b` to store buffer state --- lua/smartcolumn.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/smartcolumn.lua b/lua/smartcolumn.lua index 47ab9d1..3b55c7e 100644 --- a/lua/smartcolumn.lua +++ b/lua/smartcolumn.lua @@ -35,7 +35,6 @@ local function exceed(buf, win, min_colorcolumn) return not is_disabled() and max_column > min_colorcolumn end -local buf_states = {} local function update() local buf_filetype = vim.api.nvim_buf_get_option(0, "filetype") local colorcolumns = @@ -56,8 +55,8 @@ local function update() local buf = vim.api.nvim_win_get_buf(win) if buf == current_buf then local current_state = exceed(buf, win, min_colorcolumn) - if current_state ~= buf_states[buf] then - buf_states[buf] = current_state + if current_state ~= vim.b.prev_state then + vim.b.prev_state = current_state if current_state then if type(colorcolumns) == "table" then vim.wo[win].colorcolumn = table.concat(colorcolumns, ",")