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

added folding #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.adoc
Expand Up @@ -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.
Expand Down
44 changes: 44 additions & 0 deletions ftplugin/asciidoc.vim
@@ -0,0 +1,44 @@
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 "="
elseif (nextline =~ '\v^\=+$')
return ">0"
elseif (nextline =~ '\v^-+$')
return ">1"
elseif (nextline =~ '\v^\~+$')
return ">2"
elseif (nextline =~ '\v^\^+$')
return ">3"
elseif (nextline =~ '\v^\++$')
return ">4"
endif
elseif (line =~ '\v^\=')
if (line =~ '\v^\=\s')
return ">0"
elseif (line =~ '\v^\=\=\s')
return ">1"
elseif (line =~ '\v^\=\=\=\s')
return ">2"
elseif (line =~ '\v^\=\=\=\s')
return ">3"
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

if has("folding") && exists("g:asciidoc_folding")
setlocal foldexpr=AsciidocFold()
setlocal foldmethod=expr
endif