mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Make disable accept a function
Replaces the condition setting (though it does the exact inverse)
This commit is contained in:
parent
76673d61c3
commit
d24a1c63d4
2 changed files with 34 additions and 16 deletions
|
|
@ -74,14 +74,9 @@ Each module corresponds to an entry in the dictionary passed to the
|
||||||
EOF
|
EOF
|
||||||
<
|
<
|
||||||
|
|
||||||
All modules share some common options, like `enable`, `disable`, and
|
All modules share some common options, like `enable` and `disable`.
|
||||||
`condition`.
|
|
||||||
When `enable` is `true` this will enable the module for all supported languages,
|
When `enable` is `true` this will enable the module for all supported languages,
|
||||||
if you want to disable the module for some languages you can pass a list to the `disable` option.
|
if you want to disable the module for some languages you can pass a list to the `disable` option.
|
||||||
For more fine-grained control, `condition` takes a function and whenever it returns
|
|
||||||
`false` the module is disabled for that buffer.
|
|
||||||
The `condition` function is called once when a module starts in a buffer and
|
|
||||||
received the language and the buffer number as arguments.
|
|
||||||
|
|
||||||
>
|
>
|
||||||
lua <<EOF
|
lua <<EOF
|
||||||
|
|
@ -97,6 +92,24 @@ received the language and the buffer number as arguments.
|
||||||
EOF
|
EOF
|
||||||
<
|
<
|
||||||
|
|
||||||
|
For more fine-grained control, `disabled` can also take a function and
|
||||||
|
whenever it returns `true`, the module is disabled for that buffer.
|
||||||
|
The function is called once when a module starts in a buffer and receives the
|
||||||
|
language and buffer number as arguments:
|
||||||
|
|
||||||
|
>
|
||||||
|
lua <<EOF
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
highlight = {
|
||||||
|
enable = true,
|
||||||
|
disable = function(lang, bufnr) -- Disable in large C++ buffers
|
||||||
|
return lang == "cpp" and api.nvim_buf_line_count(bufnr) > 50000
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
<
|
||||||
|
|
||||||
Options that define or accept a keymap use the same format you use to define
|
Options that define or accept a keymap use the same format you use to define
|
||||||
keymaps in Neovim, so you can write keymaps as `gd`, `<space>a`, `<leader>a`
|
keymaps in Neovim, so you can write keymaps as `gd`, `<space>a`, `<leader>a`
|
||||||
`<C-a>` (control + a), `<A-n>` (alt + n), `<CR>` (enter), etc.
|
`<C-a>` (control + a), `<A-n>` (alt + n), `<CR>` (enter), etc.
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,16 @@ local builtin_modules = {
|
||||||
highlight = {
|
highlight = {
|
||||||
module_path = "nvim-treesitter.highlight",
|
module_path = "nvim-treesitter.highlight",
|
||||||
enable = false,
|
enable = false,
|
||||||
disable = { "markdown" }, -- FIXME(vigoux): markdown highlighting breaks everything for now
|
|
||||||
custom_captures = {},
|
custom_captures = {},
|
||||||
is_supported = queries.has_highlights,
|
is_supported = function(lang)
|
||||||
|
-- FIXME(vigoux): markdown highlighting breaks everything for now
|
||||||
|
return lang ~= "markdown" and queries.has_highlights(lang)
|
||||||
|
end,
|
||||||
additional_vim_regex_highlighting = false,
|
additional_vim_regex_highlighting = false,
|
||||||
},
|
},
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
module_path = "nvim-treesitter.incremental_selection",
|
module_path = "nvim-treesitter.incremental_selection",
|
||||||
enable = false,
|
enable = false,
|
||||||
disable = {},
|
|
||||||
keymaps = {
|
keymaps = {
|
||||||
init_selection = "gnn",
|
init_selection = "gnn",
|
||||||
node_incremental = "grn",
|
node_incremental = "grn",
|
||||||
|
|
@ -45,7 +46,6 @@ local builtin_modules = {
|
||||||
indent = {
|
indent = {
|
||||||
module_path = "nvim-treesitter.indent",
|
module_path = "nvim-treesitter.indent",
|
||||||
enable = false,
|
enable = false,
|
||||||
disable = {},
|
|
||||||
is_supported = queries.has_indents,
|
is_supported = queries.has_indents,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -351,16 +351,21 @@ function M.is_enabled(mod, lang, bufnr)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if module_config.condition and not module_config.condition(lang, bufnr) then
|
local disable = module_config.disable
|
||||||
return false
|
if type(disable) == 'function' then
|
||||||
end
|
if disable(lang, bufnr) then
|
||||||
|
|
||||||
for _, parser in pairs(module_config.disable) do
|
|
||||||
if lang == parser then
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
elseif type(disable) == 'table' then
|
||||||
|
-- Otherwise it's a list of languages
|
||||||
|
for _, parser in pairs(disable) do
|
||||||
|
if lang == parser then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue