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

Don't fold when file is short #196

Open
Rizhiy opened this issue Jan 19, 2024 · 2 comments
Open

Don't fold when file is short #196

Rizhiy opened this issue Jan 19, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Rizhiy
Copy link

Rizhiy commented Jan 19, 2024

Feature description

Disable folding if the file is less than X lines long.

Describe the solution you'd like

I used to have the following code when I was using built-in folding, to disable folding for short files:

local autocmd = vim.api.nvim_create_autocmd
autocmd({ "BufReadPost" }, {
    callback = function(_)
        if vim.api.nvim_buf_line_count(0) > 70 then
            vim.opt.foldlevel = 1
        else
            vim.opt.foldlevel = 10
        end
    end,
})

Is it possible to accomplish the same with ufo?

If not, that would be a nice feature to have.

Additional context

Not much point folding parts, if the whole file already fits on the screen.

@Rizhiy Rizhiy added the enhancement New feature or request label Jan 19, 2024
@kevinhwang91
Copy link
Owner

nvim-ufo/doc/example.lua

Lines 113 to 127 in b0741a6

local function applyFoldsAndThenCloseAllFolds(providerName)
require('async')(function()
local bufnr = vim.api.nvim_get_current_buf()
-- make sure buffer is attached
require('ufo').attach(bufnr)
-- getFolds return Promise if providerName == 'lsp'
local ranges = await(require('ufo').getFolds(bufnr, providerName))
if not vim.tbl_isempty(ranges) then
local ok = require('ufo').applyFolds(bufnr, ranges)
if ok then
require('ufo').closeAllFolds()
end
end
end)
end

For now, run this snippet in BufReadPost and replace closeAllFolds with closeFoldsWith under the condition.

If users need this feature, upvote this feature.

@Mo0rBy
Copy link

Mo0rBy commented May 21, 2024

Just came across this issue while attempting to search for issues for an equal/opposite feature: "collapse all folds when file is larger than X lines".

Maybe a new feature could be created where a user can define 2 parameters, an upper and lower bound, or 1 parameter, that tells UFO to collapse/open all folds when the file is larger or smaller the given parameter(s).

I'm unsure if there is already a way to do this as I only found this plugin yesterday (and what a great plugin it is too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants