Skip to content

Commit

Permalink
feature: add togglability and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgriffing committed Jul 11, 2021
1 parent dace687 commit c05824e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<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()
```

## Supported Languages

We currently support all the languages supported in tree-sitter. Not all languages have specialized support, though most will probably need some.
Expand Down
24 changes: 24 additions & 0 deletions lua/nvim-biscuits/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ 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 = 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)
Expand Down Expand Up @@ -138,6 +145,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(lang) ..
Expand All @@ -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

0 comments on commit c05824e

Please sign in to comment.