Skip to content

Commit

Permalink
Merge pull request #18 from code-biscuits/feature-add-togglability
Browse files Browse the repository at this point in the history
feature: add togglability and documentation
  • Loading branch information
cmgriffing authored Jul 21, 2021
2 parents 6377663 + 455726d commit f2b266f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,41 @@ 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 <<EOF
require('nvim-biscuits').setup({
toggle_keybind = "<leader>cb"
})
EOF
```

OR

```lua
lua <<EOF
require('nvim-biscuits').setup({
language_config = {
rust = {
toggle_keybind = "<leader>cb"
}
}
})
EOF
```

If you prefer to bind manually, the function is exposed as:

```lua
require('nvim-biscuits').toggle_biscuits()
```

## 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.
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 <<EOF
Expand Down
25 changes: 25 additions & 0 deletions lua/nvim-biscuits/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ local ts_parsers = require('nvim-treesitter.parsers')
local ts_utils = require('nvim-treesitter.ts_utils')
local nvim_biscuits = {}

local should_render_biscuits = true

local make_biscuit_hl_group_name =
function(lang) return 'BiscuitColor' .. lang end

Expand All @@ -30,6 +32,12 @@ nvim_biscuits.decorate_nodes = function(bufnr, 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)
Expand Down Expand Up @@ -153,6 +161,16 @@ nvim_biscuits.BufferAttach = function(bufnr)
attached_buffers[bufnr] = true

local lang = ts_parsers.get_buf_lang(bufnr)

local toggle_keybind = config.get_language_config(final_config, lang,
"toggle_keybind")
if toggle_keybind ~= nil and
not config.get_language_config(final_config, lang, "disabled") then
vim.api.nvim_set_keymap("n", toggle_keybind,
":lua require('nvim-biscuits').toggle_biscuits()<CR>",
{noremap = false})
end

local on_lines = function() nvim_biscuits.decorate_nodes(bufnr, lang) end

vim.cmd("highlight default link " .. make_biscuit_hl_group_name(lang) ..
Expand Down Expand Up @@ -186,4 +204,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

0 comments on commit f2b266f

Please sign in to comment.