Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feature-add-togglability
  • Loading branch information
cmgriffing committed Jul 19, 2021
2 parents 75ee66a + 6377663 commit 455726d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,23 @@ 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

```lua
lua <<EOF
require('nvim-biscuits').setup({
cursor_line_only = true
})
EOF
```

## 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
22 changes: 19 additions & 3 deletions lua/nvim-biscuits/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang)
should_decorate = false
end

if should_decorate then
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 == true then
local trim_by_words = config.get_language_config(final_config,
lang,
"trim_by_words")
Expand Down Expand Up @@ -121,8 +127,11 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang)
{text, biscuit_highlight_group_name}
}, {})
end
else
-- utils.console_log('empty')
end

if should_decorate == false and should_clear == true then
vim.api.nvim_buf_clear_namespace(bufnr, biscuit_highlight_group,
end_line, end_line + 1)
end
end

Expand Down Expand Up @@ -178,6 +187,13 @@ nvim_biscuits.BufferAttach = function(bufnr)
au %s <buffer=%s> :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 <buffer=%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,
{
Expand Down

0 comments on commit 455726d

Please sign in to comment.