From c05824e72878dd6b48ba4a24507534351d522b8a Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Sun, 11 Jul 2021 13:18:05 -0700 Subject: [PATCH 1/2] feature: add togglability and documentation --- README.md | 31 +++++++++++++++++++++++++++++++ lua/nvim-biscuits/init.lua | 24 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/README.md b/README.md index 7de2fdf..575e119 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,37 @@ require('nvim-biscuits').setup({ EOF ``` +## Configuration (Keybinding to toggle visibility) + +You can show or hide the biscuits by placing a `toggle_keybind` at the root of your config or inside a language config. + +```lua +lua <", + {noremap = false}) + end + local on_lines = function() nvim_biscuits.decorate_nodes(bufnr, lang) end vim.cmd("highlight default link " .. make_biscuit_hl_group(lang) .. @@ -164,4 +181,11 @@ nvim_biscuits.BufferAttach = function(bufnr) end end +nvim_biscuits.toggle_biscuits = function() + should_render_biscuits = not should_render_biscuits + local bufnr = vim.api.nvim_get_current_buf() + local lang = ts_parsers.get_buf_lang(bufnr) + nvim_biscuits.decorate_nodes(bufnr, lang) +end + return nvim_biscuits From 75ee66a835b010ba54fc95a3c52149a21c259e9f Mon Sep 17 00:00:00 2001 From: Chris Griffing Date: Sun, 18 Jul 2021 13:05:22 -0700 Subject: [PATCH 2/2] fix: use proper namespace when clearing --- lua/nvim-biscuits/init.lua | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lua/nvim-biscuits/init.lua b/lua/nvim-biscuits/init.lua index ff10928..6072aa1 100644 --- a/lua/nvim-biscuits/init.lua +++ b/lua/nvim-biscuits/init.lua @@ -14,16 +14,12 @@ local nvim_biscuits = {} local should_render_biscuits = true -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 - if not should_render_biscuits then - vim.api.nvim_buf_clear_namespace(bufnr, 0, 0, -1) - return - end - utils.console_log("decorating nodes") local parser = ts_parsers.get_parser(bufnr, lang) @@ -33,7 +29,15 @@ 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) + + if not should_render_biscuits then + vim.api.nvim_buf_clear_namespace(bufnr, biscuit_highlight_group, 0, -1) + return + end + local root = parser:parse()[1]:root() local nodes = ts_utils.get_named_children(root) @@ -108,10 +112,13 @@ 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 else @@ -157,7 +164,7 @@ nvim_biscuits.BufferAttach = function(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