From 4c0a11006f5c4c45ebd448d6c0994fe20a2683cd Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Wed, 14 Jul 2021 14:08:30 -0700 Subject: [PATCH 1/4] feat: add option for only showing biscuits on the current cursor line --- README.md | 12 ++++++++++++ lua/nvim-biscuits/init.lua | 19 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7de2fdf..6941f48 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,18 @@ require('nvim-biscuits').setup({ EOF ``` +## Configuration (Cursor Line Only) + +You can configure the biscuits to only show on the line that has your cursor. This can be useful if you find that default config makes the text too cluttered. + +```lua +lua < :lua require("nvim-biscuits").decorate_nodes(%s, "%s") augroup END ]], on_events, bufnr, bufnr, lang), false) + elseif final_config.cursor_line_only == true then + vim.api.nvim_exec(string.format([[ + augroup Biscuits + au! + au %s :lua require("nvim-biscuits").decorate_nodes(%s, "%s") + augroup END + ]], "CursorMoved,CursorMovedI", bufnr, bufnr, lang), false) else vim.api.nvim_buf_attach(bufnr, false, { From 13d1ca2879461665889bf8baa09018a5b979c6bf Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Wed, 14 Jul 2021 14:42:29 -0700 Subject: [PATCH 2/4] fix: handle clearing better to no remove wrong biscuits --- lua/nvim-biscuits/init.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/nvim-biscuits/init.lua b/lua/nvim-biscuits/init.lua index 876d859..e4ccb3d 100644 --- a/lua/nvim-biscuits/init.lua +++ b/lua/nvim-biscuits/init.lua @@ -72,9 +72,8 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang) if should_decorate == false then vim.api.nvim_buf_clear_namespace(bufnr, 0, end_line, - end_line + 2) - else - + end_line + 1) + elseif should_decorate == true then local trim_by_words = config.get_language_config(final_config, lang, "trim_by_words") From 1a38982e99d2e20083940016d4db80f499e08b09 Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Wed, 14 Jul 2021 14:56:19 -0700 Subject: [PATCH 3/4] fix: change how we determine if something should be cleared --- lua/nvim-biscuits/init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/nvim-biscuits/init.lua b/lua/nvim-biscuits/init.lua index e4ccb3d..c99e560 100644 --- a/lua/nvim-biscuits/init.lua +++ b/lua/nvim-biscuits/init.lua @@ -66,14 +66,13 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang) end local cursor = vim.api.nvim_win_get_cursor(0) + local should_clear = false if final_config.cursor_line_only and end_line + 1 ~= cursor[1] then should_decorate = false + should_clear = true end - if should_decorate == false then - vim.api.nvim_buf_clear_namespace(bufnr, 0, end_line, - end_line + 1) - elseif should_decorate == true then + if should_decorate == true then local trim_by_words = config.get_language_config(final_config, lang, "trim_by_words") @@ -115,6 +114,11 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang) }, {}) end end + + if should_decorate == false and should_clear == true then + vim.api.nvim_buf_clear_namespace(bufnr, 0, end_line, + end_line + 1) + end end nodes = children From c30a3cb61ec49a6de042742984fe96067f68afab Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Sun, 18 Jul 2021 12:52:14 -0700 Subject: [PATCH 4/4] fix: use correct namespace when clearing --- lua/nvim-biscuits/init.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lua/nvim-biscuits/init.lua b/lua/nvim-biscuits/init.lua index c99e560..00c577e 100644 --- a/lua/nvim-biscuits/init.lua +++ b/lua/nvim-biscuits/init.lua @@ -12,7 +12,8 @@ local ts_parsers = require('nvim-treesitter.parsers') local ts_utils = require('nvim-treesitter.ts_utils') local nvim_biscuits = {} -local make_biscuit_hl_group = function(lang) return 'BiscuitColor' .. lang end +local make_biscuit_hl_group_name = + function(lang) return 'BiscuitColor' .. lang end nvim_biscuits.decorate_nodes = function(bufnr, lang) if config.get_language_config(final_config, lang, "disabled") then return end @@ -26,7 +27,9 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang) return end - local biscuit_highlight_group = make_biscuit_hl_group(lang) + local biscuit_highlight_group_name = make_biscuit_hl_group_name(lang) + local biscuit_highlight_group = vim.api.nvim_create_namespace( + biscuit_highlight_group_name) local root = parser:parse()[1]:root() local nodes = ts_utils.get_named_children(root) @@ -107,17 +110,20 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang) if utils.trim(text) ~= '' then text = prefix_string .. text - vim.api.nvim_buf_clear_namespace(bufnr, 0, end_line, - end_line + 1) - vim.api.nvim_buf_set_virtual_text(bufnr, 0, end_line, { - {text, biscuit_highlight_group} + vim.api.nvim_buf_clear_namespace(bufnr, + biscuit_highlight_group, + end_line, end_line + 1) + vim.api.nvim_buf_set_virtual_text(bufnr, + biscuit_highlight_group, + end_line, { + {text, biscuit_highlight_group_name} }, {}) end end if should_decorate == false and should_clear == true then - vim.api.nvim_buf_clear_namespace(bufnr, 0, end_line, - end_line + 1) + vim.api.nvim_buf_clear_namespace(bufnr, biscuit_highlight_group, + end_line, end_line + 1) end end @@ -149,7 +155,7 @@ nvim_biscuits.BufferAttach = function(bufnr) local lang = ts_parsers.get_buf_lang(bufnr) local on_lines = function() nvim_biscuits.decorate_nodes(bufnr, lang) end - vim.cmd("highlight default link " .. make_biscuit_hl_group(lang) .. + vim.cmd("highlight default link " .. make_biscuit_hl_group_name(lang) .. " BiscuitColor") -- we need to fire once at the very start