From 2adcf8ea57a4c03dec7b5b679aa35ebba40fd1c1 Mon Sep 17 00:00:00 2001 From: Timm Knape Date: Fri, 20 Jul 2018 12:05:44 +0200 Subject: [PATCH 1/3] added folding --- ftplugin/asciidoc.vim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ftplugin/asciidoc.vim diff --git a/ftplugin/asciidoc.vim b/ftplugin/asciidoc.vim new file mode 100644 index 0000000..52c5bb2 --- /dev/null +++ b/ftplugin/asciidoc.vim @@ -0,0 +1,27 @@ +function! AsciidocFold() + let line = getline(v:lnum) + if (line =~ '\v^[a-zA-Z]') + let nextline = getline(v:lnum + 1) + if (strlen(nextline) != strlen(line)) + return "=" + endif + if (nextline =~ '\v^-+$') + return ">1" + endif + if (nextline =~ '\v^\~+$') + return ">2" + endif + if (nextline =~ '\v^\^+$') + return ">3" + endif + if (nextline =~ '\v^\++$') + return ">4" + endif + endif + return "=" +endfunction + +if has("folding") && exists("g:asciidoc_folding") + setlocal foldexpr=AsciidocFold() + setlocal foldmethod=expr +endif From 1427082e01bb8857f8c633e16a5f7e1afc776790 Mon Sep 17 00:00:00 2001 From: Timm Knape Date: Sun, 22 Jul 2018 11:58:46 +0200 Subject: [PATCH 2/3] updated documentation and added folding for other sections styles --- README.adoc | 11 +++++++++++ ftplugin/asciidoc.vim | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.adoc b/README.adoc index 7513418..aa60472 100644 --- a/README.adoc +++ b/README.adoc @@ -11,6 +11,17 @@ In addition to making reading AsciiDoc documents much easier, syntax highlightin This repository contains the Vim files necessary to syntax highlight AsciiDoc in Vim. A stable version of these files is included in the Vim distribution (see https://github.com/vim/vim/blob/master/runtime/syntax/asciidoc.vim[]). +== Folding + +Folding on the section level is included as well. +To enable the folding, add + +---- +let g:asciidoc_folding=1 +---- + +to the `.vimrc` file. + == Installation (development files) Install the highlighter by copying `asciidoc.vim` to your `$HOME/.vim/syntax` directory. diff --git a/ftplugin/asciidoc.vim b/ftplugin/asciidoc.vim index 52c5bb2..7613ba5 100644 --- a/ftplugin/asciidoc.vim +++ b/ftplugin/asciidoc.vim @@ -4,17 +4,23 @@ function! AsciidocFold() let nextline = getline(v:lnum + 1) if (strlen(nextline) != strlen(line)) return "=" - endif - if (nextline =~ '\v^-+$') + elseif (nextline =~ '\v^-+$') return ">1" - endif - if (nextline =~ '\v^\~+$') + elseif (nextline =~ '\v^\~+$') return ">2" - endif - if (nextline =~ '\v^\^+$') + elseif (nextline =~ '\v^\^+$') return ">3" + elseif (nextline =~ '\v^\++$') + return ">4" endif - if (nextline =~ '\v^\++$') + elseif (line =~ '\v^\=\=') + if (line =~ '\v^\=\=\s') + return ">1" + elseif (line =~ '\v^\=\=\=\s') + return ">2" + elseif (line =~ '\v^\=\=\=\s') + return ">3" + elseif (line =~ '\v^\=\=\=\=\s') return ">4" endif endif From d81b8848781273df6c429bfffa6d86d950306df2 Mon Sep 17 00:00:00 2001 From: Timm Knape Date: Mon, 29 Apr 2019 23:17:49 +0200 Subject: [PATCH 3/3] fold code blocks and first level parts --- ftplugin/asciidoc.vim | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ftplugin/asciidoc.vim b/ftplugin/asciidoc.vim index 7613ba5..e3ba082 100644 --- a/ftplugin/asciidoc.vim +++ b/ftplugin/asciidoc.vim @@ -4,6 +4,8 @@ function! AsciidocFold() let nextline = getline(v:lnum + 1) if (strlen(nextline) != strlen(line)) return "=" + elseif (nextline =~ '\v^\=+$') + return ">0" elseif (nextline =~ '\v^-+$') return ">1" elseif (nextline =~ '\v^\~+$') @@ -13,8 +15,10 @@ function! AsciidocFold() elseif (nextline =~ '\v^\++$') return ">4" endif - elseif (line =~ '\v^\=\=') - if (line =~ '\v^\=\=\s') + elseif (line =~ '\v^\=') + if (line =~ '\v^\=\s') + return ">0" + elseif (line =~ '\v^\=\=\s') return ">1" elseif (line =~ '\v^\=\=\=\s') return ">2" @@ -23,6 +27,13 @@ function! AsciidocFold() elseif (line =~ '\v^\=\=\=\=\s') return ">4" endif + elseif (line =~ '\v^----$') + let prevline = getline(v:lnum - 1) + if (prevline[0] == "[") + return "a1" + else + return "s1" + endif endif return "=" endfunction