diff options
| author | Munif Tanjim <hello@muniftanjim.dev> | 2021-07-08 23:08:06 +0600 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2021-07-08 21:42:02 +0200 |
| commit | 97761acaff346bb7d2350ee0c6d42012fe5985b6 (patch) | |
| tree | 5de70e43a4d7847c54c31fad06c368c5e34c012c | |
| parent | remove packer and nomad from hcl.used_by (#1527) (diff) | |
| download | nvim-treesitter-97761acaff346bb7d2350ee0c6d42012fe5985b6.tar nvim-treesitter-97761acaff346bb7d2350ee0c6d42012fe5985b6.tar.gz nvim-treesitter-97761acaff346bb7d2350ee0c6d42012fe5985b6.tar.bz2 nvim-treesitter-97761acaff346bb7d2350ee0c6d42012fe5985b6.tar.lz nvim-treesitter-97761acaff346bb7d2350ee0c6d42012fe5985b6.tar.xz nvim-treesitter-97761acaff346bb7d2350ee0c6d42012fe5985b6.tar.zst nvim-treesitter-97761acaff346bb7d2350ee0c6d42012fe5985b6.zip | |
Folds: support 'foldminlines'
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | doc/nvim-treesitter.txt | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter/fold.lua | 4 |
3 files changed, 5 insertions, 3 deletions
@@ -274,7 +274,7 @@ set foldmethod=expr set foldexpr=nvim_treesitter#foldexpr() ``` -This will respect your `foldnestmax` setting. +This will respect your `foldminlines` and `foldnestmax` settings. # Advanced setup diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 07b9cd10d..493761d86 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -438,7 +438,7 @@ To use it: > set foldexpr=nvim_treesitter#foldexpr() < -This will respect your 'foldnestmax' setting. +This will respect your 'foldminlines' and 'foldnestmax' settings. Note: This is highly experimental, and folding can break on some types of edits. If you encounter such breakage, hiting `zx` should fix folding. diff --git a/lua/nvim-treesitter/fold.lua b/lua/nvim-treesitter/fold.lua index 1d635bfd2..2502f717d 100644 --- a/lua/nvim-treesitter/fold.lua +++ b/lua/nvim-treesitter/fold.lua @@ -37,6 +37,8 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr) local prev_start = -1 local prev_stop = -1 + local min_fold_lines = api.nvim_win_get_option(0, "foldminlines") + for _, node in ipairs(matches) do local start, _, stop, stop_col = node.node:range() @@ -45,7 +47,7 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr) end local fold_length = stop - start + 1 - local should_fold = fold_length >= 2 + local should_fold = fold_length > min_fold_lines -- Fold only multiline nodes that are not exactly the same as previously met folds -- Checking against just the previously found fold is sufficient if nodes |
