Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

support for folding #1

Open
c-cube opened this issue Sep 22, 2015 · 5 comments
Open

support for folding #1

c-cube opened this issue Sep 22, 2015 · 5 comments

Comments

@c-cube
Copy link

c-cube commented Sep 22, 2015

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
Copy link

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
Copy link
Author

c-cube commented Jan 4, 2016

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
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants