mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-27 20:05:23 +00:00
treesitter: allow setting of filetype pattern and excludes for indent
This commit is contained in:
parent
5ab359ee7d
commit
d30ba87023
3 changed files with 41 additions and 4 deletions
|
|
@ -390,4 +390,12 @@ https://github.com/gorbit99/codewindow.nvim
|
||||||
|
|
||||||
- Add razor support for `roslyn_ls` and `csharp_ls`
|
- Add razor support for `roslyn_ls` and `csharp_ls`
|
||||||
|
|
||||||
|
[mputz86](https://github.com/mputz86)
|
||||||
|
|
||||||
|
- Add `vim.treesitter.indent.pattern` to specify file pattern(s) for which
|
||||||
|
treesitter indentation should be used
|
||||||
|
- Add `vim.treesitter.indent.excludes` to exclude filetypes from the treesitter
|
||||||
|
indentation; e.g. useful for Haskell and PureScript, for which treesitter
|
||||||
|
indentation does not work good
|
||||||
|
|
||||||
<!-- vim: set textwidth=80: -->
|
<!-- vim: set textwidth=80: -->
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
|
inherit (lib.strings) optionalString;
|
||||||
inherit (lib.lists) optionals;
|
inherit (lib.lists) optionals;
|
||||||
inherit (lib.nvim.dag) entryAfter;
|
inherit (lib.nvim.dag) entryAfter;
|
||||||
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
|
||||||
cfg = config.vim.treesitter;
|
cfg = config.vim.treesitter;
|
||||||
in {
|
in {
|
||||||
|
|
@ -39,8 +41,14 @@ in {
|
||||||
-- Enable treesitter highlighting for all filetypes
|
-- Enable treesitter highlighting for all filetypes
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = "nvf_treesitter",
|
group = "nvf_treesitter",
|
||||||
pattern = "*",
|
pattern = ${toLuaObject cfg.indent.pattern},
|
||||||
callback = function()
|
callback = function(args)
|
||||||
|
${optionalString (builtins.length cfg.indent.excludes > 0) ''
|
||||||
|
local ft = vim.bo[args.buf].filetype
|
||||||
|
if vim.tbl_contains(${toLuaObject cfg.indent.excludes}, ft) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
''}
|
||||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
||||||
inherit (lib.types) listOf nullOr package bool;
|
inherit (lib.types) listOf nullOr package bool str oneOf;
|
||||||
in {
|
in {
|
||||||
options.vim.treesitter = {
|
options.vim.treesitter = {
|
||||||
enable = mkEnableOption "treesitter, also enabled automatically through language options";
|
enable = mkEnableOption "treesitter, also enabled automatically through language options";
|
||||||
|
|
@ -64,7 +64,28 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
indent = {enable = mkEnableOption "indentation with treesitter" // {default = true;};};
|
indent = {
|
||||||
|
enable = mkEnableOption "indentation with treesitter" // {default = true;};
|
||||||
|
pattern = mkOption {
|
||||||
|
type = oneOf [str (listOf str)];
|
||||||
|
default = "*";
|
||||||
|
example = literalExpression ''["lua" "nix"]'';
|
||||||
|
description = ''
|
||||||
|
Specify the filetype pattern(s) for which the treesitter indentation should be used.
|
||||||
|
|
||||||
|
See {command}`:h autocmd-pattern`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
excludes = mkOption {
|
||||||
|
type = listOf str;
|
||||||
|
default = [];
|
||||||
|
example = literalExpression ''["haskell", "purescript"]'';
|
||||||
|
description = ''
|
||||||
|
Exclude the listed filetypes from using treesitter indentation.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
highlight = {enable = mkEnableOption "highlighting with treesitter" // {default = true;};};
|
highlight = {enable = mkEnableOption "highlighting with treesitter" // {default = true;};};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue