Open kiryph opened 7 years ago
Nice work!
I tried to piggyback on the work done in the syntax detection (hence the synIDattr
calls) but seems like it's not as fast as I thought...
The alternatives are:
This is the real problem with markdown, if you want to be "correct" as I try to be here, you need to consider a fair amount of context to decide what is what and that is slooow
So, the answer could be to ad an option g:markdown_enable_simple_folding
and g:markdown_enable_smart_folding
with g:markdown_enable_folding
to enable g:markdown_enable_smart_folding
to be backward compatible
Where g:markdown_enable_simple_folding
is folding based on simple (and fast) regular expressions
Pull requests on this are welcomed ๐
Thanks for your quick response and your thoughts!
I did some research about folding capabilities of vim plugins for markdown files:
$VIMRUNTIME/ftplugin/markdown.vim
offers header folding (maintainer Tim Pope, most recent version can be found here https://github.com/tpope/vim-markdown)<!-- {{{ ->>
or <!-- Custom fold fold-begin -->
and selected div classes which end with </div foldend>
.I was hoping that your plugin can fold the html tag <details>
in a markdown file:
<details><summary>Abstract</summary>
*The invention is directed to...*
</details>
since none of the other plugins offer a possibility for this.
So I think, adding fast folding based on regular expressions is not necessary, just disable the folding of your plugin and use the one distributed with vim.
I have a question: Would it be possible to improve the speed by modifying the syntax file?
Right now, I switched to vim-pandoc using fold comments where, however, I miss support for fold texts (see https://github.com/vim-pandoc/vim-pandoc/issues/199). Having a line
## <!-- {{{ --> / 12 lines / -----------
does not tell you anything about what is hidden in the fold.
I have a question: Would it be possible to improve the speed by modifying the syntax file?
Good question, I don't know if synIDattr/synID
could be faster with a simpler grammar, I don't think so because it's a fact that they are slow
But even so, we will go back to the same problem, simpler syntax can be achieved eliminating the context consideration (the amount of text to consider in the surrounding area) but then will be very difficult to maintain correctness ๐
In the end it's a tradeoff between "simple and fast" Vs "correct and slow", I chose the second, other plugins chose the first
Hi @gabrielelana. Do you have some time to look at improving folding capabilities again?
I care about folding as well, but it's not very efficient at the moment.
Since I always put a title with #
at the top of my markdown files, vim-markdown always fold the entire file when I enter it.
I do not know what would be a good way to handling auto-folding, but maybe adding a setting to manually set the preferred depth for headers could make it less cumbersome.
let g:markdown_enable_folding = 1
let g:markdown_folding_level = 3
# Level 1 title
## Level 2
+--- 9 lines: ### level 3 titleยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
+--- 9 lines: ### another titleยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
## Another Level 2 title
+--- 9 lines: ### level 3 titleยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
+--- 9 lines: ### another titleยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
It is also strange that I cannot unfold 2 levels of headers with 2zo
. Right now, 2zo
and zo
in
+--- 44 lines: # Level 1 titleยทยทยทยทยทยทยทยทยทยทยทยท
both result in
# Level 1 title
+--- 20 lines: ## level 2ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
+--- 20 lines: ## Another Level 2ยทยทยทยทยทยทยทยทยทยท
I wish ##
headers were considered under the cursor when the whole file is folded...
I have added to my vimrc
let g:markdown_enable_folding = 1
to enable folding. However, this makes vim not usable anymore. I had to turn it off.I did some profiling according to http://stackoverflow.com/a/12216578/1057593.
As expected the problematic function is the fold-function. The profiling result for
FUNCTION markdown#FoldLevelOfLine()
is in particular:The problematic lines are:
My vim version is
MWE-vimrc, using vim-plug installed to
~/.vim/autoload/plug.vim
and the plugins to~/.vim/plugged/
I already use
Konfekt/FastFold
. However, folds still have to be updated when opening the file, opening and closing folds. There is no chance that I wait so long to open files, open or close folds.Is there any chance to improve the performance?