nvim-ufo
nvim-ufo copied to clipboard
Support for Vim's foldmarkers
Feature description
Currently, while using this plugin, you can't use the fold markers you created previously. I'd like to have the possibility to use Vim's basic fold method, the manual one using the fold markers.
Describe the solution you'd like
The solution I'm proposing is to just replicate the original Vim foldmarker support while also having the advanced functionality of this plugin available.
Additional context
Some helpful stuff:
- The currently set fold markers can be used inside Lua by reading the options (yes, they're stored inside an array):
local fmrOpen = vim.opt.foldmarker:get()[1]
local fmrClose = vim.opt.foldmarker:get()[2]
This will read the foldmarkers that are set by anything: be it user configuration, a plugin, the modeline etc.
- Vim actually doesn't care if the foldmarkers are part of the code, or if they're inside comments (a good example is this), it just searches for the foldmarkers wherever it finds them in the buffer. This usually gets solved by using different foldmarkers, but, if you don't want this to happen at all and want to go the approach that foldmarkers should be only inside comments, you could also do some matching with the code's comment string, but this isn't perfect.
local commentString = vim.opt.commentstring:get()
Why isn't it perfect? Well, it renders pretty different results. Take a couple of examples (%s
is a placeholder for the comment)
- The commentstring for Lua is
--%s
(this example is expectable) - The commentstring for C/C++ is
/*%s*/
(for C/C++, it's apparently a multi-line comment, even though there's a single-line comment too) - The commmentstring for Python is
# %s
(yes, with a space, even though Python doesn't require that space for comments)
So, using the commentstring isn't perfect, and it requires a bit more work. I just recommend going the Vim way and matching the foldmarkers wherever they appear in the text, I think it's the better way.
nvim-ufo can provide the marker
provider, but it's not able to combine the fold ranges between two providers using general setup.
Must program yourself under provider_selector
with require('ufo').getFolds
API.
https://github.com/kevinhwang91/nvim-ufo/blob/c412ff87165eb8712e2810799dfa90b728c40028/doc/example.lua#L20-L31
Look like #90 @msva is interested in this feature, close this issue because of duplicate.
@kevinhwang91
with require('ufo').getFolds
API.
And is it any documentation about how to extend the result of call to that function with custom folds?
@msva No, only source code https://github.com/kevinhwang91/nvim-ufo/blob/9e829d5cfa3de6a2ff561d86399772b0339ae49d/lua/ufo.lua#L109-L113
And search getFolds
and read related code from doc/example.lua
. You can also search getFolds
from GitHub issue, I remember that someone has asked for info about this API.