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

fix: allow BufAttach to be called without a bufnr and lang and allow … #52

Merged
merged 1 commit into from
Apr 20, 2024
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
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,47 @@ require('nvim-biscuits').setup({
EOF
```

## Configuration (lazy.nvim support)

If you are using [lazy.nvim](https://github.com/folke/lazy.nvim), you will have to wire up nvim-biscuits is a specific way.

Since you are using lazy.nvim, it is recommended to not use the internal nvim-biscuits [visibilty toggle](https://github.com/code-biscuits/nvim-biscuits?tab=readme-ov-file#configuration-keybinding-to-toggle-visibility).

When setting your `keys` value, you just need to call `BufAttach` inside the callback function:

```lua
keys = {
{
"<leader>bb",
function()
require("nvim-biscuits").BufferAttach()
end,
mode = "n",
desc = "Enable Biscuits",
},
},
```

If you want to lazy load nvim-biscuits but also use the internal visibilty toggle, there are a couple ways of setting things up. If you are letting `show_on_start` default to `false`, you will need to manually toggle the biscuits in the callback function.

```lua
keys = {
{
"<leader>bb",
function()
local nvim_biscuits =
require("nvim-biscuits")
nvim_biscuits.BufferAttach()
nvim_biscuits.toggle_biscuits()
end,
mode = "n",
desc = "Enable Biscuits",
},
},
```

A cleaner way of doing it is to set `show_on_start` to true for nvim-biscuits. Then, you do not need to call `toggle_biscuits` in your lazy.nvim callback.

## 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
9 changes: 9 additions & 0 deletions lua/nvim-biscuits/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ end

local attached_buffers = {}
nvim_biscuits.BufferAttach = function(bufnr, lang)

if bufnr == nil then
bufnr = vim.api.nvim_get_current_buf()
end

if lang == nil then
lang = ts_parsers.get_buf_lang(bufnr):gsub("-", "")
end

if attached_buffers[bufnr] then return end

attached_buffers[bufnr] = true
Expand Down