asciidoc / vim-asciidoc

:no_entry: DEPRECATED: (Soon to be) the official repository for the AsciiDoc syntax support in VIM
47 stars 10 forks source link

support for folding #1

Open c-cube opened 9 years ago

c-cube commented 9 years ago

Hello, I really like the asciidoc coloring! A thing I miss compared to other markup languages, though, is folding based on the document structure (e.g., with markdown, I can fold/unfold sections using the usual vim folds). Is adding such a feature possible? Thanks!

jjaderberg commented 8 years ago

To fold document and section titles I keep the following in ~/.vim/after/ftplugin/asciidoc.vim:

" From https://github.com/mjakl/vim-asciidoc/
" Fixed it so that it doesn't interpret every line starting with `=` as heading
" Removed conditional fold options
function! Foldexpr_asciidoc(lnum)
    let l0 = getline(a:lnum)
    if l0 =~ '^=\{1,5}\s\+\S.*$'
        return '>'.matchend(l0, '^=\+')
    else
        return '='
    endif
endfunc

setlocal foldexpr=Foldexpr_asciidoc(v:lnum)
setlocal foldmethod=expr
c-cube commented 8 years ago

That looks nice. Could we try to merge this into this project, with due credit to https://github.com/mjakl/vim-asciidoc/? I can make a PR if the maintainers are in favor.

jjaderberg commented 8 years ago

This is 'expression folding' though, not sure it should go in a syntax file. A filetype plugin is probably a better fit–at least the options shouldn't be set in a syntax file.

It's possible to define folds based on syntax. See :help fold-syntax and :help syn-fold. An example from the Java syntax file that ships with Vim:

syn region javaFold start="{" end="}" transparent fold

This creates a fold for a syntax region–everything between { and }. In the asciidoc syntax file, section titles are not regions but simple syntax matches, so they can't be folded this way. Could probably create a "section" syntax region that starts with a section title and runs until the next section title, then that region could be folded. That's a little more involved than the simple function above.

mlopezgva commented 5 years ago

No news on this? Should keep the above code outside the project? I know that for small documentation purposes this is not important, but for mid-sized it gets more relevance. That and concealing some syntax, like some M↓ plugins do.

Thanks for the plugin and code, BTW.

mlopezgva commented 5 years ago

To fold document and section titles I keep the following in ~/.vim/after/ftplugin/asciidoc.vim:

" From https://github.com/mjakl/vim-asciidoc/
" Fixed it so that it doesn't interpret every line starting with `=` as heading
" Removed conditional fold options
function! Foldexpr_asciidoc(lnum)
    let l0 = getline(a:lnum)
    if l0 =~ '^=\{1,5}\s\+\S.*$'
        return '>'.matchend(l0, '^=\+')
    else
        return '='
    endif
endfunc

setlocal foldexpr=Foldexpr_asciidoc(v:lnum)
setlocal foldmethod=expr

Hi!

How could I add text blocks (----,++++,____) as folding elements?

Thanks.