anuvyklack / pretty-fold.nvim

Foldtext customization in Neovim
Apache License 2.0
441 stars 21 forks source link

[nvim noob] no idea how to set it up #27

Closed okuma10 closed 1 year ago

okuma10 commented 2 years ago

I added it to Packer in my Packer init.lua. Created a pretty-fold-config where I pasted the settings into an init.lua. But I don't see any changes. Is this supposed to work with custom folds or it auto detects. Also how to toggle it? Apologies if maybe asking the obvious but I'm a noob at nvim(and lua)

aasutossh commented 1 year ago

You probably have to :PackerInstall and :PackerCompile after that. I am using Lunarvim, there's a line -- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile

wintermute-cell commented 1 year ago

@okuma10 is it working for you yet? If not, could you share your current init.lua so I can take a look?

okuma10 commented 1 year ago

not sure I did ran :PackerInstall and :PackerCompile . Maybe it's setup correctly but I'm supposed to manualy fold things? I did try using the default fold feature of Nvim, where I had to manually define a custom fold region. The shitty thing was that it got messed up every time I open and edit the the file. Even though I was saving these "snapshot" things. Anyway here is the setup I'm using at the moment

image

It's basically copy-paste of what the readme says. And I just load it from the main init.lua

wintermute-cell commented 1 year ago

Okay that config does look alright. If you don't want to make any configurations, you could shorten the whole setup down to require('pretty-fold').setup(). You can take a look at my config, where I only changed the fill_char, and nothing else: https://github.com/wintermute-cell/dotfiles/blob/18eaf57f042bbee6c6aa4ed3449ee7e839e93513/nvim/.config/nvim/lua/neovim/plugins.lua#L49

About folds not working automatically, that is a different issue; pretty-fold.nvim is only supposed to make the fold text pretty, it does not change the actual functionality. To fix your issue of having to apply folds manually, there are multiple ways to achieve this, depending of what kind of file you want to have folds in. Since you have Treesitter installed, you could use it for generating folds as well (which works pretty well for me). As far as I remember, all you have to do to enable Treesitter folds, is these steps:

  1. Set the following options (the first two are required, the third one is optional and controls the initial fold level when you open a file):

    vim.opt.foldmethod = 'expr'                                -- enable folding (default 'foldmarker')
    vim.wo.foldexpr = "nvim_treesitter#foldexpr()"
    vim.opt.foldlevel = 9999                                     -- open a file fully expanded, set to 

    (My config for further reference: https://github.com/wintermute-cell/dotfiles/blob/18eaf57f042bbee6c6aa4ed3449ee7e839e93513/nvim/.config/nvim/lua/neovim/options.lua#L19)

  2. OPTIONAL: In your Treesitter configs.setup(), you can pass the following:

    fold = {
        fold_one_line_after = true,
    },

    This will preserve things like function headers when folding them. (Again, my config for further reference and context: https://github.com/wintermute-cell/dotfiles/blob/18eaf57f042bbee6c6aa4ed3449ee7e839e93513/nvim/.config/nvim/lua/neovim/treesitter.lua#L20)

When you have applied these options, you should have automatic folds that you can toggle with za in files where there is a language server active. Should the above not work, or should you have any other problems with your configurations that are not directly related to pretty-fold.nvim, feel free to message me under contact@veiled.world.

okuma10 commented 1 year ago

Hey thanks, I'm a bit late to reply but I was changing the Nvim setup following a tutorial. It's working now. Looking nice and pretty!

okuma10 commented 1 year ago

I'll reopen this since I spoke a bit early. What I found was that everything works ok...when I test the settings via ':luafile%' command. But once I close NVIM and reopen it, the settings won't be applied. When I rung that command in that retty_fold_config file, all the formatting is correct when I open up nvim: image

after I run :luafile% image image

I do have the pretty fold settings loading in my init file image

wintermute-cell commented 1 year ago

Hmm.. My first guess would be what the require call is failing, but I couldn't say why either. You could try to make it fail loudly. I'd generally recommend not just to return when the require fails, but to print something; you generally want to know if something is going wrong there. You could do that like this:

local status_ok, configs = pcall(require, 'pretty-fold')
if not status_ok then
    print "pretty_fold_config.lua: Unable to require pretty-fold!"
end

If you see that the require failed, the file is probably being loaded too early for some reason. If that's not the issue you'll need to show me some more of your config.

okuma10 commented 1 year ago

I added the print call but nothing shows up. I moved the require from the main init.lua, to the bottom, and that didn't work either I've uploaded the whole config I have here. https://github.com/okuma10/nvim/tree/main/nvim

wintermute-cell commented 1 year ago

Damn, your config almost broke me, but I found the issue. Ill make you a pull request with the needed change; you issue was calling setup() twice, the first time without any arguments, so it just took the first one and applied no settings.

Two question tho:

okuma10 commented 1 year ago

they thanks a lot for having a look. I suppose when switching to that nvim setup from that youtuber I ended up with a lot of leftovers and overlooked the pretty-fold one. It works great now!

As for the folding...not quite sure honestly. I had that treesitter folding , but that didn't work. So I started using manual folding but then I had to set it up for every file I work on, so I just added the setting for manual fold. Honestly the way I folded was using the #pragma region - #pragma endregion for C and #region - #endregion for Python. That worked really nice in other IDE's I used like Pycharm,Clion or VSCode.Because I don't want if and loop folding, but I do like function folding. Here however this pragma isn't recognized and I have no idea of how to set it up. So I'm manual folding now, although that doesn't give perfect results, since sometimes folds will break and will start folding different lines. But it's working good enough to keep things a bit more organized.

As for the plugins.lua, that's from the youtube setup I followed. Saving plugins.lua auto calls PackerSync as you said, which I think is a nice feature. However it enters in an unwholly alliance with the autosaver I have and I agree it's a real pain in the butt when trying to edit in normal mode. Since in normal mode any change will trigger a save, thus that will trigger an update of these 50 plugins. Not sure if I can tell the autosave to ignore that specific file.