-
Notifications
You must be signed in to change notification settings - Fork 11
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: use nvim-treesitter define_modules to attach/detach to buffers #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,34 +140,15 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang) | |
end | ||
end | ||
|
||
nvim_biscuits.setup = function(user_config) | ||
if user_config == nil then | ||
user_config = {} | ||
end | ||
|
||
final_config = utils.merge_tables(final_config, user_config) | ||
|
||
if user_config.default_config then | ||
final_config = utils.merge_tables(final_config, | ||
user_config.default_config) | ||
end | ||
|
||
utils.clear_log() | ||
end | ||
|
||
local attached_buffers = {} | ||
nvim_biscuits.BufferAttach = function(bufnr) | ||
bufnr = bufnr or vim.api.nvim_get_current_buf() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
nvim_biscuits.BufferAttach = function(bufnr, lang) | ||
if attached_buffers[bufnr] then return end | ||
|
||
attached_buffers[bufnr] = true | ||
|
||
local lang = ts_parsers.get_buf_lang(bufnr):gsub("-", "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now implemented in the |
||
if toggle_keybind ~= nil then | ||
vim.api.nvim_set_keymap("n", toggle_keybind, | ||
"<Cmd>lua require('nvim-biscuits').toggle_biscuits()<CR>", | ||
{ noremap = false, desc = "toggle biscuits" }) | ||
|
@@ -214,6 +195,40 @@ nvim_biscuits.BufferAttach = function(bufnr) | |
end | ||
end | ||
|
||
nvim_biscuits.setup = function(user_config) | ||
if user_config == nil then | ||
user_config = {} | ||
end | ||
|
||
final_config = utils.merge_tables(final_config, user_config) | ||
|
||
if user_config.default_config then | ||
final_config = utils.merge_tables(final_config, | ||
user_config.default_config) | ||
end | ||
|
||
-- This uses the official nvim-treesitter api to attach/detach to buffers | ||
-- see: https://github.com/nvim-treesitter/nvim-treesitter#adding-modules | ||
-- the attach/detach functions will not run if the is_supported function | ||
-- returns false. | ||
require'nvim-treesitter'.define_modules { | ||
nvim_biscuits = { | ||
enable = true, | ||
attach = function(bufnr, lang) | ||
nvim_biscuits.BufferAttach(bufnr, lang) | ||
end, | ||
detach = function(bufnr) | ||
attached_buffers[bufnr] = nil | ||
end, | ||
is_supported = function(lang) | ||
return not config.get_language_config(final_config, lang, "disabled") | ||
end | ||
} | ||
} | ||
|
||
utils.clear_log() | ||
end | ||
|
||
nvim_biscuits.toggle_biscuits = function() | ||
nvim_biscuits.should_render_biscuits = | ||
not nvim_biscuits.should_render_biscuits | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,3 @@ | |
|
||
highlight default BiscuitColor ctermfg=gray guifg=gray | ||
|
||
augroup NVIM_BISCUITS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer need this. |
||
autocmd! | ||
autocmd BufEnter * :lua require('nvim-biscuits').BufferAttach() | ||
augroup END |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this function below
nvim_biscuits.BufferAttach
definition so that we can use it inside the setup.