Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add extra config flag for toggle_keybind support to hide biscuits by default #24

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ EOF

You can show or hide the biscuits by placing a `toggle_keybind` at the root of your config or inside a language config.

We also expose an optional flag, `show_on_start`, to enable biscuits to show on initial load. This value defaults to `false`;

```lua
lua <<EOF
require('nvim-biscuits').setup({
toggle_keybind = "<leader>cb"
toggle_keybind = "<leader>cb",
show_on_start = true -- defaults to false
})
EOF
```
Expand Down
25 changes: 14 additions & 11 deletions lua/nvim-biscuits/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ if not has_ts then error("nvim-treesitter must be installed") end

local ts_parsers = require('nvim-treesitter.parsers')
local ts_utils = require('nvim-treesitter.ts_utils')
local nvim_biscuits = {}

local should_render_biscuits = true
local nvim_biscuits = {should_render_biscuits = true}

local make_biscuit_hl_group_name =
function(lang) return 'BiscuitColor' .. lang end
Expand All @@ -33,7 +31,7 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang)
local biscuit_highlight_group = vim.api.nvim_create_namespace(
biscuit_highlight_group_name)

if not should_render_biscuits then
if not nvim_biscuits.should_render_biscuits then
vim.api.nvim_buf_clear_namespace(bufnr, biscuit_highlight_group, 0, -1)
return
end
Expand Down Expand Up @@ -121,11 +119,10 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang)
vim.api.nvim_buf_clear_namespace(bufnr,
biscuit_highlight_group,
end_line, end_line + 1)
vim.api.nvim_buf_set_extmark(bufnr, biscuit_highlight_group, end_line, 0, {
vim.api.nvim_buf_set_extmark(bufnr, biscuit_highlight_group,
end_line, 0, {
virt_text_pos = "eol",
virt_text = {
{text, biscuit_highlight_group_name}
},
virt_text = {{text, biscuit_highlight_group_name}},
hl_mode = "combine"
})
end
Expand Down Expand Up @@ -178,8 +175,13 @@ nvim_biscuits.BufferAttach = function(bufnr)
vim.cmd("highlight default link " .. make_biscuit_hl_group_name(lang) ..
" BiscuitColor")

-- we need to fire once at the very start
nvim_biscuits.decorate_nodes(bufnr, lang)
-- we need to fire once at the very start if config allows
if toggle_keybind ~= nil and
config.get_language_config(final_config, lang, "show_on_start") == true then
nvim_biscuits.decorate_nodes(bufnr, lang)
else
nvim_biscuits.should_render_biscuits = false
end

local on_events = table.concat(final_config.on_events, ',')
if on_events ~= "" then
Expand Down Expand Up @@ -207,7 +209,8 @@ nvim_biscuits.BufferAttach = function(bufnr)
end

nvim_biscuits.toggle_biscuits = function()
should_render_biscuits = not should_render_biscuits
nvim_biscuits.should_render_biscuits =
not nvim_biscuits.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)
Expand Down